CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PythiaFilterGammaGamma.cc
Go to the documentation of this file.
3 #include "Math/GenVector/VectorUtil.h"
4 //#include "CLHEP/HepMC/GenParticle.h"
6 
7 #include "TFile.h"
8 #include "TLorentzVector.h"
9 
10 #include <iostream>
11 
12 using namespace edm;
13 using namespace std;
14 using namespace HepMC;
15 
16 
18  token_(consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared"))),
19  maxEvents(iConfig.getUntrackedParameter<int>("maxEvents", 100000)),
20  ptSeedThr(iConfig.getUntrackedParameter<double>("PtSeedThr")),
21  etaSeedThr(iConfig.getUntrackedParameter<double>("EtaSeedThr")),
22  ptGammaThr(iConfig.getUntrackedParameter<double>("PtGammaThr")),
23  etaGammaThr(iConfig.getUntrackedParameter<double>("EtaGammaThr")),
24  ptTkThr(iConfig.getUntrackedParameter<double>("PtTkThr")),
25  etaTkThr(iConfig.getUntrackedParameter<double>("EtaTkThr")),
26  ptElThr(iConfig.getUntrackedParameter<double>("PtElThr")),
27  etaElThr(iConfig.getUntrackedParameter<double>("EtaElThr")),
28  dRTkMax(iConfig.getUntrackedParameter<double>("dRTkMax")),
29  dRSeedMax(iConfig.getUntrackedParameter<double>("dRSeedMax")),
30  dPhiSeedMax(iConfig.getUntrackedParameter<double>("dPhiSeedMax")),
31  dEtaSeedMax(iConfig.getUntrackedParameter<double>("dEtaSeedMax")),
32  dRNarrowCone(iConfig.getUntrackedParameter<double>("dRNarrowCone")),
33  pTMinCandidate1(iConfig.getUntrackedParameter<double>("PtMinCandidate1")),
34  pTMinCandidate2(iConfig.getUntrackedParameter<double>("PtMinCandidate2")),
35  etaMaxCandidate(iConfig.getUntrackedParameter<double>("EtaMaxCandidate")),
36  invMassMin(iConfig.getUntrackedParameter<double>("InvMassMin")),
37  invMassMax(iConfig.getUntrackedParameter<double>("InvMassMax")),
38  energyCut(iConfig.getUntrackedParameter<double>("EnergyCut")),
39  nTkConeMax(iConfig.getUntrackedParameter<int>("NTkConeMax")),
40  nTkConeSum(iConfig.getUntrackedParameter<int>("NTkConeSum")),
41  acceptPrompts(iConfig.getUntrackedParameter<bool>("AcceptPrompts")),
42  promptPtThreshold(iConfig.getUntrackedParameter<double>("PromptPtThreshold")) {
43 
44  nSelectedEvents = 0;
45  nGeneratedEvents = 0;
46  counterPrompt = 0;
47 
48 }
49 
51 {
52  cout << "Number of Selected Events: " << nSelectedEvents << endl;
53  cout << "Number of Generated Events: " << nGeneratedEvents << endl;
54  cout << "Number of Prompt photons: " << counterPrompt << endl;
55 }
56 
58 
59 
60  if(nSelectedEvents >= maxEvents) {
61  throw cms::Exception("endJob")<<"We have reached the maximum number of events...";
62  }
63 
65 
66  bool accepted = false;
67 
69  iEvent.getByToken(token_, evt);
70  myGenEvent = evt->GetEvent();
71 
72  std::vector<const GenParticle*> seeds, egamma, stable;
73  std::vector<const GenParticle*>::const_iterator itPart, itStable, itEn;
74 
75  // Loop on egamma
76  for(HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end(); ++p) {
77 
78  if (
79  ((*p)->status()==1&&(*p)->pdg_id() == 22) || // gamma
80  ((*p)->status()==1&&abs((*p)->pdg_id()) == 11)) // electron
81 
82  {
83  // check for eta and pT threshold for seed in gamma, el
84  if ((*p)->momentum().perp() > ptSeedThr &&
85  fabs((*p)->momentum().eta()) < etaSeedThr) {
86 
87  seeds.push_back(*p);
88  }
89  }
90 
91 
92  if ((*p)->status() == 1) {
93 
94  // save charged stable tracks
95  if (abs((*p)->pdg_id()) == 211 ||
96  abs((*p)->pdg_id()) == 321 ||
97  abs((*p)->pdg_id()) == 11 ||
98  abs((*p)->pdg_id()) == 13 ||
99  abs((*p)->pdg_id()) == 15) {
100  // check if it passes the cut
101  if ((*p)->momentum().perp() > ptTkThr &&
102  fabs((*p)->momentum().eta()) < etaTkThr) {
103  stable.push_back(*p);
104  }
105  }
106 
107  // save egamma for candidate calculation
108  if ((*p)->pdg_id() == 22 &&
109  (*p)->momentum().perp() > ptGammaThr &&
110  fabs((*p)->momentum().eta()) < etaGammaThr) {
111  egamma.push_back(*p);
112  }
113  if (abs((*p)->pdg_id()) == 11 &&
114  (*p)->momentum().perp() > ptElThr &&
115  fabs((*p)->momentum().eta()) < etaElThr) {
116  egamma.push_back(*p);
117  }
118  }
119  }
120 
121  if (seeds.size() < 2) return accepted;
122 
123  std::vector<int> nTracks;
124  std::vector<TLorentzVector> candidate, candidateNarrow, candidateSeed;
125  std::vector<const GenParticle*>::iterator itSeed;
126 
127  const GenParticle* mom;
128  int this_id;
129  int first_different_id;
130 
131  for(itSeed = seeds.begin(); itSeed != seeds.end(); ++itSeed) {
132 
133  TLorentzVector energy, narrowCone, temp1, temp2, tempseed;
134 
135  tempseed.SetXYZM((*itSeed)->momentum().px(), (*itSeed)->momentum().py(), (*itSeed)->momentum().pz(), 0);
136  for(itEn = egamma.begin(); itEn != egamma.end(); ++itEn) {
137  temp1.SetXYZM((*itEn)->momentum().px(), (*itEn)->momentum().py(), (*itEn)->momentum().pz(), 0);
138 
139  double DR = temp1.DeltaR(tempseed);
140  double DPhi = temp1.DeltaPhi(tempseed);
141  double DEta = (*itEn)->momentum().eta()-(*itSeed)->momentum().eta();
142  if(DPhi<0) DPhi=-DPhi;
143  if(DEta<0) DEta=-DEta;
144 
145  if (DR < dRSeedMax || (DPhi<dPhiSeedMax&&DEta<dEtaSeedMax)) {
146  energy += temp1;
147  }
148  if (DR < dRNarrowCone) {
149  narrowCone += temp1;
150  }
151  }
152 
153  int counter = 0;
154 
155  if ( energy.Et() != 0. ) {
156  if (fabs(energy.Eta()) < etaMaxCandidate) {
157 
158  temp2.SetXYZM(energy.Px(), energy.Py(), energy.Pz(), 0);
159 
160  for(itStable = stable.begin(); itStable != stable.end(); ++itStable) {
161  temp1.SetXYZM((*itStable)->momentum().px(), (*itStable)->momentum().py(), (*itStable)->momentum().pz(), 0);
162  double DR = temp1.DeltaR(temp2);
163  if (DR < dRTkMax) counter++;
164  }
165 
166  if(acceptPrompts) {
167 
168  if ((*itSeed)->momentum().perp()>promptPtThreshold)
169  {
170  bool isPrompt=true;
171  this_id = (*itSeed)->pdg_id();
172  mom = (*itSeed);
173  while (mom->pdg_id() == this_id) {
174 
175  const GenParticle* mother = mom->production_vertex() ?
176  *(mom->production_vertex()->particles_in_const_begin()) : 0;
177 
178  mom = mother;
179  if (mom == 0) {
180  break;
181  }
182  }
183 
184  first_different_id = mom->pdg_id();
185 
186  if (mom->status() == 2 && std::abs(first_different_id)>100) isPrompt=false;
187 
188 
189  if(isPrompt) counter=0;
190  if(isPrompt) counterPrompt++;
191  }
192  }
193  }
194  }
195 
196  candidate.push_back(energy);
197  candidateSeed.push_back(tempseed);
198  candidateNarrow.push_back(narrowCone);
199  nTracks.push_back(counter);
200  }
201 
202  if (candidate.size() <2) return accepted;
203 
204  TLorentzVector minvMin, minvMax;
205 
206  int i1, i2;
207  for(unsigned int i=0; i<candidate.size()-1; ++i) {
208 
209  if (candidate[i].Energy() < energyCut) continue;
210  if(nTracks[i]>nTkConeMax) continue;
211  if (fabs(candidate[i].Eta()) > etaMaxCandidate) continue;
212 
213  for(unsigned int j=i+1; j<candidate.size(); ++j) {
214  if (candidate[j].Energy() < energyCut) continue;
215  if(nTracks[j]>nTkConeMax) continue;
216  if (fabs(candidate[j].Eta()) > etaMaxCandidate) continue;
217 
218  if (nTracks[i] + nTracks[j] > nTkConeSum) continue;
219 
220  if (candidate[i].Pt() > candidate[j].Pt()) {
221  i1 = i;
222  i2 = j;
223  }
224  else {
225  i1 = j;
226  i2 = i;
227  }
228 
229  if (candidate[i1].Pt() < pTMinCandidate1 || candidate[i2].Pt() < pTMinCandidate2) continue;
230 
231  minvMin = candidate[i] + candidate[j];
232  if (minvMin.M() < invMassMin) continue;
233 
234  minvMax = candidate[i] + candidate[j];
235  if (minvMax.M() > invMassMax) continue;
236 
237  accepted = true;
238 
239  }
240  }
241 
242  if (accepted) nSelectedEvents++;
243  return accepted;
244 }
245 
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
static const int stable
Definition: TopGenEvent.h:11
virtual bool filter(edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:230
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
static std::atomic< unsigned int > counter
const HepMC::GenEvent * myGenEvent
PythiaFilterGammaGamma(const edm::ParameterSet &)
edm::EDGetTokenT< edm::HepMCProduct > token_
tuple cout
Definition: gather_cfg.py:121