CMS 3D CMS Logo

ZMuMuEfficiency.cc
Go to the documentation of this file.
1 /* \class ZMuMuEfficiency
2  *
3  * author: Pasquale Noli
4  * revised by Salvatore di Guida
5  * revised for CSA08 by Davide Piccolo
6  *
7  * Efficiency of reconstruction tracker and muon Chamber
8  *
9  */
10 
27 #include "TH1.h"
28 #include <vector>
29 
30 using namespace edm;
31 using namespace std;
32 using namespace reco;
33 
35 
37 public:
39 
40 private:
41  void analyze(const edm::Event &event, const edm::EventSetup &setup) override;
42  bool check_ifZmumu(const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2);
43  float getParticlePt(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2);
44  float getParticleEta(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2);
45  float getParticlePhi(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2);
46  Particle::LorentzVector getParticleP4(const int ipart,
47  const Candidate *dauGen0,
48  const Candidate *dauGen1,
49  const Candidate *dauGen2);
50  void endJob() override;
51 
66 
67  double zMassMin_, zMassMax_, ptmin_, etamax_, isomax_;
68  unsigned int nbinsPt_, nbinsEta_;
69  reco::CandidateBaseRef globalMuonCandRef_, trackMuonCandRef_, standAloneMuonCandRef_;
71 
72  //histograms for measuring tracker efficiency
73  TH1D *h_etaStandAlone_, *h_etaMuonOverlappedToStandAlone_;
74  TH1D *h_ptStandAlone_, *h_ptMuonOverlappedToStandAlone_;
75 
76  //histograms for measuring standalone efficiency
77  TH1D *h_etaTrack_, *h_etaMuonOverlappedToTrack_;
78  TH1D *h_ptTrack_, *h_ptMuonOverlappedToTrack_;
79 
80  //histograms for MC acceptance
81  TH1D *h_nZMCfound_;
82  TH1D *h_ZetaGen_, *h_ZptGen_, *h_ZmassGen_;
83  TH1D *h_muetaGen_, *h_muptGen_, *h_muIsoGen_;
84  TH1D *h_dimuonPtGen_, *h_dimuonMassGen_, *h_dimuonEtaGen_;
85  TH1D *h_ZetaGenPassed_, *h_ZptGenPassed_, *h_ZmassGenPassed_;
86  TH1D *h_muetaGenPassed_, *h_muptGenPassed_, *h_muIsoGenPassed_;
87  TH1D *h_dimuonPtGenPassed_, *h_dimuonMassGenPassed_, *h_dimuonEtaGenPassed_;
88  //histograms for invarian mass resolution
89  TH1D *h_DELTA_ZMuMuMassReco_dimuonMassGen_, *h_DELTA_ZMuStaMassReco_dimuonMassGen_,
91 
92  int numberOfEventsWithZMuMufound, numberOfEventsWithZMuStafound;
93  int numberOfMatchedZMuSta_, numberOfMatchedSelectedZMuSta_;
94  int numberOfMatchedZMuMu_, numberOfMatchedSelectedZMuMu_;
95  int numberOfOverlappedStandAlone_, numberOfOverlappedTracks_, numberOfMatchedZMuTrack_notOverlapped;
96  int numberOfMatchedZMuTrack_exclusive, numberOfMatchedSelectedZMuTrack_exclusive;
97  int numberOfMatchedZMuTrack_matchedZMuMu, numberOfMatchedZMuTrack_matchedSelectedZMuMu;
98  int totalNumberOfevents, totalNumberOfZfound, totalNumberOfZPassed;
99  int noMCmatching, ZMuTrack_exclusive_1match, ZMuTrack_exclusive_morematch;
100  int ZMuTrackselected_exclusive_1match, ZMuTrackselected_exclusive_morematch;
101  int ZMuTrack_ZMuMu_1match, ZMuTrack_ZMuMu_2match, ZMuTrack_ZMuMu_morematch;
102 
103  int n_zMuMufound_genZsele, n_zMuStafound_genZsele, n_zMuTrkfound_genZsele;
104 };
105 
109 #include <iostream>
110 #include <iterator>
111 #include <cmath>
112 
114  : zMuMuToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuMu"))),
115  zMuMuMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuMuMatchMap"))),
116  zMuTrackToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuTrack"))),
117  zMuTrackMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuTrackMatchMap"))),
118  zMuStandAloneToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuStandAlone"))),
119  zMuStandAloneMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuStandAloneMatchMap"))),
120  muonsToken_(consumes<CandidateView>(pset.getParameter<InputTag>("muons"))),
121  muonMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("muonMatchMap"))),
122  muonIsoToken_(mayConsume<IsolationCollection>(pset.getParameter<InputTag>("muonIso"))),
123  tracksToken_(consumes<CandidateView>(pset.getParameter<InputTag>("tracks"))),
124  trackIsoToken_(mayConsume<IsolationCollection>(pset.getParameter<InputTag>("trackIso"))),
125  standAloneToken_(consumes<CandidateView>(pset.getParameter<InputTag>("standAlone"))),
126  standAloneIsoToken_(mayConsume<IsolationCollection>(pset.getParameter<InputTag>("standAloneIso"))),
127  genParticlesToken_(consumes<GenParticleCollection>(pset.getParameter<InputTag>("genParticles"))),
128 
129  zMassMin_(pset.getUntrackedParameter<double>("zMassMin")),
130  zMassMax_(pset.getUntrackedParameter<double>("zMassMax")),
131  ptmin_(pset.getUntrackedParameter<double>("ptmin")),
132  etamax_(pset.getUntrackedParameter<double>("etamax")),
133  isomax_(pset.getUntrackedParameter<double>("isomax")),
134  nbinsPt_(pset.getUntrackedParameter<unsigned int>("nbinsPt")),
135  nbinsEta_(pset.getUntrackedParameter<unsigned int>("nbinsEta")) {
137  TFileDirectory trackEffDir = fs->mkdir("TrackEfficiency");
138 
139  // tracker efficiency distributions
140  h_etaStandAlone_ = trackEffDir.make<TH1D>(
141  "StandAloneMuonEta", "StandAlone #eta for Z -> #mu + standalone", nbinsEta_, -etamax_, etamax_);
143  trackEffDir.make<TH1D>("MuonOverlappedToStandAloneEta",
144  "Global muon overlapped to standAlone #eta for Z -> #mu + sa",
145  nbinsEta_,
146  -etamax_,
147  etamax_);
149  trackEffDir.make<TH1D>("StandAloneMuonPt", "StandAlone p_{t} for Z -> #mu + standalone", nbinsPt_, ptmin_, 100);
151  trackEffDir.make<TH1D>("MuonOverlappedToStandAlonePt",
152  "Global muon overlapped to standAlone p_{t} for Z -> #mu + sa",
153  nbinsPt_,
154  ptmin_,
155  100);
156 
157  // StandAlone efficiency distributions
158  TFileDirectory standaloneEffDir = fs->mkdir("StandaloneEfficiency");
159  h_etaTrack_ =
160  standaloneEffDir.make<TH1D>("TrackMuonEta", "Track #eta for Z -> #mu + track", nbinsEta_, -etamax_, etamax_);
161  h_etaMuonOverlappedToTrack_ = standaloneEffDir.make<TH1D>("MuonOverlappedToTrackEta",
162  "Global muon overlapped to track #eta for Z -> #mu + tk",
163  nbinsEta_,
164  -etamax_,
165  etamax_);
166  h_ptTrack_ = standaloneEffDir.make<TH1D>("TrackMuonPt", "Track p_{t} for Z -> #mu + track", nbinsPt_, ptmin_, 100);
167  h_ptMuonOverlappedToTrack_ = standaloneEffDir.make<TH1D>(
168  "MuonOverlappedToTrackPt", "Global muon overlapped to track p_{t} for Z -> #mu + tk", nbinsPt_, ptmin_, 100);
169 
170  // inv. mass resolution studies
171  TFileDirectory invMassResolutionDir = fs->mkdir("invriantMassResolution");
173  invMassResolutionDir.make<TH1D>("zMuMu_invMassResolution", "zMuMu invariant Mass Resolution", 50, -25, 25);
175  invMassResolutionDir.make<TH1D>("zMuSta_invMassResolution", "zMuSta invariant Mass Resolution", 50, -25, 25);
177  invMassResolutionDir.make<TH1D>("zMuTrack_invMassResolution", "zMuTrack invariant Mass Resolution", 50, -25, 25);
178 
179  // generator level histograms
180  TFileDirectory genParticleDir = fs->mkdir("genParticle");
181  h_nZMCfound_ = genParticleDir.make<TH1D>("NumberOfgeneratedZeta", "n. of generated Z per event", 4, -.5, 3.5);
182  h_ZetaGen_ = genParticleDir.make<TH1D>("generatedZeta", "#eta of generated Z", 100, -5., 5.);
183  h_ZptGen_ = genParticleDir.make<TH1D>("generatedZpt", "pt of generated Z", 100, 0., 200.);
184  h_ZmassGen_ = genParticleDir.make<TH1D>("generatedZmass", "mass of generated Z", 100, 0., 200.);
185  h_muetaGen_ = genParticleDir.make<TH1D>("generatedMuonEta", "#eta of generated muons from Z decay", 100, -5., 5.);
186  h_muptGen_ = genParticleDir.make<TH1D>("generatedMuonpt", "pt of generated muons from Z decay", 100, 0., 200.);
187  h_dimuonEtaGen_ = genParticleDir.make<TH1D>("generatedDimuonEta", "#eta of generated dimuon", 100, -5., 5.);
188  h_dimuonPtGen_ = genParticleDir.make<TH1D>("generatedDimuonPt", "pt of generated dimuon", 100, 0., 200.);
189  h_dimuonMassGen_ = genParticleDir.make<TH1D>("generatedDimuonMass", "mass of generated dimuon", 100, 0., 200.);
190  h_ZetaGenPassed_ = genParticleDir.make<TH1D>("generatedZeta_passed", "#eta of generated Z after cuts", 100, -5., 5.);
191  h_ZptGenPassed_ = genParticleDir.make<TH1D>("generatedZpt_passed", "pt of generated Z after cuts", 100, 0., 200.);
193  genParticleDir.make<TH1D>("generatedZmass_passed", "mass of generated Z after cuts", 100, 0., 200.);
194  h_muetaGenPassed_ = genParticleDir.make<TH1D>(
195  "generatedMuonEta_passed", "#eta of generated muons from Z decay after cuts", 100, -5., 5.);
196  h_muptGenPassed_ = genParticleDir.make<TH1D>(
197  "generatedMuonpt_passed", "pt of generated muons from Z decay after cuts", 100, 0., 200.);
199  genParticleDir.make<TH1D>("generatedDimuonEta_passed", "#eta of generated dimuon after cuts", 100, -5., 5.);
201  genParticleDir.make<TH1D>("generatedDimuonPt_passed", "pt of generated dimuon after cuts", 100, 0., 200.);
203  genParticleDir.make<TH1D>("generatedDimuonMass_passed", "mass of generated dimuon after cuts", 100, 0., 200.);
204  // to insert isolation histograms ..............
205 
219  noMCmatching = 0;
227 
231 
232  // generator counters
236 }
237 
240  Handle<GenParticleMatch> zMuMuMatchMap; //Map of Z made by Mu global + Mu global
241  Handle<CandidateView> zMuTrack;
242  Handle<GenParticleMatch> zMuTrackMatchMap; //Map of Z made by Mu + Track
243  Handle<CandidateView> zMuStandAlone;
244  Handle<GenParticleMatch> zMuStandAloneMatchMap; //Map of Z made by Mu + StandAlone
245  Handle<CandidateView> muons; //Collection of Muons
246  Handle<GenParticleMatch> muonMatchMap;
248  Handle<CandidateView> tracks; //Collection of Tracks
250  Handle<CandidateView> standAlone; //Collection of StandAlone
251  Handle<IsolationCollection> standAloneIso;
252  Handle<GenParticleCollection> genParticles; // Collection of Generatd Particles
253 
254  event.getByToken(zMuMuToken_, zMuMu);
255  event.getByToken(zMuTrackToken_, zMuTrack);
256  event.getByToken(zMuStandAloneToken_, zMuStandAlone);
257  event.getByToken(muonsToken_, muons);
258  event.getByToken(tracksToken_, tracks);
259  event.getByToken(standAloneToken_, standAlone);
260  event.getByToken(genParticlesToken_, genParticles);
261 
262  cout << "********* zMuMu size : " << zMuMu->size() << endl;
263  cout << "********* zMuStandAlone size : " << zMuStandAlone->size() << endl;
264  cout << "********* zMuTrack size : " << zMuTrack->size() << endl;
265  cout << "********* muons size : " << muons->size() << endl;
266  cout << "********* standAlone size : " << standAlone->size() << endl;
267  cout << "********* tracks size : " << tracks->size() << endl;
268  cout << "********* generated size : " << genParticles->size() << endl;
269 
270  // generator level distributions
271 
272  int nZMCfound = 0;
274  int ngen = genParticles->size();
275  bool ZMuMuMatchedfound = false;
276  bool ZMuMuMatchedSelectedfound = false;
277  bool ZMuStaMatchedfound = false;
278  //bool ZMuStaMatchedSelectedfound = false;
279  int ZMuTrackMatchedfound = 0;
280  int ZMuTrackMatchedSelected_exclusivefound = 0;
281 
282  double dimuonMassGen = 0;
283 
284  for (int i = 0; i < ngen; i++) {
285  const Candidate &genCand = (*genParticles)[i];
286 
287  // if((genCand.pdgId() == 23) && (genCand.status() == 2)) //this is an intermediate Z0
288  // cout << ">>> intermediate Z0 found, with " << genCand.numberOfDaughters() << " daughters" << endl;
289  if ((genCand.pdgId() == 23) && (genCand.status() == 3)) { //this is a Z0
290  if (genCand.numberOfDaughters() == 3) { // possible Z0 decays in mu+ mu-, the 3rd daughter is the same Z0
291  const Candidate *dauGen0 = genCand.daughter(0);
292  const Candidate *dauGen1 = genCand.daughter(1);
293  const Candidate *dauGen2 = genCand.daughter(2);
294  if (check_ifZmumu(dauGen0, dauGen1, dauGen2)) { // Z0 in mu+ mu-
296  nZMCfound++;
297  bool checkpt = false;
298  bool checketa = false;
299  bool checkmass = false;
300  float mupluspt, muminuspt, mupluseta, muminuseta;
301  mupluspt = getParticlePt(-13, dauGen0, dauGen1, dauGen2);
302  muminuspt = getParticlePt(13, dauGen0, dauGen1, dauGen2);
303  mupluseta = getParticleEta(-13, dauGen0, dauGen1, dauGen2);
304  muminuseta = getParticleEta(13, dauGen0, dauGen1, dauGen2);
305  //float muplusphi = getParticlePhi(-13,dauGen0,dauGen1,dauGen2);
306  //float muminusphi = getParticlePhi(13,dauGen0,dauGen1,dauGen2);
307  Particle::LorentzVector pZ(0, 0, 0, 0);
308  Particle::LorentzVector muplusp4 = getParticleP4(-13, dauGen0, dauGen1, dauGen2);
309  Particle::LorentzVector muminusp4 = getParticleP4(13, dauGen0, dauGen1, dauGen2);
310  pZ = muplusp4 + muminusp4;
311  double dimuon_pt = sqrt(pZ.x() * pZ.x() + pZ.y() * pZ.y());
312  double tan_theta_half = tan(atan(dimuon_pt / pZ.z()) / 2.);
313  double dimuon_eta = 0.;
314  if (tan_theta_half > 0)
315  dimuon_eta = -log(tan(tan_theta_half));
316  if (tan_theta_half <= 0)
317  dimuon_eta = log(tan(-tan_theta_half));
318 
319  dimuonMassGen = pZ.mass(); // dimuon invariant Mass at Generator Level
320 
321  h_ZmassGen_->Fill(genCand.mass());
322  h_ZetaGen_->Fill(genCand.eta());
323  h_ZptGen_->Fill(genCand.pt());
324  h_dimuonMassGen_->Fill(pZ.mass());
325  h_dimuonEtaGen_->Fill(dimuon_eta);
326  h_dimuonPtGen_->Fill(dimuon_pt);
327  h_muetaGen_->Fill(mupluseta);
328  h_muetaGen_->Fill(muminuseta);
329  h_muptGen_->Fill(mupluspt);
330  h_muptGen_->Fill(muminuspt);
331  // dimuon 4-momentum
332  // h_mDimuonMC->Fill(pZ.mass());
333  // h_ZminusDimuonMassMC->Fill(genCand.mass()-pZ.mass());
334  // h_DeltaPhiMC->Fill(deltaPhi(muplusphi,muminusphi));
335  // if (dauGen2==23) float z_eta = dauGen2->eta();
336  // if (dauGen2==23) float Zpt = dauGen2->pt();
337  // h_DeltaPhivsZPtMC->Fill(DeltaPhi(muplusphi,muminusphi),ZPt);
338 
339  if (mupluspt > ptmin_ && muminuspt > ptmin_)
340  checkpt = true;
341  if (mupluseta < etamax_ && muminuseta < etamax_)
342  checketa = true;
343  if (genCand.mass() > zMassMin_ && genCand.mass() < zMassMax_)
344  checkmass = true;
345  if (checkpt && checketa && checkmass) {
347  h_ZmassGenPassed_->Fill(genCand.mass());
348  h_ZetaGenPassed_->Fill(genCand.eta());
349  h_ZptGenPassed_->Fill(genCand.pt());
350  h_dimuonMassGenPassed_->Fill(pZ.mass());
351  h_dimuonEtaGenPassed_->Fill(dimuon_eta);
352  h_dimuonPtGenPassed_->Fill(dimuon_pt);
353  h_muetaGenPassed_->Fill(mupluseta);
354  h_muetaGenPassed_->Fill(muminuseta);
355  h_muptGenPassed_->Fill(mupluspt);
356  h_muptGenPassed_->Fill(muminuspt);
357 
358  if (!zMuMu->empty()) {
360  } else if (!zMuStandAlone->empty()) {
362  } else {
364  }
365  }
366  }
367  }
368  }
369  }
370  h_nZMCfound_->Fill(nZMCfound); // number of Z found in the event at generator level
371 
372  //TRACK efficiency (conto numero di eventi Zmumu global e ZmuSta (ricorda che sono due campioni esclusivi)
373 
374  if (!zMuMu->empty()) {
376  event.getByToken(zMuMuMatchMapToken_, zMuMuMatchMap);
377  event.getByToken(muonIsoToken_, muonIso);
378  event.getByToken(standAloneIsoToken_, standAloneIso);
379  event.getByToken(muonMatchMapToken_, muonMatchMap);
380  for (unsigned int i = 0; i < zMuMu->size(); ++i) { //loop on candidates
381  const Candidate &zMuMuCand = (*zMuMu)[i]; //the candidate
382  CandidateBaseRef zMuMuCandRef = zMuMu->refAt(i);
383  bool isMatched = false;
384  GenParticleRef zMuMuMatch = (*zMuMuMatchMap)[zMuMuCandRef];
385 
386  if (zMuMuMatch.isNonnull()) { // ZMuMu matched
387  isMatched = true;
389  }
390  CandidateBaseRef dau0 = zMuMuCand.daughter(0)->masterClone();
391  CandidateBaseRef dau1 = zMuMuCand.daughter(1)->masterClone();
392  if (isMatched)
393  ZMuMuMatchedfound = true;
394 
395  // Cuts
396  if ((dau0->pt() > ptmin_) && (dau1->pt() > ptmin_) && (fabs(dau0->eta()) < etamax_) &&
397  (fabs(dau1->eta()) < etamax_) && (zMuMuCand.mass() > zMassMin_) && (zMuMuCand.mass() < zMassMax_) &&
398  (isMatched)) {
399  //The Z daughters are already matched!
400  const double globalMuonIsolation0 = (*muonIso)[dau0];
401  const double globalMuonIsolation1 = (*muonIso)[dau1];
402  if ((globalMuonIsolation0 < isomax_) &&
403  (globalMuonIsolation1 < isomax_)) { // ZMuMu matched and selected by cuts
404  ZMuMuMatchedSelectedfound = true;
406  h_etaStandAlone_->Fill(dau0->eta()); // StandAlone found dau0, eta
407  h_etaStandAlone_->Fill(dau1->eta()); // StandAlone found dau1, eta
408  h_etaMuonOverlappedToStandAlone_->Fill(dau0->eta()); // is global muon so dau0 is also found as a track, eta
409  h_etaMuonOverlappedToStandAlone_->Fill(dau1->eta()); // is global muon so dau1 is also found as a track, eta
410  h_ptStandAlone_->Fill(dau0->pt()); // StandAlone found dau0, pt
411  h_ptStandAlone_->Fill(dau1->pt()); // StandAlone found dau1, pt
412  h_ptMuonOverlappedToStandAlone_->Fill(dau0->pt()); // is global muon so dau0 is also found as a track, pt
413  h_ptMuonOverlappedToStandAlone_->Fill(dau1->pt()); // is global muon so dau1 is also found as a track, pt
414 
415  h_etaTrack_->Fill(dau0->eta()); // Track found dau0, eta
416  h_etaTrack_->Fill(dau1->eta()); // Track found dau1, eta
417  h_etaMuonOverlappedToTrack_->Fill(dau0->eta()); // is global muon so dau0 is also found as a StandAlone, eta
418  h_etaMuonOverlappedToTrack_->Fill(dau1->eta()); // is global muon so dau1 is also found as a StandAlone, eta
419  h_ptTrack_->Fill(dau0->pt()); // Track found dau0, pt
420  h_ptTrack_->Fill(dau1->pt()); // Track found dau1, pt
421  h_ptMuonOverlappedToTrack_->Fill(dau0->pt()); // is global muon so dau0 is also found as a StandAlone, pt
422  h_ptMuonOverlappedToTrack_->Fill(dau1->pt()); // is global muon so dau1 is also found as a StandAlone, pt
423 
424  h_DELTA_ZMuMuMassReco_dimuonMassGen_->Fill(zMuMuCand.mass() - dimuonMassGen);
425  // check that the two muons are matched . .per ora è solo un mio controllo
426  for (unsigned int j = 0; j < muons->size(); ++j) {
427  CandidateBaseRef muCandRef = muons->refAt(j);
428  GenParticleRef muonMatch = (*muonMatchMap)[muCandRef];
429  // if (muonMatch.isNonnull()) cout << "mu match n. " << j << endl;
430  }
431  }
432  }
433  }
434  }
435 
436  if (!zMuStandAlone->empty()) {
438  event.getByToken(zMuStandAloneMatchMapToken_, zMuStandAloneMatchMap);
439  event.getByToken(muonIsoToken_, muonIso);
440  event.getByToken(standAloneIsoToken_, standAloneIso);
441  event.getByToken(muonMatchMapToken_, muonMatchMap);
442  for (unsigned int i = 0; i < zMuStandAlone->size(); ++i) { //loop on candidates
443  const Candidate &zMuStaCand = (*zMuStandAlone)[i]; //the candidate
444  CandidateBaseRef zMuStaCandRef = zMuStandAlone->refAt(i);
445  bool isMatched = false;
446  GenParticleRef zMuStaMatch = (*zMuStandAloneMatchMap)[zMuStaCandRef];
447  if (zMuStaMatch.isNonnull()) { // ZMuSta Macthed
448  isMatched = true;
449  ZMuStaMatchedfound = true;
451  }
452  CandidateBaseRef dau0 = zMuStaCand.daughter(0)->masterClone();
453  CandidateBaseRef dau1 = zMuStaCand.daughter(1)->masterClone();
454 
455  // Cuts
456  if ((dau0->pt() > ptmin_) && (dau1->pt() > ptmin_) && (fabs(dau0->eta()) < etamax_) &&
457  (fabs(dau1->eta()) < etamax_) && (zMuStaCand.mass() > zMassMin_) && (zMuStaCand.mass() < zMassMax_) &&
458  (isMatched)) {
460  if (dau0->isGlobalMuon()) {
461  standAloneMuonCandRef_ = dau1;
462  globalMuonCandRef_ = dau0;
463  }
464  if (dau1->isGlobalMuon()) {
465  standAloneMuonCandRef_ = dau0;
466  globalMuonCandRef_ = dau1;
467  }
468 
469  const double globalMuonIsolation = (*muonIso)[globalMuonCandRef_];
470  const double standAloneMuonIsolation = (*standAloneIso)[standAloneMuonCandRef_];
471 
472  if ((globalMuonIsolation < isomax_) && (standAloneMuonIsolation < isomax_)) { // ZMuSta matched and selected
473  //ZMuStaMatchedSelectedfound = true;
475  h_etaStandAlone_->Fill(standAloneMuonCandRef_->eta()); //Denominator eta for measuring track efficiency
476  h_ptStandAlone_->Fill(standAloneMuonCandRef_->pt()); //Denominator pt for measuring track eff
478  zMuStaCand.mass() - dimuonMassGen); // differnce between ZMuSta reco and dimuon mass gen
479  }
480  }
481  }
482  } //end loop on Candidate
483 
484  //STANDALONE efficiency
485 
486  if (!zMuTrack->empty()) {
487  event.getByToken(zMuTrackMatchMapToken_, zMuTrackMatchMap);
488  event.getByToken(muonIsoToken_, muonIso);
489  event.getByToken(trackIsoToken_, trackIso);
490  event.getByToken(muonMatchMapToken_, muonMatchMap);
491  for (unsigned int i = 0; i < zMuTrack->size(); ++i) { //loop on candidates
492  const Candidate &zMuTrkCand = (*zMuTrack)[i]; //the candidate
493  CandidateBaseRef zMuTrkCandRef = zMuTrack->refAt(i);
494  bool isMatched = false;
495  GenParticleRef zMuTrkMatch = (*zMuTrackMatchMap)[zMuTrkCandRef];
496  if (zMuTrkMatch.isNonnull()) {
497  isMatched = true;
498  }
499  CandidateBaseRef dau0 = zMuTrkCand.daughter(0)->masterClone();
500  CandidateBaseRef dau1 = zMuTrkCand.daughter(1)->masterClone();
501 
502  if (isMatched) {
503  ZMuTrackMatchedfound++;
504  if (ZMuMuMatchedfound)
506  if (ZMuMuMatchedSelectedfound)
508  if (!ZMuMuMatchedfound)
510  }
511  // Cuts
512  if ((dau0->pt() > ptmin_) && (dau1->pt() > ptmin_) && (fabs(dau0->eta()) < etamax_) &&
513  (fabs(dau1->eta()) < etamax_) && (zMuTrkCand.mass() > zMassMin_) && (zMuTrkCand.mass() < zMassMax_) &&
514  (isMatched) && !ZMuMuMatchedfound && !ZMuStaMatchedfound) {
515  // dau0 is always the global muon, dau1 is the track for ZMuTrack collection
516  const double globalMuonIsolation = (*muonIso)[dau0];
517  const double trackMuonIsolation = (*trackIso)[dau1];
518  if ((globalMuonIsolation < isomax_) &&
519  (trackMuonIsolation < isomax_)) { // ZMuTRack matched - selected without ZMuMu found (exclusive)
521  ZMuTrackMatchedSelected_exclusivefound++;
522  h_etaTrack_->Fill(dau1->eta()); //Denominator eta Sta
523  h_ptTrack_->Fill(dau1->pt()); //Denominator pt Sta
524  h_DELTA_ZMuTrackMassReco_dimuonMassGen_->Fill(zMuTrkCand.mass() - dimuonMassGen);
525  }
526  }
527  }
528  } //end loop on Candidate
529 
530  if (!ZMuMuMatchedfound && !ZMuStaMatchedfound && ZMuTrackMatchedfound == 0)
531  noMCmatching++;
532  if (!ZMuMuMatchedfound && ZMuTrackMatchedfound == 1)
534  if (!ZMuMuMatchedfound && ZMuTrackMatchedfound > 1)
536  if (!ZMuMuMatchedfound && ZMuTrackMatchedSelected_exclusivefound == 1)
538  if (!ZMuMuMatchedfound && ZMuTrackMatchedSelected_exclusivefound > 1)
540  if (ZMuMuMatchedfound && ZMuTrackMatchedfound == 1)
542  if (ZMuMuMatchedfound && ZMuTrackMatchedfound == 2)
544  if (ZMuMuMatchedfound && ZMuTrackMatchedfound > 2)
546 }
547 
548 bool ZMuMuEfficiency::check_ifZmumu(const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2) {
549  int partId0 = dauGen0->pdgId();
550  int partId1 = dauGen1->pdgId();
551  int partId2 = dauGen2->pdgId();
552  bool muplusFound = false;
553  bool muminusFound = false;
554  bool ZFound = false;
555  if (partId0 == 13 || partId1 == 13 || partId2 == 13)
556  muminusFound = true;
557  if (partId0 == -13 || partId1 == -13 || partId2 == -13)
558  muplusFound = true;
559  if (partId0 == 23 || partId1 == 23 || partId2 == 23)
560  ZFound = true;
561  return (muplusFound && muminusFound && ZFound);
562 }
563 
564 float ZMuMuEfficiency::getParticlePt(const int ipart,
565  const Candidate *dauGen0,
566  const Candidate *dauGen1,
567  const Candidate *dauGen2) {
568  int partId0 = dauGen0->pdgId();
569  int partId1 = dauGen1->pdgId();
570  int partId2 = dauGen2->pdgId();
571  float ptpart = 0.;
572  if (partId0 == ipart) {
573  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
574  const Candidate *dauMuGen = dauGen0->daughter(k);
575  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
576  ptpart = dauMuGen->pt();
577  }
578  }
579  }
580  if (partId1 == ipart) {
581  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
582  const Candidate *dauMuGen = dauGen1->daughter(k);
583  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
584  ptpart = dauMuGen->pt();
585  }
586  }
587  }
588  if (partId2 == ipart) {
589  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
590  const Candidate *dauMuGen = dauGen2->daughter(k);
591  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
592  ptpart = dauMuGen->pt();
593  }
594  }
595  }
596  return ptpart;
597 }
598 
599 float ZMuMuEfficiency::getParticleEta(const int ipart,
600  const Candidate *dauGen0,
601  const Candidate *dauGen1,
602  const Candidate *dauGen2) {
603  int partId0 = dauGen0->pdgId();
604  int partId1 = dauGen1->pdgId();
605  int partId2 = dauGen2->pdgId();
606  float etapart = 0.;
607  if (partId0 == ipart) {
608  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
609  const Candidate *dauMuGen = dauGen0->daughter(k);
610  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
611  etapart = dauMuGen->eta();
612  }
613  }
614  }
615  if (partId1 == ipart) {
616  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
617  const Candidate *dauMuGen = dauGen1->daughter(k);
618  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
619  etapart = dauMuGen->eta();
620  }
621  }
622  }
623  if (partId2 == ipart) {
624  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
625  const Candidate *dauMuGen = dauGen2->daughter(k);
626  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
627  etapart = dauMuGen->eta();
628  }
629  }
630  }
631  return etapart;
632 }
633 
634 float ZMuMuEfficiency::getParticlePhi(const int ipart,
635  const Candidate *dauGen0,
636  const Candidate *dauGen1,
637  const Candidate *dauGen2) {
638  int partId0 = dauGen0->pdgId();
639  int partId1 = dauGen1->pdgId();
640  int partId2 = dauGen2->pdgId();
641  float phipart = 0.;
642  if (partId0 == ipart) {
643  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
644  const Candidate *dauMuGen = dauGen0->daughter(k);
645  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
646  phipart = dauMuGen->phi();
647  }
648  }
649  }
650  if (partId1 == ipart) {
651  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
652  const Candidate *dauMuGen = dauGen1->daughter(k);
653  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
654  phipart = dauMuGen->phi();
655  }
656  }
657  }
658  if (partId2 == ipart) {
659  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
660  const Candidate *dauMuGen = dauGen2->daughter(k);
661  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
662  phipart = dauMuGen->phi();
663  }
664  }
665  }
666  return phipart;
667 }
668 
670  const Candidate *dauGen0,
671  const Candidate *dauGen1,
672  const Candidate *dauGen2) {
673  int partId0 = dauGen0->pdgId();
674  int partId1 = dauGen1->pdgId();
675  int partId2 = dauGen2->pdgId();
676  Particle::LorentzVector p4part(0., 0., 0., 0.);
677  if (partId0 == ipart) {
678  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
679  const Candidate *dauMuGen = dauGen0->daughter(k);
680  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
681  p4part = dauMuGen->p4();
682  }
683  }
684  }
685  if (partId1 == ipart) {
686  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
687  const Candidate *dauMuGen = dauGen1->daughter(k);
688  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
689  p4part = dauMuGen->p4();
690  }
691  }
692  }
693  if (partId2 == ipart) {
694  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
695  const Candidate *dauMuGen = dauGen2->daughter(k);
696  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
697  p4part = dauMuGen->p4();
698  }
699  }
700  }
701  return p4part;
702 }
703 
705  // double efficiencySTA =(double)numberOfOverlappedStandAlone_/(double)numberOfMatchedZMuTrack_;
706  // double errorEff_STA = sqrt( efficiencySTA*(1 - efficiencySTA)/(double)numberOfMatchedZMuTrack_);
707 
708  double myTrackEff = 2. * numberOfMatchedSelectedZMuMu_ /
710  double myErrTrackEff = sqrt(myTrackEff * (1 - myTrackEff) /
712 
713  double myStaEff = 2. * numberOfMatchedSelectedZMuMu_ /
715  double myErrStaEff = sqrt(myTrackEff * (1 - myTrackEff) /
717 
718  // double efficiencyTRACK =(double)numberOfOverlappedTracks_/(double)numberOfMatchedZMuSta_;
719  // double errorEff_TRACK = sqrt( efficiencyTRACK*(1 - efficiencyTRACK)/(double)numberOfMatchedZMuSta_);
720 
721  cout << "------------------------------------ Counters for MC acceptance --------------------------------" << endl;
722  cout << "totalNumberOfevents = " << totalNumberOfevents << endl;
723  cout << "totalNumberOfZfound = " << totalNumberOfZfound << endl;
724  cout << "totalNumberOfZpassed = " << totalNumberOfZPassed << endl;
725  cout << "n. of events zMuMu found (gen level selected)" << n_zMuMufound_genZsele << endl;
726  cout << "n. of events zMuSta found (gen level selected)" << n_zMuStafound_genZsele << endl;
727  cout << "n. of events zMuTrk found (gen level selected)" << n_zMuTrkfound_genZsele << endl;
728 
729  cout << "---------------------------- Counter for MC truth efficiency calculation--------------------- " << endl;
730 
731  cout << "number of events with ZMuMu found = " << numberOfEventsWithZMuMufound << endl;
732  cout << "number of events with ZMuSta found = " << numberOfEventsWithZMuStafound << endl;
733  cout << "-------------------------------------------------------------------------------------- " << endl;
734 
735  cout << "number of events without MC maching = " << noMCmatching << endl;
736  cout << "number of ZMuTrack exclsive 1 match = " << ZMuTrack_exclusive_1match << endl;
737  cout << "number of ZMuTrack exclsive more match = " << ZMuTrack_exclusive_morematch << endl;
738  cout << "number of ZMuTrack selected exclusive 1 match = " << ZMuTrackselected_exclusive_1match << endl;
739  cout << "number of ZMuTrack selected exclusive more match = " << ZMuTrackselected_exclusive_morematch << endl;
740  cout << "number of ZMuTrack ZMuMu 1 match = " << ZMuTrack_ZMuMu_1match << endl;
741  cout << "number of ZMuTrack ZMuMu 2 match = " << ZMuTrack_ZMuMu_2match << endl;
742  cout << "number of ZMuTrack ZMuMu more match = " << ZMuTrack_ZMuMu_morematch << endl;
743  cout << "numberOfMatchedZMuMu = " << numberOfMatchedZMuMu_ << endl;
744  cout << "numberOfMatchedSelectdZMuMu = " << numberOfMatchedSelectedZMuMu_ << endl;
745  cout << "numberOfMatchedZMuSta = " << numberOfMatchedZMuSta_ << endl;
746  cout << "numberOfMatchedSelectedZMuSta = " << numberOfMatchedSelectedZMuSta_ << endl;
747  cout << "numberOfMatchedZMuTrack_matchedZMuMu = " << numberOfMatchedZMuTrack_matchedZMuMu << endl;
748  cout << "numberOfMatchedZMuTrack_matchedSelectedZMuMu = " << numberOfMatchedZMuTrack_matchedSelectedZMuMu << endl;
749  cout << "numberOfMatchedZMuTrack exclusive = " << numberOfMatchedZMuTrack_exclusive << endl;
750  cout << "numberOfMatchedSelectedZMuTrack exclusive = " << numberOfMatchedSelectedZMuTrack_exclusive << endl;
751  cout << " ----------------------------- Efficiency --------------------------------- " << endl;
752  cout << "Efficiency StandAlone = " << myStaEff << " +/- " << myErrStaEff << endl;
753  cout << "Efficiency Track = " << myTrackEff << " +/- " << myErrTrackEff << endl;
754 }
755 
757 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
EDGetTokenT< GenParticleMatch > zMuMuMatchMapToken_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
TH1D * h_ptMuonOverlappedToTrack_
TH1D * h_dimuonPtGenPassed_
ZMuMuEfficiency(const edm::ParameterSet &pset)
bool check_ifZmumu(const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
EDGetTokenT< CandidateView > zMuStandAloneToken_
int numberOfMatchedSelectedZMuSta_
TH1D * h_etaMuonOverlappedToStandAlone_
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
int ZMuTrackselected_exclusive_1match
int numberOfMatchedZMuTrack_exclusive
size_type size() const
TH1D * h_dimuonEtaGenPassed_
EDGetTokenT< CandidateView > zMuTrackToken_
int numberOfMatchedZMuTrack_matchedSelectedZMuMu
reco::CandidateBaseRef standAloneMuonCandRef_
int numberOfOverlappedStandAlone_
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
TH1D * h_DELTA_ZMuMuMassReco_dimuonMassGen_
int numberOfMatchedZMuTrack_matchedZMuMu
RefToBase< value_type > refAt(size_type i) const
EDGetTokenT< CandidateView > tracksToken_
virtual int status() const =0
status word
EDGetTokenT< GenParticleCollection > genParticlesToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
OverlapChecker overlap_
float getParticlePt(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
virtual int pdgId() const =0
PDG identifier.
T sqrt(T t)
Definition: SSEVec.h:19
void endJob() override
bool empty() const
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int ZMuTrackselected_exclusive_morematch
int numberOfMatchedSelectedZMuTrack_exclusive
bool isMatched(TrackingRecHit const &hit)
float getParticleEta(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
T * make(const Args &...args) const
make new ROOT object
reco::CandidateBaseRef trackMuonCandRef_
EDGetTokenT< CandidateView > zMuMuToken_
float getParticlePhi(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
TH1D * h_DELTA_ZMuStaMassReco_dimuonMassGen_
virtual const CandidateBaseRef & masterClone() const =0
virtual bool isGlobalMuon() const =0
zMuMu
zMuMu vector of PSet is common to all categories except zMuTrk category
virtual double eta() const =0
momentum pseudorapidity
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
virtual double pt() const =0
transverse momentum
int numberOfEventsWithZMuMufound
virtual double mass() const =0
mass
int numberOfMatchedZMuTrack_notOverlapped
unsigned int nbinsPt_
Particle::LorentzVector getParticleP4(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
int numberOfMatchedSelectedZMuMu_
ValueMap< float > IsolationCollection
TH1D * h_dimuonMassGenPassed_
TH1D * h_ptMuonOverlappedToStandAlone_
EDGetTokenT< CandidateView > standAloneToken_
fixed size matrix
HLT enums.
TH1D * h_DELTA_ZMuTrackMassReco_dimuonMassGen_
EDGetTokenT< IsolationCollection > standAloneIsoToken_
EDGetTokenT< GenParticleMatch > zMuTrackMatchMapToken_
int numberOfEventsWithZMuStafound
TH1D * h_etaMuonOverlappedToTrack_
int ZMuTrack_exclusive_morematch
unsigned int nbinsEta_
EDGetTokenT< GenParticleMatch > muonMatchMapToken_
virtual size_type numberOfDaughters() const =0
number of daughters
EDGetTokenT< IsolationCollection > trackIsoToken_
virtual double phi() const =0
momentum azimuthal angle
EDGetTokenT< CandidateView > muonsToken_
EDGetTokenT< IsolationCollection > muonIsoToken_
Definition: event.py:1
math::PtEtaPhiELorentzVectorF LorentzVector
EDGetTokenT< GenParticleMatch > zMuStandAloneMatchMapToken_
reco::CandidateBaseRef globalMuonCandRef_