ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ScintillatorTowerTTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ScintillatorTowerTTree.cc
2 
4 
5 #include <calobase/RawTower.h>
6 #include <calobase/RawTowerContainer.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/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, basi...
22 #include <map> // for _Rb_tree_const_iterator
23 #include <utility> // for pair
24 
25 using namespace std;
26 
28  : SubsysReco(name)
29  , savetowers(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 G4TOWER_<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("SCINTILLATORTOWERHIST");
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>(towers, _outnodename, "PHObject");
52  dstNode->addNode(node);
53  evtno = 0;
54  return 0;
55 }
56 
58 {
59  evtno++;
60  G4RootScintillatorTowerContainer *towers = findNode::getClass<G4RootScintillatorTowerContainer>(topNode, _outnodename);
61 
62  RawTowerContainer *g4towers = findNode::getClass<RawTowerContainer>(topNode, _towernodename);
63  if (!g4towers)
64  {
65  cout << "could not find " << _towernodename << endl;
66  gSystem->Exit(1);
67  }
68  RawTowerContainer::ConstRange tower_range = g4towers->getTowers();
69 
70  double etot = 0;
71  for (RawTowerContainer::ConstIterator tower_iter = tower_range.first; tower_iter != tower_range.second; tower_iter++)
72  {
73  RawTower *intower = tower_iter->second;
74  if (savetowers)
75  {
76  towers->AddTower(*intower);
77  }
78  etot += intower->get_energy();
79  }
80  etot_hist->Fill(etot);
81  towers->set_etotal(etot);
82  towers->set_event(evtno);
83  return 0;
84 }
85 
87 {
89  delete hm;
90  return 0;
91 }
92 
93 void G4ScintillatorTowerTTree::Detector(const std::string &det)
94 {
95  _detector = det;
96  _outnodename = "G4RootScintillatorTower_" + det;
97  _towernodename = "TOWER_" + det;
98  if (!_histofilename.size())
99  {
100  _histofilename = "ScintillatorTowerHistos_" + det + ".root";
101  }
102 }