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 
541  // loop jet collection
542  std::vector<reco::Jet> correctedJets;
543  std::vector<double> JetTagValues;
544  unsigned int mult = 0, multLoose = 0, multCSV = 0;
545 
547  if (!event.getByToken(jets_, jets)) {
548  return;
549  }
550 
551  for (edm::View<reco::Jet>::const_iterator jet = jets->begin();
552  jet != jets->end(); ++jet) {
553  bool isLoose = false;
554  // check additional jet selection for pf jets
555  if (dynamic_cast<const reco::PFJet*>(&*jet)) {
556  reco::PFJet sel = dynamic_cast<const reco::PFJet&>(*jet);
557  if ((*jetlooseSelection_)(sel)) isLoose = true;
558  sel.scaleEnergy(corrector->correction(*jet));
559  if (!(*jetSelection_)(sel)) continue;
560  }
561 
562  // prepare jet to fill monitor histograms
563  reco::Jet monitorJet = *jet;
564 
565  ++mult; // determine jet (no Id) multiplicity
566  monitorJet.scaleEnergy(corrector->correction(*jet));
567 
568  if (isLoose){ //Loose Id
569  unsigned int idx = jet - jets->begin();
570  correctedJets.push_back(monitorJet);
571  if (includeBTag_) {
572  // fill b-discriminators
573  edm::RefToBase<reco::Jet> jetRef = jets->refAt(idx);
574  fill("jetBCSV_", (*btagCSV)[jetRef]);
575  if ((*btagCSV)[jetRef] > btagCSVWP_) ++multCSV;
576  // Fill a vector with Jet b-tag WP for later M3+1tag calculation: CSV
577  // tagger
578  JetTagValues.push_back((*btagCSV)[jetRef]);
579  }
580 
581  // fill pt/eta for the leading four jets
582  if (multLoose == 0) {
583  fill("jet1Pt_", monitorJet.pt());
584  fill("jet1Eta_", monitorJet.eta());
585  };
586  if (multLoose == 1) {
587  fill("jet2Pt_", monitorJet.pt());
588  fill("jet2Eta_", monitorJet.eta());
589  }
590  if (multLoose == 2) {
591  fill("jet3Pt_", monitorJet.pt());
592  fill("jet3Eta_", monitorJet.eta());
593  }
594  if (multLoose == 3) {
595  fill("jet4Pt_", monitorJet.pt());
596  fill("jet4Eta_", monitorJet.eta());
597  }
598  multLoose++;
599  }
600  }
601  fill("jetMult_" , mult);
602  fill("jetMultLoose_", multLoose);
603  fill("jetMultBCSVM_", multCSV);
604 
605  /*
606  ------------------------------------------------------------
607 
608  MET Monitoring
609 
610  ------------------------------------------------------------
611  */
612 
613  // fill monitoring histograms for met
614  for (std::vector<edm::EDGetTokenT<edm::View<reco::MET> > >::const_iterator
615  met_ = mets_.begin();
616  met_ != mets_.end(); ++met_) {
618  if (!event.getByToken(*met_, met)) continue;
619  if (met->begin() != met->end()) {//If we ever have to use more than one type of met again
620  unsigned int idx = met_ - mets_.begin();
621  if (idx == 0) fill("metPflow_", met->begin()->et());
622  }
623  }
624 
625  /*
626  ------------------------------------------------------------
627 
628  Event Monitoring
629 
630  ------------------------------------------------------------
631  */
632 
633  // fill W boson and top mass estimates
634 
635  Calculate eventKinematics(MAXJETS, WMASS);
636  double wMass = eventKinematics.massWBoson(correctedJets);
637  double topMass = eventKinematics.massTopQuark(correctedJets);
638  if (wMass >= 0 && topMass >= 0) {
639  fill("massW_", wMass);
640  fill("massTop_", topMass);
641  }
642 
643  // Fill M3 with Btag (CSV Tight) requirement
644 
645  if (!includeBTag_) return;
646  if (correctedJets.size() != JetTagValues.size()) return;
647  double btopMass =
648  eventKinematics.massBTopQuark(correctedJets, JetTagValues, btagCSVWP_);
649  if (btopMass >= 0) fill("massBTop_", btopMass);
650 
651  // fill plots for trigger monitoring
652  if ((lowerEdge_ == -1. && upperEdge_ == -1.) ||
653  (lowerEdge_ < wMass && wMass < upperEdge_)) {
655  fill(event, *triggerTable, "trigger", triggerPaths_);
656  if (logged_ <= hists_.find("eventLogger_")->second->getNbinsY()) {
657  // log runnumber, lumi block, event number & some
658  // more pysics infomation for interesting events
659  fill("eventLogger_", 0.5, logged_ + 0.5, event.eventAuxiliary().run());
660  fill("eventLogger_", 1.5, logged_ + 0.5,
661  event.eventAuxiliary().luminosityBlock());
662  fill("eventLogger_", 2.5, logged_ + 0.5, event.eventAuxiliary().event());
663  if (correctedJets.size() > 0)
664  fill("eventLogger_", 3.5, logged_ + 0.5, correctedJets[0].pt());
665  if (correctedJets.size() > 1)
666  fill("eventLogger_", 4.5, logged_ + 0.5, correctedJets[1].pt());
667  if (correctedJets.size() > 2)
668  fill("eventLogger_", 5.5, logged_ + 0.5, correctedJets[2].pt());
669  if (correctedJets.size() > 3)
670  fill("eventLogger_", 6.5, logged_ + 0.5, correctedJets[3].pt());
671  fill("eventLogger_", 7.5, logged_ + 0.5, wMass);
672  fill("eventLogger_", 8.5, logged_ + 0.5, topMass);
673  ++logged_;
674  }
675  }
676 }
677 }
678 
680  : vertexSelect_(nullptr),
681  beamspot_(""),
682  beamspotSelect_(nullptr),
683  MuonStep(nullptr),
684  ElectronStep(nullptr),
685  PvStep(nullptr),
686  METStep(nullptr) {
687  JetSteps.clear();
688  CaloJetSteps.clear();
689  PFJetSteps.clear();
690  // configure preselection
691  edm::ParameterSet presel =
692  cfg.getParameter<edm::ParameterSet>("preselection");
693  if (presel.existsAs<edm::ParameterSet>("trigger")) {
695  presel.getParameter<edm::ParameterSet>("trigger");
696  triggerTable__ = consumes<edm::TriggerResults>(
697  trigger.getParameter<edm::InputTag>("src"));
698  triggerPaths_ = trigger.getParameter<std::vector<std::string> >("select");
699  }
700  if (presel.existsAs<edm::ParameterSet>("beamspot")) {
702  presel.getParameter<edm::ParameterSet>("beamspot");
703  beamspot_ = beamspot.getParameter<edm::InputTag>("src");
704  beamspot__ =
705  consumes<reco::BeamSpot>(beamspot.getParameter<edm::InputTag>("src"));
707  beamspot.getParameter<std::string>("select")));
708  }
709 
710  // configure the selection
711  sel_ = cfg.getParameter<std::vector<edm::ParameterSet> >("selection");
712  setup_ = cfg.getParameter<edm::ParameterSet>("setup");
713  for (unsigned int i = 0; i < sel_.size(); ++i) {
714  selectionOrder_.push_back(sel_.at(i).getParameter<std::string>("label"));
715  selection_[selectionStep(selectionOrder_.back())] = std::make_pair(
716  sel_.at(i),
717  std::unique_ptr<TopSingleLepton::MonitorEnsemble>(
719  selectionStep(selectionOrder_.back()).c_str(),
721  }
722  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin();
723  selIt != selectionOrder_.end(); ++selIt) {
724  std::string key = selectionStep(*selIt), type = objectType(*selIt);
725  if (selection_.find(key) != selection_.end()) {
726  if (type == "muons") {
728  consumesCollector()));
729  }
730  if (type == "elecs") {
733  }
734  if (type == "pvs") {
736  consumesCollector()));
737  }
738  if (type == "jets") {
739  JetSteps.push_back(std::unique_ptr<SelectionStep<reco::Jet>>(
741  }
742  if (type == "jets/pf") {
743  PFJetSteps.push_back(std::unique_ptr<SelectionStep<reco::PFJet>>(
745  }
746  if (type == "jets/calo") {
747  CaloJetSteps.push_back(std::unique_ptr<SelectionStep<reco::CaloJet>>(
749  }
750  if (type == "met") {
752  consumesCollector()));
753  }
754  }
755  }
756 }
758  edm::Run const &, edm::EventSetup const & ){
759 
760  for (auto selIt = selection_.begin(); selIt != selection_.end(); ++selIt) {
761  selIt->second.second->book(ibooker);
762  }
763 }
765  const edm::EventSetup& setup) {
766 
769  if (!event.getByToken(triggerTable__, triggerTable)) return;
770  if (!accept(event, *triggerTable, triggerPaths_)) return;
771  }
772  if (!beamspot__.isUninitialized()) {
774  if (!event.getByToken(beamspot__, beamspot)) return;
775  if (!(*beamspotSelect_)(*beamspot)) return;
776  }
777  // cout<<" apply selection steps"<<endl;
778  unsigned int passed = 0;
779  unsigned int nJetSteps = -1;
780  unsigned int nPFJetSteps = -1;
781  unsigned int nCaloJetSteps = -1;
782  for (std::vector<std::string>::const_iterator selIt = selectionOrder_.begin();
783  selIt != selectionOrder_.end(); ++selIt) {
784  std::string key = selectionStep(*selIt), type = objectType(*selIt);
785  if (selection_.find(key) != selection_.end()) {
786  if (type == "empty") {
787  selection_[key].second->fill(event, setup);
788  }
789  if (type == "muons" && MuonStep != 0) {
790  if (MuonStep->select(event)) {
791  ++passed;
792  // cout<<"selected event! "<<selection_[key].second<<endl;
793  selection_[key].second->fill(event, setup);
794  } else
795  break;
796  }
797  // cout<<" apply selection steps 2"<<endl;
798  if (type == "elecs" && ElectronStep != 0) {
799  // cout<<"In electrons ..."<<endl;
800  if (ElectronStep->select(event, "electron")) {
801  ++passed;
802  selection_[key].second->fill(event, setup);
803  } else
804  break;
805  }
806  // cout<<" apply selection steps 3"<<endl;
807  if (type == "pvs" && PvStep != 0) {
808  if (PvStep->selectVertex(event)) {
809  ++passed;
810  selection_[key].second->fill(event, setup);
811  } else
812  break;
813  }
814  // cout<<" apply selection steps 4"<<endl;
815  if (type == "jets") {
816  nJetSteps++;
817  if (JetSteps[nJetSteps] != NULL) {
818  if (JetSteps[nJetSteps]->select(event, setup)) {
819  ++passed;
820  selection_[key].second->fill(event, setup);
821  } else
822  break;
823  }
824  }
825  if (type == "jets/pf") {
826  nPFJetSteps++;
827  if (PFJetSteps[nPFJetSteps] != NULL) {
828  if (PFJetSteps[nPFJetSteps]->select(event, setup)) {
829  ++passed;
830  selection_[key].second->fill(event, setup);
831  } else
832  break;
833  }
834  }
835  if (type == "jets/calo") {
836  nCaloJetSteps++;
837  if (CaloJetSteps[nCaloJetSteps] != NULL) {
838  if (CaloJetSteps[nCaloJetSteps]->select(event, setup)) {
839  ++passed;
840  selection_[key].second->fill(event, setup);
841  } else
842  break;
843  }
844  }
845  if (type == "met" && METStep != 0) {
846  if (METStep->select(event)) {
847  ++passed;
848  selection_[key].second->fill(event, setup);
849  } else
850  break;
851  }
852  }
853  }
854 }
855 
856 // Local Variables:
857 // show-trailing-whitespace: t
858 // truncate-lines: t
859 // 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:92
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:186
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:519
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:1
double pt() const final
transverse momentum
TopSingleLeptonDQM(const edm::ParameterSet &cfg)
default constructor
#define NULL
Definition: scimark2.h:8
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
std::unique_ptr< StringCutObjectSelector< reco::PFJet > > jetSelection_
Helper class for the calculation of a top and a W boson mass estime.
std::string jetSelect_
extra selection on jets
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
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:118
def pv(vc)
Definition: MetAnalyzer.py:6
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
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
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:43
std::vector< std::unique_ptr< SelectionStep< reco::CaloJet > > > CaloJetSteps
std::unique_ptr< StringCutObjectSelector< reco::PFCandidate > > muonIso_
extra isolation criterion on muon