CMS 3D CMS Logo

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