Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetNconstituents.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetNconstituents.cc
1 //____________________________________________________________________________..
2 
3 #include "JetNconstituents.h"
4 
7 
9 #include <phool/getClass.h>
10 
11 #include <jetbase/JetMap.h>
12 #include <jetbase/Jetv1.h>
13 
15 
16 #include <calobase/RawTower.h>
17 #include <calobase/RawTowerContainer.h>
18 #include <calobase/RawTowerGeom.h>
19 #include <calobase/RawTowerGeomContainer.h>
20 #include <calobase/TowerInfoContainer.h>
21 #include <calobase/TowerInfo.h>
22 
24 
25 #include <TH2D.h>
26 #include <TH1D.h>
27 
28 #include <iostream>
29 #include <string>
30 #include <vector>
31 
32 //____________________________________________________________________________..
33 JetNconstituents::JetNconstituents(const std::string &recojetname, const std::string &outputfilename):
34 
35  SubsysReco("JetNconstituents_" + recojetname)
36  , m_recoJetName(recojetname)
37  , m_outputFileName(outputfilename)
38  , m_etaRange(-1.1, 1.1)
39  , m_ptRange(5, 100)
40 {
41  std::cout << "JetNconstituents::JetNconstituents(const std::string& recojetname, const std::string& outputfilename) Calling ctor" << std::endl;
42 }
43 
44 //____________________________________________________________________________..
46 {
47  std::cout << "JetNconstituents::~JetNconstituents() Calling dtor" << std::endl;
48 }
49 
50 
51 //____________________________________________________________________________..
53 {
54  std::cout << "JetNconstituents::Init(PHCompositeNode *topNode) Initializing" << std::endl;
56  std::cout << "JetValidation::Init - Output to " << m_outputFileName << std::endl;
57 
58  // configure histograms
59  h1d_nConsituents = new TH1D("h1d_nConsituents", "h1d_nConsituents", 300, 0, 300);
60  h1d_nConsituents->GetXaxis()->SetTitle("N_{Consts}");
61  h1d_nConsituents->GetYaxis()->SetTitle("Jet Counts");
62 
63  h1d_nConsituents_IHCal = new TH1D("h1d_nConsituents_IHCal", "h1d_nConsituents_IHCal", 300, 0, 300);
64  h1d_nConsituents_IHCal->GetXaxis()->SetTitle("N_{Consts}");
65  h1d_nConsituents_IHCal->GetYaxis()->SetTitle("Jet Counts");
66 
67  h1d_nConsituents_OHCal = new TH1D("h1d_nConsituents_OHCal", "h1d_nConsituents_OHCal", 300, 0, 300);
68  h1d_nConsituents_OHCal->GetXaxis()->SetTitle("N_{Consts}");
69  h1d_nConsituents_OHCal->GetYaxis()->SetTitle("Jet Counts");
70 
71  h1d_nConsituents_EMCal = new TH1D("h1d_nConsituents_EMCal", "h1d_nConsituents_EMCal", 300, 0, 300);
72  h1d_nConsituents_EMCal->GetXaxis()->SetTitle("N_{Consts}");
73  h1d_nConsituents_EMCal->GetYaxis()->SetTitle("Jet Counts");
74 
75  h1d_FracEnergy_EMCal = new TH1D("h1d_FracEnergy_EMCal", "h1d_FracEnergy_EMCal", 100, 0, 1);
76  h1d_FracEnergy_EMCal->GetXaxis()->SetTitle("Fraction of Jet Energy");
77  h1d_FracEnergy_EMCal->GetYaxis()->SetTitle("Jet Counts");
78 
79  h1d_FracEnergy_IHCal = new TH1D("h1d_FracEnergy_IHCal", "h1d_FracEnergy_IHCal", 100, 0, 1);
80  h1d_FracEnergy_IHCal->GetXaxis()->SetTitle("Fraction of Jet Energy");
81  h1d_FracEnergy_IHCal->GetYaxis()->SetTitle("Jet Counts");
82 
83  h1d_FracEnergy_OHCal = new TH1D("h1d_FracEnergy_OHCal", "h1d_FracEnergy_OHCal", 100, 0, 1);
84  h1d_FracEnergy_OHCal->GetXaxis()->SetTitle("Fraction of Jet Energy");
85  h1d_FracEnergy_OHCal->GetYaxis()->SetTitle("Jet Counts");
86 
87  h2d_FracEnergy_vs_CaloLayer = new TH2D("h2d_FracEnergy_vs_CaloLayer", "h2d_FracEnergy_vs_CaloLayer", 3, 0, 3, 100, 0, 1);
88  h2d_FracEnergy_vs_CaloLayer->GetXaxis()->SetTitle("Calorimeter Layer ID");
89  h2d_FracEnergy_vs_CaloLayer->GetYaxis()->SetTitle("Fraction of Jet Energy");
90  h2d_FracEnergy_vs_CaloLayer->GetXaxis()->SetBinLabel(1, "EMCal");
91  h2d_FracEnergy_vs_CaloLayer->GetXaxis()->SetBinLabel(2, "HCalIn");
92  h2d_FracEnergy_vs_CaloLayer->GetXaxis()->SetBinLabel(3, "HCalOut");
93 
94  h2d_nConstituent_vs_CaloLayer = new TH2D("h2d_nConstituent_vs_CaloLayer", "h2d_nConstituent_vs_CaloLayer", 3, 0, 3, 200, 0, 200);
95  h2d_nConstituent_vs_CaloLayer->GetXaxis()->SetTitle("Calorimeter Layer ID");
96  h2d_nConstituent_vs_CaloLayer->GetYaxis()->SetTitle("Number of Constituents");
97  h2d_nConstituent_vs_CaloLayer->GetXaxis()->SetBinLabel(1, "EMCal");
98  h2d_nConstituent_vs_CaloLayer->GetXaxis()->SetBinLabel(2, "HCalIn");
99  h2d_nConstituent_vs_CaloLayer->GetXaxis()->SetBinLabel(3, "HCalOut");
100 
102 }
103 
104 //____________________________________________________________________________..
106 {
107  std::cout << "JetNconstituents::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
109 }
110 
111 //____________________________________________________________________________..
113 {
114  //std::cout << "JetValidation::process_event(PHCompositeNode *topNode) Processing Event" << std::endl;
115 
116  // get the jets
117  JetMap* jets = findNode::getClass<JetMap>(topNode, m_recoJetName);
118  if(!jets){
119  std::cout << "JetNconstituents::process_event - Error can not find DST Reco JetMap node " << m_recoJetName << std::endl;
120  exit(-1);
121  }
122 
123  TowerInfoContainer *towersEM3 = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC_RETOWER");
124  TowerInfoContainer *towersIH3 = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALIN");
125  TowerInfoContainer *towersOH3 = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALOUT");
126  RawTowerGeomContainer *tower_geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
127  RawTowerGeomContainer *tower_geomOH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
128  if(!towersEM3 || !towersIH3 || !towersOH3){
129  std::cout
130  <<"MyJetAnalysis::process_event - Error can not find raw tower node "
131  << std::endl;
132  exit(-1);
133  }
134 
135  if(!tower_geom || !tower_geomOH){
136  std::cout
137  <<"MyJetAnalysis::process_event - Error can not find raw tower geometry "
138  << std::endl;
139  exit(-1);
140  }
141 
142  // loop over jets
143  for(JetMap::Iter iter = jets->begin(); iter != jets->end(); ++iter){
144 
145  Jet* jet = iter->second;
146 
147  // apply eta and pt cuts
148  bool eta_cut = (jet->get_eta() >= m_etaRange.first) and (jet->get_eta() <= m_etaRange.second);
149  bool pt_cut = (jet->get_pt() >= m_ptRange.first) and (jet->get_pt() <= m_ptRange.second);
150  if ((not eta_cut) or (not pt_cut)) continue;
151  // to remove noise jets
152  if(jet->get_pt() < 1) continue;
153 
154  // fill histograms
155  h1d_nConsituents->Fill(jet->size_comp());
156 
157  float ohcal_energy_sum = 0;
158  float ihcal_energy_sum = 0;
159  float emcal_energy_sum = 0;
160  // float jet_energy = jet->get_e();
161 
162 
163  float jet_energy_sum = 0;
164  int n_constituents_emcal = 0;
165  int n_constituents_ihcal = 0;
166  int n_constituents_ohcal = 0;
167  int nconst = 0;
168 
169  for (Jet::ConstIter comp = jet->begin_comp(); comp != jet->end_comp(); ++comp)
170  {
171  TowerInfo *tower;
172  nconst++;
173  unsigned int channel = (*comp).second;
174 
175  if ((*comp).first == 15 || (*comp).first == 30)
176  {
177  tower = towersIH3->get_tower_at_channel(channel);
178  if(!tower || !tower_geom){ continue; }
179  ihcal_energy_sum += tower->get_energy();
180  n_constituents_ihcal++;
181  jet_energy_sum += tower->get_energy();
182  }
183  else if ((*comp).first == 16 || (*comp).first == 31)
184  {
185  tower = towersOH3->get_tower_at_channel(channel);
186  if(!tower || !tower_geomOH){ continue; }
187  ohcal_energy_sum += tower->get_energy();
188  n_constituents_ohcal++;
189  jet_energy_sum += tower->get_energy();
190  }
191  else if ((*comp).first == 14 || (*comp).first == 29){
192  tower = towersEM3->get_tower_at_channel(channel);
193  if(!tower || !tower_geom){ continue; }
194  emcal_energy_sum += tower->get_energy();
195  n_constituents_emcal++;
196  jet_energy_sum += tower->get_energy();
197  }
198  }
199 
200  float eFrac_emcal = emcal_energy_sum/jet_energy_sum;
201  float eFrac_ihcal = ihcal_energy_sum/jet_energy_sum;
202  float eFrac_ohcal = ohcal_energy_sum/jet_energy_sum;
203 
204  // fill histograms
205  h1d_nConsituents_IHCal->Fill(n_constituents_ihcal);
206  h1d_nConsituents_OHCal->Fill(n_constituents_ohcal);
207  h1d_nConsituents_EMCal->Fill(n_constituents_emcal);
208  h1d_nConsituents->Fill(nconst);
209  h1d_FracEnergy_EMCal->Fill(eFrac_emcal);
210  h1d_FracEnergy_IHCal->Fill(eFrac_ihcal);
211  h1d_FracEnergy_OHCal->Fill(eFrac_ohcal);
212 
213  for (int ibin =1; ibin< h2d_FracEnergy_vs_CaloLayer->GetNbinsX()+1; ibin++){
214  float bin_center = h2d_FracEnergy_vs_CaloLayer->GetXaxis()->GetBinCenter(ibin);
215  if(ibin == 1){
216  h2d_FracEnergy_vs_CaloLayer->Fill(bin_center, eFrac_emcal);
217  h2d_nConstituent_vs_CaloLayer->Fill(bin_center, n_constituents_emcal);
218  }
219  else if(ibin == 2){
220  h2d_FracEnergy_vs_CaloLayer->Fill(bin_center, eFrac_ihcal);
221  h2d_nConstituent_vs_CaloLayer->Fill(bin_center, n_constituents_ihcal);
222  }
223  else if(ibin == 3){
224  h2d_FracEnergy_vs_CaloLayer->Fill(bin_center, eFrac_ohcal);
225  h2d_nConstituent_vs_CaloLayer->Fill(bin_center, n_constituents_ohcal);
226  }
227  }
228 
229  }
230 
231 
232 
234 }
235 
236 //____________________________________________________________________________..
238 {
239  // std::cout << "JetNconstituents::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl;
240 
242 }
243 
244 //____________________________________________________________________________..
246 {
247  std::cout << "JetNconstituents::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
248  std::cout << "JetValidation::End - Output to " << m_outputFileName << std::endl;
250  // float ptmin = m_ptRange.first;
251  // float ptmax = m_ptRange.second;
252 
253  // write histograms to root file
254  h1d_nConsituents->Write();
255  h1d_nConsituents_IHCal->Write();
256  h1d_nConsituents_OHCal->Write();
257  h1d_nConsituents_EMCal->Write();
258  h1d_FracEnergy_EMCal->Write();
259  h1d_FracEnergy_IHCal->Write();
260  h1d_FracEnergy_OHCal->Write();
263 
264 
265 
266 
267  std::cout << "JetValidation::End(PHCompositeNode *topNode) This is the End..." << std::endl;
268 
270 }
271 
272 //____________________________________________________________________________..
274 {
275  std::cout << "JetNconstituents::End(PHCompositeNode *topNode) This is the End..." << std::endl;
277 }
278 
279 //____________________________________________________________________________..
281 {
282  //std::cout << "JetNconstituents::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
284 }
285 
286 //____________________________________________________________________________..
287 void JetNconstituents::Print(const std::string &what) const
288 {
289  std::cout << "JetNconstituents::Print(const std::string &what) const Printing info for " << what << std::endl;
290 }