CMS 3D CMS Logo

ZMuMu_vtxAnalyzer.cc
Go to the documentation of this file.
1 /* \class ZMuMu_vtxAnalyzer
2  *
3  * author: Davide Piccolo
4  *
5  * ZMuMu Vtx analyzer:
6  * check muon vtx distributions,
7  *
8  */
9 
34 #include "TH1.h"
35 #include "TH2.h"
36 #include "TH3.h"
37 #include <vector>
38 
39 using namespace std;
40 using namespace reco;
41 using namespace edm;
42 
44 
46 public:
48 
49 private:
50  void analyze(const edm::Event &event, const edm::EventSetup &setup) override;
51  bool check_ifZmumu(const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2);
52  float getParticlePt(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2);
53  float getParticleEta(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2);
54  float getParticlePhi(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2);
55  Particle::LorentzVector getParticleP4(const int ipart,
56  const Candidate *dauGen0,
57  const Candidate *dauGen1,
58  const Candidate *dauGen2);
59  void endJob() override;
60 
71 
72  bool bothMuons_;
73 
74  double etamax_, ptmin_, massMin_, massMax_, isoMax_;
75 
76  reco::CandidateBaseRef globalMuonCandRef_, trackMuonCandRef_, standAloneMuonCandRef_;
78 
79  // general histograms
80 
81  // vertex studies
82  // ... zmumu No cuts
83  TH1D *h_muon_vz, *h_dimuon_vz, *h_muon_d0signed;
84  TH1D *h_muon_vz_respectToPV, *h_muon_d0signed_respectToPV;
85  // ... cynematic cuts zmumu
86  TH1D *h_zmumuSele_muon_vz, *h_zmumuSele_dimuon_vz, *h_zmumuSele_muon_d0signed;
87  TH1D *h_zmumuSele_muon_vz_respectToPV, *h_zmumuSele_muon_d0signed_respectToPV;
88  // ... cynematic cuts zmumuNotIso
90  TH1D *h_zmumuNotIsoSele_muonIso_vz, *h_zmumuNotIsoSele_muonIso_d0signed;
91  TH1D *h_zmumuNotIsoSele_muonIso_vz_respectToPV, *h_zmumuNotIsoSele_muonIso_d0signed_respectToPV;
92  TH1D *h_zmumuNotIsoSele_muonNotIso_vz, *h_zmumuNotIsoSele_muonNotIso_d0signed;
93  TH1D *h_zmumuNotIsoSele_muonNotIso_vz_respectToPV, *h_zmumuNotIsoSele_muonNotIso_d0signed_respectToPV;
94  // ... cynematic cuts zmutrack
95  TH1D *h_zmutrackSele_muon_vz, *h_zmutrackSele_muon_d0signed;
96  TH1D *h_zmutrackSele_muon_vz_respectToPV, *h_zmutrackSele_muon_d0signed_respectToPV;
97  TH1D *h_zmutrackSele_track_vz, *h_zmutrackSele_track_d0signed;
98  TH1D *h_zmutrackSele_track_vz_respectToPV, *h_zmutrackSele_track_d0signed_respectToPV;
99  // ... cynematic cuts zmusta
100  TH1D *h_zmustaSele_muon_vz, *h_zmustaSele_muon_d0signed;
101  TH1D *h_zmustaSele_muon_vz_respectToPV, *h_zmustaSele_muon_d0signed_respectToPV;
102  TH1D *h_zmustaSele_sta_vz, *h_zmustaSele_sta_d0signed;
103  TH1D *h_zmustaSele_sta_vz_respectToPV, *h_zmustaSele_sta_d0signed_respectToPV;
104 
105  // global counters
106 };
107 
113 #include <iostream>
114 #include <iterator>
115 #include <cmath>
116 
118  : zMuMuToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuMu"))),
119  zMuMuMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuMuMatchMap"))),
120  zMuStandAloneToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuStandAlone"))),
121  zMuStandAloneMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuStandAloneMatchMap"))),
122  zMuTrackToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuTrack"))),
123  zMuTrackMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuTrackMatchMap"))),
124  muonsToken_(consumes<CandidateView>(pset.getParameter<InputTag>("muons"))),
125  tracksToken_(consumes<CandidateView>(pset.getParameter<InputTag>("tracks"))),
126  genParticlesToken_(consumes<GenParticleCollection>(pset.getParameter<InputTag>("genParticles"))),
127  primaryVerticesToken_(consumes<VertexCollection>(pset.getParameter<InputTag>("primaryVertices"))),
128 
129  bothMuons_(pset.getParameter<bool>("bothMuons")),
130 
131  etamax_(pset.getUntrackedParameter<double>("etamax")),
132  ptmin_(pset.getUntrackedParameter<double>("ptmin")),
133  massMin_(pset.getUntrackedParameter<double>("zMassMin")),
134  massMax_(pset.getUntrackedParameter<double>("zMassMax")),
135  isoMax_(pset.getUntrackedParameter<double>("isomax")) {
137 
138  // general histograms
139 
140  // vertex histograms
141  // ... zmumu no Cuts
142  h_muon_vz = fs->make<TH1D>("muonVz", "z vertex of muons", 50, -20., 20.);
143  h_muon_d0signed = fs->make<TH1D>("muonD0signed", "d0 vertex of muons", 50, -.1, .1);
144  h_dimuon_vz = fs->make<TH1D>("dimuonVz", "z vertex of dimuon", 50, -20., 20.);
146  fs->make<TH1D>("muonVz_respectToPV", "z vertex of muons respect to PrimaryVertex", 50, -.05, .05);
148  fs->make<TH1D>("muonD0signed_respectToPV", "d0 vertex of muons respect to PrimaryVertex", 50, -.05, .05);
149  // ... zmumu cynematic Cuts
150  h_zmumuSele_muon_vz = fs->make<TH1D>("zmumuSele_muonVz", "z vertex of muons (zmumu sele)", 50, -20., 20.);
151  h_zmumuSele_muon_d0signed = fs->make<TH1D>("zmumuSele_muonD0signed", "d0 vertex of muons (zmumu sele)", 50, -.1, .1);
152  h_zmumuSele_dimuon_vz = fs->make<TH1D>("zmumuSele_dimuonVz", "z vertex of dimuon (zmumu sele)", 50, -20., 20.);
154  "zmumuSele_muonVz_respectToPV", "z vertex of muons respect to PrimaryVertex (zmumu sele)", 50, -.05, .05);
156  "zmumuSele_muonD0signed_respectToPV", "d0 vertex of muons respect to PrimaryVertex (zmumu sele)", 50, -.05, .05);
157  // ... zmumuNotIso cynematic Cuts
159  fs->make<TH1D>("zmumuNotIsoSele_dimuonVz", "z vertex of dimuon (zmumuNotIso sele)", 50, -20., 20.);
161  fs->make<TH1D>("zmumuNotIsoSele_muonIsoVz", "z vertex of muons (zmumuNotIso sele muon Iso)", 50, -20., 20.);
163  fs->make<TH1D>("zmumuNotIsoSele_muonIsoD0signed", "d0 vertex of muons (zmumuNotIso sele muon Iso)", 50, -.1, .1);
165  fs->make<TH1D>("zmumuNotIsoSele_muonIsoVz_respectToPV",
166  "z vertex of muons respect to PrimaryVertex (zmumuNotIso sele muon Iso)",
167  50,
168  -.05,
169  .05);
171  fs->make<TH1D>("zmumuNotIsoSele_muonIsoD0signed_respectToPV",
172  "d0 vertex of muons respect to PrimaryVertex (zmumuNotIso sele muon Iso)",
173  50,
174  -.05,
175  .05);
177  "zmumuNotIsoSele_muonNotIsoVz", "z vertex of muons (zmumuNotIso sele muon Not Iso)", 50, -20., 20.);
179  "zmumuNotIsoSele_muonNotIsoD0signed", "d0 vertex of muons (zmumuNotIso sele muon Not Iso)", 50, -.1, .1);
181  fs->make<TH1D>("zmumuNotIsoSele_muonNotIsoVz_respectToPV",
182  "z vertex of muons respect to PrimaryVertex (zmumuNotIso sele muon Not Iso)",
183  50,
184  -.05,
185  .05);
187  fs->make<TH1D>("zmumuNotIsoSele_muonNotIsoD0signed_respectToPV",
188  "d0 vertex of muons respect to PrimaryVertex (zmumuNotIso sele muon Not Iso)",
189  50,
190  -.05,
191  .05);
192  // ... zmutrack cynematic Cuts
193  h_zmutrackSele_muon_vz = fs->make<TH1D>("zmutrackSele_muonVz", "z vertex of muon (zmutrack sele)", 50, -20., 20.);
195  fs->make<TH1D>("zmutrackSele_muonD0signed", "d0 vertex of muon (zmutrack sele)", 50, -.1, .1);
197  "zmutrackSele_muonVz_respectToPV", "z vertex of muon respect to PV (zmutrack sele)", 50, -.05, .05);
199  "zmutrackSele_muonD0signed_respectToPV", "d0 vertex of muon respect to PV (zmutrack sele)", 50, -.1, .1);
200  h_zmutrackSele_track_vz = fs->make<TH1D>("zmutrackSele_trackVz", "z vertex of track (zmutrack sele)", 50, -20., 20.);
202  fs->make<TH1D>("zmutrackSele_trackD0signed", "d0 vertex of track (zmutrack sele)", 50, -.1, .1);
204  "zmutrackSele_trackVz_respectToPV", "z vertex of track respect to PV (zmutrack sele)", 50, -.05, .05);
206  "zmutrackSele_trackD0signed_respectToPV", "d0 vertex of track respect to PV (zmutrack sele)", 50, -.1, .1);
207  // ... zmusta cynematic Cuts
208  h_zmustaSele_muon_vz = fs->make<TH1D>("zmustaSele_muonVz", "z vertex of muon (zmusta sele)", 50, -20., 20.);
210  fs->make<TH1D>("zmustaSele_muonD0signed", "d0 vertex of muon (zmusta sele)", 50, -.1, .1);
212  fs->make<TH1D>("zmustaSele_muonVz_respectToPV", "z vertex of muon respect to PV (zmusta sele)", 50, -.05, .05);
214  "zmustaSele_muonD0signed_respectToPV", "d0 vertex of muon respect to PV (zmusta sele)", 50, -.1, .1);
215  h_zmustaSele_sta_vz = fs->make<TH1D>("zmustaSele_staVz", "z vertex of sta (zmusta sele)", 50, -20., 20.);
216  h_zmustaSele_sta_d0signed = fs->make<TH1D>("zmustaSele_staD0signed", "d0 vertex of sta (zmusta sele)", 50, -.1, .1);
218  fs->make<TH1D>("zmustaSele_staVz_respectToPV", "z vertex of sta respect to PV (zmusta sele)", 50, -.05, .05);
220  fs->make<TH1D>("zmustaSele_staD0signed_respectToPV", "d0 vertex of sta respect to PV (zmusta sele)", 50, -.1, .1);
221 }
222 
225  Handle<GenParticleMatch> zMuMuMatchMap; //Map of Z made by Mu global + Mu global
226  Handle<CandidateView> zMuStandAlone;
227  Handle<GenParticleMatch> zMuStandAloneMatchMap; //Map of Z made by Mu + StandAlone
228  Handle<CandidateView> zMuTrack;
229  Handle<GenParticleMatch> zMuTrackMatchMap; //Map of Z made by Mu + Track
230  Handle<CandidateView> muons; //Collection of Muons
231  Handle<CandidateView> tracks; //Collection of Tracks
232 
233  Handle<GenParticleCollection> genParticles; // Collection of Generatd Particles
234  Handle<reco::VertexCollection> primaryVertices; // Collection of primary Vertices
235 
236  event.getByToken(zMuMuToken_, zMuMu);
237  event.getByToken(zMuStandAloneToken_, zMuStandAlone);
238  event.getByToken(zMuTrackToken_, zMuTrack);
239  event.getByToken(genParticlesToken_, genParticles);
240  event.getByToken(primaryVerticesToken_, primaryVertices);
241  event.getByToken(muonsToken_, muons);
242  event.getByToken(tracksToken_, tracks);
243 
244  /*
245  cout << "********* zMuMu size : " << zMuMu->size() << endl;
246  cout << "********* zMuStandAlone size : " << zMuStandAlone->size() << endl;
247  cout << "********* zMuTrack size : " << zMuTrack->size() << endl;
248  cout << "********* muons size : " << muons->size() << endl;
249  cout << "********* tracks size : " << tracks->size() << endl;
250  cout << "********* vertices size : " << primaryVertices->size() << endl;
251  */
252 
253  // std::cout<<"Run-> "<<event.id().run()<<std::endl;
254  // std::cout<<"Event-> "<<event.id().event()<<std::endl;
255 
256  bool zMuMu_found = false;
257 
258  // loop on ZMuMu
259  if (!zMuMu->empty()) {
260  event.getByToken(zMuMuMatchMapToken_, zMuMuMatchMap);
261  for (unsigned int i = 0; i < zMuMu->size(); ++i) { //loop on candidates
262  const Candidate &zMuMuCand = (*zMuMu)[i]; //the candidate
263  CandidateBaseRef zMuMuCandRef = zMuMu->refAt(i);
264 
265  const Candidate *lep0 = zMuMuCand.daughter(0);
266  const Candidate *lep1 = zMuMuCand.daughter(1);
267  const pat::Muon &muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
268  double trkiso0 = muonDau0.trackIso();
269  const pat::Muon &muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
270  double trkiso1 = muonDau1.trackIso();
271 
272  // vertex
273  h_muon_vz->Fill(muonDau0.vz());
274  h_muon_vz->Fill(muonDau1.vz());
275  h_dimuon_vz->Fill((muonDau0.vz() + muonDau1.vz()) / 2.);
276 
277  TrackRef mu0TrkRef = muonDau0.track();
278  float d0signed_mu0 = (*mu0TrkRef).dxy();
279  float d0signed_mu0_respectToPV = (*mu0TrkRef).dxy(primaryVertices->begin()->position());
280  float vz_mu0_respectToPV = (*mu0TrkRef).dz(primaryVertices->begin()->position());
281 
282  TrackRef mu1TrkRef = muonDau1.track();
283  float d0signed_mu1 = (*mu1TrkRef).dxy();
284  float d0signed_mu1_respectToPV = (*mu1TrkRef).dxy(primaryVertices->begin()->position());
285  float vz_mu1_respectToPV = (*mu1TrkRef).dz(primaryVertices->begin()->position());
286  h_muon_d0signed->Fill(d0signed_mu0);
287  h_muon_d0signed->Fill(d0signed_mu1);
288  h_muon_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV);
289  h_muon_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV);
290  h_muon_vz_respectToPV->Fill(vz_mu0_respectToPV);
291  h_muon_vz_respectToPV->Fill(vz_mu1_respectToPV);
292 
293  // eta , pt distributions
294  double pt0 = zMuMuCand.daughter(0)->pt();
295  double pt1 = zMuMuCand.daughter(1)->pt();
296  double eta0 = zMuMuCand.daughter(0)->eta();
297  double eta1 = zMuMuCand.daughter(1)->eta();
298  double mass = zMuMuCand.mass();
299 
300  // HLT match
301  const pat::TriggerObjectStandAloneCollection mu0HLTMatches = muonDau0.triggerObjectMatchesByPath("HLT_Mu9");
302  const pat::TriggerObjectStandAloneCollection mu1HLTMatches = muonDau1.triggerObjectMatchesByPath("HLT_Mu9");
303 
304  bool trig0found = false;
305  bool trig1found = false;
306  if (!mu0HLTMatches.empty())
307  trig0found = true;
308  if (!mu1HLTMatches.empty())
309  trig1found = true;
310 
311  // cynematical selection
312  if ((trig0found || trig1found) && pt0 > ptmin_ && pt1 > ptmin_ && abs(eta0) < etamax_ && abs(eta1) < etamax_ &&
313  mass > massMin_) {
314  if (trkiso0 < isoMax_ && trkiso1 < isoMax_) { // zmumu both isolated
315  h_zmumuSele_muon_vz->Fill(muonDau0.vz());
316  h_zmumuSele_muon_vz->Fill(muonDau1.vz());
317  h_zmumuSele_dimuon_vz->Fill((muonDau0.vz() + muonDau1.vz()) / 2.);
318  h_zmumuSele_muon_d0signed->Fill(d0signed_mu0);
319  h_zmumuSele_muon_d0signed->Fill(d0signed_mu1);
320  h_zmumuSele_muon_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV);
321  h_zmumuSele_muon_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV);
322  h_zmumuSele_muon_vz_respectToPV->Fill(vz_mu0_respectToPV);
323  h_zmumuSele_muon_vz_respectToPV->Fill(vz_mu1_respectToPV);
324  }
325  if (trkiso0 >= isoMax_ && trkiso1 < isoMax_) { // zmumu just muon1 isolated
326  h_zmumuNotIsoSele_muonNotIso_vz->Fill(muonDau0.vz());
327  h_zmumuNotIsoSele_muonIso_vz->Fill(muonDau1.vz());
328  h_zmumuNotIsoSele_dimuon_vz->Fill((muonDau0.vz() + muonDau1.vz()) / 2.);
329  h_zmumuNotIsoSele_muonNotIso_d0signed->Fill(d0signed_mu0);
330  h_zmumuNotIsoSele_muonIso_d0signed->Fill(d0signed_mu1);
331  h_zmumuNotIsoSele_muonNotIso_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV);
332  h_zmumuNotIsoSele_muonIso_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV);
333  h_zmumuNotIsoSele_muonNotIso_vz_respectToPV->Fill(vz_mu0_respectToPV);
334  h_zmumuNotIsoSele_muonIso_vz_respectToPV->Fill(vz_mu1_respectToPV);
335  }
336  if (trkiso0 < isoMax_ && trkiso1 >= isoMax_) { // zmumu just muon0 isolated
337  h_zmumuNotIsoSele_muonNotIso_vz->Fill(muonDau1.vz());
338  h_zmumuNotIsoSele_muonIso_vz->Fill(muonDau0.vz());
339  h_zmumuNotIsoSele_dimuon_vz->Fill((muonDau1.vz() + muonDau1.vz()) / 2.);
340  h_zmumuNotIsoSele_muonNotIso_d0signed->Fill(d0signed_mu1);
341  h_zmumuNotIsoSele_muonIso_d0signed->Fill(d0signed_mu0);
342  h_zmumuNotIsoSele_muonNotIso_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV);
343  h_zmumuNotIsoSele_muonIso_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV);
344  h_zmumuNotIsoSele_muonNotIso_vz_respectToPV->Fill(vz_mu1_respectToPV);
345  h_zmumuNotIsoSele_muonIso_vz_respectToPV->Fill(vz_mu0_respectToPV);
346  }
347  }
348  } // end loop on ZMuMu cand
349  } // end if ZMuMu size > 0
350 
351  // loop on ZMuSta
352  bool zMuSta_found = false;
353  if (!zMuMu_found && !zMuStandAlone->empty()) {
354  event.getByToken(zMuStandAloneMatchMapToken_, zMuStandAloneMatchMap);
355  for (unsigned int i = 0; i < zMuStandAlone->size(); ++i) { //loop on candidates
356  const Candidate &zMuStandAloneCand = (*zMuStandAlone)[i]; //the candidate
357  CandidateBaseRef zMuStandAloneCandRef = zMuStandAlone->refAt(i);
358  GenParticleRef zMuStandAloneMatch = (*zMuStandAloneMatchMap)[zMuStandAloneCandRef];
359 
360  const Candidate *lep0 = zMuStandAloneCand.daughter(0);
361  const Candidate *lep1 = zMuStandAloneCand.daughter(1);
362  const pat::Muon &muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
363  double trkiso0 = muonDau0.trackIso();
364  const pat::Muon &muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
365  double trkiso1 = muonDau1.trackIso();
366 
367  // vertex
368 
369  TrackRef mu0TrkRef = muonDau0.track();
370  float d0signed_mu0 = (*mu0TrkRef).dxy();
371  float d0signed_mu0_respectToPV = (*mu0TrkRef).dxy(primaryVertices->begin()->position());
372  float vz_mu0_respectToPV = (*mu0TrkRef).dz(primaryVertices->begin()->position());
373 
374  TrackRef mu1TrkRef = muonDau1.track();
375  float d0signed_mu1 = (*mu1TrkRef).dxy();
376  float d0signed_mu1_respectToPV = (*mu1TrkRef).dxy(primaryVertices->begin()->position());
377  float vz_mu1_respectToPV = (*mu1TrkRef).dz(primaryVertices->begin()->position());
378 
379  double pt0 = zMuStandAloneCand.daughter(0)->pt();
380  double pt1 = zMuStandAloneCand.daughter(1)->pt();
381  double eta0 = zMuStandAloneCand.daughter(0)->eta();
382  double eta1 = zMuStandAloneCand.daughter(1)->eta();
383  double mass = zMuStandAloneCand.mass();
384 
385  // HLT match
386  const pat::TriggerObjectStandAloneCollection mu0HLTMatches = muonDau0.triggerObjectMatchesByPath("HLT_Mu9");
387  const pat::TriggerObjectStandAloneCollection mu1HLTMatches = muonDau1.triggerObjectMatchesByPath("HLT_Mu9");
388 
389  bool trig0found = false;
390  bool trig1found = false;
391  if (!mu0HLTMatches.empty())
392  trig0found = true;
393  if (!mu1HLTMatches.empty())
394  trig1found = true;
395 
396  // check the global muon ... trigger is required just on global muon
397  bool trigfound = false;
398  if (muonDau0.isGlobalMuon())
399  trigfound = trig0found;
400  if (muonDau1.isGlobalMuon())
401  trigfound = trig1found;
402 
403  // cynematical selection
404  if (trigfound && pt0 > ptmin_ && pt1 > ptmin_ && abs(eta0) < etamax_ && abs(eta1) < etamax_ && mass > massMin_ &&
405  trkiso0 < isoMax_ && trkiso1 < isoMax_) {
406  zMuSta_found = true;
407  h_zmustaSele_muon_vz->Fill(muonDau0.vz(), 1.); // muon vz
408  h_zmustaSele_sta_vz->Fill(muonDau1.vz(), 1.); // sta vz
409  h_zmustaSele_muon_d0signed->Fill(d0signed_mu0, 1.); // muon d0
410  h_zmustaSele_sta_d0signed->Fill(d0signed_mu1, 1.); // sta d0
411  h_zmustaSele_muon_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV, 1.); // muon d0 respect PV
412  h_zmustaSele_sta_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV, 1.); // sta d0 respect PV
413  h_zmustaSele_muon_vz_respectToPV->Fill(vz_mu0_respectToPV, 1.); // muon vz respect PV
414  h_zmustaSele_sta_vz_respectToPV->Fill(vz_mu1_respectToPV, 1.); // sta vz respect PV
415  }
416 
417  } // end loop on ZMuStandAlone cand
418  } // end if ZMuStandAlone size > 0
419 
420  // loop on ZMuTrack
421  if (!zMuMu_found && !zMuSta_found && !zMuTrack->empty()) {
422  event.getByToken(zMuTrackMatchMapToken_, zMuTrackMatchMap);
423  for (unsigned int i = 0; i < zMuTrack->size(); ++i) { //loop on candidates
424  const Candidate &zMuTrackCand = (*zMuTrack)[i]; //the candidate
425  CandidateBaseRef zMuTrackCandRef = zMuTrack->refAt(i);
426  const Candidate *lep0 = zMuTrackCand.daughter(0);
427  const Candidate *lep1 = zMuTrackCand.daughter(1);
428  const pat::Muon &muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
429  double trkiso0 = muonDau0.trackIso();
430  const pat::GenericParticle &trackDau1 = dynamic_cast<const pat::GenericParticle &>(*lep1->masterClone());
431  double trkiso1 = trackDau1.trackIso();
432 
433  // vertex
434 
435  TrackRef mu0TrkRef = muonDau0.track();
436  float d0signed_mu0 = (*mu0TrkRef).dxy();
437  float d0signed_mu0_respectToPV = (*mu0TrkRef).dxy(primaryVertices->begin()->position());
438  float vz_mu0_respectToPV = (*mu0TrkRef).dz(primaryVertices->begin()->position());
439 
440  TrackRef mu1TrkRef = trackDau1.track();
441  float d0signed_mu1 = (*mu1TrkRef).dxy();
442  float d0signed_mu1_respectToPV = (*mu1TrkRef).dxy(primaryVertices->begin()->position());
443  float vz_mu1_respectToPV = (*mu1TrkRef).dz(primaryVertices->begin()->position());
444 
445  // cynematical parameters
446 
447  double pt0 = zMuTrackCand.daughter(0)->pt();
448  double pt1 = zMuTrackCand.daughter(1)->pt();
449  double eta0 = zMuTrackCand.daughter(0)->eta();
450  double eta1 = zMuTrackCand.daughter(1)->eta();
451  double mass = zMuTrackCand.mass();
452 
453  // HLT match (check just dau0 the global)
454  const pat::TriggerObjectStandAloneCollection mu0HLTMatches = muonDau0.triggerObjectMatchesByPath("HLT_Mu9");
455 
456  bool trig0found = false;
457  if (!mu0HLTMatches.empty())
458  trig0found = true;
459 
460  // cynematical selection
461  if (trig0found && pt0 > ptmin_ && pt1 > ptmin_ && abs(eta0) < etamax_ && abs(eta1) < etamax_ && mass > massMin_ &&
462  trkiso0 < isoMax_ && trkiso1 < isoMax_) {
463  h_zmutrackSele_muon_vz->Fill(muonDau0.vz(), 1.); // muon vz
464  h_zmutrackSele_track_vz->Fill(trackDau1.vz(), 1.); // track vz
465  h_zmutrackSele_muon_d0signed->Fill(d0signed_mu0, 1.); // muon d0
466  h_zmutrackSele_track_d0signed->Fill(d0signed_mu1, 1.); // track d0
467  h_zmutrackSele_muon_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV, 1.); // muon d0 respect PV
468  h_zmutrackSele_track_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV, 1.); // track d0 respect PV
469  h_zmutrackSele_muon_vz_respectToPV->Fill(vz_mu0_respectToPV, 1.); // muon vz respect PV
470  h_zmutrackSele_track_vz_respectToPV->Fill(vz_mu1_respectToPV, 1.); // track vz respect PV
471  }
472 
473  } // end loop on ZMuTrack cand
474  } // end if ZMuTrack size > 0
475 
476 } // end analyze
477 
478 bool ZMuMu_vtxAnalyzer::check_ifZmumu(const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2) {
479  int partId0 = dauGen0->pdgId();
480  int partId1 = dauGen1->pdgId();
481  int partId2 = dauGen2->pdgId();
482  bool muplusFound = false;
483  bool muminusFound = false;
484  bool ZFound = false;
485  if (partId0 == 13 || partId1 == 13 || partId2 == 13)
486  muminusFound = true;
487  if (partId0 == -13 || partId1 == -13 || partId2 == -13)
488  muplusFound = true;
489  if (partId0 == 23 || partId1 == 23 || partId2 == 23)
490  ZFound = true;
491  return (muplusFound && muminusFound && ZFound);
492 }
493 
494 float ZMuMu_vtxAnalyzer::getParticlePt(const int ipart,
495  const Candidate *dauGen0,
496  const Candidate *dauGen1,
497  const Candidate *dauGen2) {
498  int partId0 = dauGen0->pdgId();
499  int partId1 = dauGen1->pdgId();
500  int partId2 = dauGen2->pdgId();
501  float ptpart = 0.;
502  if (partId0 == ipart) {
503  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
504  const Candidate *dauMuGen = dauGen0->daughter(k);
505  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
506  ptpart = dauMuGen->pt();
507  }
508  }
509  }
510  if (partId1 == ipart) {
511  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
512  const Candidate *dauMuGen = dauGen1->daughter(k);
513  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
514  ptpart = dauMuGen->pt();
515  }
516  }
517  }
518  if (partId2 == ipart) {
519  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
520  const Candidate *dauMuGen = dauGen2->daughter(k);
521  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
522  ptpart = dauMuGen->pt();
523  }
524  }
525  }
526  return ptpart;
527 }
528 
529 float ZMuMu_vtxAnalyzer::getParticleEta(const int ipart,
530  const Candidate *dauGen0,
531  const Candidate *dauGen1,
532  const Candidate *dauGen2) {
533  int partId0 = dauGen0->pdgId();
534  int partId1 = dauGen1->pdgId();
535  int partId2 = dauGen2->pdgId();
536  float etapart = 0.;
537  if (partId0 == ipart) {
538  for (unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
539  const Candidate *dauMuGen = dauGen0->daughter(k);
540  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
541  etapart = dauMuGen->eta();
542  }
543  }
544  }
545  if (partId1 == ipart) {
546  for (unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
547  const Candidate *dauMuGen = dauGen1->daughter(k);
548  if (dauMuGen->pdgId() == ipart && dauMuGen->status() == 1) {
549  etapart = dauMuGen->eta();
550  }
551  }
552  }
553  if (partId2 == ipart) {
554  for (unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
555  const Candidate *dauMuGen = dauGen2->daughter(k);
556  if (abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() == 1) {
557  etapart = dauMuGen->eta();
558  }
559  }
560  }
561  return etapart;
562 }
563 
564 float ZMuMu_vtxAnalyzer::getParticlePhi(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 phipart = 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  phipart = dauMuGen->phi();
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  phipart = dauMuGen->phi();
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  phipart = dauMuGen->phi();
593  }
594  }
595  }
596  return phipart;
597 }
598 
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  Particle::LorentzVector p4part(0., 0., 0., 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  p4part = dauMuGen->p4();
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  p4part = dauMuGen->p4();
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  p4part = dauMuGen->p4();
628  }
629  }
630  }
631  return p4part;
632 }
633 
635 
637 
EDGetTokenT< GenParticleMatch > zMuTrackMatchMapToken_
TH1D * h_zmumuSele_muon_d0signed_respectToPV
TH1D * h_zmumuNotIsoSele_muonNotIso_d0signed
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
float getParticlePt(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
OverlapChecker overlap_
EDGetTokenT< GenParticleMatch > zMuStandAloneMatchMapToken_
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
TH1D * h_zmumuNotIsoSele_muonIso_d0signed
bool check_ifZmumu(const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
TH1D * h_zmutrackSele_track_vz_respectToPV
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
TH1D * h_zmumuNotIsoSele_dimuon_vz
float getParticleEta(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
size_type size() const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
EDGetTokenT< GenParticleCollection > genParticlesToken_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
reco::TrackRef track() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
TH1D * h_zmustaSele_muon_vz_respectToPV
float trackIso() const
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
float trackIso() const
Definition: Muon.h:177
TH1D * h_zmutrackSele_track_d0signed
TH1D * h_zmutrackSele_muon_d0signed
TH1D * h_zmumuNotIsoSele_muonIso_vz
RefToBase< value_type > refAt(size_type i) const
virtual int status() const =0
status word
TH1D * h_zmutrackSele_track_d0signed_respectToPV
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
TH1D * h_zmumuNotIsoSele_muonNotIso_d0signed_respectToPV
TH1D * h_zmumuSele_muon_vz_respectToPV
EDGetTokenT< GenParticleMatch > zMuMuMatchMapToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool isGlobalMuon() const override
Definition: Muon.h:298
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
virtual int pdgId() const =0
PDG identifier.
TH1D * h_zmumuNotIsoSele_muonIso_d0signed_respectToPV
void endJob() override
EDGetTokenT< CandidateView > zMuMuToken_
TH1D * h_zmustaSele_sta_d0signed_respectToPV
bool empty() const
edm::ValueMap< float > IsolationCollection
TH1D * h_zmutrackSele_muon_vz_respectToPV
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Particle::LorentzVector getParticleP4(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
TH1D * h_zmumuNotIsoSele_muonNotIso_vz_respectToPV
const TriggerObjectStandAloneCollection triggerObjectMatchesByPath(const std::string &namePath, const bool pathLastFilterAccepted=false, const bool pathL3FilterAccepted=true) const
Definition: PATObject.h:682
TH1D * h_zmustaSele_sta_vz_respectToPV
double vz() const override
z coordinate of vertex position
TH1D * h_zmumuNotIsoSele_muonNotIso_vz
virtual const CandidateBaseRef & masterClone() const =0
zMuMu
zMuMu vector of PSet is common to all categories except zMuTrk category
virtual double eta() const =0
momentum pseudorapidity
reco::CandidateBaseRef trackMuonCandRef_
virtual double pt() const =0
transverse momentum
reco::TrackRef track() const override
TH1D * h_zmustaSele_muon_d0signed_respectToPV
virtual double mass() const =0
mass
EDGetTokenT< CandidateView > tracksToken_
EDGetTokenT< VertexCollection > primaryVerticesToken_
fixed size matrix
ZMuMu_vtxAnalyzer(const edm::ParameterSet &pset)
HLT enums.
EDGetTokenT< CandidateView > muonsToken_
TH1D * h_zmumuNotIsoSele_muonIso_vz_respectToPV
TH1D * h_muon_d0signed_respectToPV
lep1
print &#39;MRbb(1b)&#39;,event.mr_bb
EDGetTokenT< CandidateView > zMuStandAloneToken_
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
TH1D * h_zmutrackSele_muon_d0signed_respectToPV
virtual size_type numberOfDaughters() const =0
number of daughters
EDGetTokenT< CandidateView > zMuTrackToken_
virtual double phi() const =0
momentum azimuthal angle
float getParticlePhi(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
Analysis-level muon class.
Definition: Muon.h:51
Definition: event.py:1
math::PtEtaPhiELorentzVectorF LorentzVector