Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:18

0001 //____________________________________________________________________________..
0002 //
0003 // This is a template for a Fun4All SubsysReco module with all methods from the
0004 // $OFFLINE_MAIN/include/fun4all/SubsysReco.h baseclass
0005 // You do not have to implement all of them, you can just remove unused methods
0006 // here and in CaloHotTowerSim.h.
0007 //
0008 // CaloHotTowerSim(const std::string &name = "CaloHotTowerSim")
0009 // everything is keyed to CaloHotTowerSim, duplicate names do work but it makes
0010 // e.g. finding culprits in logs difficult or getting a pointer to the module
0011 // from the command line
0012 //
0013 // CaloHotTowerSim::~CaloHotTowerSim()
0014 // this is called when the Fun4AllServer is deleted at the end of running. Be
0015 // mindful what you delete - you do loose ownership of object you put on the node tree
0016 //
0017 // int CaloHotTowerSim::Init(PHCompositeNode *topNode)
0018 // This method is called when the module is registered with the Fun4AllServer. You
0019 // can create historgrams here or put objects on the node tree but be aware that
0020 // modules which haven't been registered yet did not put antyhing on the node tree
0021 //
0022 // int CaloHotTowerSim::InitRun(PHCompositeNode *topNode)
0023 // This method is called when the first event is read (or generated). At
0024 // this point the run number is known (which is mainly interesting for raw data
0025 // processing). Also all objects are on the node tree in case your module's action
0026 // depends on what else is around. Last chance to put nodes under the DST Node
0027 // We mix events during readback if branches are added after the first event
0028 //
0029 // int CaloHotTowerSim::process_event(PHCompositeNode *topNode)
0030 // called for every event. Return codes trigger actions, you find them in
0031 // $OFFLINE_MAIN/include/fun4all/Fun4AllReturnCodes.h
0032 //   everything is good:
0033 //     return Fun4AllReturnCodes::EVENT_OK
0034 //   abort event reconstruction, clear everything and process next event:
0035 //     return Fun4AllReturnCodes::ABORT_EVENT; 
0036 //   proceed but do not save this event in output (needs output manager setting):
0037 //     return Fun4AllReturnCodes::DISCARD_EVENT; 
0038 //   abort processing:
0039 //     return Fun4AllReturnCodes::ABORT_RUN
0040 // all other integers will lead to an error and abort of processing
0041 //
0042 // int CaloHotTowerSim::ResetEvent(PHCompositeNode *topNode)
0043 // If you have internal data structures (arrays, stl containers) which needs clearing
0044 // after each event, this is the place to do that. The nodes under the DST node are cleared
0045 // by the framework
0046 //
0047 // int CaloHotTowerSim::EndRun(const int runnumber)
0048 // This method is called at the end of a run when an event from a new run is
0049 // encountered. Useful when analyzing multiple runs (raw data). Also called at
0050 // the end of processing (before the End() method)
0051 //
0052 // int CaloHotTowerSim::End(PHCompositeNode *topNode)
0053 // This is called at the end of processing. It needs to be called by the macro
0054 // by Fun4AllServer::End(), so do not forget this in your macro
0055 //
0056 // int CaloHotTowerSim::Reset(PHCompositeNode *topNode)
0057 // not really used - it is called before the dtor is called
0058 //
0059 // void CaloHotTowerSim::Print(const std::string &what) const
0060 // Called from the command line - useful to print information when you need it
0061 //
0062 //____________________________________________________________________________..
0063 
0064 #include "CaloHotTowerSim.h"
0065 
0066 #include <fun4all/Fun4AllReturnCodes.h>
0067 #include <fun4all/Fun4AllServer.h>
0068 
0069 #include <phool/PHCompositeNode.h>
0070 #include <phool/getClass.h>
0071 #include <phool/phool.h>
0072 
0073 // Tower stuff
0074 #include <calobase/TowerInfo.h>
0075 #include <calobase/TowerInfoDefs.h>
0076 #include <calobase/TowerInfoContainer.h>
0077 
0078 // ROOT stuff
0079 #include <TFile.h>
0080 
0081 // c++
0082 #include <iostream>
0083 #include <fstream>
0084 
0085 using std::cout;
0086 using std::cerr;
0087 using std::endl;
0088 using std::string;
0089 using std::vector;
0090 using std::pair;
0091 using std::min;
0092 using std::max;
0093 using std::to_string;
0094 
0095 //____________________________________________________________________________..
0096 CaloHotTowerSim::CaloHotTowerSim(const string &name):
0097  SubsysReco(name),
0098  m_iEvent(0),
0099  m_bins_events(1),
0100  m_bins_phi(256),
0101  m_bins_eta(96),
0102  m_min_towerE(0.1), /*GeV*/
0103  m_energy_min(9999), /*GeV*/
0104  m_energy_max(0), /*GeV*/
0105  m_avgBadTowers(0),
0106  m_emcTowerNode("TOWERINFO_CALIB_CEMC"),
0107  m_outputFile("test.root")
0108 {
0109   cout << "CaloHotTowerSim::CaloHotTowerSim(const string &name) Calling ctor" << endl;
0110 }
0111 
0112 //____________________________________________________________________________..
0113 CaloHotTowerSim::~CaloHotTowerSim() {
0114   cout << "CaloHotTowerSim::~CaloHotTowerSim() Calling dtor" << endl;
0115 }
0116 
0117 //____________________________________________________________________________..
0118 Int_t CaloHotTowerSim::Init(PHCompositeNode *topNode) {
0119   cout << "CaloHotTowerSim::Init(PHCompositeNode *topNode) Initializing" << endl;
0120 
0121   // so that the histos actually get written out
0122   Fun4AllServer *se = Fun4AllServer::instance();
0123   se->Print("NODETREE");
0124 
0125   hEvents = new TH1F("hEvents","Events; Status; Counts", m_bins_events, 0, m_bins_events);
0126 
0127   h2TowerEnergy = new TH2F("h2TowerEnergy","Tower Energy; Tower Index #phi; Tower Index #eta", m_bins_phi, -0.5, m_bins_phi-0.5, m_bins_eta, -0.5, m_bins_eta-0.5);
0128 
0129   h2TowerControlEnergy = new TH2F("h2TowerControlEnergy","Tower Energy; Tower Index #phi; Tower Index #eta", m_bins_phi, -0.5, m_bins_phi-0.5, m_bins_eta, -0.5, m_bins_eta-0.5);
0130 
0131   return Fun4AllReturnCodes::EVENT_OK;
0132 }
0133 
0134 //____________________________________________________________________________..
0135 Int_t CaloHotTowerSim::process_event(PHCompositeNode *topNode) {
0136 
0137   if(m_iEvent%20 == 0) cout << "Progress: " << m_iEvent << endl;
0138   ++m_iEvent;
0139 
0140   // Get TowerInfoContainer
0141   TowerInfoContainer* towers = findNode::getClass<TowerInfoContainer>(topNode, m_emcTowerNode.c_str());
0142   if (!towers) {
0143     cout << PHWHERE << "CaloHotTowerSim::process_event Could not find node " << m_emcTowerNode << endl;
0144     return Fun4AllReturnCodes::ABORTEVENT;
0145   }
0146 
0147   hEvents->Fill(0);
0148 
0149   for (UInt_t i = 0; i < towers->size(); ++i)
0150   {
0151     UInt_t key = TowerInfoDefs::encode_emcal(i);
0152     UInt_t iphi = TowerInfoDefs::getCaloTowerPhiBin(key);
0153     UInt_t ieta = TowerInfoDefs::getCaloTowerEtaBin(key);
0154 
0155     TowerInfo *tower = towers->get_tower_at_channel(i);
0156 
0157     Float_t energy = tower->get_energy();
0158 
0159     if (tower->get_isHot()) ++m_avgBadTowers;
0160 
0161     if (energy >= m_min_towerE)
0162     {
0163       h2TowerControlEnergy->Fill(iphi, ieta, energy);
0164 
0165       if (!tower->get_isHot())
0166       {
0167         h2TowerEnergy->Fill(iphi, ieta, energy);
0168       }
0169 
0170       m_energy_min = min(m_energy_min, energy);
0171       m_energy_max = max(m_energy_max, energy);
0172     }
0173   }
0174 
0175   return Fun4AllReturnCodes::EVENT_OK;
0176 }
0177 
0178 //____________________________________________________________________________..
0179 Int_t CaloHotTowerSim::End(PHCompositeNode *topNode) {
0180   cout << "CaloHotTowerSim::End(PHCompositeNode *topNode) This is the End..." << endl;
0181   cout << "Min Energy: " << m_energy_min << ", Max Energy: " << m_energy_max << endl;
0182   cout << "Avg Bad Towers: " << m_avgBadTowers/hEvents->GetBinContent(1) << endl;
0183 
0184   TFile output(m_outputFile.c_str(),"recreate");
0185 
0186   output.cd();
0187   hEvents->Write();
0188   h2TowerEnergy->Write();
0189   h2TowerControlEnergy->Write();
0190 
0191   output.Close();
0192 
0193   return Fun4AllReturnCodes::EVENT_OK;
0194 }