ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EICG4dRICHTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EICG4dRICHTree.cc
1 #include "EICG4dRICHTree.h"
2 
3 // TODO: may not need things commented with `---`
4 
5 // tracking
6 //#include <g4vertex/GlobalVertex.h> //---
7 //#include <g4vertex/GlobalVertexMap.h> //---
8 
9 // fun4all
10 //#include <fun4all/Fun4AllHistoManager.h> //---
12 #include <g4main/PHG4Hit.h>
14 #include <g4main/PHG4Hitv1.h>
15 #include <phool/PHCompositeNode.h>
16 #include <phool/getClass.h>
17 //#include <g4main/PHG4Particle.h> //---
18 //#include <g4main/PHG4TruthInfoContainer.h> //---
19 
20 // drich
21 #include "EICG4dRICHHit.h"
22 
23 // root
24 #include <TFile.h>
25 #include <TH1.h>
26 #include <TH2.h>
27 #include <TMath.h>
28 #include <TTree.h>
29 
30 // geant
31 #include <G4SystemOfUnits.hh>
32 
33 // C++ includes
34 #include <sstream>
35 #include <string>
36 /*
37 using std::std::cerr;
38 using std::std::cout;
39 using std::std::endl;
40 using std::string;
41 */
42 //-------------------------------------
43 EICG4dRICHTree::EICG4dRICHTree(const std::string &name, const std::string &filename)
44  : SubsysReco(name)
45  , m_outfileN(filename)
46  , evnum(0)
47 //, m_hm(nullptr) //---
48 {
49  // resetVars(); //---
50  initTrees();
51 }
52 
53 //-------------------------------------
55 {
56  delete m_tree;
57  // delete m_hm; //---
58 }
59 
60 //-------------------------------------
62 {
63  if (Verbosity() > VERBOSITY_A_LOT)
64  std::cout << std::endl
65  << "CALL EICG4dRICHTree::Init" << std::endl;
66 
67  m_outfile = new TFile(m_outfileN.c_str(), "RECREATE");
68 
69  return 0;
70 }
71 
72 //-------------------------------------
74 {
75  if (Verbosity() > VERBOSITY_A_LOT)
76  {
77  std::cout << std::endl
78  << "CALL EICG4dRICHTree::process_event"
79  << " ====================" << std::endl;
80  }
81 
82  getHits(topNode);
83 
85 }
86 
87 //-------------------------------------
89 {
90  if (Verbosity() >= VERBOSITY_MORE) std::cout << std::endl
91  << "CALL EICG4dRICHTree::End" << std::endl;
92 
93  m_outfile->cd();
94  m_tree->Write();
95  m_outfile->Write();
96  m_outfile->Close();
97 
98  delete m_outfile;
99  if (Verbosity() >= VERBOSITY_MORE) std::cout << "DONE EICG4dRICHTree::End" << std::endl;
100  return 0;
101 }
102 
103 //----------------------------------------------
105 {
106  // get hits container
107  PHG4HitContainer *hitCont = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_dRICH_0"); // TODO: do not hard code name
108 
109  if (!hitCont)
110  {
111  std::cerr << "ERROR: hitCont not found" << std::endl;
112  return;
113  }
114 
115  evnum++;
116  if (evnum % 100 == 0)
117  std::cout << ">" << evnum << " events processed" << std::endl;
118 
119  // loop over hits, filling tree
120  auto hitRange = hitCont->getHits();
121  for (auto hitIter = hitRange.first; hitIter != hitRange.second; hitIter++)
122  {
123  EICG4dRICHHit *hit = dynamic_cast<EICG4dRICHHit *>(hitIter->second);
124 
125  if (Verbosity() > VERBOSITY_A_LOT)
126  {
127  std::cout << "----- HIT PRINTOUT:" << std::endl;
128  hit->print();
129  }
130 
131  trackID = (Int_t) hit->get_trkid();
132  strcpy(hitType, hit->get_hit_type_name());
133  strcpy(hitSubtype, hit->get_hit_subtype_name());
134  petal = (Int_t) hit->get_petal();
135  psst = (Int_t) hit->get_psst();
136  pdg = (Int_t) hit->get_pdg();
137  strcpy(particleName, hit->get_particle_name().c_str());
138  strcpy(process, hit->get_process().c_str());
139  parentID = (Int_t) hit->get_parent_id();
145  deltaT = (Double_t) hit->get_delta_t();
146  edep = (Double_t) hit->get_edep();
147  m_tree->Fill();
148  }
149 }
150 
151 //---------------------------------------------
153 {
154  arr[0] = (Double_t) vec.x();
155  arr[1] = (Double_t) vec.y();
156  arr[2] = (Double_t) vec.z();
157 }
158 
159 //---------------------------------------------
161 {
162  m_tree = new TTree("tree", "tree");
163  m_tree->Branch("evnum", &evnum, "evnum/I");
164  m_tree->Branch("trackID", &trackID, "trackID/I");
165  m_tree->Branch("hitType", hitType, "hitType/C");
166  m_tree->Branch("hitSubtype", hitSubtype, "hitSubtype/C");
167  m_tree->Branch("petal", &petal, "petal/I");
168  m_tree->Branch("psst", &psst, "psst/I");
169  m_tree->Branch("pdg", &pdg, "pdg/I");
170  m_tree->Branch("particleName", particleName, "particleName/C");
171  m_tree->Branch("process", process, "process/C");
172  m_tree->Branch("parentID", &parentID, "parentID/I");
173  m_tree->Branch("hitPos", hitPos, "hitPos[3]/D");
174  m_tree->Branch("hitP", hitP, "hitP[3]/D");
175  m_tree->Branch("hitPdir", hitPdir, "hitPdir[3]/D");
176  m_tree->Branch("hitVtxPos", hitVtxPos, "hitVtxPos[3]/D");
177  m_tree->Branch("hitVtxPdir", hitVtxPdir, "hitVtxPdir[3]/D");
178  m_tree->Branch("deltaT", &deltaT, "deltaT/D");
179  m_tree->Branch("edep", &edep, "edep/D");
180 }
181 
182 //----------------------------------------
183 /*
184 // TODO: may not need this...
185 void EICG4dRICHTree::resetVars() {
186  evnum = 0;
187  trackID = -999;
188  for(int c=0; c<3; c++) hitPos[c]=-999;
189  deltaT=-999;
190 }
191 */