CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PdfWeightProducer Class Reference
Inheritance diagram for PdfWeightProducer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PdfWeightProducer (const edm::ParameterSet &)
 
 ~PdfWeightProducer () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () 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
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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)
 

Private Member Functions

void beginJob () override
 
void endJob () override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::string fixPOWHEG_
 
edm::InputTag genTag_
 
edm::EDGetTokenT< reco::GenParticleCollectiongenToken_
 
edm::InputTag pdfInfoTag_
 
edm::EDGetTokenT< GenEventInfoProductpdfInfoToken_
 
std::vector< std::string > pdfSetNames_
 
std::vector< std::string > pdfShortNames_
 
bool useFirstAsDefault_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer 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
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsInputProcessBlocks ()
 
static bool wantsProcessBlocks ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- 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 = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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 21 of file PdfWeightProducer.cc.

Constructor & Destructor Documentation

◆ PdfWeightProducer()

PdfWeightProducer::PdfWeightProducer ( const edm::ParameterSet pset)
explicit

Definition at line 54 of file PdfWeightProducer.cc.

55  : fixPOWHEG_(pset.getUntrackedParameter<std::string>("FixPOWHEG", "")),
56  useFirstAsDefault_(pset.getUntrackedParameter<bool>("useFirstAsDefault", false)),
57  genTag_(pset.getUntrackedParameter<edm::InputTag>("GenTag", edm::InputTag("genParticles"))),
58  genToken_(mayConsume<reco::GenParticleCollection>(genTag_)),
59  pdfInfoTag_(pset.getUntrackedParameter<edm::InputTag>("PdfInfoTag", edm::InputTag("generator"))),
60  pdfInfoToken_(consumes<GenEventInfoProduct>(pdfInfoTag_)),
61  pdfSetNames_(pset.getUntrackedParameter<std::vector<std::string> >("PdfSetNames")) {
62  if (!fixPOWHEG_.empty())
63  pdfSetNames_.insert(pdfSetNames_.begin(), fixPOWHEG_);
64 
65  if (pdfSetNames_.size() > 3) {
66  edm::LogWarning("") << pdfSetNames_.size()
67  << " PDF sets requested on input. Using only the first 3 sets and ignoring the rest!!";
68  pdfSetNames_.erase(pdfSetNames_.begin() + 3, pdfSetNames_.end());
69  }
70 
71  for (unsigned int k = 0; k < pdfSetNames_.size(); k++) {
72  size_t dot = pdfSetNames_[k].find_first_of('.');
73  size_t underscore = pdfSetNames_[k].find_first_of('_');
74  if (underscore < dot) {
75  pdfShortNames_.push_back(pdfSetNames_[k].substr(0, underscore));
76  } else {
77  pdfShortNames_.push_back(pdfSetNames_[k].substr(0, dot));
78  }
79  produces<std::vector<double> >(pdfShortNames_[k]);
80  }
81 }

References dot(), fixPOWHEG_, dqmdumpme::k, pdfSetNames_, and pdfShortNames_.

◆ ~PdfWeightProducer()

PdfWeightProducer::~PdfWeightProducer ( )
override

Definition at line 84 of file PdfWeightProducer.cc.

84 {}

Member Function Documentation

◆ beginJob()

void PdfWeightProducer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 87 of file PdfWeightProducer.cc.

87  {
88  for (unsigned int k = 1; k <= pdfSetNames_.size(); k++) {
90  }
91 }

References LHAPDF::initPDFSet(), dqmdumpme::k, and pdfSetNames_.

◆ endJob()

void PdfWeightProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 94 of file PdfWeightProducer.cc.

94 {}

◆ produce()

void PdfWeightProducer::produce ( edm::Event iEvent,
const edm::EventSetup  
)
overrideprivatevirtual

Implements edm::EDProducer.

Definition at line 97 of file PdfWeightProducer.cc.

