CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimplePi0DiscAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecoEgamma/Examples
4 // Class: SimplePi0DiscAnalyzer
5 //
13 //
14 // Original Author: Aristotelis Kyriakis
15 // Created: May 26 13:22:06 CEST 2009
16 // $Id: SimplePi0DiscAnalyzer.cc,v 1.11 2010/10/19 17:39:21 wmtan Exp $
17 //
18 //
19 
20 // user include files
36 
37 #include "CLHEP/Units/PhysicalConstants.h"
38 #include <iostream>
39 #include "TMath.h"
40 #include "TFile.h"
41 #include "TH1F.h"
42 #include "TH1I.h"
43 #include "TH2F.h"
44 #include "TProfile.h"
45 #include "TTree.h"
46 #include <iostream>
47 
48 using namespace reco;
49 
51 {
52 
53  outputFile_ = conf.getParameter<std::string>("outputFile");
54  rootFile_ = new TFile(outputFile_.c_str(),"RECREATE");
55 
56 
57  photonCollectionProducer_ = conf.getParameter<std::string>("phoProducer");
58  photonCollection_ = conf.getParameter<std::string>("photonCollection");
59 
60 
61 
62 }
63 
65 {
66 
67  // do anything here that needs to be done at desctruction time
68  // (e.g. close files, deallocate resources etc.)
69  rootFile_->Write();
70  rootFile_->Close();
71 }
72 
74 
75  rootFile_->cd();
76  std::cout << "beginJob() -> Book the Histograms" << std::endl;
77 
78  hConv_ntracks_ = new TH1F("nConvTracks","Number of tracks of converted Photons ",10,0.,10);
79  hAll_nnout_Assoc_ = new TH1F("All_nnout_Assoc","NNout for All Photons(AssociationMap)",100,0.,1.);
80  hAll_nnout_NoConv_Assoc_ = new TH1F("All_nnout_NoConv_Assoc","NNout for Unconverted Photons(AssociationMap)",100,0.,1.);
81  hAll_nnout_NoConv_Assoc_R9_ = new TH1F("All_nnout_NoConv_Assoc_R9","NNout for Unconverted Photons with R9>0.93 (AssociationMap)",100,0.,1.);
82  hBarrel_nnout_Assoc_ = new TH1F("barrel_nnout_Assoc","NNout for Barrel Photons(AssociationMap)",100,0.,1.);
83  hBarrel_nnout_NoConv_Assoc_ = new TH1F("barrel_nnout_NoConv_Assoc","NNout for Barrel Unconverted Photons(AssociationMap)",100,0.,1.);
84  hBarrel_nnout_NoConv_Assoc_R9_ = new TH1F("barrel_nnout_NoConv_Assoc_R9","NNout for Barrel Unconverted Photons with R9>0.93 (AssociationMap)",100,0.,1.);
85  hEndcNoPresh_nnout_Assoc_ = new TH1F("endcNoPresh_nnout_Assoc","NNout for Endcap NoPresh Photons(AssociationMap)",100,0.,1.);
86  hEndcNoPresh_nnout_NoConv_Assoc_ = new TH1F("endcNoPresh_nnout_NoConv_Assoc","NNout for Endcap Unconverted NoPresh Photons(AssociationMap)",100,0.,1.);
87  hEndcNoPresh_nnout_NoConv_Assoc_R9_ = new TH1F("endcNoPresh_nnout_NoConv_Assoc_R9","NNout for Endcap Unconverted NoPresh Photons with R9>0.93 (AssociationMap)",100,0.,1.);
88  hEndcWithPresh_nnout_Assoc_ = new TH1F("endcWithPresh_nnout_Assoc","NNout for Endcap WithPresh Photons(AssociationMap)",100,0.,1.);
89  hEndcWithPresh_nnout_NoConv_Assoc_ = new TH1F("endcWithPresh_nnout_NoConv_Assoc","NNout for Endcap Unconverted WithPresh Photons(AssociationMap)",100,0.,1.);
90  hEndcWithPresh_nnout_NoConv_Assoc_R9_ = new TH1F("endcWithPresh_nnout_NoConv_Assoc_R9","NNout for Endcap Unconverted WithPresh Photons with R9>0.93 (AssociationMap)",100,0.,1.);
91 
92 }
93 
94 void
96 
97  rootFile_->cd();
98  std::cout << "endJob() -> Write the Histograms" << std::endl;
99  hConv_ntracks_->Write();
100 
101  hAll_nnout_Assoc_->Write();
102  hAll_nnout_NoConv_Assoc_->Write();
103  hAll_nnout_NoConv_Assoc_R9_->Write();
104  hBarrel_nnout_Assoc_->Write();
105  hBarrel_nnout_NoConv_Assoc_->Write();
106  hBarrel_nnout_NoConv_Assoc_R9_->Write();
107  hEndcNoPresh_nnout_Assoc_->Write();
108  hEndcNoPresh_nnout_NoConv_Assoc_->Write();
109  hEndcNoPresh_nnout_NoConv_Assoc_R9_->Write();
110  hEndcWithPresh_nnout_Assoc_->Write();
111  hEndcWithPresh_nnout_NoConv_Assoc_->Write();
112  hEndcWithPresh_nnout_NoConv_Assoc_R9_->Write();
113 
114 }
115 
116 void
118 {
119  std::cout << std::endl;
120  std::cout << " -------------- NEW EVENT : Run, Event = " << iEvent.id() << std::endl;
121 
123  iEvent.getByLabel(photonCollectionProducer_, photonCollection_ , PhotonHandle);
124  const reco::PhotonCollection photons = *(PhotonHandle.product());
125 
126  std::cout <<"----> Photons size: "<< photons.size()<<std::endl;
127 
129  iEvent.getByLabel("piZeroDiscriminators","PhotonPi0DiscriminatorAssociationMap", map);
131 
132 // int PhoInd = 0;
133 
134  for( reco::PhotonCollection::const_iterator iPho = photons.begin(); iPho != photons.end(); iPho++) { // Loop over Photons
135 
136  reco::Photon localPho(*iPho);
137 
138  float Photon_et = localPho.et(); float Photon_eta = localPho.eta();
139  float Photon_phi = localPho.phi(); float Photon_r9 = localPho.r9();
140  bool isPhotConv = localPho.hasConversionTracks();
141 // std::cout << "Photon Id = " << PhoInd
142  std::cout << "Photon Id = " << iPho - photons.begin()
143  << " with Et = " << Photon_et
144  << " Eta = " << Photon_eta
145  << " Phi = " << Photon_phi
146  << " R9 = " << Photon_r9
147  << " and conv_id = " << isPhotConv << std::endl;
148 
149 
150  SuperClusterRef it_super = localPho.superCluster(); // get the SC related to the Photon candidate
151 
152 // hConv_ntracks_->Fill(Ntrk_conv);
153 
154  float nn = -10;
155 // mapIter = map->find(edm::Ref<reco::PhotonCollection>(PhotonHandle,PhoInd));
156  mapIter = map->find(edm::Ref<reco::PhotonCollection>(PhotonHandle,iPho - photons.begin()));
157  if(mapIter!=map->end()) {
158  nn = mapIter->val;
159  }
160  if(fabs(it_super->eta()) <= 1.442) {
161  hBarrel_nnout_Assoc_->Fill(nn);
162  hAll_nnout_Assoc_->Fill(nn);
163  std::cout << "AssociationMap Barrel NN = " << nn << std::endl;
164  if(!isPhotConv) {
165  hBarrel_nnout_NoConv_Assoc_->Fill(nn);
166  hAll_nnout_NoConv_Assoc_->Fill(nn);
167  }
168  if(Photon_r9>0.93) {
169  hBarrel_nnout_NoConv_Assoc_R9_->Fill(nn);
170  hAll_nnout_NoConv_Assoc_R9_->Fill(nn);
171  }
172  } else if( (fabs(it_super->eta()) >= 1.556 && fabs(it_super->eta()) < 1.65) || fabs(it_super->eta()) > 2.5) {
173  hEndcNoPresh_nnout_Assoc_->Fill(nn);
174  hAll_nnout_Assoc_->Fill(nn);
175  std::cout << "AssociationMap EndcNoPresh NN = " << nn << std::endl;
176  if(!isPhotConv) {
177  hEndcNoPresh_nnout_NoConv_Assoc_->Fill(nn);
178  hAll_nnout_NoConv_Assoc_->Fill(nn);
179  }
180  if(Photon_r9>0.93) {
181  hEndcNoPresh_nnout_NoConv_Assoc_R9_->Fill(nn);
182  hAll_nnout_NoConv_Assoc_R9_->Fill(nn);
183  }
184  } else if(fabs(it_super->eta()) >= 1.65 && fabs(it_super->eta()) <= 2.5 ) {
185  hEndcWithPresh_nnout_Assoc_->Fill(nn);
186  hAll_nnout_Assoc_->Fill(nn);
187  std::cout << "AssociationMap EndcWithPresh NN = " << nn << std::endl;
188  if(!isPhotConv) {
189  hEndcWithPresh_nnout_NoConv_Assoc_->Fill(nn);
190  hAll_nnout_NoConv_Assoc_->Fill(nn);
191  }
192  if(Photon_r9>0.93) {
193  hEndcWithPresh_nnout_NoConv_Assoc_R9_->Fill(nn);
194  hAll_nnout_NoConv_Assoc_R9_->Fill(nn);
195  }
196  }
197 
198 
199 // PhoInd++;
200  } // End Loop over Photons
201 
202 }
203 //define this as a plug-in
205 
T getParameter(std::string const &) const
virtual double et() const GCC11_FINAL
transverse energy
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
Definition: Photon.cc:59
SimplePi0DiscAnalyzer(const edm::ParameterSet &conf)
dictionary map
Definition: Association.py:205
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
int iEvent
Definition: GenABIO.cc:243
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
tuple conf
Definition: dbtoconf.py:185
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
bool hasConversionTracks() const
Bool flagging photons with a vector of refereces to conversions with size &gt;0.
Definition: Photon.h:70
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
T const * product() const
Definition: Handle.h:74
edm::EventID id() const
Definition: EventBase.h:56
float r9() const
Definition: Photon.h:191
tuple cout
Definition: gather_cfg.py:121
virtual void analyze(const edm::Event &e, const edm::EventSetup &c)