File indexing completed on 2025-08-06 08:19:16
0001 #include "G4ScintillatorTowerTTree.h"
0002 #include "G4RootScintillatorTowerContainer.h"
0003
0004 #include <calobase/TowerInfo.h>
0005 #include <calobase/TowerInfoContainerv1.h>
0006
0007 #include <fun4all/Fun4AllHistoManager.h>
0008 #include <fun4all/SubsysReco.h> // for SubsysReco
0009
0010 #include <phool/PHCompositeNode.h>
0011 #include <phool/PHIODataNode.h> // for PHIODataNode
0012 #include <phool/PHNode.h> // for PHNode
0013 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0014 #include <phool/PHObject.h> // for PHObject
0015 #include <phool/getClass.h>
0016
0017 #include <TH1.h>
0018 #include <TSystem.h>
0019
0020 #include <iostream> // for operator<<, endl, basi...
0021 #include <map> // for _Rb_tree_const_iterator
0022 #include <utility> // for pair
0023
0024 using namespace std;
0025
0026 G4ScintillatorTowerTTree::G4ScintillatorTowerTTree(const std::string &name)
0027 : SubsysReco(name)
0028 , savetowers(1)
0029 , evtno(0)
0030 , hm(nullptr)
0031 , etot_hist(nullptr)
0032 {
0033 }
0034
0035 int G4ScintillatorTowerTTree::Init(PHCompositeNode *topNode)
0036 {
0037 if (!_detector.size())
0038 {
0039 cout << "Detector not set via Detector(<name>) method" << endl;
0040 cout << "(it is the name appended to the G4TOWER_<name> nodename)" << endl;
0041 cout << "you do not want to run like this, exiting now" << endl;
0042 gSystem->Exit(1);
0043 }
0044 hm = new Fun4AllHistoManager("SCINTILLATORTOWERHIST");
0045 etot_hist = new TH1F("etot", "total deposited energy", 200, 0, 20);
0046 hm->registerHisto(etot_hist);
0047 PHNodeIterator iter(topNode);
0048 PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0049 G4RootScintillatorTowerContainer *towers = new G4RootScintillatorTowerContainer();
0050 PHIODataNode<PHObject> *node = new PHIODataNode<PHObject>(towers, _outnodename, "PHObject");
0051 dstNode->addNode(node);
0052 evtno = 0;
0053 return 0;
0054 }
0055
0056 int G4ScintillatorTowerTTree::process_event(PHCompositeNode *topNode)
0057 {
0058 evtno++;
0059 G4RootScintillatorTowerContainer *towers = findNode::getClass<G4RootScintillatorTowerContainer>(topNode, _outnodename);
0060
0061 TowerInfoContainer *g4towers = findNode::getClass<TowerInfoContainerv1>(topNode, _towernodename);
0062 if (!g4towers)
0063 {
0064 cout << "could not find " << _towernodename << endl;
0065 gSystem->Exit(1);
0066 }
0067
0068 double etot = 0;
0069
0070 unsigned int nchannels = g4towers->size();
0071 for (unsigned int channel = 0; channel < nchannels; channel++)
0072 {
0073 TowerInfo *intower = g4towers->get_tower_at_channel(channel);
0074 if (savetowers)
0075 {
0076 unsigned int towerkey = g4towers->encode_key(channel);
0077 int ieta = g4towers->getTowerEtaBin(towerkey);
0078 int iphi = g4towers->getTowerPhiBin(towerkey);
0079 double towerenergy = intower->get_energy();
0080 towers->AddTower(towerenergy, ieta, iphi);
0081 }
0082 etot += intower->get_energy();
0083 }
0084 etot_hist->Fill(etot);
0085 towers->set_etotal(etot);
0086 towers->set_event(evtno);
0087 return 0;
0088 }
0089
0090 int G4ScintillatorTowerTTree::End(PHCompositeNode * )
0091 {
0092 hm->dumpHistos(_histofilename);
0093 delete hm;
0094 return 0;
0095 }
0096
0097 void G4ScintillatorTowerTTree::Detector(const std::string &det)
0098 {
0099 _detector = det;
0100 _outnodename = "G4RootScintillatorTower_" + det;
0101 _towernodename = "TOWERINFO_" + det;
0102 if (!_histofilename.size())
0103 {
0104 _histofilename = "ScintillatorTowerHistos_" + det + ".root";
0105 }
0106 }