ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4HitTTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4HitTTree.cc
1 #include "G4HitTTree.h"
2 
3 #include "G4RootHitContainer.h"
4 
5 #include <g4main/PHG4Hit.h>
7 
9 #include <fun4all/SubsysReco.h> // for SubsysReco
10 
11 #include <phool/PHCompositeNode.h>
12 #include <phool/PHIODataNode.h> // for PHIODataNode
13 #include <phool/PHNodeIterator.h> // for PHNodeIterator
14 #include <phool/PHObject.h> // for PHObject
15 #include <phool/getClass.h>
16 
17 #include <TH1.h>
18 #include <TH2.h>
19 #include <TSystem.h>
20 
21 #include <iostream> // for operator<<, endl, basic_ost...
22 #include <map> // for _Rb_tree_const_iterator
23 #include <utility> // for pair
24 
25 using namespace std;
26 
27 G4HitTTree::G4HitTTree(const std::string &name)
28  : SubsysReco(name)
29  , savehits(1)
30  , evtno(0)
31  , hm(nullptr)
32  , etot_hist(nullptr)
33  , eion_etot_hist(nullptr)
34 {
35  BlackHoleName("BH_1"); // initialize this to what we have in our common sims
36 }
37 
39 {
40  if (!_detector.size())
41  {
42  cout << "Detector not set via Detector(<name>) method" << endl;
43  cout << "(it is the name appended to the G4HIT_<name> nodename)" << endl;
44  cout << "you do not want to run like this, exiting now" << endl;
45  gSystem->Exit(1);
46  }
47  hm = new Fun4AllHistoManager("HITHIST");
48  etot_hist = new TH1F("etot", "total deposited energy", 200, 0, 20);
50  eion_etot_hist = new TH2F("eion_etot", "ionization energy vs total energy", 200, 0, 20, 200, 0, 20);
52 
53  PHNodeIterator iter(topNode);
54  PHCompositeNode *dstNode = static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
57  dstNode->addNode(node);
58  evtno = 0;
59  return 0;
60 }
61 
63 {
64  evtno++;
65  G4RootHitContainer *hits = findNode::getClass<G4RootHitContainer>(topNode, _outnodename);
66  PHG4HitContainer *g4hits = findNode::getClass<PHG4HitContainer>(topNode, _hitnodename);
67  double etot = 0;
68  double eion = 0;
69  if (g4hits)
70  {
71  PHG4HitContainer::ConstRange hit_range = g4hits->getHits();
72  //shower_z->Reset();
73  // cout << "Number of Hits: " << g4hits->size() << endl;
74  for (PHG4HitContainer::ConstIterator hit_iter = hit_range.first; hit_iter != hit_range.second; hit_iter++)
75  {
76  PHG4Hit *inhit = hit_iter->second;
77  if (savehits)
78  {
79  hits->AddHit(inhit);
80  }
81  etot += inhit->get_edep();
82  eion += inhit->get_eion();
83  }
84  etot_hist->Fill(etot);
85  eion_etot_hist->Fill(etot, eion);
86  }
87  g4hits = findNode::getClass<PHG4HitContainer>(topNode, _absorbernodename);
88  if (g4hits)
89  {
90  PHG4HitContainer::ConstRange hit_range = g4hits->getHits();
91  //shower_z->Reset();
92  // cout << "Number of Hits: " << g4hits->size() << endl;
93  for (PHG4HitContainer::ConstIterator hit_iter = hit_range.first; hit_iter != hit_range.second; hit_iter++)
94  {
95  PHG4Hit *inhit = hit_iter->second;
96  if (savehits)
97  {
98  hits->AddHit(inhit);
99  }
100  }
101  }
102  double eleak = 0;
103  g4hits = findNode::getClass<PHG4HitContainer>(topNode, _blackholenodename);
104  if (g4hits)
105  {
106  PHG4HitContainer::ConstRange hit_range = g4hits->getHits();
107  for (PHG4HitContainer::ConstIterator hit_iter = hit_range.first; hit_iter != hit_range.second; hit_iter++)
108  {
109  if (savehits)
110  {
111  // PHG4Hit *g4h = hits->AddHit( *(hit_iter->second));
112  }
113  eleak += hit_iter->second->get_edep();
114  }
115  }
116  hits->set_etotal(etot);
117  hits->set_eion(eion);
118  hits->set_leakage(eleak);
119  hits->set_event(evtno);
120  return 0;
121 }
122 
124 {
125  hm->dumpHistos("HitHistos.root");
126  delete hm;
127  return 0;
128 }
129 
130 void G4HitTTree::Detector(const std::string &det)
131 {
132  _detector = det;
133  _outnodename = "G4RootHit_" + det;
134  _hitnodename = "G4HIT_" + det;
135  _absorbernodename = "G4HIT_ABSORBER_" + det;
136 }
137 
138 void G4HitTTree::BlackHoleName(const std::string &bh)
139 {
140  _blackholenodename = "G4HIT_" + bh;
141 }