From 45af73dfb3e48000b7b044b3ce55505c229ecd0c Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 5 Oct 2020 15:54:47 +0200 Subject: [PATCH 1/2] Porting Andrea's MG26X fixes Fix a few places where missing_weightgroup wasn't set Debug back off Formatting --- .../plugins/GenWeightsTableProducer.cc | 62 +++++++++++++++---- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc index 4728bca56d2bc..ff05c1ca63021 100644 --- a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc @@ -551,12 +551,18 @@ class GenWeightsTableProducer : public edm::global::EDProducer lheReweighingIDs; std::regex weightgroupmg26x(""); + std::regex weightgroupmg26xNew(""); std::regex weightgroup(""); std::regex weightgroupRwgt(""); std::regex endweightgroup(""); std::regex scalewmg26x( ""); + std::regex scalewmg26xNew( + ""); + + // MUR=2.0 std::regex scalew( "\\s*(?:lhapdf=\\d+|dyn=\\s*-?\\d+)?\\s*((?:mu[rR]|renscfact)=(\\S+)\\s+(" "?:mu[Ff]|facscfact)=(\\S+)(\\s+.*)?)"); @@ -567,6 +573,14 @@ class GenWeightsTableProducer : public edm::global::EDProducer\\s*(?:PDF=(\\d+)\\s*MemberID=(\\d+))?\\s*(?:\\s.*)?"); + // + + // PDF=325300 MemberID=0 + std::regex pdfwmg26xNew( + "" + "\\s*(?:PDF=(\\d+)\\s*MemberID=(\\d+))?\\s*(?:\\s.*)?"); + std::regex rwgt("(.+)?()?"); std::smatch groups; for (auto iter = lheInfo->headers_begin(), end = lheInfo->headers_end(); iter != end; ++iter) { @@ -581,34 +595,47 @@ class GenWeightsTableProducer : public edm::global::EDProducer"); if (std::regex_search(lines[iLine], groups, weightgroupmg26x)) { ismg26x = true; + } else if (std::regex_search(lines[iLine], groups, weightgroupmg26xNew)) { + ismg26xNew = true; } } for (unsigned int iLine = 0, nLines = lines.size(); iLine < nLines; ++iLine) { if (lheDebug) std::cout << lines[iLine]; - if (std::regex_search(lines[iLine], groups, ismg26x ? weightgroupmg26x : weightgroup)) { + if (std::regex_search(lines[iLine], + groups, + ismg26x ? weightgroupmg26x : (ismg26xNew ? weightgroupmg26xNew : weightgroup))) { std::string groupname = groups.str(2); if (ismg26x) groupname = groups.str(1); + else if (ismg26xNew) + groupname = groups.str(2); if (lheDebug) std::cout << ">>> Looks like the beginning of a weight group for '" << groupname << "'" << std::endl; if (groupname.find("scale_variation") == 0 || groupname == "Central scale variation") { if (lheDebug) std::cout << ">>> Looks like scale variation for theory uncertainties" << std::endl; for (++iLine; iLine < nLines; ++iLine) { - if (lheDebug) + if (lheDebug) { std::cout << " " << lines[iLine]; - if (std::regex_search(lines[iLine], groups, ismg26x ? scalewmg26x : scalew)) { + } + if (std::regex_search( + lines[iLine], groups, ismg26x ? scalewmg26x : (ismg26xNew ? scalewmg26xNew : scalew))) { if (lheDebug) std::cout << " >>> Scale weight " << groups[1].str() << " for " << groups[3].str() << " , " << groups[4].str() << " , " << groups[5].str() << std::endl; - scaleVariationIDs.emplace_back(groups.str(1), groups.str(2), groups.str(3), groups.str(4)); + if (ismg26xNew) { + scaleVariationIDs.emplace_back(groups.str(4), groups.str(1), groups.str(3), groups.str(2)); + } else { + scaleVariationIDs.emplace_back(groups.str(1), groups.str(2), groups.str(3), groups.str(4)); + } } else if (std::regex_search(lines[iLine], endweightgroup)) { if (lheDebug) std::cout << ">>> Looks like the end of a weight group" << std::endl; @@ -616,12 +643,14 @@ class GenWeightsTableProducer : public edm::global::EDProducer>> Looks like the beginning of a new weight group, I will assume I missed the end " "of the group." << std::endl; - if (ismg26x) + if (ismg26x || ismg26xNew) missed_weightgroup = true; --iLine; // rewind by one, and go back to the outer loop break; @@ -648,12 +677,14 @@ class GenWeightsTableProducer : public edm::global::EDProducer>> Looks like the beginning of a new weight group, I will assume I missed the end " "of the group." << std::endl; - if (ismg26x) + if (ismg26x || ismg26xNew) missed_weightgroup = true; --iLine; // rewind by one, and go back to the outer loop break; @@ -690,7 +721,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer>> Looks like the beginning of a new weight group, I will assume I missed the end " "of the group." << std::endl; - if (ismg26x) + if (ismg26x || ismg26xNew) missed_weightgroup = true; --iLine; // rewind by one, and go back to the outer loop break; @@ -704,10 +735,15 @@ class GenWeightsTableProducer : public edm::global::EDProducer>> Looks like the beginning of a new weight group, I will assume I missed the end " "of the group." << std::endl; - if (ismg26x) + if (ismg26x || ismg26xNew) missed_weightgroup = true; --iLine; // rewind by one, and go back to the outer loop break; @@ -758,7 +794,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer>> Looks like the beginning of a new weight group, I will assume I missed the end " "of the group." << std::endl; - if (ismg26x) + if (ismg26x || ismg26xNew) missed_weightgroup = true; --iLine; // rewind by one, and go back to the outer loop break; From 1f2dcbafb72cffe742901ea134fea9916a7e6a40 Mon Sep 17 00:00:00 2001 From: Dylan Teague Date: Wed, 21 Oct 2020 12:10:28 +0200 Subject: [PATCH 2/2] Fix central weight and error from mg26xNew --- .../plugins/GenWeightsTableProducer.cc | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc index ff05c1ca63021..9b7a24add8d0e 100644 --- a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc @@ -549,9 +549,9 @@ class GenWeightsTableProducer : public edm::global::EDProducer scaleVariationIDs; std::vector pdfSetWeightIDs; std::vector lheReweighingIDs; + bool isFirstGroup = true; std::regex weightgroupmg26x(""); - std::regex weightgroupmg26xNew(""); std::regex weightgroup(""); std::regex weightgroupRwgt(""); std::regex endweightgroup(""); @@ -602,26 +602,26 @@ class GenWeightsTableProducer : public edm::global::EDProducer"); if (std::regex_search(lines[iLine], groups, weightgroupmg26x)) { ismg26x = true; - } else if (std::regex_search(lines[iLine], groups, weightgroupmg26xNew)) { + } else if (std::regex_search(lines[iLine], groups, scalewmg26xNew) || + std::regex_search(lines[iLine], groups, pdfwmg26xNew)) { ismg26xNew = true; } } for (unsigned int iLine = 0, nLines = lines.size(); iLine < nLines; ++iLine) { if (lheDebug) std::cout << lines[iLine]; - if (std::regex_search(lines[iLine], - groups, - ismg26x ? weightgroupmg26x : (ismg26xNew ? weightgroupmg26xNew : weightgroup))) { + if (std::regex_search(lines[iLine], groups, ismg26x ? weightgroupmg26x : weightgroup)) { std::string groupname = groups.str(2); if (ismg26x) groupname = groups.str(1); - else if (ismg26xNew) - groupname = groups.str(2); if (lheDebug) std::cout << ">>> Looks like the beginning of a weight group for '" << groupname << "'" << std::endl; - if (groupname.find("scale_variation") == 0 || groupname == "Central scale variation") { - if (lheDebug) + if (groupname.find("scale_variation") == 0 || groupname == "Central scale variation" || isFirstGroup) { + if (lheDebug && groupname.find("scale_variation") != 0 && groupname != "Central scale variation") + std::cout << ">>> First weight is not scale variation, but assuming is the Central Weight" << std::endl; + else if (lheDebug) std::cout << ">>> Looks like scale variation for theory uncertainties" << std::endl; + isFirstGroup = false; for (++iLine; iLine < nLines; ++iLine) { if (lheDebug) { std::cout << " " << lines[iLine]; @@ -643,9 +643,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer>> Looks like the beginning of a new weight group, I will assume I missed the end " "of the group." @@ -677,9 +675,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer>> Looks like the beginning of a new weight group, I will assume I missed the end " "of the group."