CMS 3D CMS Logo

PDFWeightsTest.cc
Go to the documentation of this file.
15 #include "TTree.h"
16 #include <iostream>
17 using namespace std;
18 using namespace edm;
19 using namespace HepMC;
20 
22 private:
27 
28  unsigned int pdfWeightOffset_;
29  unsigned int nPdfWeights_;
30  unsigned int nPdfEigWeights_;
31 
32  TTree* tree_;
33  std::vector<float> pdfweights_;
34  std::vector<float> pdfeigweights_;
35  float weight_;
36 
37 public:
38  explicit PDFWeightsTest(const ParameterSet& cfg)
39  : srcToken_(consumes<LHEEventProduct>(edm::InputTag("externalLHEProducer"))),
40  srcTokenAlt_(consumes<LHEEventProduct>(edm::InputTag("source"))),
41  srcTokenGen_(consumes<GenEventInfoProduct>(edm::InputTag("generator"))),
42  pdfWeightOffset_(cfg.getParameter<unsigned int>("pdfWeightOffset")),
43  nPdfWeights_(cfg.getParameter<unsigned int>("nPdfWeights")),
44  nPdfEigWeights_(cfg.getParameter<unsigned int>("nPdfEigWeights")),
45  pdfweights_(nPdfWeights_),
46  pdfeigweights_(nPdfEigWeights_) {
48  tree_ = fs->make<TTree>("tree", "");
49 
50  tree_->Branch("pdfrep", &pdfweights_);
51  tree_->Branch("pdfeig", &pdfeigweights_);
52  tree_->Branch("weight", &weight_);
53 
54  edm::FileInPath mc2hessianCSV = cfg.getParameter<edm::FileInPath>("mc2hessianCSV");
55  pdfweightshelper_.Init(nPdfWeights_, nPdfEigWeights_, mc2hessianCSV);
56  }
57 
58 private:
59  void analyze(const Event& evt, const EventSetup& es) override {
61  evt.getByToken(srcToken_, lheInfo);
62 
63  if (!lheInfo.isValid()) {
64  evt.getByToken(srcTokenAlt_, lheInfo);
65  }
66 
67  double nomlheweight = lheInfo->weights()[0].wgt;
68 
70  evt.getByToken(srcTokenGen_, genInfo);
71 
72  weight_ = genInfo->weight();
73 
74  //get the original mc replica weights
75  std::vector<double> inpdfweights(nPdfWeights_);
76  for (unsigned int ipdf = 0; ipdf < nPdfWeights_; ++ipdf) {
77  unsigned int iwgt = ipdf + pdfWeightOffset_;
78 
79  //this is the weight to be used for evaluating uncertainties with mc replica weights
80  pdfweights_[ipdf] = lheInfo->weights()[iwgt].wgt * weight_ / nomlheweight;
81 
82  //this is the raw weight to be fed to the mc2hessian convertor
83  inpdfweights[ipdf] = lheInfo->weights()[iwgt].wgt;
84  }
85 
86  std::vector<double> outpdfweights(nPdfEigWeights_);
87  //do the actual conversion, where the nominal lhe weight is needed as the reference point for the linearization
88  pdfweightshelper_.DoMC2Hessian(nomlheweight, inpdfweights.data(), outpdfweights.data());
89 
90  for (unsigned int iwgt = 0; iwgt < nPdfEigWeights_; ++iwgt) {
91  double wgtval = outpdfweights[iwgt];
92 
93  //the is the weight to be used for evaluating uncertainties with hessian weights
94  pdfeigweights_[iwgt] = wgtval * weight_ / nomlheweight;
95  }
96 
97  tree_->Fill();
98  }
99 };
100 
102 
GenEventInfoProduct
Definition: GenEventInfoProduct.h:17
Handle.h
EDAnalyzer.h
PDFWeightsTest::srcToken_
EDGetTokenT< LHEEventProduct > srcToken_
Definition: PDFWeightsTest.cc:24
LHEEventProduct
Definition: LHEEventProduct.h:12
edm::EDGetTokenT< LHEEventProduct >
PDFWeightsTest::weight_
float weight_
Definition: PDFWeightsTest.cc:35
edm
HLT enums.
Definition: AlignableModifier.h:19
PDFWeightsTest::nPdfEigWeights_
unsigned int nPdfEigWeights_
Definition: PDFWeightsTest.cc:30
PDFWeightsTest::srcTokenAlt_
EDGetTokenT< LHEEventProduct > srcTokenAlt_
Definition: PDFWeightsTest.cc:25
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
edm::Handle
Definition: AssociativeIterator.h:50
PDFWeightsHelper::Init
void Init(unsigned int nreplicas, unsigned int neigenvectors, const edm::FileInPath &incsv)
Definition: PDFWeightsHelper.cc:7
PDFWeightsHelper::DoMC2Hessian
void DoMC2Hessian(double nomweight, const double *inweights, double *outweights) const
Definition: PDFWeightsHelper.cc:28
EDMException.h
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
genWeightsTable_cfi.lheInfo
lheInfo
Definition: genWeightsTable_cfi.py:6
Service.h
PDFWeightsTest::srcTokenGen_
EDGetTokenT< GenEventInfoProduct > srcTokenGen_
Definition: PDFWeightsTest.cc:26
PDFWeightsTest::pdfeigweights_
std::vector< float > pdfeigweights_
Definition: PDFWeightsTest.cc:34
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
TFileService.h
PDFWeightsTest::pdfWeightOffset_
unsigned int pdfWeightOffset_
Definition: PDFWeightsTest.cc:28
edm::ParameterSet
Definition: ParameterSet.h:47
GenEventInfoProduct.h
Event.h
ParticleDataTable.h
PDFWeightsTest::PDFWeightsTest
PDFWeightsTest(const ParameterSet &cfg)
Definition: PDFWeightsTest.cc:38
edm::Service< TFileService >
createfilelist.int
int
Definition: createfilelist.py:10
edm::EventSetup
Definition: EventSetup.h:57
PDFWeightsTest::pdfweightshelper_
PDFWeightsHelper pdfweightshelper_
Definition: PDFWeightsTest.cc:23
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
PDFWeightsHelper
Definition: PDFWeightsHelper.h:10
PDFWeightsTest::pdfweights_
std::vector< float > pdfweights_
Definition: PDFWeightsTest.cc:33
LHEEventProduct.h
std
Definition: JetResolutionObject.h:76
HepMC
Definition: GenParticle.h:15
EventSetup.h
PDFWeightsTest::tree_
TTree * tree_
Definition: PDFWeightsTest.cc:32
PDFWeightsTest
Definition: PDFWeightsTest.cc:21
ParameterSet.h
HepMCProduct.h
PDFWeightsTest::analyze
void analyze(const Event &evt, const EventSetup &es) override
Definition: PDFWeightsTest.cc:59
edm::Event
Definition: Event.h:73
PDFWeightsTest::nPdfWeights_
unsigned int nPdfWeights_
Definition: PDFWeightsTest.cc:29
edm::InputTag
Definition: InputTag.h:15
PDFWeightsHelper.h
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
GenEventInfoProduct::weight
double weight() const
Definition: GenEventInfoProduct.h:35