CMS 3D CMS Logo

TopSingleLeptonDQM.cc
Go to the documentation of this file.
7 #include <iostream>
11 
12 using namespace std;
13 namespace TopSingleLepton {
14 
15 // maximal number of leading jets
16 // to be used for top mass estimate
17 static const unsigned int MAXJETS = 4;
18 // nominal mass of the W boson to
19 // be used for the top mass estimate
20 static const double WMASS = 80.4;
21 
22 MonitorEnsemble::MonitorEnsemble(const char* label,
23  const edm::ParameterSet& cfg,
25  : label_(label),
26  elecIso_(nullptr),
27  elecSelect_(nullptr),
28  pvSelect_(nullptr),
29  muonIso_(nullptr),
30  muonSelect_(nullptr),
31  jetIDSelect_(nullptr),
32  includeBTag_(false),
33  lowerEdge_(-1.),
34  upperEdge_(-1.),
35  logged_(0) {
36 
37  // sources have to be given; this PSet is not optional
38  edm::ParameterSet sources = cfg.getParameter<edm::ParameterSet>("sources");
39  muons_ = iC.consumes<edm::View<reco::PFCandidate> >(
40  sources.getParameter<edm::InputTag>("muons"));
41  elecs_ = iC.consumes<edm::View<reco::PFCandidate> >(
42  sources.getParameter<edm::InputTag>("elecs"));
43  pvs_ = iC.consumes<edm::View<reco::Vertex> >(
44  sources.getParameter<edm::InputTag>("pvs"));
45  jets_ = iC.consumes<edm::View<reco::Jet> >(
46  sources.getParameter<edm::InputTag>("jets"));
47  for (edm::InputTag const& tag :
48  sources.getParameter<std::vector<edm::InputTag> >("mets"))
49  mets_.push_back(iC.consumes<edm::View<reco::MET> >(tag));
50  // electronExtras are optional; they may be omitted or
51  // empty
52  if (cfg.existsAs<edm::ParameterSet>("elecExtras")) {
53  // rho for PF isolation with EA corrections
54  // eventrhoToken_ =
55  // iC.consumes<double>(edm::InputTag("fixedGridRhoFastjetAll"));
56 
57  edm::ParameterSet elecExtras =
58  cfg.getParameter<edm::ParameterSet>("elecExtras");
59  // select is optional; in case it's not found no
60  // selection will be applied
61  if (elecExtras.existsAs<std::string>("select")) {
63  elecExtras.getParameter<std::string>("select")));
64  }
65  // isolation is optional; in case it's not found no
66  // isolation will be applied
67  if (elecExtras.existsAs<std::string>("isolation")) {
69  elecExtras.getParameter<std::string>("isolation")));
70  }
71  // electronId is optional; in case it's not found the
72  // InputTag will remain empty
73  if (elecExtras.existsAs<edm::ParameterSet>("electronId")) {
74  edm::ParameterSet elecId =
75  elecExtras.getParameter<edm::ParameterSet>("electronId");
76  electronId_ = iC.consumes<edm::ValueMap<float> >(
77  elecId.getParameter<edm::InputTag>("src"));
78  eidCutValue_ = elecId.getParameter<double>("cutValue");
79  }
80  }
81  // pvExtras are opetional; they may be omitted or empty
82  if (cfg.existsAs<edm::ParameterSet>("pvExtras")) {
83  edm::ParameterSet pvExtras =
84  cfg.getParameter<edm::ParameterSet>("pvExtras");
85  // select is optional; in case it's not found no
86  // selection will be applied
87  if (pvExtras.existsAs<std::string>("select")) {
89  pvExtras.getParameter<std::string>("select")));
90  }
91  }
92  // muonExtras are optional; they may be omitted or empty
93  if (cfg.existsAs<edm::ParameterSet>("muonExtras")) {
94  edm::ParameterSet muonExtras =
95  cfg.getParameter<edm::ParameterSet>("muonExtras");
96  // select is optional; in case it's not found no
97  // selection will be applied
98  if (muonExtras.existsAs<std::string>("select")) {
100  muonExtras.getParameter<std::string>("select")));
101  }
102  // isolation is optional; in case it's not found no
103  // isolation will be applied
104  if (muonExtras.existsAs<std::string>("isolation")) {
106  muonExtras.getParameter<std::string>("isolation")));
107  }
108  }
109 
110  // jetExtras are optional; they may be omitted or
111  // empty
112  if (cfg.existsAs<edm::ParameterSet>("jetExtras")) {
113  edm::ParameterSet jetExtras =
114  cfg.getParameter<edm::ParameterSet>("jetExtras");
115  // jetCorrector is optional; in case it's not found
116  // the InputTag will remain empty
117  if (jetExtras.existsAs<std::string>("jetCorrector")) {
118  jetCorrector_ = jetExtras.getParameter<std::string>("jetCorrector");
119  }
120  // read jetID information if it exists
121  if (jetExtras.existsAs<edm::ParameterSet>("jetID")) {
122  edm::ParameterSet jetID =
123  jetExtras.getParameter<edm::ParameterSet>("jetID");
124  jetIDLabel_ = iC.consumes<reco::JetIDValueMap>(
125  jetID.getParameter<edm::InputTag>("label"));
127  jetID.getParameter<std::string>("select")));
128  }
129  // select is optional; in case it's not found no
130  // selection will be applied (only implemented for
131  // CaloJets at the moment)
132  if (jetExtras.existsAs<std::string>("select")) {
133  jetSelect_ = jetExtras.getParameter<std::string>("select");
134  }
135  // jetBDiscriminators are optional; in case they are
136  // not found the InputTag will remain empty; they
137  // consist of pairs of edm::JetFlavorAssociation's &
138  // corresponding working points
139  includeBTag_ = jetExtras.existsAs<edm::ParameterSet>("jetBTaggers");
140  if (includeBTag_) {
141 
142  edm::ParameterSet btagCSV =
143  jetExtras.getParameter<edm::ParameterSet>("jetBTaggers")
144  .getParameter<edm::ParameterSet>("cvsVertex");
145  btagCSV_ = iC.consumes<reco::JetTagCollection>(
146  btagCSV.getParameter<edm::InputTag>("label"));
147  btagCSVWP_ = btagCSV.getParameter<double>("workingPoint");
148  }
149  }
150 
151  // triggerExtras are optional; they may be omitted or empty
152  if (cfg.existsAs<edm::ParameterSet>("triggerExtras")) {
153  edm::ParameterSet triggerExtras =
154  cfg.getParameter<edm::ParameterSet>("triggerExtras");
155  triggerTable_ = iC.consumes<edm::TriggerResults>(
156  triggerExtras.getParameter<edm::InputTag>("src"));
157  triggerPaths_ =
158  triggerExtras.getParameter<std::vector<std::string> >("paths");
159  }
160 
161  // massExtras is optional; in case it's not found no mass
162  // window cuts are applied for the same flavor monitor
163  // histograms
164  if (cfg.existsAs<edm::ParameterSet>("massExtras")) {
165  edm::ParameterSet massExtras =
166  cfg.getParameter<edm::ParameterSet>("massExtras");
167  lowerEdge_ = massExtras.getParameter<double>("lowerEdge");
168  upperEdge_ = massExtras.getParameter<double>("upperEdge");
169  }
170 
171  // setup the verbosity level for booking histograms;
172  // per default the verbosity level will be set to
173  // STANDARD. This will also be the chosen level in
174  // the case when the monitoring PSet is not found
176  if (cfg.existsAs<edm::ParameterSet>("monitoring")) {
178  cfg.getParameter<edm::ParameterSet>("monitoring");
179  if (monitoring.getParameter<std::string>("verbosity") == "DEBUG")
180  verbosity_ = DEBUG;
181  if (monitoring.getParameter<std::string>("verbosity") == "VERBOSE")
182  verbosity_ = VERBOSE;
183  if (monitoring.getParameter<std::string>("verbosity") == "STANDARD")
184  verbosity_ = STANDARD;
185  }
186  // and don't forget to do the histogram booking
187  directory_ = cfg.getParameter<std::string>("directory");
188  // book(ibooker);
189 }
190 
192  // set up the current directory path
193  std::string current(directory_);
194  current += label_;
195  ibooker.setCurrentFolder(current);
196 
197  // determine number of bins for trigger monitoring
198  unsigned int nPaths = triggerPaths_.size();
199 
200  // --- [STANDARD] --- //
201  // Run Number
202  hists_["RunNumb_"] = ibooker.book1D("RunNumber", "Run Nr.", 1.e4, 1.5e5, 3.e5);
203  // instantaneous luminosity
204  hists_["InstLumi_"] = ibooker.book1D("InstLumi", "Inst. Lumi.", 100, 0., 1.e3);
205  // number of selected primary vertices
206  hists_["pvMult_"] = ibooker.book1D("PvMult", "N_{pvs}", 100, 0., 100.);
207  // pt of the leading muon
208  hists_["muonPt_"] = ibooker.book1D("MuonPt", "pt(#mu)", 50, 0., 250.);
209  // muon multiplicity before std isolation
210  hists_["muonMult_"] = ibooker.book1D("MuonMult", "N_{All}(#mu)", 10, 0., 10.);
211  // muon multiplicity after std isolation
212  hists_["muonMultIso_"] = ibooker.book1D("MuonMultIso",
213  "N_{Iso}(#mu)", 10, 0., 10.);
214  // pt of the leading electron
215  hists_["elecPt_"] = ibooker.book1D("ElecPt", "pt(e)", 50, 0., 250.);
216  // electron multiplicity before std isolation
217  hists_["elecMult_"] = ibooker.book1D("ElecMult", "N_{All}(e)", 10, 0., 10.);
218  // electron multiplicity after std isolation
219  hists_["elecMultIso_"] = ibooker.book1D("ElecMultIso", "N_{Iso}(e)", 10, 0., 10.);
220  // multiplicity of jets with pt>20 (corrected to L2+L3)
221  hists_["jetMult_"] = ibooker.book1D("JetMult", "N_{30}(jet)", 10, 0., 10.);
222  // trigger efficiency estimates for single lepton triggers
223  hists_["triggerEff_"] = ibooker.book1D("TriggerEff",
224  "Eff(trigger)", nPaths, 0., nPaths);
225  // monitored trigger occupancy for single lepton triggers
226  hists_["triggerMon_"] = ibooker.book1D("TriggerMon",
227  "Mon(trigger)", nPaths, 0., nPaths);
228  // MET (calo)
229  hists_["metCalo_"] = ibooker.book1D("METCalo", "MET_{Calo}", 50, 0., 200.);
230  // W mass estimate
231  hists_["massW_"] = ibooker.book1D("MassW", "M(W)", 60, 0., 300.);
232  // Top mass estimate
233  hists_["massTop_"] = ibooker.book1D("MassTop", "M(Top)", 50, 0., 500.);
234  // b-tagged Top mass
235  hists_["massBTop_"] = ibooker.book1D("MassBTop", "M(Top, 1 b-tag)", 50, 0., 500.);
236  // set bin labels for trigger monitoring
238 
239  if (verbosity_ == STANDARD) return;
240 
241  // --- [VERBOSE] --- //
242  // eta of the leading muon
243  hists_["muonEta_"] = ibooker.book1D("MuonEta", "#eta(#mu)", 30, -3., 3.);
244  // relative isolation of the candidate muon (depending on the decay channel)
245  hists_["muonRelIso_"] = ibooker.book1D(
246  "MuonRelIso", "Iso_{Rel}(#mu) (#Delta#beta Corrected)", 50, 0., 1.);
247  // eta of the leading electron
248  hists_["elecEta_"] = ibooker.book1D("ElecEta", "#eta(e)", 30, -3., 3.);
249  // std isolation variable of the leading electron
250  hists_["elecRelIso_"] = ibooker.book1D("ElecRelIso", "Iso_{Rel}(e)", 50, 0., 1.);
251  // multiplicity of btagged jets (for track counting high efficiency) with
252  // pt(L2L3)>30
253  // hists_["jetMultBEff_"] = ibooker.book1D("JetMultBEff",
254  // "N_{30}(TCHE)", 10, 0., 10.);
255  // btag discriminator for track counting high efficiency for jets with
256  // pt(L2L3)>30
257  //hists_["jetBDiscEff_"] = ibooker.book1D("JetBDiscEff",
258  // "Disc_{TCHE}(jet)", 100, 0., 10.);
259  // eta of the 1. leading jet (corrected to L2+L3)
260  hists_["jet1Eta_"] = ibooker.book1D("Jet1Eta", "#eta_{L2L3}(jet1)", 60, -3., 3.);
261  // pt of the 1. leading jet (corrected to L2+L3)
262  hists_["jet1Pt_"] = ibooker.book1D("Jet1Pt", "pt_{L2L3}(jet1)", 60, 0., 300.);
263  // eta of the 2. leading jet (corrected to L2+L3)
264  hists_["jet2Eta_"] = ibooker.book1D("Jet2Eta", "#eta_{L2L3}(jet2)", 60, -3., 3.);
265  // pt of the 2. leading jet (corrected to L2+L3)
266  hists_["jet2Pt_"] = ibooker.book1D("Jet2Pt", "pt_{L2L3}(jet2)", 60, 0., 300.);
267  // eta of the 3. leading jet (corrected to L2+L3)
268  hists_["jet3Eta_"] = ibooker.book1D("Jet3Eta", "#eta_{L2L3}(jet3)", 60, -3., 3.);
269  // pt of the 3. leading jet (corrected to L2+L3)
270  hists_["jet3Pt_"] = ibooker.book1D("Jet3Pt", "pt_{L2L3}(jet3)", 60, 0., 300.);
271  // eta of the 4. leading jet (corrected to L2+L3)
272  hists_["jet4Eta_"] = ibooker.book1D("Jet4Eta", "#eta_{L2L3}(jet4)", 60, -3., 3.);
273  // pt of the 4. leading jet (corrected to L2+L3)
274  hists_["jet4Pt_"] = ibooker.book1D("Jet4Pt", "pt_{L2L3}(jet4)", 60, 0., 300.);
275  // MET (tc)
276  hists_["metTC_"] = ibooker.book1D("METTC", "MET_{TC}", 50, 0., 200.);
277  // MET (pflow)
278  hists_["metPflow_"] = ibooker.book1D("METPflow", "MET_{Pflow}", 50, 0., 200.);
279  // dz for muons (to suppress cosmis)
280  hists_["muonDelZ_"] = ibooker.book1D("MuonDelZ", "d_{z}(#mu)", 50, -25., 25.);
281  // dxy for muons (to suppress cosmics)
282  hists_["muonDelXY_"] = ibooker.book2D("MuonDelXY",
283  "d_{xy}(#mu)", 50, -0.1, 0.1, 50, -0.1, 0.1);
284 
285  // set axes titles for dxy for muons
286  hists_["muonDelXY_"]->setAxisTitle("x [cm]", 1);
287  hists_["muonDelXY_"]->setAxisTitle("y [cm]", 2);
288 
289  if (verbosity_ == VERBOSE) return;
290 
291  // --- [DEBUG] --- //
292  // charged hadron isolation component of the candidate muon (depending on the
293  // decay channel)
294  hists_["muonChHadIso_"] = ibooker.book1D("MuonChHadIsoComp",
295  "ChHad_{IsoComponent}(#mu)", 50, 0., 5.);
296  // neutral hadron isolation component of the candidate muon (depending on the
297  // decay channel)
298  hists_["muonNeHadIso_"] = ibooker.book1D("MuonNeHadIsoComp",
299  "NeHad_{IsoComponent}(#mu)", 50, 0., 5.);
300  // photon isolation component of the candidate muon (depending on the decay
301  // channel)
302  hists_["muonPhIso_"] = ibooker.book1D("MuonPhIsoComp",
303  "Photon_{IsoComponent}(#mu)", 50, 0., 5.);
304  // charged hadron isolation component of the candidate electron (depending on
305  // the decay channel)
306  hists_["elecChHadIso_"] = ibooker.book1D("ElectronChHadIsoComp",
307  "ChHad_{IsoComponent}(e)", 50, 0., 5.);
308  // neutral hadron isolation component of the candidate electron (depending on
309  // the decay channel)
310  hists_["elecNeHadIso_"] = ibooker.book1D("ElectronNeHadIsoComp",
311  "NeHad_{IsoComponent}(e)", 50, 0., 5.);
312  // photon isolation component of the candidate electron (depending on the
313  // decay channel)
314  hists_["elecPhIso_"] = ibooker.book1D("ElectronPhIsoComp",
315  "Photon_{IsoComponent}(e)", 50, 0., 5.);
316 
317  // multiplicity for combined secondary vertex
318  hists_["jetMultCSVtx_"] = ibooker.book1D("JetMultCSV", "N_{30}(CSV)", 10, 0., 10.);
319  // btag discriminator for combined secondary vertex
320  hists_["jetBCVtx_"] = ibooker.book1D("JetDiscCSV",
321  "Disc_{CSV}(JET)", 100, -1., 2.);
322  // pt of the 1. leading jet (uncorrected)
323  hists_["jet1PtRaw_"] = ibooker.book1D("Jet1PtRaw", "pt_{Raw}(jet1)", 60, 0., 300.);
324  // pt of the 2. leading jet (uncorrected)
325  hists_["jet2PtRaw_"] = ibooker.book1D("Jet2PtRaw", "pt_{Raw}(jet2)", 60, 0., 300.);
326  // pt of the 3. leading jet (uncorrected)
327  hists_["jet3PtRaw_"] = ibooker.book1D("Jet3PtRaw", "pt_{Raw}(jet3)", 60, 0., 300.);
328  // pt of the 4. leading jet (uncorrected)
329  hists_["jet4PtRaw_"] = ibooker.book1D("Jet4PtRaw", "pt_{Raw}(jet4)", 60, 0., 300.);
330  // selected events
331  hists_["eventLogger_"] = ibooker.book2D("EventLogger",
332  "Logged Events", 9, 0., 9., 10, 0., 10.);
333 
334  // set axes titles for selected events
335  hists_["eventLogger_"]->getTH1()->SetOption("TEXT");
336  hists_["eventLogger_"]->setBinLabel(1, "Run", 1);
337  hists_["eventLogger_"]->setBinLabel(2, "Block", 1);
338  hists_["eventLogger_"]->setBinLabel(3, "Event", 1);
339  hists_["eventLogger_"]->setBinLabel(4, "pt_{L2L3}(jet1)", 1);
340  hists_["eventLogger_"]->setBinLabel(5, "pt_{L2L3}(jet2)", 1);
341  hists_["eventLogger_"]->setBinLabel(6, "pt_{L2L3}(jet3)", 1);
342  hists_["eventLogger_"]->setBinLabel(7, "pt_{L2L3}(jet4)", 1);
343  hists_["eventLogger_"]->setBinLabel(8, "M_{W}", 1);
344  hists_["eventLogger_"]->setBinLabel(9, "M_{Top}", 1);
345  hists_["eventLogger_"]->setAxisTitle("logged evts", 2);
346  return;
347 }
348 
350  const edm::EventSetup& setup) {
351  // fetch trigger event if configured such
353 
355  if (!event.getByToken(triggerTable_, triggerTable)) return;
356  }
357 
358  /*
359  ------------------------------------------------------------
360 
361  Primary Vertex Monitoring
362 
363  ------------------------------------------------------------
364  */
365  // fill monitoring plots for primary verices
367  if (!event.getByToken(pvs_, pvs)) return;
368  unsigned int pvMult = 0;
369  for (edm::View<reco::Vertex>::const_iterator pv = pvs->begin();
370  pv != pvs->end(); ++pv) {
371  if (!pvSelect_ || (*pvSelect_)(*pv)) pvMult++;
372  }
373  fill("pvMult_", pvMult);
374 
375  /*
376  ------------------------------------------------------------
377 
378  Run and Inst. Luminosity information (Inst. Lumi. filled now with a dummy
379  value=5.0)
380 
381  ------------------------------------------------------------
382  */
383  if (!event.eventAuxiliary().run()) return;
384  fill("RunNumb_", event.eventAuxiliary().run());
385 
386  double dummy = 5.;
387  fill("InstLumi_", dummy);
388 
389  /*
390  ------------------------------------------------------------
391 
392  Electron Monitoring
393 
394  ------------------------------------------------------------
395  */
396 
397  // fill monitoring plots for electrons
399  if (!event.getByToken(elecs_, elecs)) return;
400 
401  // check availability of electron id
403  if (!electronId_.isUninitialized()) {
404  if (!event.getByToken(electronId_, electronId)) return;
405  }
406 
407  // loop electron collection
408  unsigned int eMult = 0, eMultIso = 0;
409  std::vector<const reco::PFCandidate*> isoElecs;
410  for (edm::View<reco::PFCandidate>::const_iterator elec = elecs->begin();
411  elec != elecs->end(); ++elec) {
412  if (elec->gsfElectronRef().isNull()) {
413  continue;
414  }
415  reco::GsfElectronRef gsf_el = elec->gsfElectronRef();
416  // restrict to electrons with good electronId
417  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[gsf_el] >=
418  eidCutValue_)) {
419  if (!elecSelect_ || (*elecSelect_)(*elec)) {
420 
421  double el_ChHadIso = gsf_el->pfIsolationVariables().sumChargedHadronPt;
422  double el_NeHadIso = gsf_el->pfIsolationVariables().sumNeutralHadronEt;
423  double el_PhIso = gsf_el->pfIsolationVariables().sumPhotonEt;
424  double el_pfRelIso =
425  (el_ChHadIso +
426  max(0., el_NeHadIso + el_PhIso -
427  0.5 * gsf_el->pfIsolationVariables().sumPUPt)) /
428  gsf_el->pt();
429  if (eMult == 0) {
430  // restrict to the leading electron
431  fill("elecPt_", elec->pt());
432  fill("elecEta_", elec->eta());
433  fill("elecRelIso_", el_pfRelIso);
434  fill("elecChHadIso_", el_ChHadIso);
435  fill("elecNeHadIso_", el_NeHadIso);
436  fill("elecPhIso_", el_PhIso);
437  }
438  // in addition to the multiplicity counter buffer the iso
439  // electron candidates for later overlap check with jets
440  ++eMult;
441  if (!elecIso_ || (*elecIso_)(*elec)) {
442  isoElecs.push_back(&(*elec));
443  ++eMultIso;
444  }
445  }
446  }
447  }
448  fill("elecMult_", eMult);
449  fill("elecMultIso_", eMultIso);
450 
451  /*
452  ------------------------------------------------------------
453 
454  Muon Monitoring
455 
456  ------------------------------------------------------------
457  */
458 
459  // fill monitoring plots for muons
460  unsigned int mMult = 0, mMultIso = 0;
461 
464 
465  if (!event.getByToken(muons_, muons)) return;
466 
467  for (edm::View<reco::PFCandidate>::const_iterator muonit = muons->begin();
468  muonit != muons->end(); ++muonit) {
469 
470  if (muonit->muonRef().isNull()) continue;
471  reco::MuonRef muon = muonit->muonRef();
472 
473  // restrict to globalMuons
474  if (muon->isGlobalMuon()) {
475  fill("muonDelZ_", muon->innerTrack()->vz()); // CB using inner track!
476  fill("muonDelXY_", muon->innerTrack()->vx(), muon->innerTrack()->vy());
477 
478  // apply preselection
479  if (!muonSelect_ || (*muonSelect_)(*muonit)) {
480 
481  double chHadPt = muon->pfIsolationR04().sumChargedHadronPt;
482  double neHadEt = muon->pfIsolationR04().sumNeutralHadronEt;
483  double phoEt = muon->pfIsolationR04().sumPhotonEt;
484 
485  double pfRelIso =
486  (chHadPt +
487  max(0., neHadEt + phoEt - 0.5 * muon->pfIsolationR04().sumPUPt)) /
488  muon->pt(); // CB dBeta corrected iso!
489 
490  if (mMult == 0) {
491  // restrict to leading muon
492  fill("muonPt_", muon->pt());
493  fill("muonEta_", muon->eta());
494 
495  fill("muonRelIso_", pfRelIso);
496 
497  fill("muonChHadIso_", chHadPt);
498  fill("muonNeHadIso_", neHadEt);
499  fill("muonPhIso_", phoEt);
500  }
501  ++mMult;
502  if (!muonIso_ || (*muonIso_)(*muonit)) ++mMultIso;
503  }
504  }
505  }
506  fill("muonMult_", mMult);
507  fill("muonMultIso_", mMultIso);
508 
509  /*
510  ------------------------------------------------------------
511 
512  Jet Monitoring
513 
514  ------------------------------------------------------------
515  */
516 
517  // check availability of the btaggers
518  edm::Handle<reco::JetTagCollection> btagEff, btagPur, btagVtx, btagCSV;
519  if (includeBTag_) {
520 
521  if (!event.getByToken(btagCSV_, btagCSV)) return;
522  }
523  // load jet corrector if configured such
524  const JetCorrector* corrector = 0;
525  if (!jetCorrector_.empty()) {
526  // check whether a jet correcto is in the event setup or not
528  JetCorrectionsRecord>())) {
529  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
530  } else {
531  edm::LogVerbatim("TopSingleLeptonDQM")
532  << "\n"
533  << "-----------------------------------------------------------------"
534  "-------------------- \n"
535  << " No JetCorrectionsRecord available from EventSetup: "
536  " \n"
537  << " - Jets will not be corrected. "
538  " \n"
539  << " - If you want to change this add the following lines to your "
540  "cfg file: \n"
541  << " "
542  " \n"
543  << " ## load jet corrections "
544  " \n"
545  << " "
546  "process.load(\"JetMETCorrections.Configuration."
547  "JetCorrectionServicesAllAlgos_cff\") \n"
548  << " process.prefer(\"ak5CaloL2L3\") "
549  " \n"
550  << " "
551  " \n"
552  << "-----------------------------------------------------------------"
553  "-------------------- \n";
554  }
555  }
556 
557  // loop jet collection
558  std::vector<reco::Jet> correctedJets;
559  std::vector<double> JetTagValues;
560  unsigned int mult = 0, multCSV = 0;
561 
563  if (!event.getByToken(jets_, jets)) {
564  return;
565  }
566 
568  if (jetIDSelect_) {
569  if (!event.getByToken(jetIDLabel_, jetID)) return;
570  }
571 
572  for (edm::View<reco::Jet>::const_iterator jet = jets->begin();
573  jet != jets->end(); ++jet) {
574  // check jetID for calo jets
575  unsigned int idx = jet - jets->begin();
576  if (jetIDSelect_ &&
577  dynamic_cast<const reco::CaloJet*>(jets->refAt(idx).get())) {
578  if (!(*jetIDSelect_)((*jetID)[jets->refAt(idx)])) continue;
579  }
580  // chekc additional jet selection for calo, pf and bare reco jets
581  if (dynamic_cast<const reco::CaloJet*>(&*jet)) {
582  reco::CaloJet sel = dynamic_cast<const reco::CaloJet&>(*jet);
583  sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
585  if (!jetSelect(sel)) {
586  continue;
587  }
588  } else if (dynamic_cast<const reco::PFJet*>(&*jet)) {
589  reco::PFJet sel = dynamic_cast<const reco::PFJet&>(*jet);
590  sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
592  if (!jetSelect(sel)) continue;
593  } else {
594  reco::Jet sel = *jet;
595  sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
597  if (!jetSelect(sel)) continue;
598  }
599 
600  // prepare jet to fill monitor histograms
601  reco::Jet monitorJet = *jet;
602  monitorJet.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
603  correctedJets.push_back(monitorJet);
604  ++mult; // determine jet multiplicity
605  if (includeBTag_) {
606  // fill b-discriminators
607  edm::RefToBase<reco::Jet> jetRef = jets->refAt(idx);
608 
609  fill("jetBCVtx_", (*btagCSV)[jetRef]);
610  if ((*btagCSV)[jetRef] > btagCSVWP_) ++multCSV;
611 
612  // Fill a vector with Jet b-tag WP for later M3+1tag calculation: CSV
613  // tagger
614  JetTagValues.push_back((*btagCSV)[jetRef]);
615  }
616  // fill pt (raw or L2L3) for the leading four jets
617  if (idx == 0) {
618  fill("jet1Pt_", monitorJet.pt());
619  fill("jet1PtRaw_", jet->pt());
620  fill("jet1Eta_", monitorJet.eta());
621  };
622  if (idx == 1) {
623  fill("jet2Pt_", monitorJet.pt());
624  fill("jet2PtRaw_", jet->pt());
625  fill("jet2Eta_", monitorJet.eta());
626  }
627  if (idx == 2) {
628  fill("jet3Pt_", monitorJet.pt());
629  fill("jet3PtRaw_", jet->pt());
630  fill("jet3Eta_", monitorJet.eta());
631  }
632  if (idx == 3) {
633  fill("jet4Pt_", monitorJet.pt());
634  fill("jet4PtRaw_", jet->pt());
635  fill("jet4Eta_", monitorJet.eta());
636  }
637  }
638  fill("jetMult_", mult);
639 
640  fill("jetMultCSVtx_", multCSV);
641 
642  /*
643  ------------------------------------------------------------
644 
645  MET Monitoring
646 
647  ------------------------------------------------------------
648  */
649 
650  // fill monitoring histograms for met
651  for (std::vector<edm::EDGetTokenT<edm::View<reco::MET> > >::const_iterator
652  met_ = mets_.begin();
653  met_ != mets_.end(); ++met_) {
655  if (!event.getByToken(*met_, met)) continue;
656  if (met->begin() != met->end()) {
657  unsigned int idx = met_ - mets_.begin();
658  if (idx == 0) fill("metCalo_", met->begin()->et());
659  if (idx == 1) fill("metTC_", met->begin()->et());
660  if (idx == 2) fill("metPflow_", met->begin()->et());
661  }
662  }
663 
664  /*
665  ------------------------------------------------------------
666 
667  Event Monitoring
668 
669  ------------------------------------------------------------
670  */
671 
672  // fill W boson and top mass estimates
673 
674  Calculate eventKinematics(MAXJETS, WMASS);
675  double wMass = eventKinematics.massWBoson(correctedJets);
676  double topMass = eventKinematics.massTopQuark(correctedJets);
677  if (wMass >= 0 && topMass >= 0) {
678  fill("massW_", wMass);
679  fill("massTop_", topMass);
680  }
681 
682  // Fill M3 with Btag (CSV Tight) requirement
683 
684  if (!includeBTag_) return;
685  if (correctedJets.size() != JetTagValues.size()) return;
686  double btopMass =
687  eventKinematics.massBTopQuark(correctedJets, JetTagValues, btagCSVWP_);
688  if (btopMass >= 0) fill("massBTop_", btopMass);
689 
690  // fill plots for trigger monitoring
691  if ((lowerEdge_ == -1. && upperEdge_ == -1.) ||
692  (lowerEdge_ < wMass && wMass < upperEdge_)) {
694  fill(event, *triggerTable, "trigger", triggerPaths_);
695  if (logged_ <= hists_.find("eventLogger_")->second->getNbinsY()) {
696  // log runnumber, lumi block, event number & some
697  // more pysics infomation for interesting events
698  fill("eventLogger_", 0.5, logged_ + 0.5, event.eventAuxiliary().run());
699  fill("eventLogger_", 1.5, logged_ + 0.5,
700  event.eventAuxiliary().luminosityBlock());
701  fill("eventLogger_", 2.5, logged_ + 0.5, event.eventAuxiliary().event());
702  if (correctedJets.size() > 0)
703  fill("eventLogger_", 3.5, logged_ + 0.5, correctedJets[0].pt());
704  if (correctedJets.size() > 1)
705  fill("eventLogger_", 4.5, logged_ + 0.5, correctedJets[1].pt());
706  if (correctedJets.size() > 2)
707  fill("eventLogger_", 5.5, logged_ + 0.5, correctedJets[2].pt());
708  if (correctedJets.size() > 3)
709  fill("eventLogger_", 6.5, logged_ + 0.5, correctedJets[3].pt());
710  fill("eventLogger_", 7.5, logged_ + 0.5, wMass);
711  fill("eventLogger_", 8.5, logged_ + 0.5, topMass);
712  ++logged_;
713  }
714  }
715 }
716 }
717 
719  : vertexSelect_(nullptr),
720  beamspot_(""),
721  beamspotSelect_(nullptr),
722  MuonStep(nullptr),
723  ElectronStep(nullptr),
724  PvStep(nullptr),
725  METStep(nullptr) {
726  JetSteps.clear();
727  CaloJetSteps.clear();
728  PFJetSteps.clear();
729  // configure preselection
730  edm::ParameterSet presel =
731  cfg.getParameter<edm::ParameterSet>("preselection");
732  if (presel.existsAs<edm::ParameterSet>("trigger")) {
734  presel.getParameter<edm::ParameterSet>("trigger");
735  triggerTable__ = consumes<edm::TriggerResults>(
736  trigger.getParameter<edm::InputTag>("src"));
737  triggerPaths_ = trigger.getParameter<std::vector<std::string> >("select");
738  }
739  if (presel.existsAs<edm::ParameterSet>("beamspot")) {
741  presel.getParameter<edm::ParameterSet>("beamspot");
742  beamspot_ = beamspot.getParameter<edm::InputTag>("src");
743  beamspot__ =
744  consumes<reco::BeamSpot>(beamspot.getParameter<edm::InputTag>("src"));
746  beamspot.getParameter<std::string>("select")));
747  }
748 
749  // conifgure the selection
750  sel_ = cfg.getParameter<std::vector<edm::ParameterSet> >("selection");
751  setup_ = cfg.getParameter<edm::ParameterSet>("setup");
752  for (unsigned int i = 0; i < sel_.size(); ++i) {
753  selectionOrder_.push_back(sel_.at(i).getParameter<std::string>("label"));
754  selection_[selectionStep(selectionOrder_.back())] = std::make_pair(
755  sel_.at(i),
756  std::unique_ptr<TopSingleLepton::MonitorEnsemble>(
758  selectionStep(selectionOrder_.back()).c_str(),
760  }
761  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin();
762  selIt != selectionOrder_.end(); ++selIt) {
763  std::string key = selectionStep(*selIt), type = objectType(*selIt);
764  if (selection_.find(key) != selection_.end()) {
765  if (type == "muons") {
767  consumesCollector()));
768  }
769  if (type == "elecs") {
772  }
773  if (type == "pvs") {
775  consumesCollector()));
776  }
777  if (type == "jets") {
778  JetSteps.push_back(std::unique_ptr<SelectionStep<reco::Jet>>(
780  }
781  if (type == "jets/pf") {
782  PFJetSteps.push_back(std::unique_ptr<SelectionStep<reco::PFJet>>(
784  }
785  if (type == "jets/calo") {
786  CaloJetSteps.push_back(std::unique_ptr<SelectionStep<reco::CaloJet>>(
788  }
789  if (type == "met") {
791  consumesCollector()));
792  }
793  }
794  }
795 }
797  edm::Run const &, edm::EventSetup const & ){
798 
799  for (auto selIt = selection_.begin(); selIt != selection_.end(); ++selIt) {
800  selIt->second.second->book(ibooker);
801  }
802 }
804  const edm::EventSetup& setup) {
805 
808  if (!event.getByToken(triggerTable__, triggerTable)) return;
809  if (!accept(event, *triggerTable, triggerPaths_)) return;
810  }
811  if (!beamspot__.isUninitialized()) {
813  if (!event.getByToken(beamspot__, beamspot)) return;
814  if (!(*beamspotSelect_)(*beamspot)) return;
815  }
816  // cout<<" apply selection steps"<<endl;
817  unsigned int passed = 0;
818  unsigned int nJetSteps = -1;
819  unsigned int nPFJetSteps = -1;
820  unsigned int nCaloJetSteps = -1;
821  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin();
822  selIt != selectionOrder_.end(); ++selIt) {
823  std::string key = selectionStep(*selIt), type = objectType(*selIt);
824  if (selection_.find(key) != selection_.end()) {
825  if (type == "empty") {
826  selection_[key].second->fill(event, setup);
827  }
828  if (type == "muons" && MuonStep != 0) {
829  if (MuonStep->select(event)) {
830  ++passed;
831  // cout<<"selected event! "<<selection_[key].second<<endl;
832  selection_[key].second->fill(event, setup);
833  } else
834  break;
835  }
836  // cout<<" apply selection steps 2"<<endl;
837  if (type == "elecs" && ElectronStep != 0) {
838  // cout<<"In electrons ..."<<endl;
839  if (ElectronStep->select(event, "electron")) {
840  ++passed;
841  selection_[key].second->fill(event, setup);
842  } else
843  break;
844  }
845  // cout<<" apply selection steps 3"<<endl;
846  if (type == "pvs" && PvStep != 0) {
847  if (PvStep->selectVertex(event)) {
848  ++passed;
849  selection_[key].second->fill(event, setup);
850  } else
851  break;
852  }
853  // cout<<" apply selection steps 4"<<endl;
854  if (type == "jets") {
855  nJetSteps++;
856  if (JetSteps[nJetSteps] != NULL) {
857  if (JetSteps[nJetSteps]->select(event, setup)) {
858  ++passed;
859  selection_[key].second->fill(event, setup);
860  } else
861  break;
862  }
863  }
864  if (type == "jets/pf") {
865  nPFJetSteps++;
866  if (PFJetSteps[nPFJetSteps] != NULL) {
867  if (PFJetSteps[nPFJetSteps]->select(event, setup)) {
868  ++passed;
869  selection_[key].second->fill(event, setup);
870  } else
871  break;
872  }
873  }
874  if (type == "jets/calo") {
875  nCaloJetSteps++;
876  if (CaloJetSteps[nCaloJetSteps] != NULL) {
877  if (CaloJetSteps[nCaloJetSteps]->select(event, setup)) {
878  ++passed;
879  selection_[key].second->fill(event, setup);
880  } else
881  break;
882  }
883  }
884  if (type == "met" && METStep != 0) {
885  if (METStep->select(event)) {
886  ++passed;
887  selection_[key].second->fill(event, setup);
888  } else
889  break;
890  }
891  }
892  }
893 }
894 
895 // Local Variables:
896 // show-trailing-whitespace: t
897 // truncate-lines: t
898 // End:
std::map< std::string, MonitorElement * > hists_
histogram container
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
virtual double pt() const final
transverse momentum
int logged_
number of logged interesting events
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
EventAuxiliary const & eventAuxiliary() const override
Definition: Event.h:78
edm::EDGetTokenT< edm::View< reco::PFCandidate > > muons_
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
Jets made from CaloTowers.
Definition: CaloJet.h:29
std::unique_ptr< SelectionStep< reco::PFCandidate > > ElectronStep
virtual void scaleEnergy(double fScale)
scale energy of the jet
virtual void analyze(const edm::Event &event, const edm::EventSetup &setup) override
do this during the event loop
std::unique_ptr< StringCutObjectSelector< reco::BeamSpot > > beamspotSelect_
string cut selector
virtual double eta() const final
momentum pseudorapidity
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::vector< std::string > triggerPaths_
Base class for all types of Jets.
Definition: Jet.h:20
edm::EDGetTokenT< edm::TriggerResults > triggerTable_
trigger table
std::unique_ptr< StringCutObjectSelector< reco::JetID > > jetIDSelect_
extra jetID selection on calo jets
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > muonSelect_
extra selection on muons
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > elecSelect_
extra selection on electrons
RunNumber_t run() const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
TopSingleLeptonDQM(const edm::ParameterSet &cfg)
default constructor
#define NULL
Definition: scimark2.h:8
edm::EDGetTokenT< reco::BeamSpot > beamspot__
std::map< std::string, std::pair< edm::ParameterSet, std::unique_ptr< TopSingleLepton::MonitorEnsemble > > > selection_
edm::EDGetTokenT< reco::JetTagCollection > btagCSV_
#define nullptr
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
Jets made from PFObjects.
Definition: PFJet.h:21
std::vector< std::string > triggerPaths_
trigger paths
std::vector< std::string > selectionOrder_
std::vector< edm::EDGetTokenT< edm::View< reco::MET > > > mets_
considers a vector of METs
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > elecIso_
extra isolation criterion on electron
std::string selectionStep(const std::string &label)
edm::EDGetTokenT< edm::View< reco::Jet > > jets_
input sources for monitoring
LuminosityBlockNumber_t luminosityBlock() const
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:91
Level verbosity_
verbosity level for booking
static const double WMASS
double lowerEdge_
mass window upper and lower edge
std::vector< std::unique_ptr< SelectionStep< reco::Jet > > > JetSteps
Helper class for the calculation of a top and a W boson mass estime.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::InputTag beamspot_
beamspot
vector< PseudoJet > jets
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
def pv(vc)
Definition: MetAnalyzer.py:6
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > elecs_
void book(DQMStore::IBooker &ibooker)
book histograms in subdirectory directory
edm::EDGetTokenT< edm::TriggerResults > triggerTable__
trigger table
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
std::unique_ptr< SelectionStep< reco::PFCandidate > > MuonStep
std::unique_ptr< SelectionStep< reco::MET > > METStep
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
met
===> hadronic RAZOR
std::string label_
instance label
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:50
Templated helper class to allow a selection on a certain object collection.
std::string objectType(const std::string &label)
std::unique_ptr< StringCutObjectSelector< reco::Vertex > > pvSelect_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
void fill(const edm::Event &event, const edm::EventSetup &setup)
fill monitor histograms with electronId and jetCorrections
static EventSetupRecordKey makeKey()
std::vector< edm::ParameterSet > sel_
bool isUninitialized() const
Definition: EDGetToken.h:73
edm::ParameterSet setup_
void triggerBinLabels(std::string channel, const std::vector< std::string > labels)
set configurable labels for trigger monitoring histograms
std::string jetCorrector_
jetCorrector
static const unsigned int MAXJETS
std::vector< std::unique_ptr< SelectionStep< reco::PFJet > > > PFJetSteps
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label
EventNumber_t event() const
std::unique_ptr< SelectionStep< reco::Vertex > > PvStep
Definition: event.py:1
Definition: Run.h:42
std::vector< std::unique_ptr< SelectionStep< reco::CaloJet > > > CaloJetSteps
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > muonIso_
extra isolation criterion on muon