CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PythiaFilterGammaJetWithBg.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 // <<<<<<< PythiaFilterGammaJetWithBg.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  //***
109  HepMC::GenEvent::particle_const_iterator ppp = myGenEvent->particles_begin();
110  for(int i=0;i<6;++i) ppp++;
111  HepMC::GenParticle* particle7 = (*ppp);
112  ppp++;
113  HepMC::GenParticle* particle8 = (*ppp);
114 
115  double dphi7=std::abs(deltaPhi(phiPhoton,
116  particle7->momentum().phi()));
117  double dphi=std::abs(deltaPhi(phiPhoton,
118  particle8->momentum().phi()));
119  //***
120 
121  int jetline=8;
122  if(dphi7>dphi) {
123  dphi=dphi7;
124  jetline=7;
125  }
126 
127 // std::cout<<" Dphi "<<dphi<<" "<<dphiMin<<std::endl;
128 // if(dphi<dphiMin) {
129 // std::cout<<"Reject dphi"<<std::endl;
130 // continue;
131 // }
132 
133  //double etaJet= myGenEvent->particle(jetline)->momentum().eta();
134  //***
135  double etaJet = 0.0;
136  if(jetline==8) etaJet = particle8->momentum().eta();
137  else etaJet = particle7->momentum().eta();
138  //***
139 
140  double eta1=etaJet-detaMax;
141  double eta2=etaJet+detaMax;
142  if (eta1>etaPhotonCut2) eta1=etaPhotonCut2;
143  if (eta2<-etaPhotonCut2) eta2=-etaPhotonCut2;
144 // std::cout<<" Etaphoton "<<etaPhoton<<" "<<eta1<<" "<<eta2<<std::endl;
145  if (etaPhoton<eta1 ||etaPhoton>eta2) {
146 // std::cout<<"Reject eta"<<std::endl;
147  continue;
148  }
149  bool inEB(0);
150  double tgx(0);
151  double tgy(0);
152  if( std::abs(etaPhoton)<ebEtaMax) inEB=1;
153  else{
154  tgx=(*is)->momentum().px()/(*is)->momentum().pz();
155  tgy=(*is)->momentum().py()/(*is)->momentum().pz();
156  }
157 
158  double etPhoton=0;
159  double etPhotonCharged=0;
160  double etCone=0;
161  double etConeCharged=0;
162  double ptMaxHadron=0;
163 
164 
165  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end(); ++p ) {
166 
167  if ( (*p)->status()!=1 ) continue;
168  int pid= (*p)->pdg_id();
169  int apid= std::abs(pid);
170  if (apid>11 && apid<21) continue; //get rid of muons and neutrinos
171  double eta=(*p)->momentum().eta();
172  double phi=(*p)->momentum().phi();
173  if (deltaR2(etaPhoton, phiPhoton, eta, phi)>cone*cone) continue;
174  double pt=(*p)->momentum().perp();
175 
176  //***
178  iSetup.getData( pdt );
179 
180 
181  // double charge=(*p)->particledata().charge();
182  // int charge3=(*p)->particleID().threeCharge();
183 
184  int charge3 = ((pdt->particle((*p)->pdg_id()))->ID().threeCharge());
185  //***
186 
187  etCone+=pt;
188  if(charge3 && pt<2) etConeCharged+=pt;
189 
190  //select particles matching a crystal array centered on photon
191  if(inEB) {
192  if( std::abs(eta-etaPhoton)> deltaEB ||
193  std::abs(deltaPhi(phi,phiPhoton)) > deltaEB) continue;
194  }
195  else if( std::abs((*p)->momentum().px()/(*p)->momentum().pz() - tgx)
196  > deltaEE ||
197  std::abs((*p)->momentum().py()/(*p)->momentum().pz() - tgy)
198  > deltaEE) continue;
199 
200  etPhoton+=pt;
201  if(charge3 && pt<2) etPhotonCharged+=pt;
202  if(apid>100 && apid!=310 && pt>ptMaxHadron) ptMaxHadron=pt;
203 
204  }
205 // std::cout<<" etPhoton "<<etPhoton<<" "<<ptMin<<" "<<ptMax<<std::endl;
206 
207  if(etPhoton<ptMin ||etPhoton>ptMax) {
208 // std::cout<<" Reject etPhoton "<<std::endl;
209  continue;
210  }
211  //isolation cuts
212 
213 // double isocut1 = 5+etPhoton/20-etPhoton*etPhoton/1e4;
214  double isocut2 = 3+etPhoton/20-etPhoton*etPhoton*etPhoton/1e6;
215  double isocut3 = 4.5+etPhoton/40;
216  if (etPhoton>165.)
217  {
218 // isocut1 = 5.+165./20.-165.*165./1e4;
219  isocut2 = 3.+165./20.-165.*165.*165./1e6;
220  isocut3 = 4.5+165./40.;
221  }
222 
223 // std::cout<<" etCone "<<etCone<<" "<<etPhoton<<" "<<etCone-etPhoton<<" "<<isocut1<<std::endl;
224 // std::cout<<"Second cut on iso "<<etCone-etPhoton-(etConeCharged-etPhotonCharged)<<" cut value "<<isocut2<<" etPhoton "<<etPhoton<<std::endl;
225 // std::cout<<" PtHadron "<<ptMaxHadron<<" "<<4.5+etPhoton/40<<std::endl;
226 
227  if(etCone-etPhoton> 5+etPhoton/20-etPhoton*etPhoton/1e4) continue;
228 // std::cout<<" Accept 1"<<std::endl;
229  if(etCone-etPhoton-(etConeCharged-etPhotonCharged) >
230  isocut2) continue;
231 // std::cout<<" Accept 2"<<std::endl;
232  if(ptMaxHadron > isocut3) continue;
233 
234 // std::cout<<"Accept event "<<std::endl;
235  accepted=true;
236  break;
237 
238  } //loop over seeds
239 
240 
241  if (accepted) {
243  std::cout<<" Event preselected "<<theNumberOfSelected<<" Proccess ID "<<myGenEvent->signal_process_id()<<std::endl;
244  return true;
245  }
246  else return false;
247 
248 }
249 
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
virtual bool filter(edm::Event &, const edm::EventSetup &)
bool operator()(const HepMC::GenParticle *a, const HepMC::GenParticle *b) const
PythiaFilterGammaJetWithBg(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