diff --git a/Generators/Rivet_i/src/Rivet_i.cxx b/Generators/Rivet_i/src/Rivet_i.cxx index d31888f0cc95dcbea14a4c0dc2d803e1ca175911..df70158eae01e4e96c28b9854b08021fc7b4f135 100644 --- a/Generators/Rivet_i/src/Rivet_i.cxx +++ b/Generators/Rivet_i/src/Rivet_i.cxx @@ -137,8 +137,8 @@ StatusCode Rivet_i::initialize() { assert(m_analysisHandler); m_analysisHandler->setIgnoreBeams(m_ignorebeams); //< Whether to do beam ID/energy consistency checks m_analysisHandler->skipMultiWeights(m_skipweights); //< Only run on the nominal weight - m_analysisHandler->selectMultiWeights(m_matchWeights); //< Only run on a subset of the multi-weights - m_analysisHandler->deselectMultiWeights(m_unmatchWeights); //< Veto a subset of the multi-weights + //m_analysisHandler->selectMultiWeights(m_matchWeights); //< Only run on a subset of the multi-weights + //m_analysisHandler->deselectMultiWeights(m_unmatchWeights); //< Veto a subset of the multi-weights if(m_weightcap>0) m_analysisHandler->setWeightCap(m_weightcap); // Set Rivet native log level to match Athena @@ -340,6 +340,22 @@ const HepMC::GenEvent* Rivet_i::checkEvent(const HepMC::GenEvent* event) { {"/","over"} }; std::regex re("(([^()]+))"); // Regex for stuff enclosed by parentheses () + + // TEMP from Rivet dev branch + vector<std::regex> select_patterns, deselect_patterns; + if (m_matchWeights != "") { + // Compile regex from each string in the comma-separated list + for (const string& pattern : split(m_matchWeights, ",")) { + select_patterns.push_back( std::regex(pattern) ); + } + } + if (m_unmatchWeights != "") { + // Compile regex from each string in the comma-separated list + for (const string& pattern : split(m_unmatchWeights, ",")) { + deselect_patterns.push_back( std::regex(pattern) ); + } + } + // END OF TEMP for (std::sregex_iterator i = std::sregex_iterator(str.begin(), str.end(), re); i != std::sregex_iterator(); ++i ) { std::smatch m = *i; @@ -356,11 +372,32 @@ const HepMC::GenEvent* Rivet_i::checkEvent(const HepMC::GenEvent* event) { start_pos = wname.find(sub.first); } } + // Pulling some logic from the Rivet development branch + // until we have a release with this patch: + + // Check if weight name matches a supplied string/regex and filter to select those only + bool match = select_patterns.empty(); + for (const std::regex& re : select_patterns) { + if ( std::regex_match(wname, re) ) { + match = true; + break; + } + } + // Check if the remaining weight names match supplied string/regexes and *de*select accordingly + bool unmatch = false; + for (const std::regex& re : deselect_patterns) { + if ( std::regex_match(wname, re) ) { unmatch = true; break; } + } + if (!match || unmatch) continue; + + // end of borrowing logic from the Rivet development branch new_name_to_value[wname] = value; old_name_to_new_name[old_name] = wname; } } + auto itEnd = old_name_to_new_name.end(); for (const string& old_name : orig_order) { + if (old_name_to_new_name.find(old_name) == itEnd) continue; const string& new_name = old_name_to_new_name[old_name]; new_wc[ new_name ] = new_name_to_value[new_name]; }