ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ScintillatorSlatTTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ScintillatorSlatTTree.cc
2 
4 
7 
9 #include <fun4all/SubsysReco.h> // for SubsysReco
10 
11 #include <phool/PHCompositeNode.h>
12 #include <phool/PHIODataNode.h> // for PHIODataNode
13 #include <phool/PHNode.h> // for PHNode
14 #include <phool/PHNodeIterator.h> // for PHNodeIterator
15 #include <phool/PHObject.h> // for PHObject
16 #include <phool/getClass.h>
17 
18 #include <TH1.h>
19 #include <TSystem.h>
20 
21 #include <iostream> // for operator<<, endl
22 #include <map> // for _Rb_tree_cons...
23 #include <utility> // for pair
24 
25 using namespace std;
26 
28  : SubsysReco(name)
29  , saveslats(1)
30  , evtno(0)
31  , hm(nullptr)
32  , etot_hist(nullptr)
33 {
34 }
35 
37 {
38  if (!_detector.size())
39  {
40  cout << "Detector not set via Detector(<name>) method" << endl;
41  cout << "(it is the name appended to the G4CELL_<name> nodename)" << endl;
42  cout << "you do not want to run like this, exiting now" << endl;
43  gSystem->Exit(1);
44  }
45  hm = new Fun4AllHistoManager("SCINTILLATORSLATHIST");
46  etot_hist = new TH1F("etot", "total deposited energy", 200, 0, 20);
48  PHNodeIterator iter(topNode);
49  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
51  PHIODataNode<PHObject> *node = new PHIODataNode<PHObject>(slats, _outnodename, "PHObject");
52  dstNode->addNode(node);
53  evtno = 0;
54  return 0;
55 }
56 
58 {
59  evtno++;
60  G4RootScintillatorSlatContainer *slats = findNode::getClass<G4RootScintillatorSlatContainer>(topNode, _outnodename);
61 
62  PHG4ScintillatorSlatContainer *g4slats = findNode::getClass<PHG4ScintillatorSlatContainer>(topNode, _slatnodename);
63  if (!g4slats)
64  {
65  cout << "could not find " << _slatnodename << endl;
66  gSystem->Exit(1);
67  }
68  PHG4ScintillatorSlatContainer::ConstRange slat_range = g4slats->getScintillatorSlats();
69 
70  double etot = 0;
71  for (PHG4ScintillatorSlatContainer::ConstIterator slat_iter = slat_range.first; slat_iter != slat_range.second; slat_iter++)
72  {
73  PHG4ScintillatorSlat *inslat = slat_iter->second;
74  if (saveslats)
75  {
76  slats->AddSlat(*inslat);
77  }
78  etot += inslat->get_edep();
79  }
80  etot_hist->Fill(etot);
81  slats->set_etotal(etot);
82  slats->set_event(evtno);
83  return 0;
84 }
85 
87 {
89  delete hm;
90  return 0;
91 }
92 
93 void G4ScintillatorSlatTTree::Detector(const std::string &det)
94 {
95  _detector = det;
96  _outnodename = "G4RootScintillatorSlat_" + det;
97  _slatnodename = "G4CELL_" + det;
98  if (!_histofilename.size())
99  {
100  _histofilename = "ScintillatorSlatHistos_" + det + ".root";
101  }
102 }