CMS 3D CMS Logo

ZMuMu_efficiencyAnalyzer.cc
Go to the documentation of this file.
1 /* \class ZMuMu_efficieyAnalyzer
2  *
3  * author: Davide Piccolo
4  *
5  * ZMuMu efficiency analyzer:
6  * check muon reco efficiencies from MC truth,
7  *
8  */
9 
34 
35 #include "TH1.h"
36 #include "TH2.h"
37 #include "TH3.h"
38 #include <vector>
39 #include <string>
40 
41 using namespace edm;
42 using namespace std;
43 using namespace reco;
44 
46 
48 public:
50 private:
51  void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
52  bool check_ifZmumu(const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
53  float getParticlePt(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
54  float getParticleEta(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
55  float getParticlePhi(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
56  Particle::LorentzVector getParticleP4(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
57  void endJob() override;
58 
69 
70  bool bothMuons_;
71 
72  double etamax_, ptmin_, massMin_, massMax_, isoMax_;
73 
74  // binning of entries array (at moment defined by hand and not in cfg file)
75  unsigned int etaBins;
76  unsigned int ptBins;
77  double etaRange[7];
78  double ptRange[5];
79 
80  reco::CandidateBaseRef globalMuonCandRef_, trackMuonCandRef_, standAloneMuonCandRef_;
82 
83  // general histograms
84  TH1D *h_zmm_mass, *h_zmm2HLT_mass;
85  TH1D *h_zmm1HLTplus_mass, *h_zmmNotIsoplus_mass, *h_zmsplus_mass, *h_zmtplus_mass;
86  TH1D *h_zmm1HLTminus_mass, *h_zmmNotIsominus_mass, *h_zmsminus_mass, *h_zmtminus_mass;
87 
88  // global counters
89  int nGlobalMuonsMatched_passed; // total number of global muons MC matched and passing cuts (and triggered)
90 
91  vector<TH1D *> hmumu2HLTplus_eta, hmumu1HLTplus_eta, hmustaplus_eta, hmutrackplus_eta, hmumuNotIsoplus_eta;
92  vector<TH1D *> hmumu2HLTplus_pt, hmumu1HLTplus_pt, hmustaplus_pt, hmutrackplus_pt, hmumuNotIsoplus_pt;
93  vector<TH1D *> hmumu2HLTminus_eta, hmumu1HLTminus_eta, hmustaminus_eta, hmutrackminus_eta, hmumuNotIsominus_eta;
94  vector<TH1D *> hmumu2HLTminus_pt, hmumu1HLTminus_pt, hmustaminus_pt, hmutrackminus_pt, hmumuNotIsominus_pt;
95 };
96 
102 #include <iostream>
103 #include <iterator>
104 #include <cmath>
105 
107  zMuMuToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuMu"))),
108  zMuMuMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuMuMatchMap"))),
109  zMuStandAloneToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuStandAlone"))),
110  zMuStandAloneMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuStandAloneMatchMap"))),
111  zMuTrackToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuTrack"))),
112  zMuTrackMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuTrackMatchMap"))),
113  muonsToken_(consumes<CandidateView>(pset.getParameter<InputTag>("muons"))),
114  tracksToken_(consumes<CandidateView>(pset.getParameter<InputTag>("tracks"))),
115  genParticlesToken_(consumes<GenParticleCollection>(pset.getParameter<InputTag>("genParticles"))),
116  primaryVerticesToken_(consumes<VertexCollection>(pset.getParameter<InputTag>("primaryVertices"))),
117 
118  bothMuons_(pset.getParameter<bool>("bothMuons")),
119 
120  etamax_(pset.getUntrackedParameter<double>("etamax")),
121  ptmin_(pset.getUntrackedParameter<double>("ptmin")),
122  massMin_(pset.getUntrackedParameter<double>("zMassMin")),
123  massMax_(pset.getUntrackedParameter<double>("zMassMax")),
124  isoMax_(pset.getUntrackedParameter<double>("isomax")) {
126 
127  // general histograms
128  h_zmm_mass = fs->make<TH1D>("zmm_mass","zmumu mass",100,0.,200.);
129  h_zmm2HLT_mass = fs->make<TH1D>("zmm2HLT_mass","zmumu 2HLT mass",100,0.,200.);
130  h_zmm1HLTplus_mass = fs->make<TH1D>("zmm1HLTplus_mass","zmumu 1HLT plus mass",100,0.,200.);
131  h_zmmNotIsoplus_mass = fs->make<TH1D>("zmmNotIsoplus_mass","zmumu a least One Not Iso plus mass",100,0.,200.);
132  h_zmsplus_mass = fs->make<TH1D>("zmsplus_mass","zmusta plus mass",100,0.,200.);
133  h_zmtplus_mass = fs->make<TH1D>("zmtplus_mass","zmutrack plus mass",100,0.,200.);
134  h_zmm1HLTminus_mass = fs->make<TH1D>("zmm1HLTminus_mass","zmumu 1HLT minus mass",100,0.,200.);
135  h_zmmNotIsominus_mass = fs->make<TH1D>("zmmNotIsominus_mass","zmumu a least One Not Iso minus mass",100,0.,200.);
136  h_zmsminus_mass = fs->make<TH1D>("zmsminus_mass","zmusta minus mass",100,0.,200.);
137  h_zmtminus_mass = fs->make<TH1D>("zmtminus_mass","zmutrack minus mass",100,0.,200.);
138 
139  cout << "primo" << endl;
140  // creating histograms for each Pt, eta interval
141 
142  TFileDirectory etaDirectory = fs->mkdir("etaIntervals"); // in this directory will be saved all the histos of different eta intervals
143  TFileDirectory ptDirectory = fs->mkdir("ptIntervals"); // in this directory will be saved all the histos of different pt intervals
144 
145  // binning of entries array (at moment defined by hand and not in cfg file)
146  etaBins = 6;
147  ptBins = 4;
148  double etaRangeTmp[7] = {-2.,-1.2,-0.8,0.,0.8,1.2,2.};
149  double ptRangeTmp[5] = {20.,40.,60.,80.,100.};
150  for (unsigned int i=0;i<=etaBins;i++) etaRange[i] = etaRangeTmp[i];
151  for (unsigned int i=0;i<=ptBins;i++) ptRange[i] = ptRangeTmp[i];
152 
153  // eta histograms creation
154  cout << "eta istograms creation " << endl;
155 
156  for (unsigned int i=0;i<etaBins;i++) {
157  cout << " bin eta plus " << i << endl;
158  // muon plus
159  double range0 = etaRange[i];
160  double range1= etaRange[i+1];
161  std::string ap, bp;
162  ap = "zmumu2HLTplus_etaRange" + std::to_string(i);
163  bp = "zmumu2HLT plus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
164  cout << ap << " " << bp << endl;
165  hmumu2HLTplus_eta.push_back(etaDirectory.make<TH1D>(ap.c_str(), bp.c_str(), 200, 0., 200.));
166  ap = "zmumu1HLTplus_etaRange" + std::to_string(i);
167  bp = "zmumu1HLT plus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
168  cout << ap << " " << bp << endl;
169  hmumu1HLTplus_eta.push_back(etaDirectory.make<TH1D>(ap.c_str(), bp.c_str(), 200, 0., 200.));
170  ap = "zmustaplus_etaRange" + std::to_string(i);
171  bp = "zmusta plus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
172  cout << ap << " " << bp << endl;
173  hmustaplus_eta.push_back(etaDirectory.make<TH1D>(ap.c_str(), bp.c_str(), 50, 0., 200.));
174  ap = "zmutrackplus_etaRange" + std::to_string(i);
175  bp = "zmutrack plus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
176  cout << ap << " " << bp << endl;
177  hmutrackplus_eta.push_back(etaDirectory.make<TH1D>(ap.c_str(), bp.c_str(), 100, 0., 200.));
178  ap = "zmumuNotIsoplus_etaRange" + std::to_string(i);
179  bp = "zmumuNotIso plus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
180  cout << ap << " " << bp << endl;
181  hmumuNotIsoplus_eta.push_back(etaDirectory.make<TH1D>(ap.c_str(), bp.c_str(), 100, 0., 200.));
182  // muon minus
183  cout << " bin eta minus " << i << endl;
184  std::string am, bm;
185  am = "zmumu2HLTminus_etaRange" + std::to_string(i);
186  bm = "zmumu2HLT minus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
187  cout << am << " " << bm << endl;
188  hmumu2HLTminus_eta.push_back(etaDirectory.make<TH1D>(am.c_str(), bm.c_str(), 200, 0., 200.));
189  am = "zmumu1HLTminus_etaRange" + std::to_string(i);
190  bm = "zmumu1HLT minus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
191  cout << am << " " << bm << endl;
192  hmumu1HLTminus_eta.push_back(etaDirectory.make<TH1D>(am.c_str(), bm.c_str(), 200, 0., 200.));
193  am = "zmustaminus_etaRange" + std::to_string(i);
194  bm = "zmusta minus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
195  cout << am << " " << bm << endl;
196  hmustaminus_eta.push_back(etaDirectory.make<TH1D>(am.c_str(), bm.c_str(), 50, 0., 200.));
197  am = "zmutrackminus_etaRange" + std::to_string(i);
198  bm = "zmutrack minus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
199  cout << am << " " << bm << endl;
200  hmutrackminus_eta.push_back(etaDirectory.make<TH1D>(am.c_str(), bm.c_str(), 100, 0., 200.));
201  am = "zmumuNotIsominus_etaRange" + std::to_string(i);
202  bm = "zmumuNotIso minus mass eta Range " + std::to_string(range0) + " to " + std::to_string(range1);
203  cout << am << " " << bm << endl;
204  hmumuNotIsominus_eta.push_back(etaDirectory.make<TH1D>(am.c_str(), bm.c_str(), 100, 0., 200.));
205  }
206 
207  // pt histograms creation
208  cout << "pt istograms creation " << endl;
209 
210  for (unsigned int i=0;i<ptBins;i++) {
211  double range0 = ptRange[i];
212  double range1= ptRange[i+1];
213  // muon plus
214  cout << " bin pt plus " << i << endl;
215  std::string ap1, bp1;
216  ap1 = "zmumu2HLTplus_ptRange" + std::to_string(i);
217  bp1 = "zmumu2HLT plus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
218  cout << ap1 << " " << bp1 << endl;
219  hmumu2HLTplus_pt.push_back(ptDirectory.make<TH1D>(ap1.c_str(), bp1.c_str(), 200, 0., 200.));
220  ap1 = "zmumu1HLTplus_ptRange" + std::to_string(i);
221  bp1 = "zmumu1HLT plus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
222  cout << ap1 << " " << bp1 << endl;
223  hmumu1HLTplus_pt.push_back(ptDirectory.make<TH1D>(ap1.c_str(), bp1.c_str(), 200, 0., 200.));
224  ap1 = "zmustaplus_ptRange" + std::to_string(i);
225  bp1 = "zmusta plus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
226  cout << ap1 << " " << bp1 << endl;
227  hmustaplus_pt.push_back(ptDirectory.make<TH1D>(ap1.c_str(), bp1.c_str(), 50, 0., 200.));
228  ap1 = "zmutrackplus_ptRange" + std::to_string(i);
229  bp1 = "zmutrack plus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
230  cout << ap1 << " " << bp1 << endl;
231  hmutrackplus_pt.push_back(ptDirectory.make<TH1D>(ap1.c_str(), bp1.c_str(), 100, 0., 200.));
232  ap1 = "zmumuNotIsoplus_ptRange" + std::to_string(i);
233  bp1 = "zmumuNotIso plus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
234  cout << ap1 << " " << bp1 << endl;
235  hmumuNotIsoplus_pt.push_back(ptDirectory.make<TH1D>(ap1.c_str(), bp1.c_str(), 100, 0., 200.));
236  // muon minus
237  cout << " bin pt minus " << i << endl;
238  std::string am1, bm1;
239  am1 = "zmumu2HLTminus_ptRange" + std::to_string(i);
240  bm1 = "zmumu2HLT minus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
241  cout << am1 << " " << bm1 << endl;
242  hmumu2HLTminus_pt.push_back(ptDirectory.make<TH1D>(am1.c_str(), bm1.c_str(), 200, 0., 200.));
243  am1 = "zmumu1HLTminus_ptRange" + std::to_string(i);
244  bm1 = "zmumu1HLT minus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
245  cout << am1 << " " << bm1 << endl;
246  hmumu1HLTminus_pt.push_back(ptDirectory.make<TH1D>(am1.c_str(), bm1.c_str(), 200, 0., 200.));
247  am1 = "zmustaminus_ptRange" + std::to_string(i);
248  bm1 = "zmusta minus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
249  cout << am1 << " " << bm1 << endl;
250  hmustaminus_pt.push_back(ptDirectory.make<TH1D>(am1.c_str(), bm1.c_str(), 50, 0., 200.));
251  am1 = "zmutrackminus_ptRange" + std::to_string(i);
252  bm1 = "zmutrack minus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
253  cout << am1 << " " << bm1 << endl;
254  hmutrackminus_pt.push_back(ptDirectory.make<TH1D>(am1.c_str(), bm1.c_str(), 100, 0., 200.));
255  am1 = "zmumuNotIsominus_ptRange" + std::to_string(i);
256  bm1 = "zmumuNotIso minus mass pt Range " + std::to_string(range0) + " to " + std::to_string(range1);
257  cout << am1 << " " << bm1 << endl;
258  hmumuNotIsominus_pt.push_back(ptDirectory.make<TH1D>(am1.c_str(), bm1.c_str(), 100, 0., 200.));
259  }
260 
261  // clear global counters
263 }
264 
266  Handle<CandidateView> zMuMu;
267  Handle<GenParticleMatch> zMuMuMatchMap; //Map of Z made by Mu global + Mu global
268  Handle<CandidateView> zMuStandAlone;
269  Handle<GenParticleMatch> zMuStandAloneMatchMap; //Map of Z made by Mu + StandAlone
270  Handle<CandidateView> zMuTrack;
271  Handle<GenParticleMatch> zMuTrackMatchMap; //Map of Z made by Mu + Track
272  Handle<CandidateView> muons; //Collection of Muons
273  Handle<CandidateView> tracks; //Collection of Tracks
274 
275  Handle<GenParticleCollection> genParticles; // Collection of Generatd Particles
276  Handle<VertexCollection> primaryVertices; // Collection of primary Vertices
277 
278  event.getByToken(zMuMuToken_, zMuMu);
279  event.getByToken(zMuStandAloneToken_, zMuStandAlone);
280  event.getByToken(zMuTrackToken_, zMuTrack);
281  event.getByToken(genParticlesToken_, genParticles);
282  event.getByToken(primaryVerticesToken_, primaryVertices);
283  event.getByToken(muonsToken_, muons);
284  event.getByToken(tracksToken_, tracks);
285 
286  /*
287  cout << "********* zMuMu size : " << zMuMu->size() << endl;
288  cout << "********* zMuStandAlone size : " << zMuStandAlone->size() << endl;
289  cout << "********* zMuTrack size : " << zMuTrack->size() << endl;
290  cout << "********* muons size : " << muons->size() << endl;
291  cout << "********* tracks size : " << tracks->size() << endl;
292  cout << "********* vertices size : " << primaryVertices->size() << endl;
293  */
294 
295  // std::cout<<"Run-> "<<event.id().run()<<std::endl;
296  // std::cout<<"Event-> "<<event.id().event()<<std::endl;
297 
298 
299 
300  bool zMuMu_found = false;
301  // loop on ZMuMu
302  if (!zMuMu->empty() ) {
303  for(unsigned int i = 0; i < zMuMu->size(); ++i) { //loop on candidates
304  const Candidate & zMuMuCand = (*zMuMu)[i]; //the candidate
305  CandidateBaseRef zMuMuCandRef = zMuMu->refAt(i);
306 
307  const Candidate * lep0 = zMuMuCand.daughter( 0 );
308  const Candidate * lep1 = zMuMuCand.daughter( 1 );
309  const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
310  double trkiso0 = muonDau0.trackIso();
311  const pat::Muon & muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
312  double trkiso1 = muonDau1.trackIso();
313 
314  // kinemtic variables
315  double pt0 = zMuMuCand.daughter(0)->pt();
316  double pt1 = zMuMuCand.daughter(1)->pt();
317  double eta0 = zMuMuCand.daughter(0)->eta();
318  double eta1 = zMuMuCand.daughter(1)->eta();
319  double charge0 = zMuMuCand.daughter(0)->charge();
320  double charge1 = zMuMuCand.daughter(1)->charge();
321  double mass = zMuMuCand.mass();
322 
323  // HLT match
324  const pat::TriggerObjectStandAloneCollection mu0HLTMatches =
325  muonDau0.triggerObjectMatchesByPath( "HLT_Mu9" );
326  const pat::TriggerObjectStandAloneCollection mu1HLTMatches =
327  muonDau1.triggerObjectMatchesByPath( "HLT_Mu9" );
328 
329  bool trig0found = false;
330  bool trig1found = false;
331  if( !mu0HLTMatches.empty() )
332  trig0found = true;
333  if( !mu1HLTMatches.empty() )
334  trig1found = true;
335 
336  // kinematic selection
337 
338  bool checkOppositeCharge = false;
339  if (charge0 != charge1) checkOppositeCharge = true;
340  if (pt0>ptmin_ && pt1>ptmin_ && abs(eta0)<etamax_ && abs(eta1)<etamax_ && mass>massMin_ && mass<massMax_ && checkOppositeCharge) {
341  if (trig0found || trig1found) { // at least one muon match HLT
342  zMuMu_found = true; // Z found as global-global (so don't check Zms and Zmt)
343  if (trkiso0 < isoMax_ && trkiso1 < isoMax_) { // both muons are isolated
344  if (trig0found && trig1found) {
345 
346  // ******************** category zmm 2 HLT ****************
347 
348  h_zmm2HLT_mass->Fill(mass);
349  h_zmm_mass->Fill(mass);
350 
351  // check the cynematics to fill correct histograms
352 
353  for (unsigned int j=0;j<etaBins;j++) { // eta Bins loop
354  double range0 = etaRange[j];
355  double range1= etaRange[j+1];
356 
357  // eta histograms
358 
359  if (eta0>=range0 && eta0<range1)
360  {
361  if (charge0<0) hmumu2HLTminus_eta[j]->Fill(mass); // mu- in bin eta
362  if (charge0>0) hmumu2HLTplus_eta[j]->Fill(mass); // mu+ in bin eta
363  }
364  if (eta1>=range0 && eta1<range1)
365  {
366  if (charge1<0) hmumu2HLTminus_eta[j]->Fill(mass); // mu- in bin eta
367  if (charge1>0) hmumu2HLTplus_eta[j]->Fill(mass); // mu+ in bin eta
368  }
369  } // end loop etaBins
370 
371  for (unsigned int j=0;j<ptBins;j++) { // pt Bins loop
372  double range0pt = ptRange[j];
373  double range1pt = ptRange[j+1];
374  // pt histograms
375  if (pt0>=range0pt && pt0<range1pt)
376  {
377  if (charge0<0) hmumu2HLTminus_pt[j]->Fill(mass); // mu- in bin eta
378  if (charge0>0) hmumu2HLTplus_pt[j]->Fill(mass); // mu+ in bin eta
379  }
380  if (pt1>=range0pt && pt1<range1pt)
381  {
382  if (charge1<0) hmumu2HLTminus_pt[j]->Fill(mass); // mu- in bin eta
383  if (charge1>0) hmumu2HLTplus_pt[j]->Fill(mass); // mu+ in bin eta
384  }
385  } // end loop ptBins
386 
387  } // ******************* end category zmm 2 HLT ****************
388 
389  if (!trig0found || !trig1found) {
390  // ****************** category zmm 1 HLT ******************
391  h_zmm_mass->Fill(mass);
392  double eta = 9999;
393  double pt = 9999;
394  double charge = 0;
395  if (trig0found) {
396  eta = eta1; // check muon not HLT matched
397  pt = pt1;
398  charge = charge1;
399  } else {
400  eta = eta0;
401  pt =pt0;
402  charge = charge0;
403  }
404  if (charge<0) h_zmm1HLTminus_mass->Fill(mass);
405  if (charge>0) h_zmm1HLTplus_mass->Fill(mass);
406 
407  for (unsigned int j=0;j<etaBins;j++) { // eta Bins loop
408  double range0 = etaRange[j];
409  double range1= etaRange[j+1];
410  // eta histograms fill the bin of the muon not HLT matched
411  if (eta>=range0 && eta<range1)
412  {
413  if (charge<0) hmumu1HLTminus_eta[j]->Fill(mass);
414  if (charge>0) hmumu1HLTplus_eta[j]->Fill(mass);
415  }
416  } // end loop etaBins
417  for (unsigned int j=0;j<ptBins;j++) { // pt Bins loop
418  double range0 = ptRange[j];
419  double range1= ptRange[j+1];
420  // pt histograms
421  if (pt>=range0 && pt<range1)
422  {
423  if (charge<0) hmumu1HLTminus_pt[j]->Fill(mass);
424  if (charge>0) hmumu1HLTplus_pt[j]->Fill(mass);
425  }
426  } // end loop ptBins
427 
428  } // ****************** end category zmm 1 HLT ***************
429 
430  } else { // one or both muons are not isolated
431  // ***************** category zmumuNotIso **************** (per ora non studio iso vs eta e pt da capire meglio)
432 
433  } // end if both muons isolated
434 
435  } // end if at least 1 HLT trigger found
436  } // end if kinematic selection
437 
438 
439  } // end loop on ZMuMu cand
440  } // end if ZMuMu size > 0
441 
442  // loop on ZMuSta
443  bool zMuSta_found = false;
444  if (!zMuMu_found && !zMuStandAlone->empty() ) {
445  event.getByToken(zMuStandAloneMatchMapToken_, zMuStandAloneMatchMap);
446  for(unsigned int i = 0; i < zMuStandAlone->size(); ++i) { //loop on candidates
447  const Candidate & zMuStandAloneCand = (*zMuStandAlone)[i]; //the candidate
448  CandidateBaseRef zMuStandAloneCandRef = zMuStandAlone->refAt(i);
449  GenParticleRef zMuStandAloneMatch = (*zMuStandAloneMatchMap)[zMuStandAloneCandRef];
450 
451  const Candidate * lep0 = zMuStandAloneCand.daughter( 0 );
452  const Candidate * lep1 = zMuStandAloneCand.daughter( 1 );
453  const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
454  double trkiso0 = muonDau0.trackIso();
455  const pat::Muon & muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
456  double trkiso1 = muonDau1.trackIso();
457  double pt0 = zMuStandAloneCand.daughter(0)->pt();
458  double pt1 = zMuStandAloneCand.daughter(1)->pt();
459  double eta0 = zMuStandAloneCand.daughter(0)->eta();
460  double eta1 = zMuStandAloneCand.daughter(1)->eta();
461  double charge0 = zMuStandAloneCand.daughter(0)->charge();
462  double charge1 = zMuStandAloneCand.daughter(1)->charge();
463  double mass = zMuStandAloneCand.mass();
464 
465  // HLT match
466  const pat::TriggerObjectStandAloneCollection mu0HLTMatches =
467  muonDau0.triggerObjectMatchesByPath( "HLT_Mu9" );
468  const pat::TriggerObjectStandAloneCollection mu1HLTMatches =
469  muonDau1.triggerObjectMatchesByPath( "HLT_Mu9" );
470 
471  bool trig0found = false;
472  bool trig1found = false;
473  if( !mu0HLTMatches.empty() )
474  trig0found = true;
475  if( !mu1HLTMatches.empty() )
476  trig1found = true;
477 
478  // check HLT match of Global muon and save eta, pt of second muon (standAlone)
479  bool trigGlbfound = false;
480  double pt =999.;
481  double eta = 999.;
482  double charge = 0;
483  if (muonDau0.isGlobalMuon()) {
484  trigGlbfound = trig0found;
485  pt = pt1;
486  eta = eta1;
487  charge = charge1;
488  }
489  if (muonDau1.isGlobalMuon()) {
490  trigGlbfound = trig1found;
491  pt = pt0;
492  eta = eta0;
493  charge = charge0;
494  }
495 
496  bool checkOppositeCharge = false;
497  if (charge0 != charge1) checkOppositeCharge = true;
498 
499  if (checkOppositeCharge && trigGlbfound && pt0>ptmin_ && pt1>ptmin_ && abs(eta0)<etamax_ && abs(eta1)<etamax_ && mass>massMin_ && mass<massMax_ && trkiso0<isoMax_ && trkiso1<isoMax_ ) { // global mu match HLT + kinematic cuts + opposite charge
500 
501  if (charge<0) h_zmsminus_mass->Fill(mass);
502  if (charge>0) h_zmsplus_mass->Fill(mass);
503 
504  for (unsigned int j=0;j<etaBins;j++) { // eta Bins loop
505  double range0 = etaRange[j];
506  double range1= etaRange[j+1];
507  // eta histograms
508  if (eta>=range0 && eta<range1) {
509  if (charge<0) hmustaminus_eta[j]->Fill(mass);
510  if (charge>0) hmustaplus_eta[j]->Fill(mass);
511  }
512  } // end loop etaBins
513  for (unsigned int j=0;j<ptBins;j++) { // pt Bins loop
514  double range0 = ptRange[j];
515  double range1= ptRange[j+1];
516  // pt histograms
517  if (pt>=range0 && pt<range1) {
518  if (charge<0) hmustaminus_pt[j]->Fill(mass);
519  if (charge>0) hmustaplus_pt[j]->Fill(mass);
520  }
521  } // end loop ptBins
522 
523  } // end if trigGlbfound + kinecuts + OppostieCharge
524  } // end loop on ZMuStandAlone cand
525  } // end if ZMuStandAlone size > 0
526 
527 
528  // loop on ZMuTrack
529  // bool zMuTrack_found = false;
530  if (!zMuMu_found && !zMuSta_found && !zMuTrack->empty() ) {
531  event.getByToken(zMuTrackMatchMapToken_, zMuTrackMatchMap);
532  for(unsigned int i = 0; i < zMuTrack->size(); ++i) { //loop on candidates
533  const Candidate & zMuTrackCand = (*zMuTrack)[i]; //the candidate
534  CandidateBaseRef zMuTrackCandRef = zMuTrack->refAt(i);
535  const Candidate * lep0 = zMuTrackCand.daughter( 0 );
536  const Candidate * lep1 = zMuTrackCand.daughter( 1 );
537  const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
538  double trkiso0 = muonDau0.trackIso();
539  const pat::GenericParticle & trackDau1 = dynamic_cast<const pat::GenericParticle &>(*lep1->masterClone());
540  double trkiso1 = trackDau1.trackIso();
541  double pt0 = zMuTrackCand.daughter(0)->pt();
542  double pt1 = zMuTrackCand.daughter(1)->pt();
543  double eta0 = zMuTrackCand.daughter(0)->eta();
544  double eta1 = zMuTrackCand.daughter(1)->eta();
545  double charge0 = zMuTrackCand.daughter(0)->charge();
546  double charge1 = zMuTrackCand.daughter(1)->charge();
547  double mass = zMuTrackCand.mass();
548 
549  // HLT match (check just dau0 the global)
550  const pat::TriggerObjectStandAloneCollection mu0HLTMatches =
551  muonDau0.triggerObjectMatchesByPath( "HLT_Mu9" );
552 
553  bool trig0found = false;
554  if( !mu0HLTMatches.empty() )
555  trig0found = true;
556 
557  bool checkOppositeCharge = false;
558  if (charge0 != charge1) checkOppositeCharge = true;
559 
560  if (checkOppositeCharge && trig0found && pt0>ptmin_ && pt1>ptmin_ && abs(eta0)<etamax_ && abs(eta1)<etamax_ && mass>massMin_ && mass<massMax_ && trkiso0<isoMax_ && trkiso1<isoMax_ ) { // global mu match HLT + kinematic cuts + opposite charge
561 
562  if (charge1<0) h_zmtminus_mass->Fill(mass);
563  if (charge1>0) h_zmtplus_mass->Fill(mass);
564 
565  for (unsigned int j=0;j<etaBins;j++) { // eta Bins loop
566  double range0 = etaRange[j];
567  double range1= etaRange[j+1];
568  // eta histograms
569  if (eta1>=range0 && eta1<range1) {
570  if (charge1<0) hmutrackminus_eta[j]->Fill(mass); // just check muon1 (mu0 is global by definition)
571  if (charge1>0) hmutrackplus_eta[j]->Fill(mass); // just check muon1 (mu0 is global by definition)
572  }
573  } // end loop etaBins
574  for (unsigned int j=0;j<ptBins;j++) { // pt Bins loop
575  double range0 = ptRange[j];
576  double range1= ptRange[j+1];
577  // pt histograms
578  if (pt1>=range0 && pt1<range1) {
579  if (charge1<0) hmutrackminus_pt[j]->Fill(mass); // just check muon1 (mu0 is global by definition)
580  if (charge1>0) hmutrackplus_pt[j]->Fill(mass); // just check muon1 (mu0 is global by definition)
581  }
582  } // end loop ptBins
583 
584  } // end if trig0found
585 
586 
587  } // end loop on ZMuTrack cand
588  } // end if ZMuTrack size > 0
589 
590 } // end analyze
591 
592 bool ZMuMu_efficiencyAnalyzer::check_ifZmumu(const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
593 {
594  int partId0 = dauGen0->pdgId();
595  int partId1 = dauGen1->pdgId();
596  int partId2 = dauGen2->pdgId();
597  bool muplusFound=false;
598  bool muminusFound=false;
599  bool ZFound=false;
600  if (partId0==13 || partId1==13 || partId2==13) muminusFound=true;
601  if (partId0==-13 || partId1==-13 || partId2==-13) muplusFound=true;
602  if (partId0==23 || partId1==23 || partId2==23) ZFound=true;
603  return (muplusFound && muminusFound && ZFound);
604 }
605 
606 float ZMuMu_efficiencyAnalyzer::getParticlePt(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
607 {
608  int partId0 = dauGen0->pdgId();
609  int partId1 = dauGen1->pdgId();
610  int partId2 = dauGen2->pdgId();
611  float ptpart=0.;
612  if (partId0 == ipart) {
613  for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
614  const Candidate * dauMuGen = dauGen0->daughter(k);
615  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
616  ptpart = dauMuGen->pt();
617  }
618  }
619  }
620  if (partId1 == ipart) {
621  for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
622  const Candidate * dauMuGen = dauGen1->daughter(k);
623  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
624  ptpart = dauMuGen->pt();
625  }
626  }
627  }
628  if (partId2 == ipart) {
629  for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
630  const Candidate * dauMuGen = dauGen2->daughter(k);
631  if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
632  ptpart = dauMuGen->pt();
633  }
634  }
635  }
636  return ptpart;
637 }
638 
639 float ZMuMu_efficiencyAnalyzer::getParticleEta(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
640 {
641  int partId0 = dauGen0->pdgId();
642  int partId1 = dauGen1->pdgId();
643  int partId2 = dauGen2->pdgId();
644  float etapart=0.;
645  if (partId0 == ipart) {
646  for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
647  const Candidate * dauMuGen = dauGen0->daughter(k);
648  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
649  etapart = dauMuGen->eta();
650  }
651  }
652  }
653  if (partId1 == ipart) {
654  for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
655  const Candidate * dauMuGen = dauGen1->daughter(k);
656  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
657  etapart = dauMuGen->eta();
658  }
659  }
660  }
661  if (partId2 == ipart) {
662  for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
663  const Candidate * dauMuGen = dauGen2->daughter(k);
664  if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
665  etapart = dauMuGen->eta();
666  }
667  }
668  }
669  return etapart;
670 }
671 
672 float ZMuMu_efficiencyAnalyzer::getParticlePhi(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
673 {
674  int partId0 = dauGen0->pdgId();
675  int partId1 = dauGen1->pdgId();
676  int partId2 = dauGen2->pdgId();
677  float phipart=0.;
678  if (partId0 == ipart) {
679  for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
680  const Candidate * dauMuGen = dauGen0->daughter(k);
681  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
682  phipart = dauMuGen->phi();
683  }
684  }
685  }
686  if (partId1 == ipart) {
687  for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
688  const Candidate * dauMuGen = dauGen1->daughter(k);
689  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
690  phipart = dauMuGen->phi();
691  }
692  }
693  }
694  if (partId2 == ipart) {
695  for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
696  const Candidate * dauMuGen = dauGen2->daughter(k);
697  if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
698  phipart = dauMuGen->phi();
699  }
700  }
701  }
702  return phipart;
703 }
704 
705 Particle::LorentzVector ZMuMu_efficiencyAnalyzer::getParticleP4(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
706 {
707  int partId0 = dauGen0->pdgId();
708  int partId1 = dauGen1->pdgId();
709  int partId2 = dauGen2->pdgId();
710  Particle::LorentzVector p4part(0.,0.,0.,0.);
711  if (partId0 == ipart) {
712  for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
713  const Candidate * dauMuGen = dauGen0->daughter(k);
714  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
715  p4part = dauMuGen->p4();
716  }
717  }
718  }
719  if (partId1 == ipart) {
720  for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
721  const Candidate * dauMuGen = dauGen1->daughter(k);
722  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
723  p4part = dauMuGen->p4();
724  }
725  }
726  }
727  if (partId2 == ipart) {
728  for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
729  const Candidate * dauMuGen = dauGen2->daughter(k);
730  if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
731  p4part = dauMuGen->p4();
732  }
733  }
734  }
735  return p4part;
736 }
737 
738 
739 
741 
742 
743 
744 }
745 
747 
749 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
EDGetTokenT< GenParticleMatch > zMuMuMatchMapToken_
reco::CandidateBaseRef trackMuonCandRef_
EDGetTokenT< CandidateView > muonsToken_
def analyze(function, filename, filter=None)
Definition: Profiling.py:11
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
EDGetTokenT< GenParticleMatch > zMuStandAloneMatchMapToken_
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
EDGetTokenT< GenParticleCollection > genParticlesToken_
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
size_type size() const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
EDGetTokenT< CandidateView > tracksToken_
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
float trackIso() const
float trackIso() const
Definition: Muon.h:171
EDGetTokenT< GenParticleMatch > zMuTrackMatchMapToken_
bool check_ifZmumu(const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
EDGetTokenT< CandidateView > zMuTrackToken_
float getParticlePhi(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
RefToBase< value_type > refAt(size_type i) const
virtual int status() const =0
status word
edm::ValueMap< float > IsolationCollection
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
bool isGlobalMuon() const override
Definition: Muon.h:265
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
virtual int pdgId() const =0
PDG identifier.
bool empty() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T * make(const Args &...args) const
make new ROOT object
const TriggerObjectStandAloneCollection triggerObjectMatchesByPath(const std::string &namePath, const bool pathLastFilterAccepted=false, const bool pathL3FilterAccepted=true) const
Definition: PATObject.h:612
EDGetTokenT< CandidateView > zMuStandAloneToken_
int k[5][pyjets_maxn]
float getParticleEta(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
virtual const CandidateBaseRef & masterClone() const =0
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
primaryVertices
Definition: jets_cff.py:100
virtual double pt() const =0
transverse momentum
virtual double mass() const =0
mass
Particle::LorentzVector getParticleP4(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
virtual int charge() const =0
electric charge
EDGetTokenT< VertexCollection > primaryVerticesToken_
fixed size matrix
HLT enums.
lep1
print &#39;MRbb(1b)&#39;,event.mr_bb
EDGetTokenT< CandidateView > zMuMuToken_
float getParticlePt(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
virtual size_type numberOfDaughters() const =0
number of daughters
virtual double phi() const =0
momentum azimuthal angle
Analysis-level muon class.
Definition: Muon.h:50
ZMuMu_efficiencyAnalyzer(const edm::ParameterSet &pset)
Definition: event.py:1
math::PtEtaPhiELorentzVectorF LorentzVector