CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PythiaFilterEMJet.cc
Go to the documentation of this file.
3 #include <iostream>
4 #include<list>
5 #include<map>
6 #include<vector>
7 #include<cmath>
8 
9 using namespace edm;
10 using namespace std;
11 
12 namespace{
13 
14  inline double deltaR2(double eta0, double phi0, double eta, double phi){
15  double dphi=phi-phi0;
16  if(dphi>M_PI) dphi-=2*M_PI;
17  else if(dphi<=-M_PI) dphi+=2*M_PI;
18  return dphi*dphi+(eta-eta0)*(eta-eta0);
19  }
20 
21  double deltaPhi(double phi0, double phi){
22  double dphi=phi-phi0;
23  if(dphi>M_PI) dphi-=2*M_PI;
24  else if(dphi<=-M_PI) dphi+=2*M_PI;
25  return dphi;
26  }
27 
28  class ParticlePtGreater{
29  public:
30  int operator()(const HepMC::GenParticle * p1,
31  const HepMC::GenParticle * p2) const{
32  return p1->momentum().perp() > p2->momentum().perp();
33  }
34  };
35 }
36 
37 
39 token_(consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared"))),
40 etaMin(iConfig.getUntrackedParameter<double>("MinEMEta", 0)),
41 eTSumMin(iConfig.getUntrackedParameter<double>("ETSumMin", 50.)),
42 pTMin(iConfig.getUntrackedParameter<double>("MinEMpT", 5.)),
43 etaMax(iConfig.getUntrackedParameter<double>("MaxEMEta", 2.7)),
44 eTSumMax(iConfig.getUntrackedParameter<double>("ETSumMax", 100.)),
45 pTMax(iConfig.getUntrackedParameter<double>("MaxEMpT", 999999.)),
46 ebEtaMax(1.479),
47 maxnumberofeventsinrun(iConfig.getUntrackedParameter<int>("MaxEvents",3000000)){
48 
49  deltaEB=0.01745/2 *5; // delta_eta, delta_phi
50  deltaEE=2.93/317/2 *5; // delta_x/z, delta_y/z
53 
54  cout << " Max Events : " << maxnumberofeventsinrun << endl;
55  cout << " Cut Definition: " << endl;
56  cout << " MinEMEta = " << etaMin << endl;
57  cout << " ETSumMin = " << eTSumMin << endl;
58  cout << " MinEMpT = " << pTMin << endl;
59  cout << " MaxEMEta = " << etaMax << endl;
60  cout << " ETSumMax = " << eTSumMax << endl;
61  cout << " MaxEMpT = " << pTMax << endl;
62  cout << " 5x5 crystal cone around EM axis in ECAL Barrel = " << deltaEB << endl;
63  cout << " 5x5 crystal cone around EM axis in ECAL Endcap = " << deltaEE << endl;
64 
65 }
66 
68 {
69 std::cout << "Total number of tested events = " << theNumberOfTestedEvt << std::endl;
70 std::cout << "Total number of accepted events = " << theNumberOfSelected << std::endl;
71 }
72 
73 
74 // ------------ method called to produce the data ------------
76 
78  throw cms::Exception("endJob") << "we have reached the maximum number of events ";
79  }
80 
82  if(theNumberOfTestedEvt%1000 == 0) cout << "Number of tested events = " << theNumberOfTestedEvt << endl;
83 
84  bool accepted = false;
86  iEvent.getByToken(token_, evt);
87 
88  list<const HepMC::GenParticle *> EM_seeds;
89  const HepMC::GenEvent * myGenEvent = evt->GetEvent();
90 
91  int particle_id = 1;
92 
93  //select e+/e-/gamma particles in the events
94  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
95  p != myGenEvent->particles_end();
96  ++p ) {
97 
98 
99  if ( (abs((*p)->pdg_id())==11 || (*p)->pdg_id()==22)
100  && (*p)->status()==1
101  && (*p)->momentum().perp() > pTMin
102  && (*p)->momentum().perp() < pTMax
103  && fabs((*p)->momentum().eta()) < etaMax
104  && fabs((*p)->momentum().eta()) > etaMin ) {
105  EM_seeds.push_back(*p);
106  }
107  particle_id++;
108  }
109 
110  EM_seeds.sort(ParticlePtGreater());
111 
112  double etaEMClus=0;
113  double phiEMClus=0;
114  double ptEMClus=0;
115  for(std::list<const HepMC::GenParticle *>::const_iterator is=EM_seeds.begin();
116  is!= EM_seeds.end();
117  ++is){
118  double etaEM=(*is)->momentum().eta();
119  double phiEM=(*is)->momentum().phi();
120  double ptEM=(*is)->momentum().perp();
121  //pass at the cluster the seed infos
122  etaEMClus = etaEM;
123  phiEMClus = phiEM;
124  ptEMClus = ptEM;
125 
126  //check if the EM particle is in the barrel
127  bool inEB(0);
128  double tgx(0);
129  double tgy(0);
130  if( std::abs(etaEM)<ebEtaMax ) inEB=1;
131  else{
132  tgx=(*is)->momentum().px()/(*is)->momentum().pz();
133  tgy=(*is)->momentum().py()/(*is)->momentum().pz();
134  }
135 
136 // std::vector<const HepMC::GenParticle*> takenEM ;
137 // std::vector<const HepMC::GenParticle*>::const_iterator itPart ;
138 
139  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
140  p != myGenEvent->particles_end();
141  ++p ) {
142 
143  if (((*p)->status()==1 && (*p)->pdg_id() == 22) || // gamma
144  ((*p)->status()==1 && abs((*p)->pdg_id()) == 11) ) // electron
145 // (*p)->pdg_id() == 111 || // pi0
146 // abs((*p)->pdg_id()) == 221 || // eta
147 // abs((*p)->pdg_id()) == 331 || // eta prime
148 // abs((*p)->pdg_id()) == 113 || // rho0
149 // abs((*p)->pdg_id()) == 223 ) // omega*/
150  {
151 // // check if found is daughter of one already taken
152 // bool isUsed = false ;
153 // const HepMC::GenParticle* mother = (*p)->production_vertex() ?
154 // *((*p)->production_vertex()->particles_in_const_begin()) : 0 ;
155 // const HepMC::GenParticle* motherMother = (mother != 0 && mother->production_vertex()) ?
156 // *(mother->production_vertex()->particles_in_const_begin()) : 0 ;
157 // const HepMC::GenParticle* motherMotherMother = (motherMother != 0 && motherMother->production_vertex()) ?
158 // *(motherMother->production_vertex()->particles_in_const_begin()) : 0 ;
159 // for(itPart = takenEM.begin(); itPart != takenEM.end(); ++itPart) {
160 // if ((*itPart) == mother ||
161 // (*itPart) == motherMother ||
162 // (*itPart) == motherMotherMother)
163 // {
164 // isUsed = true ;
165 // break ;
166 // }
167 // }
168 // if (!isUsed) takenEM.push_back(*p);
169 
170  double pt=(*p)->momentum().perp();
171  if (pt == ptEM) continue ; //discard the same particle of the seed
172  double eta=(*p)->momentum().eta();
173  double phi=(*p)->momentum().phi();
174 
175  if(inEB) {
176  if( std::abs(eta-etaEM)> deltaEB ||
177  std::abs(deltaPhi(phi,phiEM)) > deltaEB) continue;
178  }
179  else if( std::abs((*p)->momentum().px()/(*p)->momentum().pz() - tgx)
180  > deltaEE ||
181  std::abs((*p)->momentum().py()/(*p)->momentum().pz() - tgy)
182  > deltaEE) continue;
183  ptEMClus += pt ;
184  if(inEB)
185  {
186  etaEMClus += (eta-etaEMClus)*pt/ptEMClus ;
187  phiEMClus += deltaPhi(phi,phiEM)*pt/ptEMClus;
188  }
189  else
190  {
191  etaEMClus += ((*p)->momentum().px()/(*p)->momentum().pz() - tgx)*pt/ptEMClus ;
192  phiEMClus += ((*p)->momentum().py()/(*p)->momentum().pz() - tgy)*pt/ptEMClus;
193  }
194  }
195  }
196  if( ptEMClus > eTSumMin)
197  accepted = true ;
198  }
199 
200  if (accepted) {
202  cout << "========> Event preselected " << theNumberOfSelected
203  << " Proccess ID " << myGenEvent->signal_process_id() << endl;
204  return true;
205  }
206  else return false;
207 }
208 
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::EDGetTokenT< edm::HepMCProduct > token_
int iEvent
Definition: GenABIO.cc:230
PythiaFilterEMJet(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
double p2[4]
Definition: TauolaWrapper.h:90
#define M_PI
double p1[4]
Definition: TauolaWrapper.h:89
tuple cout
Definition: gather_cfg.py:121
virtual bool filter(edm::Event &, const edm::EventSetup &)