Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TowerTiming.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TowerTiming.cc
1 #include "TowerTiming.h"
2 
3 #include <calobase/RawTowerGeomContainer.h>
4 #include <calobase/RawTowerContainer.h>
5 #include <calobase/RawTower.h>
6 
8 #include <g4main/PHG4Particle.h>
9 #include <g4main/PHG4VtxPoint.h>
10 
12 
13 #include <phool/getClass.h>
14 
15 #include <TFile.h>
16 #include <TH1.h>
17 #include <TH2.h>
18 #include <TNtuple.h>
19 
20 #include<sstream>
21 
22 using namespace std;
23 
25  SubsysReco( name ),
26  hm(nullptr),
27  _filename(filename),
28  ntuptwr(nullptr),
29  ntupe(nullptr),
30  outfile(nullptr)
31 {}
32 
34 {
35  // delete ntup;
36  delete hm;
37 }
38 
39 
40 int
42 {
43  ostringstream hname, htit;
44  hm = new Fun4AllHistoManager(Name());
45  outfile = new TFile(_filename.c_str(), "RECREATE");
46  ntuptwr = new TNtuple("twr","Towers","detid:phi:eta:edep:t");
47  ntupe = new TNtuple("truth", "The Absolute Truth", "phi:theta:eta:e:p");
48  return 0;
49 }
50 
51 int
53 {
54  map<int, PHG4Particle*>::const_iterator particle_iter;
55  PHG4TruthInfoContainer *_truth_container = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
56 
58  _truth_container->GetPrimaryParticleRange();
59  float ntvars[5] = {0};
60  for (PHG4TruthInfoContainer::ConstIterator particle_iter = primary_range.first;
61  particle_iter != primary_range.second; ++particle_iter)
62  {
63  PHG4Particle *particle = particle_iter->second;
64  ntvars[0] = atan2(particle->get_py(), particle->get_px());
65  ntvars[1] = atan(sqrt(particle->get_py()*particle->get_py() +
66  particle->get_px()*particle->get_px()) /
67  particle->get_pz());
68  ntvars[2] = 0.5*log((particle->get_e()+particle->get_pz())/
69  (particle->get_e()-particle->get_pz()));
70  ntvars[3] = particle->get_e();
71  ntvars[4] = particle->get_pz();
72  }
73  ntupe->Fill(ntvars);
74  RawTowerContainer *towers = nullptr;
75  // double emc[10] = {0};
76  // double ih[10] = {0};
77  // double oh[10] = {0};
78  // double mag[10] = {0};
79  // double bh[10] = {0};
80  // double eall[5] = {0};
81  string nodename[3] = {"TOWER_SIM_CEMC", "TOWER_SIM_HCALIN", "TOWER_SIM_HCALOUT"};
82  string geonodename[3] = {"TOWERGEOM_CEMC", "TOWERGEOM_HCALIN", "TOWERGEOM_HCALOUT"};
83  for (int j=0; j<3;j++)
84  {
85  towers = findNode::getClass<RawTowerContainer>(topNode,nodename[j]);
86  if (towers)
87  {
88  RawTowerGeomContainer* towergeom = findNode::getClass<RawTowerGeomContainer>(topNode,geonodename[j]);
89  if (!towergeom)
90  {
91  cout << "no geometry node " << geonodename << endl;
92  continue;
93  }
94  RawTowerContainer::ConstRange twr_range = towers->getTowers();
95  for ( RawTowerContainer::ConstIterator twr_iter = twr_range.first ; twr_iter != twr_range.second; ++twr_iter )
96  {
97  double energy = twr_iter->second->get_energy();
98  int phibin = twr_iter->second->get_binphi();
99  int etabin = twr_iter->second->get_bineta();
100  double phi = towergeom->get_phicenter(phibin);
101  double eta = towergeom->get_etacenter(etabin);
102  ntuptwr->Fill(j,
103  phi,
104  eta,
105  energy,
106  twr_iter->second->get_time());
107  // double radius = sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
108  // hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y() +
109  // hit_iter->second->get_avg_z() * hit_iter->second->get_avg_z());
110 // double phi = atan2(hit_iter->second->get_avg_y(),hit_iter->second->get_avg_x());
111 // double theta = atan(sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
112 // hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y()) /
113 // hit_iter->second->get_avg_z());
114 // // handle rollover from pi to -pi
115 // double diffphi = phi-ntvars[0];
116 // if (diffphi > M_PI)
117 // {
118 // diffphi -= 2*M_PI;
119 // }
120 // else if (diffphi < - M_PI)
121 // {
122 // diffphi += 2*M_PI;
123 // }
124 
125 // double deltasqrt = sqrt(diffphi*diffphi+(theta-ntvars[1])*(theta-ntvars[1]));
126 // double edep = hit_iter->second->get_edep();
127 // eall[0] += edep;
128 // for (int i=0; i<10; i++)
129 // {
130 // if (deltasqrt < i*0.1)
131 // {
132 // emc[i]+=edep;
133 // }
134 // }
135 // }
136  }
137  }
138  }
139  return 0;
140 }
141 
142 int
144 {
145  outfile->cd();
146  // ntup->Write();
147  ntuptwr->Write();
148  ntupe->Write();
149  outfile->Write();
150  outfile->Close();
151  delete outfile;
152  hm->dumpHistos(_filename, "UPDATE");
153  return 0;
154 }
155 
156 void
157 TowerTiming::AddNode(const std::string &name, const int detid)
158 {
159  _node_postfix.insert(name);
160  _detid[name] = detid;
161  return;
162 }