97  {
98  if (iEvent.isRealData())
99  return;
100 
102  if (!iEvent.getByToken(pdfInfoToken_, pdfstuff)) {
103  edm::LogError("PDFWeightProducer") << ">>> PdfInfo not found: " << pdfInfoTag_.encode() << " !!!";
104  return;
105  }
106 
107  float Q = pdfstuff->pdf()->scalePDF;
108 
109  int id1 = pdfstuff->pdf()->id.first;
110  double x1 = pdfstuff->pdf()->x.first;
111  double pdf1 = pdfstuff->pdf()->xPDF.first;
112 
113  int id2 = pdfstuff->pdf()->id.second;
114  double x2 = pdfstuff->pdf()->x.second;
115  double pdf2 = pdfstuff->pdf()->xPDF.second;
116  if (useFirstAsDefault_ && pdf1 == -1. && pdf2 == -1.) {
117  LHAPDF::usePDFMember(1, 0);
118  pdf1 = LHAPDF::xfx(1, x1, Q, id1) / x1;
119  pdf2 = LHAPDF::xfx(1, x2, Q, id2) / x2;
120  }
121 
122  // Ad-hoc fix for POWHEG
123  if (!fixPOWHEG_.empty()) {
125  if (!iEvent.getByToken(genToken_, genParticles)) {
126  edm::LogError("PDFWeightProducer") << ">>> genParticles not found: " << genTag_.encode() << " !!!";
127  return;
128  }
129  unsigned int gensize = genParticles->size();
130  double mboson = 0.;
131  for (unsigned int i = 0; i < gensize; ++i) {
132  const reco::GenParticle& part = (*genParticles)[i];
133  int status = part.status();
134  if (status != 3)
135  continue;
136  int id = part.pdgId();
137  if (id != 23 && abs(id) != 24)
138  continue;
139  mboson = part.mass();
140  break;
141  }
142  Q = sqrt(mboson * mboson + Q * Q);
143  LHAPDF::usePDFMember(1, 0);
144  pdf1 = LHAPDF::xfx(1, x1, Q, id1) / x1;
145  pdf2 = LHAPDF::xfx(1, x2, Q, id2) / x2;
146  }
147 
148  // Put PDF weights in the event
149  for (unsigned int k = 1; k <= pdfSetNames_.size(); ++k) {
150  std::unique_ptr<std::vector<double> > weights(new std::vector<double>);
151  unsigned int nweights = 1;
152  if (LHAPDF::numberPDF(k) > 1)
153  nweights += LHAPDF::numberPDF(k);
154  weights->reserve(nweights);
155 
156  for (unsigned int i = 0; i < nweights; ++i) {
158  double newpdf1 = LHAPDF::xfx(k, x1, Q, id1) / x1;
159  double newpdf2 = LHAPDF::xfx(k, x2, Q, id2) / x2;
160  weights->push_back(newpdf1 / pdf1 * newpdf2 / pdf2);
161  }
163  }
164 }

References funct::abs(), edm::InputTag::encode(), fixPOWHEG_, genParticles2HepMC_cfi::genParticles, genTag_, genToken_, mps_fire::i, gen::PdfInfo::id, globals_cff::id1, globals_cff::id2, iEvent, dqmdumpme::k, eostools::move(), LHAPDF::numberPDF(), GenEventInfoProduct::pdf(), pdfInfoTag_, pdfInfoToken_, pdfSetNames_, pdfShortNames_, class-composition::Q, gen::PdfInfo::scalePDF, mathSSE::sqrt(), mps_update::status, useFirstAsDefault_, LHAPDF::usePDFMember(), HLT_FULL_cff::weights, gen::PdfInfo::x, testProducerWithPsetDescEmpty_cfi::x1, testProducerWithPsetDescEmpty_cfi::x2, LHAPDF::xfx(), and gen::PdfInfo::xPDF.

Member Data Documentation

◆ fixPOWHEG_

std::string PdfWeightProducer::fixPOWHEG_
private

Definition at line 31 of file PdfWeightProducer.cc.

Referenced by PdfWeightProducer(), and produce().

◆ genTag_

edm::InputTag PdfWeightProducer::genTag_
private

Definition at line 33 of file PdfWeightProducer.cc.

Referenced by produce().

◆ genToken_

