CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PythiaFilterGammaJetWithOutBg.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 token_(consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared"))),
42 etaMax(iConfig.getUntrackedParameter<double>("MaxPhotonEta", 2.8)),
43 ptSeed(iConfig.getUntrackedParameter<double>("PhotonSeedPt", 5.)),
44 ptMin(iConfig.getUntrackedParameter<double>("MinPhotonPt")),
45 ptMax(iConfig.getUntrackedParameter<double>("MaxPhotonPt")),
46 dphiMin(iConfig.getUntrackedParameter<double>("MinDeltaPhi", -1)/180*M_PI),
47 detaMax(iConfig.getUntrackedParameter<double>("MaxDeltaEta", 10.)),
48 etaPhotonCut2(iConfig.getUntrackedParameter<double>("MinPhotonEtaForwardJet", 1.3)),
49 cone(0.5),ebEtaMax(1.479),
50 maxnumberofeventsinrun(iConfig.getUntrackedParameter<int>("MaxEvents",10)){
51 
52  deltaEB=0.01745/2 *5; // delta_eta, delta_phi
53  deltaEE=2.93/317/2 *5; // delta_x/z, delta_y/z
55 }
56 
57 
59 
60 
61 // ------------ method called to produce the data ------------
63 
64 // <<<<<<< PythiaFilterGammaJetWithOutBg.cc
65 // if(theNumberOfSelected>=maxnumberofeventsinrun) {
66 // throw cms::Exception("endJob")<<"we have reached the maximum number of events ";
67 // }
68 // =======
69 // >>>>>>> 1.4
70 
71  bool accepted = false;
73  iEvent.getByToken(token_, evt);
74 
75  std::list<const HepMC::GenParticle *> seeds;
76  const HepMC::GenEvent * myGenEvent = evt->GetEvent();
77 
78  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end(); ++p ) {
79 
80  if ( (*p)->pdg_id()==22 && (*p)->status()==1
81  && (*p)->momentum().perp() > ptSeed
82  && std::abs((*p)->momentum().eta()) < etaMax ) seeds.push_back(*p);
83 
84  }
85 
86  seeds.sort(ParticlePtGreater());
87 
88 // std::cout<<" Number of seeds "<<seeds.size()<<" ProccessID "<<myGenEvent->signal_process_id()<<std::endl;
89 // std::cout<<" ParticleId 7= "<<myGenEvent->particle(7)->pdg_id()
90 // <<" pT "<<myGenEvent->particle(7)->momentum().perp()
91 // <<" Eta "<<myGenEvent->particle(7)->momentum().eta()
92 // <<" Phi "<<myGenEvent->particle(7)->momentum().phi()<<std::endl;
93 // std::cout<<" ParticleId 8= "<<myGenEvent->particle(8)->pdg_id()<<" pT "<<myGenEvent->particle(8)->momentum().perp()<<" Eta "<<myGenEvent->particle(8)->momentum().eta()<<" Phi "<<myGenEvent->particle(8)->momentum().phi()<<std::endl;
94 
95  for(std::list<const HepMC::GenParticle *>::const_iterator is=
96  seeds.begin(); is!=seeds.end(); is++){
97 
98  double etaPhoton=(*is)->momentum().eta();
99  double phiPhoton=(*is)->momentum().phi();
100 
101  /*
102  double dphi7=std::abs(deltaPhi(phiPhoton,
103  myGenEvent->particle(7)->momentum().phi()));
104  double dphi=std::abs(deltaPhi(phiPhoton,
105  myGenEvent->particle(8)->momentum().phi()));
106  */
107 
108  HepMC::GenEvent::particle_const_iterator ppp = myGenEvent->particles_begin();
109  for(int i=0;i<6;++i) ppp++;
110  HepMC::GenParticle* particle7 = (*ppp);
111  ppp++;
112  HepMC::GenParticle* particle8 = (*ppp);
113 
114  double dphi7=std::abs(deltaPhi(phiPhoton,
115  particle7->momentum().phi()));
116  double dphi=std::abs(deltaPhi(phiPhoton,
117  particle8->momentum().phi()));
118 
119  int jetline=8;
120  if(dphi7>dphi) {
121  dphi=dphi7;
122  jetline=7;
123  }
124 
125 // std::cout<<" Dphi "<<dphi<<" "<<dphiMin<<std::endl;
126 // if(dphi<dphiMin) {
127 // std::cout<<"Reject dphi"<<std::endl;
128 // continue;
129 // }
130 
131 // double etaJet= myGenEvent->particle(jetline)->momentum().eta();
132  double etaJet = 0.0;
133  if(jetline==8) etaJet = particle8->momentum().eta();
134  else etaJet = particle7->momentum().eta();
135 
136  double eta1=etaJet-detaMax;
137  double eta2=etaJet+detaMax;
138  if (eta1>etaPhotonCut2) eta1=etaPhotonCut2;
139  if (eta2<-etaPhotonCut2) eta2=-etaPhotonCut2;
140 
141 // std::cout<<" Etaphoton "<<etaPhoton<<" "<<eta1<<" "<<eta2<<std::endl;
142 
143  if (etaPhoton<eta1 ||etaPhoton>eta2) {
144 // std::cout<<"Reject eta"<<std::endl;
145  continue;
146  }
147  bool inEB(0);
148  double tgx(0);
149  double tgy(0);
150  if( std::abs(etaPhoton)<ebEtaMax) inEB=1;
151  else{
152  tgx=(*is)->momentum().px()/(*is)->momentum().pz();
153  tgy=(*is)->momentum().py()/(*is)->momentum().pz();
154  }
155 
156  double etPhoton=0;
157  double etPhotonCharged=0;
158  double etCone=0;
159  double etConeCharged=0;
160  double ptMaxHadron=0;
161 
162 
163  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end(); ++p ) {
164 
165  if ( (*p)->status()!=1 ) continue;
166  int pid= (*p)->pdg_id();
167  int apid= std::abs(pid);
168  if (apid>11 && apid<21) continue; //get rid of muons and neutrinos
169  double eta=(*p)->momentum().eta();
170  double phi=(*p)->momentum().phi();
171  if (deltaR2(etaPhoton, phiPhoton, eta, phi)>cone*cone) continue;
172  double pt=(*p)->momentum().perp();
173 
174 // double charge=(*p)->particledata().charge();
175 // int charge3=(*p)->particleID().threeCharge();
176 
177  //***
179  iSetup.getData( pdt );
180  int charge3 = ((pdt->particle((*p)->pdg_id()))->ID().threeCharge());
181  //***
182 
183  etCone+=pt;
184  if(charge3 && pt<2) etConeCharged+=pt;
185 
186  //select particles matching a crystal array centered on photon
187  if(inEB) {
188  if( std::abs(eta-etaPhoton)> deltaEB ||
189  std::abs(deltaPhi(phi,phiPhoton)) > deltaEB) continue;
190  }
191  else if( std::abs((*p)->momentum().px()/(*p)->momentum().pz() - tgx)
192  > deltaEE ||
193  std::abs((*p)->momentum().py()/(*p)->momentum().pz() - tgy)
194  > deltaEE) continue;
195 
196  etPhoton+=pt;
197  if(charge3 && pt<2) etPhotonCharged+=pt;
198  if(apid>100 && apid!=310 && pt>ptMaxHadron) ptMaxHadron=pt;
199 
200  }
201 // std::cout<<" etPhoton "<<etPhoton<<" "<<ptMin<<" "<<ptMax<<std::endl;
202  if(etPhoton<ptMin ||etPhoton>ptMax) {
203 // std::cout<<" Reject etPhoton "<<std::endl;
204  continue;
205  }
206  //isolation cuts
207 
208 // double isocut1 = 5+etPhoton/20-etPhoton*etPhoton/1e4;
209 // double isocut2 = 3+etPhoton/20-etPhoton*etPhoton*etPhoton/1e6;
210 // double isocut3 = 4.5+etPhoton/40;
211 // if (etPhoton>165.)
212 // {
213 // isocut1 = 5.+165./20.-165.*165./1e4;
214 // isocut2 = 3.+165./20.-165.*165.*165./1e6;
215 // isocut3 = 4.5+165./40.;
216 // }
217 // std::cout<<" etCone "<<etCone<<" "<<etPhoton<<" "<<etCone-etPhoton<<" "<<isocut1<<std::endl;
218 // std::cout<<"Second cut on iso "<<etCone-etPhoton-(etConeCharged-etPhotonCharged)<<" cut value "<<isocut2<<" etPhoton "<<etPhoton<<std::endl;
219 // std::cout<<" PtHadron "<<ptMaxHadron<<" "<<4.5+etPhoton/40<<std::endl;
220 // if(etCone-etPhoton> 5+etPhoton/20-etPhoton*etPhoton/1e4) continue;
221 // std::cout<<" Accept 1"<<std::endl;
222 // if(etCone-etPhoton-(etConeCharged-etPhotonCharged) >
223 // isocut2) continue;
224 // std::cout<<" Accept 2"<<std::endl;
225 // if(ptMaxHadron > isocut3) continue;
226 // std::cout<<"Accept event "<<std::endl;
227 
228  accepted=true;
229  break;
230 
231  } //loop over seeds
232 
233 
234  if (accepted) {
236  std::cout<<" Event preselected "<<theNumberOfSelected<<" Proccess ID "<<myGenEvent->signal_process_id()<<std::endl;
237  return true;
238  }
239  else return false;
240 
241 }
242 
int i
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< edm::HepMCProduct > token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
void getData(T &iHolder) const
Definition: EventSetup.h:79
int iEvent
Definition: GenABIO.cc:230
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
bool operator()(const HepMC::GenParticle *a, const HepMC::GenParticle *b) const
PythiaFilterGammaJetWithOutBg(const edm::ParameterSet &)
tuple pid
Definition: sysUtil.py:22
Geom::Phi< T > phi() const
double p1[4]
Definition: TauolaWrapper.h:89
tuple cout
Definition: gather_cfg.py:121
virtual bool filter(edm::Event &, const edm::EventSetup &)