CMS 3D CMS Logo

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