CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Attributes
GenWeightsTableProducer Class Reference
Inheritance diagram for GenWeightsTableProducer:
edm::global::EDProducer< edm::StreamCache< LumiCacheInfoHolder >, edm::RunCache< DynamicWeightChoice >, edm::RunSummaryCache< CounterMap >, edm::EndRunProducer > edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

std::unique_ptr< LumiCacheInfoHolder > beginStream (edm::StreamID) const override
 
void fillLHEPdfWeightTablesFromGenInfo (Counter *counter, const DynamicWeightChoiceGenInfo *weightChoice, double genWeight, const GenEventInfoProduct &genProd, std::unique_ptr< nanoaod::FlatTable > &outScale, std::unique_ptr< nanoaod::FlatTable > &outPdf, std::unique_ptr< nanoaod::FlatTable > &outNamed, std::unique_ptr< nanoaod::FlatTable > &outPS) const
 
void fillLHEWeightTables (Counter *counter, const DynamicWeightChoice *weightChoice, double genWeight, const LHEEventProduct &lheProd, const GenEventInfoProduct &genProd, std::unique_ptr< nanoaod::FlatTable > &outScale, std::unique_ptr< nanoaod::FlatTable > &outPdf, std::unique_ptr< nanoaod::FlatTable > &outRwgt, std::unique_ptr< nanoaod::FlatTable > &outNamed, std::unique_ptr< nanoaod::FlatTable > &outPS) const
 
void fillOnlyPSWeightTable (Counter *counter, double genWeight, const GenEventInfoProduct &genProd, std::unique_ptr< nanoaod::FlatTable > &outPS) const
 
 GenWeightsTableProducer (edm::ParameterSet const &params)
 
std::shared_ptr< DynamicWeightChoice > globalBeginRun (edm::Run const &iRun, edm::EventSetup const &) const override
 
std::shared_ptr< CounterMap > globalBeginRunSummary (edm::Run const &, edm::EventSetup const &) const override
 
void globalEndRun (edm::Run const &, edm::EventSetup const &) const override
 
void globalEndRunProduce (edm::Run &iRun, edm::EventSetup const &, CounterMap const *runCounterMap) const override
 
void globalEndRunSummary (edm::Run const &, edm::EventSetup const &, CounterMap *runCounterMap) const override
 
void produce (edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
 
void streamBeginLuminosityBlock (edm::StreamID id, edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &eventSetup) const override
 
void streamBeginRun (edm::StreamID id, edm::Run const &, edm::EventSetup const &) const override
 
void streamEndRunSummary (edm::StreamID id, edm::Run const &, edm::EventSetup const &, CounterMap *runCounterMap) const override
 
 ~GenWeightsTableProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer< edm::StreamCache< LumiCacheInfoHolder >, edm::RunCache< DynamicWeightChoice >, edm::RunSummaryCache< CounterMap >, edm::EndRunProducer >
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Protected Attributes

std::atomic< bool > debug_
 
std::atomic< bool > debugRun_
 
const edm::EDGetTokenT< GenLumiInfoHeadergenLumiInfoHeadTag_
 
const edm::EDGetTokenT< GenEventInfoProductgenTag_
 
std::atomic< bool > hasIssuedWarning_
 
std::unordered_map< std::string, uint32_t > lhaNameToID_
 
const std::vector< edm::InputTaglheLabel_
 
const std::vector< edm::EDGetTokenT< LHERunInfoProduct > > lheRunTag_
 
const std::vector< edm::EDGetTokenT< LHEEventProduct > > lheTag_
 
int lheWeightPrecision_
 
unsigned int maxPdfWeights_
 
std::vector< std::string > namedWeightIDs_
 
std::vector< std::string > namedWeightLabels_
 
std::vector< uint32_t > preferredPDFLHAIDs_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 declare what type of product will make and with which optional label More...
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Definition at line 236 of file GenWeightsTableProducer.cc.

Constructor & Destructor Documentation

◆ GenWeightsTableProducer()

GenWeightsTableProducer::GenWeightsTableProducer ( edm::ParameterSet const &  params)
inline

Definition at line 241 of file GenWeightsTableProducer.cc.

242  : genTag_(consumes<GenEventInfoProduct>(params.getParameter<edm::InputTag>("genEvent"))),
243  lheLabel_(params.getParameter<std::vector<edm::InputTag>>("lheInfo")),
245  [this](const edm::InputTag& tag) { return mayConsume<LHEEventProduct>(tag); })),
247  lheLabel_, [this](const edm::InputTag& tag) { return mayConsume<LHERunInfoProduct, edm::InRun>(tag); })),
249  mayConsume<GenLumiInfoHeader, edm::InLumi>(params.getParameter<edm::InputTag>("genLumiInfoHeader"))),
250  namedWeightIDs_(params.getParameter<std::vector<std::string>>("namedWeightIDs")),
251  namedWeightLabels_(params.getParameter<std::vector<std::string>>("namedWeightLabels")),
252  lheWeightPrecision_(params.getParameter<int32_t>("lheWeightPrecision")),
253  maxPdfWeights_(params.getParameter<uint32_t>("maxPdfWeights")),
254  debug_(params.getUntrackedParameter<bool>("debug", false)),
255  debugRun_(debug_.load()),
256  hasIssuedWarning_(false) {
257  produces<nanoaod::FlatTable>();
258  produces<std::string>("genModel");
259  produces<nanoaod::FlatTable>("LHEScale");
260  produces<nanoaod::FlatTable>("LHEPdf");
261  produces<nanoaod::FlatTable>("LHEReweighting");
262  produces<nanoaod::FlatTable>("LHENamed");
263  produces<nanoaod::FlatTable>("PS");
264  produces<nanoaod::MergeableCounterTable, edm::Transition::EndRun>();
265  if (namedWeightIDs_.size() != namedWeightLabels_.size()) {
266  throw cms::Exception("Configuration", "Size mismatch between namedWeightIDs & namedWeightLabels");
267  }
268  for (const edm::ParameterSet& pdfps : params.getParameter<std::vector<edm::ParameterSet>>("preferredPDFs")) {
269  const std::string& name = pdfps.getParameter<std::string>("name");
270  uint32_t lhaid = pdfps.getParameter<uint32_t>("lhaid");
271  preferredPDFLHAIDs_.push_back(lhaid);
273  lhaNameToID_[name + ".LHgrid"] = lhaid;
274  }
275  }

References GlobalPosition_Frontier_DevDB_cff::tag.

◆ ~GenWeightsTableProducer()

GenWeightsTableProducer::~GenWeightsTableProducer ( )
inlineoverride

Definition at line 277 of file GenWeightsTableProducer.cc.

277 {}

Member Function Documentation

◆ beginStream()

std::unique_ptr<LumiCacheInfoHolder> GenWeightsTableProducer::beginStream ( edm::StreamID  ) const
inlineoverride

Definition at line 858 of file GenWeightsTableProducer.cc.

858  {
859  return std::make_unique<LumiCacheInfoHolder>();
860  }

◆ fillDescriptions()

static void GenWeightsTableProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
inlinestatic

Definition at line 1031 of file GenWeightsTableProducer.cc.

