CMS 3D CMS Logo

SingleTopTChannelLeptonDQM.cc
Go to the documentation of this file.
10 #include <iostream>
11 #include <memory>
12 
16 using namespace std;
18 
19  // maximal number of leading jets
20  // to be used for top mass estimate
21  static const unsigned int MAXJETS = 4;
22  // nominal mass of the W boson to
23  // be used for the top mass estimate
24  static const double WMASS = 80.4;
25 
26  MonitorEnsemble::MonitorEnsemble(const char* label,
27  const edm::ParameterSet& cfg,
28  const edm::VParameterSet& vcfg,
30  : label_(label),
31  elecSelect_(nullptr),
32  pvSelect_(nullptr),
33  muonIso_(nullptr),
34  muonSelect_(nullptr),
35  jetIDSelect_(nullptr),
36  jetlooseSelection_(nullptr),
37  jetSelection_(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>>(sources.getParameter<edm::InputTag>("muons"));
45  elecs_ = iC.consumes<edm::View<reco::PFCandidate>>(sources.getParameter<edm::InputTag>("elecs"));
46  jets_ = iC.consumes<edm::View<reco::Jet>>(sources.getParameter<edm::InputTag>("jets"));
47  for (edm::InputTag const& tag : sources.getParameter<std::vector<edm::InputTag>>("mets"))
48  mets_.push_back(iC.consumes<edm::View<reco::MET>>(tag));
49  pvs_ = iC.consumes<edm::View<reco::Vertex>>(sources.getParameter<edm::InputTag>("pvs"));
50  // electronExtras are optional; they may be omitted or
51  // empty
52  if (cfg.existsAs<edm::ParameterSet>("elecExtras")) {
53  // rho for PF isolation with EA corrections
54  // eventrhoToken_ =
55  // iC.consumes<double>(edm::InputTag("fixedGridRhoFastjetAll"));
56 
57  edm::ParameterSet elecExtras = 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_ = std::make_unique<StringCutObjectSelector<reco::PFCandidate>>(
62  elecExtras.getParameter<std::string>("select"));
63  }
64 
65  if (elecExtras.existsAs<std::string>("rho")) {
66  rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
67  }
68  // electronId is optional; in case it's not found the
69  // InputTag will remain empty
70  if (elecExtras.existsAs<edm::ParameterSet>("electronId")) {
71  edm::ParameterSet elecId = elecExtras.getParameter<edm::ParameterSet>("electronId");
72  electronId_ = iC.consumes<edm::ValueMap<float>>(elecId.getParameter<edm::InputTag>("src"));
73  eidCutValue_ = elecId.getParameter<double>("cutValue");
74  }
75  }
76  // pvExtras are optional; they may be omitted or empty
77  if (cfg.existsAs<edm::ParameterSet>("pvExtras")) {
78  edm::ParameterSet pvExtras = cfg.getParameter<edm::ParameterSet>("pvExtras");
79  // select is optional; in case it's not found no
80  // selection will be applied
81  if (pvExtras.existsAs<std::string>("select")) {
82  pvSelect_ =
83  std::make_unique<StringCutObjectSelector<reco::Vertex>>(pvExtras.getParameter<std::string>("select"));
84  }
85  }
86  // muonExtras are optional; they may be omitted or empty
87  if (cfg.existsAs<edm::ParameterSet>("muonExtras")) {
88  edm::ParameterSet muonExtras = cfg.getParameter<edm::ParameterSet>("muonExtras");
89  // select is optional; in case it's not found no
90  // selection will be applied
91  if (muonExtras.existsAs<std::string>("select")) {
92  muonSelect_ = std::make_unique<StringCutObjectSelector<reco::PFCandidate>>(
93  muonExtras.getParameter<std::string>("select"));
94  }
95  // isolation is optional; in case it's not found no
96  // isolation will be applied
97  if (muonExtras.existsAs<std::string>("isolation")) {
98  muonIso_ = std::make_unique<StringCutObjectSelector<reco::PFCandidate>>(
99  muonExtras.getParameter<std::string>("isolation"));
100  }
101  }
102 
103  // jetExtras are optional; they may be omitted or
104  // empty
105  if (cfg.existsAs<edm::ParameterSet>("jetExtras")) {
106  edm::ParameterSet jetExtras = cfg.getParameter<edm::ParameterSet>("jetExtras");
107  // jetCorrector is optional; in case it's not found
108  // the InputTag will remain empty
109  if (jetExtras.existsAs<std::string>("jetCorrector")) {
110  jetCorrector_ = iC.esConsumes(edm::ESInputTag("", jetExtras.getParameter<std::string>("jetCorrector")));
111  }
112  // read jetID information if it exists
113  if (jetExtras.existsAs<edm::ParameterSet>("jetID")) {
114  edm::ParameterSet jetID = jetExtras.getParameter<edm::ParameterSet>("jetID");
115  jetIDLabel_ = iC.consumes<reco::JetIDValueMap>(jetID.getParameter<edm::InputTag>("label"));
116  jetIDSelect_ =
117  std::make_unique<StringCutObjectSelector<reco::JetID>>(jetID.getParameter<std::string>("select"));
118  }
119  // select is optional; in case it's not found no
120  // selection will be applied (only implemented for
121  // CaloJets at the moment)
122  if (jetExtras.existsAs<std::string>("select")) {
123  jetSelect_ = jetExtras.getParameter<std::string>("select");
124  jetSelection_ = std::make_unique<StringCutObjectSelector<reco::PFJet>>(jetSelect_);
125  jetlooseSelection_ = std::make_unique<StringCutObjectSelector<reco::PFJet>>(
126  "chargedHadronEnergyFraction()>0 && chargedMultiplicity()>0 && chargedEmEnergyFraction()<0.99 && "
127  "neutralHadronEnergyFraction()<0.99 && neutralEmEnergyFraction()<0.99 && "
128  "(chargedMultiplicity()+neutralMultiplicity())>1");
129  }
130 
131  // jetBDiscriminators are optional; in case they are
132  // not found the InputTag will remain empty; they
133  // consist of pairs of edm::JetFlavorAssociation's &
134  // corresponding working points
135  includeBTag_ = jetExtras.existsAs<edm::ParameterSet>("jetBTaggers");
136  if (includeBTag_) {
137  edm::ParameterSet btagCSV =
138  jetExtras.getParameter<edm::ParameterSet>("jetBTaggers").getParameter<edm::ParameterSet>("cvsVertex");
139  btagCSV_ = iC.consumes<reco::JetTagCollection>(btagCSV.getParameter<edm::InputTag>("label"));
140  btagCSVWP_ = btagCSV.getParameter<double>("workingPoint");
141  }
142  }
143 
144  // triggerExtras are optional; they may be omitted or empty
145  if (cfg.existsAs<edm::ParameterSet>("triggerExtras")) {
146  edm::ParameterSet triggerExtras = cfg.getParameter<edm::ParameterSet>("triggerExtras");
147  triggerTable_ = iC.consumes<edm::TriggerResults>(triggerExtras.getParameter<edm::InputTag>("src"));
148  triggerPaths_ = triggerExtras.getParameter<std::vector<std::string>>("paths");
149  }
150 
151  // massExtras is optional; in case it's not found no mass
152  // window cuts are applied for the same flavor monitor
153  // histograms
154  if (cfg.existsAs<edm::ParameterSet>("massExtras")) {
155  edm::ParameterSet massExtras = cfg.getParameter<edm::ParameterSet>("massExtras");
156  lowerEdge_ = massExtras.getParameter<double>("lowerEdge");
157  upperEdge_ = massExtras.getParameter<double>("upperEdge");
158  }
159 
160  // setup the verbosity level for booking histograms;
161  // per default the verbosity level will be set to
162  // STANDARD. This will also be the chosen level in
163  // the case when the monitoring PSet is not found
165  if (cfg.existsAs<edm::ParameterSet>("monitoring")) {
166  edm::ParameterSet monitoring = cfg.getParameter<edm::ParameterSet>("monitoring");
167  if (monitoring.getParameter<std::string>("verbosity") == "DEBUG")
168  verbosity_ = DEBUG;
169  if (monitoring.getParameter<std::string>("verbosity") == "VERBOSE")
171  if (monitoring.getParameter<std::string>("verbosity") == "STANDARD")
173  }
174  // and don't forget to do the histogram booking
175  directory_ = cfg.getParameter<std::string>("directory");
176  }
177 
179  // set up the current directory path
180  std::string current(directory_);
181  current += label_;
182  ibooker.setCurrentFolder(current);
183 
184  // --- [STANDARD] --- //
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 tight Id and tight Iso
192  hists_["muonMultTight_"] = ibooker.book1D("MuonMultTight", "N_{TightIso,TightId}(#mu)", 10, 0., 10.);
193  // pt of the leading electron
194  hists_["elecPt_"] = ibooker.book1D("ElecPt", "pt(e TightId, TightIso)", 40, 0., 200.);
195  // multiplicity of jets with pt>30 (corrected to L1+L2+L3)
196  hists_["jetMult_"] = ibooker.book1D("JetMult", "N_{30}(jet)", 10, 0., 10.);
197  // multiplicity of loose Id jets with pt>30
198  hists_["jetLooseMult_"] = ibooker.book1D("JetLooseMult", "N_{30,loose}(jet)", 10, 0., 10.);
199 
200  // MET (pflow)
201  hists_["metPflow_"] = ibooker.book1D("METPflow", "MET_{Pflow}", 50, 0., 200.);
202  // W mass estimate
203  hists_["massW_"] = ibooker.book1D("MassW", "M(W)", 60, 0., 300.);
204  // Top mass estimate
205  hists_["massTop_"] = ibooker.book1D("MassTop", "M(Top)", 50, 0., 500.);
206  // W mass transverse estimate mu
207  hists_["MTWm_"] = ibooker.book1D("MTWm", "M_{T}^{W}(#mu)", 60, 0., 300.);
208  // Top mass transverse estimate mu
209  hists_["mMTT_"] = ibooker.book1D("mMTT", "M_{T}^{t}(#mu)", 50, 0., 500.);
210 
211  // W mass transverse estimate e
212  hists_["MTWe_"] = ibooker.book1D("MTWe", "M_{T}^{W}(e)", 60, 0., 300.);
213  // Top mass transverse estimate e
214  hists_["eMTT_"] = ibooker.book1D("eMTT", "M_{T}^{t}(e)", 50, 0., 500.);
215 
216  // set bin labels for trigger monitoring
218 
219  if (verbosity_ == STANDARD)
220  return;
221 
222  // --- [VERBOSE] --- //
223 
224  // eta of the leading muon
225  hists_["muonEta_"] = ibooker.book1D("MuonEta", "#eta(#mu TightId, TightIso)", 30, -3., 3.);
226  // relative isolation of the candidate muon (depending on the decay channel)
227  hists_["muonRelIso_"] = ibooker.book1D("MuonRelIso", "Iso_{Rel}(#mu TightId) (#Delta#beta Corrected)", 50, 0., 1.);
228  // phi of the leading muon
229  hists_["muonPhi_"] = ibooker.book1D("MuonPhi", "#phi(#mu TightId, TightIso)", 40, -4., 4.);
230  // eta of the leading electron
231  hists_["elecEta_"] = ibooker.book1D("ElecEta", "#eta(e tightId, TightIso)", 30, -3., 3.);
232  // std isolation variable of the leading electron
233  hists_["elecRelIso_"] = ibooker.book1D("ElecRelIso", "Iso_{Rel}(e TightId)", 50, 0., 1.);
234  // phi of the leading electron
235  hists_["elecPhi_"] = ibooker.book1D("ElecPhi", "#phi(e tightId, TightIso)", 40, -4., 4.);
236  // multiplicity of tight Id, tight Iso electorns
237  hists_["elecMultTight_"] = ibooker.book1D("ElecMultTight", "N_{TightIso,TightId}(e)", 10, 0., 10.);
238 
239  hists_["jet1Eta_"] = ibooker.book1D("Jet1Eta", "#eta_{30,loose}(jet1)", 60, -3., 3.);
240  // pt of the 1. leading jet (corrected to L2+L3)
241  hists_["jet1Pt_"] = ibooker.book1D("Jet1Pt", "pt_{30,loose}(jet1)", 60, 0., 300.);
242  // eta of the 2. leading jet (corrected to L2+L3)
243  hists_["jet2Eta_"] = ibooker.book1D("Jet2Eta", "#eta_{30,loose}(jet2)", 60, -3., 3.);
244  // pt of the 2. leading jet (corrected to L2+L3)
245  hists_["jet2Pt_"] = ibooker.book1D("Jet2Pt", "pt_{30,loose}(jet2)", 60, 0., 300.);
246 
247  // dz for muons (to suppress cosmis)
248  hists_["muonDelZ_"] = ibooker.book1D("MuonDelZ", "d_{z}(#mu)", 50, -25., 25.);
249  // dxy for muons (to suppress cosmics)
250  hists_["muonDelXY_"] = ibooker.book2D("MuonDelXY", "d_{xy}(#mu)", 50, -0.1, 0.1, 50, -0.1, 0.1);
251 
252  // set axes titles for dxy for muons
253  hists_["muonDelXY_"]->setAxisTitle("x [cm]", 1);
254  hists_["muonDelXY_"]->setAxisTitle("y [cm]", 2);
255 
256  if (verbosity_ == VERBOSE)
257  return;
258 
259  // --- [DEBUG] --- //
260  // charged hadron isolation component of the candidate muon (depending on the
261  // decay channel)
262  hists_["muonChHadIso_"] = ibooker.book1D("MuonChHadIsoComp", "ChHad_{IsoComponent}(#mu TightId)", 50, 0., 5.);
263  // neutral hadron isolation component of the candidate muon (depending on the
264  // decay channel)
265  hists_["muonNeHadIso_"] = ibooker.book1D("MuonNeHadIsoComp", "NeHad_{IsoComponent}(#mu TightId)", 50, 0., 5.);
266  // photon isolation component of the candidate muon (depending on the decay
267  // channel)
268  hists_["muonPhIso_"] = ibooker.book1D("MuonPhIsoComp", "Photon_{IsoComponent}(#mu TightId)", 50, 0., 5.);
269  // charged hadron isolation component of the candidate electron (depending on
270  // the decay channel)
271  hists_["elecChHadIso_"] = ibooker.book1D("ElectronChHadIsoComp", "ChHad_{IsoComponent}(e tightId)", 50, 0., 5.);
272  // neutral hadron isolation component of the candidate electron (depending on
273  // the decay channel)
274  hists_["elecNeHadIso_"] = ibooker.book1D("ElectronNeHadIsoComp", "NeHad_{IsoComponent}(e tightId)", 50, 0., 5.);
275  // photon isolation component of the candidate electron (depending on the
276  // decay channel)
277  hists_["elecPhIso_"] = ibooker.book1D("ElectronPhIsoComp", "Photon_{IsoComponent}(e tightId)", 50, 0., 5.);
278 
279  // multiplicity for combined secondary vertex
280  hists_["jetMultBCSVM_"] = ibooker.book1D("JetMultBCSVM", "N_{30}(CSVM)", 10, 0., 10.);
281  // btag discriminator for combined secondary vertex
282  hists_["jetBCSV_"] = ibooker.book1D("JetDiscCSV", "BJet Disc_{CSV}(JET)", 100, -1., 2.);
283  // pt of the 1. leading jet (uncorrected)
284  // hists_["jet1PtRaw_"] = ibooker.book1D("Jet1PtRaw", "pt_{Raw}(jet1)", 60, 0., 300.);
285  // pt of the 2. leading jet (uncorrected)
286  // hists_["jet2PtRaw_"] = ibooker.book1D("Jet2PtRaw", "pt_{Raw}(jet2)", 60, 0., 300.);
287  // pt of the 3. leading jet (uncorrected)
288  // hists_["jet3PtRaw_"] = ibooker.book1D("Jet3PtRaw", "pt_{Raw}(jet3)", 60, 0., 300.);
289  // pt of the 4. leading jet (uncorrected)
290  // hists_["jet4PtRaw_"] = ibooker.book1D("Jet4PtRaw", "pt_{Raw}(jet4)", 60, 0., 300.);
291  // selected events
292  hists_["eventLogger_"] = ibooker.book2D("EventLogger", "Logged Events", 9, 0., 9., 10, 0., 10.);
293 
294  // set axes titles for selected events
295  hists_["eventLogger_"]->getTH1()->SetOption("TEXT");
296  hists_["eventLogger_"]->setBinLabel(1, "Run", 1);
297  hists_["eventLogger_"]->setBinLabel(2, "Block", 1);
298  hists_["eventLogger_"]->setBinLabel(3, "Event", 1);
299  hists_["eventLogger_"]->setBinLabel(4, "pt_{30,loose}(jet1)", 1);
300  hists_["eventLogger_"]->setBinLabel(5, "pt_{30,loose}(jet2)", 1);
301  hists_["eventLogger_"]->setBinLabel(6, "pt_{30,loose}(jet3)", 1);
302  hists_["eventLogger_"]->setBinLabel(7, "pt_{30,loose}(jet4)", 1);
303  hists_["eventLogger_"]->setBinLabel(8, "M_{W}", 1);
304  hists_["eventLogger_"]->setBinLabel(9, "M_{Top}", 1);
305  hists_["eventLogger_"]->setAxisTitle("logged evts", 2);
306  return;
307  }
308 
310  // fetch trigger event if configured such
312 
313  /*
314  ------------------------------------------------------------
315 
316  Primary Vertex Monitoring
317 
318  ------------------------------------------------------------
319  */
320 
321  // fill monitoring plots for primary verices
323 
324  if (!event.getByToken(pvs_, pvs))
325  return;
326  const reco::Vertex& Pvertex = pvs->front();
327  unsigned int pvMult = 0;
328  for (edm::View<reco::Vertex>::const_iterator pv = pvs->begin(); pv != pvs->end(); ++pv) {
329  if (!pvSelect_ || (*pvSelect_)(*pv))
330  pvMult++;
331  }
332  fill("pvMult_", pvMult);
333  /*
334  ------------------------------------------------------------
335 
336  Electron Monitoring
337 
338  ------------------------------------------------------------
339  */
340 
341  // fill monitoring plots for electrons
344  edm::Handle<double> _rhoHandle;
345  event.getByLabel(rhoTag, _rhoHandle);
346 
347  if (!event.getByToken(elecs_, elecs))
348  return;
349 
350  // check availability of electron id
352  if (!electronId_.isUninitialized()) {
353  if (!event.getByToken(electronId_, electronId)) {
354  return;
355  }
356  }
357  // loop electron collection
358  unsigned int eMult = 0, eMultIso = 0;
359  std::vector<const reco::PFCandidate*> isoElecs;
360 
361  for (edm::View<reco::PFCandidate>::const_iterator elec = elecs->begin(); elec != elecs->end(); ++elec) {
362  if (elec->gsfElectronRef().isNull()) {
363  continue;
364  }
365  reco::GsfElectronRef gsf_el = elec->gsfElectronRef();
366  // restrict to electrons with good electronId
368  ? true
369  : ((double)(*electronId)[gsf_el] >=
370  eidCutValue_)) { //This Electron Id is not currently used, but we can keep this for future needs
371  if (!elecSelect_ || (*elecSelect_)(*elec)) {
372  double el_ChHadIso = gsf_el->pfIsolationVariables().sumChargedHadronPt;
373  double el_NeHadIso = gsf_el->pfIsolationVariables().sumNeutralHadronEt;
374  double el_PhIso = gsf_el->pfIsolationVariables().sumPhotonEt;
375  double absEta = std::abs(gsf_el->superCluster()->eta());
376 
377  //Effective Area computation
378  double eA = 0;
379  if (absEta < 1.000)
380  eA = 0.1703;
381  else if (absEta < 1.479)
382  eA = 0.1715;
383  else if (absEta < 2.000)
384  eA = 0.1213;
385  else if (absEta < 2.200)
386  eA = 0.1230;
387  else if (absEta < 2.300)
388  eA = 0.1635;
389  else if (absEta < 2.400)
390  eA = 0.1937;
391  else if (absEta < 5.000)
392  eA = 0.2393;
393 
394  double rho = _rhoHandle.isValid() ? (float)(*_rhoHandle) : 0;
395  double el_pfRelIso = (el_ChHadIso + max(0., el_NeHadIso + el_PhIso - rho * eA)) / gsf_el->pt();
396 
397  //Only TightId
398  if (eMult == 0) { // Restricted to the leading tight electron
399  fill("elecRelIso_", el_pfRelIso);
400  fill("elecChHadIso_", el_ChHadIso);
401  fill("elecNeHadIso_", el_NeHadIso);
402  fill("elecPhIso_", el_PhIso);
403  }
404  ++eMult;
405 
406  if (!((el_pfRelIso < 0.0588 && absEta < 1.479) || (el_pfRelIso < 0.0571 && absEta > 1.479)))
407  continue; // PF Isolation with Effective Area Corrections according to https://twiki.cern.ch/twiki/bin/viewauth/CMS/CutBasedElectronIdentificationRun2
408 
409  // TightId and TightIso
410  if (eMultIso == 0) { //Only leading
411  e = *gsf_el;
412  fill("elecPt_", gsf_el->pt());
413  fill("elecEta_", gsf_el->eta());
414  fill("elecPhi_", gsf_el->phi());
415  }
416  ++eMultIso;
417  }
418  }
419  }
420  //fill("elecMult_", eMult);
421  fill("elecMultTight_", eMultIso);
422 
423  /*
424  ------------------------------------------------------------
425 
426  Muon Monitoring
427 
428  ------------------------------------------------------------
429  */
430 
431  // fill monitoring plots for muons
432  unsigned int mMult = 0, mTight = 0, mTightId = 0;
433 
437  reco::Muon mu;
438 
439  if (!event.getByToken(muons_, muons))
440  return;
441 
442  for (edm::View<reco::PFCandidate>::const_iterator muonit = muons->begin(); muonit != muons->end(); ++muonit) {
443  if (muonit->muonRef().isNull())
444  continue;
445  reco::MuonRef muon = muonit->muonRef();
446 
447  // restrict to globalMuons
448  if (muon->isGlobalMuon()) {
449  fill("muonDelZ_", muon->innerTrack()->vz()); // CB using inner track!
450  fill("muonDelXY_", muon->innerTrack()->vx(), muon->innerTrack()->vy());
451 
452  // apply preselection
453  if ((!muonSelect_ || (*muonSelect_)(*muonit))) {
454  mMult++;
455  double chHadPt = muon->pfIsolationR04().sumChargedHadronPt;
456  double neHadEt = muon->pfIsolationR04().sumNeutralHadronEt;
457  double phoEt = muon->pfIsolationR04().sumPhotonEt;
458  double pfRelIso = (chHadPt + max(0., neHadEt + phoEt - 0.5 * muon->pfIsolationR04().sumPUPt)) /
459  muon->pt(); // CB dBeta corrected iso!
460 
461  if (!(muon->isGlobalMuon() && muon->isPFMuon() && muon->globalTrack()->normalizedChi2() < 10. &&
462  muon->globalTrack()->hitPattern().numberOfValidMuonHits() > 0 && muon->numberOfMatchedStations() > 1 &&
463  muon->innerTrack()->hitPattern().numberOfValidPixelHits() > 0 &&
464  muon->innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5 &&
465  fabs(muon->muonBestTrack()->dxy(Pvertex.position())) < 0.2 &&
466  fabs(muon->muonBestTrack()->dz(Pvertex.position())) < 0.5))
467  continue; //Only tight muons
468 
469  if (mTightId == 0) {
470  fill("muonRelIso_", pfRelIso);
471  fill("muonChHadIso_", chHadPt);
472  fill("muonNeHadIso_", neHadEt);
473  fill("muonPhIso_", phoEt);
474  }
475  mTightId++;
476 
477  if (!(pfRelIso < 0.15))
478  continue; //Tight Iso
479 
480  if (mTight == 0) { //Leading tightId tightIso muon
481  mu = *(muon);
482  fill("muonPt_", muon->pt());
483  fill("muonEta_", muon->eta());
484  fill("muonPhi_", muon->phi());
485  }
486  mTight++;
487  }
488  }
489  }
490  fill("muonMult_", mMult);
491  fill("muonMultTight_", mTight);
492 
493  /*
494  ------------------------------------------------------------
495 
496  Jet Monitoring
497 
498  ------------------------------------------------------------
499  */
500 
501  // check availability of the btaggers
502  edm::Handle<reco::JetTagCollection> btagEff, btagPur, btagVtx, btagCSV;
503  if (includeBTag_) {
504  if (!event.getByToken(btagCSV_, btagCSV))
505  return;
506  }
507 
508  // load jet
509  // corrector if configured such
510  const JetCorrector* corrector = nullptr;
512  // check whether a jet correcto is in the event setup or not
513  if (setup.find(edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>())) {
514  corrector = &setup.getData(jetCorrector_);
515  ;
516  } else {
517  edm::LogVerbatim("SingleTopTChannelLeptonDQM")
518  << "\n"
519  << "-----------------------------------------------------------------"
520  "-------------------- \n"
521  << " No JetCorrectionsRecord available from EventSetup:\n"
522  << " - Jets will not be corrected.\n"
523  << " - If you want to change this add the following lines to your "
524  "cfg file:\n"
525  << "\n"
526  << " ## load jet corrections\n"
527  << " "
528  "process.load(\"JetMETCorrections.Configuration."
529  "JetCorrectionServicesAllAlgos_cff\") \n"
530  << " process.prefer(\"ak5CaloL2L3\")\n"
531  << "\n"
532  << "-----------------------------------------------------------------"
533  "-------------------- \n";
534  }
535  }
536  // loop jet collection
537  std::vector<reco::Jet> correctedJets;
538  std::vector<double> JetTagValues;
539  reco::Jet TaggedJetCand;
540  unsigned int mult = 0, multLoose = 0, multCSV = 0;
541  vector<double> bJetDiscVal;
542 
544  if (!event.getByToken(jets_, jets)) {
545  return;
546  }
547 
548  for (edm::View<reco::Jet>::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
549  bool isLoose = false;
550  // check jetID for calo jets, keep functionality if we ever want to go back to those
551  // unsigned int idx = jet - jets->begin();
552  // if (dynamic_cast<const reco::CaloJet*>(&*jet)) {
553  // if (jetIDSelect_ &&
554  // dynamic_cast<const reco::CaloJet*>(jets->refAt(idx).get())) {
555  // if (!(*jetIDSelect_)((*jetID)[jets->refAt(idx)])) continue;
556  // }
557  // }
558 
559  // check additional jet selection for pf jets
560  if (dynamic_cast<const reco::PFJet*>(&*jet)) {
561  reco::PFJet sel = dynamic_cast<const reco::PFJet&>(*jet);
562  if ((*jetlooseSelection_)(sel))
563  isLoose = true;
564  sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
565  if (!(*jetSelection_)(sel))
566  continue;
567  }
568  // prepare jet to fill monitor histograms
569  reco::Jet monitorJet = *jet;
570 
571  ++mult; // determine jet (no Id) multiplicity
572  monitorJet.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
573 
574  if (isLoose) { //Loose Id
575  unsigned int idx = jet - jets->begin();
576  correctedJets.push_back(monitorJet);
577  if (includeBTag_) {
578  // fill b-discriminators
579  edm::RefToBase<reco::Jet> jetRef = jets->refAt(idx);
580  fill("jetBCSV_", (*btagCSV)[jetRef]);
581  if ((*btagCSV)[jetRef] > btagCSVWP_) {
582  if (multCSV == 0) {
583  TaggedJetCand = monitorJet;
584  bJetDiscVal.push_back((*btagCSV)[jetRef]);
585  } else if (multCSV == 1) {
586  bJetDiscVal.push_back((*btagCSV)[jetRef]);
587  if (bJetDiscVal[1] > bJetDiscVal[0])
588  TaggedJetCand = monitorJet;
589  }
590  ++multCSV;
591  }
592  JetTagValues.push_back((*btagCSV)[jetRef]);
593  }
594 
595  // fill pt/eta for the leading four jets
596  if (multLoose == 0) {
597  fill("jet1Pt_", monitorJet.pt());
598  fill("jet1Eta_", monitorJet.eta());
599  };
600  if (multLoose == 1) {
601  fill("jet2Pt_", monitorJet.pt());
602  fill("jet2Eta_", monitorJet.eta());
603  }
604  multLoose++;
605  }
606  }
607  fill("jetMult_", mult);
608  fill("jetMultLoose_", multLoose);
609  fill("jetMultBCSVM_", multCSV);
610 
611  /*
612  ------------------------------------------------------------
613 
614  MET Monitoring
615 
616  ------------------------------------------------------------
617  */
618 
619  // fill monitoring histograms for met
620  reco::MET mET;
621  for (std::vector<edm::EDGetTokenT<edm::View<reco::MET>>>::const_iterator met_ = mets_.begin(); met_ != mets_.end();
622  ++met_) {
624  if (!event.getByToken(*met_, met))
625  continue;
626  if (met->begin() != met->end()) {
627  unsigned int idx = met_ - mets_.begin();
628  if (idx == 0) {
629  fill("metPflow_", met->begin()->et());
630  mET = *(met->begin());
631  }
632  }
633  }
634 
635  /*
636  ------------------------------------------------------------
637 
638  Event Monitoring
639 
640  ------------------------------------------------------------
641  */
642 
643  // fill W boson and top mass estimates
644  Calculate eventKinematics(MAXJETS, WMASS);
645  double wMass = eventKinematics.massWBoson(correctedJets);
646  double topMass = eventKinematics.massTopQuark(correctedJets);
647  if (wMass >= 0 && topMass >= 0) {
648  fill("massW_", wMass);
649  fill("massTop_", topMass);
650  }
651  // fill plots for trigger monitoring
652  if ((lowerEdge_ == -1. && upperEdge_ == -1.) || (lowerEdge_ < wMass && wMass < upperEdge_)) {
654  fill(event, *triggerTable, "trigger", triggerPaths_);
655  if (logged_ <= hists_.find("eventLogger_")->second->getNbinsY()) {
656  // log runnumber, lumi block, event number & some
657  // more pysics infomation for interesting events
658  fill("eventLogger_", 0.5, logged_ + 0.5, event.eventAuxiliary().run());
659  fill("eventLogger_", 1.5, logged_ + 0.5, event.eventAuxiliary().luminosityBlock());
660  fill("eventLogger_", 2.5, logged_ + 0.5, event.eventAuxiliary().event());
661  if (!correctedJets.empty())
662  fill("eventLogger_", 3.5, logged_ + 0.5, correctedJets[0].pt());
663  if (correctedJets.size() > 1)
664  fill("eventLogger_", 4.5, logged_ + 0.5, correctedJets[1].pt());
665  if (correctedJets.size() > 2)
666  fill("eventLogger_", 5.5, logged_ + 0.5, correctedJets[2].pt());
667  if (correctedJets.size() > 3)
668  fill("eventLogger_", 6.5, logged_ + 0.5, correctedJets[3].pt());
669  fill("eventLogger_", 7.5, logged_ + 0.5, wMass);
670  fill("eventLogger_", 8.5, logged_ + 0.5, topMass);
671  ++logged_;
672  }
673  }
674  if (multCSV != 0 && mTight == 1) {
675  double mtW = eventKinematics.tmassWBoson(&mu, mET, TaggedJetCand);
676  fill("MTWm_", mtW);
677  double MTT = eventKinematics.tmassTopQuark(&mu, mET, TaggedJetCand);
678  fill("mMTT_", MTT);
679  }
680 
681  if (multCSV != 0 && eMultIso == 1) {
682  double mtW = eventKinematics.tmassWBoson(&e, mET, TaggedJetCand);
683  fill("MTWe_", mtW);
684  double MTT = eventKinematics.tmassTopQuark(&e, mET, TaggedJetCand);
685  fill("eMTT_", MTT);
686  }
687  }
688 } // namespace SingleTopTChannelLepton
689 
691  : vertexSelect_(nullptr),
692  beamspot_(""),
693  beamspotSelect_(nullptr),
694  MuonStep(nullptr),
695  PFMuonStep(nullptr),
696  ElectronStep(nullptr),
697  PFElectronStep(nullptr),
698  PvStep(nullptr),
699  METStep(nullptr) {
700  JetSteps.clear();
701  CaloJetSteps.clear();
702  PFJetSteps.clear();
703  // configure preselection
704  edm::ParameterSet presel = cfg.getParameter<edm::ParameterSet>("preselection");
705  if (presel.existsAs<edm::ParameterSet>("trigger")) {
707  triggerTable__ = consumes<edm::TriggerResults>(trigger.getParameter<edm::InputTag>("src"));
708  triggerPaths_ = trigger.getParameter<std::vector<std::string>>("select");
709  }
710  if (presel.existsAs<edm::ParameterSet>("beamspot")) {
712  beamspot_ = beamspot.getParameter<edm::InputTag>("src");
713  beamspot__ = consumes<reco::BeamSpot>(beamspot.getParameter<edm::InputTag>("src"));
715  std::make_unique<StringCutObjectSelector<reco::BeamSpot>>(beamspot.getParameter<std::string>("select"));
716  }
717  // configure the selection
718  std::vector<edm::ParameterSet> sel = cfg.getParameter<std::vector<edm::ParameterSet>>("selection");
719 
720  for (unsigned int i = 0; i < sel.size(); ++i) {
721  selectionOrder_.push_back(sel.at(i).getParameter<std::string>("label"));
723  std::make_pair(sel.at(i),
724  std::make_unique<SingleTopTChannelLepton::MonitorEnsemble>(
725  selectionStep(selectionOrder_.back()).c_str(),
726  cfg.getParameter<edm::ParameterSet>("setup"),
727  cfg.getParameter<std::vector<edm::ParameterSet>>("selection"),
728  consumesCollector()));
729  }
730  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin(); selIt != selectionOrder_.end();
731  ++selIt) {
732  std::string key = selectionStep(*selIt), type = objectType(*selIt);
733  if (selection_.find(key) != selection_.end()) {
734  using std::unique_ptr;
735 
736  if (type == "muons") {
737  MuonStep = std::make_unique<SelectionStep<reco::Muon>>(selection_[key].first, consumesCollector());
738  }
739  if (type == "muons/pf") {
740  PFMuonStep = std::make_unique<SelectionStep<reco::PFCandidate>>(selection_[key].first, consumesCollector());
741  }
742  if (type == "elecs") {
743  ElectronStep = std::make_unique<SelectionStep<reco::GsfElectron>>(selection_[key].first, consumesCollector());
744  }
745  if (type == "elecs/pf") {
746  PFElectronStep = std::make_unique<SelectionStep<reco::PFCandidate>>(selection_[key].first, consumesCollector());
747  }
748  if (type == "pvs") {
749  PvStep = std::make_unique<SelectionStep<reco::Vertex>>(selection_[key].first, consumesCollector());
750  }
751  if (type == "jets") {
752  JetSteps.push_back(std::make_unique<SelectionStep<reco::Jet>>(selection_[key].first, consumesCollector()));
753  }
754  if (type == "jets/pf") {
756  }
757  if (type == "jets/calo") {
758  CaloJetSteps.push_back(
760  }
761  if (type == "met") {
762  METStep = std::make_unique<SelectionStep<reco::MET>>(selection_[key].first, consumesCollector());
763  }
764  }
765  }
766 }
768  for (auto selIt = selection_.begin(); selIt != selection_.end(); ++selIt) {
769  selIt->second.second->book(ibooker);
770  }
771 }
775  if (!event.getByToken(triggerTable__, triggerTable))
776  return;
777  if (!accept(event, *triggerTable, triggerPaths_))
778  return;
779  }
780  if (!beamspot__.isUninitialized()) {
782  if (!event.getByToken(beamspot__, beamspot))
783  return;
784  if (!(*beamspotSelect_)(*beamspot))
785  return;
786  }
787  // apply selection steps
788  unsigned int passed = 0;
789  unsigned int nJetSteps = -1;
790  unsigned int nPFJetSteps = -1;
791  unsigned int nCaloJetSteps = -1;
792  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin(); selIt != selectionOrder_.end();
793  ++selIt) {
794  std::string key = selectionStep(*selIt), type = objectType(*selIt);
795  if (selection_.find(key) != selection_.end()) {
796  if (type == "empty") {
797  selection_[key].second->fill(event, setup);
798  }
799  if (type == "presel") {
800  selection_[key].second->fill(event, setup);
801  }
802  if (type == "elecs" && ElectronStep != nullptr) {
803  if (ElectronStep->select(event)) {
804  ++passed;
805  selection_[key].second->fill(event, setup);
806  } else
807  break;
808  }
809  if (type == "elecs/pf" && PFElectronStep != nullptr) {
810  if (PFElectronStep->select(event, "electron")) {
811  ++passed;
812 
813  selection_[key].second->fill(event, setup);
814 
815  } else
816  break;
817  }
818  if (type == "muons" && MuonStep != nullptr) {
819  if (MuonStep->select(event)) {
820  ++passed;
821  selection_[key].second->fill(event, setup);
822  } else
823  break;
824  }
825  if (type == "muons/pf" && PFMuonStep != nullptr) {
826  if (PFMuonStep->select(event, "muon")) {
827  ++passed;
828  selection_[key].second->fill(event, setup);
829  } else
830  break;
831  }
832  if (type == "jets") {
833  nJetSteps++;
834  if (JetSteps[nJetSteps]) {
835  if (JetSteps[nJetSteps]->select(event, setup)) {
836  ++passed;
837  selection_[key].second->fill(event, setup);
838  } else
839  break;
840  }
841  }
842  if (type == "jets/pf") {
843  nPFJetSteps++;
844  if (PFJetSteps[nPFJetSteps]) {
845  if (PFJetSteps[nPFJetSteps]->select(event, setup)) {
846  ++passed;
847  selection_[key].second->fill(event, setup);
848  } else
849  break;
850  }
851  }
852  if (type == "jets/calo") {
853  nCaloJetSteps++;
854  if (CaloJetSteps[nCaloJetSteps]) {
855  if (CaloJetSteps[nCaloJetSteps]->select(event, setup)) {
856  ++passed;
857  selection_[key].second->fill(event, setup);
858  } else
859  break;
860  }
861  }
862  if (type == "met" && METStep != nullptr) {
863  if (METStep->select(event)) {
864  ++passed;
865  selection_[key].second->fill(event, setup);
866  } else
867  break;
868  }
869  }
870  }
871 }
std::vector< std::string > selectionOrder_
std::map< std::string, MonitorElement * > hists_
Log< level::Info, true > LogVerbatim
std::string objectType(const std::string &label)
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
virtual void scaleEnergy(double fScale)
scale energy of the jet
std::vector< std::string > triggerPaths_
trigger paths
Level verbosity_
verbosity level for booking
double pt() const final
transverse momentum
std::unique_ptr< StringCutObjectSelector< reco::PFJet > > jetlooseSelection_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
std::unique_ptr< SelectionStep< reco::Vertex > > PvStep
const Point & position() const
position
Definition: Vertex.h:127
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
Base class for all types of Jets.
Definition: Jet.h:20
int logged_
number of logged interesting events
std::vector< std::unique_ptr< SelectionStep< reco::CaloJet > > > CaloJetSteps
std::vector< std::unique_ptr< SelectionStep< reco::Jet > > > JetSteps
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
double massTopQuark(const std::vector< reco::Jet > &jets)
calculate t-quark mass estimate
edm::EDGetTokenT< edm::TriggerResults > triggerTable__
trigger table
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
edm::EDGetTokenT< edm::View< reco::PFCandidate > > muons_
Jets made from PFObjects.
Definition: PFJet.h:20
double massWBoson(const std::vector< reco::Jet > &jets)
calculate W boson mass estimate
SingleTopTChannelLeptonDQM(const edm::ParameterSet &cfg)
default constructor
electronId
when omitted electron plots will be filled w/o cut on electronId
constexpr bool hasValidIndex() const noexcept
Definition: ESGetToken.h:74
char const * label
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > muonSelect_
extra selection on muons
Helper class for the calculation of a top and a W boson mass estime.
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > muonIso_
extra isolation criterion on muon
double lowerEdge_
mass window upper and lower edge
void triggerBinLabels(std::string channel, const std::vector< std::string > labels)
set configurable labels for trigger monitoring histograms
std::vector< edm::ParameterSet > sel
constexpr bool isInitialized() const noexcept
Definition: ESGetToken.h:72
Definition: MET.h:41
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< StringCutObjectSelector< reco::Vertex > > pvSelect_
edm::ESGetToken< JetCorrector, JetCorrectionsRecord > jetCorrector_
jetCorrector
double tmassTopQuark(reco::RecoCandidate *lep, const reco::MET &met, const reco::Jet &b)
calculate top quark transverse mass estimate
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::unique_ptr< StringCutObjectSelector< reco::JetID > > jetIDSelect_
extra jetID selection on calo jets
std::unique_ptr< SelectionStep< reco::PFCandidate > > PFElectronStep
edm::EDGetTokenT< edm::TriggerResults > triggerTable_
trigger table
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label
edm::EDGetTokenT< reco::JetTagCollection > btagCSV_
std::string selectionStep(const std::string &label)
double tmassWBoson(reco::RecoCandidate *lep, const reco::MET &met, const reco::Jet &b)
calculate W boson transverse mass estimate
std::unique_ptr< SelectionStep< reco::GsfElectron > > ElectronStep
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
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
edm::EDGetTokenT< edm::View< reco::PFCandidate > > elecs_
std::unique_ptr< SelectionStep< reco::MET > > METStep
static const unsigned int MAXJETS
bool isValid() const
Definition: HandleBase.h:70
std::vector< edm::EDGetTokenT< edm::View< reco::MET > > > mets_
considers a vector of METs
Templated helper class to allow a selection on a certain object collection.
void fill(const edm::Event &event, const edm::EventSetup &setup)
fill monitor histograms with electronId and jetCorrections
edm::EDGetTokenT< edm::View< reco::Jet > > jets_
input sources for monitoring
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
void book(DQMStore::IBooker &ibooker)
book histograms in subdirectory directory
edm::EDGetTokenT< reco::BeamSpot > beamspot__
std::unique_ptr< StringCutObjectSelector< reco::BeamSpot > > beamspotSelect_
string cut selector
std::unique_ptr< StringCutObjectSelector< reco::PFJet > > jetSelection_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
do this during the event loop
std::vector< std::unique_ptr< SelectionStep< reco::PFJet > > > PFJetSteps
std::map< std::string, std::pair< edm::ParameterSet, std::unique_ptr< SingleTopTChannelLepton::MonitorEnsemble > > > selection_
std::unique_ptr< SelectionStep< reco::Muon > > MuonStep
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > elecSelect_
extra selection on electrons
Definition: event.py:1
Definition: Run.h:45
std::unique_ptr< SelectionStep< reco::PFCandidate > > PFMuonStep
double eta() const final
momentum pseudorapidity