edm::EDGetTokenT<reco::GenParticleCollection> PdfWeightProducer::genToken_
private

Definition at line 34 of file PdfWeightProducer.cc.

Referenced by produce().

◆ pdfInfoTag_

edm::InputTag PdfWeightProducer::pdfInfoTag_
private

Definition at line 35 of file PdfWeightProducer.cc.

Referenced by produce().

◆ pdfInfoToken_

edm::EDGetTokenT<GenEventInfoProduct> PdfWeightProducer::pdfInfoToken_
private

Definition at line 36 of file PdfWeightProducer.cc.

Referenced by produce().

◆ pdfSetNames_

std::vector<std::string> PdfWeightProducer::pdfSetNames_
private

Definition at line 37 of file PdfWeightProducer.cc.

Referenced by beginJob(), PdfWeightProducer(), and produce().

◆ pdfShortNames_

std::vector<std::string> PdfWeightProducer::pdfShortNames_
private

Definition at line 38 of file PdfWeightProducer.cc.

Referenced by PdfWeightProducer(), and produce().

◆ useFirstAsDefault_

bool PdfWeightProducer::useFirstAsDefault_
private

Definition at line 32 of file PdfWeightProducer.cc.

Referenced by produce().

dot
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
Definition: Basic3DVectorLD.h:212
mps_fire.i
i
Definition: mps_fire.py:428
genParticles2HepMC_cfi.genParticles
genParticles
Definition: genParticles2HepMC_cfi.py:4
GenEventInfoProduct::pdf
const PDF * pdf() const
Definition: GenEventInfoProduct.h:45
PdfWeightProducer::genToken_
edm::EDGetTokenT< reco::GenParticleCollection > genToken_
Definition: PdfWeightProducer.cc:34
gen::PdfInfo::x
std::pair< double, double > x
Definition: PdfInfo.h:13
reco::GenParticle
Definition: GenParticle.h:21
mps_update.status
status
Definition: mps_update.py:69
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
globals_cff.id1
id1
Definition: globals_cff.py:33
PdfWeightProducer::genTag_
edm::InputTag genTag_
Definition: PdfWeightProducer.cc:33
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
class-composition.Q
Q
Definition: class-composition.py:82
LHAPDF::usePDFMember
void usePDFMember(int nset, int member)
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
part
part
Definition: HCALResponse.h:20
LHAPDF::initPDFSet
void initPDFSet(int nset, const std::string &filename, int member=0)
HLT_FULL_cff.weights
weights
Definition: HLT_FULL_cff.py:99178
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
PdfWeightProducer::pdfSetNames_
std::vector< std::string > pdfSetNames_
Definition: PdfWeightProducer.cc:37
gen::PdfInfo::xPDF
std::pair< double, double > xPDF
Definition: PdfInfo.h:14
LHAPDF::xfx
double xfx(int nset, double x, double Q, int fl)
dqmdumpme.k
k
Definition: dqmdumpme.py:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PdfWeightProducer::pdfInfoTag_
edm::InputTag pdfInfoTag_
Definition: PdfWeightProducer.cc:35
PdfWeightProducer::pdfInfoToken_
edm::EDGetTokenT< GenEventInfoProduct > pdfInfoToken_
Definition: PdfWeightProducer.cc:36
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::InputTag::encode
std::string encode() const
Definition: InputTag.cc:159
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
gen::PdfInfo::scalePDF
double scalePDF
Definition: PdfInfo.h:15
PdfWeightProducer::useFirstAsDefault_
bool useFirstAsDefault_
Definition: PdfWeightProducer.cc:32
eostools.move
def move(src, dest)
Definition: eostools.py:511
LHAPDF::numberPDF
int numberPDF(int nset)
gen::PdfInfo::id
std::pair< int, int > id
Definition: PdfInfo.h:12
PdfWeightProducer::fixPOWHEG_
std::string fixPOWHEG_
Definition: PdfWeightProducer.cc:31
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PdfWeightProducer::pdfShortNames_
std::vector< std::string > pdfShortNames_
Definition: PdfWeightProducer.cc:38
globals_cff.id2
id2
Definition: globals_cff.py:34
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27