CMS 3D CMS Logo

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