Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 53 additions & 71 deletions offline/packages/CaloReco/CaloTowerStatus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,17 @@

#include <ffamodules/CDBInterface.h>

#include <ffaobjects/EventHeader.h>

#include <fun4all/Fun4AllReturnCodes.h>
#include <fun4all/SubsysReco.h> // for SubsysReco

#include <phool/PHCompositeNode.h>
#include <phool/PHIODataNode.h> // for PHIODataNode
#include <phool/PHNode.h> // for PHNode
#include <phool/PHNodeIterator.h> // for PHNodeIterator
#include <phool/PHObject.h> // for PHObject
#include <phool/getClass.h>
#include <phool/phool.h>
#include <phool/recoConsts.h>

#include <TSystem.h>

#include <algorithm>
#include <cmath>
#include <cstdlib> // for exit
#include <exception> // for exception
#include <iostream> // for operator<<, basic_ostream
#include <stdexcept> // for runtime_error
#include <iostream> // for operator<<, basic_ostream

//____________________________________________________________________________..
CaloTowerStatus::CaloTowerStatus(const std::string &name)
Expand All @@ -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";
Expand All @@ -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)
{
Expand All @@ -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";
Expand All @@ -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;
Expand All @@ -148,43 +129,27 @@ 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<PHCompositeNode *>(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();
}
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);
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
Comment thread
Steepspace marked this conversation as resolved.

// 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);
}
Expand All @@ -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;
Expand Down
12 changes: 3 additions & 9 deletions offline/packages/CaloReco/CaloTowerStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

#include "CaloTowerDefs.h"

#include <calobase/TowerInfoContainer.h> // for TowerInfoContainer, TowerIn...

#include <fun4all/SubsysReco.h>

#include <iostream>
#include <string>
#include <vector>

Expand All @@ -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;
Expand Down Expand Up @@ -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};
Expand All @@ -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
{
Expand Down