CMS 3D CMS Logo

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