File indexing completed on 2025-08-06 08:17:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "DeadHotMapLoader.h"
0012
0013 #include <calobase/RawTowerDeadMap.h>
0014 #include <calobase/RawTowerDeadMapv1.h>
0015 #include <calobase/RawTowerDefs.h>
0016 #include <calobase/TowerInfoDefs.h>
0017
0018 #include <cdbobjects/CDBTTree.h>
0019
0020 #include <ffamodules/CDBInterface.h>
0021
0022 #include <fun4all/Fun4AllReturnCodes.h>
0023 #include <fun4all/SubsysReco.h>
0024
0025 #include <phool/PHCompositeNode.h>
0026 #include <phool/PHIODataNode.h>
0027 #include <phool/PHNode.h>
0028 #include <phool/PHNodeIterator.h>
0029 #include <phool/PHObject.h>
0030 #include <phool/getClass.h>
0031 #include <phool/phool.h> // for PHWHERE
0032
0033 #include <cassert>
0034 #include <iostream>
0035 #include <stdexcept>
0036 #include <string>
0037
0038 DeadHotMapLoader::DeadHotMapLoader(const std::string &detector)
0039 : SubsysReco("DeadHotMapLoader_" + detector)
0040 , m_detector(detector)
0041 {
0042 }
0043
0044 int DeadHotMapLoader::InitRun(PHCompositeNode *topNode)
0045 {
0046 PHNodeIterator iter(topNode);
0047 PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(iter.findFirst(
0048 "PHCompositeNode", "RUN"));
0049 if (!runNode)
0050 {
0051 std::cerr << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
0052 << "Run Node missing, doing nothing." << std::endl;
0053 throw std::runtime_error("Failed to find Run node in RawTowerCalibration::CreateNodes");
0054 }
0055
0056
0057 PHNodeIterator dstiter(runNode);
0058 PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", m_detector));
0059 if (!DetNode)
0060 {
0061 DetNode = new PHCompositeNode(m_detector);
0062 runNode->addNode(DetNode);
0063 }
0064
0065
0066 std::string deadMapName = "DEADMAP_" + m_detector;
0067 RawTowerDeadMap *m_deadmap = findNode::getClass<RawTowerDeadMapv1>(DetNode, deadMapName);
0068 if (!m_deadmap)
0069 {
0070 const RawTowerDefs::CalorimeterId caloid = RawTowerDefs::convert_name_to_caloid(m_detector);
0071
0072 m_deadmap = new RawTowerDeadMapv1(caloid);
0073 PHIODataNode<PHObject> *towerNode = new PHIODataNode<PHObject>(m_deadmap, deadMapName, "PHObject");
0074 DetNode->addNode(towerNode);
0075 }
0076
0077
0078
0079 std::string url = CDBInterface::instance()->getUrl(m_detector + "_BadTowerMap");
0080 if(url.empty())
0081 {
0082 std::cout << PHWHERE << " Could not get Dead Map for CDB. Detector: " << m_detector << std::endl;
0083 return Fun4AllReturnCodes::ABORTRUN;
0084 }
0085
0086 m_CDBTTree = new CDBTTree(url);
0087
0088 if(!m_CDBTTree)
0089 {
0090 std::cout << "No CDB TTree found from url " << url << std::endl;
0091 return Fun4AllReturnCodes::ABORTRUN;
0092 }
0093
0094 int etabins;
0095 int phibins;
0096
0097 if (m_detector.c_str()[0] == 'H')
0098 {
0099 etabins = 24;
0100 phibins = 64;
0101
0102
0103 for(int i = 0; i < etabins*phibins; i++)
0104 {
0105 int isDead = m_CDBTTree->GetIntValue(i,"status");
0106 if(isDead > 0)
0107 {
0108 unsigned int key = TowerInfoDefs::encode_hcal(i);
0109 int ieta = TowerInfoDefs::getCaloTowerEtaBin(key);
0110 int iphi = TowerInfoDefs::getCaloTowerPhiBin(key);
0111 m_deadmap->addDeadTower(ieta, iphi);
0112 }
0113 }
0114 }
0115
0116 else if(m_detector.c_str()[0] == 'C')
0117 {
0118 etabins = 96;
0119 phibins = 256;
0120
0121 for(int i = 0; i < 96*256; i++)
0122 {
0123 int isDead = m_CDBTTree->GetIntValue(i,"status");
0124 if(isDead > 0)
0125 {
0126 unsigned int key = TowerInfoDefs::encode_emcal(i);
0127 int ieta = TowerInfoDefs::getCaloTowerEtaBin(key);
0128 int iphi = TowerInfoDefs::getCaloTowerPhiBin(key);
0129 m_deadmap->addDeadTower(ieta, iphi);
0130 }
0131 }
0132 }
0133
0134
0135 if (Verbosity())
0136 {
0137 std::cout << "DeadHotMapLoader::" << m_detector << "::InitRun - loading dead map completed : ";
0138 m_deadmap->identify();
0139 }
0140 return Fun4AllReturnCodes::EVENT_OK;
0141 }