CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PythiaFilterGammaJetIsoPi0.cc
Go to the documentation of this file.
6 #include <iostream>
7 #include<list>
8 #include<vector>
9 #include<cmath>
10 
11 using namespace edm;
12 using namespace std;
13 
14 namespace{
15 
16  double deltaR2(double eta0, double phi0, double eta, double phi){
17  double dphi=phi-phi0;
18  if(dphi>M_PI) dphi-=2*M_PI;
19  else if(dphi<=-M_PI) dphi+=2*M_PI;
20  return dphi*dphi+(eta-eta0)*(eta-eta0);
21  }
22 
23  double deltaPhi(double phi0, double phi){
24  double dphi=phi-phi0;
25  if(dphi>M_PI) dphi-=2*M_PI;
26  else if(dphi<=-M_PI) dphi+=2*M_PI;
27  return dphi;
28  }
29 
30  class ParticlePtGreater{
31  public:
32  int operator()(const HepMC::GenParticle * p1,
33  const HepMC::GenParticle * p2) const{
34  return p1->momentum().perp() > p2->momentum().perp();
35  }
36  };
37 }
38 
39 
41  label_(iConfig.getUntrackedParameter("moduleLabel",std::string("generator"))),
42  etaMin(iConfig.getUntrackedParameter<double>("MinPi0Eta", 1.65)),
43  PtMin(iConfig.getUntrackedParameter<double>("MinPi0Pt", 50.)),
44  etaMax(iConfig.getUntrackedParameter<double>("MaxPi0Eta", 2.5)),
45  PtMax(iConfig.getUntrackedParameter<double>("MaxPi0Pt", 100.)),
46  isocone(iConfig.getUntrackedParameter<double>("IsoCone",0.3)),
47  isodr(iConfig.getUntrackedParameter<double>("IsoDR",0.5)),
48  ebEtaMax(1.479){
49 //
50  deltaEB=0.01745/2 *5; // delta_eta, delta_phi
51  deltaEE=2.93/317/2 *5; // delta_x/z, delta_y/z
54 
55  cout << " Cut Definition: " << endl;
56  cout << " MinPi0Pt = " << PtMin << endl;
57  cout << " MaxPi0Pt = " << PtMax << endl;
58  cout << " MinPi0Eta = " << etaMin << endl;
59  cout << " MaxPi0Eta = " << etaMax << endl;
60 //
61  cout << " Pi0 Isolation Cone = " << isocone << endl;
62  cout << " Max dR between pi0 and Photon = " << isodr << endl;
63  cout << " 5x5 crystal cone around pi0 axis in ECAL Barrel = " << deltaEB << endl;
64  cout << " 5x5 crystal cone around pi0 axis in ECAL Endcap = " << deltaEE << endl;
65 
68 
69 }
70 
71 
73 
74 
75 // ------------ method called to produce the data ------------
77 
79  if(theNumberOfTestedEvt%1000 == 0) cout << "Number of tested events = " << theNumberOfTestedEvt << endl;
80 
81  bool accepted = false;
83  iEvent.getByLabel(label_, evt);
84 
85  const HepMC::GenEvent * myGenEvent = evt->GetEvent();
86 
87  list<const HepMC::GenParticle *> pi0_seeds;
88 
89  int pi0_id = -1;
90  int particle_id = 1;
91  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
92  p != myGenEvent->particles_end(); ++p ) {
93 
94  double Particle_pt = (*p)->momentum().perp();
95  double Particle_eta = (*p)->momentum().eta();
96 
97  if ( (*p)->pdg_id()==111) {
98 
99  if(Particle_pt > PtMin && Particle_pt < PtMax && Particle_eta < etaMax && Particle_eta > etaMin )
100  {
101  pi0_id = particle_id;
102  pi0_seeds.push_back(*p);
103  break;
104  }
105  }
106  particle_id++;
107  }
108 
109  HepMC::GenEvent::particle_const_iterator ppp = myGenEvent->particles_begin();
110  for(int i=0;i<7;++i) ppp++;
111  HepMC::GenParticle* particle8 = (*ppp);
112 
113  int photon_id = 7;
114  if(particle8->pdg_id() == 22) {
115  photon_id = 8;
116  }
117 
118  if(pi0_seeds.size() == 1) {
119  double eta_photon = myGenEvent->barcode_to_particle(photon_id)->momentum().eta();
120  double phi_photon = myGenEvent->barcode_to_particle(photon_id)->momentum().eta();
121  double eta_pi0 = myGenEvent->barcode_to_particle(pi0_id)->momentum().eta();
122  double phi_pi0 = myGenEvent->barcode_to_particle(pi0_id)->momentum().phi();
123 
124  double dr_pi0_photon = sqrt(deltaR2(eta_photon, phi_photon, eta_pi0, phi_pi0));
125 // check if pi0 comes from the jet and is far from the photon
126 // ----------------------------------------------------------
127  if(dr_pi0_photon > isodr) {
128 
129  bool inEB(0);
130  double tgx(0);
131  double tgy(0);
132  if( std::abs(eta_pi0) < ebEtaMax) inEB=1;
133  else{
134  tgx=myGenEvent->barcode_to_particle(pi0_id)->momentum().px()/myGenEvent->barcode_to_particle(pi0_id)->momentum().pz();
135  tgy=myGenEvent->barcode_to_particle(pi0_id)->momentum().py()/myGenEvent->barcode_to_particle(pi0_id)->momentum().pz();
136  }
137 
138  double etPi0=0;
139  double etPi0Charged=0;
140  double etCone=0;
141  double etConeCharged=0;
142  double ptMaxHadron=0;
143 
144  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
145  p != myGenEvent->particles_end(); ++p ) {
146 
147  if ( (*p)->status()!=1 ) continue; // use only stable particles
148  int pid= (*p)->pdg_id();
149  int apid= std::abs(pid);
150  if (apid>11 && apid<21) continue; //get rid of muons and neutrinos
151  double eta=(*p)->momentum().eta();
152  double phi=(*p)->momentum().phi();
153  if ( sqrt(deltaR2(eta_pi0, phi_pi0, eta, phi)) > isocone) continue;
154  double pt=(*p)->momentum().perp();
155  etCone+=pt; // add the pt if particle inside the cone
156 
158  iSetup.getData( pdt );
159 
160  int charge3 = ((pdt->particle((*p)->pdg_id()))->ID().threeCharge());
161 
162  if(charge3) etConeCharged+=pt;
163 
164  //select particles matching a crystal array centered on pi0 direction
165  if(inEB) {
166  if( std::abs(eta-eta_pi0)> deltaEB ||
167  std::abs(deltaPhi(phi,phi_pi0)) > deltaEB) continue;
168  }
169  else if( fabs((*p)->momentum().px()/(*p)->momentum().pz() - tgx) > deltaEE ||
170  fabs((*p)->momentum().py()/(*p)->momentum().pz() - tgy) > deltaEE) continue;
171 
172  etPi0+=pt;
173 
174  if(charge3) etPi0Charged+=pt;
175 
176  if(apid>100 && apid!=310 && pt>ptMaxHadron) ptMaxHadron=pt; // 310 -> K0s
177 
178  } // for ( HepMC::GenEvent::particle_const_iterator
179 
180  //isolation cuts
181 
182  double iso_cut1 = 5 + etPi0/20 - etPi0*etPi0/1e4;
183  double iso_cut2 = 3 + etPi0/20 - etPi0*etPi0*etPi0/1e6;
184  double iso_cut3 = 4.5 + etPi0/40;
185  if (etPi0>165.)
186  {
187  iso_cut1 = 5.+165./20.-165.*165./1e4;
188  iso_cut2 = 3.+165./20.-165.*165.*165./1e6;
189  iso_cut3 = 4.5+165./40.;
190  }
191  double iso_cut4 = 0.02; // Fraction of charged energy in the cone 2%
192 
193 
194  double iso_val1 = etCone - etPi0;
195  double iso_val2 = iso_val1 - (etConeCharged - etPi0Charged);
196  double iso_val3 = etConeCharged/etPi0;
197 
198  if( iso_val1 < iso_cut1) {
199  if( iso_val2 < iso_cut2) {
200  if(ptMaxHadron < iso_cut3) {
201  if(iso_val3 < iso_cut4) {
202  accepted=true;
203  }
204  } // if(ptMaxHadron < iso_cut3)
205  } // if( iso_val2 < iso_cut2)
206  } // if( iso_val1 < iso_cut1)
207  } // if(dr_pi0_jet < 0.1 && deta_pi0_photon > 1)
208  } //if(pi0_seeds.size() == 1) {
209 
210 
211  if (accepted) {
213  cout << "========> Event: " << iEvent.id()
214  << " of Proccess ID " << myGenEvent->signal_process_id()
215  << " preselected " << endl;
216  cout << " Number of preselected events: " << theNumberOfSelected << endl;
217  return true;
218  }
219  else return false;
220 
221 }
222 
int i
Definition: DBlmapReader.cc:9
#define abs(x)
Definition: mlp_lapack.h:159
T eta() const
void getData(T &iHolder) const
Definition: EventSetup.h:67
int iEvent
Definition: GenABIO.cc:243
T sqrt(T t)
Definition: SSEVec.h:46
double p2[4]
Definition: TauolaWrapper.h:90
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
double deltaR2(const Vector1 &v1, const Vector2 &v2)
Definition: VectorUtil.h:78
#define M_PI
Definition: BFit3D.cc:3
edm::EventID id() const
Definition: EventBase.h:56
double p1[4]
Definition: TauolaWrapper.h:89
PythiaFilterGammaJetIsoPi0(const edm::ParameterSet &)
tuple cout
Definition: gather_cfg.py:121
virtual bool filter(edm::Event &, const edm::EventSetup &)
Definition: DDAxes.h:10