1031  {
1033  desc.add<edm::InputTag>("genEvent", edm::InputTag("generator"))
1034  ->setComment("tag for the GenEventInfoProduct, to get the main weight");
1035  desc.add<edm::InputTag>("genLumiInfoHeader", edm::InputTag("generator"))
1036  ->setComment("tag for the GenLumiInfoProduct, to get the model string");
1037  desc.add<std::vector<edm::InputTag>>("lheInfo", std::vector<edm::InputTag>{{"externalLHEProducer"}, {"source"}})
1038  ->setComment("tag(s) for the LHE information (LHEEventProduct and LHERunInfoProduct)");
1039 
1041  prefpdf.add<std::string>("name");
1042  prefpdf.add<uint32_t>("lhaid");
1043  desc.addVPSet("preferredPDFs", prefpdf, std::vector<edm::ParameterSet>())
1044  ->setComment(
1045  "LHA PDF Ids of the preferred PDF sets, in order of preference (the first matching one will be used)");
1046  desc.add<std::vector<std::string>>("namedWeightIDs")->setComment("set of LHA weight IDs for named LHE weights");
1047  desc.add<std::vector<std::string>>("namedWeightLabels")
1048  ->setComment("output names for the namedWeightIDs (in the same order)");
1049  desc.add<int32_t>("lheWeightPrecision")->setComment("Number of bits in the mantissa for LHE weights");
1050  desc.add<uint32_t>("maxPdfWeights")->setComment("Maximum number of PDF weights to save (to crop NN replicas)");
1051  desc.addOptionalUntracked<bool>("debug")->setComment("dump out all LHE information for one event");
1052  descriptions.add("genWeightsTable", desc);
1053  }

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptionalUntracked(), edm::ParameterSetDescription::addVPSet(), HLT_2018_cff::InputTag, edm::ParameterDescriptionNode::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

◆ fillLHEPdfWeightTablesFromGenInfo()

void GenWeightsTableProducer::fillLHEPdfWeightTablesFromGenInfo ( Counter *  counter,
const DynamicWeightChoiceGenInfo *  weightChoice,
double  genWeight,
const GenEventInfoProduct genProd,
std::unique_ptr< nanoaod::FlatTable > &  outScale,
std::unique_ptr< nanoaod::FlatTable > &  outPdf,
std::unique_ptr< nanoaod::FlatTable > &  outNamed,
std::unique_ptr< nanoaod::FlatTable > &  outPS 
) const
inline

Definition at line 433 of file GenWeightsTableProducer.cc.

