CMS 3D CMS Logo

ZMuMu_MCanalyzer.cc
Go to the documentation of this file.
1 /* \class ZMuMu_MCanalyzer
2  *
3  * author: Davide Piccolo
4  *
5  * ZMuMu MC analyzer:
6  * check muon reco efficiencies from MC truth,
7  *
8  */
9 
36 #include "TH1.h"
37 #include "TH2.h"
38 #include "TH3.h"
39 #include <vector>
40 
41 using namespace edm;
42 using namespace std;
43 using namespace reco;
44 using namespace reco;
45 using namespace isodeposit;
46 
48 
50 public:
52 
53 private:
54  void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
55  bool check_ifZmumu(const Candidate* dauGen0, const Candidate* dauGen1, const Candidate* dauGen2);
56  float getParticlePt(const int ipart, const Candidate* dauGen0, const Candidate* dauGen1, const Candidate* dauGen2);
57  float getParticleEta(const int ipart, const Candidate* dauGen0, const Candidate* dauGen1, const Candidate* dauGen2);
58  float getParticlePhi(const int ipart, const Candidate* dauGen0, const Candidate* dauGen1, const Candidate* dauGen2);
59  Particle::LorentzVector getParticleP4(const int ipart,
60  const Candidate* dauGen0,
61  const Candidate* dauGen1,
62  const Candidate* dauGen2);
63  void endJob() override;
64 
74 
75  bool bothMuons_;
76 
77  double etamin_, etamax_, ptmin_, massMin_, massMax_, isoMax_;
78 
79  double ptThreshold_, etEcalThreshold_, etHcalThreshold_, dRVetoTrk_, dRTrk_, dREcal_, dRHcal_, alpha_, beta_;
80 
82  string hltPath_;
83  reco::CandidateBaseRef globalMuonCandRef_, trackMuonCandRef_, standAloneMuonCandRef_;
85 
86  // general histograms
87  TH1D *h_trackProbe_eta, *h_trackProbe_pt, *h_staProbe_eta, *h_staProbe_pt, *h_ProbeOk_eta, *h_ProbeOk_pt;
88 
89  // global counters
90  int nGlobalMuonsMatched_passed; // total number of global muons MC matched and passing cuts (and triggered)
91  int nGlobalMuonsMatched_passedIso; // total number of global muons MC matched and passing cuts including Iso
92  int n2GlobalMuonsMatched_passedIso; // total number of Z->2 global muons MC matched and passing cuts including Iso
93  int nStaMuonsMatched_passedIso; // total number of sta only muons MC matched and passing cuts including Iso
94  int nTracksMuonsMatched_passedIso; // total number of tracks only muons MC matched and passing cuts including Iso
95  int n2GlobalMuonsMatched_passedIso2Trg; // total number of Z->2 global muons MC matched and passing cuts including Iso and both triggered
96  int nMu0onlyTriggered; // n. of events zMuMu with mu0 only triggered
97  int nMu1onlyTriggered; // n. of events zMuMu with mu1 only triggered
98 
99  int nZMuMu_matched; // n. of events zMuMu macthed
100  int nZMuSta_matched; // n of events zMuSta macthed
101  int nZMuTrk_matched; // n. of events zMuTrk mathced
102 };
103 
104 template <typename T>
105 double isolation(const T* t,
106  double ptThreshold,
107  double etEcalThreshold,
108  double etHcalThreshold,
109  double dRVetoTrk,
110  double dRTrk,
111  double dREcal,
112  double dRHcal,
113  double alpha,
114  double beta,
115  bool relativeIsolation) {
116  // on 34X:
117  const pat::IsoDeposit* trkIso = t->isoDeposit(pat::TrackIso);
118  // const pat::IsoDeposit * trkIso = t->trackerIsoDeposit();
119  // on 34X
120  const pat::IsoDeposit* ecalIso = t->isoDeposit(pat::EcalIso);
121  // const pat::IsoDeposit * ecalIso = t->ecalIsoDeposit();
122  // on 34X
123  const pat::IsoDeposit* hcalIso = t->isoDeposit(pat::HcalIso);
124  // const pat::IsoDeposit * hcalIso = t->hcalIsoDeposit();
125 
126  Direction dir = Direction(t->eta(), t->phi());
127 
128  pat::IsoDeposit::AbsVetos vetosTrk;
129  vetosTrk.push_back(new ConeVeto(dir, dRVetoTrk));
130  vetosTrk.push_back(new ThresholdVeto(ptThreshold));
131 
132  pat::IsoDeposit::AbsVetos vetosEcal;
133  vetosEcal.push_back(new ConeVeto(dir, 0.));
134  vetosEcal.push_back(new ThresholdVeto(etEcalThreshold));
135 
136  pat::IsoDeposit::AbsVetos vetosHcal;
137  vetosHcal.push_back(new ConeVeto(dir, 0.));
138  vetosHcal.push_back(new ThresholdVeto(etHcalThreshold));
139 
140  double isovalueTrk = (trkIso->sumWithin(dRTrk, vetosTrk));
141  double isovalueEcal = (ecalIso->sumWithin(dREcal, vetosEcal));
142  double isovalueHcal = (hcalIso->sumWithin(dRHcal, vetosHcal));
143 
144  double iso =
145  alpha * (((1 + beta) / 2 * isovalueEcal) + ((1 - beta) / 2 * isovalueHcal)) + ((1 - alpha) * isovalueTrk);
146  if (relativeIsolation)
147  iso /= t->pt();
148  return iso;
149 }
150 
152  double ptThreshold,
153  double etEcalThreshold,
154  double etHcalThreshold,
155  double dRVetoTrk,
156  double dRTrk,
157  double dREcal,
158  double dRHcal,
159  double alpha,
160  double beta,
161  bool relativeIsolation) {
162  const pat::Muon* mu = dynamic_cast<const pat::Muon*>(&*c->masterClone());
163  if (mu != nullptr)
164  return isolation(mu,
165  ptThreshold,
168  dRVetoTrk,
169  dRTrk,
170  dREcal,
171  dRHcal,
172  alpha,
173  beta,
175  const pat::GenericParticle* trk = dynamic_cast<const pat::GenericParticle*>(&*c->masterClone());
176  if (trk != nullptr)
177  return isolation(trk,
178  ptThreshold,
181  dRVetoTrk,
182  dRTrk,
183  dREcal,
184  dRHcal,
185  alpha,
186  beta,
189  << "Candidate daughter #0 is neither pat::Muons nor pat::GenericParticle\n";
190  return -1;
191 }
192 
203 #include <iostream>
204 #include <iterator>
205 #include <cmath>
206 
208  : zMuMuToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuMu"))),
209  zMuMuMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuMuMatchMap"))),
210  zMuStandAloneToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuStandAlone"))),
211  zMuStandAloneMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuStandAloneMatchMap"))),
212  zMuTrackToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuTrack"))),
213  zMuTrackMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuTrackMatchMap"))),
214  muonsToken_(consumes<CandidateView>(pset.getParameter<InputTag>("muons"))),
215  tracksToken_(consumes<CandidateView>(pset.getParameter<InputTag>("tracks"))),
216  genParticlesToken_(consumes<GenParticleCollection>(pset.getParameter<InputTag>("genParticles"))),
217 
218  bothMuons_(pset.getParameter<bool>("bothMuons")),
219  etamin_(pset.getUntrackedParameter<double>("etamin")),
220  etamax_(pset.getUntrackedParameter<double>("etamax")),
221  ptmin_(pset.getUntrackedParameter<double>("ptmin")),
222  massMin_(pset.getUntrackedParameter<double>("zMassMin")),
223  massMax_(pset.getUntrackedParameter<double>("zMassMax")),
224  isoMax_(pset.getUntrackedParameter<double>("isomax")),
225  ptThreshold_(pset.getUntrackedParameter<double>("ptThreshold")),
226  etEcalThreshold_(pset.getUntrackedParameter<double>("etEcalThreshold")),
227  etHcalThreshold_(pset.getUntrackedParameter<double>("etHcalThreshold")),
228  dRVetoTrk_(pset.getUntrackedParameter<double>("deltaRVetoTrk")),
229  dRTrk_(pset.getUntrackedParameter<double>("deltaRTrk")),
230  dREcal_(pset.getUntrackedParameter<double>("deltaREcal")),
231  dRHcal_(pset.getUntrackedParameter<double>("deltaRHcal")),
232  alpha_(pset.getUntrackedParameter<double>("alpha")),
233  beta_(pset.getUntrackedParameter<double>("beta")),
234  relativeIsolation_(pset.getUntrackedParameter<bool>("relativeIsolation")),
235  hltPath_(pset.getUntrackedParameter<std::string>("hltPath")) {
237 
238  // binning of entries array (at moment defined by hand and not in cfg file)
239  double etaRange[8] = {-2.5, -2., -1.2, -0.8, 0.8, 1.2, 2., 2.5};
240  double ptRange[4] = {20., 40., 60., 100.};
241 
242  // general histograms
243  h_trackProbe_eta = fs->make<TH1D>("trackProbeEta", "Eta of tracks", 7, etaRange);
244  h_trackProbe_pt = fs->make<TH1D>("trackProbePt", "Pt of tracks", 3, ptRange);
245  h_staProbe_eta = fs->make<TH1D>("standAloneProbeEta", "Eta of standAlone", 7, etaRange);
246  h_staProbe_pt = fs->make<TH1D>("standAloneProbePt", "Pt of standAlone", 3, ptRange);
247  h_ProbeOk_eta = fs->make<TH1D>("probeOkEta", "Eta of probe Ok", 7, etaRange);
248  h_ProbeOk_pt = fs->make<TH1D>("probeOkPt", "Pt of probe ok", 3, ptRange);
249 
250  // clear global counters
257  nMu0onlyTriggered = 0;
258  nMu1onlyTriggered = 0;
259  nZMuMu_matched = 0;
260  nZMuSta_matched = 0;
261  nZMuTrk_matched = 0;
262 }
263 
266  Handle<GenParticleMatch> zMuMuMatchMap; //Map of Z made by Mu global + Mu global
267  Handle<CandidateView> zMuStandAlone;
268  Handle<GenParticleMatch> zMuStandAloneMatchMap; //Map of Z made by Mu + StandAlone
269  Handle<CandidateView> zMuTrack;
270  Handle<GenParticleMatch> zMuTrackMatchMap; //Map of Z made by Mu + Track
271  Handle<CandidateView> muons; //Collection of Muons
272  Handle<CandidateView> tracks; //Collection of Tracks
273 
274  Handle<GenParticleCollection> genParticles; // Collection of Generatd Particles
275 
276  event.getByToken(zMuMuToken_, zMuMu);
277  event.getByToken(zMuStandAloneToken_, zMuStandAlone);
278  event.getByToken(zMuTrackToken_, zMuTrack);
279  event.getByToken(genParticlesToken_, genParticles);
280  event.getByToken(muonsToken_, muons);
281  event.getByToken(tracksToken_, tracks);
282 
283  /*
284  cout << "********* zMuMu size : " << zMuMu->size() << endl;
285  cout << "********* zMuStandAlone size : " << zMuStandAlone->size() << endl;
286  cout << "********* zMuTrack size : " << zMuTrack->size() << endl;
287  cout << "********* muons size : " << muons->size() << endl;
288  cout << "********* tracks size : " << tracks->size() << endl;
289  */
290  // std::cout<<"Run-> "<<event.id().run()<<std::endl;
291  // std::cout<<"Event-> "<<event.id().event()<<std::endl;
292 
293  bool zMuMu_found = false;
294 
295  // loop on ZMuMu
296  if (!zMuMu->empty()) {
297  event.getByToken(zMuMuMatchMapToken_, zMuMuMatchMap);
298  for (unsigned int i = 0; i < zMuMu->size(); ++i) { //loop on candidates
299  const Candidate& zMuMuCand = (*zMuMu)[i]; //the candidate
300  CandidateBaseRef zMuMuCandRef = zMuMu->refAt(i);
301 
302  const Candidate* lep0 = zMuMuCand.daughter(0);
303  const Candidate* lep1 = zMuMuCand.daughter(1);
304  const pat::Muon& muonDau0 = dynamic_cast<const pat::Muon&>(*lep0->masterClone());
305  // double trkiso0 = muonDau0.trackIso();
306  const pat::Muon& muonDau1 = dynamic_cast<const pat::Muon&>(*lep1->masterClone());
307  //double trkiso1 = muonDau1.trackIso();
308 
309  double iso0 = candidateIsolation(lep0,
310  ptThreshold_,
313  dRVetoTrk_,
314  dRTrk_,
315  dREcal_,
316  dRHcal_,
317  alpha_,
318  beta_,
320  double iso1 = candidateIsolation(lep1,
321  ptThreshold_,
324  dRVetoTrk_,
325  dRTrk_,
326  dREcal_,
327  dRHcal_,
328  alpha_,
329  beta_,
331 
332  double pt0 = zMuMuCand.daughter(0)->pt();
333  double pt1 = zMuMuCand.daughter(1)->pt();
334  double eta0 = zMuMuCand.daughter(0)->eta();
335  double eta1 = zMuMuCand.daughter(1)->eta();
336  double mass = zMuMuCand.mass();
337 
338  // HLT match
340  const pat::TriggerObjectStandAloneCollection mu1HLTMatches = muonDau1.triggerObjectMatchesByPath(hltPath_);
341 
342  bool trig0found = false;
343  bool trig1found = false;
344  if (!mu0HLTMatches.empty())
345  trig0found = true;
346  if (!mu1HLTMatches.empty())
347  trig1found = true;
348 
349  GenParticleRef zMuMuMatch = (*zMuMuMatchMap)[zMuMuCandRef];
350  if (zMuMuMatch.isNonnull()) { // ZMuMu matched
351  zMuMu_found = true;
352  nZMuMu_matched++;
353  if (pt0 > ptmin_ && pt1 > ptmin_ && abs(eta0) > etamin_ && abs(eta1) > etamin_ && abs(eta0) < etamax_ &&
354  abs(eta1) < etamax_ && mass > massMin_ && mass < massMax_ &&
355  (trig0found || trig1found)) { // kinematic and trigger cuts passed
356  nGlobalMuonsMatched_passed++; // first global Muon passed kine cuts
357  nGlobalMuonsMatched_passed++; // second global muon passsed kine cuts
358  if (iso0 < isoMax_)
359  nGlobalMuonsMatched_passedIso++; // first global muon passed the iso cut
360  if (iso1 < isoMax_)
361  nGlobalMuonsMatched_passedIso++; // second global muon passed the iso cut
362  if (iso0 < isoMax_ && iso1 < isoMax_) {
363  n2GlobalMuonsMatched_passedIso++; // both muons passed iso cut
364  if (trig0found && trig1found)
365  n2GlobalMuonsMatched_passedIso2Trg++; // both muons have HLT
366  if (trig0found && !trig1found)
368  if (trig1found && !trig0found)
370  // histograms vs eta and pt
371  if (trig1found) { // check efficiency of muon0 not imposing the trigger on it
372  h_trackProbe_eta->Fill(eta0);
373  h_trackProbe_pt->Fill(pt0);
374  h_staProbe_eta->Fill(eta0);
375  h_staProbe_pt->Fill(pt0);
376  h_ProbeOk_eta->Fill(eta0);
377  h_ProbeOk_pt->Fill(pt0);
378  }
379  if (trig0found) { // check efficiency of muon1 not imposing the trigger on it
380  h_trackProbe_eta->Fill(eta1);
381  h_staProbe_eta->Fill(eta1);
382  h_trackProbe_pt->Fill(pt1);
383  h_staProbe_pt->Fill(pt1);
384  h_ProbeOk_eta->Fill(eta1);
385  h_ProbeOk_pt->Fill(pt1);
386  }
387  }
388  }
389  } // end MC match
390 
391  } // end loop on ZMuMu cand
392  } // end if ZMuMu size > 0
393 
394  // loop on ZMuSta
395  bool zMuSta_found = false;
396  if (!zMuMu_found && !zMuStandAlone->empty()) {
397  event.getByToken(zMuStandAloneMatchMapToken_, zMuStandAloneMatchMap);
398  for (unsigned int i = 0; i < zMuStandAlone->size(); ++i) { //loop on candidates
399  const Candidate& zMuStandAloneCand = (*zMuStandAlone)[i]; //the candidate
400  CandidateBaseRef zMuStandAloneCandRef = zMuStandAlone->refAt(i);
401  GenParticleRef zMuStandAloneMatch = (*zMuStandAloneMatchMap)[zMuStandAloneCandRef];
402 
403  const Candidate* lep0 = zMuStandAloneCand.daughter(0);
404  const Candidate* lep1 = zMuStandAloneCand.daughter(1);
405  const pat::Muon& muonDau0 = dynamic_cast<const pat::Muon&>(*lep0->masterClone());
406  //double trkiso0 = muonDau0.trackIso();
407  // const pat::Muon & muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
408  //double trkiso1 = muonDau1.trackIso();
409 
410  double iso0 = candidateIsolation(lep0,
411  ptThreshold_,
414  dRVetoTrk_,
415  dRTrk_,
416  dREcal_,
417  dRHcal_,
418  alpha_,
419  beta_,
421  double iso1 = candidateIsolation(lep1,
422  ptThreshold_,
425  dRVetoTrk_,
426  dRTrk_,
427  dREcal_,
428  dRHcal_,
429  alpha_,
430  beta_,
432 
433  double pt0 = zMuStandAloneCand.daughter(0)->pt();
434  double pt1 = zMuStandAloneCand.daughter(1)->pt();
435  double eta0 = zMuStandAloneCand.daughter(0)->eta();
436  double eta1 = zMuStandAloneCand.daughter(1)->eta();
437  double mass = zMuStandAloneCand.mass();
438 
439  // HLT match (check just dau0 the global)
441 
442  bool trig0found = false;
443  if (!mu0HLTMatches.empty())
444  trig0found = true;
445 
446  if (zMuStandAloneMatch.isNonnull()) { // ZMuStandAlone matched
447  zMuSta_found = true;
448  nZMuSta_matched++;
449  if (pt0 > ptmin_ && pt1 > ptmin_ && abs(eta0) > etamin_ && abs(eta1) > etamin_ && abs(eta0) < etamax_ &&
450  abs(eta1) < etamax_ && mass > massMin_ && mass < massMax_ && iso0 < isoMax_ && iso1 < isoMax_ &&
451  trig0found) { // all cuts and trigger passed
453  // histograms vs eta and pt
454  h_staProbe_eta->Fill(eta1);
455  h_staProbe_pt->Fill(pt1);
456  }
457  } // end MC match
458  } // end loop on ZMuStandAlone cand
459  } // end if ZMuStandAlone size > 0
460 
461  // loop on ZMuTrack
462  if (!zMuMu_found && !zMuSta_found && !zMuTrack->empty()) {
463  event.getByToken(zMuTrackMatchMapToken_, zMuTrackMatchMap);
464  for (unsigned int i = 0; i < zMuTrack->size(); ++i) { //loop on candidates
465  const Candidate& zMuTrackCand = (*zMuTrack)[i]; //the candidate
466  CandidateBaseRef zMuTrackCandRef = zMuTrack->refAt(i);
467  const Candidate* lep0 = zMuTrackCand.daughter(0);
468  const Candidate* lep1 = zMuTrackCand.daughter(1);
469  const pat::Muon& muonDau0 = dynamic_cast<const pat::Muon&>(*lep0->masterClone());
470  //double trkiso0 = muonDau0.trackIso();
471  //const pat::GenericParticle & trackDau1 = dynamic_cast<const pat::GenericParticle &>(*lep1->masterClone());
472  //double trkiso1 = trackDau1.trackIso();
473  double iso0 = candidateIsolation(lep0,
474  ptThreshold_,
477  dRVetoTrk_,
478  dRTrk_,
479  dREcal_,
480  dRHcal_,
481  alpha_,
482  beta_,
484  double iso1 = candidateIsolation(lep1,
485  ptThreshold_,
488  dRVetoTrk_,
489  dRTrk_,
490  dREcal_,
491  dRHcal_,
492  alpha_,
493  beta_,
495 
496  double pt0 = zMuTrackCand.daughter(0)->pt();
497  double pt1 = zMuTrackCand.daughter(1)->pt();
498  double eta0 = zMuTrackCand.daughter(0)->eta();
499  double eta1 = zMuTrackCand.daughter(1)->eta();
500  double mass = zMuTrackCand.mass();
501 
502  // HLT match (check just dau0 the global)
504 
505  bool trig0found = false;
506  if (!mu0HLTMatches.empty())
507  trig0found = true;
508 
509  GenParticleRef zMuTrackMatch = (*zMuTrackMatchMap)[zMuTrackCandRef];
510  if (zMuTrackMatch.isNonnull()) { // ZMuTrack matched
511  nZMuTrk_matched++;
512  if (pt0 > ptmin_ && pt1 > ptmin_ && abs(eta0) > etamin_ && abs(eta1) > etamin_ && abs(eta0) < etamax_ &&
513  abs(eta1) < etamax_ && mass > massMin_ && mass < massMax_ && iso0 < isoMax_ && iso1 < isoMax_ &&
514  trig0found) { // all cuts and trigger passed
516  // histograms vs eta and pt
517  h_trackProbe_eta->Fill(eta1);
518  h_trackProbe_pt->Fill(pt1);
519  }
520  } // end MC match
521  } // end loop on ZMuTrack cand
522  } // end if ZMuTrack size > 0
523 
524 } // end analyze
525 
526 bool ZMuMu_MCanalyzer::check_ifZmumu(const Candidate* dauGen0, const Candidate* dauGen1, const Candidate* dauGen2) {
527  int partId0 = dauGen0->pdgId();
528  int partId1 = dauGen1->pdgId();
529  int partId2 = dauGen2->pdgId();
530  bool muplusFound = false;
531  bool muminusFound = false;
532  bool ZFound = false;
533  if (partId0 == 13 || partId1 == 13 || partId2 == 13)
534  muminusFound = true;
535  if (partId0 == -13 || partId1 == -13 || partId2 == -13)
536  muplusFound = true;
537  if (partId0 == 23 || partId1 == 23 || partId2 == 23)
538  ZFound = true;
539  return (muplusFound && muminusFound && ZFound);
540 }
541 
542 float ZMuMu_MCanalyzer::getParticlePt(const int ipart,
543  const Candidate* dauGen0,
544  const Candidate* dauGen1,
545  const Candidate* dauGen2) {
546  int partId0 = dauGen0->pdgId();
547  int partId1 = dauGen1->pdgId();
548  int partId2 = dauGen2->pdgId();
549  float ptpart = 0.;
550  if (partId0 == ipart) {
551  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
552  const Candidate* dauMuGen = dauGen0->daughter(k);
553  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
554  ptpart = dauMuGen->pt();
555  }
556  }
557  }
558  if (partId1 == ipart) {
559  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
560  const Candidate* dauMuGen = dauGen1->daughter(k);
561  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
562  ptpart = dauMuGen->pt();
563  }
564  }
565  }
566  if (partId2 == ipart) {
567  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
568  const Candidate* dauMuGen = dauGen2->daughter(k);
569  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
570  ptpart = dauMuGen->pt();
571  }
572  }
573  }
574  return ptpart;
575 }
576 
577 float ZMuMu_MCanalyzer::getParticleEta(const int ipart,
578  const Candidate* dauGen0,
579  const Candidate* dauGen1,
580  const Candidate* dauGen2) {
581  int partId0 = dauGen0->pdgId();
582  int partId1 = dauGen1->pdgId();
583  int partId2 = dauGen2->pdgId();
584  float etapart = 0.;
585  if (partId0 == ipart) {
586  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
587  const Candidate* dauMuGen = dauGen0->daughter(k);
588  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
589  etapart = dauMuGen->eta();
590  }
591  }
592  }
593  if (partId1 == ipart) {
594  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
595  const Candidate* dauMuGen = dauGen1->daughter(k);
596  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
597  etapart = dauMuGen->eta();
598  }
599  }
600  }
601  if (partId2 == ipart) {
602  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
603  const Candidate* dauMuGen = dauGen2->daughter(k);
604  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
605  etapart = dauMuGen->eta();
606  }
607  }
608  }
609  return etapart;
610 }
611 
612 float ZMuMu_MCanalyzer::getParticlePhi(const int ipart,
613  const Candidate* dauGen0,
614  const Candidate* dauGen1,
615  const Candidate* dauGen2) {
616  int partId0 = dauGen0->pdgId();
617  int partId1 = dauGen1->pdgId();
618  int partId2 = dauGen2->pdgId();
619  float phipart = 0.;
620  if (partId0 == ipart) {
621  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
622  const Candidate* dauMuGen = dauGen0->daughter(k);
623  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
624  phipart = dauMuGen->phi();
625  }
626  }
627  }
628  if (partId1 == ipart) {
629  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
630  const Candidate* dauMuGen = dauGen1->daughter(k);
631  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
632  phipart = dauMuGen->phi();
633  }
634  }
635  }
636  if (partId2 == ipart) {
637  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
638  const Candidate* dauMuGen = dauGen2->daughter(k);
639  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
640  phipart = dauMuGen->phi();
641  }
642  }
643  }
644  return phipart;
645 }
646 
648  const Candidate* dauGen0,
649  const Candidate* dauGen1,
650  const Candidate* dauGen2) {
651  int partId0 = dauGen0->pdgId();
652  int partId1 = dauGen1->pdgId();
653  int partId2 = dauGen2->pdgId();
654  Particle::LorentzVector p4part(0., 0., 0., 0.);
655  if (partId0 == ipart) {
656  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
657  const Candidate* dauMuGen = dauGen0->daughter(k);
658  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
659  p4part = dauMuGen->p4();
660  }
661  }
662  }
663  if (partId1 == ipart) {
664  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
665  const Candidate* dauMuGen = dauGen1->daughter(k);
666  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
667  p4part = dauMuGen->p4();
668  }
669  }
670  }
671  if (partId2 == ipart) {
672  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
673  const Candidate* dauMuGen = dauGen2->daughter(k);
674  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
675  p4part = dauMuGen->p4();
676  }
677  }
678  }
679  return p4part;
680 }
681 
684  double err_effIso = sqrt(eff_Iso * (1 - eff_Iso) / nGlobalMuonsMatched_passed);
685 
686  double n1_afterIso =
688  double n2_afterIso =
691  double effSta_afterIso =
693  double effTrk_afterIso =
695  double effHLT_afterIso = (2. * n2GlobalMuonsMatched_passedIso2Trg) /
697  double err_effHLT_afterIso = sqrt(effHLT_afterIso * (1 - effHLT_afterIso) / nGLB_afterIso);
698  double err_effsta_afterIso = sqrt(effSta_afterIso * (1 - effSta_afterIso) / n1_afterIso);
699  double err_efftrk_afterIso = sqrt(effTrk_afterIso * (1 - effTrk_afterIso) / n2_afterIso);
700 
701  cout << "------------------------------------ Counters --------------------------------" << endl;
702 
703  cout << "number of events zMuMu matched " << nZMuMu_matched << endl;
704  cout << "number of events zMuSta matched " << nZMuSta_matched << endl;
705  cout << "number of events zMuTk matched " << nZMuTrk_matched << endl;
706  cout << "number of events zMuMu with mu0 only triggered " << nMu0onlyTriggered << endl;
707  cout << "number of events zMuMu with mu1 only triggered " << nMu1onlyTriggered << endl;
708  cout << "=========================================" << endl;
709  cout << "n. of global muons MC matched and passing cuts: " << nGlobalMuonsMatched_passed << endl;
710  cout << "n. of global muons MC matched and passing also Iso cut: " << nGlobalMuonsMatched_passedIso << endl;
711  cout << "n. of Z -> 2 global muons MC matched and passing ALL cuts: " << n2GlobalMuonsMatched_passedIso << endl;
712  cout << "n. of ZMuSta MC matched and passing ALL cuts: " << nStaMuonsMatched_passedIso << endl;
713  cout << "n. of ZmuTrck MC matched and passing ALL cuts: " << nTracksMuonsMatched_passedIso << endl;
714  cout << "n. of Z -> 2 global muons MC matched and passing ALL cuts and both triggered: "
716  cout << "=================================================================================" << endl;
717  cout << "Iso efficiency: " << eff_Iso << " +/- " << err_effIso << endl;
718  cout << "HLT efficiency: " << effHLT_afterIso << " +/- " << err_effHLT_afterIso << endl;
719  cout << "eff StandAlone (after Isocut) : " << effSta_afterIso << "+/-" << err_effsta_afterIso << endl;
720  cout << "eff Tracker (after Isocut) : " << effTrk_afterIso << "+/-" << err_efftrk_afterIso << endl;
721 }
722 
724 
RazorAnalyzer.lep1
lep1
print 'MRbb(1b)',event.mr_bb
Definition: RazorAnalyzer.py:261
ewkMuLumiMonitorDQM_cfi.ptThreshold
ptThreshold
Definition: ewkMuLumiMonitorDQM_cfi.py:13
reco::Candidate::daughter
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
ZMuMu_MCanalyzer::zMuTrackToken_
EDGetTokenT< CandidateView > zMuTrackToken_
Definition: ZMuMu_MCanalyzer.cc:69
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
OverlapChecker
Definition: OverlapChecker.h:17
Handle.h
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
zMuMuMuonUserData.dRHcal
dRHcal
Definition: zMuMuMuonUserData.py:19
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
pat::EcalIso
Definition: Isolation.h:11
Muon.h
IsoDepositVetos.h
genParticles2HepMC_cfi.genParticles
genParticles
Definition: genParticles2HepMC_cfi.py:4
ZMuMuAnalysisNtupler_cff.zMuMu
zMuMu
zMuMu vector of PSet is common to all categories except zMuTrk category
Definition: ZMuMuAnalysisNtupler_cff.py:340
edm::View::empty
bool empty() const
generateTowerEtThresholdLUT.etaRange
etaRange
Definition: generateTowerEtThresholdLUT.py:55
edm::errors::InvalidReference
Definition: EDMException.h:39
ZMuMu_MCanalyzer::h_ProbeOk_eta
TH1D * h_ProbeOk_eta
Definition: ZMuMu_MCanalyzer.cc:87
ZMuMu_MCanalyzer::h_ProbeOk_pt
TH1D * h_ProbeOk_pt
Definition: ZMuMu_MCanalyzer.cc:87
ZMuMu_MCanalyzer::nGlobalMuonsMatched_passedIso
int nGlobalMuonsMatched_passedIso
Definition: ZMuMu_MCanalyzer.cc:91
ZMuMu_MCanalyzer::etamin_
double etamin_
Definition: ZMuMu_MCanalyzer.cc:77
ZMuMu_MCanalyzer::beta_
double beta_
Definition: ZMuMu_MCanalyzer.cc:79
reco::Candidate::mass
virtual double mass() const =0
mass
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
ZMuMu_MCanalyzer::endJob
void endJob() override
Definition: ZMuMu_MCanalyzer.cc:682
edm::View::refAt
RefToBase< value_type > refAt(size_type i) const
zMuMuMuonUserData.alpha
alpha
zGenParticlesMatch = cms.InputTag(""),
Definition: zMuMuMuonUserData.py:9
reco::Candidate::eta
virtual double eta() const =0
momentum pseudorapidity
edm::EDGetTokenT< CandidateView >
IsolationCollection
ValueMap< float > IsolationCollection
Definition: ZMuMu_MCanalyzer.cc:47
edm
HLT enums.
Definition: AlignableModifier.h:19
zMuMuMuonUserData.beta
beta
Definition: zMuMuMuonUserData.py:10
ZMuMuCategoriesSequences_cff.trkIso
trkIso
Definition: ZMuMuCategoriesSequences_cff.py:140
Muon.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
GenericParticle.h
ZMuMu_MCanalyzer::nMu0onlyTriggered
int nMu0onlyTriggered
Definition: ZMuMu_MCanalyzer.cc:96
reco::GenParticleCollection
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Definition: GenParticleFwd.h:13
ZMuMu_MCanalyzer::h_trackProbe_eta
TH1D * h_trackProbe_eta
Definition: ZMuMu_MCanalyzer.cc:87
ZMuMu_MCanalyzer::ZMuMu_MCanalyzer
ZMuMu_MCanalyzer(const edm::ParameterSet &pset)
Definition: ZMuMu_MCanalyzer.cc:207
reco::Candidate::pt
virtual double pt() const =0
transverse momentum
ZMuMu_MCanalyzer::hltPath_
string hltPath_
Definition: ZMuMu_MCanalyzer.cc:82
ZMuMu_MCanalyzer::massMax_
double massMax_
Definition: ZMuMu_MCanalyzer.cc:77
ZMuMu_MCanalyzer::analyze
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
Definition: ZMuMu_MCanalyzer.cc:264
reco::Candidate::status
virtual int status() const =0
status word
EDAnalyzer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
ZMuMu_MCanalyzer::dREcal_
double dREcal_
Definition: ZMuMu_MCanalyzer.cc:79
edm::Handle
Definition: AssociativeIterator.h:50
RecoCandidate.h
IsoDepositDirection.h
ZMuMu_MCanalyzer::getParticlePhi
float getParticlePhi(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
Definition: ZMuMu_MCanalyzer.cc:612
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
CandMatchMap.h
edm::Ref< GenParticleCollection >
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
GenParticle.h
CandidateFwd.h
ZMuMu_MCanalyzer::zMuMuToken_
EDGetTokenT< CandidateView > zMuMuToken_
Definition: ZMuMu_MCanalyzer.cc:65
ZMuMu_MCanalyzer::zMuStandAloneToken_
EDGetTokenT< CandidateView > zMuStandAloneToken_
Definition: ZMuMu_MCanalyzer.cc:67
reco::isodeposit::ConeVeto
Definition: IsoDepositVetos.h:9
MakerMacros.h
ZMuMu_MCanalyzer::trackMuonCandRef_
reco::CandidateBaseRef trackMuonCandRef_
Definition: ZMuMu_MCanalyzer.cc:83
ZMuMu_MCanalyzer::ptmin_
double ptmin_
Definition: ZMuMu_MCanalyzer.cc:77
ZMuMu_MCanalyzer::nZMuMu_matched
int nZMuMu_matched
Definition: ZMuMu_MCanalyzer.cc:99
Track.h
ZMuMu_MCanalyzer::muonsToken_
EDGetTokenT< CandidateView > muonsToken_
Definition: ZMuMu_MCanalyzer.cc:71
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ZMuMu_MCanalyzer::dRVetoTrk_
double dRVetoTrk_
Definition: ZMuMu_MCanalyzer.cc:79
ZMuMu_MCanalyzer::check_ifZmumu
bool check_ifZmumu(const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
Definition: ZMuMu_MCanalyzer.cc:526
ZMuMu_MCanalyzer::isoMax_
double isoMax_
Definition: ZMuMu_MCanalyzer.cc:77
zMuMuMuonUserData.dREcal
dREcal
Definition: zMuMuMuonUserData.py:18
isolation
double isolation(const T *t, double ptThreshold, double etEcalThreshold, double etHcalThreshold, double dRVetoTrk, double dRTrk, double dREcal, double dRHcal, double alpha, double beta, bool relativeIsolation)
Definition: ZMuMu_MCanalyzer.cc:105
Service.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
ZMuMu_MCanalyzer::bothMuons_
bool bothMuons_
Definition: ZMuMu_MCanalyzer.cc:75
zMuMuMuonUserData.dRTrk
dRTrk
Definition: zMuMuMuonUserData.py:17
reco::IsoDeposit::AbsVetos
isodeposit::AbsVetos AbsVetos
Definition: IsoDeposit.h:53
ZMuMu_MCanalyzer::nMu1onlyTriggered
int nMu1onlyTriggered
Definition: ZMuMu_MCanalyzer.cc:97
Particle.h
reco::Candidate::numberOfDaughters
virtual size_type numberOfDaughters() const =0
number of daughters
HLT_FULL_cff.pt1
pt1
Definition: HLT_FULL_cff.py:9870
Isolation.h
ZMuMu_MCanalyzer::h_staProbe_eta
TH1D * h_staProbe_eta
Definition: ZMuMu_MCanalyzer.cc:87
dqmdumpme.k
k
Definition: dqmdumpme.py:60
ZMuMu_MCanalyzer::etamax_
double etamax_
Definition: ZMuMu_MCanalyzer.cc:77
IsoDeposit.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View::size
size_type size() const
TFileService.h
HLT_FULL_cff.eta1
eta1
Definition: HLT_FULL_cff.py:9541
edm::View
Definition: CaloClusterFwd.h:14
ZMuMu_MCanalyzer::nTracksMuonsMatched_passedIso
int nTracksMuonsMatched_passedIso
Definition: ZMuMu_MCanalyzer.cc:94
ZMuMu_MCanalyzer::nZMuTrk_matched
int nZMuTrk_matched
Definition: ZMuMu_MCanalyzer.cc:101
ZMuMu_MCanalyzer::nZMuSta_matched
int nZMuSta_matched
Definition: ZMuMu_MCanalyzer.cc:100
pat::GenericParticle
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed)
Definition: GenericParticle.h:38
edm::ParameterSet
Definition: ParameterSet.h:47
ZMuMu_MCanalyzer::h_staProbe_pt
TH1D * h_staProbe_pt
Definition: ZMuMu_MCanalyzer.cc:87
CandAssociation.h
Event.h
ZMuMuCategoriesNtuples_cff.relativeIsolation
relativeIsolation
Definition: ZMuMuCategoriesNtuples_cff.py:27
deltaR.h
zMuMuMuonUserData.dRVetoTrk
dRVetoTrk
Definition: zMuMuMuonUserData.py:16
ZMuMu_MCanalyzer::nGlobalMuonsMatched_passed
int nGlobalMuonsMatched_passed
Definition: ZMuMu_MCanalyzer.cc:90
MuonErrorMatrixValues_cff.ptRange
ptRange
Definition: MuonErrorMatrixValues_cff.py:3
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
ZMuMu_MCanalyzer::zMuTrackMatchMapToken_
EDGetTokenT< GenParticleMatch > zMuTrackMatchMapToken_
Definition: ZMuMu_MCanalyzer.cc:70
pat::TrackIso
Definition: Isolation.h:10
ZMuMu_MCanalyzer::dRHcal_
double dRHcal_
Definition: ZMuMu_MCanalyzer.cc:79
LorentzVector.h
edm::Service< TFileService >
reco::IsoDeposit::sumWithin
double sumWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:137
pat::HcalIso
Definition: Isolation.h:12
pat::TriggerObjectStandAloneCollection
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
Definition: TriggerObjectStandAlone.h:219
ZMuMu_MCanalyzer::massMin_
double massMin_
Definition: ZMuMu_MCanalyzer.cc:77
ZMuMu_MCanalyzer::nStaMuonsMatched_passedIso
int nStaMuonsMatched_passedIso
Definition: ZMuMu_MCanalyzer.cc:93
candidateIsolation
double candidateIsolation(const reco::Candidate *c, double ptThreshold, double etEcalThreshold, double etHcalThreshold, double dRVetoTrk, double dRTrk, double dREcal, double dRHcal, double alpha, double beta, bool relativeIsolation)
Definition: ZMuMu_MCanalyzer.cc:151
zMuMuMuonUserData.etEcalThreshold
etEcalThreshold
Definition: zMuMuMuonUserData.py:14
ZMuMu_MCanalyzer::genParticlesToken_
EDGetTokenT< GenParticleCollection > genParticlesToken_
Definition: ZMuMu_MCanalyzer.cc:73
pat::PATObject::triggerObjectMatchesByPath
const TriggerObjectStandAloneCollection triggerObjectMatchesByPath(const std::string &namePath, const bool pathLastFilterAccepted=false, const bool pathL3FilterAccepted=true) const
Definition: PATObject.h:679
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
ZMuMu_MCanalyzer
Definition: ZMuMu_MCanalyzer.cc:49
reco::Candidate::pdgId
virtual int pdgId() const =0
PDG identifier.
ZMuMu_MCanalyzer::n2GlobalMuonsMatched_passedIso2Trg
int n2GlobalMuonsMatched_passedIso2Trg
Definition: ZMuMu_MCanalyzer.cc:95
InputTag.h
reco::isodeposit::ThresholdVeto
Definition: IsoDepositVetos.h:21
reco::Candidate
Definition: Candidate.h:27
ValueMap.h
reco::JetExtendedAssociation::LorentzVector
math::PtEtaPhiELorentzVectorF LorentzVector
Definition: JetExtendedAssociation.h:25
std
Definition: JetResolutionObject.h:76
ZMuMu_MCanalyzer::etHcalThreshold_
double etHcalThreshold_
Definition: ZMuMu_MCanalyzer.cc:79
ZMuMu_MCanalyzer::getParticleEta
float getParticleEta(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
Definition: ZMuMu_MCanalyzer.cc:577
ZMuMu_MCanalyzer::zMuMuMatchMapToken_
EDGetTokenT< GenParticleMatch > zMuMuMatchMapToken_
Definition: ZMuMu_MCanalyzer.cc:66
T
long double T
Definition: Basic3DVectorLD.h:48
ZMuMu_MCanalyzer::etEcalThreshold_
double etEcalThreshold_
Definition: ZMuMu_MCanalyzer.cc:79
edm::ValueMap< float >
reco::isodeposit::Direction
Definition: IsoDepositDirection.h:19
ZMuMu_MCanalyzer::dRTrk_
double dRTrk_
Definition: ZMuMu_MCanalyzer.cc:79
Exception
Definition: hltDiff.cc:246
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
EventSetup.h
ZMuMu_MCanalyzer::tracksToken_
EDGetTokenT< CandidateView > tracksToken_
Definition: ZMuMu_MCanalyzer.cc:72
reco::IsoDeposit
Definition: IsoDeposit.h:49
ZMuMu_MCanalyzer::alpha_
double alpha_
Definition: ZMuMu_MCanalyzer.cc:79
edm::RefToBase< Candidate >
reco::Candidate::masterClone
virtual const CandidateBaseRef & masterClone() const =0
reco::Candidate::p4
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
ZMuMu_MCanalyzer::ptThreshold_
double ptThreshold_
Definition: ZMuMu_MCanalyzer.cc:79
AssociationVector.h
OverlapChecker.h
Candidate.h
ZMuMu_MCanalyzer::h_trackProbe_pt
TH1D * h_trackProbe_pt
Definition: ZMuMu_MCanalyzer.cc:87
IsoDepositFwd.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
ZMuMu_MCanalyzer::relativeIsolation_
bool relativeIsolation_
Definition: ZMuMu_MCanalyzer.cc:81
ZMuMu_MCanalyzer::zMuStandAloneMatchMapToken_
EDGetTokenT< GenParticleMatch > zMuStandAloneMatchMapToken_
Definition: ZMuMu_MCanalyzer.cc:68
event
Definition: event.py:1
ZMuMu_MCanalyzer::getParticlePt
float getParticlePt(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
Definition: ZMuMu_MCanalyzer.cc:542
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
ZMuMu_MCanalyzer::overlap_
OverlapChecker overlap_
Definition: ZMuMu_MCanalyzer.cc:84
reco::Candidate::phi
virtual double phi() const =0
momentum azimuthal angle
ZMuMu_MCanalyzer::getParticleP4
Particle::LorentzVector getParticleP4(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
Definition: ZMuMu_MCanalyzer.cc:647
TriggerObjectStandAlone.h
ZMuMu_MCanalyzer::n2GlobalMuonsMatched_passedIso
int n2GlobalMuonsMatched_passedIso
Definition: ZMuMu_MCanalyzer.cc:92
edm::InputTag
Definition: InputTag.h:15
zMuMuMuonUserData.etHcalThreshold
etHcalThreshold
Definition: zMuMuMuonUserData.py:15
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
PATObject.h