CMS 3D CMS Logo

ZCounting.cc
Go to the documentation of this file.
11 
12 #include <TLorentzVector.h>
13 
14 #include <memory>
15 
17 
18 //
19 // -------------------------------------- Constructor --------------------------------------------
20 //
22  : triggerResultsInputTag_(iConfig.getParameter<edm::InputTag>("TriggerResults")),
23  fPVName_token(consumes<reco::VertexCollection>(
24  iConfig.getUntrackedParameter<std::string>("edmPVName", "offlinePrimaryVertices"))),
25  fMuonName_token(consumes<reco::MuonCollection>(iConfig.getUntrackedParameter<std::string>("edmName", "muons"))),
26  fStandaloneRegName_token(consumes<reco::TrackCollection>(
27  iConfig.getUntrackedParameter<std::string>("StandaloneReg", "standAloneMuons"))),
28  fStandaloneUpdName_token(consumes<reco::TrackCollection>(
29  iConfig.getUntrackedParameter<std::string>("StandaloneUpd", "standAloneMuons:UpdatedAtVtx"))),
30  fTrackName_token(
31  consumes<reco::TrackCollection>(iConfig.getUntrackedParameter<std::string>("edmTrackName", "generalTracks"))),
32 
33  PtCutL1_(iConfig.getUntrackedParameter<double>("PtCutL1")),
34  PtCutL2_(iConfig.getUntrackedParameter<double>("PtCutL2")),
35  EtaCutL1_(iConfig.getUntrackedParameter<double>("EtaCutL1")),
36  EtaCutL2_(iConfig.getUntrackedParameter<double>("EtaCutL2")),
37 
38  MassBin_(iConfig.getUntrackedParameter<int>("MassBin")),
39  MassMin_(iConfig.getUntrackedParameter<double>("MassMin")),
40  MassMax_(iConfig.getUntrackedParameter<double>("MassMax")),
41 
42  LumiBin_(iConfig.getUntrackedParameter<int>("LumiBin")),
43  LumiMin_(iConfig.getUntrackedParameter<double>("LumiMin")),
44  LumiMax_(iConfig.getUntrackedParameter<double>("LumiMax")),
45 
46  PVBin_(iConfig.getUntrackedParameter<int>("PVBin")),
47  PVMin_(iConfig.getUntrackedParameter<double>("PVMin")),
48  PVMax_(iConfig.getUntrackedParameter<double>("PVMax")),
49 
50  VtxNTracksFitCut_(iConfig.getUntrackedParameter<double>("VtxNTracksFitMin")),
51  VtxNdofCut_(iConfig.getUntrackedParameter<double>("VtxNdofMin")),
52  VtxAbsZCut_(iConfig.getUntrackedParameter<double>("VtxAbsZMax")),
53  VtxRhoCut_(iConfig.getUntrackedParameter<double>("VtxRhoMax")),
54 
55  IDTypestr_(iConfig.getUntrackedParameter<std::string>("IDType")),
56  IsoTypestr_(iConfig.getUntrackedParameter<std::string>("IsoType")),
57  IsoCut_(iConfig.getUntrackedParameter<double>("IsoCut")) {
58  edm::LogInfo("ZCounting") << "Constructor ZCounting::ZCounting " << std::endl;
59 
60  // Trigger settings
61  triggers = new TriggerTools();
62  triggers->setTriggerResultsToken(consumes<edm::TriggerResults>(triggerResultsInputTag_));
63  triggers->setTriggerEventToken(consumes<trigger::TriggerEvent>(iConfig.getParameter<edm::InputTag>("TriggerEvent")));
65 
66  edm::LogVerbatim("ZCounting") << "ZCounting::ZCounting set trigger names";
67  const std::vector<std::string> patterns_ = iConfig.getParameter<std::vector<std::string>>("MuonTriggerNames");
68  for (const std::string& pattern_ : patterns_) {
69  triggers->addTriggerRecord(pattern_);
70  }
71 
72  if (IDTypestr_ == "Loose")
73  IDType_ = LooseID;
74  else if (IDTypestr_ == "Medium")
75  IDType_ = MediumID;
76  else if (IDTypestr_ == "Tight")
77  IDType_ = TightID;
78  else if (IDTypestr_ == "CustomTight")
80  else
81  IDType_ = NoneID;
82 
83  if (IsoTypestr_ == "Tracker-based")
85  else if (IsoTypestr_ == "PF-based")
86  IsoType_ = PFIso;
87  else
88  IsoType_ = NoneIso;
89 }
90 
91 //
92 // -------------------------------------- Destructor --------------------------------------------
93 //
94 ZCounting::~ZCounting() { edm::LogInfo("ZCounting") << "Destructor ZCounting::~ZCounting " << std::endl; }
95 
96 //
97 // -------------------------------------- beginRun --------------------------------------------
98 //
99 void ZCounting::dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
100  edm::LogInfo("ZCounting") << "ZCounting::beginRun" << std::endl;
101 
102  // initialize triggers
103 
104  edm::LogVerbatim("ZCounting") << "ZCounting::dqmBeginRun now at " << iRun.id();
105  bool hltChanged_ = true;
106  if (hltConfigProvider_.init(iRun, iSetup, triggerResultsInputTag_.process(), hltChanged_)) {
107  edm::LogVerbatim("ZCounting") << "ZCounting::dqmBeginRun [TriggerObjMatchValueMapsProducer::beginRun] "
108  "HLTConfigProvider initialized [processName() = \""
109  << hltConfigProvider_.processName() << "\", tableName() = \""
110  << hltConfigProvider_.tableName() << "\", size() = " << hltConfigProvider_.size()
111  << "]";
112  } else {
113  edm::LogError("ZCounting") << "ZCounting::dqmBeginRun Initialization of HLTConfigProvider failed for Run="
114  << iRun.id() << " (process=\"" << triggerResultsInputTag_.process()
115  << "\") -> plugin will not produce outputs for this Run";
116  return;
117  }
118 
120 }
121 
122 //
123 // -------------------------------------- bookHistos --------------------------------------------
124 //
126  edm::LogInfo("ZCounting") << "ZCounting::bookHistograms" << std::endl;
127  ibooker_.cd();
128  ibooker_.setCurrentFolder("ZCounting/Histograms");
129 
130  // Muon histograms
131  h_mass_2HLT_BB = ibooker_.book2D("h_mass_2HLT_BB",
132  "Both muon pass HLT in barrel-barrel",
133  LumiBin_,
134  LumiMin_,
135  LumiMax_,
136  MassBin_,
137  MassMin_,
138  MassMax_);
139  h_mass_2HLT_BE = ibooker_.book2D("h_mass_2HLT_BE",
140  "Both muon pass HLT passing in barrel-endcap",
141  LumiBin_,
142  LumiMin_,
143  LumiMax_,
144  MassBin_,
145  MassMin_,
146  MassMax_);
147  h_mass_2HLT_EE = ibooker_.book2D("h_mass_2HLT_EE",
148  "Both muon pass HLT passing in endcap-endcap",
149  LumiBin_,
150  LumiMin_,
151  LumiMax_,
152  MassBin_,
153  MassMin_,
154  MassMax_);
155  h_mass_1HLT_BB = ibooker_.book2D("h_mass_1HLT_BB",
156  "One muon pass HLT in barrel-barrel",
157  LumiBin_,
158  LumiMin_,
159  LumiMax_,
160  MassBin_,
161  MassMin_,
162  MassMax_);
163  h_mass_1HLT_BE = ibooker_.book2D("h_mass_1HLT_BE",
164  "One muon pass HLT passing in barrel-endcap",
165  LumiBin_,
166  LumiMin_,
167  LumiMax_,
168  MassBin_,
169  MassMin_,
170  MassMax_);
171  h_mass_1HLT_EE = ibooker_.book2D("h_mass_1HLT_EE",
172  "One muon pass HLT passing in endcap-endcap",
173  LumiBin_,
174  LumiMin_,
175  LumiMax_,
176  MassBin_,
177  MassMin_,
178  MassMax_);
179 
180  h_mass_ID_fail_BB = ibooker_.book2D(
181  "h_mass_ID_fail_BB", "Muon ID failing barrel-barrel", LumiBin_, LumiMin_, LumiMax_, MassBin_, MassMin_, MassMax_);
182  h_mass_ID_fail_BE = ibooker_.book2D(
183  "h_mass_ID_fail_BE", "Muon ID failing barrel-endcap", LumiBin_, LumiMin_, LumiMax_, MassBin_, MassMin_, MassMax_);
184 
185  h_mass_ID_fail_EE = ibooker_.book2D(
186  "h_mass_ID_fail_EE", "Muon ID failing endcap-endcap", LumiBin_, LumiMin_, LumiMax_, MassBin_, MassMin_, MassMax_);
187 
188  h_mass_Glo_pass_BB = ibooker_.book2D("h_mass_Glo_pass_BB",
189  "Muon Glo passing barrel-barrel",
190  LumiBin_,
191  LumiMin_,
192  LumiMax_,
193  MassBin_,
194  MassMin_,
195  MassMax_);
196  h_mass_Glo_pass_BE = ibooker_.book2D("h_mass_Glo_pass_BE",
197  "Muon Glo passing barrel-endcap",
198  LumiBin_,
199  LumiMin_,
200  LumiMax_,
201  MassBin_,
202  MassMin_,
203  MassMax_);
204 
205  h_mass_Glo_pass_EE = ibooker_.book2D("h_mass_Glo_pass_EE",
206  "Muon Glo passing endcap-endcap",
207  LumiBin_,
208  LumiMin_,
209  LumiMax_,
210  MassBin_,
211  MassMin_,
212  MassMax_);
213 
214  h_mass_Glo_fail_BB = ibooker_.book2D("h_mass_Glo_fail_BB",
215  "Muon Glo failing barrel-barrel",
216  LumiBin_,
217  LumiMin_,
218  LumiMax_,
219  MassBin_,
220  MassMin_,
221  MassMax_);
222  h_mass_Glo_fail_BE = ibooker_.book2D("h_mass_Glo_fail_BE",
223  "Muon Glo failing barrel-endcap",
224  LumiBin_,
225  LumiMin_,
226  LumiMax_,
227  MassBin_,
228  MassMin_,
229  MassMax_);
230 
231  h_mass_Glo_fail_EE = ibooker_.book2D("h_mass_Glo_fail_EE",
232  "Muon Glo failing endcap-endcap",
233  LumiBin_,
234  LumiMin_,
235  LumiMax_,
236  MassBin_,
237  MassMin_,
238  MassMax_);
239 
240  h_mass_Sta_pass_BB = ibooker_.book2D("h_mass_Sta_pass_BB",
241  "Muon Sta passing barrel-barrel",
242  LumiBin_,
243  LumiMin_,
244  LumiMax_,
245  MassBin_,
246  MassMin_,
247  MassMax_);
248  h_mass_Sta_pass_BE = ibooker_.book2D("h_mass_Sta_pass_BE",
249  "Muon Sta passing barrel-endcap",
250  LumiBin_,
251  LumiMin_,
252  LumiMax_,
253  MassBin_,
254  MassMin_,
255  MassMax_);
256 
257  h_mass_Sta_pass_EE = ibooker_.book2D("h_mass_Sta_pass_EE",
258  "Muon Sta passing endcap-endcap",
259  LumiBin_,
260  LumiMin_,
261  LumiMax_,
262  MassBin_,
263  MassMin_,
264  MassMax_);
265 
266  h_mass_Sta_fail_BB = ibooker_.book2D("h_mass_Sta_fail_BB",
267  "Muon Sta failing barrel-barrel",
268  LumiBin_,
269  LumiMin_,
270  LumiMax_,
271  MassBin_,
272  MassMin_,
273  MassMax_);
274  h_mass_Sta_fail_BE = ibooker_.book2D("h_mass_Sta_fail_BE",
275  "Muon Sta failing barrel-endcap",
276  LumiBin_,
277  LumiMin_,
278  LumiMax_,
279  MassBin_,
280  MassMin_,
281  MassMax_);
282 
283  h_mass_Sta_fail_EE = ibooker_.book2D("h_mass_Sta_fail_EE",
284  "Muon Sta failing endcap-endcap",
285  LumiBin_,
286  LumiMin_,
287  LumiMax_,
288  MassBin_,
289  MassMin_,
290  MassMax_);
291 
292  h_npv = ibooker_.book2D(
293  "h_npv", "Events with valid primary vertex", LumiBin_, LumiMin_, LumiMax_, PVBin_, PVMin_, PVMax_);
294 
295  // Axis titles
296  h_mass_2HLT_BB->setAxisTitle("luminosity section", 1);
297  h_mass_2HLT_BE->setAxisTitle("luminosity section", 1);
298  h_mass_2HLT_EE->setAxisTitle("luminosity section", 1);
299  h_mass_1HLT_BB->setAxisTitle("luminosity section", 1);
300  h_mass_1HLT_BE->setAxisTitle("luminosity section", 1);
301  h_mass_1HLT_EE->setAxisTitle("luminosity section", 1);
302  h_mass_ID_fail_BB->setAxisTitle("luminosity section", 1);
303  h_mass_ID_fail_BE->setAxisTitle("luminosity section", 1);
304  h_mass_ID_fail_EE->setAxisTitle("luminosity section", 1);
305  h_mass_Glo_pass_BB->setAxisTitle("luminosity section", 1);
306  h_mass_Glo_pass_BE->setAxisTitle("luminosity section", 1);
307  h_mass_Glo_pass_EE->setAxisTitle("luminosity section", 1);
308  h_mass_Glo_fail_BB->setAxisTitle("luminosity section", 1);
309  h_mass_Glo_fail_BE->setAxisTitle("luminosity section", 1);
310  h_mass_Glo_fail_EE->setAxisTitle("luminosity section", 1);
311  h_mass_Sta_pass_BB->setAxisTitle("luminosity section", 1);
312  h_mass_Sta_pass_BE->setAxisTitle("luminosity section", 1);
313  h_mass_Sta_pass_EE->setAxisTitle("luminosity section", 1);
314  h_mass_Sta_fail_BB->setAxisTitle("luminosity section", 1);
315  h_mass_Sta_fail_BE->setAxisTitle("luminosity section", 1);
316  h_mass_Sta_fail_EE->setAxisTitle("luminosity section", 1);
317  h_mass_2HLT_BB->setAxisTitle("tag and probe mass", 2);
318  h_mass_2HLT_BE->setAxisTitle("tag and probe mass", 2);
319  h_mass_2HLT_EE->setAxisTitle("tag and probe mass", 2);
320  h_mass_1HLT_BB->setAxisTitle("tag and probe mass", 2);
321  h_mass_1HLT_BE->setAxisTitle("tag and probe mass", 2);
322  h_mass_1HLT_EE->setAxisTitle("tag and probe mass", 2);
323  h_mass_ID_fail_BB->setAxisTitle("tag and probe mass", 2);
324  h_mass_ID_fail_BE->setAxisTitle("tag and probe mass", 2);
325  h_mass_ID_fail_EE->setAxisTitle("tag and probe mass", 2);
326  h_mass_Glo_pass_BB->setAxisTitle("tag and probe mass", 2);
327  h_mass_Glo_pass_BE->setAxisTitle("tag and probe mass", 2);
328  h_mass_Glo_pass_EE->setAxisTitle("tag and probe mass", 2);
329  h_mass_Glo_fail_BB->setAxisTitle("tag and probe mass", 2);
330  h_mass_Glo_fail_BE->setAxisTitle("tag and probe mass", 2);
331  h_mass_Glo_fail_EE->setAxisTitle("tag and probe mass", 2);
332  h_mass_Sta_pass_BB->setAxisTitle("tag and probe mass", 2);
333  h_mass_Sta_pass_BE->setAxisTitle("tag and probe mass", 2);
334  h_mass_Sta_pass_EE->setAxisTitle("tag and probe mass", 2);
335  h_mass_Sta_fail_BB->setAxisTitle("tag and probe mass", 2);
336  h_mass_Sta_fail_BE->setAxisTitle("tag and probe mass", 2);
337  h_mass_Sta_fail_EE->setAxisTitle("tag and probe mass", 2);
338  h_npv->setAxisTitle("luminosity section", 1);
339  h_npv->setAxisTitle("number of primary vertices", 2);
340 }
341 
342 //
343 // -------------------------------------- Analyze --------------------------------------------
344 //
345 //--------------------------------------------------------------------------------------------------
346 void ZCounting::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { // Fill event tree on the fly
347  edm::LogInfo("ZCounting") << "ZCounting::analyze" << std::endl;
348 
349  //-------------------------------
350  //--- Vertex
351  //-------------------------------
353  iEvent.getByToken(fPVName_token, hVertexProduct);
354  if (!hVertexProduct.isValid()) {
355  edm::LogWarning("ZCounting") << "ZCounting::analyze - no valid primary vertex product found" << std::endl;
356  return;
357  }
358 
359  const reco::Vertex* pv = nullptr;
360  int nvtx = 0;
361 
362  for (auto const& itVtx : *hVertexProduct) {
363  if (itVtx.isFake())
364  continue;
365  if (itVtx.tracksSize() < VtxNTracksFitCut_)
366  continue;
367  if (itVtx.ndof() < VtxNdofCut_)
368  continue;
369  if (fabs(itVtx.z()) > VtxAbsZCut_)
370  continue;
371  if (itVtx.position().Rho() > VtxRhoCut_)
372  continue;
373 
374  if (nvtx == 0) {
375  pv = &itVtx;
376  }
377  nvtx++;
378  }
379 
380  h_npv->Fill(iEvent.luminosityBlock(), nvtx);
381 
382  //-------------------------------
383  //--- Trigger
384  //-------------------------------
386 
387  // Trigger requirement
388  if (!triggers->pass())
389  return;
390 
391  //-------------------------------
392  //--- Muon and Track collections
393  //-------------------------------
395  iEvent.getByToken(fMuonName_token, hMuonProduct);
396  if (!hMuonProduct.isValid()) {
397  edm::LogWarning("ZCounting") << "ZCounting::analyze - no valid hMuonProduct found" << std::endl;
398  return;
399  }
400 
402  iEvent.getByToken(fTrackName_token, hTrackProduct);
403  if (!hTrackProduct.isValid()) {
404  edm::LogWarning("ZCounting") << "ZCounting::analyze - no valid hTrackProduct found" << std::endl;
405  return;
406  }
407 
408  //-------------------------------
409  //--- Merged standalone muon collections
410  //--- The muon collection contains duplicates (from standAloneMuons and standAloneMuons:UpdatedAtVtx collections) and missing standAloneMuons
411  //--- We need to produce a merged standalone muon collection to reproduce the decision in the global muon producer
412  //-------------------------------
413  edm::Handle<reco::TrackCollection> tracksStandAlone;
414  iEvent.getByToken(fStandaloneRegName_token, tracksStandAlone);
415  if (!tracksStandAlone.isValid()) {
416  edm::LogWarning("ZCounting") << "ZCounting::analyze - no valid tracksStandAlone found" << std::endl;
417  return;
418  }
419 
420  edm::Handle<reco::TrackCollection> tracksStandAloneUpdatedAtVtx;
421  iEvent.getByToken(fStandaloneUpdName_token, tracksStandAloneUpdatedAtVtx);
422  if (!tracksStandAloneUpdatedAtVtx.isValid()) {
423  edm::LogWarning("ZCounting") << "ZCounting::analyze - no valid tracksStandAloneUpdatedAtVtx found" << std::endl;
424  return;
425  }
426 
427  std::vector<const reco::Track*> hStandaloneProduct;
428  std::vector<bool> passGlobalMuonMap;
429 
430  for (auto const& standAlone : *tracksStandAlone) {
431  auto const extraIdx = standAlone.extra().key();
432 
433  const reco::Track* track = &standAlone;
434 
435  // replicate logic in GlobalMuonProducer, take the updatedAtVtx track if it exists and has
436  // the same eta sign as the original, otherwise take the original
437  for (auto const& standAloneUpdatedAtVtx : *tracksStandAloneUpdatedAtVtx) {
438  if (standAloneUpdatedAtVtx.extra().key() == extraIdx) {
439  const bool etaFlip1 = (standAloneUpdatedAtVtx.eta() * standAlone.eta()) >= 0;
440  if (etaFlip1) {
441  track = &standAloneUpdatedAtVtx;
442  }
443  break;
444  }
445  }
446 
447  // kinematic cuts
448  if (track->pt() < MIN_PT_STA)
449  continue;
450  if (fabs(track->eta()) > MAX_ETA_STA)
451  continue;
452  // require minimum number of valid hits (mainly to reduce background)
453  if (track->numberOfValidHits() < N_STA_HITS)
454  continue;
455 
456  // look for corresponding muon object to check if the standalone muon is global
457  bool isGlobalMuon = false;
458  for (auto const& itMu2 : *hMuonProduct) {
459  if (itMu2.standAloneMuon().isNull())
460  continue;
461 
462  auto const& muonStandAlone = *itMu2.standAloneMuon();
463 
464  if (track->extra().key() == muonStandAlone.extra().key()) {
465  // we found a corresponding muon object
466  if (muonStandAlone.pt() == track->pt() && muonStandAlone.eta() == track->eta() &&
467  muonStandAlone.phi() == track->phi()) {
468  // the corresponding muon object uses the same standalone muon track
469  // check if is a global muon
470  isGlobalMuon = passGlobalMuon(itMu2);
471  }
472  break;
473  }
474  }
475 
476  passGlobalMuonMap.push_back(isGlobalMuon);
477  hStandaloneProduct.push_back(track);
478  }
479 
480  TLorentzVector vTag(0., 0., 0., 0.);
481  TLorentzVector vProbe(0., 0., 0., 0.);
482  TLorentzVector vTrack(0., 0., 0., 0.);
483 
484  // Tag loop
485  for (auto const& itMu1 : *hMuonProduct) {
486  const float pt1 = itMu1.muonBestTrack()->pt();
487  const float eta1 = itMu1.muonBestTrack()->eta();
488  const float phi1 = itMu1.muonBestTrack()->phi();
489  const float q1 = itMu1.muonBestTrack()->charge();
490 
491  // Tag selection: kinematic cuts, lepton selection and trigger matching
492  if (pt1 < PtCutL1_)
493  continue;
494  if (fabs(eta1) > EtaCutL1_)
495  continue;
496  if (!(passGlobalMuon(itMu1) && passMuonID(itMu1, pv) && passMuonIso(itMu1)))
497  continue;
498  if (!triggers->passObj(eta1, phi1))
499  continue;
500 
501  vTag.SetPtEtaPhiM(pt1, eta1, phi1, MUON_MASS);
502 
503  bool isTagCentral = false;
504  if (fabs(eta1) < MUON_BOUND)
505  isTagCentral = true;
506 
507  // Probe loop over muons
508  for (auto const& itMu2 : *hMuonProduct) {
509  if (&itMu2 == &itMu1)
510  continue;
511 
512  const float pt2 = itMu2.muonBestTrack()->pt();
513  const float eta2 = itMu2.muonBestTrack()->eta();
514  const float phi2 = itMu2.muonBestTrack()->phi();
515  const float q2 = itMu2.muonBestTrack()->charge();
516 
517  // Probe selection: kinematic cuts and opposite charge requirement
518  if (pt2 < PtCutL2_)
519  continue;
520  if (fabs(eta2) > EtaCutL2_)
521  continue;
522  if (q1 == q2)
523  continue;
524 
525  vProbe.SetPtEtaPhiM(pt2, eta2, phi2, MUON_MASS);
526 
527  // Mass window
528  TLorentzVector vDilep = vTag + vProbe;
529  float dilepMass = vDilep.M();
530  if ((dilepMass < MassMin_) || (dilepMass > MassMax_))
531  continue;
532 
533  bool isProbeCentral = fabs(eta2) < MUON_BOUND;
534 
535  // Determine event category for efficiency calculation
536  if (passGlobalMuon(itMu2) && passMuonID(itMu2, pv) && passMuonIso(itMu2)) {
537  if (triggers->passObj(eta2, phi2)) {
538  // category 2HLT: both muons passing trigger requirements
539  if (&itMu1 > &itMu2)
540  continue; // make sure we don't double count MuMu2HLT category
541 
542  if (isTagCentral && isProbeCentral) {
543  h_mass_2HLT_BB->Fill(iEvent.luminosityBlock(), dilepMass);
544  } else if (!isTagCentral && !isProbeCentral) {
545  h_mass_2HLT_EE->Fill(iEvent.luminosityBlock(), dilepMass);
546  } else {
547  h_mass_2HLT_BE->Fill(iEvent.luminosityBlock(), dilepMass);
548  }
549  } else {
550  // category 1HLT: only one muon passes trigger
551  if (isTagCentral && isProbeCentral) {
552  h_mass_1HLT_BB->Fill(iEvent.luminosityBlock(), dilepMass);
553  } else if (!isTagCentral && !isProbeCentral) {
554  h_mass_1HLT_EE->Fill(iEvent.luminosityBlock(), dilepMass);
555  } else {
556  h_mass_1HLT_BE->Fill(iEvent.luminosityBlock(), dilepMass);
557  }
558  }
559  } else if (passGlobalMuon(itMu2)) {
560  // category Glo: probe is a Global muon but failing selection
561  if (isTagCentral && isProbeCentral) {
562  h_mass_ID_fail_BB->Fill(iEvent.luminosityBlock(), dilepMass);
563  } else if (!isTagCentral && !isProbeCentral) {
564  h_mass_ID_fail_EE->Fill(iEvent.luminosityBlock(), dilepMass);
565  } else {
566  h_mass_ID_fail_BE->Fill(iEvent.luminosityBlock(), dilepMass);
567  }
568  }
569  } // End of probe loop over muons
570 
571  // Probe loop over standalone muons, for global muon efficiency calculation
572  for (std::vector<reco::Track>::size_type idx = 0; idx < hStandaloneProduct.size(); idx++) {
573  const reco::Track* itSta = hStandaloneProduct[idx];
574 
575  // standalone muon kinematics
576  const float pt2 = itSta->pt();
577  const float eta2 = itSta->eta();
578  const float phi2 = itSta->phi();
579 
580  // kinematic cuts
581  if (pt2 < PtCutL2_)
582  continue;
583  if (fabs(eta2) > EtaCutL2_)
584  continue;
585 
586  vProbe.SetPtEtaPhiM(pt2, eta2, phi2, MUON_MASS);
587 
588  // Mass window
589  TLorentzVector vDilep = vTag + vProbe;
590  float dilepMass = vDilep.M();
591  if ((dilepMass < MassMin_) || (dilepMass > MassMax_))
592  continue;
593 
594  const bool isProbeCentral = fabs(eta2) < MUON_BOUND;
595 
596  if (passGlobalMuonMap[idx]) {
597  if (isTagCentral && isProbeCentral) {
598  h_mass_Glo_pass_BB->Fill(iEvent.luminosityBlock(), dilepMass);
599  } else if (!isTagCentral && !isProbeCentral) {
600  h_mass_Glo_pass_EE->Fill(iEvent.luminosityBlock(), dilepMass);
601  } else {
602  h_mass_Glo_pass_BE->Fill(iEvent.luminosityBlock(), dilepMass);
603  }
604  } else {
605  if (isTagCentral && isProbeCentral) {
606  h_mass_Glo_fail_BB->Fill(iEvent.luminosityBlock(), dilepMass);
607  } else if (!isTagCentral && !isProbeCentral) {
608  h_mass_Glo_fail_EE->Fill(iEvent.luminosityBlock(), dilepMass);
609  } else {
610  h_mass_Glo_fail_BE->Fill(iEvent.luminosityBlock(), dilepMass);
611  }
612  }
613  }
614 
615  // Probe loop over tracks, only for standalone efficiency calculation
616  for (auto const& itTrk : *hTrackProduct) {
617  const float pt2 = itTrk.pt();
618  const float eta2 = itTrk.eta();
619  const float phi2 = itTrk.phi();
620  const float q2 = itTrk.charge();
621 
622  // Probe selection: kinematic cuts and opposite charge requirement
623  if (pt2 < PtCutL2_)
624  continue;
625  if (fabs(eta2) > EtaCutL2_)
626  continue;
627  if (q1 == q2)
628  continue;
629  if (!passTrack(itTrk))
630  continue;
631 
632  vTrack.SetPtEtaPhiM(pt2, eta2, phi2, MUON_MASS);
633 
634  TLorentzVector vDilep = vTag + vTrack;
635  float dilepMass = vDilep.M();
636  if ((dilepMass < MassMin_) || (dilepMass > MassMax_))
637  continue;
638 
639  // check if track is matched to standalone muon
640  bool isStandalone = false;
641  for (const reco::Track* itSta : hStandaloneProduct) {
642  if (reco::deltaR2(itSta->eta(), itSta->phi(), eta2, phi2) < DRMAX_IO) {
643  isStandalone = true;
644  break;
645  }
646  }
647 
648  const bool isTrackCentral = fabs(eta2) < MUON_BOUND;
649 
650  if (isStandalone) {
651  if (isTagCentral && isTrackCentral) {
652  h_mass_Sta_pass_BB->Fill(iEvent.luminosityBlock(), dilepMass);
653  } else if (!isTagCentral && !isTrackCentral) {
654  h_mass_Sta_pass_EE->Fill(iEvent.luminosityBlock(), dilepMass);
655  } else {
656  h_mass_Sta_pass_BE->Fill(iEvent.luminosityBlock(), dilepMass);
657  }
658  } else {
659  if (isTagCentral && isTrackCentral) {
660  h_mass_Sta_fail_BB->Fill(iEvent.luminosityBlock(), dilepMass);
661  } else if (!isTagCentral && !isTrackCentral) {
662  h_mass_Sta_fail_EE->Fill(iEvent.luminosityBlock(), dilepMass);
663  } else {
664  h_mass_Sta_fail_BE->Fill(iEvent.luminosityBlock(), dilepMass);
665  }
666  }
667  } //End of probe loop over tracks
668  } //End of tag loop
669 }
670 
671 //
672 // -------------------------------------- functions --------------------------------------------
673 //
674 
675 //--------------------------------------------------------------------------------------------------
676 // Definition of the CustomTightID function
678  // tight POG cut based ID w/o impact parameter cuts
679  return muon.isGlobalMuon() && muon.isPFMuon() && muon.globalTrack()->normalizedChi2() < 10. &&
680  muon.globalTrack()->hitPattern().numberOfValidMuonHits() > 0 && muon.numberOfMatchedStations() > 1 &&
681  muon.innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5 &&
682  muon.innerTrack()->hitPattern().numberOfValidPixelHits() > 0;
683 }
684 
685 //--------------------------------------------------------------------------------------------------
687  // Muon ID selection, using internal function "DataFormats/MuonReco/src/MuonSelectors.cc
688  switch (IDType_) {
689  case LooseID:
690  return muon::isLooseMuon(muon);
691  case MediumID:
692  return muon::isMediumMuon(muon);
693  case CustomTightID:
694  return isCustomTightMuon(muon);
695  case TightID:
696  return vtx != nullptr && muon::isTightMuon(muon, *vtx);
697  case NoneID:
698  return true;
699  }
700  return false;
701 }
702 
703 //--------------------------------------------------------------------------------------------------
705  // Global muon selection:
706  // - standard global muon criterium,
707  // - requirements on inner and outer track pT>15 and |eta|
708  // - requirements on deltaR(inner track, outer track)
709 
710  return muon.isGlobalMuon() && muon.outerTrack()->numberOfValidHits() >= N_STA_HITS &&
711  muon.innerTrack()->pt() > MIN_PT_TRK && std::abs(muon.innerTrack()->eta()) < MAX_ETA_TRK &&
712  muon.outerTrack()->pt() > MIN_PT_STA && std::abs(muon.outerTrack()->eta()) < MAX_ETA_STA &&
714  muon.outerTrack()->eta(), muon.outerTrack()->phi(), muon.innerTrack()->eta(), muon.innerTrack()->phi()) <
715  DRMAX_IO;
716 }
717 
718 //--------------------------------------------------------------------------------------------------
720  return track.hitPattern().trackerLayersWithMeasurement() >= 6 && track.hitPattern().numberOfValidPixelHits() >= 1 &&
721  track.originalAlgo() != 13 // reject muon seeded tracks - InOut
722  && track.originalAlgo() != 14; // reject muon seeded tracks - OutIn
723 }
724 
725 //--------------------------------------------------------------------------------------------------
727  //Muon isolation selection, up-to-date with MUO POG recommendation
728  switch (IsoType_) {
729  case TrackerIso:
730  return muon.isolationR03().sumPt < IsoCut_;
731  case PFIso:
732  return muon.pfIsolationR04().sumChargedHadronPt +
733  std::max(0.,
734  muon.pfIsolationR04().sumNeutralHadronEt + muon.pfIsolationR04().sumPhotonEt -
735  0.5 * muon.pfIsolationR04().sumPUPt) <
736  IsoCut_;
737  case NoneIso:
738  return true;
739  }
740 
741  return false;
742 }
743 
MonitorElement * h_mass_Sta_pass_EE
Definition: ZCounting.h:135
ZCounting(const edm::ParameterSet &ps)
Definition: ZCounting.cc:21
Log< level::Info, true > LogVerbatim
const double MassMax_
Definition: ZCounting.h:69
MonitorElement * h_mass_Sta_pass_BE
Definition: ZCounting.h:134
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void setDRMAX(const double _drMax)
Definition: TriggerTools.h:28
MonitorElement * h_mass_Sta_fail_BE
Definition: ZCounting.h:137
bool passMuonIso(const reco::Muon &muon)
Definition: ZCounting.cc:726
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
const double VtxNTracksFitCut_
Definition: ZCounting.h:79
void initHLTObjects(const HLTConfigProvider &hltConfigProvider_)
Definition: TriggerTools.cc:35
const edm::InputTag triggerResultsInputTag_
Definition: ZCounting.h:47
bool passTrack(const reco::Track &track)
Definition: ZCounting.cc:719
MonitorElement * h_mass_1HLT_BE
Definition: ZCounting.h:119
const double DRMAX_HLT
Definition: ZCounting.h:97
TriggerTools * triggers
Definition: ZCounting.h:94
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const double VtxAbsZCut_
Definition: ZCounting.h:81
const int PVBin_
Definition: ZCounting.h:75
const std::string IDTypestr_
Definition: ZCounting.h:84
const double EtaCutL2_
Definition: ZCounting.h:65
MonitorElement * h_mass_Glo_pass_BB
Definition: ZCounting.h:126
MuonIsoTypes IsoType_
Definition: ZCounting.h:90
void setTriggerEventToken(edm::EDGetTokenT< trigger::TriggerEvent > token)
Definition: TriggerTools.h:27
MonitorElement * h_mass_2HLT_BE
Definition: ZCounting.h:115
const double EtaCutL1_
Definition: ZCounting.h:64
Log< level::Error, false > LogError
edm::EDGetTokenT< reco::TrackCollection > fStandaloneUpdName_token
Definition: ZCounting.h:56
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
uint16_t size_type
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
MonitorElement * h_mass_Glo_fail_BE
Definition: ZCounting.h:130
bool isLooseMuon(const reco::Muon &)
HLTConfigProvider hltConfigProvider_
Definition: ZCounting.h:93
edm::EDGetTokenT< reco::TrackCollection > fTrackName_token
Definition: ZCounting.h:59
void Fill(long long x)
const double MIN_PT_STA
Definition: ZCounting.h:102
bool isCustomTightMuon(const reco::Muon &muon)
Definition: ZCounting.cc:677
bool passMuonID(const reco::Muon &muon, const reco::Vertex *vtx)
Definition: ZCounting.cc:686
const double MUON_MASS
Definition: ZCounting.h:107
double pt() const
track transverse momentum
Definition: TrackBase.h:637
edm::EDGetTokenT< reco::MuonCollection > fMuonName_token
Definition: ZCounting.h:51
const double MassMin_
Definition: ZCounting.h:68
const double VtxNdofCut_
Definition: ZCounting.h:80
int iEvent
Definition: GenABIO.cc:224
const double LumiMax_
Definition: ZCounting.h:73
MonitorElement * h_mass_Sta_fail_BB
Definition: ZCounting.h:136
MonitorElement * h_mass_Sta_pass_BB
Definition: ZCounting.h:133
const double MAX_ETA_TRK
Definition: ZCounting.h:101
const double IsoCut_
Definition: ZCounting.h:86
unsigned int size() const
number of trigger paths in trigger table
edm::EDGetTokenT< reco::VertexCollection > fPVName_token
Definition: ZCounting.h:48
const double MAX_ETA_STA
Definition: ZCounting.h:103
MonitorElement * h_mass_ID_fail_BE
Definition: ZCounting.h:123
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void setTriggerResultsToken(edm::EDGetTokenT< edm::TriggerResults > token)
Definition: TriggerTools.h:26
MonitorElement * h_mass_ID_fail_EE
Definition: ZCounting.h:124
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool pass() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: ZCounting.cc:125
const std::string IsoTypestr_
Definition: ZCounting.h:85
MuonIDTypes IDType_
Definition: ZCounting.h:89
bool passObj(const double eta, const double phi) const
MonitorElement * h_npv
Definition: ZCounting.h:111
const int LumiBin_
Definition: ZCounting.h:71
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override
Definition: ZCounting.cc:346
MonitorElement * h_mass_2HLT_EE
Definition: ZCounting.h:116
const double MUON_BOUND
Definition: ZCounting.h:108
RunID const & id() const
Definition: RunBase.h:39
MonitorElement * h_mass_2HLT_BB
Definition: ZCounting.h:114
const double PVMin_
Definition: ZCounting.h:76
Log< level::Info, false > LogInfo
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
MonitorElement * h_mass_ID_fail_BB
Definition: ZCounting.h:122
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void addTriggerRecord(const std::string &name)
Definition: TriggerTools.h:30
const double PVMax_
Definition: ZCounting.h:77
const std::string & processName() const
process name
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
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
MonitorElement * h_mass_Sta_fail_EE
Definition: ZCounting.h:138
bool passGlobalMuon(const reco::Muon &muon)
Definition: ZCounting.cc:704
~ZCounting() override
Definition: ZCounting.cc:94
MonitorElement * h_mass_Glo_fail_BB
Definition: ZCounting.h:129
MonitorElement * h_mass_Glo_pass_BE
Definition: ZCounting.h:127
const double LumiMin_
Definition: ZCounting.h:72
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
const std::string & tableName() const
HLT ConfDB table name.
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
Definition: ZCounting.cc:99
HLT enums.
void readEvent(const edm::Event &iEvent)
Definition: TriggerTools.cc:90
const double PtCutL1_
Definition: ZCounting.h:62
const double MIN_PT_TRK
Definition: ZCounting.h:100
MonitorElement * h_mass_1HLT_EE
Definition: ZCounting.h:120
Log< level::Warning, false > LogWarning
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
std::string const & process() const
Definition: InputTag.h:40
const double PtCutL2_
Definition: ZCounting.h:63
Definition: Run.h:45
MonitorElement * h_mass_1HLT_BB
Definition: ZCounting.h:118
const double DRMAX_IO
Definition: ZCounting.h:98
const int N_STA_HITS
Definition: ZCounting.h:105
MonitorElement * h_mass_Glo_fail_EE
Definition: ZCounting.h:131
edm::EDGetTokenT< reco::TrackCollection > fStandaloneRegName_token
Definition: ZCounting.h:55
MonitorElement * h_mass_Glo_pass_EE
Definition: ZCounting.h:128
const double VtxRhoCut_
Definition: ZCounting.h:82
const int MassBin_
Definition: ZCounting.h:67
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)