Analysis Software
Documentation for sPHENIX simulation 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/RawTowerGeomContainer.h>
7 #include <calobase/TowerInfo.h>
8 #include <calobase/TowerInfoContainer.h>
9 
10 
12 #include <fun4all/SubsysReco.h> // for SubsysReco
13 
14 #include <phool/PHCompositeNode.h>
15 #include <phool/PHIODataNode.h> // for PHIODataNode
16 #include <phool/PHNodeIterator.h> // for PHNodeIterator
17 #include <phool/PHObject.h> // for PHObject
18 #include <phool/getClass.h>
19 
20 #include <TH1.h>
21 #include <TSystem.h>
22 
23 #include <iostream> // for operator<<, endl, basic_...
24 
26  : SubsysReco(name)
27  , savetowers(1)
28  , evtno(0)
29  , hm(nullptr)
30  , etot_hist(nullptr)
31 {
32 }
33 
35 {
36  if (_detector.empty())
37  {
38  std::cout << "Detector not set via Detector(<name>) method" << std::endl;
39  std::cout << "(it is the name appended to the G4TOWER_<name> nodename)" << std::endl;
40  std::cout << "you do not want to run like this, exiting now" << std::endl;
41  gSystem->Exit(1);
42  }
43  hm = new Fun4AllHistoManager("TOWERHIST");
44  etot_hist = new TH1F("etot", "total deposited energy", 200, 0, 20);
46  PHNodeIterator iter(topNode);
47  PHCompositeNode *dstNode = static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
50  dstNode->addNode(node);
51  evtno = 0;
52  return 0;
53 }
54 
56 {
57  evtno++;
58  G4RootRawTowerContainer *towers = findNode::getClass<G4RootRawTowerContainer>(topNode, _outnodename);
59  RawTowerGeomContainer *rawtowergeom = findNode::getClass<RawTowerGeomContainer>(topNode, _towergeomnodename);
60 
61  // RawTowerContainer *g4towers = findNode::getClass<RawTowerContainer>(topNode, _towernodename);
62  TowerInfoContainer *g4towers = findNode::getClass<TowerInfoContainer>(topNode, _towernodename);
63  if (!g4towers)
64  {
65  std::cout << "could not find " << _towernodename << std::endl;
66  gSystem->Exit(1);
67  }
68 
69  double etot = 0;
70 
71  unsigned int nchannels = g4towers->size();
72  for (unsigned int channel = 0; channel < nchannels;channel++)
73  {
74  TowerInfo *intower =g4towers->get_tower_at_channel(channel);
75  if (savetowers)
76  {
77  unsigned int towerkey = g4towers->encode_key(channel);
78  int ieta = g4towers->getTowerEtaBin(towerkey);
79  int iphi = g4towers->getTowerPhiBin(towerkey);
80 
81  G4RootRawTower roottwr(rawtowergeom->get_etacenter(ieta), rawtowergeom->get_phicenter(iphi), intower->get_energy());
82  towers->AddG4RootRawTower(roottwr);
83  }
84  etot += intower->get_energy();
85  }
86  etot_hist->Fill(etot);
87  towers->set_etotal(etot);
88  towers->set_event(evtno);
89  return 0;
90 }
91 
93 {
95  delete hm;
96  return 0;
97 }
98 
100 {
101  _detector = det;
102  _outnodename = "G4RootRawTower_" + det;
103  _towernodename = "TOWERINFO_CALIB_" + det;
104  _towergeomnodename = "TOWERGEOM_" + det;
105  if (!_histofilename.size())
106  {
107  _histofilename = "RawTowerHistos_" + det + ".root";
108  }
109 }