CMS 3D CMS Logo

GenWeightValidation.cc
Go to the documentation of this file.
2 
5 
6 using namespace edm;
7 
9  : wmanager_(iPSet, consumesCollector()),
10  genParticleToken_(consumes<reco::GenParticleCollection>(iPSet.getParameter<edm::InputTag>("genParticles"))),
11  genJetToken_(consumes<reco::GenJetCollection>(iPSet.getParameter<edm::InputTag>("genJets"))),
12  idxGenEvtInfo_(iPSet.getParameter<int>("whichGenEventInfo")),
13  idxFSRup_(iPSet.getParameter<int>("idxFSRup")),
14  idxFSRdown_(iPSet.getParameter<int>("idxFSRdown")),
15  idxISRup_(iPSet.getParameter<int>("idxISRup")),
16  idxISRdown_(iPSet.getParameter<int>("idxISRdown")),
17  leadLepPtNbin_(iPSet.getParameter<int>("leadLepPtNbin")),
18  rapidityNbin_(iPSet.getParameter<int>("rapidityNbin")),
19  leadLepPtRange_(iPSet.getParameter<double>("leadLepPtRange")),
20  leadLepPtCut_(iPSet.getParameter<double>("leadLepPtCut")),
21  lepEtaCut_(iPSet.getParameter<double>("lepEtaCut")),
22  rapidityRange_(iPSet.getParameter<double>("rapidityRange")),
23  nJetsNbin_(iPSet.getParameter<int>("nJetsNbin")),
24  jetPtNbin_(iPSet.getParameter<int>("jetPtNbin")),
25  jetPtCut_(iPSet.getParameter<double>("jetPtCut")),
26  jetEtaCut_(iPSet.getParameter<double>("jetEtaCut")),
27  jetPtRange_(iPSet.getParameter<double>("jetPtRange")) {
28  std::vector<int> idxs = {idxFSRup_, idxFSRdown_, idxISRup_, idxISRdown_};
29  std::sort(idxs.begin(), idxs.end(), std::greater<int>());
30  idxMax_ = idxs.at(0);
31 }
32 
35  std::string folderName = "Generator/GenWeight";
36  DQMHelper aDqmHelper(&iBook);
38 
39  // Number of analyzed events
40  nEvt_ = aDqmHelper.book1dHisto("nEvt", "n analyzed Events", 1, 0., 1., "bin", "Number of Events");
41  nlogWgt_ = aDqmHelper.book1dHisto("nlogWgt", "Log10(n weights)", 100, 0., 3., "log_{10}(nWgts)", "Number of Events");
42  wgtVal_ = aDqmHelper.book1dHisto("wgtVal", "weights", 100, -1.5, 3., "weight", "Number of Weights");
43  bookTemplates(aDqmHelper,
45  "leadLepPt",
46  "leading lepton Pt",
48  0.,
50  "Pt_{l} (GeV)",
51  "Number of Events");
52  bookTemplates(aDqmHelper,
54  "leadLepEta",
55  "leading lepton #eta",
59  "#eta_{l}",
60  "Number of Events");
61  bookTemplates(aDqmHelper,
63  "JetMultiplicity",
64  "Gen jet multiplicity",
65  nJetsNbin_,
66  0,
67  nJetsNbin_,
68  "n",
69  "Number of Events");
70  bookTemplates(aDqmHelper,
72  "leadJetPt",
73  "leading Gen jet Pt",
74  jetPtNbin_,
75  0.,
77  "Pt_{j} (GeV)",
78  "Number of Events");
79  bookTemplates(aDqmHelper,
81  "leadJetEta",
82  "leading Gen jet #eta",
86  "#eta_{j}",
87  "Number of Events");
88 
89  return;
90 }
91 
93  std::vector<MonitorElement*>& tmps,
94  const std::string& name,
95  const std::string& title,
96  int nbin,
97  float low,
98  float high,
99  const std::string& xtitle,
100  const std::string& ytitle) {
101  tmps.push_back(aDqmHelper.book1dHisto(name, title, nbin, low, high, xtitle, ytitle));
102  tmps.push_back(aDqmHelper.book1dHisto(name + "FSRup", title + " FSR up", nbin, low, high, xtitle, ytitle));
103  tmps.push_back(aDqmHelper.book1dHisto(name + "FSRdn", title + " FSR down", nbin, low, high, xtitle, ytitle));
104  tmps.push_back(aDqmHelper.book1dHisto(
105  name + "FSRup_ratio", "Ratio of " + title + " FSR up / Nominal", nbin, low, high, xtitle, ytitle));
106  tmps.at(3)->setEfficiencyFlag();
107  tmps.push_back(aDqmHelper.book1dHisto(
108  name + "FSRdn_ratio", "Ratio of " + title + " FSR down / Nominal", nbin, low, high, xtitle, ytitle));
109  tmps.at(4)->setEfficiencyFlag();
110  tmps.push_back(aDqmHelper.book1dHisto(name + "ISRup", title + " ISR up", nbin, low, high, xtitle, ytitle));
111  tmps.push_back(aDqmHelper.book1dHisto(name + "ISRdn", title + " ISR down", nbin, low, high, xtitle, ytitle));
112  tmps.push_back(aDqmHelper.book1dHisto(
113  name + "ISRup_ratio", "Ratio of " + title + " ISR up / Nominal", nbin, low, high, xtitle, ytitle));
114  tmps.at(7)->setEfficiencyFlag();
115  tmps.push_back(aDqmHelper.book1dHisto(
116  name + "ISRdn_ratio", "Ratio of " + title + " ISR down / Nominal", nbin, low, high, xtitle, ytitle));
117  tmps.at(8)->setEfficiencyFlag();
118 } // to get ratio plots correctly - need to modify PostProcessor_cff.py as well!
119 
121 
124 
125  unsigned weightsSize = weights_.at(idxGenEvtInfo_).size();
126  if (weightsSize < 2)
127  return; // no baseline weight in GenEventInfo
128 
130  nEvt_->Fill(0.5, weight_);
131  nlogWgt_->Fill(std::log10(weightsSize), weight_);
132 
133  for (unsigned idx = 0; idx < weightsSize; idx++)
135 
136  if ((int)weightsSize <= idxMax_)
137  return; // no PS weights in GenEventInfo
138 
140  iEvent.getByToken(genParticleToken_, ptcls);
142  iEvent.getByToken(genJetToken_, genjets);
143 
144  std::vector<reco::GenParticleRef> leptons;
145 
146  for (unsigned iptc = 0; iptc < ptcls->size(); iptc++) {
147  reco::GenParticleRef ptc(ptcls, iptc);
148  if (ptc->status() == 1 && (std::abs(ptc->pdgId()) == 11 || std::abs(ptc->pdgId()) == 13)) {
149  if (ptc->pt() > leadLepPtCut_ && std::abs(ptc->eta()) < lepEtaCut_)
150  leptons.push_back(ptc);
151  }
152  }
153 
154  std::sort(leptons.begin(), leptons.end(), HepMCValidationHelper::sortByPtRef<reco::GenParticleRef>);
155 
156  if (!leptons.empty()) {
157  reco::GenParticleRef leadLep = leptons.at(0);
158  fillTemplates(leadLepPtTemp_, leadLep->pt());
159  fillTemplates(leadLepEtaTemp_, leadLep->eta());
160  }
161 
162  std::vector<reco::GenJetRef> genjetVec;
163 
164  for (unsigned igj = 0; igj < genjets->size(); igj++) {
165  reco::GenJetRef genjet(genjets, igj);
166 
167  if (genjet->pt() > jetPtCut_ && std::abs(genjet->eta()) < jetEtaCut_)
168  genjetVec.push_back(genjet);
169  }
170 
171  fillTemplates(jetMultTemp_, (float)genjetVec.size());
172 
173  if (!genjetVec.empty()) {
174  std::sort(genjetVec.begin(), genjetVec.end(), HepMCValidationHelper::sortByPtRef<reco::GenJetRef>);
175 
176  auto leadJet = genjetVec.at(0);
177  fillTemplates(leadJetPtTemp_, leadJet->pt());
178  fillTemplates(leadJetEtaTemp_, leadJet->eta());
179  }
180 } //analyze
181 
182 void GenWeightValidation::fillTemplates(std::vector<MonitorElement*>& tmps, float obs) {
183  tmps.at(0)->Fill(obs, weight_);
184  tmps.at(1)->Fill(obs, weights_.at(idxGenEvtInfo_)[idxFSRup_] / weights_.at(idxGenEvtInfo_)[1]);
185  tmps.at(2)->Fill(obs, weights_.at(idxGenEvtInfo_)[idxFSRdown_] / weights_.at(idxGenEvtInfo_)[1]);
186  tmps.at(5)->Fill(obs, weights_.at(idxGenEvtInfo_)[idxISRup_] / weights_.at(idxGenEvtInfo_)[1]);
187  tmps.at(6)->Fill(obs, weights_.at(idxGenEvtInfo_)[idxISRdown_] / weights_.at(idxGenEvtInfo_)[1]);
188 }
const double leadLepPtRange_
std::vector< MonitorElement * > leadLepEtaTemp_
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
const edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
MonitorElement * nEvt_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
void analyze(const edm::Event &, const edm::EventSetup &) override
void fillTemplates(std::vector< MonitorElement *> &tmps, float obs)
std::vector< GenJet > GenJetCollection
collection of GenJet objects
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< MonitorElement * > jetMultTemp_
GenWeightValidation(const edm::ParameterSet &)
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:224
MonitorElement * nlogWgt_
std::vector< MonitorElement * > leadJetEtaTemp_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< MonitorElement * > leadJetPtTemp_
std::vector< MonitorElement * > leadLepPtTemp_
MonitorElement * wgtVal_
MonitorElement * book1dHisto(const std::string &name, const std::string &title, int n, double xmin, double xmax, const std::string &xaxis, const std::string &yaxis)
Definition: DQMHelper.cc:7
void bookTemplates(DQMHelper &aDqmHelper, std::vector< MonitorElement *> &tmps, const std::string &name, const std::string &title, int nbin, float low, float high, const std::string &xtitle, const std::string &ytitle)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
const edm::EDGetTokenT< reco::GenJetCollection > genJetToken_
fixed size matrix
HLT enums.
std::vector< std::vector< double > > weightsCollection(const edm::Event &)
std::vector< std::vector< double > > weights_
Definition: Run.h:45