ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RawTowerTTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4RawTowerTTree.cc
1 #include "G4RawTowerTTree.h"
2 
3 #include "G4RootRawTower.h"
5 
6 #include <calobase/RawTower.h>
7 #include <calobase/RawTowerContainer.h>
8 #include <calobase/RawTowerGeomContainer.h>
9 
11 #include <fun4all/SubsysReco.h> // for SubsysReco
12 
13 #include <phool/PHCompositeNode.h>
14 #include <phool/PHIODataNode.h> // for PHIODataNode
15 #include <phool/PHNodeIterator.h> // for PHNodeIterator
16 #include <phool/PHObject.h> // for PHObject
17 #include <phool/getClass.h>
18 
19 #include <TH1.h>
20 #include <TSystem.h>
21 
22 #include <iostream> // for operator<<, endl, basic_...
23 #include <map> // for _Rb_tree_const_iterator
24 #include <utility> // for pair
25 
26 using namespace std;
27 
29  : SubsysReco(name)
30  , savetowers(1)
31  , evtno(0)
32  , hm(nullptr)
33  , etot_hist(nullptr)
34 {
35 }
36 
38 {
39  if (_detector.empty())
40  {
41  cout << "Detector not set via Detector(<name>) method" << endl;
42  cout << "(it is the name appended to the G4TOWER_<name> nodename)" << endl;
43  cout << "you do not want to run like this, exiting now" << endl;
44  gSystem->Exit(1);
45  }
46  hm = new Fun4AllHistoManager("TOWERHIST");
47  etot_hist = new TH1F("etot", "total deposited energy", 200, 0, 20);
49  PHNodeIterator iter(topNode);
50  PHCompositeNode *dstNode = static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
52  PHIODataNode<PHObject> *node = new PHIODataNode<PHObject>(towers, _outnodename, "PHObject");
53  dstNode->addNode(node);
54  evtno = 0;
55  return 0;
56 }
57 
59 {
60  evtno++;
61  G4RootRawTowerContainer *towers = findNode::getClass<G4RootRawTowerContainer>(topNode, _outnodename);
62  RawTowerGeomContainer *rawtowergeom = findNode::getClass<RawTowerGeomContainer>(topNode, _towergeomnodename);
63 
64  RawTowerContainer *g4towers = findNode::getClass<RawTowerContainer>(topNode, _towernodename);
65  if (!g4towers)
66  {
67  cout << "could not find " << _towernodename << endl;
68  gSystem->Exit(1);
69  }
70  RawTowerContainer::ConstRange tower_range = g4towers->getTowers();
71 
72  double etot = 0;
73  for (RawTowerContainer::ConstIterator tower_iter = tower_range.first; tower_iter != tower_range.second; tower_iter++)
74  {
75  RawTower *intower = tower_iter->second;
76  if (savetowers)
77  {
78  G4RootRawTower roottwr(rawtowergeom->get_etacenter(intower->get_bineta()), rawtowergeom->get_phicenter(intower->get_binphi()), intower->get_energy());
79  towers->AddG4RootRawTower(roottwr);
80  }
81  etot += intower->get_energy();
82  }
83  etot_hist->Fill(etot);
84  towers->set_etotal(etot);
85  towers->set_event(evtno);
86  return 0;
87 }
88 
90 {
92  delete hm;
93  return 0;
94 }
95 
96 void G4RawTowerTTree::Detector(const std::string &det)
97 {
98  _detector = det;
99  _outnodename = "G4RootRawTower_" + det;
100  _towernodename = "TOWER_CALIB_" + det;
101  _towergeomnodename = "TOWERGEOM_" + det;
102  if (!_histofilename.size())
103  {
104  _histofilename = "RawTowerHistos_" + det + ".root";
105  }
106 }