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 ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- 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 ()
 
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, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- 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 const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
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
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

virtual void beginJob () override
 
virtual void endJob () override
 
virtual 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
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)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, 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 ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 21 of file PdfWeightProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 54 of file PdfWeightProducer.cc.

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

54  :
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 {
63  if (fixPOWHEG_ != "") pdfSetNames_.insert(pdfSetNames_.begin(),fixPOWHEG_);
64 
65  if (pdfSetNames_.size()>3) {
66  edm::LogWarning("") << pdfSetNames_.size() << " PDF sets requested on input. Using only the first 3 sets and ignoring the rest!!";
67  pdfSetNames_.erase(pdfSetNames_.begin()+3,pdfSetNames_.end());
68  }
69 
70  for (unsigned int k=0; k<pdfSetNames_.size(); k++) {
71  size_t dot = pdfSetNames_[k].find_first_of('.');
72  size_t underscore = pdfSetNames_[k].find_first_of('_');
73  if (underscore<dot) {
74  pdfShortNames_.push_back(pdfSetNames_[k].substr(0,underscore));
75  } else {
76  pdfShortNames_.push_back(pdfSetNames_[k].substr(0,dot));
77  }
78  produces<std::vector<double> >(pdfShortNames_[k].data());
79  }
80 }
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< reco::GenParticleCollection > genToken_
edm::InputTag genTag_
std::vector< std::string > pdfSetNames_
edm::EDGetTokenT< GenEventInfoProduct > pdfInfoToken_
int k[5][pyjets_maxn]
edm::InputTag pdfInfoTag_
std::vector< std::string > pdfShortNames_
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
PdfWeightProducer::~PdfWeightProducer ( )

Definition at line 83 of file PdfWeightProducer.cc.

83 {}

Member Function Documentation

void PdfWeightProducer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 86 of file PdfWeightProducer.cc.

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

86  {
87  for (unsigned int k=1; k<=pdfSetNames_.size(); k++) {
89  }
90 }
void initPDFSet(int nset, const std::string &filename, int member=0)
std::vector< std::string > pdfSetNames_
int k[5][pyjets_maxn]
void PdfWeightProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 93 of file PdfWeightProducer.cc.

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

Definition at line 96 of file PdfWeightProducer.cc.

References funct::abs(), DEFINE_FWK_MODULE, edm::InputTag::encode(), fixPOWHEG_, GenHFHadronMatcher_cfi::genParticles, genTag_, genToken_, edm::Event::getByToken(), mps_fire::i, gen::PdfInfo::id, edm::EventBase::isRealData(), gen::k, reco::LeafCandidate::mass(), eostools::move(), LHAPDF::numberPDF(), GenEventInfoProduct::pdf(), pdfInfoTag_, pdfInfoToken_, pdfSetNames_, pdfShortNames_, reco::LeafCandidate::pdgId(), edm::Event::put(), class-composition::Q, gen::PdfInfo::scalePDF, mathSSE::sqrt(), mps_update::status, reco::LeafCandidate::status(), useFirstAsDefault_, LHAPDF::usePDFMember(), create_public_lumi_plots::weights, gen::PdfInfo::x, LHAPDF::xfx(), and gen::PdfInfo::xPDF.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

