@@ -560,7 +560,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
560560 std::vector<ScaleVarWeight> scaleVariationIDs;
561561 std::vector<PDFSetWeights> pdfSetWeightIDs;
562562 std::vector<std::string> lheReweighingIDs;
563- bool isFirstGroup = true ;
563+ bool preScaleVariationGroup = true ;
564564
565565 std::regex weightgroupmg26x (" <weightgroup\\ s+(?:name|type)=\" (.*)\"\\ s+combine=\" (.*)\"\\ s*>" );
566566 std::regex weightgroup (" <weightgroup\\ s+combine=\" (.*)\"\\ s+(?:name|type)=\" (.*)\"\\ s*>" );
@@ -592,9 +592,20 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
592592 " \\ s*(?:PDF=(\\ d+)\\ s*MemberID=(\\ d+))?\\ s*(?:\\ s.*)?</"
593593 " weight>" );
594594
595+ std::regex mgVerRegex (R"( VERSION\s+(\d+)\.(\d+)\.(\d+))" );
596+ bool isMGVer2x = false ;
597+
595598 std::regex rwgt (" <weight\\ s+id=\" (.+)\" >(.+)?(</weight>)?" );
596599 std::smatch groups;
597600 for (auto iter = lheInfo->headers_begin (), end = lheInfo->headers_end (); iter != end; ++iter) {
601+ if (iter->tag () == " MG5ProcCard" ) {
602+ for (const auto & line : iter->lines ()) {
603+ if (std::regex_search (line, groups, mgVerRegex)) {
604+ isMGVer2x = (groups[1 ].str () == " 2" );
605+ break ;
606+ }
607+ }
608+ }
598609 if (iter->tag () != " initrwgt" ) {
599610 if (lheDebug)
600611 std::cout << " Skipping LHE header with tag" << iter->tag () << std::endl;
@@ -622,22 +633,24 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
622633 if (lheDebug)
623634 std::cout << lines[iLine];
624635 auto foundWeightGroup = std::regex_search (lines[iLine], groups, ismg26x ? weightgroupmg26x : weightgroup);
625- if (foundWeightGroup || isFirstGroup ) {
636+ if (foundWeightGroup || preScaleVariationGroup ) {
626637 std::string groupname;
627638 if (foundWeightGroup) {
628- groupname = groups.str (2 );
629- if (ismg26x)
630- groupname = groups.str (1 );
639+ groupname = ismg26x ? groups.str (1 ) : groups.str (2 );
640+ } else {
641+ // rewind by one line and check later in the inner loop
642+ --iLine;
631643 }
632644 if (lheDebug)
633645 std::cout << " >>> Looks like the beginning of a weight group for '" << groupname << " '" << std::endl;
634- if (groupname.find (" scale_variation" ) == 0 || groupname == " Central scale variation" || isFirstGroup) {
646+ if (groupname.find (" scale_variation" ) == 0 || groupname == " Central scale variation" ||
647+ preScaleVariationGroup) {
635648 if (lheDebug && groupname.find (" scale_variation" ) != 0 && groupname != " Central scale variation" )
636649 std::cout << " >>> First weight is not scale variation, but assuming is the Central Weight" << std::endl;
637650 else if (lheDebug)
638651 std::cout << " >>> Looks like scale variation for theory uncertainties" << std::endl;
639- if (foundWeightGroup ) {
640- isFirstGroup = false ;
652+ if (groupname. find ( " scale_variation " ) == 0 || groupname == " Central scale variation " ) {
653+ preScaleVariationGroup = false ;
641654 }
642655 for (++iLine; iLine < nLines; ++iLine) {
643656 if (lheDebug) {
@@ -936,7 +949,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
936949 }
937950 }
938951 // check the number of scale variations
939- if (!allowedNumScaleWeights_.empty ()) {
952+ if (isMGVer2x && !allowedNumScaleWeights_.empty ()) {
940953 auto it = std::find (allowedNumScaleWeights_.begin (), allowedNumScaleWeights_.end (), scaleVariationIDs.size ());
941954 if (it == allowedNumScaleWeights_.end ()) {
942955 throw cms::Exception (" LogicError" )
0 commit comments