CMS 3D CMS Logo

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