CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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::InputTag pdfInfoTag_
 
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
 
- 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::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- 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 20 of file PdfWeightProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 52 of file PdfWeightProducer.cc.

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

52  :
53  fixPOWHEG_(pset.getUntrackedParameter<std::string> ("FixPOWHEG", "")),
54  useFirstAsDefault_(pset.getUntrackedParameter<bool>("useFirstAsDefault",false)),
55  genTag_(pset.getUntrackedParameter<edm::InputTag> ("GenTag", edm::InputTag("genParticles"))),
56  pdfInfoTag_(pset.getUntrackedParameter<edm::InputTag> ("PdfInfoTag", edm::InputTag("generator"))),
57  pdfSetNames_(pset.getUntrackedParameter<std::vector<std::string> > ("PdfSetNames"))
58 {
59  if (fixPOWHEG_ != "") pdfSetNames_.insert(pdfSetNames_.begin(),fixPOWHEG_);
60 
61  if (pdfSetNames_.size()>3) {
62  edm::LogWarning("") << pdfSetNames_.size() << " PDF sets requested on input. Using only the first 3 sets and ignoring the rest!!";
63  pdfSetNames_.erase(pdfSetNames_.begin()+3,pdfSetNames_.end());
64  }
65 
66  for (unsigned int k=0; k<pdfSetNames_.size(); k++) {
67  size_t dot = pdfSetNames_[k].find_first_of('.');
68  size_t underscore = pdfSetNames_[k].find_first_of('_');
69  if (underscore<dot) {
70  pdfShortNames_.push_back(pdfSetNames_[k].substr(0,underscore));
71  } else {
72  pdfShortNames_.push_back(pdfSetNames_[k].substr(0,dot));
73  }
74  produces<std::vector<double> >(pdfShortNames_[k].data());
75  }
76 }
T getUntrackedParameter(std::string const &, T const &) const
edm::InputTag genTag_
std::vector< std::string > pdfSetNames_
int k[5][pyjets_maxn]
edm::InputTag pdfInfoTag_
std::vector< std::string > pdfShortNames_
T dot(const Basic3DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
PdfWeightProducer::~PdfWeightProducer ( )

Definition at line 79 of file PdfWeightProducer.cc.

79 {}

Member Function Documentation

void PdfWeightProducer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 82 of file PdfWeightProducer.cc.

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

82  {
83  for (unsigned int k=1; k<=pdfSetNames_.size(); k++) {
85  }
86 }
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 89 of file PdfWeightProducer.cc.

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

Implements edm::EDProducer.

Definition at line 92 of file PdfWeightProducer.cc.

References funct::abs(), edm::InputTag::encode(), fixPOWHEG_, genParticleCandidates2GenParticles_cfi::genParticles, genTag_, edm::Event::getByLabel(), i, edm::HandleBase::id(), edm::EventBase::isRealData(), gen::k, reco::LeafCandidate::mass(), LHAPDF::numberPDF(), pdfInfoTag_, pdfSetNames_, pdfShortNames_, reco::LeafCandidate::pdgId(), edm::Event::put(), mathSSE::sqrt(), reco::LeafCandidate::status(), ntuplemaker::status, useFirstAsDefault_, LHAPDF::usePDFMember(), create_public_pileup_plots::weights, and LHAPDF::xfx().

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

92  {
93 
94  if (iEvent.isRealData()) return;
95 
97  if (!iEvent.getByLabel(pdfInfoTag_, pdfstuff)) {
98  edm::LogError("PDFWeightProducer") << ">>> PdfInfo not found: " << pdfInfoTag_.encode() << " !!!";
99  return;
100  }
101 
102  float Q = pdfstuff->pdf()->scalePDF;
103 
104  int id1 = pdfstuff->pdf()->id.first;
105  double x1 = pdfstuff->pdf()->x.first;
106  double pdf1 = pdfstuff->pdf()->xPDF.first;
107 
108  int id2 = pdfstuff->pdf()->id.second;
109  double x2 = pdfstuff->pdf()->x.second;
110  double pdf2 = pdfstuff->pdf()->xPDF.second;
111  if (useFirstAsDefault_ && pdf1 == -1. && pdf2 == -1. ) {
113  pdf1 = LHAPDF::xfx(1, x1, Q, id1)/x1;
114  pdf2 = LHAPDF::xfx(1, x2, Q, id2)/x2;
115  }
116 
117  // Ad-hoc fix for POWHEG
118  if (fixPOWHEG_!="") {
120  if (!iEvent.getByLabel(genTag_, genParticles)) {
121  edm::LogError("PDFWeightProducer") << ">>> genParticles not found: " << genTag_.encode() << " !!!";
122  return;
123  }
124  unsigned int gensize = genParticles->size();
125  double mboson = 0.;
126  for(unsigned int i = 0; i<gensize; ++i) {
127  const reco::GenParticle& part = (*genParticles)[i];
128  int status = part.status();
129  if (status!=3) continue;
130  int id = part.pdgId();
131  if (id!=23 && abs(id)!=24) continue;
132  mboson = part.mass();
133  break;
134  }
135  Q = sqrt(mboson*mboson+Q*Q);
137  pdf1 = LHAPDF::xfx(1, x1, Q, id1)/x1;
138  pdf2 = LHAPDF::xfx(1, x2, Q, id2)/x2;
139  }
140 
141  // Put PDF weights in the event
142  for (unsigned int k=1; k<=pdfSetNames_.size(); ++k) {
143  std::auto_ptr<std::vector<double> > weights (new std::vector<double>);
144  unsigned int nweights = 1;
145  if (LHAPDF::numberPDF(k)>1) nweights += LHAPDF::numberPDF(k);
146  weights->reserve(nweights);
147 
148  for (unsigned int i=0; i<nweights; ++i) {
150  double newpdf1 = LHAPDF::xfx(k, x1, Q, id1)/x1;
151  double newpdf2 = LHAPDF::xfx(k, x2, Q, id2)/x2;
152  weights->push_back(newpdf1/pdf1*newpdf2/pdf2);
153  }
154  iEvent.put(weights,pdfShortNames_[k-1]);
155  }
156 }
int i
Definition: DBlmapReader.cc:9
ProductID id() const
Definition: HandleBase.cc:15
virtual int pdgId() const GCC11_FINAL
PDG identifier.
edm::InputTag genTag_
bool isRealData() const
Definition: EventBase.h:60
std::string encode() const
Definition: InputTag.cc:164
std::vector< std::string > pdfSetNames_
virtual int status() const GCC11_FINAL
status word
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
T sqrt(T t)
Definition: SSEVec.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int numberPDF(int nset)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
int k[5][pyjets_maxn]
virtual float mass() const GCC11_FINAL
mass
edm::InputTag pdfInfoTag_
part
Definition: HCALResponse.h:20
std::vector< std::string > pdfShortNames_
double xfx(int nset, double x, double Q, int fl)
tuple status
Definition: ntuplemaker.py:245
void usePDFMember(int nset, int member)

Member Data Documentation

std::string PdfWeightProducer::fixPOWHEG_
private

Definition at line 30 of file PdfWeightProducer.cc.

Referenced by PdfWeightProducer(), and produce().

edm::InputTag PdfWeightProducer::genTag_
private

Definition at line 32 of file PdfWeightProducer.cc.

Referenced by produce().

edm::InputTag PdfWeightProducer::pdfInfoTag_
private

Definition at line 33 of file PdfWeightProducer.cc.

Referenced by produce().

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

Definition at line 34 of file PdfWeightProducer.cc.

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

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

Definition at line 35 of file PdfWeightProducer.cc.

Referenced by PdfWeightProducer(), and produce().

bool PdfWeightProducer::useFirstAsDefault_
private

Definition at line 31 of file PdfWeightProducer.cc.

Referenced by produce().