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 NCSR "Demokritos" Athens
15 // D Maletic, "Vinca" Belgrade
16 // Created: May 26 13:22:06 CEST 2009
17 //
18 //
19 
32 
33 #include "CLHEP/Units/PhysicalConstants.h"
34 
35 #include "TFile.h"
36 #include "TH1F.h"
37 #include "TH1I.h"
38 #include "TH2F.h"
39 #include "TProfile.h"
40 #include "TTree.h"
41 
42 #include <iostream>
43 
45 public:
46  explicit SimplePi0DiscAnalyzer(const edm::ParameterSet& conf);
47 
48  ~SimplePi0DiscAnalyzer() override;
49 
50  void beginJob() override;
51  void endJob() override;
52  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
53 
54 private:
55  // ----------member data ---------------------------
56 
59 
61  TFile* rootFile_;
62 
64 
77 };
78 
81 
82 using namespace reco;
83 
85  outputFile_ = conf.getParameter<std::string>("outputFile");
86  rootFile_ = new TFile(outputFile_.c_str(), "RECREATE");
87 
88  photonCollectionProducer_ = conf.getParameter<std::string>("phoProducer");
89  photonCollection_ = conf.getParameter<std::string>("photonCollection");
90 }
91 
93  // do anything here that needs to be done at desctruction time
94  // (e.g. close files, deallocate resources etc.)
95  rootFile_->Write();
96  rootFile_->Close();
97 }
98 
100  rootFile_->cd();
101  std::cout << "beginJob() -> Book the Histograms" << std::endl;
102 
103  hConv_ntracks_ = new TH1F("nConvTracks", "Number of tracks of converted Photons ", 10, 0., 10);
104  hAll_nnout_Assoc_ = new TH1F("All_nnout_Assoc", "NNout for All Photons(AssociationMap)", 100, 0., 1.);
105  hAll_nnout_NoConv_Assoc_ =
106  new TH1F("All_nnout_NoConv_Assoc", "NNout for Unconverted Photons(AssociationMap)", 100, 0., 1.);
107  hAll_nnout_NoConv_Assoc_R9_ =
108  new TH1F("All_nnout_NoConv_Assoc_R9", "NNout for Unconverted Photons with R9>0.93 (AssociationMap)", 100, 0., 1.);
109  hBarrel_nnout_Assoc_ = new TH1F("barrel_nnout_Assoc", "NNout for Barrel Photons(AssociationMap)", 100, 0., 1.);
110  hBarrel_nnout_NoConv_Assoc_ =
111  new TH1F("barrel_nnout_NoConv_Assoc", "NNout for Barrel Unconverted Photons(AssociationMap)", 100, 0., 1.);
112  hBarrel_nnout_NoConv_Assoc_R9_ = new TH1F(
113  "barrel_nnout_NoConv_Assoc_R9", "NNout for Barrel Unconverted Photons with R9>0.93 (AssociationMap)", 100, 0., 1.);
114  hEndcNoPresh_nnout_Assoc_ =
115  new TH1F("endcNoPresh_nnout_Assoc", "NNout for Endcap NoPresh Photons(AssociationMap)", 100, 0., 1.);
116  hEndcNoPresh_nnout_NoConv_Assoc_ = new TH1F(
117  "endcNoPresh_nnout_NoConv_Assoc", "NNout for Endcap Unconverted NoPresh Photons(AssociationMap)", 100, 0., 1.);
118  hEndcNoPresh_nnout_NoConv_Assoc_R9_ =
119  new TH1F("endcNoPresh_nnout_NoConv_Assoc_R9",
120  "NNout for Endcap Unconverted NoPresh Photons with R9>0.93 (AssociationMap)",
121  100,
122  0.,
123  1.);
124  hEndcWithPresh_nnout_Assoc_ =
125  new TH1F("endcWithPresh_nnout_Assoc", "NNout for Endcap WithPresh Photons(AssociationMap)", 100, 0., 1.);
126  hEndcWithPresh_nnout_NoConv_Assoc_ = new TH1F(
127  "endcWithPresh_nnout_NoConv_Assoc", "NNout for Endcap Unconverted WithPresh Photons(AssociationMap)", 100, 0., 1.);
128  hEndcWithPresh_nnout_NoConv_Assoc_R9_ =
129  new TH1F("endcWithPresh_nnout_NoConv_Assoc_R9",
130  "NNout for Endcap Unconverted WithPresh Photons with R9>0.93 (AssociationMap)",
131  100,
132  0.,
133  1.);
134 }
135 
137  rootFile_->cd();
138  std::cout << "endJob() -> Write the Histograms" << std::endl;
139  hConv_ntracks_->Write();
140 
141  hAll_nnout_Assoc_->Write();
142  hAll_nnout_NoConv_Assoc_->Write();
143  hAll_nnout_NoConv_Assoc_R9_->Write();
144  hBarrel_nnout_Assoc_->Write();
145  hBarrel_nnout_NoConv_Assoc_->Write();
146  hBarrel_nnout_NoConv_Assoc_R9_->Write();
147  hEndcNoPresh_nnout_Assoc_->Write();
148  hEndcNoPresh_nnout_NoConv_Assoc_->Write();
149  hEndcNoPresh_nnout_NoConv_Assoc_R9_->Write();
150  hEndcWithPresh_nnout_Assoc_->Write();
151  hEndcWithPresh_nnout_NoConv_Assoc_->Write();
152  hEndcWithPresh_nnout_NoConv_Assoc_R9_->Write();
153 }
154 
156  std::cout << std::endl;
157  std::cout << " -------------- NEW EVENT : Run, Event = " << iEvent.id() << std::endl;
158 
160  iEvent.getByLabel(photonCollectionProducer_, photonCollection_, PhotonHandle);
161  const reco::PhotonCollection photons = *(PhotonHandle.product());
162 
163  std::cout << "----> Photons size: " << photons.size() << std::endl;
164 
166  iEvent.getByLabel("piZeroDiscriminators", "PhotonPi0DiscriminatorAssociationMap", map);
168 
169  // int PhoInd = 0;
170 
171  for (reco::PhotonCollection::const_iterator iPho = photons.begin(); iPho != photons.end();
172  iPho++) { // Loop over Photons
173 
174  reco::Photon localPho(*iPho);
175 
176  float Photon_et = localPho.et();
177  float Photon_eta = localPho.eta();
178  float Photon_phi = localPho.phi();
179  float Photon_r9 = localPho.r9();
180  bool isPhotConv = localPho.hasConversionTracks();
181  // std::cout << "Photon Id = " << PhoInd
182  std::cout << "Photon Id = " << iPho - photons.begin() << " with Et = " << Photon_et << " Eta = " << Photon_eta
183  << " Phi = " << Photon_phi << " R9 = " << Photon_r9 << " and conv_id = " << isPhotConv << std::endl;
184 
185  auto it_super = localPho.superCluster(); // get the SC related to the Photon candidate
186 
187  // hConv_ntracks_->Fill(Ntrk_conv);
188 
189  float nn = -10;
190  // mapIter = map->find(edm::Ref<reco::PhotonCollection>(PhotonHandle,PhoInd));
191  mapIter = map->find(edm::Ref<reco::PhotonCollection>(PhotonHandle, iPho - photons.begin()));
192  if (mapIter != map->end()) {
193  nn = mapIter->val;
194  }
195  if (fabs(it_super->eta()) <= 1.442) {
196  hBarrel_nnout_Assoc_->Fill(nn);
197  hAll_nnout_Assoc_->Fill(nn);
198  std::cout << "AssociationMap Barrel NN = " << nn << std::endl;
199  if (!isPhotConv) {
200  hBarrel_nnout_NoConv_Assoc_->Fill(nn);
201  hAll_nnout_NoConv_Assoc_->Fill(nn);
202  }
203  if (Photon_r9 > 0.93) {
204  hBarrel_nnout_NoConv_Assoc_R9_->Fill(nn);
205  hAll_nnout_NoConv_Assoc_R9_->Fill(nn);
206  }
207  } else if ((fabs(it_super->eta()) >= 1.556 && fabs(it_super->eta()) < 1.65) || fabs(it_super->eta()) > 2.5) {
208  hEndcNoPresh_nnout_Assoc_->Fill(nn);
209  hAll_nnout_Assoc_->Fill(nn);
210  std::cout << "AssociationMap EndcNoPresh NN = " << nn << std::endl;
211  if (!isPhotConv) {
212  hEndcNoPresh_nnout_NoConv_Assoc_->Fill(nn);
213  hAll_nnout_NoConv_Assoc_->Fill(nn);
214  }
215  if (Photon_r9 > 0.93) {
216  hEndcNoPresh_nnout_NoConv_Assoc_R9_->Fill(nn);
217  hAll_nnout_NoConv_Assoc_R9_->Fill(nn);
218  }
219  } else if (fabs(it_super->eta()) >= 1.65 && fabs(it_super->eta()) <= 2.5) {
220  hEndcWithPresh_nnout_Assoc_->Fill(nn);
221  hAll_nnout_Assoc_->Fill(nn);
222  std::cout << "AssociationMap EndcWithPresh NN = " << nn << std::endl;
223  if (!isPhotConv) {
224  hEndcWithPresh_nnout_NoConv_Assoc_->Fill(nn);
225  hAll_nnout_NoConv_Assoc_->Fill(nn);
226  }
227  if (Photon_r9 > 0.93) {
228  hEndcWithPresh_nnout_NoConv_Assoc_R9_->Fill(nn);
229  hAll_nnout_NoConv_Assoc_R9_->Fill(nn);
230  }
231  }
232 
233  // PhoInd++;
234  } // End Loop over Photons
235 }
Handle.h
EDAnalyzer.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
ESHandle.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SimplePi0DiscAnalyzer::rootFile_
TFile * rootFile_
Definition: SimplePi0DiscAnalyzer.cc:61
SimplePi0DiscAnalyzer::hAll_nnout_NoConv_Assoc_
TH1F * hAll_nnout_NoConv_Assoc_
Definition: SimplePi0DiscAnalyzer.cc:66
PhotonFwd.h
EDAnalyzer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
SimplePi0DiscAnalyzer::photonCollection_
std::string photonCollection_
Definition: SimplePi0DiscAnalyzer.cc:58
edm::Handle< reco::PhotonCollection >
edm::Ref
Definition: AssociativeIterator.h:58
SimplePi0DiscAnalyzer::hEndcNoPresh_nnout_Assoc_
TH1F * hEndcNoPresh_nnout_Assoc_
Definition: SimplePi0DiscAnalyzer.cc:69
MakerMacros.h
reco::Photon::hasConversionTracks
bool hasConversionTracks() const
Bool flagging photons with a vector of refereces to conversions with size >0.
Definition: Photon.h:67
Photon.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SimplePi0DiscAnalyzer::hBarrel_nnout_Assoc_
TH1F * hBarrel_nnout_Assoc_
Definition: SimplePi0DiscAnalyzer.cc:67
SimplePi0DiscAnalyzer::hBarrel_nnout_NoConv_Assoc_
TH1F * hBarrel_nnout_NoConv_Assoc_
Definition: SimplePi0DiscAnalyzer.cc:68
SimplePi0DiscAnalyzer::photonCollectionProducer_
std::string photonCollectionProducer_
Definition: SimplePi0DiscAnalyzer.cc:57
EcalSubdetector.h
edm::helpers::KeyVal::val
V val
Definition: AssociationMapHelpers.h:33
SimplePi0DiscAnalyzer::hEndcWithPresh_nnout_Assoc_
TH1F * hEndcWithPresh_nnout_Assoc_
Definition: SimplePi0DiscAnalyzer.cc:71
PhotonPi0DiscriminatorAssociation.h
edm::ParameterSet
Definition: ParameterSet.h:47
SimplePi0DiscAnalyzer::beginJob
void beginJob() override
Definition: SimplePi0DiscAnalyzer.cc:99
reco::Photon::r9
float r9() const
Definition: Photon.h:273
Event.h
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
SimplePi0DiscAnalyzer::hConv_ntracks_
TH1F * hConv_ntracks_
Definition: SimplePi0DiscAnalyzer.cc:63
SimplePi0DiscAnalyzer::hEndcNoPresh_nnout_NoConv_Assoc_
TH1F * hEndcNoPresh_nnout_NoConv_Assoc_
Definition: SimplePi0DiscAnalyzer.cc:70
iEvent
int iEvent
Definition: GenABIO.cc:224
SimplePi0DiscAnalyzer::~SimplePi0DiscAnalyzer
~SimplePi0DiscAnalyzer() override
Definition: SimplePi0DiscAnalyzer.cc:92
SimplePi0DiscAnalyzer::hAll_nnout_NoConv_Assoc_R9_
TH1F * hAll_nnout_NoConv_Assoc_R9_
Definition: SimplePi0DiscAnalyzer.cc:73
BPHMonitor_cfi.photons
photons
Definition: BPHMonitor_cfi.py:91
edm::EventSetup
Definition: EventSetup.h:58
SimplePi0DiscAnalyzer::hEndcWithPresh_nnout_NoConv_Assoc_R9_
TH1F * hEndcWithPresh_nnout_NoConv_Assoc_R9_
Definition: SimplePi0DiscAnalyzer.cc:76
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
groupFilesInBlocks.nn
nn
Definition: groupFilesInBlocks.py:150
reco::Photon
Definition: Photon.h:22
reco::LeafCandidate::et
double et() const final
transverse energy
Definition: LeafCandidate.h:127
SimplePi0DiscAnalyzer::hAll_nnout_Assoc_
TH1F * hAll_nnout_Assoc_
Definition: SimplePi0DiscAnalyzer.cc:65
SimplePi0DiscAnalyzer::outputFile_
std::string outputFile_
Definition: SimplePi0DiscAnalyzer.cc:60
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
SimplePi0DiscAnalyzer::hBarrel_nnout_NoConv_Assoc_R9_
TH1F * hBarrel_nnout_NoConv_Assoc_R9_
Definition: SimplePi0DiscAnalyzer.cc:74
SimplePi0DiscAnalyzer::endJob
void endJob() override
Definition: SimplePi0DiscAnalyzer.cc:136
EventSetup.h
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.cc:44
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
SimplePi0DiscAnalyzer::hEndcNoPresh_nnout_NoConv_Assoc_R9_
TH1F * hEndcNoPresh_nnout_NoConv_Assoc_R9_
Definition: SimplePi0DiscAnalyzer.cc:75
edm::Event
Definition: Event.h:73
SimplePi0DiscAnalyzer::hEndcWithPresh_nnout_NoConv_Assoc_
TH1F * hEndcWithPresh_nnout_NoConv_Assoc_
Definition: SimplePi0DiscAnalyzer.cc:72
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:155
SimplePi0DiscAnalyzer::SimplePi0DiscAnalyzer
SimplePi0DiscAnalyzer(const edm::ParameterSet &conf)
Definition: SimplePi0DiscAnalyzer.cc:84
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37