440  {
441  const std::vector<unsigned int>& scaleWeightIDs = weightChoice->scaleWeightIDs;
442  const std::vector<unsigned int>& pdfWeightIDs = weightChoice->pdfWeightIDs;
443  const std::vector<unsigned int>& psWeightIDs = weightChoice->psWeightIDs;
444 
445  auto weights = genProd.weights();
446  double w0 = weights.at(1);
447  double originalXWGTUP = weights.at(1);
448  ;
449 
450  std::vector<double> wScale, wPDF, wPS;
451  for (auto id : scaleWeightIDs)
452  wScale.push_back(weights.at(id) / w0);
453  for (auto id : pdfWeightIDs) {
454  wPDF.push_back(weights.at(id) / w0);
455  }
456  if (!psWeightIDs.empty()) {
457  for (auto id : psWeightIDs)
458  wPS.push_back((weights.at(id)) / w0);
459  } else
460  wPS.push_back(1.0);
461 
462  outScale.reset(new nanoaod::FlatTable(wScale.size(), "LHEScaleWeight", false));
463  outScale->addColumn<float>(
464  "", wScale, weightChoice->scaleWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);
465 
466  outPdf.reset(new nanoaod::FlatTable(wPDF.size(), "LHEPdfWeight", false));
467  outPdf->addColumn<float>(
468  "", wPDF, weightChoice->pdfWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);
469 
470  outPS.reset(new nanoaod::FlatTable(wPS.size(), "PSWeight", false));
471  outPS->addColumn<float>("",
472  wPS,
473  wPS.size() > 1 ? "PS weights (w_var / w_nominal); [0] is ISR=0.5 FSR=1; [1] is ISR=1 "
474  "FSR=0.5; [2] is ISR=2 FSR=1; [3] is ISR=1 FSR=2 "
475  : "dummy PS weight (1.0) ",
478 
479  outNamed.reset(new nanoaod::FlatTable(1, "LHEWeight", true));
480  outNamed->addColumnValue<float>(
481  "originalXWGTUP", originalXWGTUP, "Nominal event weight in the LHE file", nanoaod::FlatTable::FloatColumn);
482  /*for (unsigned int i = 0, n = wNamed.size(); i < n; ++i) {
483  outNamed->addColumnValue<float>(namedWeightLabels_[i], wNamed[i], "LHE weight for id "+namedWeightIDs_[i]+", relative to nominal", nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);
484  }*/
485 
486  counter->incLHE(genWeight, wScale, wPDF, std::vector<double>(), std::vector<double>(), wPS);
487  }

References nanoaod::FlatTable::FloatColumn, lheWeightPrecision_, GenEventInfoProduct::weights(), and HLT_2018_cff::weights.

Referenced by produce().

◆ fillLHEWeightTables()

void GenWeightsTableProducer::fillLHEWeightTables ( Counter *  counter,
const DynamicWeightChoice *  weightChoice,
double  genWeight,
const LHEEventProduct lheProd,
const GenEventInfoProduct genProd,
std::unique_ptr< nanoaod::FlatTable > &  outScale,
std::unique_ptr< nanoaod::FlatTable > &  outPdf,
std::unique_ptr< nanoaod::FlatTable > &  outRwgt,
std::unique_ptr< nanoaod::FlatTable > &  outNamed,
std::unique_ptr< nanoaod::FlatTable > &  outPS 
) const
inline

Definition at line 346 of file GenWeightsTableProducer.cc.

355  {
356  bool lheDebug = debug_.exchange(
357  false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind)
358 
359  const std::vector<std::string>& scaleWeightIDs = weightChoice->scaleWeightIDs;
360  const std::vector<std::string>& pdfWeightIDs = weightChoice->pdfWeightIDs;
361  const std::vector<std::string>& rwgtWeightIDs = weightChoice->rwgtIDs;
362 
363  double w0 = lheProd.originalXWGTUP();
364 
365  std::vector<double> wScale(scaleWeightIDs.size(), 1), wPDF(pdfWeightIDs.size(), 1), wRwgt(rwgtWeightIDs.size(), 1),
366  wNamed(namedWeightIDs_.size(), 1);
367  for (auto& weight : lheProd.weights()) {
368  if (lheDebug)
369  printf("Weight %+9.5f rel %+9.5f for id %s\n", weight.wgt, weight.wgt / w0, weight.id.c_str());
370  // now we do it slowly, can be optimized
371  auto mScale = std::find(scaleWeightIDs.begin(), scaleWeightIDs.end(), weight.id);
372  if (mScale != scaleWeightIDs.end())
373  wScale[mScale - scaleWeightIDs.begin()] = weight.wgt / w0;
374 
375  auto mPDF = std::find(pdfWeightIDs.begin(), pdfWeightIDs.end(), weight.id);
376  if (mPDF != pdfWeightIDs.end())
377  wPDF[mPDF - pdfWeightIDs.begin()] = weight.wgt / w0;
378 
379  auto mRwgt = std::find(rwgtWeightIDs.begin(), rwgtWeightIDs.end(), weight.id);
380  if (mRwgt != rwgtWeightIDs.end())
381  wRwgt[mRwgt - rwgtWeightIDs.begin()] = weight.wgt / w0;
382 
383  auto mNamed = std::find(namedWeightIDs_.begin(), namedWeightIDs_.end(), weight.id);
384  if (mNamed != namedWeightIDs_.end())
385  wNamed[mNamed - namedWeightIDs_.begin()] = weight.wgt / w0;
386  }
387 
388  int vectorSize = (genProd.weights().size() == 14 || genProd.weights().size() == 46) ? 4 : 1;
389  std::vector<double> wPS(vectorSize, 1);
390  if (vectorSize > 1) {
391  double nominal = genProd.weights()[1]; // Called 'Baseline' in GenLumiInfoHeader
392  for (unsigned int i = 6; i < 10; i++) {
393  wPS[i - 6] = (genProd.weights()[i]) / nominal;
394  }
395  }
396  outPS.reset(new nanoaod::FlatTable(wPS.size(), "PSWeight", false));
397  outPS->addColumn<float>("",
398  wPS,
399  vectorSize > 1 ? "PS weights (w_var / w_nominal); [0] is ISR=0.5 FSR=1; [1] is ISR=1 "
400  "FSR=0.5; [2] is ISR=2 FSR=1; [3] is ISR=1 FSR=2 "
401  : "dummy PS weight (1.0) ",
404 
405  outScale.reset(new nanoaod::FlatTable(wScale.size(), "LHEScaleWeight", false));
406  outScale->addColumn<float>(
407  "", wScale, weightChoice->scaleWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);
408 
409  outPdf.reset(new nanoaod::FlatTable(wPDF.size(), "LHEPdfWeight", false));
410  outPdf->addColumn<float>(
411  "", wPDF, weightChoice->pdfWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);
412 
413  outRwgt.reset(new nanoaod::FlatTable(wRwgt.size(), "LHEReweightingWeight", false));
414  outRwgt->addColumn<float>(
415  "", wRwgt, weightChoice->rwgtWeightDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);
416 
417  outNamed.reset(new nanoaod::FlatTable(1, "LHEWeight", true));
418  outNamed->addColumnValue<float>("originalXWGTUP",
419  lheProd.originalXWGTUP(),
420  "Nominal event weight in the LHE file",
422  for (unsigned int i = 0, n = wNamed.size(); i < n; ++i) {
423  outNamed->addColumnValue<float>(namedWeightLabels_[i],
424  wNamed[i],
425  "LHE weight for id " + namedWeightIDs_[i] + ", relative to nominal",
428  }
429 
430  counter->incLHE(genWeight, wScale, wPDF, wRwgt, wNamed, wPS);
431  }

References debug_, spr::find(), nanoaod::FlatTable::FloatColumn, mps_fire::i, lheWeightPrecision_, dqmiodumpmetadata::n, namedWeightIDs_, namedWeightLabels_, LHEEventProduct::originalXWGTUP(), GenEventInfoProduct::weights(), and LHEEventProduct::weights().

Referenced by produce().

◆ fillOnlyPSWeightTable()

void GenWeightsTableProducer::fillOnlyPSWeightTable ( Counter *  counter,
double  genWeight,
const GenEventInfoProduct genProd,
std::unique_ptr< nanoaod::FlatTable > &  outPS 
) const
inline

Definition at line 489 of file GenWeightsTableProducer.cc.

492  {
493  int vectorSize = (genProd.weights().size() == 14 || genProd.weights().size() == 46) ? 4 : 1;
494 
495  std::vector<double> wPS(vectorSize, 1);
496  if (vectorSize > 1) {
497  double nominal = genProd.weights()[1]; // Called 'Baseline' in GenLumiInfoHeader
498  for (unsigned int i = 6; i < 10; i++) {
499  wPS[i - 6] = (genProd.weights()[i]) / nominal;
500  }
501  }
502 
503  outPS.reset(new nanoaod::FlatTable(wPS.size(), "PSWeight", false));
504  outPS->addColumn<float>("",
505  wPS,
506  vectorSize > 1 ? "PS weights (w_var / w_nominal); [0] is ISR=0.5 FSR=1; [1] is ISR=1 "
507  "FSR=0.5; [2] is ISR=2 FSR=1; [3] is ISR=1 FSR=2 "
508  : "dummy PS weight (1.0) ",
511 
512  counter->incGenOnly(genWeight);
513  counter->incPSOnly(genWeight, wPS);
514  }

References nanoaod::FlatTable::FloatColumn, mps_fire::i, lheWeightPrecision_, and GenEventInfoProduct::weights().

Referenced by produce().

◆ globalBeginRun()

std::shared_ptr<DynamicWeightChoice> GenWeightsTableProducer::globalBeginRun ( edm::Run const &  iRun,
edm::EventSetup const &   
) const
inlineoverride

Definition at line 517 of file GenWeightsTableProducer.cc.

517  {
519 
520  bool lheDebug = debugRun_.exchange(
521  false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind)
522  auto weightChoice = std::make_shared<DynamicWeightChoice>();
523 
524  // getByToken throws since we're not in the endRun (see https://github.com/cms-sw/cmssw/pull/18499)
525  //if (iRun.getByToken(lheRunTag_, lheInfo)) {
526  for (const auto& lheLabel : lheLabel_) {
527  iRun.getByLabel(lheLabel, lheInfo);
528  if (lheInfo.isValid()) {
529  break;
530  }
531  }
532  if (lheInfo.isValid()) {
533  std::vector<ScaleVarWeight> scaleVariationIDs;
534  std::vector<PDFSetWeights> pdfSetWeightIDs;
535  std::vector<std::string> lheReweighingIDs;
536 
537  std::regex weightgroupmg26x("<weightgroup\\s+(?:name|type)=\"(.*)\"\\s+combine=\"(.*)\"\\s*>");
538  std::regex weightgroup("<weightgroup\\s+combine=\"(.*)\"\\s+(?:name|type)=\"(.*)\"\\s*>");
539  std::regex weightgroupRwgt("<weightgroup\\s+(?:name|type)=\"(.*)\"\\s*>");
540  std::regex endweightgroup("</weightgroup>");
541  std::regex scalewmg26x(
542  "<weight\\s+(?:.*\\s+)?id=\"(\\d+)\"\\s*(?:lhapdf=\\d+|dyn=\\s*-?\\d+)?\\s*((?:[mM][uU][rR]|renscfact)=\"("
543  "\\S+)\"\\s+(?:[mM][uU][Ff]|facscfact)=\"(\\S+)\")(\\s+.*)?</weight>");
544  std::regex scalew(
545  "<weight\\s+(?:.*\\s+)?id=\"(\\d+)\">\\s*(?:lhapdf=\\d+|dyn=\\s*-?\\d+)?\\s*((?:mu[rR]|renscfact)=(\\S+)\\s+("
546  "?:mu[Ff]|facscfact)=(\\S+)(\\s+.*)?)</weight>");
547  std::regex pdfw(
548  "<weight\\s+id=\"(\\d+)\">\\s*(?:PDF set|lhapdf|PDF|pdfset)\\s*=\\s*(\\d+)\\s*(?:\\s.*)?</weight>");
549  std::regex pdfwOld("<weight\\s+(?:.*\\s+)?id=\"(\\d+)\">\\s*Member \\s*(\\d+)\\s*(?:.*)</weight>");
550  std::regex pdfwmg26x(
551  "<weight\\s+id=\"(\\d+)\"\\s*MUR=\"(?:\\S+)\"\\s*MUF=\"(?:\\S+)\"\\s*(?:PDF "
552  "set|lhapdf|PDF|pdfset)\\s*=\\s*\"(\\d+)\"\\s*>\\s*(?:PDF=(\\d+)\\s*MemberID=(\\d+))?\\s*(?:\\s.*)?</"
553  "weight>");
554  std::regex rwgt("<weight\\s+id=\"(.+)\">(.+)?(</weight>)?");
555  std::smatch groups;
556  for (auto iter = lheInfo->headers_begin(), end = lheInfo->headers_end(); iter != end; ++iter) {
557  if (iter->tag() != "initrwgt") {
558  if (lheDebug)
559  std::cout << "Skipping LHE header with tag" << iter->tag() << std::endl;
560  continue;
561  }
562  if (lheDebug)
563  std::cout << "Found LHE header with tag" << iter->tag() << std::endl;
564  std::vector<std::string> lines = iter->lines();
565  bool missed_weightgroup =
566  false; //Needed because in some of the samples ( produced with MG26X ) a small part of the header info is ordered incorrectly
567  bool ismg26x = false;
568  for (unsigned int iLine = 0, nLines = lines.size(); iLine < nLines;
569  ++iLine) { //First start looping through the lines to see which weightgroup pattern is matched
570  boost::replace_all(lines[iLine], "&lt;", "<");
571  boost::replace_all(lines[iLine], "&gt;", ">");
572  if (std::regex_search(lines[iLine], groups, weightgroupmg26x)) {
573  ismg26x = true;
574  }
575  }
576  for (unsigned int iLine = 0, nLines = lines.size(); iLine < nLines; ++iLine) {
577  if (lheDebug)
578  std::cout << lines[iLine];
579  if (std::regex_search(lines[iLine], groups, ismg26x ? weightgroupmg26x : weightgroup)) {
580  std::string groupname = groups.str(2);
581  if (ismg26x)
582  groupname = groups.str(1);
583  if (lheDebug)
584  std::cout << ">>> Looks like the beginning of a weight group for '" << groupname << "'" << std::endl;
585  if (groupname.find("scale_variation") == 0 || groupname == "Central scale variation") {
586  if (lheDebug)
587  std::cout << ">>> Looks like scale variation for theory uncertainties" << std::endl;
588  for (++iLine; iLine < nLines; ++iLine) {
589  if (lheDebug)
590  std::cout << " " << lines[iLine];
591  if (std::regex_search(lines[iLine], groups, ismg26x ? scalewmg26x : scalew)) {
592  if (lheDebug)
593  std::cout << " >>> Scale weight " << groups[1].str() << " for " << groups[3].str() << " , "
594  << groups[4].str() << " , " << groups[5].str() << std::endl;
595  scaleVariationIDs.emplace_back(groups.str(1), groups.str(2), groups.str(3), groups.str(4));
596  } else if (std::regex_search(lines[iLine], endweightgroup)) {
597  if (lheDebug)
598  std::cout << ">>> Looks like the end of a weight group" << std::endl;
599  if (!missed_weightgroup) {
600  break;
601  } else
602  missed_weightgroup = false;
603  } else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
604  if (lheDebug)
605  std::cout << ">>> Looks like the beginning of a new weight group, I will assume I missed the end "
606  "of the group."
607  << std::endl;
608  if (ismg26x)
609  missed_weightgroup = true;
610  --iLine; // rewind by one, and go back to the outer loop
611  break;
612  }
613  }
614  } else if (groupname == "PDF_variation" || groupname.find("PDF_variation ") == 0) {
615  if (lheDebug)
616  std::cout << ">>> Looks like a new-style block of PDF weights for one or more pdfs" << std::endl;
617  for (++iLine; iLine < nLines; ++iLine) {
618  if (lheDebug)
619  std::cout << " " << lines[iLine];
620  if (std::regex_search(lines[iLine], groups, pdfw)) {
621  unsigned int lhaID = std::stoi(groups.str(2));
622  if (lheDebug)
623  std::cout << " >>> PDF weight " << groups.str(1) << " for " << groups.str(2) << " = " << lhaID
624  << std::endl;
625  if (pdfSetWeightIDs.empty() || !pdfSetWeightIDs.back().maybe_add(groups.str(1), lhaID)) {
626  pdfSetWeightIDs.emplace_back(groups.str(1), lhaID);
627  }
628  } else if (std::regex_search(lines[iLine], endweightgroup)) {
629  if (lheDebug)
630  std::cout << ">>> Looks like the end of a weight group" << std::endl;
631  if (!missed_weightgroup) {
632  break;
633  } else
634  missed_weightgroup = false;
635  } else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
636  if (lheDebug)
637  std::cout << ">>> Looks like the beginning of a new weight group, I will assume I missed the end "
638  "of the group."
639  << std::endl;
640  if (ismg26x)
641  missed_weightgroup = true;
642  --iLine; // rewind by one, and go back to the outer loop
643  break;
644  }
645  }
646  } else if (groupname == "PDF_variation1" || groupname == "PDF_variation2") {
647  if (lheDebug)
648  std::cout << ">>> Looks like a new-style block of PDF weights for multiple pdfs" << std::endl;
649  unsigned int lastid = 0;
650  for (++iLine; iLine < nLines; ++iLine) {
651  if (lheDebug)
652  std::cout << " " << lines[iLine];
653  if (std::regex_search(lines[iLine], groups, pdfw)) {
654  unsigned int id = std::stoi(groups.str(1));
655  unsigned int lhaID = std::stoi(groups.str(2));
656  if (lheDebug)
657  std::cout << " >>> PDF weight " << groups.str(1) << " for " << groups.str(2) << " = " << lhaID
658  << std::endl;
659  if (id != (lastid + 1) || pdfSetWeightIDs.empty()) {
660  pdfSetWeightIDs.emplace_back(groups.str(1), lhaID);
661  } else {
662  pdfSetWeightIDs.back().add(groups.str(1), lhaID);
663  }
664  lastid = id;
665  } else if (std::regex_search(lines[iLine], endweightgroup)) {
666  if (lheDebug)
667  std::cout << ">>> Looks like the end of a weight group" << std::endl;
668  if (!missed_weightgroup) {
669  break;
670  } else
671  missed_weightgroup = false;
672  } else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
673  if (lheDebug)
674  std::cout << ">>> Looks like the beginning of a new weight group, I will assume I missed the end "
675  "of the group."
676  << std::endl;
677  if (ismg26x)
678  missed_weightgroup = true;
679  --iLine; // rewind by one, and go back to the outer loop
680  break;
681  }
682  }
683  } else if (lhaNameToID_.find(groupname) != lhaNameToID_.end()) {
684  if (lheDebug)
685  std::cout << ">>> Looks like an old-style PDF weight for an individual pdf" << std::endl;
686  unsigned int firstLhaID = lhaNameToID_.find(groupname)->second;
687  bool first = true;
688  for (++iLine; iLine < nLines; ++iLine) {
689  if (lheDebug)
690  std::cout << " " << lines[iLine];
691  if (std::regex_search(lines[iLine], groups, ismg26x ? pdfwmg26x : pdfwOld)) {
692  unsigned int member = 0;
693  if (ismg26x == 0) {
694  member = std::stoi(groups.str(2));
695  } else {
696  if (!groups.str(4).empty()) {
697  member = std::stoi(groups.str(4));
698  }
699  }
700  unsigned int lhaID = member + firstLhaID;
701  if (lheDebug)
702  std::cout << " >>> PDF weight " << groups.str(1) << " for " << member << " = " << lhaID
703  << std::endl;
704  //if (member == 0) continue; // let's keep also the central value for now
705  if (first) {
706  pdfSetWeightIDs.emplace_back(groups.str(1), lhaID);
707  first = false;
708  } else {
709  pdfSetWeightIDs.back().add(groups.str(1), lhaID);
710  }
711  } else if (std::regex_search(lines[iLine], endweightgroup)) {
712  if (lheDebug)
713  std::cout << ">>> Looks like the end of a weight group" << std::endl;
714  if (!missed_weightgroup) {
715  break;
716  } else
717  missed_weightgroup = false;
718  } else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
719  if (lheDebug)
720  std::cout << ">>> Looks like the beginning of a new weight group, I will assume I missed the end "
721  "of the group."
722  << std::endl;
723  if (ismg26x)
724  missed_weightgroup = true;
725  --iLine; // rewind by one, and go back to the outer loop
726  break;
727  }
728  }
729  } else {
730  for (++iLine; iLine < nLines; ++iLine) {
731  if (lheDebug)
732  std::cout << " " << lines[iLine];
733  if (std::regex_search(lines[iLine], groups, endweightgroup)) {
734  if (lheDebug)
735  std::cout << ">>> Looks like the end of a weight group" << std::endl;
736  if (!missed_weightgroup) {
737  break;
738  } else
739  missed_weightgroup = false;
740  } else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
741  if (lheDebug)
742  std::cout << ">>> Looks like the beginning of a new weight group, I will assume I missed the end "
743  "of the group."
744  << std::endl;
745  if (ismg26x)
746  missed_weightgroup = true;
747  --iLine; // rewind by one, and go back to the outer loop
748  break;
749  }
750  }
751  }
752  } else if (std::regex_search(lines[iLine], groups, weightgroupRwgt)) {
753  std::string groupname = groups.str(1);
754  if (groupname == "mg_reweighting") {
755  if (lheDebug)
756  std::cout << ">>> Looks like a LHE weights for reweighting" << std::endl;
757  for (++iLine; iLine < nLines; ++iLine) {
758  if (lheDebug)
759  std::cout << " " << lines[iLine];
760  if (std::regex_search(lines[iLine], groups, rwgt)) {
761  std::string rwgtID = groups.str(1);
762  if (lheDebug)
763  std::cout << " >>> LHE reweighting weight: " << rwgtID << std::endl;
764  if (std::find(lheReweighingIDs.begin(), lheReweighingIDs.end(), rwgtID) == lheReweighingIDs.end()) {
765  // we're only interested in the beggining of the block
766  lheReweighingIDs.emplace_back(rwgtID);
767  }
768  } else if (std::regex_search(lines[iLine], endweightgroup)) {
769  if (lheDebug)
770  std::cout << ">>> Looks like the end of a weight group" << std::endl;
771  if (!missed_weightgroup) {
772  break;
773  } else
774  missed_weightgroup = false;
775  } else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
776  if (lheDebug)
777  std::cout << ">>> Looks like the beginning of a new weight group, I will assume I missed the end "
778  "of the group."
779  << std::endl;
780  if (ismg26x)
781  missed_weightgroup = true;
782  --iLine; // rewind by one, and go back to the outer loop
783  break;
784  }
785  }
786  }
787  }
788  }
789  //std::cout << "============= END [ " << iter->tag() << " ] ============ \n\n" << std::endl;
790 
791  // ----- SCALE VARIATIONS -----
792  std::sort(scaleVariationIDs.begin(), scaleVariationIDs.end());
793  if (lheDebug)
794  std::cout << "Found " << scaleVariationIDs.size() << " scale variations: " << std::endl;
795  std::stringstream scaleDoc;
796  scaleDoc << "LHE scale variation weights (w_var / w_nominal); ";
797  for (unsigned int isw = 0, nsw = scaleVariationIDs.size(); isw < nsw; ++isw) {
798  const auto& sw = scaleVariationIDs[isw];
799  if (isw)
800  scaleDoc << "; ";
801  scaleDoc << "[" << isw << "] is " << sw.label;
802  weightChoice->scaleWeightIDs.push_back(sw.wid);
803  if (lheDebug)
804  printf(" id %s: scales ren = % .2f fact = % .2f text = %s\n",
805  sw.wid.c_str(),
806  sw.scales.first,
807  sw.scales.second,
808  sw.label.c_str());
809  }
810  if (!scaleVariationIDs.empty())
811  weightChoice->scaleWeightsDoc = scaleDoc.str();
812 
813  // ------ PDF VARIATIONS (take the preferred one) -----
814  if (lheDebug) {
815  std::cout << "Found " << pdfSetWeightIDs.size() << " PDF set errors: " << std::endl;
816  for (const auto& pw : pdfSetWeightIDs)
817  printf("lhaIDs %6d - %6d (%3lu weights: %s, ... )\n",
818  pw.lhaIDs.first,
819  pw.lhaIDs.second,
820  pw.wids.size(),
821  pw.wids.front().c_str());
822  }
823 
824  // ------ LHE REWEIGHTING -------
825  if (lheDebug) {
826  std::cout << "Found " << lheReweighingIDs.size() << " reweighting weights" << std::endl;
827  }
828  std::copy(lheReweighingIDs.begin(), lheReweighingIDs.end(), std::back_inserter(weightChoice->rwgtIDs));
829 
830  std::stringstream pdfDoc;
831  pdfDoc << "LHE pdf variation weights (w_var / w_nominal) for LHA IDs ";
832  bool found = false;
833  for (uint32_t lhaid : preferredPDFLHAIDs_) {
834  for (const auto& pw : pdfSetWeightIDs) {
835  if (pw.lhaIDs.first != lhaid && pw.lhaIDs.first != (lhaid + 1))
836  continue; // sometimes the first weight is not saved if that PDF is the nominal one for the sample
837  if (pw.wids.size() == 1)
838  continue; // only consider error sets
839  pdfDoc << pw.lhaIDs.first << " - " << pw.lhaIDs.second;
840  weightChoice->pdfWeightIDs = pw.wids;
841  if (maxPdfWeights_ < pw.wids.size()) {
842  weightChoice->pdfWeightIDs.resize(maxPdfWeights_); // drop some replicas
843  pdfDoc << ", truncated to the first " << maxPdfWeights_ << " replicas";
844  }
845  weightChoice->pdfWeightsDoc = pdfDoc.str();
846  found = true;
847  break;
848  }
849  if (found)
850  break;
851  }
852  }
853  }
854  return weightChoice;
855  }

