CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimplePhotonAnalyzer.cc
Go to the documentation of this file.
1 
11 
15 //
25 //
26 #include "CLHEP/Units/GlobalPhysicalConstants.h"
27 #include "TFile.h"
28 
29 //========================================================================
31 //========================================================================
32 {
34  photonCollection_ = ps.getParameter<std::string>("photonCollection");
35 
36  barrelEcalHits_ = ps.getParameter<edm::InputTag>("barrelEcalHits");
37  endcapEcalHits_ = ps.getParameter<edm::InputTag>("endcapEcalHits");
38 
39 
40 
41  mcProducer_ = ps.getParameter<std::string>("mcProducer");
42  //mcCollection_ = ps.getParameter<std::string>("mcCollection");
43  vertexProducer_ = ps.getParameter<std::string>("primaryVertexProducer");
44  sample_ = ps.getParameter<int>("sample");
45 
46 
47 }
48 
49 
50 //========================================================================
52 //========================================================================
53 {
54 
55 
56 }
57 
58 //========================================================================
59 void
61 //========================================================================
62 
64 
65  float hiE=0;
66  float loE=0;
67  float hiEt=0;
68  float loEt=0;
69  float dPhi=0;
70  float loRes=0;
71  float hiRes=0;
72  if ( sample_ ==1 ) {
73  loE=0.;
74  hiE=30.;
75  loEt=0.;
76  hiEt=30.;
77  dPhi=0.2;
78  loRes=0.;
79  hiRes=1.2;
80  } else if ( sample_ ==2 ) {
81  loE=0.;
82  hiE=200.;
83  loEt=0.;
84  hiEt=50.;
85  dPhi=0.05;
86  loRes=0.7;
87  hiRes=1.2;
88  } else if ( sample_ ==3 ) {
89  loE=0.;
90  hiE=500.;
91  loEt=0.;
92  hiEt=500.;
93  dPhi=0.05;
94  loRes=0.7;
95  hiRes=1.2;
96  } else if (sample_==4) {
97  loE=0.;
98  hiE=6000.;
99  loEt=0.;
100  hiEt=1200.;
101  dPhi=0.05;
102  loRes=0.7;
103  hiRes=1.2;
104  }
105 
106 
107  effEta_ = fs->make<TProfile> ("effEta"," Photon reconstruction efficiency",50,-2.5,2.5);
108  effPhi_ = fs->make<TProfile> ("effPhi"," Photon reconstruction efficiency",80, -3.14, 3.14);
109 
110  h1_deltaEta_ = fs->make<TH1F>("deltaEta"," Reco photon Eta minus Generated photon Eta ",100,-0.2, 0.2);
111  h1_deltaPhi_ = fs->make<TH1F>("deltaPhi","Reco photon Phi minus Generated photon Phi ",100,-dPhi, dPhi);
112  h1_pho_Eta_ = fs->make<TH1F>("phoEta","Photon Eta ",40,-3., 3.);
113  h1_pho_Phi_ = fs->make<TH1F>("phoPhi","Photon Phi ",40,-3.14, 3.14);
114  h1_pho_E_ = fs->make<TH1F>("phoE","Photon Energy ",100,loE,hiE);
115  h1_pho_Et_ = fs->make<TH1F>("phoEt","Photon Et ",100,loEt,hiEt);
116 
117  h1_scEta_ = fs->make<TH1F>("scEta"," SC Eta ",40,-3., 3.);
118  h1_deltaEtaSC_ = fs->make<TH1F>("deltaEtaSC"," SC Eta minus Generated photon Eta ",100,-0.02, 0.02);
119 
120  //
121  h1_recEoverTrueEBarrel_ = fs->make<TH1F>("recEoverTrueEBarrel"," Reco photon Energy over Generated photon Energy: Barrel ",100,loRes, hiRes);
122  h1_recEoverTrueEEndcap_ = fs->make<TH1F>("recEoverTrueEEndcap"," Reco photon Energy over Generated photon Energy: Endcap ",100,loRes, hiRes);
123 
124  //
125 
126  h1_pho_R9Barrel_ = fs->make<TH1F>("phoR9Barrel","Photon 3x3 energy / SuperCluster energy : Barrel ",100,0.,1.2);
127  h1_pho_R9Endcap_ = fs->make<TH1F>("phoR9Endcap","Photon 3x3 energy / SuperCluster energy : Endcap ",100,0.,1.2);
128  h1_pho_sigmaIetaIetaBarrel_ = fs->make<TH1F>("sigmaIetaIetaBarrel", "sigmaIetaIeta: Barrel",100,0., 0.05) ;
129  h1_pho_sigmaIetaIetaEndcap_ = fs->make<TH1F>("sigmaIetaIetaEndcap" , "sigmaIetaIeta: Endcap",100,0., 0.1) ;
130  h1_pho_hOverEBarrel_ = fs->make<TH1F>("hOverEBarrel", "H/E: Barrel",100,0., 0.1) ;
131  h1_pho_hOverEEndcap_ = fs->make<TH1F>("hOverEEndcap", "H/E: Endcap",100,0., 0.1) ;
132  h1_pho_ecalIsoBarrel_ = fs->make<TH1F>("ecalIsolBarrel", "isolation et sum in Ecal: Barrel",100,0., 100.) ;
133  h1_pho_ecalIsoEndcap_ = fs->make<TH1F>("ecalIsolEndcap", "isolation et sum in Ecal: Endcap",100,0., 100.) ;
134  h1_pho_hcalIsoBarrel_ = fs->make<TH1F>("hcalIsolBarrel", "isolation et sum in Hcal: Barrel",100,0., 100.) ;
135  h1_pho_hcalIsoEndcap_ = fs->make<TH1F>("hcalIsolEndcap", "isolation et sum in Hcal: Endcap",100,0., 100.) ;
136  h1_pho_trkIsoBarrel_ = fs->make<TH1F>("trkIsolBarrel", "isolation pt sum in the tracker: Barrel",100,0., 100.) ;
137  h1_pho_trkIsoEndcap_ = fs->make<TH1F>("trkIsolEndcap", "isolation pt sum in the tracker: Endcap",100,0., 100.) ;
138 
139 
140 
141 
142 
143 }
144 
145 
146 //========================================================================
147 void
149 //========================================================================
150 
151  using namespace edm; // needed for all fwk related classes
152  edm::LogInfo("PhotonAnalyzer") << "Analyzing event number: " << evt.id() << "\n";
153 
154 
155  // get the calo topology from the event setup:
156  edm::ESHandle<CaloTopology> pTopology;
158 
159 
160 
161  // Get the corrected photon collection (set in the configuration) which also contains infos about conversions
162 
163  Handle<reco::PhotonCollection> photonHandle;
165  const reco::PhotonCollection photonCollection = *(photonHandle.product());
166 
167  Handle< HepMCProduct > hepProd ;
168  evt.getByLabel( mcProducer_.c_str(), hepProd ) ;
169  const HepMC::GenEvent * myGenEvent = hepProd->GetEvent();
170 
171 
172  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end(); ++p ) {
173  if ( !( (*p)->pdg_id() == 22 && (*p)->status()==1 ) ) continue;
174 
175  // single primary photons or photons from Higgs or RS Graviton
176  HepMC::GenParticle* mother = 0;
177  if ( (*p)->production_vertex() ) {
178  if ( (*p)->production_vertex()->particles_begin(HepMC::parents) !=
179  (*p)->production_vertex()->particles_end(HepMC::parents))
180  mother = *((*p)->production_vertex()->particles_begin(HepMC::parents));
181  }
182  if ( ((mother == 0) || ((mother != 0) && (mother->pdg_id() == 25))
183  || ((mother != 0) && (mother->pdg_id() == 22)))) {
184 
185  float minDelta=10000.;
186  std::vector<reco::Photon> localPhotons;
187  int index=0;
188  int iMatch=-1;
189 
190  float phiPho=(*p)->momentum().phi();
191  float etaPho=(*p)->momentum().eta();
192  etaPho = etaTransformation(etaPho, (*p)->production_vertex()->position().z()/10. );
193 
194  bool matched=false;
195  // loop Photon candidates
196  for( reco::PhotonCollection::const_iterator iPho = photonCollection.begin(); iPho != photonCollection.end(); iPho++) {
197  reco::Photon localPho = reco::Photon(*iPho);
198  localPhotons.push_back(localPho);
199 
201  float phiClu=localPho.phi();
202  float etaClu=localPho.eta();
203  float deltaPhi = phiClu-phiPho;
204  float deltaEta = etaClu-etaPho;
205 
206  if ( deltaPhi > pi ) deltaPhi -= twopi;
207  if ( deltaPhi < -pi) deltaPhi += twopi;
208  deltaPhi=std::pow(deltaPhi,2);
209  deltaEta=std::pow(deltaEta,2);
210  float delta = sqrt( deltaPhi+deltaEta);
211  if ( delta<0.1 && delta < minDelta ) {
212  minDelta=delta;
213  iMatch=index;
214 
215  }
216  index++;
217  } // End loop over photons
218 
219  double wt=0.;
220  if ( iMatch>-1 ) matched = true;
221 
223  if (matched ) {
224  wt=1.;
225 
226  effEta_ ->Fill ( etaPho, wt);
227  effPhi_ ->Fill ( phiPho, wt);
228  reco::Photon matchingPho = localPhotons[iMatch];
229 
230  bool phoIsInBarrel=false;
231  if ( fabs(matchingPho.superCluster()->position().eta() ) < 1.479 ) {
232  phoIsInBarrel=true;
233  }
234  edm::Handle<EcalRecHitCollection> ecalRecHitHandle;
235 
236 
237  h1_scEta_->Fill( matchingPho.superCluster()->position().eta() );
238  float trueEta= (*p)->momentum().eta() ;
239  trueEta = etaTransformation(trueEta, (*p)->production_vertex()->position().z()/10. );
240  h1_deltaEtaSC_ -> Fill( localPhotons[iMatch].superCluster()->eta()- trueEta );
241 
242  float photonE = matchingPho.energy();
243  float photonEt= matchingPho.et() ;
244  float photonEta= matchingPho.eta() ;
245  float photonPhi= matchingPho.phi() ;
246 
247  float r9 = matchingPho.r9();
248  float sigmaIetaIeta = matchingPho.sigmaIetaIeta();
249  float hOverE = matchingPho.hadronicOverEm();
250  float ecalIso = matchingPho.ecalRecHitSumEtConeDR04();
251  float hcalIso = matchingPho.hcalTowerSumEtConeDR04();
252  float trkIso = matchingPho.trkSumPtSolidConeDR04();
253 
254 
255  h1_pho_E_->Fill( photonE );
256  h1_pho_Et_->Fill( photonEt );
257  h1_pho_Eta_->Fill( photonEta );
258  h1_pho_Phi_->Fill( photonPhi );
259 
260  h1_deltaEta_ -> Fill( photonEta - (*p)->momentum().eta() );
261  h1_deltaPhi_ -> Fill( photonPhi - (*p)->momentum().phi() );
262 
263  if ( phoIsInBarrel ) {
264  h1_recEoverTrueEBarrel_ -> Fill ( photonE / (*p)->momentum().e() );
265  h1_pho_R9Barrel_->Fill( r9 );
266  h1_pho_sigmaIetaIetaBarrel_->Fill ( sigmaIetaIeta );
267  h1_pho_hOverEBarrel_-> Fill ( hOverE );
268  h1_pho_ecalIsoBarrel_-> Fill ( ecalIso );
269  h1_pho_hcalIsoBarrel_-> Fill ( hcalIso );
270  h1_pho_trkIsoBarrel_-> Fill ( trkIso );
271 
272  } else {
273  h1_recEoverTrueEEndcap_ -> Fill ( photonE / (*p)->momentum().e() );
274  h1_pho_R9Endcap_->Fill( r9 );
275  h1_pho_sigmaIetaIetaEndcap_->Fill ( sigmaIetaIeta );
276  h1_pho_hOverEEndcap_-> Fill ( hOverE );
277  h1_pho_ecalIsoEndcap_-> Fill ( ecalIso );
278  h1_pho_hcalIsoEndcap_-> Fill ( hcalIso );
279  h1_pho_trkIsoEndcap_-> Fill ( trkIso );
280 
281 
282  }
283 
284 
285  } // reco photon matching MC truth
286 
287 
288 
289 
290  } // End loop over MC particles
291 
292  }
293 
294 
295 }
296 
297 
298 float SimplePhotonAnalyzer::etaTransformation( float EtaParticle , float Zvertex) {
299 
300  //---Definitions
301  const float PI = 3.1415927;
302  //UNUSED const float TWOPI = 2.0*PI;
303 
304  //---Definitions for ECAL
305  const float R_ECAL = 136.5;
306  const float Z_Endcap = 328.0;
307  const float etaBarrelEndcap = 1.479;
308 
309  //---ETA correction
310 
311  float Theta = 0.0 ;
312  float ZEcal = R_ECAL*sinh(EtaParticle)+Zvertex;
313 
314  if(ZEcal != 0.0) Theta = atan(R_ECAL/ZEcal);
315  if(Theta<0.0) Theta = Theta+PI ;
316  float ETA = - log(tan(0.5*Theta));
317 
318  if( fabs(ETA) > etaBarrelEndcap )
319  {
320  float Zend = Z_Endcap ;
321  if(EtaParticle<0.0 ) Zend = -Zend ;
322  float Zlen = Zend - Zvertex ;
323  float RR = Zlen/sinh(EtaParticle);
324  Theta = atan(RR/Zend);
325  if(Theta<0.0) Theta = Theta+PI ;
326  ETA = - log(tan(0.5*Theta));
327  }
328  //---Return the result
329  return ETA;
330  //---end
331 }
332 
333 
334 
335 
336 //========================================================================
337 void
339 //========================================================================
340 
341 
342 
343 }
dbl * delta
Definition: mlp_gen.cc:36
virtual double energy() const GCC11_FINAL
energy
T getParameter(std::string const &) const
virtual double et() const GCC11_FINAL
transverse energy
float hcalTowerSumEtConeDR04() const
Hcal isolation sum.
Definition: Photon.h:340
TPRegexp parents
Definition: eve_filter.cc:24
float etaTransformation(float a, float b)
#define PI
float trkSumPtSolidConeDR04() const
Definition: Photon.h:352
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
Definition: Photon.cc:59
float ecalRecHitSumEtConeDR04() const
Definition: Photon.h:338
T eta() const
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
#define ETA
edm::ESHandle< CaloTopology > theCaloTopo_
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T sqrt(T t)
Definition: SSEVec.h:48
float sigmaIetaIeta() const
Definition: Photon.h:188
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
float hadronicOverEm() const
the total hadronic over electromagnetic fraction
Definition: Photon.h:167
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
SimplePhotonAnalyzer(const edm::ParameterSet &)
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
const T & get() const
Definition: EventSetup.h:55
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
static const float etaBarrelEndcap
static const float Z_Endcap
edm::EventID id() const
Definition: EventBase.h:56
float r9() const
Definition: Photon.h:191
T * make() const
make new ROOT object
static const float R_ECAL
double pi
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::string photonCollectionProducer_