File indexing completed on 2025-08-05 08:12:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
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
0074 #include <calobase/TowerInfo.h>
0075 #include <calobase/TowerInfoDefs.h>
0076 #include <calobase/TowerInfoContainer.h>
0077
0078
0079 #include <TFile.h>
0080
0081
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),
0103 m_energy_min(9999),
0104 m_energy_max(0),
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
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
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 }