CMS 3D CMS Logo

PatPhotonSimpleAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PatPhotonSimpleAnalyzer
4 // Class: PatPhotonSimpleAnalyzer
5 //
14 //
15 // Original Author: M.B. Anderson
16 // based on simple photon analyzer by: J. Stilley, A. Askew
17 //
18 // Created: Wed Sep 23 12:00:01 CDT 2008
19 //
21 // header file for this analyzer //
24 
26 // CMSSW includes //
30 
32 // Root include files //
34 #include "TH1.h"
35 #include "TFile.h"
36 #include "TMath.h"
37 #include "TTree.h"
38 
39 using namespace std;
40 
42 // Constructor //
45 {
46  // Read Parameters from configuration file
47 
48  // output filename
49  outputFile_ = ps.getParameter<std::string>("outputFile");
50  // Read variables that must be passed to allow a
51  // supercluster to be placed in histograms as a photon.
52  minPhotonEt_ = ps.getParameter<double>("minPhotonEt");
53  minPhotonAbsEta_ = ps.getParameter<double>("minPhotonAbsEta");
54  maxPhotonAbsEta_ = ps.getParameter<double>("maxPhotonAbsEta");
55  minPhotonR9_ = ps.getParameter<double>("minPhotonR9");
56  maxPhotonHoverE_ = ps.getParameter<double>("maxPhotonHoverE");
57 
58  // Read variable to that decidedes whether
59  // a TTree of photons is created or not
60  createPhotonTTree_ = ps.getParameter<bool>("createPhotonTTree");
61 
62  // open output file to store histograms
63  rootFile_ = TFile::Open(outputFile_.c_str(),"RECREATE");
64 }
65 
67 // Destructor //
70 {
71 
72 // do anything here that needs to be done at desctruction time
73 // (e.g. close files, deallocate resources etc.)
74 
75  delete rootFile_;
76 
77 }
78 
80 // method called once each job just before starting event loop //
82 void
84 {
85 
86  // go to *OUR* rootfile
87  rootFile_->cd();
88 
89  // Book Histograms
90  // PhotonID Histograms
91  h_isoEcalRecHit_ = new TH1F("photonEcalIso", "Ecal Rec Hit Isolation", 100, 0, 100);
92  h_isoHcalRecHit_ = new TH1F("photonHcalIso", "Hcal Rec Hit Isolation", 100, 0, 100);
93  h_trk_pt_solid_ = new TH1F("photonTrackSolidIso", "Sum of track pT in a cone of #DeltaR" , 100, 0, 100);
94  h_trk_pt_hollow_ = new TH1F("photonTrackHollowIso", "Sum of track pT in a hollow cone" , 100, 0, 100);
95  h_ntrk_solid_ = new TH1F("photonTrackCountSolid", "Number of tracks in a cone of #DeltaR", 100, 0, 100);
96  h_ntrk_hollow_ = new TH1F("photonTrackCountHollow", "Number of tracks in a hollow cone", 100, 0, 100);
97  h_ebgap_ = new TH1F("photonInEBgap", "Ecal Barrel gap flag", 2, -0.5, 1.5);
98  h_eeGap_ = new TH1F("photonInEEgap", "Ecal Endcap gap flag", 2, -0.5, 1.5);
99  h_ebeeGap_ = new TH1F("photonInEEgap", "Ecal Barrel/Endcap gap flag", 2, -0.5, 1.5);
100  h_r9_ = new TH1F("photonR9", "R9 = E(3x3) / E(SuperCluster)", 300, 0, 3);
101 
102  // Photon Histograms
103  h_photonEt_ = new TH1F("photonEt", "Photon E_{T}", 200, 0, 200);
104  h_photonEta_ = new TH1F("photonEta", "Photon #eta", 200, -4, 4);
105  h_photonPhi_ = new TH1F("photonPhi", "Photon #phi", 200, -1.*TMath::Pi(), TMath::Pi());
106  h_hadoverem_ = new TH1F("photonHoverE", "Hadronic over EM", 200, 0, 1);
107 
108  // Photon's SuperCluster Histograms
109  h_photonScEt_ = new TH1F("photonScEt", "Photon SuperCluster E_{T}", 200, 0, 200);
110  h_photonScEta_ = new TH1F("photonScEta", "Photon #eta", 200, -4, 4);
111  h_photonScPhi_ = new TH1F("photonScPhi", "Photon #phi", 200, -1.*TMath::Pi(), TMath::Pi());
112  h_photonScEtaWidth_ = new TH1F("photonScEtaWidth","#eta-width", 100, 0, .1);
113 
114  // Composite or Other Histograms
115  h_photonInAnyGap_ = new TH1F("photonInAnyGap", "Photon in any gap flag", 2, -0.5, 1.5);
116  h_nPassingPho_ = new TH1F("photonPassingCount", "Total number photons (0=NotPassing, 1=Passing)", 2, -0.5, 1.5);
117  h_nPho_ = new TH1F("photonCount", "Number of photons passing cuts in event", 10, 0, 10);
118 
119  // Create a TTree of photons if set to 'True' in config file
120  if ( createPhotonTTree_ ) {
121  tree_PhotonAll_ = new TTree("TreePhotonAll", "Reconstructed Photon");
122  tree_PhotonAll_->Branch("recPhoton", &recPhoton.isolationEcalRecHit, "isolationEcalRecHit/F:isolationHcalRecHit:isolationSolidTrkCone:isolationHollowTrkCone:nTrkSolidCone:nTrkHollowCone:isEBGap:isEEGap:isEBEEGap:r9:et:eta:phi:hadronicOverEm:ecalIso:hcalIso:trackIso");
123  }
124 }
125 
127 // method called to for each event //
129 void
131 {
132 
133  using namespace std;
134  using namespace edm;
135 
136  // Grab pat::Photon
137  Handle< View<pat::Photon> > photonHandle;
138  evt.getByLabel("selectedLayer1Photons", photonHandle);
139  View<pat::Photon> photons = *photonHandle;
140 
141  int photonCounter = 0;
142 
143  for (int i=0; i<int(photons.size()); i++)
144  {
145 
146  pat::Photon currentPhoton = photons.at(i);
147 
148  float photonEt = currentPhoton.et();
149  float superClusterEt = (currentPhoton.superCluster()->energy())/(cosh(currentPhoton.superCluster()->position().eta()));
150 
151  // Only store photon candidates (SuperClusters) that pass some simple cuts
152  bool passCuts = ( photonEt > minPhotonEt_ ) &&
153  ( fabs(currentPhoton.eta()) > minPhotonAbsEta_ ) &&
154  ( fabs(currentPhoton.eta()) < maxPhotonAbsEta_ ) &&
155  ( currentPhoton.r9() > minPhotonR9_ ) &&
156  ( currentPhoton.hadronicOverEm() < maxPhotonHoverE_ ) ;
157 
158  if ( passCuts )
159  {
161  // fill histograms //
163  // PhotonID Variables
164  h_isoEcalRecHit_->Fill(currentPhoton.ecalRecHitSumEtConeDR04());
165  h_isoHcalRecHit_->Fill(currentPhoton.hcalTowerSumEtConeDR04());
166  h_trk_pt_solid_ ->Fill(currentPhoton.trkSumPtSolidConeDR04());
167  h_trk_pt_hollow_->Fill(currentPhoton.trkSumPtHollowConeDR04());
168  h_ntrk_solid_-> Fill(currentPhoton.nTrkSolidConeDR04());
169  h_ntrk_hollow_-> Fill(currentPhoton.nTrkHollowConeDR04());
170  h_ebgap_-> Fill(currentPhoton.isEBGap());
171  h_eeGap_-> Fill(currentPhoton.isEEGap());
172  h_ebeeGap_-> Fill(currentPhoton.isEBEEGap());
173  h_r9_-> Fill(currentPhoton.r9());
174 
175  // Photon Variables
176  h_photonEt_-> Fill(photonEt);
177  h_photonEta_-> Fill(currentPhoton.eta());
178  h_photonPhi_-> Fill(currentPhoton.phi());
179  h_hadoverem_-> Fill(currentPhoton.hadronicOverEm());
180 
181  // Photon's SuperCluster Variables
182  // eta is with respect to detector (not physics) vertex,
183  // thus Et and eta are different from photon.
184  h_photonScEt_-> Fill(superClusterEt);
185  h_photonScEta_-> Fill(currentPhoton.superCluster()->position().eta());
186  h_photonScPhi_-> Fill(currentPhoton.superCluster()->position().phi());
187  h_photonScEtaWidth_->Fill(currentPhoton.superCluster()->etaWidth());
188 
189  // It passed photon cuts, mark it
190  h_nPassingPho_->Fill(1.0);
191 
193  // fill TTree (optional) //
195  if ( createPhotonTTree_ ) {
196  recPhoton.isolationEcalRecHit = currentPhoton.ecalRecHitSumEtConeDR04();
197  recPhoton.isolationHcalRecHit = currentPhoton.hcalTowerSumEtConeDR04();
198  recPhoton.isolationSolidTrkCone = currentPhoton.trkSumPtSolidConeDR04();
199  recPhoton.isolationHollowTrkCone = currentPhoton.trkSumPtHollowConeDR04();
200  recPhoton.nTrkSolidCone = currentPhoton.nTrkSolidConeDR04();
201  recPhoton.nTrkHollowCone = currentPhoton.nTrkHollowConeDR04();
202  recPhoton.isEBGap = currentPhoton.isEBGap();
203  recPhoton.isEEGap = currentPhoton.isEEGap();
204  recPhoton.isEBEEGap = currentPhoton.isEBEEGap();
205  recPhoton.r9 = currentPhoton.r9();
206  recPhoton.et = currentPhoton.et();
207  recPhoton.eta = currentPhoton.eta();
208  recPhoton.phi = currentPhoton.phi();
209  recPhoton.hadronicOverEm = currentPhoton.hadronicOverEm();
210  recPhoton.ecalIso = currentPhoton.ecalIso();
211  recPhoton.hcalIso = currentPhoton.hcalIso();
212  recPhoton.trackIso = currentPhoton.trackIso();
213 
214  // Fill the tree (this records all the recPhoton.* since
215  // tree_PhotonAll_ was set to point at that.
216  tree_PhotonAll_->Fill();
217  }
218 
219  // Record whether it was near any module gap.
220  // Very convoluted at the moment.
221  bool inAnyGap = currentPhoton.isEBEEGap() || (currentPhoton.isEB()&&currentPhoton.isEBGap()) || (currentPhoton.isEE()&&currentPhoton.isEEGap());
222  if (inAnyGap) {
223  h_photonInAnyGap_->Fill(1.0);
224  } else {
225  h_photonInAnyGap_->Fill(0.0);
226  }
227 
228  photonCounter++;
229  }
230  else
231  {
232  // This didn't pass photon cuts, mark it
233  h_nPassingPho_->Fill(0.0);
234  }
235 
236  } // End Loop over photons
237  h_nPho_->Fill(photonCounter);
238 
239 }
240 
242 // method called once each job just after ending the event loop //
244 void
246 {
247 
248  // go to *OUR* root file and store histograms
249  rootFile_->cd();
250 
251  // PhotonID Histograms
252  h_isoEcalRecHit_->Write();
253  h_isoHcalRecHit_->Write();
254  h_trk_pt_solid_-> Write();
255  h_trk_pt_hollow_->Write();
256  h_ntrk_solid_-> Write();
257  h_ntrk_hollow_-> Write();
258  h_ebgap_-> Write();
259  h_eeGap_-> Write();
260  h_ebeeGap_-> Write();
261  h_r9_-> Write();
262 
263  // Photon Histograms
264  h_photonEt_-> Write();
265  h_photonEta_-> Write();
266  h_photonPhi_-> Write();
267  h_hadoverem_-> Write();
268 
269  // Photon's SuperCluster Histograms
270  h_photonScEt_-> Write();
271  h_photonScEta_-> Write();
272  h_photonScPhi_-> Write();
273  h_photonScEtaWidth_->Write();
274 
275  // Composite or Other Histograms
276  h_photonInAnyGap_->Write();
277  h_nPassingPho_-> Write();
278  h_nPho_-> Write();
279 
280  // Write the root file (really writes the TTree)
281  rootFile_->Write();
282  rootFile_->Close();
283 
284 }
285 
286 //define this as a plug-in
287 // DEFINE_FWK_MODULE(PatPhotonSimpleAnalyzer);
const double Pi
T getParameter(std::string const &) const
float hcalTowerSumEtConeDR04() const
Hcal isolation sum.
Definition: Photon.h:412
Analysis-level Photon class.
Definition: Photon.h:47
float trackIso() const
Definition: Photon.h:116
double eta() const final
momentum pseudorapidity
bool isEE() const
Definition: Photon.h:123
bool isEBGap() const
true if photon is in EB, and inside the boundaries in super crystals/modules
Definition: Photon.h:125
PatPhotonSimpleAnalyzer(const edm::ParameterSet &)
float trkSumPtSolidConeDR04() const
Definition: Photon.h:424
bool isEBEEGap() const
true if photon is in boundary between EB and EE
Definition: Photon.h:133
size_type size() const
float ecalRecHitSumEtConeDR04() const
Definition: Photon.h:410
float hcalIso() const
Definition: Photon.h:122
reco::SuperClusterRef superCluster() const override
override the superCluster method from CaloJet, to access the internal storage of the supercluster ...
double et() const final
transverse energy
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void analyze(const edm::Event &, const edm::EventSetup &) override
int nTrkHollowConeDR04() const
Definition: Photon.h:430
float hadronicOverEm() const
the total hadronic over electromagnetic fraction
Definition: Photon.h:206
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
bool isEEGap() const
true if photon is in EE, and inside the boundaries in supercrystal/D
Definition: Photon.h:129
float ecalIso() const
Definition: Photon.h:119
int nTrkSolidConeDR04() const
Definition: Photon.h:428
bool isEB() const
Definition: Photon.h:121
float trkSumPtHollowConeDR04() const
Definition: Photon.h:426
HLT enums.
float r9() const
Definition: Photon.h:234
const_reference at(size_type pos) const
double phi() const final
momentum azimuthal angle