Commit 0c97e6fe authored by Christian Gutschow's avatar Christian Gutschow
Browse files

temp patch for weight selection

parent c335c269
......@@ -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];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment