CMS 3D CMS Logo

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  outputFile_ = conf.getParameter<std::string>("outputFile");
51  rootFile_ = new TFile(outputFile_.c_str(), "RECREATE");
52 
53  photonCollectionProducer_ = conf.getParameter<std::string>("phoProducer");
54  photonCollection_ = conf.getParameter<std::string>("photonCollection");
55 }
56 
58  // do anything here that needs to be done at desctruction time
59  // (e.g. close files, deallocate resources etc.)
60  rootFile_->Write();
61  rootFile_->Close();
62 }
63 
65  rootFile_->cd();
66  std::cout << "beginJob() -> Book the Histograms" << std::endl;
67 
68  hConv_ntracks_ = new TH1F("nConvTracks", "Number of tracks of converted Photons ", 10, 0., 10);
69  hAll_nnout_Assoc_ = new TH1F("All_nnout_Assoc", "NNout for All Photons(AssociationMap)", 100, 0., 1.);
70  hAll_nnout_NoConv_Assoc_ =
71  new TH1F("All_nnout_NoConv_Assoc", "NNout for Unconverted Photons(AssociationMap)", 100, 0., 1.);
72  hAll_nnout_NoConv_Assoc_R9_ =
73  new TH1F("All_nnout_NoConv_Assoc_R9", "NNout for Unconverted Photons with R9>0.93 (AssociationMap)", 100, 0., 1.);
74  hBarrel_nnout_Assoc_ = new TH1F("barrel_nnout_Assoc", "NNout for Barrel Photons(AssociationMap)", 100, 0., 1.);
75  hBarrel_nnout_NoConv_Assoc_ =
76  new TH1F("barrel_nnout_NoConv_Assoc", "NNout for Barrel Unconverted Photons(AssociationMap)", 100, 0., 1.);
77  hBarrel_nnout_NoConv_Assoc_R9_ = new TH1F(
78  "barrel_nnout_NoConv_Assoc_R9", "NNout for Barrel Unconverted Photons with R9>0.93 (AssociationMap)", 100, 0., 1.);
79  hEndcNoPresh_nnout_Assoc_ =
80  new TH1F("endcNoPresh_nnout_Assoc", "NNout for Endcap NoPresh Photons(AssociationMap)", 100, 0., 1.);
81  hEndcNoPresh_nnout_NoConv_Assoc_ = new TH1F(
82  "endcNoPresh_nnout_NoConv_Assoc", "NNout for Endcap Unconverted NoPresh Photons(AssociationMap)", 100, 0., 1.);
83  hEndcNoPresh_nnout_NoConv_Assoc_R9_ =
84  new TH1F("endcNoPresh_nnout_NoConv_Assoc_R9",
85  "NNout for Endcap Unconverted NoPresh Photons with R9>0.93 (AssociationMap)",
86  100,
87  0.,
88  1.);
89  hEndcWithPresh_nnout_Assoc_ =
90  new TH1F("endcWithPresh_nnout_Assoc", "NNout for Endcap WithPresh Photons(AssociationMap)", 100, 0., 1.);
91  hEndcWithPresh_nnout_NoConv_Assoc_ = new TH1F(
92  "endcWithPresh_nnout_NoConv_Assoc", "NNout for Endcap Unconverted WithPresh Photons(AssociationMap)", 100, 0., 1.);
93  hEndcWithPresh_nnout_NoConv_Assoc_R9_ =
94  new TH1F("endcWithPresh_nnout_NoConv_Assoc_R9",
95  "NNout for Endcap Unconverted WithPresh Photons with R9>0.93 (AssociationMap)",
96  100,
97  0.,
98  1.);
99 }
100 
102  rootFile_->cd();
103  std::cout << "endJob() -> Write the Histograms" << std::endl;
104  hConv_ntracks_->Write();
105 
106  hAll_nnout_Assoc_->Write();
107  hAll_nnout_NoConv_Assoc_->Write();
108  hAll_nnout_NoConv_Assoc_R9_->Write();
109  hBarrel_nnout_Assoc_->Write();
110  hBarrel_nnout_NoConv_Assoc_->Write();
111  hBarrel_nnout_NoConv_Assoc_R9_->Write();
112  hEndcNoPresh_nnout_Assoc_->Write();
113  hEndcNoPresh_nnout_NoConv_Assoc_->Write();
114  hEndcNoPresh_nnout_NoConv_Assoc_R9_->Write();
115  hEndcWithPresh_nnout_Assoc_->Write();
116  hEndcWithPresh_nnout_NoConv_Assoc_->Write();
117  hEndcWithPresh_nnout_NoConv_Assoc_R9_->Write();
118 }
119 
121  std::cout << std::endl;
122  std::cout << " -------------- NEW EVENT : Run, Event = " << iEvent.id() << std::endl;
123 
125  iEvent.getByLabel(photonCollectionProducer_, photonCollection_, PhotonHandle);
126  const reco::PhotonCollection photons = *(PhotonHandle.product());
127 
128  std::cout << "----> Photons size: " << photons.size() << std::endl;
129 
131  iEvent.getByLabel("piZeroDiscriminators", "PhotonPi0DiscriminatorAssociationMap", map);
133 
134  // int PhoInd = 0;
135 
136  for (reco::PhotonCollection::const_iterator iPho = photons.begin(); iPho != photons.end();
137  iPho++) { // Loop over Photons
138 
139  reco::Photon localPho(*iPho);
140 
141  float Photon_et = localPho.et();
142  float Photon_eta = localPho.eta();
143  float Photon_phi = localPho.phi();
144  float Photon_r9 = localPho.r9();
145  bool isPhotConv = localPho.hasConversionTracks();
146  // std::cout << "Photon Id = " << PhoInd
147  std::cout << "Photon Id = " << iPho - photons.begin() << " with Et = " << Photon_et << " Eta = " << Photon_eta
148  << " Phi = " << Photon_phi << " R9 = " << Photon_r9 << " and conv_id = " << isPhotConv << std::endl;
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  // PhoInd++;
199  } // End Loop over Photons
200 }
201 //define this as a plug-in
CaloJetCollection.h
reco::Photon::superCluster
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EDAnalyzer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle< reco::PhotonCollection >
BasicClusterFwd.h
ElectronSeedFwd.h
edm::Ref< SuperClusterCollection >
MakerMacros.h
reco::Photon::hasConversionTracks
bool hasConversionTracks() const
Bool flagging photons with a vector of refereces to conversions with size >0.
Definition: Photon.h:66
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GsfElectron.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalSubdetector.h
edm::helpers::KeyVal::val
V val
Definition: AssociationMapHelpers.h:33
GsfElectronFwd.h
edm::ParameterSet
Definition: ParameterSet.h:47
SimplePi0DiscAnalyzer::beginJob
void beginJob() override
Definition: SimplePi0DiscAnalyzer.cc:64
reco::Photon::r9
float r9() const
Definition: Photon.h:240
Event.h
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
iEvent
int iEvent
Definition: GenABIO.cc:224
SimplePi0DiscAnalyzer::~SimplePi0DiscAnalyzer
~SimplePi0DiscAnalyzer() override
Definition: SimplePi0DiscAnalyzer.cc:57
GsfTrack.h
BPHMonitor_cfi.photons
photons
Definition: BPHMonitor_cfi.py:91
edm::EventSetup
Definition: EventSetup.h:57
groupFilesInBlocks.nn
nn
Definition: groupFilesInBlocks.py:150
reco::Photon
Definition: Photon.h:21
reco::LeafCandidate::et
double et() const final
transverse energy
Definition: LeafCandidate.h:127
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
SuperClusterFwd.h
SimplePi0DiscAnalyzer::endJob
void endJob() override
Definition: SimplePi0DiscAnalyzer.cc:101
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
reco::PhotonCollection
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
SimplePi0DiscAnalyzer
Definition: SimplePi0DiscAnalyzer.h:40
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
edm::Event
Definition: Event.h:73
SimplePi0DiscAnalyzer.h
edm::AssociationMap::const_iterator
const iterator
Definition: AssociationMap.h:76
SimplePi0DiscAnalyzer::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: SimplePi0DiscAnalyzer.cc:120
ElectronSeed.h
SimplePi0DiscAnalyzer::SimplePi0DiscAnalyzer
SimplePi0DiscAnalyzer(const edm::ParameterSet &conf)
Definition: SimplePi0DiscAnalyzer.cc:49