96  {
97 
98  if (iEvent.isRealData()) return;
99 
101  if (!iEvent.getByToken(pdfInfoToken_, pdfstuff)) {
102  edm::LogError("PDFWeightProducer") << ">>> PdfInfo not found: " << pdfInfoTag_.encode() << " !!!";
103  return;
104  }
105 
106  float Q = pdfstuff->pdf()->scalePDF;
107 
108  int id1 = pdfstuff->pdf()->id.first;
109  double x1 = pdfstuff->pdf()->x.first;
110  double pdf1 = pdfstuff->pdf()->xPDF.first;
111 
112  int id2 = pdfstuff->pdf()->id.second;
113  double x2 = pdfstuff->pdf()->x.second;
114  double pdf2 = pdfstuff->pdf()->xPDF.second;
115  if (useFirstAsDefault_ && pdf1 == -1. && pdf2 == -1. ) {
117  pdf1 = LHAPDF::xfx(1, x1, Q, id1)/x1;
118  pdf2 = LHAPDF::xfx(1, x2, Q, id2)/x2;
119  }
120 
121  // Ad-hoc fix for POWHEG
122  if (fixPOWHEG_!="") {
124  if (!iEvent.getByToken(genToken_, genParticles)) {
125  edm::LogError("PDFWeightProducer") << ">>> genParticles not found: " << genTag_.encode() << " !!!";
126  return;
127  }
128  unsigned int gensize = genParticles->size();
129  double mboson = 0.;
130  for(unsigned int i = 0; i<gensize; ++i) {
131  const reco::GenParticle& part = (*genParticles)[i];
132  int status = part.status();
133  if (status!=3) continue;
134  int id = part.pdgId();
135  if (id!=23 && abs(id)!=24) continue;
136  mboson = part.mass();
137  break;
138  }
139  Q = sqrt(mboson*mboson+Q*Q);
141  pdf1 = LHAPDF::xfx(1, x1, Q, id1)/x1;
142  pdf2 = LHAPDF::xfx(1, x2, Q, id2)/x2;
143  }
144 
145  // Put PDF weights in the event
146  for (unsigned int k=1; k<=pdfSetNames_.size(); ++k) {
147  std::unique_ptr<std::vector<double> > weights (new std::vector<double>);
148  unsigned int nweights = 1;
149  if (LHAPDF::numberPDF(k)>1) nweights += LHAPDF::numberPDF(k);
150  weights->reserve(nweights);
151 
152  for (unsigned int i=0; i<nweights; ++i) {
154  double newpdf1 = LHAPDF::xfx(k, x1, Q, id1)/x1;
155  double newpdf2 = LHAPDF::xfx(k, x2, Q, id2)/x2;
156  weights->push_back(newpdf1/pdf1*newpdf2/pdf2);
157  }
158  iEvent.put(std::move(weights),pdfShortNames_[k-1]);
159  }
160 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
virtual double mass() const final
mass
const PDF * pdf() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::pair< double, double > x
Definition: PdfInfo.h:13
edm::EDGetTokenT< reco::GenParticleCollection > genToken_
virtual int status() const final
status word
edm::InputTag genTag_
bool isRealData() const
Definition: EventBase.h:64
std::string encode() const
Definition: InputTag.cc:166
std::vector< std::string > pdfSetNames_
std::pair< double, double > xPDF
Definition: PdfInfo.h:14
T sqrt(T t)
Definition: SSEVec.h:18
virtual int pdgId() const final
PDG identifier.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int numberPDF(int nset)
edm::EDGetTokenT< GenEventInfoProduct > pdfInfoToken_
int k[5][pyjets_maxn]
std::pair< int, int > id
Definition: PdfInfo.h:12
edm::InputTag pdfInfoTag_
part
Definition: HCALResponse.h:20
std::vector< std::string > pdfShortNames_
double xfx(int nset, double x, double Q, int fl)
double scalePDF
Definition: PdfInfo.h:15
def move(src, dest)
Definition: eostools.py:510
void usePDFMember(int nset, int member)

Member Data Documentation

std::string PdfWeightProducer::fixPOWHEG_
private

Definition at line 31 of file PdfWeightProducer.cc.

Referenced by PdfWeightProducer(), and produce().

edm::InputTag PdfWeightProducer::genTag_
private

Definition at line 33 of file PdfWeightProducer.cc.

Referenced by produce().

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

Definition at line 34 of file PdfWeightProducer.cc.

Referenced by produce().

edm::InputTag PdfWeightProducer::pdfInfoTag_
private

Definition at line 35 of file PdfWeightProducer.cc.

Referenced by produce().

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

Definition at line 36 of file PdfWeightProducer.cc.

Referenced by produce().

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

Definition at line 37 of file PdfWeightProducer.cc.

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

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

Definition at line 38 of file PdfWeightProducer.cc.

Referenced by PdfWeightProducer(), and produce().

bool PdfWeightProducer::useFirstAsDefault_
private

Definition at line 32 of file PdfWeightProducer.cc.

Referenced by produce().