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