References filterCSVwithJSON::copy, gather_cfg::cout, debugRun_, end, spr::find(), dqmdumpme::first, newFWLiteAna::found, edm::Run::getByLabel(), triggerObjects_cff::id, nano_cff::lhaid, lhaNameToID_, nano_cff::lheInfo, lheLabel_, groupFilesInBlocks::lines, maxPdfWeights_, submitDQMOfflineCAF::nLines, preferredPDFLHAIDs_, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ globalBeginRunSummary()

std::shared_ptr<CounterMap> GenWeightsTableProducer::globalBeginRunSummary ( edm::Run const &  ,
edm::EventSetup const &   
) const
inlineoverride

Definition at line 967 of file GenWeightsTableProducer.cc.

967  {
968  return std::make_shared<CounterMap>();
969  }

◆ globalEndRun()

void GenWeightsTableProducer::globalEndRun ( edm::Run const &  ,
edm::EventSetup const &   
) const
inlineoverride

Definition at line 1029 of file GenWeightsTableProducer.cc.

1029 {}

◆ globalEndRunProduce()

void GenWeightsTableProducer::globalEndRunProduce ( edm::Run iRun,
edm::EventSetup const &  ,
CounterMap const *  runCounterMap 
) const
inlineoverride

Definition at line 980 of file GenWeightsTableProducer.cc.

