@@ -262,6 +262,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
262262 lheWeightPrecision_(params.getParameter<int32_t >(" lheWeightPrecision" )),
263263 maxPdfWeights_(params.getParameter<uint32_t >(" maxPdfWeights" )),
264264 keepAllPSWeights_(params.getParameter<bool >(" keepAllPSWeights" )),
265+ allowedNumScaleWeights_(params.getParameter<std::vector<uint32_t >>(" allowedNumScaleWeights" )),
265266 debug_(params.getUntrackedParameter<bool >(" debug" , false )),
266267 debugRun_(debug_.load()),
267268 hasIssuedWarning_(false ),
@@ -620,18 +621,24 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
620621 for (unsigned int iLine = 0 , nLines = lines.size (); iLine < nLines; ++iLine) {
621622 if (lheDebug)
622623 std::cout << lines[iLine];
623- if (std::regex_search (lines[iLine], groups, ismg26x ? weightgroupmg26x : weightgroup)) {
624- std::string groupname = groups.str (2 );
625- if (ismg26x)
626- groupname = groups.str (1 );
624+ auto foundWeightGroup = std::regex_search (lines[iLine], groups, ismg26x ? weightgroupmg26x : weightgroup);
625+ if (foundWeightGroup || isFirstGroup) {
626+ std::string groupname;
627+ if (foundWeightGroup) {
628+ groupname = groups.str (2 );
629+ if (ismg26x)
630+ groupname = groups.str (1 );
631+ }
627632 if (lheDebug)
628633 std::cout << " >>> Looks like the beginning of a weight group for '" << groupname << " '" << std::endl;
629634 if (groupname.find (" scale_variation" ) == 0 || groupname == " Central scale variation" || isFirstGroup) {
630635 if (lheDebug && groupname.find (" scale_variation" ) != 0 && groupname != " Central scale variation" )
631636 std::cout << " >>> First weight is not scale variation, but assuming is the Central Weight" << std::endl;
632637 else if (lheDebug)
633638 std::cout << " >>> Looks like scale variation for theory uncertainties" << std::endl;
634- isFirstGroup = false ;
639+ if (foundWeightGroup) {
640+ isFirstGroup = false ;
641+ }
635642 for (++iLine; iLine < nLines; ++iLine) {
636643 if (lheDebug) {
637644 std::cout << " " << lines[iLine];
@@ -928,7 +935,16 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
928935 break ;
929936 }
930937 }
938+ // check the number of scale variations
939+ if (!allowedNumScaleWeights_.empty ()) {
940+ auto it = std::find (allowedNumScaleWeights_.begin (), allowedNumScaleWeights_.end (), scaleVariationIDs.size ());
941+ if (it == allowedNumScaleWeights_.end ()) {
942+ throw cms::Exception (" LogicError" )
943+ << " Number of scale variations found (" << scaleVariationIDs.size () << " ) is invalid." ;
944+ }
945+ }
931946 }
947+
932948 return weightChoice;
933949 }
934950
@@ -1171,6 +1187,9 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
11711187 desc.add <int32_t >(" lheWeightPrecision" )->setComment (" Number of bits in the mantissa for LHE weights" );
11721188 desc.add <uint32_t >(" maxPdfWeights" )->setComment (" Maximum number of PDF weights to save (to crop NN replicas)" );
11731189 desc.add <bool >(" keepAllPSWeights" )->setComment (" Store all PS weights found" );
1190+ desc.add <std::vector<uint32_t >>(" allowedNumScaleWeights" )
1191+ ->setComment (
1192+ " Allowed numbers of scale weights parsed from the header. Empty list means any number is allowed." );
11741193 desc.addOptionalUntracked <bool >(" debug" )->setComment (" dump out all LHE information for one event" );
11751194 descriptions.add (" genWeightsTable" , desc);
11761195 }
@@ -1189,6 +1208,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
11891208 int lheWeightPrecision_;
11901209 unsigned int maxPdfWeights_;
11911210 bool keepAllPSWeights_;
1211+ std::vector<uint32_t > allowedNumScaleWeights_;
11921212
11931213 mutable std::atomic<bool > debug_, debugRun_, hasIssuedWarning_, psWeightWarning_;
11941214};
0 commit comments