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