980  {
981  auto out = std::make_unique<nanoaod::MergeableCounterTable>();
982 
983  for (auto x : runCounterMap->countermap) {
984  auto runCounter = &(x.second);
985  std::string label = (!x.first.empty()) ? (std::string("_") + x.first) : "";
986  std::string doclabel = (!x.first.empty()) ? (std::string(", for model label ") + x.first) : "";
987 
988  out->addInt("genEventCount" + label, "event count" + doclabel, runCounter->num);
989  out->addFloat("genEventSumw" + label, "sum of gen weights" + doclabel, runCounter->sumw);
990  out->addFloat("genEventSumw2" + label, "sum of gen (weight^2)" + doclabel, runCounter->sumw2);
991 
992  double norm = runCounter->sumw ? 1.0 / runCounter->sumw : 1;
993  auto sumScales = runCounter->sumScale;
994  for (auto& val : sumScales)
995  val *= norm;
996  out->addVFloatWithNorm("LHEScaleSumw" + label,
997  "Sum of genEventWeight * LHEScaleWeight[i], divided by genEventSumw" + doclabel,
998  sumScales,
999  runCounter->sumw);
1000  auto sumPDFs = runCounter->sumPDF;
1001  for (auto& val : sumPDFs)
1002  val *= norm;
1003  out->addVFloatWithNorm("LHEPdfSumw" + label,
1004  "Sum of genEventWeight * LHEPdfWeight[i], divided by genEventSumw" + doclabel,
1005  sumPDFs,
1006  runCounter->sumw);
1007  if (!runCounter->sumRwgt.empty()) {
1008  auto sumRwgts = runCounter->sumRwgt;
1009  for (auto& val : sumRwgts)
1010  val *= norm;
1011  out->addVFloatWithNorm("LHEReweightingSumw" + label,
1012  "Sum of genEventWeight * LHEReweightingWeight[i], divided by genEventSumw" + doclabel,
1013  sumRwgts,
1014  runCounter->sumw);
1015  }
1016  if (!runCounter->sumNamed.empty()) { // it could be empty if there's no LHE info in the sample
1017  for (unsigned int i = 0, n = namedWeightLabels_.size(); i < n; ++i) {
1018  out->addFloatWithNorm(
1019  "LHESumw_" + namedWeightLabels_[i] + label,
1020  "Sum of genEventWeight * LHEWeight_" + namedWeightLabels_[i] + ", divided by genEventSumw" + doclabel,
1021  runCounter->sumNamed[i] * norm,
1022  runCounter->sumw);
1023  }
1024  }
1025  }
1026  iRun.put(std::move(out));
1027  }

