File indexing completed on 2025-08-05 08:13:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #define CLUSTERSTATUSMAPPER_CC
0012
0013
0014 #include "CaloStatusMapper.h"
0015
0016
0017 #include <calobase/TowerInfov2.h>
0018
0019
0020 #include <calotrigger/TriggerAnalyzer.h>
0021
0022
0023 #include <fun4all/Fun4AllReturnCodes.h>
0024 #include <fun4all/Fun4AllHistoManager.h>
0025
0026
0027 #include <phool/getClass.h>
0028 #include <phool/phool.h>
0029 #include <phool/PHCompositeNode.h>
0030
0031
0032 #include <qautils/QAHistManagerDef.h>
0033
0034
0035 #include <TH1.h>
0036 #include <TH2.h>
0037
0038
0039 #include <algorithm>
0040 #include <cassert>
0041 #include <iostream>
0042
0043
0044 namespace CSMD = CaloStatusMapperDefs;
0045
0046
0047
0048
0049
0050
0051
0052
0053 CaloStatusMapper::CaloStatusMapper(const std::string& modulename, const bool debug)
0054 : SubsysReco(modulename)
0055 {
0056
0057
0058 if (debug && (Verbosity() > 1))
0059 {
0060 std::cout << "CaloStatusMapper::CaloStatusMapper(std::string&, bool) Calling ctor" << std::endl;
0061 }
0062
0063
0064 m_inNodes.clear();
0065
0066 }
0067
0068
0069
0070
0071
0072
0073 CaloStatusMapper::CaloStatusMapper(const Config& config)
0074 : SubsysReco(config.moduleName)
0075 , m_config(config)
0076 {
0077
0078
0079 if (m_config.debug && (Verbosity() > 1))
0080 {
0081 std::cout << "CaloStatusMapper::CaloStatusMapper(Config&) Calling ctor" << std::endl;
0082 }
0083
0084 }
0085
0086
0087
0088
0089
0090
0091 CaloStatusMapper::~CaloStatusMapper()
0092 {
0093
0094
0095 if (m_config.debug && (Verbosity() > 1))
0096 {
0097 std::cout << "CaloStatusMapper::~CaloStatusMapper() Calling dtor" << std::endl;
0098 }
0099 delete m_analyzer;
0100
0101 }
0102
0103
0104
0105
0106
0107
0108
0109
0110 int CaloStatusMapper::Init(PHCompositeNode* )
0111 {
0112
0113 if (m_config.debug)
0114 {
0115 std::cout << "CaloStatusMapper::Init(PHCompositeNode*) Initializing" << std::endl;
0116 }
0117
0118
0119 delete m_analyzer;
0120 m_analyzer = new TriggerAnalyzer();
0121
0122
0123 InitHistManager();
0124 BuildHistograms();
0125
0126
0127 m_nEvent = 0;
0128 return Fun4AllReturnCodes::EVENT_OK;
0129
0130 }
0131
0132
0133
0134
0135
0136
0137 int CaloStatusMapper::process_event(PHCompositeNode* topNode)
0138 {
0139
0140 if (m_config.debug)
0141 {
0142 std::cout << "CaloStatusMapper::process_event(PHCompositeNode* topNode) Processing Event" << std::endl;
0143 }
0144
0145
0146 if (m_config.doTrgSelect)
0147 {
0148 m_analyzer -> decodeTriggers(topNode);
0149 bool hasTrigger = JetQADefs::DidTriggerFire(m_config.trgToSelect, m_analyzer);
0150 if (!hasTrigger)
0151 {
0152 return Fun4AllReturnCodes::EVENT_OK;
0153 }
0154 }
0155
0156
0157 GrabNodes(topNode);
0158
0159
0160 for (size_t iNode = 0; iNode < m_inNodes.size(); ++iNode)
0161 {
0162
0163
0164 const std::string nodeName = m_config.inNodeNames[iNode].first;
0165 const std::string statBase = MakeBaseName("Status", nodeName);
0166
0167
0168 TowerInfoContainer* towers = m_inNodes[iNode];
0169 for (size_t iTower = 0; iTower < towers->size(); ++iTower)
0170 {
0171
0172
0173 const int32_t key = towers -> encode_key(iTower);
0174 const int32_t iEta = towers -> getTowerEtaBin(key);
0175 const int32_t iPhi = towers -> getTowerPhiBin(key);
0176
0177
0178 const auto tower = towers -> get_tower_at_channel(iTower);
0179 const auto status = CSMD::GetTowerStatus(tower);
0180 if (status == CSMD::Stat::Unknown)
0181 {
0182 std::cout << PHWHERE << ": Warning! Tower has an unknown status!\n"
0183 << " channel = " << iTower << ", key = " << key << "\n"
0184 << " node = " << m_config.inNodeNames[iNode].first
0185 << std::endl;
0186 continue;
0187 }
0188
0189
0190 const std::string statLabel = m_mapStatLabels[status];
0191 const std::string perEtaBase = MakeBaseName("NPerEta", nodeName, statLabel);
0192 const std::string perPhiBase = MakeBaseName("NPerPhi", nodeName, statLabel);
0193 const std::string phiEtaBase = MakeBaseName("PhiVsEta", nodeName, statLabel);
0194
0195
0196 m_hists[statBase] -> Fill(status);
0197 m_hists[perEtaBase] -> Fill(iEta);
0198 m_hists[perPhiBase] -> Fill(iPhi);
0199 m_hists[phiEtaBase] -> Fill(iEta, iPhi);
0200
0201 }
0202 }
0203
0204
0205 ++m_nEvent;
0206 return Fun4AllReturnCodes::EVENT_OK;
0207
0208 }
0209
0210
0211
0212
0213
0214
0215 int CaloStatusMapper::End(PHCompositeNode* )
0216 {
0217
0218 if (m_config.debug)
0219 {
0220 std::cout << "CaloStatusMapper::End(PHCompositeNode* topNode) This is the End..." << std::endl;
0221 }
0222
0223
0224 for (const auto& nodeName : m_config.inNodeNames)
0225 {
0226 const std::string statBase = MakeBaseName("Status", nodeName.first);
0227 m_hists[statBase] -> Scale(1. / (double) m_nEvent);
0228 }
0229
0230
0231 for (const auto& hist : m_hists) {
0232 m_manager -> registerHisto(hist.second);
0233 }
0234 return Fun4AllReturnCodes::EVENT_OK;
0235
0236 }
0237
0238
0239
0240
0241
0242
0243
0244
0245 void CaloStatusMapper::InitHistManager()
0246 {
0247
0248
0249 if (m_config.debug && (Verbosity() > 0))
0250 {
0251 std::cout << "CaloStatusMapper::InitHistManager() Initializing histogram manager" << std::endl;
0252 }
0253
0254 m_manager = QAHistManagerDef::getHistoManager();
0255 if (!m_manager)
0256 {
0257 std::cerr << PHWHERE << ": PANIC! Couldn't grab histogram manager!" << std::endl;
0258 assert(m_manager);
0259 }
0260 return;
0261
0262 }
0263
0264
0265
0266
0267
0268
0269 void CaloStatusMapper::BuildHistograms()
0270 {
0271
0272
0273 if (m_config.debug && (Verbosity() > 0))
0274 {
0275 std::cout << "CaloStatusMapper::BuildHistograms() Creating histograms" << std::endl;
0276 }
0277
0278
0279 const CSMD::EMCalHistDef emHistDef;
0280 const CSMD::HCalHistDef hcHistDef;
0281
0282
0283 for (const auto& nodeName : m_config.inNodeNames)
0284 {
0285
0286
0287 const std::string statBase = MakeBaseName("Status", nodeName.first);
0288 const std::string statName = CSMD::MakeQAHistName(statBase, m_config.moduleName, m_config.histTag);
0289
0290
0291
0292 m_hists[statBase] = emHistDef.MakeStatus1D(statName);
0293
0294
0295 for (const auto& statLabel : m_mapStatLabels)
0296 {
0297
0298
0299 m_hists[statBase] -> GetXaxis() -> SetBinLabel(statLabel.first + 1, statLabel.second.data());
0300
0301
0302 const std::string perEtaBase = MakeBaseName("NPerEta", nodeName.first, statLabel.second);
0303 const std::string perPhiBase = MakeBaseName("NPerPhi", nodeName.first, statLabel.second);
0304 const std::string phiEtaBase = MakeBaseName("PhiVsEta", nodeName.first, statLabel.second);
0305
0306
0307 const std::string namePerEta = CSMD::MakeQAHistName(perEtaBase, m_config.moduleName, m_config.histTag);
0308 const std::string namePerPhi = CSMD::MakeQAHistName(perPhiBase, m_config.moduleName, m_config.histTag);
0309 const std::string namePhiEta = CSMD::MakeQAHistName(phiEtaBase, m_config.moduleName, m_config.histTag);
0310
0311
0312 switch (nodeName.second)
0313 {
0314 case CSMD::Calo::HCal:
0315 m_hists[perEtaBase] = hcHistDef.MakeEta1D(namePerEta);
0316 m_hists[perPhiBase] = hcHistDef.MakePhi1D(namePerPhi);
0317 m_hists[phiEtaBase] = hcHistDef.MakePhiEta2D(namePhiEta);
0318 break;
0319 case CSMD::Calo::EMCal:
0320 [[fallthrough]];
0321 default:
0322 m_hists[perEtaBase] = emHistDef.MakeEta1D(namePerEta);
0323 m_hists[perPhiBase] = emHistDef.MakePhi1D(namePerPhi);
0324 m_hists[phiEtaBase] = emHistDef.MakePhiEta2D(namePhiEta);
0325 break;
0326 }
0327
0328 }
0329 }
0330 return;
0331
0332 }
0333
0334
0335
0336
0337
0338
0339 void CaloStatusMapper::GrabNodes(PHCompositeNode* topNode)
0340 {
0341
0342
0343 if (m_config.debug && (Verbosity() > 0))
0344 {
0345 std::cout << "CaloStatusMapper::GrabNodes(PHCompositeNode*) Grabbing input nodes" << std::endl;
0346 }
0347
0348
0349 m_inNodes.clear();
0350
0351
0352 for (auto inNodeName : m_config.inNodeNames)
0353 {
0354 m_inNodes.push_back(
0355 findNode::getClass<TowerInfoContainer>(topNode, inNodeName.first)
0356 );
0357 if (!m_inNodes.back())
0358 {
0359 std::cerr << PHWHERE << ":" << " PANIC! Not able to grab node " << inNodeName.first << "! Aborting!" << std::endl;
0360 assert(m_inNodes.back());
0361 }
0362 }
0363 return;
0364
0365 }
0366
0367
0368
0369
0370
0371
0372 std::string CaloStatusMapper::MakeBaseName(
0373 const std::string& base,
0374 const std::string& node,
0375 const std::string& stat) const
0376 {
0377
0378 if (m_config.debug && (Verbosity() > 2))
0379 {
0380 std::cout << "CaloStatusMapper::MakeBaseName(std::string& x 3) Making base histogram name" << std::endl;
0381 }
0382
0383 std::string name = base + "_" + node;
0384 if (!stat.empty())
0385 {
0386 name.insert(0, stat + "_");
0387 }
0388 return name;
0389
0390 }
0391
0392