CMS 3D CMS Logo

gamma_radiative_analysis.cc
Go to the documentation of this file.
1 /* \class gamma_radiative_analyzer
2  *
3  * author: Pasquale Noli
4  *
5  * Gamma Radiative analyzer
6  *
7  *
8  */
37 #include <iostream>
38 #include <iterator>
39 #include <cmath>
40 #include <vector>
41 #include "TH1.h"
42 #include "TH2.h"
43 //#include "TH3.h"
44 
45 using namespace edm;
46 using namespace std;
47 using namespace reco;
48 using namespace isodeposit;
49 
51 
53 public:
55 
56 private:
57  void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
58  void endJob() override;
59 
66  double dRVeto_, dRTrk_, ptThreshold_;
67  //histograms
68  TH2D *h_gamma_pt_eta_, *h_mu_pt_eta_FSR_, *h_mu_pt_eta_no_FSR_;
69 
70  //boolean
71  bool FSR_mu, FSR_tk, FSR_mu0, FSR_mu1;
72 
73  //counter
74  int zmmcounter, zmscounter, zmtcounter, numOfEvent, numofGamma;
75 };
76 
78  : zMuMuToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuMu"))),
79  zMuMuMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuMuMatchMap"))),
80  zMuTkToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuTk"))),
81  zMuTkMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuTkMatchMap"))),
82  zMuSaToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuSa"))),
83  zMuSaMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuSaMatchMap"))) {
84  zmmcounter = 0;
85  zmscounter = 0;
86  zmtcounter = 0;
87  numOfEvent = 0;
88  numofGamma = 0;
90 
91  // general histograms
92  h_gamma_pt_eta_ = fs->make<TH2D>("h_gamma_pt_eta", "pt vs eta of gamma", 100, 20, 100, 100, -2.0, 2.0);
93  h_mu_pt_eta_FSR_ = fs->make<TH2D>("h_mu_pt_eta_FSR", "pt vs eta of muon with FSR", 100, 20, 100, 100, -2.0, 2.0);
95  fs->make<TH2D>("h_mu_pt_eta_no_FSR", "pt vs eta of of muon withot FSR", 100, 20, 100, 100, -2.0, 2.0);
96 }
97 
99  Handle<CandidateView> zMuMu; //Collection of Z made by Mu global + Mu global
100  Handle<GenParticleMatch> zMuMuMatchMap; //Map of Z made by Mu global + Mu global with MC
101  event.getByToken(zMuMuToken_, zMuMu);
102  Handle<CandidateView> zMuTk; //Collection of Z made by Mu global + Track
103  Handle<GenParticleMatch> zMuTkMatchMap;
104  event.getByToken(zMuTkToken_, zMuTk);
105  Handle<CandidateView> zMuSa; //Collection of Z made by Mu global + Sa
106  Handle<GenParticleMatch> zMuSaMatchMap;
107  event.getByToken(zMuSaToken_, zMuSa);
108  numOfEvent++;
109  // ZMuMu
110  if (!zMuMu->empty()) {
111  event.getByToken(zMuMuMatchMapToken_, zMuMuMatchMap);
112  for (unsigned int i = 0; i < zMuMu->size(); ++i) { //loop on candidates
113 
114  const Candidate& zMuMuCand = (*zMuMu)[i]; //the candidate
115  CandidateBaseRef zMuMuCandRef = zMuMu->refAt(i);
116 
117  CandidateBaseRef dau0 = zMuMuCand.daughter(0)->masterClone();
118  CandidateBaseRef dau1 = zMuMuCand.daughter(1)->masterClone();
119  const pat::Muon& mu0 = dynamic_cast<const pat::Muon&>(*dau0); //cast in patMuon
120  const pat::Muon& mu1 = dynamic_cast<const pat::Muon&>(*dau1);
121 
122  double zmass = zMuMuCand.mass();
123  double pt0 = mu0.pt();
124  double pt1 = mu1.pt();
125  double eta0 = mu0.eta();
126  double eta1 = mu1.eta();
127  if (pt0 > 20 && pt1 > 20 && abs(eta0) < 2 && abs(eta1) < 2 && zmass > 20 && zmass < 200) {
128  GenParticleRef zMuMuMatch = (*zMuMuMatchMap)[zMuMuCandRef];
129  if (zMuMuMatch.isNonnull()) { // ZMuMu matched
130  zmmcounter++;
131  FSR_mu0 = false;
132  FSR_mu1 = false;
133 
134  //MonteCarlo Study
135  const reco::GenParticle* muMc0 = mu0.genLepton();
136  const reco::GenParticle* muMc1 = mu1.genLepton();
137  const Candidate* motherMu0 = muMc0->mother();
138  const Candidate* motherMu1 = muMc1->mother();
139  int num_dau_muon0 = motherMu0->numberOfDaughters();
140  int num_dau_muon1 = motherMu1->numberOfDaughters();
141  if (num_dau_muon0 > 1) {
142  for (int j = 0; j < num_dau_muon0; ++j) {
143  int id = motherMu0->daughter(j)->pdgId();
144  if (id == 22) {
145  double etaG = motherMu0->daughter(j)->eta();
146  double ptG = motherMu0->daughter(j)->pt();
147  h_gamma_pt_eta_->Fill(ptG, etaG);
148  h_mu_pt_eta_FSR_->Fill(pt0, eta0);
149  FSR_mu0 = true;
150  numofGamma++;
151  }
152  }
153  } //end check of gamma
154  if (!FSR_mu0)
155  h_mu_pt_eta_no_FSR_->Fill(pt0, eta0);
156  if (num_dau_muon1 > 1) {
157  for (int j = 0; j < num_dau_muon1; ++j) {
158  int id = motherMu1->daughter(j)->pdgId();
159  if (id == 22) {
160  double etaG = motherMu1->daughter(j)->eta();
161  double ptG = motherMu1->daughter(j)->pt();
162  h_gamma_pt_eta_->Fill(ptG, etaG);
163  h_mu_pt_eta_FSR_->Fill(pt1, eta1);
164  FSR_mu1 = true;
165  numofGamma++;
166  }
167  }
168  } //end check of gamma
169  if (!FSR_mu1)
170  h_mu_pt_eta_no_FSR_->Fill(pt1, eta1);
171  } // end MC match
172  } //end of cuts
173  } // end loop on ZMuMu cand
174  } // end if ZMuMu size > 0
175 
176  // ZMuSa
177  if (!zMuSa->empty()) {
178  event.getByToken(zMuSaMatchMapToken_, zMuSaMatchMap);
179  for (unsigned int i = 0; i < zMuSa->size(); ++i) { //loop on candidates
180 
181  const Candidate& zMuSaCand = (*zMuSa)[i]; //the candidate
182  CandidateBaseRef zMuSaCandRef = zMuSa->refAt(i);
183 
184  CandidateBaseRef dau0 = zMuSaCand.daughter(0)->masterClone();
185  CandidateBaseRef dau1 = zMuSaCand.daughter(1)->masterClone();
186  const pat::Muon& mu0 = dynamic_cast<const pat::Muon&>(*dau0); //cast in patMuon
187  const pat::Muon& mu1 = dynamic_cast<const pat::Muon&>(*dau1);
188 
189  double zmass = zMuSaCand.mass();
190  double pt0 = mu0.pt();
191  double pt1 = mu1.pt();
192  double eta0 = mu0.eta();
193  double eta1 = mu1.eta();
194  if (pt0 > 20 && pt1 > 20 && abs(eta0) < 2 && abs(eta1) < 2 && zmass > 20 && zmass < 200) {
195  GenParticleRef zMuSaMatch = (*zMuSaMatchMap)[zMuSaCandRef];
196  if (zMuSaMatch.isNonnull()) { // ZMuSa matched
197  FSR_mu0 = false;
198  FSR_mu1 = false;
199  zmscounter++;
200  //MonteCarlo Study
201  const reco::GenParticle* muMc0 = mu0.genLepton();
202  const reco::GenParticle* muMc1 = mu1.genLepton();
203  const Candidate* motherMu0 = muMc0->mother();
204  const Candidate* motherMu1 = muMc1->mother();
205  int num_dau_muon0 = motherMu0->numberOfDaughters();
206  int num_dau_muon1 = motherMu1->numberOfDaughters();
207  if (num_dau_muon0 > 1) {
208  for (int j = 0; j < num_dau_muon0; ++j) {
209  int id = motherMu0->daughter(j)->pdgId();
210  if (id == 22) {
211  double etaG = motherMu0->daughter(j)->eta();
212  double ptG = motherMu0->daughter(j)->pt();
213  h_gamma_pt_eta_->Fill(ptG, etaG);
214  h_mu_pt_eta_FSR_->Fill(pt0, eta0);
215  numofGamma++;
216  FSR_mu0 = true;
217  }
218  }
219  } //end check of gamma
220  if (!FSR_mu0)
221  h_mu_pt_eta_no_FSR_->Fill(pt0, eta0);
222  if (num_dau_muon1 > 1) {
223  for (int j = 0; j < num_dau_muon1; ++j) {
224  int id = motherMu1->daughter(j)->pdgId();
225  if (id == 22) {
226  double etaG = motherMu1->daughter(j)->eta();
227  double ptG = motherMu1->daughter(j)->pt();
228  h_gamma_pt_eta_->Fill(ptG, etaG);
229  h_mu_pt_eta_FSR_->Fill(pt1, eta1);
230  numofGamma++;
231  FSR_mu1 = true;
232  }
233  }
234  } //end check of gamma
235  if (!FSR_mu1)
236  h_mu_pt_eta_no_FSR_->Fill(pt1, eta1);
237  } // end MC match
238  } //end of cuts
239  } // end loop on ZMuSa cand
240  } // end if ZMuSa size > 0
241 
242  //ZMuTk
243  if (!zMuTk->empty()) {
244  event.getByToken(zMuTkMatchMapToken_, zMuTkMatchMap);
245  for (unsigned int i = 0; i < zMuTk->size(); ++i) { //loop on candidates
246  const Candidate& zMuTkCand = (*zMuTk)[i]; //the candidate
247  CandidateBaseRef zMuTkCandRef = zMuTk->refAt(i);
248 
249  CandidateBaseRef dau0 = zMuTkCand.daughter(0)->masterClone();
250  CandidateBaseRef dau1 = zMuTkCand.daughter(1)->masterClone();
251  const pat::Muon& mu0 = dynamic_cast<const pat::Muon&>(*dau0); //cast in patMuon
252  const pat::GenericParticle& mu1 = dynamic_cast<const pat::GenericParticle&>(*dau1);
253 
254  double zmass = zMuTkCand.mass();
255  double pt0 = mu0.pt();
256  double pt1 = mu1.pt();
257  double eta0 = mu0.eta();
258  double eta1 = mu1.eta();
259  if (pt0 > 20 && pt1 > 20 && abs(eta0) < 2 && abs(eta1) < 2 && zmass > 20 && zmass < 200) { //kinematical cuts
260  GenParticleRef zMuTkMatch = (*zMuTkMatchMap)[zMuTkCandRef];
261  if (zMuTkMatch.isNonnull()) { // ZMuTk matched
262  FSR_mu = false;
263  FSR_tk = false;
264  zmtcounter++;
265  //MonteCarlo Study
266  const reco::GenParticle* muMc0 = mu0.genLepton();
267  const reco::GenParticle* muMc1 = mu1.genParticle();
268  const Candidate* motherMu0 = muMc0->mother();
269  const Candidate* motherMu1 = muMc1->mother();
270  int num_dau_muon0 = motherMu0->numberOfDaughters();
271  int num_dau_muon1 = motherMu1->numberOfDaughters();
272  if (num_dau_muon0 > 1) {
273  for (int j = 0; j < num_dau_muon0; ++j) {
274  int id = motherMu0->daughter(j)->pdgId();
275  if (id == 22) {
276  double etaG = motherMu0->daughter(j)->eta();
277  double ptG = motherMu0->daughter(j)->pt();
278  h_gamma_pt_eta_->Fill(ptG, etaG);
279  h_mu_pt_eta_FSR_->Fill(pt0, eta0);
280  numofGamma++;
281  FSR_mu0 = true;
282  }
283  }
284  } //end check of gamma
285  if (!FSR_mu0)
286  h_mu_pt_eta_no_FSR_->Fill(pt0, eta0);
287  if (num_dau_muon1 > 1) {
288  for (int j = 0; j < num_dau_muon1; ++j) {
289  int id = motherMu1->daughter(j)->pdgId();
290  if (id == 22) {
291  double etaG = motherMu1->daughter(j)->eta();
292  double ptG = motherMu1->daughter(j)->pt();
293  h_gamma_pt_eta_->Fill(ptG, etaG);
294  h_mu_pt_eta_FSR_->Fill(pt1, eta1);
295  numofGamma++;
296  FSR_mu1 = true;
297  }
298  }
299  } //end check of gamma
300  if (!FSR_mu1)
301  h_mu_pt_eta_no_FSR_->Fill(pt1, eta1);
302  } // end MC match
303  } //end Kine-cuts
304  } // end loop on ZMuTk cand
305  } // end if ZMuTk size > 0
306 } // end analyze
307 
309  cout << " ============= Summary ==========" << endl;
310  cout << " Numero di eventi = " << numOfEvent << endl;
311  cout << " 1)Numero di ZMuMu matched dopo i tagli cinematici = " << zmmcounter << endl;
312  cout << " 2)Numero di ZMuSa matched dopo i tagli cinematici = " << zmscounter << endl;
313  cout << " 3)Numero di ZMuTk matched dopo i tagli cinematici = " << zmtcounter << endl;
314  cout << " 4)Number of gamma = " << numofGamma << endl;
315 }
316 
318 
gamma_radiative_analyzer(const edm::ParameterSet &pset)
EDGetTokenT< CandidateView > zMuMuToken_
const reco::GenParticle * genLepton() const
Definition: Lepton.h:39
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
double eta() const final
momentum pseudorapidity
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
const reco::GenParticle * genParticle(size_t idx=0) const
Definition: PATObject.h:290
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
size_type size() const
double pt() const final
transverse momentum
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
RefToBase< value_type > refAt(size_type i) const
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ValueMap< float > IsolationCollection
virtual int pdgId() const =0
PDG identifier.
bool empty() const
EDGetTokenT< CandidateView > zMuSaToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EDGetTokenT< GenParticleMatch > zMuMuMatchMapToken_
EDGetTokenT< GenParticleMatch > zMuTkMatchMapToken_
zMuSa
zMUSa vector of PSet is specific for zMuSa category
EDGetTokenT< GenParticleMatch > zMuSaMatchMapToken_
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
virtual double pt() const =0
transverse momentum
virtual double mass() const =0
mass
EDGetTokenT< CandidateView > zMuTkToken_
fixed size matrix
HLT enums.
virtual size_type numberOfDaughters() const =0
number of daughters
Analysis-level muon class.
Definition: Muon.h:51
const Candidate * mother(size_type=0) const override
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
Definition: event.py:1