References mps_fire::i, label, eostools::move(), dqmiodumpmetadata::n, namedWeightLabels_, MillePedeFileConverter_cfg::out, edm::Run::put(), AlCaHLTBitMon_QueryRunRegistry::string, heppy_batch::val, and x.

◆ globalEndRunSummary()

void GenWeightsTableProducer::globalEndRunSummary ( edm::Run const &  ,
edm::EventSetup const &  ,
CounterMap *  runCounterMap 
) const
inlineoverride

Definition at line 978 of file GenWeightsTableProducer.cc.

978 {}

◆ produce()

void GenWeightsTableProducer::produce ( edm::StreamID  id,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
inlineoverridevirtual

Implements edm::global::EDProducerBase.

Definition at line 279 of file GenWeightsTableProducer.cc.

279  {
280  // get my counter for weights
281  Counter* counter = streamCache(id)->countermap.get();
282 
283  // generator information (always available)
285  iEvent.getByToken(genTag_, genInfo);
286  double weight = genInfo->weight();
287 
288  // table for gen info, always available
289  auto out = std::make_unique<nanoaod::FlatTable>(1, "genWeight", true);
290  out->setDoc("generator weight");
291  out->addColumnValue<float>("", weight, "generator weight", nanoaod::FlatTable::FloatColumn);
292  iEvent.put(std::move(out));
293 
294  std::string model_label = streamCache(id)->countermap.getLabel();
295  auto outM = std::make_unique<std::string>((!model_label.empty()) ? std::string("GenModel_") + model_label : "");
296  iEvent.put(std::move(outM), "genModel");
297  bool getLHEweightsFromGenInfo = !model_label.empty();
298 
299  // tables for LHE weights, may not be filled
300  std::unique_ptr<nanoaod::FlatTable> lheScaleTab, lhePdfTab, lheRwgtTab, lheNamedTab;
301  std::unique_ptr<nanoaod::FlatTable> genPSTab;
302 
304  for (const auto& lheTag : lheTag_) {
305  iEvent.getByToken(lheTag, lheInfo);
306  if (lheInfo.isValid()) {
307  break;
308  }
309  }
310  if (lheInfo.isValid()) {
311  if (getLHEweightsFromGenInfo)
312  edm::LogWarning("LHETablesProducer")
313  << "Found both a LHEEventProduct and a GenLumiInfoHeader: will only save weights from LHEEventProduct.\n";
314  // get the dynamic choice of weights
315  const DynamicWeightChoice* weightChoice = runCache(iEvent.getRun().index());
316  // go fill tables
318  counter, weightChoice, weight, *lheInfo, *genInfo, lheScaleTab, lhePdfTab, lheRwgtTab, lheNamedTab, genPSTab);
319  } else if (getLHEweightsFromGenInfo) {
320  const DynamicWeightChoiceGenInfo* weightChoice = &(streamCache(id)->weightChoice);
322  counter, weightChoice, weight, *genInfo, lheScaleTab, lhePdfTab, lheNamedTab, genPSTab);
323  lheRwgtTab.reset(new nanoaod::FlatTable(1, "LHEReweightingWeights", true));
324  //lheNamedTab.reset(new nanoaod::FlatTable(1, "LHENamedWeights", true));
325  //genPSTab.reset(new nanoaod::FlatTable(1, "PSWeight", true));
326  } else {
327  // Still try to add the PS weights
328  fillOnlyPSWeightTable(counter, weight, *genInfo, genPSTab);
329  // make dummy values
330  lheScaleTab.reset(new nanoaod::FlatTable(1, "LHEScaleWeights", true));
331  lhePdfTab.reset(new nanoaod::FlatTable(1, "LHEPdfWeights", true));
332  lheRwgtTab.reset(new nanoaod::FlatTable(1, "LHEReweightingWeights", true));
333  lheNamedTab.reset(new nanoaod::FlatTable(1, "LHENamedWeights", true));
334  if (!hasIssuedWarning_.exchange(true)) {
335  edm::LogWarning("LHETablesProducer") << "No LHEEventProduct, so there will be no LHE Tables\n";
336  }
337  }
338 
339  iEvent.put(std::move(lheScaleTab), "LHEScale");
340  iEvent.put(std::move(lhePdfTab), "LHEPdf");
341  iEvent.put(std::move(lheRwgtTab), "LHEReweighting");
342  iEvent.put(std::move(lheNamedTab), "LHENamed");
343  iEvent.put(std::move(genPSTab), "PS");
344  }

References fillLHEPdfWeightTablesFromGenInfo(), fillLHEWeightTables(), fillOnlyPSWeightTable(), nanoaod::FlatTable::FloatColumn, genTag_, hasIssuedWarning_, iEvent, nano_cff::lheInfo, lheTag_, eostools::move(), MillePedeFileConverter_cfg::out, AlCaHLTBitMon_QueryRunRegistry::string, GenEventInfoProduct::weight(), and mps_merge::weight.

◆ streamBeginLuminosityBlock()

void GenWeightsTableProducer::streamBeginLuminosityBlock ( edm::StreamID  id,
edm::LuminosityBlock const &  lumiBlock,
edm::EventSetup const &  eventSetup 
) const
inlineoverride

Definition at line 865 of file GenWeightsTableProducer.cc.

