CMS 3D CMS Logo

TopDiLeptonOfflineDQM.cc
Go to the documentation of this file.
1 //#include <algorithm>
7 
8 #include <memory>
9 
17 
18 namespace TopDiLeptonOffline {
19 
21  : label_(label),
22  eidCutValue_(0.),
23  elecIso_(nullptr),
24  elecSelect_(nullptr),
25  muonIso_(nullptr),
26  muonSelect_(nullptr),
27  jetIDSelect_(nullptr),
28  lowerEdge_(-1.),
29  upperEdge_(-1.),
30  elecMuLogged_(0),
31  diMuonLogged_(0),
32  diElecLogged_(0) {
33  // sources have to be given; this PSet is not optional
34  edm::ParameterSet sources = cfg.getParameter<edm::ParameterSet>("sources");
35  muons_ = iC.consumes<edm::View<reco::PFCandidate>>(sources.getParameter<edm::InputTag>("muons"));
36  elecs_ = iC.consumes<edm::View<reco::PFCandidate>>(sources.getParameter<edm::InputTag>("elecs"));
37  jets_ = iC.consumes<edm::View<reco::Jet>>(sources.getParameter<edm::InputTag>("jets"));
38  for (edm::InputTag const& tag : sources.getParameter<std::vector<edm::InputTag>>("mets"))
39  mets_.push_back(iC.consumes<edm::View<reco::MET>>(tag));
40 
41  // elecExtras are optional; they may be omitted or empty
42  if (cfg.existsAs<edm::ParameterSet>("elecExtras")) {
43  edm::ParameterSet elecExtras = cfg.getParameter<edm::ParameterSet>("elecExtras");
44  // select is optional; in case it's not found no
45  // selection will be applied
46  if (elecExtras.existsAs<std::string>("select")) {
47  elecSelect_ = std::make_unique<StringCutObjectSelector<reco::PFCandidate>>(
48  elecExtras.getParameter<std::string>("select"));
49  }
50  // isolation is optional; in case it's not found no
51  // isolation will be applied
52  if (elecExtras.existsAs<std::string>("isolation")) {
53  elecIso_ = std::make_unique<StringCutObjectSelector<reco::PFCandidate>>(
54  elecExtras.getParameter<std::string>("isolation"));
55  }
56  // electronId is optional; in case it's not found the
57  // InputTag will remain empty
58  if (elecExtras.existsAs<edm::ParameterSet>("electronId")) {
59  edm::ParameterSet elecId = elecExtras.getParameter<edm::ParameterSet>("electronId");
60  electronId_ = iC.consumes<edm::ValueMap<float>>(elecId.getParameter<edm::InputTag>("src"));
61  eidCutValue_ = elecId.getParameter<double>("cutValue");
62  // eidPattern_= elecId.getParameter<int>("pattern");
63  }
64  }
65  // muonExtras are optional; they may be omitted or empty
66  if (cfg.existsAs<edm::ParameterSet>("muonExtras")) {
67  edm::ParameterSet muonExtras = cfg.getParameter<edm::ParameterSet>("muonExtras");
68  // select is optional; in case it's not found no
69  // selection will be applied
70  if (muonExtras.existsAs<std::string>("select")) {
71  muonSelect_ = std::make_unique<StringCutObjectSelector<reco::PFCandidate, true>>(
72  muonExtras.getParameter<std::string>("select"));
73  }
74  // isolation is optional; in case it's not found no
75  // isolation will be applied
76  if (muonExtras.existsAs<std::string>("isolation")) {
77  muonIso_ = std::make_unique<StringCutObjectSelector<reco::PFCandidate, true>>(
78  muonExtras.getParameter<std::string>("isolation"));
79  }
80  }
81  // jetExtras are optional; they may be omitted or empty
82  if (cfg.existsAs<edm::ParameterSet>("jetExtras")) {
83  edm::ParameterSet jetExtras = cfg.getParameter<edm::ParameterSet>("jetExtras");
84  // jetCorrector is optional; in case it's not found
85  // the InputTag will remain empty
86  if (jetExtras.existsAs<std::string>("jetCorrector")) {
88  iC.consumes<reco::JetCorrector>(edm::InputTag(jetExtras.getParameter<std::string>("jetCorrector")));
89  }
90  // read jetID information if it exists
91  if (jetExtras.existsAs<edm::ParameterSet>("jetID")) {
92  edm::ParameterSet jetID = jetExtras.getParameter<edm::ParameterSet>("jetID");
93  jetIDLabel_ = iC.consumes<reco::JetIDValueMap>(jetID.getParameter<edm::InputTag>("label"));
94  jetIDSelect_ =
95  std::make_unique<StringCutObjectSelector<reco::JetID>>(jetID.getParameter<std::string>("select"));
96  }
97  // select is optional; in case it's not found no
98  // selection will be applied (only implemented for
99  // CaloJets at the moment)
100  if (jetExtras.existsAs<std::string>("select")) {
101  jetSelect_ = jetExtras.getParameter<std::string>("select");
102  }
103  }
104  // triggerExtras are optional; they may be omitted or empty
105  if (cfg.existsAs<edm::ParameterSet>("triggerExtras")) {
106  edm::ParameterSet triggerExtras = cfg.getParameter<edm::ParameterSet>("triggerExtras");
107  triggerTable_ = iC.consumes<edm::TriggerResults>(triggerExtras.getParameter<edm::InputTag>("src"));
108  elecMuPaths_ = triggerExtras.getParameter<std::vector<std::string>>("pathsELECMU");
109  diMuonPaths_ = triggerExtras.getParameter<std::vector<std::string>>("pathsDIMUON");
110  }
111  // massExtras is optional; in case it's not found no mass
112  // window cuts are applied for the same flavor monitor
113  // histograms
114  if (cfg.existsAs<edm::ParameterSet>("massExtras")) {
115  edm::ParameterSet massExtras = cfg.getParameter<edm::ParameterSet>("massExtras");
116  lowerEdge_ = massExtras.getParameter<double>("lowerEdge");
117  upperEdge_ = massExtras.getParameter<double>("upperEdge");
118  }
119 
120  // setup the verbosity level for booking histograms;
121  // per default the verbosity level will be set to
122  // STANDARD. This will also be the chosen level in
123  // the case when the monitoring PSet is not found
125  if (cfg.existsAs<edm::ParameterSet>("monitoring")) {
126  edm::ParameterSet monitoring = cfg.getParameter<edm::ParameterSet>("monitoring");
127  if (monitoring.getParameter<std::string>("verbosity") == "DEBUG")
128  verbosity_ = DEBUG;
129  if (monitoring.getParameter<std::string>("verbosity") == "VERBOSE")
131  if (monitoring.getParameter<std::string>("verbosity") == "STANDARD")
133  }
134  // and don't forget to do the histogram booking
135  directory_ = cfg.getParameter<std::string>("directory");
136  }
137 
139  // set up the current directory path
140  std::string current(directory_);
141  current += label_;
142  ibooker.setCurrentFolder(current);
143 
144  // determine number of bins for trigger monitoring
145  unsigned int nElecMu = elecMuPaths_.size();
146  unsigned int nDiMuon = diMuonPaths_.size();
147 
148  // --- [STANDARD] --- //
149  // Run Number
150  hists_["RunNumb_"] = ibooker.book1D("RunNumber", "Run Nr.", 1.e4, 1.5e5, 3.e5);
151  // invariant mass of opposite charge lepton pair (only filled for same flavor)
152  hists_["invMass_"] = ibooker.book1D("InvMass", "M(lep1, lep2)", 80, 0., 320.);
153  // invariant mass of opposite charge lepton pair (only filled for same flavor)
154  hists_["invMassLog_"] = ibooker.book1D("InvMassLog", "log_{10}(M(lep1, lep2))", 80, .1, 2.5);
155  // invariant mass of same charge lepton pair (log10 for low mass region, only
156  // filled for same flavor)
157  hists_["invMassWC_"] = ibooker.book1D("InvMassWC", "M_{WC}(L1, L2)", 80, 0., 320.);
158  // invariant mass of same charge lepton pair (log10 for low mass region, only
159  // filled for same flavor)
160  hists_["invMassWCLog_"] = ibooker.book1D("InvMassLogWC", "log_{10}(M_{WC})", 80, .1, 2.5);
161  // decay channel [1]: muon/muon, [2]:elec/elec, [3]:elec/muon
162  hists_["decayChannel_"] = ibooker.book1D("DecayChannel", "Decay Channel", 3, 0, 3);
163  // trigger efficiency estimates for the electron muon channel
164  hists_["elecMuEff_"] = ibooker.book1D("ElecMuEff", "Eff(e/#mu paths)", nElecMu, 0., nElecMu);
165  // monitored trigger occupancy for the electron muon channel
166  hists_["elecMuMon_"] = ibooker.book1D("ElecMuMon", "Mon(e/#mu paths)", nElecMu, 0., nElecMu);
167  // trigger efficiency estimates for the di muon channel
168  hists_["diMuonEff_"] = ibooker.book1D("DiMuonEff", "Eff(#mu/#mu paths)", nDiMuon, 0., nDiMuon);
169  // monitored trigger occupancy for the di muon channel
170  hists_["diMuonMon_"] = ibooker.book1D("DiMuonMon", "Mon(#mu/#mu paths)", nDiMuon, 0., nDiMuon);
171  // pt of the leading lepton
172  hists_["lep1Pt_"] = ibooker.book1D("Lep1Pt", "pt(lep1)", 50, 0., 200.);
173  // pt of the 2. leading lepton
174  hists_["lep2Pt_"] = ibooker.book1D("Lep2Pt", "pt(lep2)", 50, 0., 200.);
175  // multiplicity of jets with pt>30 (corrected to L2+L3)
176  hists_["jetMult_"] = ibooker.book1D("JetMult", "N_{30}(jet)", 21, -0.5, 20.5);
177  // MET (calo)
178  hists_["metCalo_"] = ibooker.book1D("METCalo", "MET_{Calo}", 50, 0., 200.);
179 
180  // set bin labels for trigger monitoring
183  // set bin labels for decayChannel_
184  hists_["decayChannel_"]->setBinLabel(1, "#mu e", 1);
185  hists_["decayChannel_"]->setBinLabel(2, "#mu #mu", 1);
186  hists_["decayChannel_"]->setBinLabel(3, "e e", 1);
187 
188  if (verbosity_ == STANDARD)
189  return;
190 
191  // --- [VERBOSE] --- //
192  // mean eta of the candidate leptons
193  hists_["sumEtaL1L2_"] = ibooker.book1D("SumEtaL1L2", "<#eta>(lep1, lep2)", 100, -5., 5.);
194  // deltaEta between the 2 candidate leptons
195  hists_["dEtaL1L2_"] = ibooker.book1D("DEtaL1L2", "#Delta#eta(lep1,lep2)", 80, -4., 4.);
196  // deltaPhi between the 2 candidate leptons
197  hists_["dPhiL1L2_"] = ibooker.book1D("DPhiL1L2", "#Delta#phi(lep1,lep2)", 64, -3.2, 3.2);
198  // pt of the candidate electron (depending on the decay channel)
199  hists_["elecPt_"] = ibooker.book1D("ElecPt", "pt(e)", 50, 0., 200.);
200  // relative isolation of the candidate electron (depending on the decay
201  // channel)
202  hists_["elecRelIso_"] = ibooker.book1D("ElecRelIso", "Iso_{Rel}(e)", 50, 0., 1.);
203  // pt of the canddiate muon (depending on the decay channel)
204  hists_["muonPt_"] = ibooker.book1D("MuonPt", "pt(#mu)", 50, 0., 200.);
205  // relative isolation of the candidate muon (depending on the decay channel)
206  hists_["muonRelIso_"] = ibooker.book1D("MuonRelIso", "Iso_{Rel}(#mu) (#Delta#beta Corrected)", 50, 0., 1.);
207  // pt of the 1. leading jet (corrected to L2+L3)
208  hists_["jet1Pt_"] = ibooker.book1D("Jet1Pt", "pt_{L2L3}(jet1)", 60, 0., 300.);
209  // pt of the 2. leading jet (corrected to L2+L3)
210  hists_["jet2Pt_"] = ibooker.book1D("Jet2Pt", "pt_{L2L3}(jet2)", 60, 0., 300.);
211  // MET (PF)
212  hists_["metPflow_"] = ibooker.book1D("METPflow", "MET_{Pflow}", 50, 0., 200.);
213  // MET (TC)
214  hists_["metTC_"] = ibooker.book1D("METTC", "MET_{TC}", 50, 0., 200.);
215  // dz for muons (to suppress cosmis)
216  hists_["muonDelZ_"] = ibooker.book1D("MuonDelZ", "d_{z}(#mu)", 50, -25., 25.);
217  // dxy for muons (to suppress cosmics)
218  hists_["muonDelXY_"] = ibooker.book2D("MuonDelXY", "d_{xy}(#mu)", 50, -1., 1., 50, -1., 1.);
219  // lepton multiplicity after std isolation
220  hists_["lepMultIso_"] = ibooker.book2D("LepMultIso", "N_{Iso}(e) vs N_{Iso}(#mu)", 5, 0., 5., 5, 0., 5.);
221 
222  // set axes titles for dxy for muons
223  hists_["muonDelXY_"]->setAxisTitle("x [cm]", 1);
224  hists_["muonDelXY_"]->setAxisTitle("y [cm]", 2);
225  // set axes titles for lepton multiplicity after std isolation
226  hists_["lepMultIso_"]->setAxisTitle("N_{Iso}(#mu)", 1);
227  hists_["lepMultIso_"]->setAxisTitle("N_{Iso}(elec)", 2);
228 
229  if (verbosity_ == VERBOSE)
230  return;
231 
232  // --- [DEBUG] --- //
233  // electron multiplicity after std isolation
234  hists_["elecMultIso_"] = ibooker.book1D("ElecMultIso", "N_{Iso}(e)", 11, -0.5, 10.5);
235  // muon multiplicity after std isolation
236  hists_["muonMultIso_"] = ibooker.book1D("MuonMultIso", "N_{Iso}(#mu)", 11, -0.5, 10.5);
237  // charged hadron isolation component of the candidate muon (depending on the
238  // decay channel)
239  hists_["muonChHadIso_"] = ibooker.book1D("MuonChHadIsoComp", "ChHad_{IsoComponent}(#mu)", 50, 0., 5.);
240  // neutral hadron isolation component of the candidate muon (depending on the
241  // decay channel)
242  hists_["muonNeHadIso_"] = ibooker.book1D("MuonNeHadIsoComp", "NeHad_{IsoComponent}(#mu)", 50, 0., 5.);
243  // photon isolation component of the candidate muon (depending on the decay
244  // channel)
245  hists_["muonPhIso_"] = ibooker.book1D("MuonPhIsoComp", "Photon_{IsoComponent}(#mu)", 50, 0., 5.);
246  // charged hadron isolation component of the candidate electron (depending on
247  // the decay channel)
248  hists_["elecChHadIso_"] = ibooker.book1D("ElectronChHadIsoComp", "ChHad_{IsoComponent}(e)", 50, 0., 5.);
249  // neutral hadron isolation component of the candidate electron (depending on
250  // the decay channel)
251  hists_["elecNeHadIso_"] = ibooker.book1D("ElectronNeHadIsoComp", "NeHad_{IsoComponent}(e)", 50, 0., 5.);
252  // photon isolation component of the candidate electron (depending on the
253  // decay channel)
254  hists_["elecPhIso_"] = ibooker.book1D("ElectronPhIsoComp", "Photon_{IsoComponent}(e)", 50, 0., 5.);
255  // eta of the leading jet
256  hists_["jet1Eta_"] = ibooker.book1D("Jet1Eta", "#eta(jet1)", 30, -5., 5.);
257  // eta of the 2. leading jet
258  hists_["jet2Eta_"] = ibooker.book1D("Jet2Eta", "#eta(jet2)", 30, -5., 5.);
259  // pt of the 1. leading jet (not corrected)
260  hists_["jet1PtRaw_"] = ibooker.book1D("Jet1PtRaw", "pt_{Raw}(jet1)", 60, 0., 300.);
261  // pt of the 2. leading jet (not corrected)
262  hists_["jet2PtRaw_"] = ibooker.book1D("Jet2PtRaw", "pt_{Raw}(jet2)", 60, 0., 300.);
263  // deltaEta between the 2 leading jets
264  hists_["dEtaJet1Jet2_"] = ibooker.book1D("DEtaJet1Jet2", "#Delta#eta(jet1,jet2)", 80, -4., 4.);
265  // deltaEta between the lepton and the leading jet
266  hists_["dEtaJet1Lep1_"] = ibooker.book1D("DEtaJet1Lep1", "#Delta#eta(jet1,lep1)", 80, -4., 4.);
267  // deltaEta between the lepton and MET
268  hists_["dEtaLep1MET_"] = ibooker.book1D("DEtaLep1MET", "#Delta#eta(lep1,MET)", 80, -4., 4.);
269  // deltaEta between leading jet and MET
270  hists_["dEtaJet1MET_"] = ibooker.book1D("DEtaJet1MET", "#Delta#eta(jet1,MET)", 80, -4., 4.);
271  // deltaPhi of 2 leading jets
272  hists_["dPhiJet1Jet2_"] = ibooker.book1D("DPhiJet1Jet2", "#Delta#phi(jet1,jet2)", 64, -3.2, 3.2);
273  // deltaPhi of 1. lepton and 1. jet
274  hists_["dPhiJet1Lep1_"] = ibooker.book1D("DPhiJet1Lep1", "#Delta#phi(jet1,lep1)", 64, -3.2, 3.2);
275  // deltaPhi of 1. lepton and MET
276  hists_["dPhiLep1MET_"] = ibooker.book1D("DPhiLep1MET", "#Delta#phi(lep1,MET)", 64, -3.2, 3.2);
277  // deltaPhi of 1. jet and MET
278  hists_["dPhiJet1MET_"] = ibooker.book1D("DPhiJet1MET", "#Delta#phi(jet1,MET)", 64, -3.2, 3.2);
279  // selected dimuon events
280  hists_["diMuonLogger_"] = ibooker.book2D("DiMuonLogger", "Logged DiMuon Events", 8, 0., 8., 10, 0., 10.);
281  // selected dielec events
282  hists_["diElecLogger_"] = ibooker.book2D("DiElecLogger", "Logged DiElec Events", 8, 0., 8., 10, 0., 10.);
283  // selected elemu events
284  hists_["elecMuLogger_"] = ibooker.book2D("ElecMuLogger", "Logged ElecMu Events", 8, 0., 8., 10, 0., 10.);
285 
286  // set bin labels for trigger monitoring
287  loggerBinLabels(std::string("diMuonLogger_"));
288  loggerBinLabels(std::string("diElecLogger_"));
289  loggerBinLabels(std::string("elecMuLogger_"));
290  return;
291  }
292 
294  // fetch trigger event if configured such
297  if (!event.getByToken(triggerTable_, triggerTable))
298  return;
299  }
300  /*
301  ------------------------------------------------------------
302 
303  Run and Inst. Luminosity information (Inst. Lumi. filled now with a dummy
304  value=5.0)
305 
306  ------------------------------------------------------------
307  */
308 
309  if (!event.eventAuxiliary().run())
310  return;
311  fill("RunNumb_", event.eventAuxiliary().run());
312 
313  double dummy = 5.;
314  fill("InstLumi_", dummy);
315 
316  /*
317  ------------------------------------------------------------
318 
319  Muon Selection
320 
321  ------------------------------------------------------------
322  */
323 
324  std::vector<const reco::PFCandidate*> isoMuons;
325 
328 
329  if (!event.getByToken(muons_, muons))
330  return;
331 
332  for (edm::View<reco::PFCandidate>::const_iterator muonit = muons->begin(); muonit != muons->end(); ++muonit) {
333  if (muonit->muonRef().isNull())
334  continue;
335  reco::MuonRef muon = muonit->muonRef();
336 
337  if (muon->innerTrack().isNull())
338  continue;
339 
340  if (muon->isGlobalMuon()) {
341  fill("muonDelZ_", muon->innerTrack()->vz()); // CB using inner track!
342  fill("muonDelXY_", muon->innerTrack()->vx(), muon->innerTrack()->vy());
343 
344  // apply selection
345  if (!muonSelect_ || (*muonSelect_)(*muonit)) {
346  double chHadPt = muon->pfIsolationR04().sumChargedHadronPt;
347  double neHadEt = muon->pfIsolationR04().sumNeutralHadronEt;
348  double phoEt = muon->pfIsolationR04().sumPhotonEt;
349 
350  double pfRelIso = (chHadPt + std::max(0., neHadEt + phoEt - 0.5 * muon->pfIsolationR04().sumPUPt)) /
351  muon->pt(); // CB dBeta corrected iso!
352 
353  fill("muonRelIso_", pfRelIso);
354 
355  fill("muonChHadIso_", chHadPt);
356  fill("muonNeHadIso_", neHadEt);
357  fill("muonPhIso_", phoEt);
358 
359  if (!muonIso_ || (*muonIso_)(*muonit))
360  isoMuons.push_back(&(*muonit));
361  }
362  }
363  }
364 
365  fill("muonMultIso_", isoMuons.size());
366 
367  /*
368  ------------------------------------------------------------
369 
370  Electron Selection
371 
372  ------------------------------------------------------------
373  */
374 
375  // buffer isolated electronss
376  std::vector<const reco::PFCandidate*> isoElecs;
378  if (!electronId_.isUninitialized()) {
379  if (!event.getByToken(electronId_, electronId))
380  return;
381  }
383  if (!event.getByToken(elecs_, elecs))
384  return;
385 
386  for (edm::View<reco::PFCandidate>::const_iterator elec = elecs->begin(); elec != elecs->end(); ++elec) {
387  if (elec->gsfElectronRef().isNull()) {
388  continue;
389  }
390  reco::GsfElectronRef gsf_el = elec->gsfElectronRef();
391  // restrict to electrons with good electronId
392  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[gsf_el] >= eidCutValue_)) {
393  // apply preselection
394  if (!elecSelect_ || (*elecSelect_)(*elec)) {
395  double el_ChHadIso = gsf_el->pfIsolationVariables().sumChargedHadronPt;
396  double el_NeHadIso = gsf_el->pfIsolationVariables().sumNeutralHadronEt;
397  double el_PhIso = gsf_el->pfIsolationVariables().sumPhotonEt;
398  double el_pfRelIso =
399  (el_ChHadIso + std::max(0., el_NeHadIso + el_PhIso - 0.5 * gsf_el->pfIsolationVariables().sumPUPt)) /
400  gsf_el->pt();
401  fill("elecRelIso_", el_pfRelIso);
402  fill("elecChHadIso_", el_ChHadIso);
403  fill("elecNeHadIso_", el_NeHadIso);
404  fill("elecPhIso_", el_PhIso);
405  if (!elecIso_ || (*elecIso_)(*elec))
406  isoElecs.push_back(&(*elec));
407  }
408  }
409  }
410  fill("elecMultIso_", isoElecs.size());
411 
412  /*
413  ------------------------------------------------------------
414 
415  Jet Selection
416 
417  ------------------------------------------------------------
418  */
419 
420  const reco::JetCorrector* corrector = nullptr;
422  // check whether a jet corrector is in the event or not
423  edm::Handle<reco::JetCorrector> correctorHandle = event.getHandle(jetCorrector_);
424  if (correctorHandle.isValid()) {
425  corrector = correctorHandle.product();
426  } else {
427  edm::LogVerbatim("TopDiLeptonOfflineDQM") << "\n"
428  << "-----------------------------------------------------------------"
429  "-------------------- \n"
430  << " No JetCorrector available from Event:\n"
431  << " - Jets will not be corrected. "
432  " \n"
433  << "-----------------------------------------------------------------"
434  "-------------------- \n";
435  }
436  }
437 
438  unsigned int mult = 0;
439  // buffer leadingJets
440  std::vector<reco::Jet> leadingJets;
442  if (!event.getByToken(jets_, jets))
443  return;
444 
446  if (jetIDSelect_) {
447  if (!event.getByToken(jetIDLabel_, jetID))
448  return;
449  }
450 
451  for (edm::View<reco::Jet>::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
452  unsigned int idx = jet - jets->begin();
453  if (jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(jets->refAt(idx).get())) {
454  if (!(*jetIDSelect_)((*jetID)[jets->refAt(idx)]))
455  continue;
456  }
457  // chekc additional jet selection for calo, pf and bare reco jets
458  if (dynamic_cast<const reco::CaloJet*>(&*jet)) {
459  reco::CaloJet sel = dynamic_cast<const reco::CaloJet&>(*jet);
460  sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
462  if (!jetSelect(sel)) {
463  continue;
464  }
465  } else if (dynamic_cast<const reco::PFJet*>(&*jet)) {
466  reco::PFJet sel = dynamic_cast<const reco::PFJet&>(*jet);
467  sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
469  if (!jetSelect(sel))
470  continue;
471  } else {
472  reco::Jet sel = *jet;
473  sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
475  if (!jetSelect(sel))
476  continue;
477  }
478  // check for overlaps
479  bool overlap = false;
480  for (std::vector<const reco::PFCandidate*>::const_iterator elec = isoElecs.begin(); elec != isoElecs.end();
481  ++elec) {
482  if (reco::deltaR((*elec)->eta(), (*elec)->phi(), jet->eta(), jet->phi()) < 0.4) {
483  overlap = true;
484  break;
485  }
486  }
487  if (overlap) {
488  continue;
489  }
490  // prepare jet to fill monitor histograms
491  reco::Jet monitorJet = *jet;
492  monitorJet.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
493  ++mult; // determine jet multiplicity
494  if (idx == 0) {
495  leadingJets.push_back(monitorJet);
496  fill("jet1Pt_", monitorJet.pt());
497  fill("jet1PtRaw_", jet->pt());
498  fill("jet1Eta_", jet->eta());
499  }
500  if (idx == 1) {
501  leadingJets.push_back(monitorJet);
502  fill("jet2Pt_", monitorJet.pt());
503  fill("jet2PtRaw_", jet->pt());
504  fill("jet2Eta_", jet->eta());
505  }
506  }
507  if (leadingJets.size() > 1) {
508  fill("dEtaJet1Jet2_", leadingJets[0].eta() - leadingJets[1].eta());
509  fill("dPhiJet1Jet2_", reco::deltaPhi(leadingJets[0].phi(), leadingJets[1].phi()));
510  if (!isoMuons.empty()) {
511  if (isoElecs.empty() || isoMuons[0]->pt() > isoElecs[0]->pt()) {
512  fill("dEtaJet1Lep1_", isoMuons[0]->eta() - leadingJets[0].eta());
513  fill("dPhiJet1Lep1_", reco::deltaPhi(isoMuons[0]->phi(), leadingJets[0].phi()));
514  }
515  }
516  if (!isoElecs.empty()) {
517  if (isoMuons.empty() || isoElecs[0]->pt() > isoMuons[0]->pt()) {
518  fill("dEtaJet1Lep1_", isoElecs[0]->eta() - leadingJets[0].eta());
519  fill("dPhiJet1Lep1_", reco::deltaPhi(isoElecs[0]->phi(), leadingJets[0].phi()));
520  }
521  }
522  }
523  fill("jetMult_", mult);
524 
525  /*
526  ------------------------------------------------------------
527 
528  MET Selection
529 
530  ------------------------------------------------------------
531  */
532 
533  // buffer for event logging
535  for (std::vector<edm::EDGetTokenT<edm::View<reco::MET>>>::const_iterator met_ = mets_.begin(); met_ != mets_.end();
536  ++met_) {
538  if (!event.getByToken(*met_, met))
539  continue;
540 
541  if (met->begin() != met->end()) {
542  unsigned int idx = met_ - mets_.begin();
543  if (idx == 0) {
544  caloMET = *met->begin();
545  fill("metCalo_", met->begin()->et());
546  if (!leadingJets.empty()) {
547  fill("dEtaJet1MET_", leadingJets[0].eta() - met->begin()->eta());
548  fill("dPhiJet1MET_", reco::deltaPhi(leadingJets[0].phi(), met->begin()->phi()));
549  }
550  if (!isoMuons.empty()) {
551  if (isoElecs.empty() || isoMuons[0]->pt() > isoElecs[0]->pt()) {
552  fill("dEtaLep1MET_", isoMuons[0]->eta() - met->begin()->eta());
553  fill("dPhiLep1MET_", reco::deltaPhi(isoMuons[0]->phi(), met->begin()->phi()));
554  }
555  }
556  if (!isoElecs.empty()) {
557  if (isoMuons.empty() || isoElecs[0]->pt() > isoMuons[0]->pt()) {
558  fill("dEtaLep1MET_", isoElecs[0]->eta() - met->begin()->eta());
559  fill("dPhiLep1MET_", reco::deltaPhi(isoElecs[0]->phi(), met->begin()->phi()));
560  }
561  }
562  }
563  if (idx == 1) {
564  fill("metTC_", met->begin()->et());
565  }
566  if (idx == 2) {
567  fill("metPflow_", met->begin()->et());
568  }
569  }
570  }
571 
572  /*
573  ------------------------------------------------------------
574 
575  Event Monitoring
576 
577  ------------------------------------------------------------
578  */
579 
580  // check number of isolated leptons
581  fill("lepMultIso_", isoMuons.size(), isoElecs.size());
582  // ELECMU channel
583  if (decayChannel(isoMuons, isoElecs) == ELECMU) {
584  fill("decayChannel_", 0.5);
585  double mass = (isoElecs[0]->p4() + isoMuons[0]->p4()).mass();
586  if ((lowerEdge_ == -1. && upperEdge_ == -1.) || (lowerEdge_ < mass && mass < upperEdge_)) {
587  fill("dEtaL1L2_", isoElecs[0]->eta() - isoMuons[0]->eta());
588  fill("sumEtaL1L2_", (isoElecs[0]->eta() + isoMuons[0]->eta()) / 2);
589  fill("dPhiL1L2_", reco::deltaPhi(isoElecs[0]->phi(), isoMuons[0]->eta()));
590  fill("elecPt_", isoElecs[0]->pt());
591  fill("muonPt_", isoMuons[0]->pt());
592  fill("lep1Pt_", isoElecs[0]->pt() > isoMuons[0]->pt() ? isoElecs[0]->pt() : isoMuons[0]->pt());
593  fill("lep2Pt_", isoElecs[0]->pt() > isoMuons[0]->pt() ? isoMuons[0]->pt() : isoElecs[0]->pt());
594  // fill plots for trigger monitoring
596  fill(event, *triggerTable, "elecMu", elecMuPaths_);
597  if (elecMuLogged_ <= hists_.find("elecMuLogger_")->second->getNbinsY()) {
598  // log runnumber, lumi block, event number & some
599  // more pysics infomation for interesting events
600  fill("elecMuLogger_", 0.5, elecMuLogged_ + 0.5, event.eventAuxiliary().run());
601  fill("elecMuLogger_", 1.5, elecMuLogged_ + 0.5, event.eventAuxiliary().luminosityBlock());
602  fill("elecMuLogger_", 2.5, elecMuLogged_ + 0.5, event.eventAuxiliary().event());
603  fill("elecMuLogger_", 3.5, elecMuLogged_ + 0.5, isoMuons[0]->pt());
604  fill("elecMuLogger_", 4.5, elecMuLogged_ + 0.5, isoElecs[0]->pt());
605  if (!leadingJets.empty())
606  fill("elecMuLogger_", 5.5, elecMuLogged_ + 0.5, leadingJets[0].pt());
607  if (leadingJets.size() > 1)
608  fill("elecMuLogger_", 6.5, elecMuLogged_ + 0.5, leadingJets[1].pt());
609  fill("elecMuLogger_", 7.5, elecMuLogged_ + 0.5, caloMET.et());
610  ++elecMuLogged_;
611  }
612  }
613  }
614 
615  // DIMUON channel
616  if (decayChannel(isoMuons, isoElecs) == DIMUON) {
617  fill("decayChannel_", 1.5);
618  int charge = isoMuons[0]->charge() * isoMuons[1]->charge();
619  double mass = (isoMuons[0]->p4() + isoMuons[1]->p4()).mass();
620 
621  fill(charge < 0 ? "invMass_" : "invMassWC_", mass);
622  fill(charge < 0 ? "invMassLog_" : "invMassWCLog_", log10(mass));
623  if ((lowerEdge_ == -1. && upperEdge_ == -1.) || (lowerEdge_ < mass && mass < upperEdge_)) {
624  fill("dEtaL1L2_", isoMuons[0]->eta() - isoMuons[1]->eta());
625  fill("sumEtaL1L2_", (isoMuons[0]->eta() + isoMuons[1]->eta()) / 2);
626  fill("dPhiL1L2_", reco::deltaPhi(isoMuons[0]->phi(), isoMuons[1]->phi()));
627  fill("muonPt_", isoMuons[0]->pt());
628  fill("muonPt_", isoMuons[1]->pt());
629  fill("lep1Pt_", isoMuons[0]->pt());
630  fill("lep2Pt_", isoMuons[1]->pt());
631  // fill plots for trigger monitoring
633  fill(event, *triggerTable, "diMuon", diMuonPaths_);
634  if (diMuonLogged_ <= hists_.find("diMuonLogger_")->second->getNbinsY()) {
635  // log runnumber, lumi block, event number & some
636  // more pysics infomation for interesting events
637  fill("diMuonLogger_", 0.5, diMuonLogged_ + 0.5, event.eventAuxiliary().run());
638  fill("diMuonLogger_", 1.5, diMuonLogged_ + 0.5, event.eventAuxiliary().luminosityBlock());
639  fill("diMuonLogger_", 2.5, diMuonLogged_ + 0.5, event.eventAuxiliary().event());
640  fill("diMuonLogger_", 3.5, diMuonLogged_ + 0.5, isoMuons[0]->pt());
641  fill("diMuonLogger_", 4.5, diMuonLogged_ + 0.5, isoMuons[1]->pt());
642  if (!leadingJets.empty())
643  fill("diMuonLogger_", 5.5, diMuonLogged_ + 0.5, leadingJets[0].pt());
644  if (leadingJets.size() > 1)
645  fill("diMuonLogger_", 6.5, diMuonLogged_ + 0.5, leadingJets[1].pt());
646  fill("diMuonLogger_", 7.5, diMuonLogged_ + 0.5, caloMET.et());
647  ++diMuonLogged_;
648  }
649  }
650  }
651 
652  // DIELEC channel
653  if (decayChannel(isoMuons, isoElecs) == DIELEC) {
654  fill("decayChannel_", 2.5);
655  int charge = isoElecs[0]->charge() * isoElecs[1]->charge();
656  double mass = (isoElecs[0]->p4() + isoElecs[1]->p4()).mass();
657  fill(charge < 0 ? "invMass_" : "invMassWC_", mass);
658  fill(charge < 0 ? "invMassLog_" : "invMassWCLog_", log10(mass));
659  if ((lowerEdge_ == -1. && upperEdge_ == -1.) || (lowerEdge_ < mass && mass < upperEdge_)) {
660  fill("dEtaL1L2_", isoElecs[0]->eta() - isoElecs[1]->eta());
661  fill("sumEtaL1L2_", (isoElecs[0]->eta() + isoElecs[1]->eta()) / 2);
662  fill("dPhiL1L2_", reco::deltaPhi(isoElecs[0]->phi(), isoElecs[1]->phi()));
663  fill("elecPt_", isoElecs[0]->pt());
664  fill("elecPt_", isoElecs[1]->pt());
665  fill("lep1Pt_", isoElecs[0]->pt());
666  fill("lep2Pt_", isoElecs[1]->pt());
667  if (diElecLogged_ <= hists_.find("diElecLogger_")->second->getNbinsY()) {
668  // log runnumber, lumi block, event number & some
669  // more pysics infomation for interesting events
670  fill("diElecLogger_", 0.5, diElecLogged_ + 0.5, event.eventAuxiliary().run());
671  fill("diElecLogger_", 1.5, diElecLogged_ + 0.5, event.eventAuxiliary().luminosityBlock());
672  fill("diElecLogger_", 2.5, diElecLogged_ + 0.5, event.eventAuxiliary().event());
673  fill("diElecLogger_", 3.5, diElecLogged_ + 0.5, isoElecs[0]->pt());
674  fill("diElecLogger_", 4.5, diElecLogged_ + 0.5, isoElecs[1]->pt());
675  if (!leadingJets.empty())
676  fill("diElecLogger_", 5.5, diElecLogged_ + 0.5, leadingJets[0].pt());
677  if (leadingJets.size() > 1)
678  fill("diElecLogger_", 6.5, diElecLogged_ + 0.5, leadingJets[1].pt());
679  fill("diElecLogger_", 7.5, diElecLogged_ + 0.5, caloMET.et());
680  ++diElecLogged_;
681  }
682  }
683  }
684  }
685 } // namespace TopDiLeptonOffline
686 
688  : vertexSelect_(nullptr),
689  beamspotSelect_(nullptr),
690  MuonStep(nullptr),
691  ElectronStep(nullptr),
692  PvStep(nullptr),
693  METStep(nullptr) {
694  JetSteps.clear();
695  CaloJetSteps.clear();
696  PFJetSteps.clear();
697  // configure the preselection
698  edm::ParameterSet presel = cfg.getParameter<edm::ParameterSet>("preselection");
699  if (presel.existsAs<edm::ParameterSet>("trigger")) {
701  // triggerTable_=trigger.getParameter<edm::InputTag>("src");
702  triggerTable_ = consumes<edm::TriggerResults>(trigger.getParameter<edm::InputTag>("src"));
703  triggerPaths_ = trigger.getParameter<std::vector<std::string>>("select");
704  }
705  if (presel.existsAs<edm::ParameterSet>("vertex")) {
707  vertex_ = consumes<std::vector<reco::Vertex>>(vertex.getParameter<edm::InputTag>("src"));
708  vertexSelect_ = std::make_unique<StringCutObjectSelector<reco::Vertex>>(vertex.getParameter<std::string>("select"));
709  }
710  if (presel.existsAs<edm::ParameterSet>("beamspot")) {
712  beamspot_ = consumes<reco::BeamSpot>(beamspot.getParameter<edm::InputTag>("src"));
714  std::make_unique<StringCutObjectSelector<reco::BeamSpot>>(beamspot.getParameter<std::string>("select"));
715  }
716 
717  // conifgure the selection
718  sel_ = cfg.getParameter<std::vector<edm::ParameterSet>>("selection");
719  setup_ = cfg.getParameter<edm::ParameterSet>("setup");
720  for (unsigned int i = 0; i < sel_.size(); ++i) {
721  selectionOrder_.push_back(sel_.at(i).getParameter<std::string>("label"));
723  std::make_pair(sel_.at(i),
724  std::make_unique<TopDiLeptonOffline::MonitorEnsemble>(
726  }
727  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin(); selIt != selectionOrder_.end();
728  ++selIt) {
729  std::string key = selectionStep(*selIt), type = objectType(*selIt);
730  if (selection_.find(key) != selection_.end()) {
731  if (type == "muons") {
732  MuonStep = std::make_unique<SelectionStep<reco::PFCandidate>>(selection_[key].first, consumesCollector());
733  }
734  if (type == "elecs") {
735  ElectronStep = std::make_unique<SelectionStep<reco::PFCandidate>>(selection_[key].first, consumesCollector());
736  }
737  if (type == "pvs") {
738  PvStep = std::make_unique<SelectionStep<reco::Vertex>>(selection_[key].first, consumesCollector());
739  }
740  if (type == "jets") {
741  JetSteps.push_back(std::make_unique<SelectionStep<reco::Jet>>(selection_[key].first, consumesCollector()));
742  }
743  if (type == "jets/pf") {
745  }
746  if (type == "jets/calo") {
747  CaloJetSteps.push_back(
749  }
750  if (type == "met") {
751  METStep = std::make_unique<SelectionStep<reco::MET>>(selection_[key].first, consumesCollector());
752  }
753  }
754  }
755 }
756 
758  for (auto selIt = selection_.begin(); selIt != selection_.end(); ++selIt) {
759  selIt->second.second->book(ibooker);
760  }
761 }
765  if (!event.getByToken(triggerTable_, triggerTable))
766  return;
767  if (!accept(event, *triggerTable, triggerPaths_))
768  return;
769  }
770  if (!vertex_.isUninitialized()) {
772  if (!event.getByToken(vertex_, vertex))
773  return;
774  if (vertex->empty() || !(*vertexSelect_)(vertex->front()))
775  return;
776  }
777  if (!beamspot_.isUninitialized()) {
779  if (!event.getByToken(beamspot_, beamspot))
780  return;
781  if (!(*beamspotSelect_)(*beamspot))
782  return;
783  }
784  unsigned int nJetSteps = -1;
785 
786  unsigned int nPFJetSteps = -1;
787 
788  unsigned int nCaloJetSteps = -1;
789  // apply selection steps
790  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin(); selIt != selectionOrder_.end();
791  ++selIt) {
792  std::string key = selectionStep(*selIt), type = objectType(*selIt);
793  if (selection_.find(key) != selection_.end()) {
794  if (type == "empty") {
795  selection_[key].second->fill(event, setup);
796  }
797  if (type == "muons" && MuonStep != nullptr) {
798  if (MuonStep->select(event)) {
799  selection_[key].second->fill(event, setup);
800  } else
801  break;
802  }
803  if (type == "elecs" && ElectronStep != nullptr) {
804  if (ElectronStep->select(event, "electron")) {
805  selection_[key].second->fill(event, setup);
806  } else
807  break;
808  }
809  if (type == "jets" && !JetSteps.empty()) {
810  nJetSteps++;
811  if (JetSteps[nJetSteps] != nullptr) {
812  if (JetSteps[nJetSteps]->select(event, setup)) {
813  selection_[key].second->fill(event, setup);
814  } else
815  break;
816  }
817  }
818 
819  if (type == "jets/pf" && !PFJetSteps.empty()) {
820  nPFJetSteps++;
821  if (PFJetSteps[nPFJetSteps] != nullptr) {
822  if (PFJetSteps[nPFJetSteps]->select(event, setup)) {
823  selection_[key].second->fill(event, setup);
824  } else
825  break;
826  }
827  }
828 
829  if (type == "jets/calo" && !CaloJetSteps.empty()) {
830  nCaloJetSteps++;
831  if (CaloJetSteps[nCaloJetSteps] != nullptr) {
832  if (CaloJetSteps[nCaloJetSteps]->select(event, setup)) {
833  selection_[key].second->fill(event, setup);
834  } else
835  break;
836  }
837  }
838 
839  if (type == "met" && METStep != nullptr) {
840  if (METStep->select(event)) {
841  selection_[key].second->fill(event, setup);
842  } else
843  break;
844  }
845  }
846  }
847 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
Log< level::Info, true > LogVerbatim
std::string selectionStep(const std::string &label)
std::vector< std::string > selectionOrder_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Jets made from CaloTowers.
Definition: CaloJet.h:27
virtual void scaleEnergy(double fScale)
scale energy of the jet
double pt() const final
transverse momentum
std::unique_ptr< SelectionStep< reco::Vertex > > PvStep
Level verbosity_
verbosity level for booking
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::vector< std::unique_ptr< SelectionStep< reco::CaloJet > > > CaloJetSteps
Base class for all types of Jets.
Definition: Jet.h:20
edm::EDGetTokenT< std::vector< reco::Vertex > > vertex_
primary vertex
MonitorEnsemble(const char *label, const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
T const * product() const
Definition: Handle.h:70
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
void loggerBinLabels(std::string hist)
set labels for event logging histograms
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > elecIso_
extra isolation criterion on electron
std::unique_ptr< StringCutObjectSelector< reco::Vertex > > vertexSelect_
string cut selector
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
std::vector< edm::ParameterSet > sel_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
void fill(const edm::Event &event, const edm::EventSetup &setup)
fill monitor histograms with electronId and jetCorrections
Jets made from PFObjects.
Definition: PFJet.h:20
electronId
when omitted electron plots will be filled w/o cut on electronId
edm::EDGetTokenT< edm::View< reco::Jet > > jets_
input sources for monitoring
edm::EDGetTokenT< reco::JetCorrector > jetCorrector_
jetCorrector
std::vector< std::unique_ptr< SelectionStep< reco::Jet > > > JetSteps
char const * label
std::unique_ptr< StringCutObjectSelector< reco::JetID > > jetIDSelect_
extra jetID selection on calo jets
DecayChannel decayChannel(const std::vector< const reco::PFCandidate *> &muons, const std::vector< const reco::PFCandidate *> &elecs) const
determine dileptonic decay channel
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
do this during the event loop
edm::EDGetTokenT< edm::View< reco::PFCandidate > > muons_
std::unique_ptr< SelectionStep< reco::PFCandidate > > MuonStep
Definition: MET.h:41
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate, true > > muonSelect_
extra selection on muons
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
double lowerEdge_
mass window upper and lower edge
std::vector< edm::EDGetTokenT< edm::View< reco::MET > > > mets_
considers a vector of METs
std::vector< std::string > elecMuPaths_
key
prepare the HTCondor submission files and eventually submit them
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > elecSelect_
extra selection on electrons
std::unique_ptr< SelectionStep< reco::MET > > METStep
TopDiLeptonOfflineDQM(const edm::ParameterSet &cfg)
default constructor
std::unique_ptr< SelectionStep< reco::PFCandidate > > ElectronStep
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
int elecMuLogged_
number of logged interesting events
std::vector< std::string > diMuonPaths_
trigger paths for di muon channel
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::map< std::string, MonitorElement * > hists_
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
void book(DQMStore::IBooker &ibooker)
book histograms in subdirectory directory
bool isValid() const
Definition: HandleBase.h:70
Templated helper class to allow a selection on a certain object collection.
edm::EDGetTokenT< edm::TriggerResults > triggerTable_
trigger table
std::unique_ptr< StringCutObjectSelector< reco::BeamSpot > > beamspotSelect_
string cut selector
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
edm::EDGetTokenT< edm::TriggerResults > triggerTable_
trigger table
std::vector< std::string > triggerPaths_
trigger paths
std::string objectType(const std::string &label)
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate, true > > muonIso_
extra isolation criterion on muon
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
edm::EDGetTokenT< reco::BeamSpot > beamspot_
beamspot
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label
std::map< std::string, std::pair< edm::ParameterSet, std::unique_ptr< TopDiLeptonOffline::MonitorEnsemble > > > selection_
void triggerBinLabels(std::string channel, const std::vector< std::string > labels)
set configurable labels for trigger monitoring histograms
Definition: event.py:1
Definition: Run.h:45
edm::EDGetTokenT< edm::View< reco::PFCandidate > > elecs_
std::vector< std::unique_ptr< SelectionStep< reco::PFJet > > > PFJetSteps