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