867  {
868  auto counterMap = &(streamCache(id)->countermap);
869  edm::Handle<GenLumiInfoHeader> genLumiInfoHead;
870  lumiBlock.getByToken(genLumiInfoHeadTag_, genLumiInfoHead);
871  if (!genLumiInfoHead.isValid())
872  edm::LogWarning("LHETablesProducer")
873  << "No GenLumiInfoHeader product found, will not fill generator model string.\n";
875  if (genLumiInfoHead.isValid()) {
876  label = genLumiInfoHead->configDescription();
877  boost::replace_all(label, "-", "_");
878  boost::replace_all(label, "/", "_");
879  }
880  counterMap->setLabel(label);
881 
882  if (genLumiInfoHead.isValid()) {
883  auto weightChoice = &(streamCache(id)->weightChoice);
884 
885  std::vector<ScaleVarWeight> scaleVariationIDs;
886  std::vector<PDFSetWeights> pdfSetWeightIDs;
887  weightChoice->psWeightIDs.clear();
888 
889  std::regex scalew("LHE,\\s+id\\s+=\\s+(\\d+),\\s+(.+)\\,\\s+mur=(\\S+)\\smuf=(\\S+)");
890  std::regex pdfw("LHE,\\s+id\\s+=\\s+(\\d+),\\s+(.+),\\s+Member\\s+(\\d+)\\s+of\\ssets\\s+(\\w+\\b)");
891  std::smatch groups;
892  auto weightNames = genLumiInfoHead->weightNames();
893  std::unordered_map<std::string, uint32_t> knownPDFSetsFromGenInfo_;
894  unsigned int weightIter = 0;
895  for (auto line : weightNames) {
896  if (std::regex_search(line, groups, scalew)) { // scale variation
897  auto id = groups.str(1);
898  auto group = groups.str(2);
899  auto mur = groups.str(3);
900  auto muf = groups.str(4);
901  if (group.find("Central scale variation") != std::string::npos)
902  scaleVariationIDs.emplace_back(groups.str(1), groups.str(2), groups.str(3), groups.str(4));
903  } else if (std::regex_search(line, groups, pdfw)) { // PDF variation
904  auto id = groups.str(1);
905  auto group = groups.str(2);
906  auto memberid = groups.str(3);
907  auto pdfset = groups.str(4);
908  if (group.find(pdfset) != std::string::npos) {
909  if (knownPDFSetsFromGenInfo_.find(pdfset) == knownPDFSetsFromGenInfo_.end()) {
910  knownPDFSetsFromGenInfo_[pdfset] = std::atoi(id.c_str());
911  pdfSetWeightIDs.emplace_back(id, std::atoi(id.c_str()));
912  } else
913  pdfSetWeightIDs.back().add(id, std::atoi(id.c_str()));
914  }
915  } else if (line.find("isrDef") != std::string::npos ||
916  line.find("fsrDef") != std::string::npos) { // PS variation
917  weightChoice->psWeightIDs.push_back(weightIter);
918  }
919  weightIter++;
920  }
921 
922  weightChoice->scaleWeightIDs.clear();
923  weightChoice->pdfWeightIDs.clear();
924 
925  std::sort(scaleVariationIDs.begin(), scaleVariationIDs.end());
926  std::stringstream scaleDoc;
927  scaleDoc << "LHE scale variation weights (w_var / w_nominal); ";
928  for (unsigned int isw = 0, nsw = scaleVariationIDs.size(); isw < nsw; ++isw) {
929  const auto& sw = scaleVariationIDs[isw];
930  if (isw)
931  scaleDoc << "; ";
932  scaleDoc << "[" << isw << "] is " << sw.label;
933  weightChoice->scaleWeightIDs.push_back(std::atoi(sw.wid.c_str()));
934  }
935  if (!scaleVariationIDs.empty())
936  weightChoice->scaleWeightsDoc = scaleDoc.str();
937  std::stringstream pdfDoc;
938  pdfDoc << "LHE pdf variation weights (w_var / w_nominal) for LHA names ";
939  bool found = false;
940  for (const auto& pw : pdfSetWeightIDs) {
941  if (pw.wids.size() == 1)
942  continue; // only consider error sets
943  for (auto wantedpdf : lhaNameToID_) {
944  auto pdfname = wantedpdf.first;
945  if (knownPDFSetsFromGenInfo_.find(pdfname) == knownPDFSetsFromGenInfo_.end())
946  continue;
947  uint32_t lhaid = knownPDFSetsFromGenInfo_.at(pdfname);
948  if (pw.lhaIDs.first != lhaid)
949  continue;
950  pdfDoc << pdfname;
951  for (auto x : pw.wids)
952  weightChoice->pdfWeightIDs.push_back(std::atoi(x.c_str()));
953  if (maxPdfWeights_ < pw.wids.size()) {
954  weightChoice->pdfWeightIDs.resize(maxPdfWeights_); // drop some replicas
955  pdfDoc << ", truncated to the first " << maxPdfWeights_ << " replicas";
956  }
957  weightChoice->pdfWeightsDoc = pdfDoc.str();
958  found = true;
959  break;
960  }
961  if (found)
962  break;
963  }
964  }
965  }

References GenLumiInfoHeader::configDescription(), newFWLiteAna::found, genLumiInfoHeadTag_, edm::LuminosityBlock::getByToken(), watchdog::group, edm::HandleBase::isValid(), label, nano_cff::lhaid, lhaNameToID_, mps_splice::line, maxPdfWeights_, AlCaHLTBitMon_QueryRunRegistry::string, GenLumiInfoHeader::weightNames(), and x.

◆ streamBeginRun()

void GenWeightsTableProducer::streamBeginRun ( edm::StreamID  id,
edm::Run const &  ,
edm::EventSetup const &   
) const
inlineoverride

Definition at line 862 of file GenWeightsTableProducer.cc.

862  {
863  streamCache(id)->clear();
864  }

◆ streamEndRunSummary()

void GenWeightsTableProducer::streamEndRunSummary ( edm::StreamID  id,
edm::Run const &  ,
edm::EventSetup const &  ,
CounterMap *  runCounterMap 
) const
inlineoverride

Definition at line 971 of file GenWeightsTableProducer.cc.

974  {
975  runCounterMap->merge(streamCache(id)->countermap);
976  }

Member Data Documentation

◆ debug_

std::atomic<bool> GenWeightsTableProducer::debug_
mutableprotected

Definition at line 1069 of file GenWeightsTableProducer.cc.

Referenced by fillLHEWeightTables().

◆ debugRun_

std::atomic<bool> GenWeightsTableProducer::debugRun_
mutableprotected

Definition at line 1069 of file GenWeightsTableProducer.cc.

Referenced by globalBeginRun().

◆ genLumiInfoHeadTag_

const edm::EDGetTokenT<GenLumiInfoHeader> GenWeightsTableProducer::genLumiInfoHeadTag_
protected

Definition at line 1060 of file GenWeightsTableProducer.cc.

Referenced by streamBeginLuminosityBlock().

◆ genTag_

const edm::EDGetTokenT<GenEventInfoProduct> GenWeightsTableProducer::genTag_
protected

Definition at line 1056 of file GenWeightsTableProducer.cc.

Referenced by produce().

◆ hasIssuedWarning_

std::atomic<bool> GenWeightsTableProducer::hasIssuedWarning_
mutableprotected

Definition at line 1069 of file GenWeightsTableProducer.cc.

Referenced by produce().

◆ lhaNameToID_

std::unordered_map<std::string, uint32_t> GenWeightsTableProducer::lhaNameToID_
protected

Definition at line 1063 of file GenWeightsTableProducer.cc.

Referenced by globalBeginRun(), and streamBeginLuminosityBlock().

◆ lheLabel_

const std::vector<edm::InputTag> GenWeightsTableProducer::lheLabel_
protected

Definition at line 1057 of file GenWeightsTableProducer.cc.

Referenced by globalBeginRun().

◆ lheRunTag_

const std::vector<edm::EDGetTokenT<LHERunInfoProduct> > GenWeightsTableProducer::lheRunTag_
protected

Definition at line 1059 of file GenWeightsTableProducer.cc.

◆ lheTag_

