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