Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHAna.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHAna.cc
1 #include "PHAna.h"
2 
3 #include <phool/phool.h>
4 #include <phool/getClass.h>
7 #include <g4main/PHG4Particle.h>
8 #include <g4main/PHG4Hit.h>
9 #include <g4main/PHG4VtxPoint.h>
10 #include <fun4all/PHTFileServer.h>
11 #include <fun4all/Fun4AllServer.h>
12 
13 #include <TNtuple.h>
14 #include <TH1.h>
15 
16 #include <iostream>
17 
18 using namespace std;
19 
20 //____________________________________
21 PHAna::PHAna(const string &name):
22  SubsysReco(name),
23  _flags( NONE )
24 {
25  //initialize
26  _event = 0;
27  _outfile = "phana.root";
28  _truth = 0;
29  _sf = 0;
30  _hcalin_towers = 0;
31 }
32 
33 //___________________________________
35 {
36  cout << PHWHERE << " Openning file " << _outfile << endl;
37  PHTFileServer::get().open( _outfile, "RECREATE");
38 
39  if(_flags & TRUTH) _truth = new TNtuple("truth","truth","event:Energy:Rapidity:Pt:Phi:PID");
40  if(_flags & HIST ) create_histos();
41  if(_flags & SF ) _sf = new TNtuple("sf","sf","event:sfhcalin:sfhcalout:sfcemc");
42  return 0;
43 }
44 
45 //__________________________________
46 //Call user instructions for every event
48 {
49  _event++;
50  if(_event%1000==0) cout << PHWHERE << "Events processed: " << _event << endl;
51  GetNodes(topNode);
52  if(_flags & TRUTH) fill_truth_ntuple(topNode);
53 
54  if(_flags & HIST) fill_histos(topNode);
55 
56  if(_flags & SF) fill_sf_ntuple(topNode);
57 
58  return 0;
59 }
60 
61 //__________________________________
63 {
65  Fun4AllHistoManager *hm = se->getHistoManager("HISTOS");
66 
68  {
70  TH1F *h = (TH1F*) hm->getHisto("zvertex");
71  if(h) h->Fill( point->get_z() );
72  h = (TH1F*) hm->getHisto("xvertex");
73  if(h) h->Fill( point->get_x() );
74  h = (TH1F*) hm->getHisto("yvertex");
75  if(h) h->Fill( point->get_y() );
76  }
77 
78 }
79 
80 //_____________________________________
82 {
83  map<int, PHG4Particle*>::const_iterator particle_iter;
84  float ntvars[7];
85 
88 
89  for (PHG4TruthInfoContainer::ConstIterator particle_iter = primary_range.first;
90  particle_iter != primary_range.second; ++particle_iter)
91  {
92  PHG4Particle *particle = particle_iter->second;
93  ntvars[0] = _event;
94  ntvars[1] = particle->get_e();
95  ntvars[2] = 0.5*log((particle->get_e()+particle->get_pz())/
96  (particle->get_e()-particle->get_pz()));
97  ntvars[3] = sqrt(Square(particle->get_px())+Square(particle->get_py()));
98  ntvars[4] = atan2(particle->get_py(), particle->get_px());
99  ntvars[5] = particle->get_pid();
100  _truth->Fill( ntvars );
101  }
102 
103 }
104 
105 //_____________________________________
107 {
108  //Total Outer HCal energy deposited and light yield
109  float e_hcout = 0.;
110  float ev_hcout = 0.;
112  for(PHG4HitContainer::ConstIterator hit_iter = hcalout_hit_range.first;
113  hit_iter != hcalout_hit_range.second; hit_iter++)
114  {
115  PHG4Hit *this_hit = hit_iter->second;
116  e_hcout += this_hit->get_edep();
117  ev_hcout += this_hit->get_light_yield();
118  }
119 
120  //Total Outer HCal absorbed energy
121  float ea_hcout = 0.;
123  for (PHG4HitContainer::ConstIterator hit_iter = hcalout_abs_hit_range.first;
124  hit_iter != hcalout_abs_hit_range.second; hit_iter++)
125  {
126  PHG4Hit *this_hit = hit_iter->second;
127  ea_hcout += this_hit->get_edep();
128  }
129 
130  //Total Inner HCal energy deposit and light yield
131  float e_hcin =0.;
132  float ev_hcin = 0.;
134  for (PHG4HitContainer::ConstIterator hit_iter = hcalin_hit_range.first;
135  hit_iter != hcalin_hit_range.second; hit_iter++)
136  {
137  PHG4Hit *this_hit = hit_iter->second;
138  e_hcin += this_hit->get_edep();
139  ev_hcin += this_hit->get_light_yield();
140  }
141 
142  //Total Inner HCal absorbed energy
143  float ea_hcin = 0.;
145  for (PHG4HitContainer::ConstIterator hit_iter = hcalin_abs_hit_range.first;
146  hit_iter != hcalin_abs_hit_range.second; hit_iter++)
147  {
148  PHG4Hit *this_hit = hit_iter->second;
149 
150  ea_hcin += this_hit->get_edep();
151  }
152 
154  for (PHG4HitContainer::ConstIterator hit_iter = hcalin_spt_hit_range.first;
155  hit_iter != hcalin_spt_hit_range.second; hit_iter++)
156  {
157  PHG4Hit *this_hit = hit_iter->second;
158  ea_hcin += this_hit->get_edep();
159  }
160 
161  //Total EMCal deposited energy and light yield
162  float e_cemc = 0.;
163  float ev_cemc = 0.;
165  for (PHG4HitContainer::ConstIterator hit_iter = cemc_hit_range.first;
166  hit_iter != cemc_hit_range.second; hit_iter++)
167  {
168  PHG4Hit *this_hit = hit_iter->second;
169 
170  e_cemc += this_hit->get_edep();
171  ev_cemc += this_hit->get_light_yield();
172  }
173 
174  //Total EMCal absorbed energy
175  float ea_cemc = 0.;
177  for (PHG4HitContainer::ConstIterator hit_iter = cemc_abs_hit_range.first;
178  hit_iter != cemc_abs_hit_range.second; hit_iter++)
179  {
180  PHG4Hit *this_hit = hit_iter->second;
181  ea_cemc += this_hit->get_edep();
182  }
183 
185  for (PHG4HitContainer::ConstIterator hit_iter = cemc_electronics_hit_range.first;
186  hit_iter != cemc_electronics_hit_range.second; hit_iter++)
187  {
188  PHG4Hit *this_hit = hit_iter->second;
189 
190  ea_cemc += this_hit->get_edep();
191  }
192 
193 
194  float ntvars[4];
195  ntvars[0] = _event;
196  ntvars[1] = ev_hcin/(e_hcin+ea_hcin);
197  ntvars[2] = ev_hcout/(e_hcout+ea_hcout);
198  ntvars[3] = ev_cemc/(e_cemc+ea_cemc);
199 
200  _sf->Fill( ntvars );
201 }
202 
203 //___________________________________
205 {
207  Fun4AllHistoManager *hm = se->getHistoManager("HISTOS");
208  if (!hm)
209  {
210  hm = new Fun4AllHistoManager("HISTOS");
211  se->registerHistoManager(hm);
212  }
213  hm->registerHisto( new TH1F("zvertex","zvertex",120,-30,30) );
214  hm->registerHisto( new TH1F("xvertex","xvertex",120,-5,5) );
215  hm->registerHisto( new TH1F("yvertex","yvertex",120,-5,5) );
216 
217 }
218 
219 //___________________________________
221 {
222  //DST objects
223  //Truth container
224  _truth_container = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
225  if(!_truth_container && _event<2) cout << PHWHERE << " PHG4TruthInfoContainer node not found on node tree" << endl;
226 
227  //Outer HCal hit container
228  _hcalout_hit_container = findNode::getClass<PHG4HitContainer> (topNode, "G4HIT_HCALOUT");
229  if(!_hcalout_hit_container && _event<2) cout << PHWHERE << " G4HIT_HCALOUT node not found on node tree" << endl;
230 
231  //Outer HCal absorber hit container
232  _hcalout_abs_hit_container = findNode::getClass<PHG4HitContainer> (topNode, "G4HIT_ABSORBER_HCALOUT");
233  if(!_hcalout_abs_hit_container && _event<2) cout << PHWHERE << " G4HIT_ABSORBER_HCALOUT node not found on node tree" << endl;
234 
235  //Inner HCal hit container
236  _hcalin_hit_container = findNode::getClass<PHG4HitContainer> (topNode, "G4HIT_HCALIN");
237  if(!_hcalin_hit_container && _event<2) cout << PHWHERE << " G4HIT_HCALIN node not found on node tree" << endl;
238 
239  //Inner HCal absorber hit container
240  _hcalin_abs_hit_container = findNode::getClass<PHG4HitContainer> (topNode, "G4HIT_ABSORBER_HCALIN");
241  if(!_hcalin_abs_hit_container && _event<2) cout << PHWHERE << " G4HIT_ABSORBER_HCALIN node not found on node tree" << endl;
242 
243  //Inner HCal support structure hit container
244  _hcalin_spt_hit_container = findNode::getClass<PHG4HitContainer> (topNode, "G4HIT_HCALIN_SPT");
245  if(!_hcalin_spt_hit_container && _event<2) cout << PHWHERE << " G4HIT_HCALIN_SPT node not found on node tree" << endl;
246 
247  //EMCAL hit container
248  _cemc_hit_container = findNode::getClass<PHG4HitContainer> (topNode, "G4HIT_CEMC");
249  if(!_cemc_hit_container && _event<2) cout << PHWHERE << " G4HIT_CEMC node not found on node tree" << endl;
250 
251  //EMCal absorber hit container
252  _cemc_abs_hit_container = findNode::getClass<PHG4HitContainer> (topNode, "G4HIT_ABSORBER_CEMC");
253  if(!_cemc_abs_hit_container && _event<2) cout << PHWHERE << " G4HIT_ABSORBER_CEMC node not found on node tree" << endl;
254 
255  //EMCal Electronics hit container
256  _cemc_electronics_hit_container = findNode::getClass<PHG4HitContainer> (topNode, "G4HIT_CEMC_ELECTRONICS");
257  if(!_cemc_electronics_hit_container && _event<2) cout << PHWHERE << " G4HIT_CEMC_EMCELECTRONICS node not found on node tree" << endl;
258 
259 }
260 
261 //______________________________________
263 {
265  if( _truth ) _truth->Write();
266  if( _sf ) _sf->Write();
267  if(_flags & HIST)
268  {
270  Fun4AllHistoManager *hm = se->getHistoManager("HISTOS");
271  for(unsigned int i=0; i<hm->nHistos(); i++) hm->getHisto(i)->Write();
272  }
273  return 0;
274 }
275