CMS 3D CMS Logo

TopSingleLeptonDQM_miniAOD.cc
Go to the documentation of this file.
7 #include <iostream>
8 #include <memory>
9 
13 
18 
19 using namespace std;
20 
22 
23  // maximal number of leading jets
24  // to be used for top mass estimate
25  static const unsigned int MAXJETS = 4;
26  // nominal mass of the W boson to
27  // be used for the top mass estimate
28  static const double WMASS = 80.4;
29 
30  MonitorEnsemble::MonitorEnsemble(const char* label, const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
31  : label_(label),
32  elecIso_(nullptr),
33  elecSelect_(nullptr),
34  pvSelect_(nullptr),
35  muonIso_(nullptr),
36  muonSelect_(nullptr),
37  jetIDSelect_(nullptr),
38  jetSelect(nullptr),
39  includeBTag_(false),
40  lowerEdge_(-1.),
41  upperEdge_(-1.),
42  logged_(0) {
43  // sources have to be given; this PSet is not optional
44  edm::ParameterSet sources = cfg.getParameter<edm::ParameterSet>("sources");
45  // muons_ = iC.consumes<edm::View<reco::PFCandidate> >(
46  // sources.getParameter<edm::InputTag>("muons"));
47 
48  muons_ = iC.consumes<edm::View<pat::Muon>>(sources.getParameter<edm::InputTag>("muons"));
49 
50  elecs_ = iC.consumes<edm::View<pat::Electron>>(sources.getParameter<edm::InputTag>("elecs"));
51  pvs_ = iC.consumes<edm::View<reco::Vertex>>(sources.getParameter<edm::InputTag>("pvs"));
52  jets_ = iC.consumes<edm::View<pat::Jet>>(sources.getParameter<edm::InputTag>("jets"));
53  for (edm::InputTag const& tag : sources.getParameter<std::vector<edm::InputTag>>("mets"))
54  mets_.push_back(iC.consumes<edm::View<pat::MET>>(tag));
55  // electronExtras are optional; they may be omitted or
56  // empty
57  if (cfg.existsAs<edm::ParameterSet>("elecExtras")) {
58  edm::ParameterSet elecExtras = 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")) {
62  elecSelect_ =
63  std::make_unique<StringCutObjectSelector<pat::Electron>>(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")) {
68  elecIso_ =
69  std::make_unique<StringCutObjectSelector<pat::Electron>>(elecExtras.getParameter<std::string>("isolation"));
70  }
71 
72  if (elecExtras.existsAs<std::string>("rho")) {
73  rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
74  }
75  // electronId is optional; in case it's not found the
76  // InputTag will remain empty
77  if (elecExtras.existsAs<edm::ParameterSet>("electronId")) {
78  edm::ParameterSet elecId = elecExtras.getParameter<edm::ParameterSet>("electronId");
79  electronId_ = iC.consumes<edm::ValueMap<float>>(elecId.getParameter<edm::InputTag>("src"));
80  eidCutValue_ = elecId.getParameter<double>("cutValue");
81  }
82  }
83  // pvExtras are opetional; they may be omitted or empty
84  if (cfg.existsAs<edm::ParameterSet>("pvExtras")) {
85  edm::ParameterSet pvExtras = cfg.getParameter<edm::ParameterSet>("pvExtras");
86  // select is optional; in case it's not found no
87  // selection will be applied
88  if (pvExtras.existsAs<std::string>("select")) {
89  pvSelect_ =
90  std::make_unique<StringCutObjectSelector<reco::Vertex>>(pvExtras.getParameter<std::string>("select"));
91  }
92  }
93  // muonExtras are optional; they may be omitted or empty
94  if (cfg.existsAs<edm::ParameterSet>("muonExtras")) {
95  edm::ParameterSet muonExtras = 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")) {
99  muonSelect_ =
100  std::make_unique<StringCutObjectSelector<pat::Muon>>(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")) {
105  muonIso_ =
106  std::make_unique<StringCutObjectSelector<pat::Muon>>(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 = cfg.getParameter<edm::ParameterSet>("jetExtras");
114  // read jetID information if it exists
115  if (jetExtras.existsAs<edm::ParameterSet>("jetID")) {
116  edm::ParameterSet jetID = jetExtras.getParameter<edm::ParameterSet>("jetID");
117  jetIDLabel_ = iC.consumes<reco::JetIDValueMap>(jetID.getParameter<edm::InputTag>("label"));
118  jetIDSelect_ =
119  std::make_unique<StringCutObjectSelector<reco::JetID>>(jetID.getParameter<std::string>("select"));
120  }
121  // select is optional; in case it's not found no
122  // selection will be applied (only implemented for
123  // CaloJets at the moment)
124  if (jetExtras.existsAs<std::string>("select")) {
125  jetSelect_ = jetExtras.getParameter<std::string>("select");
126  jetSelect = std::make_unique<StringCutObjectSelector<pat::Jet>>(jetSelect_);
127  }
128  }
129 
130  // triggerExtras are optional; they may be omitted or empty
131  if (cfg.existsAs<edm::ParameterSet>("triggerExtras")) {
132  edm::ParameterSet triggerExtras = cfg.getParameter<edm::ParameterSet>("triggerExtras");
133  triggerTable_ = iC.consumes<edm::TriggerResults>(triggerExtras.getParameter<edm::InputTag>("src"));
134  triggerPaths_ = triggerExtras.getParameter<std::vector<std::string>>("paths");
135  }
136 
137  // massExtras is optional; in case it's not found no mass
138  // window cuts are applied for the same flavor monitor
139  // histograms
140  if (cfg.existsAs<edm::ParameterSet>("massExtras")) {
141  edm::ParameterSet massExtras = cfg.getParameter<edm::ParameterSet>("massExtras");
142  lowerEdge_ = massExtras.getParameter<double>("lowerEdge");
143  upperEdge_ = massExtras.getParameter<double>("upperEdge");
144  }
145 
146  // setup the verbosity level for booking histograms;
147  // per default the verbosity level will be set to
148  // STANDARD. This will also be the chosen level in
149  // the case when the monitoring PSet is not found
151  if (cfg.existsAs<edm::ParameterSet>("monitoring")) {
152  edm::ParameterSet monitoring = cfg.getParameter<edm::ParameterSet>("monitoring");
153  if (monitoring.getParameter<std::string>("verbosity") == "DEBUG")
154  verbosity_ = DEBUG;
155  if (monitoring.getParameter<std::string>("verbosity") == "VERBOSE")
157  if (monitoring.getParameter<std::string>("verbosity") == "STANDARD")
159  }
160  // and don't forget to do the histogram booking
161  directory_ = cfg.getParameter<std::string>("directory");
162  // book(ibooker);
163  }
164 
166  // set up the current directory path
167  std::string current(directory_);
168  current += label_;
169  ibooker.setCurrentFolder(current);
170 
171  // determine number of bins for trigger monitoring
172  //unsigned int nPaths = triggerPaths_.size();
173 
174  // --- [STANDARD] --- //
175  // Run Number
176  //hists_["RunNumb_"] = ibooker.book1D("RunNumber", "Run Nr.", 1.e4, 1.5e5, 3.e5);
177  // instantaneous luminosity
178  //hists_["InstLumi_"] = ibooker.book1D("InstLumi", "Inst. Lumi.", 100, 0., 1.e3);
179  // number of selected primary vertices
180  hists_["pvMult_"] = ibooker.book1D("PvMult", "N_{good pvs}", 50, 0., 50.);
181  // pt of the leading muon
182  hists_["muonPt_"] = ibooker.book1D("MuonPt", "pt(#mu TightId, TightIso)", 40, 0., 200.);
183  // muon multiplicity before std isolation
184  hists_["muonMult_"] = ibooker.book1D("MuonMult", "N_{loose}(#mu)", 10, 0., 10.);
185  // muon multiplicity after std isolation
186  //hists_["muonMultIso_"] = ibooker.book1D("MuonMultIso",
187  // "N_{TightIso}(#mu)", 10, 0., 10.);
188 
189  hists_["muonMultTight_"] = ibooker.book1D("MuonMultTight", "N_{TightIso,TightId}(#mu)", 10, 0., 10.);
190 
191  // pt of the leading electron
192  hists_["elecPt_"] = ibooker.book1D("ElecPt", "pt(e TightId, TightIso)", 40, 0., 200.);
193  // electron multiplicity before std isolation
194  //hists_["elecMult_"] = ibooker.book1D("ElecMult", "N_{looseId}(e)", 10, 0., 10.);
195  // electron multiplicity after std isolation
196  //hists_["elecMultIso_"] = ibooker.book1D("ElecMultIso", "N_{Iso}(e)", 10, 0., 10.);
197  // multiplicity of jets with pt>20 (corrected to L2+L3)
198  hists_["jetMult_"] = ibooker.book1D("JetMult", "N_{30}(jet)", 10, 0., 10.);
199  hists_["jetLooseMult_"] = ibooker.book1D("JetLooseMult", "N_{30,loose}(jet)", 10, 0., 10.);
200 
201  // trigger efficiency estimates for single lepton triggers
202  //hists_["triggerEff_"] = ibooker.book1D("TriggerEff",
203  // "Eff(trigger)", nPaths, 0., nPaths);
204  // monitored trigger occupancy for single lepton triggers
205  //hists_["triggerMon_"] = ibooker.book1D("TriggerMon",
206  // "Mon(trigger)", nPaths, 0., nPaths);
207  // MET (calo)
208  hists_["slimmedMETs_"] = ibooker.book1D("slimmedMETs", "MET_{slimmed}", 40, 0., 200.);
209  // W mass estimate
210  hists_["massW_"] = ibooker.book1D("MassW", "M(W)", 60, 0., 300.);
211  // Top mass estimate
212  hists_["massTop_"] = ibooker.book1D("MassTop", "M(Top)", 50, 0., 500.);
213  // b-tagged Top mass
214  hists_["massBTop_"] = ibooker.book1D("MassBTop", "M(Top, 1 b-tag)", 50, 0., 500.);
215  // set bin labels for trigger monitoring
217 
218  if (verbosity_ == STANDARD)
219  return;
220 
221  // --- [VERBOSE] --- //
222  // eta of the leading muon
223  hists_["muonEta_"] = ibooker.book1D("MuonEta", "#eta(#mu TightId,TightIso)", 30, -3., 3.);
224  // relative isolation of the candidate muon (depending on the decay channel)
225  hists_["muonPhi_"] = ibooker.book1D("MuonPhi", "#phi(#mu TightId,TightIso)", 40, -4., 4.);
226  hists_["muonRelIso_"] = ibooker.book1D("MuonRelIso", "Iso_{Rel}(#mu TightId) (#Delta#beta Corrected)", 50, 0., 1.);
227 
228  // eta of the leading electron
229  hists_["elecEta_"] = ibooker.book1D("ElecEta", "#eta(e TightId, TightIso)", 30, -3., 3.);
230  hists_["elecPhi_"] = ibooker.book1D("ElecPhi", "#phi(e TightId, TightIso)", 40, -4., 4.);
231  // std isolation variable of the leading electron
232  hists_["elecRelIso_"] = ibooker.book1D("ElecRelIso", "Iso_{Rel}(e TightId)", 50, 0., 1.);
233 
234  hists_["elecMultTight_"] = ibooker.book1D("ElecMultTight", "N_{TightIso,TightId}(e)", 10, 0., 10.);
235 
236  // multiplicity of btagged jets (for track counting high efficiency) with
237  // pt(L2L3)>30
238  //hists_["jetMultBEff_"] = ibooker.book1D("JetMultBEff",
239  // "N_{30}(TCHE)", 10, 0., 10.);
240  // btag discriminator for track counting high efficiency for jets with
241  // pt(L2L3)>30
242  //hists_["jetBDiscEff_"] = ibooker.book1D("JetBDiscEff",
243  // "Disc_{TCHE}(jet)", 100, 0., 10.);
244  // eta of the 1. leading jet (corrected to L2+L3)
245  hists_["jet1Eta_"] = ibooker.book1D("Jet1Eta", "#eta_{30,loose}(jet1)", 60, -3., 3.);
246  // pt of the 1. leading jet (corrected to L2+L3)
247  hists_["jet1Pt_"] = ibooker.book1D("Jet1Pt", "pt_{30,loose}(jet1)", 60, 0., 300.);
248  // eta of the 2. leading jet (corrected to L2+L3)
249  hists_["jet2Eta_"] = ibooker.book1D("Jet2Eta", "#eta_{30,loose}(jet2)", 60, -3., 3.);
250  // pt of the 2. leading jet (corrected to L2+L3)
251  hists_["jet2Pt_"] = ibooker.book1D("Jet2Pt", "pt_{30,loose}(jet2)", 60, 0., 300.);
252  // eta of the 3. leading jet (corrected to L2+L3)
253  hists_["jet3Eta_"] = ibooker.book1D("Jet3Eta", "#eta_{30,loose}(jet3)", 60, -3., 3.);
254  // pt of the 3. leading jet (corrected to L2+L3)
255  hists_["jet3Pt_"] = ibooker.book1D("Jet3Pt", "pt_{30,loose}(jet3)", 60, 0., 300.);
256  // eta of the 4. leading jet (corrected to L2+L3)
257  hists_["jet4Eta_"] = ibooker.book1D("Jet4Eta", "#eta_{30,loose}(jet4)", 60, -3., 3.);
258  // pt of the 4. leading jet (corrected to L2+L3)
259  hists_["jet4Pt_"] = ibooker.book1D("Jet4Pt", "pt_{30,loose}(jet4)", 60, 0., 300.);
260  // MET (tc)
261  // MET (pflow)
262  hists_["slimmedMETsPuppi_"] = ibooker.book1D("slimmedMETsPuppi", "MET_{slimmedPuppi}", 40, 0., 200.);
263  // dz for muons (to suppress cosmis)
264  hists_["muonDelZ_"] = ibooker.book1D("MuonDelZ", "d_{z}(#mu)", 50, -25., 25.);
265  // dxy for muons (to suppress cosmics)
266  hists_["muonDelXY_"] = ibooker.book2D("MuonDelXY", "d_{xy}(#mu)", 50, -0.1, 0.1, 50, -0.1, 0.1);
267 
268  // set axes titles for dxy for muons
269  hists_["muonDelXY_"]->setAxisTitle("x [cm]", 1);
270  hists_["muonDelXY_"]->setAxisTitle("y [cm]", 2);
271 
272  if (verbosity_ == VERBOSE)
273  return;
274 
275  // --- [DEBUG] --- //
276  // charged hadron isolation component of the candidate muon (depending on the
277  // decay channel)
278  hists_["muonChHadIso_"] = ibooker.book1D("MuonChHadIsoComp", "ChHad_{IsoComponent}(#mu TightId)", 50, 0., 5.);
279  // neutral hadron isolation component of the candidate muon (depending on the
280  // decay channel)
281  hists_["muonNeHadIso_"] = ibooker.book1D("MuonNeHadIsoComp", "NeHad_{IsoComponent}(#mu TightId)", 50, 0., 5.);
282  // photon isolation component of the candidate muon (depending on the decay
283  // channel)
284  hists_["muonPhIso_"] = ibooker.book1D("MuonPhIsoComp", "Photon_{IsoComponent}(#mu TightId)", 50, 0., 5.);
285  // charged hadron isolation component of the candidate electron (depending on
286  // the decay channel)
287  hists_["elecChHadIso_"] = ibooker.book1D("ElectronChHadIsoComp", "ChHad_{IsoComponent}(e TightId)", 50, 0., 5.);
288  // neutral hadron isolation component of the candidate electron (depending on
289  // the decay channel)
290  hists_["elecNeHadIso_"] = ibooker.book1D("ElectronNeHadIsoComp", "NeHad_{IsoComponent}(e TightId)", 50, 0., 5.);
291  // photon isolation component of the candidate electron (depending on the
292  // decay channel)
293  hists_["elecPhIso_"] = ibooker.book1D("ElectronPhIsoComp", "Photon_{IsoComponent}(e TightId)", 50, 0., 5.);
294  // multiplicity of btagged jets (for track counting high purity) with
295  // pt(L2L3)>30
296  //hists_["jetMultBPur_"] = ibooker.book1D("JetMultBPur",
297  // "N_{30}(TCHP)", 10, 0., 10.);
298  // btag discriminator for track counting high purity
299  //hists_["jetBDiscPur_"] = ibooker.book1D("JetBDiscPur",
300  // "Disc_{TCHP}(Jet)", 100, 0., 10.);
301  // multiplicity of btagged jets (for simple secondary vertex) with pt(L2L3)>30
302  //hists_["jetMultBVtx_"] = ibooker.book1D("JetMultBVtx",
303  // "N_{30}(SSVHE)", 10, 0., 10.);
304  // btag discriminator for simple secondary vertex
305  //hists_["jetBDiscVtx_"] = ibooker.book1D("JetBDiscVtx",
306  // "Disc_{SSVHE}(Jet)", 35, -1., 6.);
307  // multiplicity for combined secondary vertex
308  hists_["jetMultBDeepJetM_"] = ibooker.book1D("JetMultBDeepJetM", "N_{30}(DeepJetM)", 10, 0., 10.);
309  // btag discriminator for combined secondary vertex
310  hists_["jetBDeepJet_"] = ibooker.book1D("JetDiscDeepJet", "BJet Disc_{DeepJet}(JET)", 100, -1., 2.);
311  // pt of the 1. leading jet (uncorrected)
312  //hists_["jet1PtRaw_"] = ibooker.book1D("Jet1PtRaw", "pt_{Raw}(jet1)", 60, 0., 300.);
313  // pt of the 2. leading jet (uncorrected)
314  //hists_["jet2PtRaw_"] = ibooker.book1D("Jet2PtRaw", "pt_{Raw}(jet2)", 60, 0., 300.);
315  // pt of the 3. leading jet (uncorrected)
316  //hists_["jet3PtRaw_"] = ibooker.book1D("Jet3PtRaw", "pt_{Raw}(jet3)", 60, 0., 300.);
317  // pt of the 4. leading jet (uncorrected)
318  //hists_["jet4PtRaw_"] = ibooker.book1D("Jet4PtRaw", "pt_{Raw}(jet4)", 60, 0., 300.);
319  // selected events
320  hists_["eventLogger_"] = ibooker.book2D("EventLogger", "Logged Events", 9, 0., 9., 10, 0., 10.);
321 
322  // set axes titles for selected events
323  hists_["eventLogger_"]->getTH1()->SetOption("TEXT");
324  hists_["eventLogger_"]->setBinLabel(1, "Run", 1);
325  hists_["eventLogger_"]->setBinLabel(2, "Block", 1);
326  hists_["eventLogger_"]->setBinLabel(3, "Event", 1);
327  hists_["eventLogger_"]->setBinLabel(4, "pt_{L2L3}(jet1)", 1);
328  hists_["eventLogger_"]->setBinLabel(5, "pt_{L2L3}(jet2)", 1);
329  hists_["eventLogger_"]->setBinLabel(6, "pt_{L2L3}(jet3)", 1);
330  hists_["eventLogger_"]->setBinLabel(7, "pt_{L2L3}(jet4)", 1);
331  hists_["eventLogger_"]->setBinLabel(8, "M_{W}", 1);
332  hists_["eventLogger_"]->setBinLabel(9, "M_{Top}", 1);
333  hists_["eventLogger_"]->setAxisTitle("logged evts", 2);
334  return;
335  }
336 
338  // fetch trigger event if configured such
340 
342  if (!event.getByToken(triggerTable_, triggerTable))
343  return;
344  }
345 
346  /*
347  ------------------------------------------------------------
348 
349  Primary Vertex Monitoring
350 
351  ------------------------------------------------------------
352  */
353  // fill monitoring plots for primary verices
355  if (!event.getByToken(pvs_, pvs))
356  return;
357  const reco::Vertex& pver = pvs->front();
358 
359  unsigned int pvMult = 0;
360  if (pvs.isValid()) {
361  for (edm::View<reco::Vertex>::const_iterator pv = pvs->begin(); pv != pvs->end(); ++pv) {
362  bool isGood =
363  (!(pv->isFake()) && (pv->ndof() > 4.0) && (abs(pv->z()) < 24.0) && (abs(pv->position().Rho()) < 2.0));
364  if (!isGood)
365  continue;
366  pvMult++;
367  }
368  //std::cout<<" npv "<<testn<<endl;
369  }
370 
371  fill("pvMult_", pvMult);
372 
373  /*
374  ------------------------------------------------------------
375 
376  Run and Inst. Luminosity information (Inst. Lumi. filled now with a dummy
377  value=5.0)
378 
379  ------------------------------------------------------------
380  */
381 
382  //if (!event.eventAuxiliary().run()) return;
383 
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))
400  return;
401 
402  edm::Handle<double> _rhoHandle;
403  event.getByLabel(rhoTag, _rhoHandle);
404  //if (!event.getByToken(elecs_, elecs)) return;
405 
406  // check availability of electron id
408  if (!electronId_.isUninitialized()) {
409  if (!event.getByToken(electronId_, electronId))
410  return;
411  }
412 
413  // loop electron collection
414  unsigned int eMultIso = 0, eMult = 0;
415  std::vector<const pat::Electron*> isoElecs;
416 
417  for (edm::View<pat::Electron>::const_iterator elec = elecs->begin(); elec != elecs->end(); ++elec) {
418  if (true) { //loose id
419  if (!elecSelect_ || (*elecSelect_)(*elec)) {
420  double el_ChHadIso = elec->pfIsolationVariables().sumChargedHadronPt;
421  double el_NeHadIso = elec->pfIsolationVariables().sumNeutralHadronEt;
422  double el_PhIso = elec->pfIsolationVariables().sumPhotonEt;
423 
424  double rho = _rhoHandle.isValid() ? (float)(*_rhoHandle) : 0;
425  double absEta = abs(elec->superCluster()->eta());
426  double eA = 0;
427  if (absEta < 1.000)
428  eA = 0.1703;
429  else if (absEta < 1.479)
430  eA = 0.1715;
431  else if (absEta < 2.000)
432  eA = 0.1213;
433  else if (absEta < 2.200)
434  eA = 0.1230;
435  else if (absEta < 2.300)
436  eA = 0.1635;
437  else if (absEta < 2.400)
438  eA = 0.1937;
439  else if (absEta < 5.000)
440  eA = 0.2393;
441 
442  double el_pfRelIso = (el_ChHadIso + max(0., el_NeHadIso + el_PhIso - rho * eA)) / elec->pt();
443 
444  ++eMult;
445 
446  if (eMult == 1) {
447  fill("elecRelIso_", el_pfRelIso);
448  fill("elecChHadIso_", el_ChHadIso);
449  fill("elecNeHadIso_", el_NeHadIso);
450  fill("elecPhIso_", el_PhIso);
451  }
452  //loose Iso
453  //if(!((el_pfRelIso<0.0994 && absEta<1.479)||(el_pfRelIso<0.107 && absEta>1.479)))continue;
454 
455  //tight Iso
456  if (!((el_pfRelIso < 0.0588 && absEta < 1.479) || (el_pfRelIso < 0.0571 && absEta > 1.479)))
457  continue;
458  ++eMultIso;
459 
460  if (eMultIso == 1) {
461  // restrict to the leading electron
462  fill("elecPt_", elec->pt());
463  fill("elecEta_", elec->eta());
464  fill("elecPhi_", elec->phi());
465  }
466  }
467  }
468  }
469  //fill("elecMult_", eMult);
470  fill("elecMultTight_", eMultIso);
471 
472  /*
473  ------------------------------------------------------------
474 
475  Muon Monitoring
476 
477  ------------------------------------------------------------
478  */
479 
480  // fill monitoring plots for muons
481  unsigned int mMult = 0, mTight = 0, mTightId = 0;
482 
485 
486  if (!event.getByToken(muons_, muons))
487  return;
488 
489  for (edm::View<pat::Muon>::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
490  // restrict to globalMuons
491  if (muon->isGlobalMuon()) {
492  fill("muonDelZ_", muon->innerTrack()->vz()); // CB using inner track!
493  fill("muonDelXY_", muon->innerTrack()->vx(), muon->innerTrack()->vy());
494 
495  // apply preselection loose muon
496  if (!muonSelect_ || (*muonSelect_)(*muon)) {
497  //loose muon count
498  ++mMult;
499 
500  double chHadPt = muon->pfIsolationR04().sumChargedHadronPt;
501  double neHadEt = muon->pfIsolationR04().sumNeutralHadronEt;
502  double phoEt = muon->pfIsolationR04().sumPhotonEt;
503 
504  double pfRelIso = (chHadPt + max(0., neHadEt + phoEt - 0.5 * muon->pfIsolationR04().sumPUPt)) /
505  muon->pt(); // CB dBeta corrected iso!
506 
507  if (!(muon->isGlobalMuon() && muon->isPFMuon() && muon->globalTrack()->normalizedChi2() < 10. &&
508  muon->globalTrack()->hitPattern().numberOfValidMuonHits() > 0 && muon->numberOfMatchedStations() > 1 &&
509  fabs(muon->muonBestTrack()->dxy(pver.position())) < 0.2 &&
510  fabs(muon->muonBestTrack()->dz(pver.position())) < 0.5 &&
511  muon->innerTrack()->hitPattern().numberOfValidPixelHits() > 0 &&
512  muon->innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5))
513  continue;
514 
515  if (mTightId == 0) {
516  // restrict to leading muon
517  fill("muonRelIso_", pfRelIso);
518  fill("muonChHadIso_", chHadPt);
519  fill("muonNeHadIso_", neHadEt);
520  fill("muonPhIso_", phoEt);
521  //fill("muonRelIso_", pfRelIso);
522  }
523 
524  if (!(pfRelIso < 0.15))
525  continue;
526  //tight id
527  if (mTight == 0) {
528  // restrict to leading muon
529 
530  fill("muonPt_", muon->pt());
531  fill("muonEta_", muon->eta());
532  fill("muonPhi_", muon->phi());
533  }
534  mTight++;
535  mTightId++;
536  }
537  }
538  }
539  fill("muonMult_", mMult); //loose
540  fill("muonMultTight_", mTight); //tight id & iso
541 
542  /*
543  ------------------------------------------------------------
544 
545  Jet Monitoring
546 
547  ------------------------------------------------------------
548  */
549 
550  // loop jet collection
551  std::vector<pat::Jet> correctedJets;
552  std::vector<double> JetTagValues;
553  unsigned int mult = 0, loosemult = 0, multBDeepJetM = 0;
554 
556  if (!event.getByToken(jets_, jets)) {
557  return;
558  }
559 
560  for (edm::View<pat::Jet>::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
561  // check jetID for calo jets
562  //unsigned int idx = jet - jets->begin();
563 
564  const pat::Jet& sel = *jet;
565 
566  if (!(*jetSelect)(sel))
567  continue;
568  // if (!jetSelect(sel)) continue;
569 
570  // prepare jet to fill monitor histograms
571  const pat::Jet& monitorJet = *jet;
572 
573  ++mult;
574 
575  if (monitorJet.chargedHadronEnergyFraction() > 0 && monitorJet.chargedMultiplicity() > 0 &&
576  monitorJet.chargedEmEnergyFraction() < 0.99 && monitorJet.neutralHadronEnergyFraction() < 0.99 &&
577  monitorJet.neutralEmEnergyFraction() < 0.99 &&
578  (monitorJet.chargedMultiplicity() + monitorJet.neutralMultiplicity()) > 1) {
579  correctedJets.push_back(monitorJet);
580  ++loosemult; // determine jet multiplicity
581 
582  double discriminator = monitorJet.bDiscriminator("pfDeepFlavourJetTags:probb") +
583  monitorJet.bDiscriminator("pfDeepFlavourJetTags:probbb") +
584  monitorJet.bDiscriminator("pfDeepFlavourJetTags:problepb");
585 
586  fill("jetBDeepJet_", discriminator); //hard coded discriminator and value right now.
587  if (discriminator > 0.2435)
588  ++multBDeepJetM;
589 
590  // Fill a vector with Jet b-tag WP for later M3+1tag calculation: DeepJet
591  // tagger
592  JetTagValues.push_back(discriminator);
593  // }
594  // fill pt (raw or L2L3) for the leading four jets
595  if (loosemult == 1) {
596  //cout<<" jet id= "<<monitorJet.chargedHadronEnergyFraction()<<endl;
597 
598  fill("jet1Pt_", monitorJet.pt());
599  //fill("jet1PtRaw_", jet->pt());
600  fill("jet1Eta_", monitorJet.eta());
601  };
602  if (loosemult == 2) {
603  fill("jet2Pt_", monitorJet.pt());
604  //fill("jet2PtRaw_", jet->pt());
605  fill("jet2Eta_", monitorJet.eta());
606  }
607  if (loosemult == 3) {
608  fill("jet3Pt_", monitorJet.pt());
609  //fill("jet3PtRaw_", jet->pt());
610  fill("jet3Eta_", monitorJet.eta());
611  }
612  if (loosemult == 4) {
613  fill("jet4Pt_", monitorJet.pt());
614  //fill("jet4PtRaw_", jet->pt());
615  fill("jet4Eta_", monitorJet.eta());
616  }
617  }
618  }
619  fill("jetMult_", mult);
620  fill("jetLooseMult_", loosemult);
621  fill("jetMultBDeepJetM_", multBDeepJetM);
622 
623  /*
624  ------------------------------------------------------------
625 
626  MET Monitoring
627 
628  ------------------------------------------------------------
629  */
630 
631  // fill monitoring histograms for met
632  for (std::vector<edm::EDGetTokenT<edm::View<pat::MET>>>::const_iterator met_ = mets_.begin(); met_ != mets_.end();
633  ++met_) {
635  if (!event.getByToken(*met_, met))
636  continue;
637  if (met->begin() != met->end()) {
638  unsigned int idx = met_ - mets_.begin();
639  if (idx == 0)
640  fill("slimmedMETs_", met->begin()->et());
641  if (idx == 2)
642  fill("slimmedMETsPuppi_", met->begin()->et());
643  }
644  }
645 
646  /*
647  ------------------------------------------------------------
648 
649  Event Monitoring
650 
651  ------------------------------------------------------------
652  */
653 
654  // fill W boson and top mass estimates
655 
656  Calculate_miniAOD eventKinematics(MAXJETS, WMASS);
657  double wMass = eventKinematics.massWBoson(correctedJets);
658  double topMass = eventKinematics.massTopQuark(correctedJets);
659  if (wMass >= 0 && topMass >= 0) {
660  fill("massW_", wMass);
661  fill("massTop_", topMass);
662  }
663 
664  // Fill M3 with Btag (DeepJet Tight) requirement
665 
666  // if (!includeBTag_) return;
667  if (correctedJets.size() != JetTagValues.size())
668  return;
669 
670  double btopMass = eventKinematics.massBTopQuark(correctedJets, JetTagValues, 0.2435); //hard coded DeepJet value
671 
672  if (btopMass >= 0)
673  fill("massBTop_", btopMass);
674 
675  // fill plots for trigger monitoring
676  if ((lowerEdge_ == -1. && upperEdge_ == -1.) || (lowerEdge_ < wMass && wMass < upperEdge_)) {
678  fill(event, *triggerTable, "trigger", triggerPaths_);
679  if (logged_ <= hists_.find("eventLogger_")->second->getNbinsY()) {
680  // log runnumber, lumi block, event number & some
681  // more pysics infomation for interesting events
682  fill("eventLogger_", 0.5, logged_ + 0.5, event.eventAuxiliary().run());
683  fill("eventLogger_", 1.5, logged_ + 0.5, event.eventAuxiliary().luminosityBlock());
684  fill("eventLogger_", 2.5, logged_ + 0.5, event.eventAuxiliary().event());
685  //if (correctedJets.size() > 0)
686  if (!correctedJets.empty())
687  fill("eventLogger_", 3.5, logged_ + 0.5, correctedJets[0].pt());
688  if (correctedJets.size() > 1)
689  fill("eventLogger_", 4.5, logged_ + 0.5, correctedJets[1].pt());
690  if (correctedJets.size() > 2)
691  fill("eventLogger_", 5.5, logged_ + 0.5, correctedJets[2].pt());
692  if (correctedJets.size() > 3)
693  fill("eventLogger_", 6.5, logged_ + 0.5, correctedJets[3].pt());
694  fill("eventLogger_", 7.5, logged_ + 0.5, wMass);
695  fill("eventLogger_", 8.5, logged_ + 0.5, topMass);
696  ++logged_;
697  }
698  }
699  }
700 } // namespace TopSingleLepton_miniAOD
701 
703  : vertexSelect_(nullptr),
704  beamspot_(""),
705  beamspotSelect_(nullptr),
706  MuonStep(nullptr),
707  ElectronStep(nullptr),
708  PvStep(nullptr),
709  METStep(nullptr) {
710  JetSteps.clear();
711 
712  // configure preselection
713  edm::ParameterSet presel = cfg.getParameter<edm::ParameterSet>("preselection");
714  if (presel.existsAs<edm::ParameterSet>("trigger")) {
716  triggerTable__ = consumes<edm::TriggerResults>(trigger.getParameter<edm::InputTag>("src"));
717  triggerPaths_ = trigger.getParameter<std::vector<std::string>>("select");
718  }
719  if (presel.existsAs<edm::ParameterSet>("beamspot")) {
721  beamspot_ = beamspot.getParameter<edm::InputTag>("src");
722  beamspot__ = consumes<reco::BeamSpot>(beamspot.getParameter<edm::InputTag>("src"));
724  std::make_unique<StringCutObjectSelector<reco::BeamSpot>>(beamspot.getParameter<std::string>("select"));
725  }
726 
727  // conifgure the selection
728  sel_ = cfg.getParameter<std::vector<edm::ParameterSet>>("selection");
729  setup_ = cfg.getParameter<edm::ParameterSet>("setup");
730  for (unsigned int i = 0; i < sel_.size(); ++i) {
731  selectionOrder_.push_back(sel_.at(i).getParameter<std::string>("label"));
733  std::make_pair(sel_.at(i),
734  std::make_unique<TopSingleLepton_miniAOD::MonitorEnsemble>(
736  }
737  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin(); selIt != selectionOrder_.end();
738  ++selIt) {
739  std::string key = selectionStep(*selIt), type = objectType(*selIt);
740  if (selection_.find(key) != selection_.end()) {
741  if (type == "muons") {
742  MuonStep = std::make_unique<SelectionStep<pat::Muon>>(selection_[key].first, consumesCollector());
743  }
744  if (type == "elecs") {
745  ElectronStep = std::make_unique<SelectionStep<pat::Electron>>(selection_[key].first, consumesCollector());
746  }
747  if (type == "pvs") {
748  PvStep = std::make_unique<SelectionStep<reco::Vertex>>(selection_[key].first, consumesCollector());
749  }
750  if (type == "jets") {
751  JetSteps.push_back(std::make_unique<SelectionStep<pat::Jet>>(selection_[key].first, consumesCollector()));
752  }
753 
754  if (type == "met") {
755  METStep = std::make_unique<SelectionStep<pat::MET>>(selection_[key].first, consumesCollector());
756  }
757  }
758  }
759 }
761  for (auto selIt = selection_.begin(); selIt != selection_.end(); ++selIt) {
762  selIt->second.second->book(ibooker);
763  }
764 }
768  if (!event.getByToken(triggerTable__, triggerTable))
769  return;
770  if (!accept(event, *triggerTable, triggerPaths_))
771  return;
772  }
773  if (!beamspot__.isUninitialized()) {
775  if (!event.getByToken(beamspot__, beamspot))
776  return;
777  if (!(*beamspotSelect_)(*beamspot))
778  return;
779  }
780 
781  unsigned int nJetSteps = -1;
782 
783  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin(); selIt != selectionOrder_.end();
784  ++selIt) {
785  std::string key = selectionStep(*selIt), type = objectType(*selIt);
786  if (selection_.find(key) != selection_.end()) {
787  if (type == "empty") {
788  selection_[key].second->fill(event, setup);
789  }
790  if (type == "muons" && MuonStep != nullptr) {
791  if (MuonStep->select(event)) {
792  selection_[key].second->fill(event, setup);
793  } else
794  break;
795  }
796 
797  if (type == "elecs" && ElectronStep != nullptr) {
798  if (ElectronStep->select(event)) {
799  selection_[key].second->fill(event, setup);
800  } else
801  break;
802  }
803 
804  if (type == "pvs" && PvStep != nullptr) {
805  if (PvStep->selectVertex(event)) {
806  selection_[key].second->fill(event, setup);
807  } else
808  break;
809  }
810 
811  if (type == "jets") {
812  nJetSteps++;
813  if (JetSteps[nJetSteps] != nullptr) {
814  if (JetSteps[nJetSteps]->select(event, setup)) {
815  selection_[key].second->fill(event, setup);
816  } else
817  break;
818  }
819  }
820 
821  if (type == "met" && METStep != nullptr) {
822  if (METStep->select(event)) {
823  selection_[key].second->fill(event, setup);
824  } else
825  break;
826  }
827  }
828  }
829 }
830 
831 // Local Variables:
832 // show-trailing-whitespace: t
833 // truncate-lines: t
834 // End:
std::unique_ptr< StringCutObjectSelector< pat::Muon > > muonIso_
extra isolation criterion on muon
std::unique_ptr< StringCutObjectSelector< reco::JetID > > jetIDSelect_
extra jetID selection on calo jets
std::vector< edm::EDGetTokenT< edm::View< pat::MET > > > mets_
considers a vector of METs
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::unique_ptr< StringCutObjectSelector< pat::Muon > > muonSelect_
extra selection on muons
float bDiscriminator(const std::string &theLabel) const
-— methods for accessing b-tagging info -—
std::unique_ptr< SelectionStep< reco::Vertex > > PvStep
double pt() const final
transverse momentum
std::string objectType(const std::string &label)
std::unique_ptr< StringCutObjectSelector< pat::Electron > > elecIso_
extra isolation criterion on electron
int chargedMultiplicity() const
chargedMultiplicity
Definition: Jet.h:740
edm::EDGetTokenT< edm::View< pat::Jet > > jets_
input sources for monitoring
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label
const Point & position() const
position
Definition: Vertex.h:128
void triggerBinLabels(std::string channel, const std::vector< std::string > labels)
set configurable labels for trigger monitoring histograms
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
edm::EDGetTokenT< edm::View< pat::Electron > > elecs_
static const unsigned int MAXJETS
std::unique_ptr< StringCutObjectSelector< reco::BeamSpot > > beamspotSelect_
string cut selector
int neutralMultiplicity() const
neutralMultiplicity
Definition: Jet.h:464
double massWBoson(const std::vector< pat::Jet > &jets)
calculate W boson mass estimate
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
std::map< std::string, std::pair< edm::ParameterSet, std::unique_ptr< TopSingleLepton_miniAOD::MonitorEnsemble > > > selection_
float neutralHadronEnergyFraction() const
neutralHadronEnergyFraction (relative to uncorrected jet energy)
Definition: Jet.h:402
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
std::vector< edm::ParameterSet > sel_
std::vector< std::string > selectionOrder_
TopSingleLeptonDQM_miniAOD(const edm::ParameterSet &cfg)
default constructor
electronId
when omitted electron plots will be filled w/o cut on electronId
char const * label
edm::EDGetTokenT< reco::BeamSpot > beamspot__
std::string selectionStep(const std::string &label)
std::unique_ptr< StringCutObjectSelector< pat::Jet > > jetSelect
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::unique_ptr< StringCutObjectSelector< reco::Vertex > > pvSelect_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
edm::EDGetTokenT< edm::TriggerResults > triggerTable_
trigger table
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::map< std::string, MonitorElement * > hists_
histogram container
key
prepare the HTCondor submission files and eventually submit them
std::vector< std::string > triggerPaths_
trigger paths
std::unique_ptr< SelectionStep< pat::MET > > METStep
std::vector< std::unique_ptr< SelectionStep< pat::Jet > > > JetSteps
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
do this during the event loop
double massTopQuark(const std::vector< pat::Jet > &jets)
calculate t-quark mass estimate
std::unique_ptr< SelectionStep< pat::Muon > > MuonStep
edm::EDGetTokenT< edm::View< pat::Muon > > muons_
float chargedHadronEnergyFraction() const
chargedHadronEnergyFraction (relative to uncorrected jet energy)
Definition: Jet.h:398
void fill(const edm::Event &event, const edm::EventSetup &setup)
fill monitor histograms with electronId and jetCorrections
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
double massBTopQuark(const std::vector< pat::Jet > &jets, std::vector< double > VbtagWP, double btagWP_)
calculate b-tagged t-quark mass estimate
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:221
double lowerEdge_
mass window upper and lower edge
void book(DQMStore::IBooker &ibooker)
book histograms in subdirectory directory
Analysis-level calorimeter jet class.
Definition: Jet.h:77
int logged_
number of logged interesting events
float chargedEmEnergyFraction() const
chargedEmEnergyFraction (relative to uncorrected jet energy)
Definition: Jet.h:406
bool isValid() const
Definition: HandleBase.h:70
Templated helper class to allow a selection on a certain object collection.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
float neutralEmEnergyFraction() const
neutralEmEnergyFraction (relative to uncorrected jet energy)
Definition: Jet.h:410
std::unique_ptr< StringCutObjectSelector< pat::Electron > > elecSelect_
extra selection on electrons
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Level verbosity_
verbosity level for booking
std::unique_ptr< SelectionStep< pat::Electron > > ElectronStep
edm::EDGetTokenT< edm::TriggerResults > triggerTable__
trigger table
Definition: event.py:1
Definition: Run.h:45
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
double eta() const final
momentum pseudorapidity