const std::vector<edm::EDGetTokenT<LHEEventProduct> > GenWeightsTableProducer::lheTag_
protected

Definition at line 1058 of file GenWeightsTableProducer.cc.

Referenced by produce().

◆ lheWeightPrecision_

int GenWeightsTableProducer::lheWeightPrecision_
protected

◆ maxPdfWeights_

unsigned int GenWeightsTableProducer::maxPdfWeights_
protected

Definition at line 1067 of file GenWeightsTableProducer.cc.

Referenced by globalBeginRun(), and streamBeginLuminosityBlock().

◆ namedWeightIDs_

std::vector<std::string> GenWeightsTableProducer::namedWeightIDs_
protected

Definition at line 1064 of file GenWeightsTableProducer.cc.

Referenced by fillLHEWeightTables().

◆ namedWeightLabels_

std::vector<std::string> GenWeightsTableProducer::namedWeightLabels_
protected

Definition at line 1065 of file GenWeightsTableProducer.cc.

Referenced by fillLHEWeightTables(), and globalEndRunProduce().

◆ preferredPDFLHAIDs_

std::vector<uint32_t> GenWeightsTableProducer::preferredPDFLHAIDs_
protected

Definition at line 1062 of file GenWeightsTableProducer.cc.

Referenced by globalBeginRun().

nanoaod::FlatTable::FloatColumn
Definition: FlatTable.h:39
counter
Definition: counter.py:1
HLT_2018_cff.weights
weights
Definition: HLT_2018_cff.py:87167
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
GenWeightsTableProducer::genLumiInfoHeadTag_
const edm::EDGetTokenT< GenLumiInfoHeader > genLumiInfoHeadTag_
Definition: GenWeightsTableProducer.cc:1060
align::Counter
std::function< unsigned int(align::ID)> Counter
Definition: AlignableIndexer.h:31
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
GenWeightsTableProducer::genTag_
const edm::EDGetTokenT< GenEventInfoProduct > genTag_
Definition: GenWeightsTableProducer.cc:1056
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
LHEEventProduct::originalXWGTUP
double originalXWGTUP() const
Definition: LHEEventProduct.h:34
mps_merge.weight
weight
Definition: mps_merge.py:88
GenWeightsTableProducer::lhaNameToID_
std::unordered_map< std::string, uint32_t > lhaNameToID_
Definition: GenWeightsTableProducer.cc:1063
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
GenWeightsTableProducer::hasIssuedWarning_
std::atomic< bool > hasIssuedWarning_
Definition: GenWeightsTableProducer.cc:1069
DDAxes::x
GenWeightsTableProducer::lheLabel_
const std::vector< edm::InputTag > lheLabel_
Definition: GenWeightsTableProducer.cc:1057
GenWeightsTableProducer::fillOnlyPSWeightTable
void fillOnlyPSWeightTable(Counter *counter, double genWeight, const GenEventInfoProduct &genProd, std::unique_ptr< nanoaod::FlatTable > &outPS) const
Definition: GenWeightsTableProducer.cc:489
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
GenWeightsTableProducer::debug_
std::atomic< bool > debug_
Definition: GenWeightsTableProducer.cc:1069
submitDQMOfflineCAF.nLines
nLines
Definition: submitDQMOfflineCAF.py:676
dqmdumpme.first
first
Definition: dqmdumpme.py:55
edm::ParameterSetDescription::addOptionalUntracked
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:110
end
#define end
Definition: vmac.h:39
GenLumiInfoHeader::weightNames
const std::vector< std::string > & weightNames() const
Definition: GenLumiInfoHeader.h:25
GenLumiInfoHeader::configDescription
const std::string & configDescription() const
Definition: GenLumiInfoHeader.h:19
edm::Run::put
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:108
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
GenWeightsTableProducer::fillLHEWeightTables
void fillLHEWeightTables(Counter *counter, const DynamicWeightChoice *weightChoice, double genWeight, const LHEEventProduct &lheProd, const GenEventInfoProduct &genProd, std::unique_ptr< nanoaod::FlatTable > &outScale, std::unique_ptr< nanoaod::FlatTable > &outPdf, std::unique_ptr< nanoaod::FlatTable > &outRwgt, std::unique_ptr< nanoaod::FlatTable > &outNamed, std::unique_ptr< nanoaod::FlatTable > &outPS) const
Definition: GenWeightsTableProducer.cc:346
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::vector_transform
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
edm::LogWarning
Definition: MessageLogger.h:141
GenWeightsTableProducer::fillLHEPdfWeightTablesFromGenInfo
void fillLHEPdfWeightTablesFromGenInfo(Counter *counter, const DynamicWeightChoiceGenInfo *weightChoice, double genWeight, const GenEventInfoProduct &genProd, std::unique_ptr< nanoaod::FlatTable > &outScale, std::unique_ptr< nanoaod::FlatTable > &outPdf, std::unique_ptr< nanoaod::FlatTable > &outNamed, std::unique_ptr< nanoaod::FlatTable > &outPS) const
Definition: GenWeightsTableProducer.cc:433
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
groupFilesInBlocks.lines
lines
Definition: groupFilesInBlocks.py:95
edm::ParameterSetDescription::addVPSet
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
Definition: ParameterSetDescription.h:149
nano_cff.lheInfo
lheInfo
Definition: nano_cff.py:99
nano_cff.lhaid
lhaid
Definition: nano_cff.py:101
LHEEventProduct::weights
const std::vector< WGT > & weights() const
Definition: LHEEventProduct.h:35
GenWeightsTableProducer::namedWeightLabels_
std::vector< std::string > namedWeightLabels_
Definition: GenWeightsTableProducer.cc:1065
iEvent
int iEvent
Definition: GenABIO.cc:224
GenWeightsTableProducer::debugRun_
std::atomic< bool > debugRun_
Definition: GenWeightsTableProducer.cc:1069
GenWeightsTableProducer::preferredPDFLHAIDs_
std::vector< uint32_t > preferredPDFLHAIDs_
Definition: GenWeightsTableProducer.cc:1062
GenWeightsTableProducer::lheTag_
const std::vector< edm::EDGetTokenT< LHEEventProduct > > lheTag_
Definition: GenWeightsTableProducer.cc:1058
nanoaod::FlatTable
Definition: FlatTable.h:36
GenWeightsTableProducer::lheWeightPrecision_
int lheWeightPrecision_
Definition: GenWeightsTableProducer.cc:1066
heppy_batch.val
val
Definition: heppy_batch.py:351
eostools.move
def move(src, dest)
Definition: eostools.py:511
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
Exception
Definition: hltDiff.cc:246
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
GenWeightsTableProducer::lheRunTag_
const std::vector< edm::EDGetTokenT< LHERunInfoProduct > > lheRunTag_
Definition: GenWeightsTableProducer.cc:1059
GenWeightsTableProducer::maxPdfWeights_
unsigned int maxPdfWeights_
Definition: GenWeightsTableProducer.cc:1067
edm::ParameterDescriptionNode::setComment
void setComment(std::string const &value)
Definition: ParameterDescriptionNode.cc:106
GenEventInfoProduct::weights
std::vector< double > & weights()
Definition: GenEventInfoProduct.h:32
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
mps_splice.line
line
Definition: mps_splice.py:76
edm::InputTag
Definition: InputTag.h:15
GenWeightsTableProducer::namedWeightIDs_
std::vector< std::string > namedWeightIDs_
Definition: GenWeightsTableProducer.cc:1064
label
const char * label
Definition: PFTauDecayModeTools.cc:11
weight
Definition: weight.py:1
GenEventInfoProduct::weight
double weight() const
Definition: GenEventInfoProduct.h:35
watchdog.group
group
Definition: watchdog.py:82