diff --git a/offline/packages/CaloReco/CaloTowerStatus.cc b/offline/packages/CaloReco/CaloTowerStatus.cc index f9e63348b6..4cba2f1fcf 100644 --- a/offline/packages/CaloReco/CaloTowerStatus.cc +++ b/offline/packages/CaloReco/CaloTowerStatus.cc @@ -8,27 +8,17 @@ #include -#include - #include #include // for SubsysReco #include -#include // for PHIODataNode -#include // for PHNode -#include // for PHNodeIterator -#include // for PHObject #include -#include -#include #include +#include #include -#include // for exit -#include // for exception -#include // for operator<<, basic_ostream -#include // for runtime_error +#include // for operator<<, basic_ostream //____________________________________________________________________________.. CaloTowerStatus::CaloTowerStatus(const std::string &name) @@ -40,22 +30,9 @@ CaloTowerStatus::CaloTowerStatus(const std::string &name) } } -//____________________________________________________________________________.. -CaloTowerStatus::~CaloTowerStatus() -{ - if (Verbosity() > 0) - { - std::cout << "CaloTowerStatus::~CaloTowerStatus() Calling dtor" << std::endl; - } - delete m_cdbttree_chi2; - delete m_cdbttree_hotMap; -} - //____________________________________________________________________________.. int CaloTowerStatus::InitRun(PHCompositeNode *topNode) { - PHNodeIterator nodeIter(topNode); - if (m_dettype == CaloTowerDefs::CEMC) { m_detector = "CEMC"; @@ -78,28 +55,30 @@ int CaloTowerStatus::InitRun(PHCompositeNode *topNode) m_detector = "SEPD"; } + CreateNodeTree(topNode); + + CDBTTree *cdbttree_chi2{nullptr}; + m_calibName_chi2 = m_detector + "_hotTowers_fracBadChi2"; m_fieldname_chi2 = "fraction"; - std::string calibdir_chi2; if (!m_directURL_chi2.empty()) { - calibdir_chi2 = m_directURL_chi2; - std::cout << "CaloTowerStatus::InitRun: Using direct URL override for chi2: " << calibdir_chi2 << std::endl; - m_cdbttree_chi2 = new CDBTTree(calibdir_chi2); + std::cout << "CaloTowerStatus::InitRun: Using direct URL override for chi2: " << m_directURL_chi2 << std::endl; + cdbttree_chi2 = new CDBTTree(m_directURL_chi2); } else { - calibdir_chi2 = CDBInterface::instance()->getUrl(m_calibName_chi2); + std::string calibdir_chi2 = CDBInterface::instance()->getUrl(m_calibName_chi2); if (!calibdir_chi2.empty()) { - m_cdbttree_chi2 = new CDBTTree(calibdir_chi2); + cdbttree_chi2 = new CDBTTree(calibdir_chi2); if (Verbosity() > 0) { std::cout << "CaloTowerStatus::InitRun Found " << m_calibName_chi2 << " Doing isHot for frac bad chi2" << std::endl; } } - else + else { if (m_doAbortNoChi2) { @@ -114,6 +93,8 @@ int CaloTowerStatus::InitRun(PHCompositeNode *topNode) } } + CDBTTree *cdbttree_hotMap = nullptr; + m_calibName_hotMap = m_detector + "_BadTowerMap"; m_fieldname_hotMap = "status"; m_fieldname_z_score = m_detector + "_sigma"; @@ -123,14 +104,14 @@ int CaloTowerStatus::InitRun(PHCompositeNode *topNode) { calibdir_hotMap = m_directURL_hotMap; std::cout << "CaloTowerStatus::InitRun: Using direct URL override for hot map: " << calibdir_hotMap << std::endl; - m_cdbttree_hotMap = new CDBTTree(calibdir_hotMap); + cdbttree_hotMap = new CDBTTree(calibdir_hotMap); } else { calibdir_hotMap = CDBInterface::instance()->getUrl(m_calibName_hotMap); if (!calibdir_hotMap.empty()) { - m_cdbttree_hotMap = new CDBTTree(calibdir_hotMap); + cdbttree_hotMap = new CDBTTree(calibdir_hotMap); if (Verbosity() > 1) { std::cout << "CaloTowerStatus::Init " << m_detector << " hot map found " << m_calibName_hotMap << " Doing isHot" << std::endl; @@ -148,35 +129,19 @@ int CaloTowerStatus::InitRun(PHCompositeNode *topNode) { std::cout << "CaloTowerStatus::InitRun hot map info, " << m_calibName_hotMap << " not found, not doing isHot" << std::endl; } - } + } } if (Verbosity() > 0) { - std::cout << "CaloTowerStatus::Init " << m_detector << " doing hotBadChi2=" << std::boolalpha << m_doHotChi2 << " doing hot map=" << std::boolalpha << m_doHotMap << std::endl; + std::cout << "CaloTowerStatus::Init " << m_detector << " doing hotBadChi2=" << std::boolalpha << m_doHotChi2 << " doing hot map=" << std::boolalpha << m_doHotMap << std::endl; } - PHNodeIterator iter(topNode); + LoadCalib(cdbttree_chi2, cdbttree_hotMap); + + delete cdbttree_chi2; + delete cdbttree_hotMap; - // Looking for the DST node - PHCompositeNode *dstNode; - dstNode = dynamic_cast(iter.findFirst("PHCompositeNode", "DST")); - if (!dstNode) - { - std::cout << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__ - << "DST Node missing, doing nothing." << std::endl; - exit(1); - } - try - { - CreateNodeTree(topNode); - LoadCalib(); - } - catch (std::exception &e) - { - std::cout << e.what() << std::endl; - return Fun4AllReturnCodes::ABORTRUN; - } if (Verbosity() > 0) { topNode->print(); @@ -184,7 +149,7 @@ int CaloTowerStatus::InitRun(PHCompositeNode *topNode) return Fun4AllReturnCodes::EVENT_OK; } -void CaloTowerStatus::LoadCalib() +void CaloTowerStatus::LoadCalib(CDBTTree *cdbttree_chi2, CDBTTree *cdbttree_hotMap) { unsigned int ntowers = m_raw_towers->size(); m_cdbInfo_vec.resize(ntowers); @@ -193,14 +158,14 @@ void CaloTowerStatus::LoadCalib() { unsigned int key = m_raw_towers->encode_key(channel); - if (m_doHotChi2) + if (m_doHotChi2 && cdbttree_chi2) { - m_cdbInfo_vec[channel].fraction_badChi2 = m_cdbttree_chi2->GetFloatValue(key, m_fieldname_chi2); + m_cdbInfo_vec[channel].fraction_badChi2 = cdbttree_chi2->GetFloatValue(key, m_fieldname_chi2); } - if (m_doHotMap) + if (m_doHotMap && cdbttree_hotMap) { - m_cdbInfo_vec[channel].hotMap_val = m_cdbttree_hotMap->GetIntValue(key, m_fieldname_hotMap); - m_cdbInfo_vec[channel].z_score = m_cdbttree_hotMap->GetFloatValue(key, m_fieldname_z_score); + m_cdbInfo_vec[channel].hotMap_val = cdbttree_hotMap->GetIntValue(key, m_fieldname_hotMap); + m_cdbInfo_vec[channel].z_score = cdbttree_hotMap->GetFloatValue(key, m_fieldname_z_score); } } } @@ -234,14 +199,32 @@ int CaloTowerStatus::process_event(PHCompositeNode * /*topNode*/) { m_raw_towers->get_tower_at_channel(channel)->set_isHot(true); } - if (( hotMap_val == 1 || // dead - std::fabs(z_score) > z_score_threshold || // hot or cold - (hotMap_val == 3 && z_score >= -1 * z_score_threshold_default)) // cold part 2 - && m_doHotMap) + if (m_doHotMap) { - m_raw_towers->get_tower_at_channel(channel)->set_isHot(true); + bool is_hot_tower = false; + + // 1. Default behavior: rely on valid positive hotMap status codes only + if (z_score_threshold == z_score_threshold_default) + { + is_hot_tower = (hotMap_val > 0); + } + // 2. Custom behavior: evaluate based on the custom z_score threshold + else + { + bool is_dead = (hotMap_val == 1); + bool exceeds_zscore_limit = (std::abs(z_score) > z_score_threshold); // Captures both hot and cold by sigma + bool is_low_yield_cold = (hotMap_val == 3 && z_score >= -1 * z_score_threshold_default); // Captures the mean-based cold towers + + is_hot_tower = (is_dead || exceeds_zscore_limit || is_low_yield_cold); + } + + // Apply the result + if (is_hot_tower) + { + m_raw_towers->get_tower_at_channel(channel)->set_isHot(true); + } } - if (chi2 > std::min(std::max(badChi2_treshold_const, adc * adc * badChi2_treshold_quadratic),badChi2_treshold_max)) + if (chi2 > std::min(std::max(badChi2_treshold_const, adc * adc * badChi2_treshold_quadratic), badChi2_treshold_max)) { m_raw_towers->get_tower_at_channel(channel)->set_isBadChi2(true); } @@ -260,10 +243,9 @@ void CaloTowerStatus::CreateNodeTree(PHCompositeNode *topNode) if (!m_raw_towers) { std::cout << Name() << "::" << m_detector.c_str() << "::" << __PRETTY_FUNCTION__ - << " " << RawTowerNodeName << " Node missing, doing bail out!" + << " " << RawTowerNodeName << " Node missing, exiting!" << std::endl; - throw std::runtime_error( - "Failed to find " + RawTowerNodeName + " node in CaloTowerStatus::CreateNodes"); + gSystem->Exit(1); } return; diff --git a/offline/packages/CaloReco/CaloTowerStatus.h b/offline/packages/CaloReco/CaloTowerStatus.h index 9c261155c4..21cb652634 100644 --- a/offline/packages/CaloReco/CaloTowerStatus.h +++ b/offline/packages/CaloReco/CaloTowerStatus.h @@ -5,11 +5,8 @@ #include "CaloTowerDefs.h" -#include // for TowerInfoContainer, TowerIn... - #include -#include #include #include @@ -22,7 +19,7 @@ class CaloTowerStatus : public SubsysReco public: CaloTowerStatus(const std::string &name = "CaloTowerStatus"); - ~CaloTowerStatus() override; + ~CaloTowerStatus() override = default; int InitRun(PHCompositeNode *topNode) override; int process_event(PHCompositeNode *topNode) override; @@ -98,9 +95,6 @@ class CaloTowerStatus : public SubsysReco private: TowerInfoContainer *m_raw_towers{nullptr}; - CDBTTree *m_cdbttree_chi2{nullptr}; - CDBTTree *m_cdbttree_hotMap{nullptr}; - bool m_doHotChi2{true}; bool m_doHotMap{true}; bool m_doAbortNoHotMap{false}; @@ -121,13 +115,13 @@ class CaloTowerStatus : public SubsysReco std::string m_directURL_chi2; float badChi2_treshold_const = {1e4}; - float badChi2_treshold_quadratic = {1./100}; + float badChi2_treshold_quadratic = {1. / 100}; float badChi2_treshold_max = {1e8}; float fraction_badChi2_threshold = {0.01}; float z_score_threshold = {5}; float z_score_threshold_default = {5}; - void LoadCalib(); + void LoadCalib(CDBTTree *cdbttree_chi2, CDBTTree *cdbttree_hotMap); struct CDBInfo {