Skip to content
Snippets Groups Projects
Commit 117760ce authored by Christian Gutschow's avatar Christian Gutschow
Browse files

disable weight-name cleaning for unnamed weights

parent 00cce5cd
No related branches found
No related tags found
10 merge requests!66713update MadGraph version,!51680Add functionality to MultiBjetFilter,!44215added ART tests,!42752Fix for TopRecon UserHook,!41097TruthJetFilter phi filter,!38102Add SameParticleHardScatteringFilter,!36648Rivet doc update,!33707WIP: Fixes for the updated Powheg Wt_DR process, and removal of Wt_DR_onshellW and Wt_DS_onshellW processes,!3297121.6 parameter dict pythia fixes,!3229821.6 Rivet_i: skip weight-name cleaning for unnamed weights
......@@ -305,47 +305,51 @@ const HepMC::GenEvent* Rivet_i::checkEvent(const HepMC::GenEvent* event) {
}
// weight-name cleaning
vector<pair<string,string> > w_subs = {
{" nominal ",""},
{" set = ","_"},
{" = ","_"},
{"=",""},
{",",""},
{".",""},
{":",""},
{" ","_"},
{"#","num"},
{"\n","_"},
{"/","over"}
};
const HepMC::WeightContainer& old_wc = event->weights();
HepMC::WeightContainer& new_wc = modEvent->weights();
new_wc.clear();
std::ostringstream stream;
old_wc.print(stream);
string str = stream.str();
std::regex re("(([^()]+))"); // Regex for stuff enclosed by parentheses ()
for (std::sregex_iterator i = std::sregex_iterator(str.begin(), str.end(), re);
i != std::sregex_iterator(); ++i ) {
std::smatch m = *i;
vector<string> temp = ::split(m.str(), "[,]");
if (temp.size() == 2 || temp.size() == 3) {
string wname = temp[0];
if (temp.size() == 3) wname += "," + temp[1];
double value = old_wc[wname];
for (const auto& sub : w_subs) {
size_t start_pos = wname.find(sub.first);
while (start_pos != std::string::npos) {
wname.replace(start_pos, sub.first.length(), sub.second);
start_pos = wname.find(sub.first);
// if it only has one element,
// then it doesn't use named weights
// --> no need for weight-name cleaning
if (str.size() > 1) {
HepMC::WeightContainer& new_wc = modEvent->weights();
new_wc.clear();
vector<pair<string,string> > w_subs = {
{" nominal ",""},
{" set = ","_"},
{" = ","_"},
{"=",""},
{",",""},
{".",""},
{":",""},
{" ","_"},
{"#","num"},
{"\n","_"},
{"/","over"}
};
std::regex re("(([^()]+))"); // Regex for stuff enclosed by parentheses ()
for (std::sregex_iterator i = std::sregex_iterator(str.begin(), str.end(), re);
i != std::sregex_iterator(); ++i ) {
std::smatch m = *i;
vector<string> temp = ::split(m.str(), "[,]");
if (temp.size() == 2 || temp.size() == 3) {
string wname = temp[0];
if (temp.size() == 3) wname += "," + temp[1];
double value = old_wc[wname];
for (const auto& sub : w_subs) {
size_t start_pos = wname.find(sub.first);
while (start_pos != std::string::npos) {
wname.replace(start_pos, sub.first.length(), sub.second);
start_pos = wname.find(sub.first);
}
}
new_wc[wname];
new_wc.back() = value;
}
new_wc[wname];
new_wc.back() = value;
}
// end of weight-name cleaning
}
// end of weight-name cleaning
if (!modEvent->valid_beam_particles()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment