EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EvalRootTTreeReco.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EvalRootTTreeReco.cc
1 
2 #include "EvalRootTTreeReco.h"
3 
4 #include "EvalCluster.h"
5 #include "EvalHit.h"
6 #include "EvalRootTTree.h"
7 #include "EvalTower.h"
8 
9 #include <g4main/PHG4Hit.h>
11 #include <g4main/PHG4Particle.h>
13 #include <g4main/PHG4VtxPoint.h>
14 
15 #include <calobase/RawCluster.h>
16 #include <calobase/RawClusterContainer.h>
17 #include <calobase/RawTower.h>
18 #include <calobase/RawTowerContainer.h>
19 #include <calobase/RawTowerGeom.h>
20 #include <calobase/RawTowerGeomContainer.h>
21 
23 
24 #include <phool/PHCompositeNode.h>
25 #include <phool/getClass.h>
26 
27 #include <TSystem.h>
28 
29 #include <iostream> // for operator<<, endl, basic_ost...
30 
31 //____________________________________________________________________________..
33  : SubsysReco(name)
34 {
35 }
36 
37 //____________________________________________________________________________..
39 {
40 }
41 
42 //____________________________________________________________________________..
44 {
45  if (m_Detector.empty())
46  {
47  std::cout << "Detector not set via Detector(<name>) method" << std::endl;
48  std::cout << "(it is the name appended to the G4HIT_<name> nodename)" << std::endl;
49  std::cout << "you do not want to run like this, exiting now" << std::endl;
50  gSystem->Exit(1);
51  }
52  PHNodeIterator iter(topNode);
53  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
54  EvalRootTTree *evaltree = new EvalRootTTree();
55  PHIODataNode<PHObject> *node = new PHIODataNode<PHObject>(evaltree, m_OutputNode, "PHObject");
56  dstNode->addNode(node);
58 }
59 
60 //____________________________________________________________________________..
62 {
64 }
65 
66 //____________________________________________________________________________..
68 {
69  PHG4TruthInfoContainer *truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
70 
71  EvalRootTTree *evaltree = findNode::getClass<EvalRootTTree>(topNode, m_OutputNode);
72  PHG4VtxPoint *gvertex = truthinfo->GetPrimaryVtx(truthinfo->GetPrimaryVertexIndex());
73  if (gvertex)
74  {
75  evaltree->set_gvx(gvertex->get_x());
76  evaltree->set_gvy(gvertex->get_y());
77  evaltree->set_gvz(gvertex->get_z());
79  int justone = 0;
80  for (PHG4TruthInfoContainer::ConstIterator iter = range.first;
81  iter != range.second;
82  ++iter)
83  {
84  justone++;
85  PHG4Particle *primary = iter->second;
86  double gpx = primary->get_px();
87  double gpy = primary->get_py();
88  double gpz = primary->get_pz();
89  double gpt = std::sqrt(gpx * gpx + gpy * gpy);
90  double gmom = std::sqrt(gpx * gpx + gpy * gpy + gpz * gpz);
91 
92  evaltree->set_gpx(gpx);
93  evaltree->set_gpy(gpy);
94  evaltree->set_gpz(gpz);
95  evaltree->set_ge(primary->get_e());
96  evaltree->set_gpid(primary->get_pid());
97  double geta = NAN;
98  if (gpt > 0)
99  {
100  geta = asinh(gpz / gpt);
101  }
102  evaltree->set_geta(geta);
103  evaltree->set_gphi(atan2(gpy, gpx));
104  evaltree->set_gtheta(acos(gpz / gmom));
105  }
106  if (justone > 1)
107  {
108  std::cout << "this only works for single particle events"
109  << " here I see " << justone << " primaries" << std::endl;
110  gSystem->Exit(1);
111  }
112  }
113  // add hits
114  PHG4HitContainer *g4hits = findNode::getClass<PHG4HitContainer>(topNode, m_HitNodeName);
115 
116  if (g4hits && !m_DropHitsFlag)
117  {
118  double esum = 0.;
119  evaltree->set_nhits(g4hits->size());
120  PHG4HitContainer::ConstRange hit_range = g4hits->getHits();
121  for (PHG4HitContainer::ConstIterator hit_iter = hit_range.first; hit_iter != hit_range.second; hit_iter++)
122  {
123  evaltree->AddHit(hit_iter->second);
124  esum += hit_iter->second->get_edep();
125  }
126  evaltree->set_hesum(esum);
127  }
128 
129  // add towers
130  RawTowerGeomContainer *rawtowergeomcontainer = findNode::getClass<RawTowerGeomContainer>(topNode, m_TowerGeoNodeName);
131 
132  RawTowerContainer *g4towers = findNode::getClass<RawTowerContainer>(topNode, m_TowerNodeName);
133  if (g4towers)
134  {
135  double esum = 0.;
136  evaltree->set_ntowers(g4towers->size());
137  RawTowerContainer::ConstRange tower_range = g4towers->getTowers();
138  for (RawTowerContainer::ConstIterator tower_iter = tower_range.first; tower_iter != tower_range.second; tower_iter++)
139  {
140  RawTower *twr = tower_iter->second;
141  EvalTower *evaltwr = evaltree->AddTower(twr);
142  RawTowerGeom *geom = rawtowergeomcontainer->get_tower_geometry(twr->get_key());
143  evaltwr->set_teta(geom->get_eta());
144  evaltwr->set_ttheta(geom->get_theta());
145  evaltwr->set_tphi(geom->get_phi());
146  evaltwr->set_tx(geom->get_center_x());
147  evaltwr->set_ty(geom->get_center_y());
148  evaltwr->set_tz(geom->get_center_z());
149  esum += twr->get_energy();
150  }
151  evaltree->set_tesum(esum);
152  }
153  // Clusters
154  RawClusterContainer *clusters = findNode::getClass<RawClusterContainer>(topNode, m_ClusterNodeName);
155  if (clusters)
156  {
157  double esum = 0.;
158  evaltree->set_nclusters(clusters->size());
159  for (const auto &iterator : clusters->getClustersMap())
160  {
161  RawCluster *cluster = iterator.second;
162  evaltree->AddCluster(cluster);
163  esum += cluster->get_energy();
164  }
165  evaltree->set_cesum(esum);
166  }
167 
169 }
170 
171 //____________________________________________________________________________..
173 {
175 }
176 
177 //____________________________________________________________________________..
178 int EvalRootTTreeReco::EndRun(const int runnumber)
179 {
181 }
182 
183 //____________________________________________________________________________..
185 {
187 }
188 
189 //____________________________________________________________________________..
191 {
193 }
194 
195 //____________________________________________________________________________..
196 void EvalRootTTreeReco::Print(const std::string &what) const
197 {
198  std::cout << "EvalRootTTreeReco::Print(const std::string &what) const Printing info for " << what << std::endl;
199 }
200 
201 void EvalRootTTreeReco::Detector(const std::string &name)
202 {
203  m_Detector = name;
204  m_OutputNode = "EvalTTree_" + name;
205  m_HitNodeName = "G4HIT_" + name;
206  m_TowerNodeName = "TOWER_CALIB_" + name;
207  m_TowerGeoNodeName = "TOWERGEOM_" + name;
208  m_ClusterNodeName = "CLUSTER_" + name;
209 }