ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterTritonTool Class Reference

GNN cluster energy calibration. More...

#include <CaloClusterTritonTool.h>

Inheritance diagram for CaloClusterTritonTool:
Collaboration diagram for CaloClusterTritonTool:

Public Member Functions

 CaloClusterTritonTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~CaloClusterTritonTool ()=default
virtual StatusCode initialize () override
virtual StatusCode inference (const xAOD::CaloClusterContainer &clusters, std::vector< double > &clusterE_GNN_vec) const override

Private Member Functions

StatusCode buildInputs (const xAOD::CaloCluster &cluster, AthInfer::InputDataMap &inputData, std::size_t &nCells) const
 Fill the input tensor map for one cluster; nCells is the number of cells retained after the energy threshold.
StatusCode inferCluster (const xAOD::CaloCluster &cluster, double &energyGeV, bool &valid) const
 Run inference for one cluster. energyGeV is meaningful only if valid.

Private Attributes

Gaudi::Property< float > m_cellEThreshold
Gaudi::Property< std::string > m_cellIdsName
Gaudi::Property< std::string > m_cellFeaturesName
Gaudi::Property< std::string > m_globalFeaturesName
Gaudi::Property< std::string > m_outputName
ToolHandle< AthInfer::IAthInferenceTool > m_tritonTool

Detailed Description

GNN cluster energy calibration.

Each cluster is represented as a graph of its constituent cells and sent to a Triton server through AthInfer::TritonTool.

Model signature (tensor names configurable): CELL_IDS : int64 [nCells, 1] compact 32-bit cell identifiers CELL_FEATURES : float [nCells, 1] weighted cell energy [GeV] GLOBAL_FEATURES : float [1] cluster raw (EM-scale) energy [GeV] OUTPUT : float [1, 1] predicted cluster energy [GeV]

Since the graph size varies per cluster, one request is issued per cluster. Clusters with no cells above threshold, or with a non-finite / non-positive prediction, fall back to the raw (EM-scale) energy.

Definition at line 34 of file CaloClusterTritonTool.h.

Constructor & Destructor Documentation

◆ CaloClusterTritonTool()

CaloClusterTritonTool::CaloClusterTritonTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Definition at line 17 of file CaloClusterTritonTool.cxx.

18 : base_class(type, name, parent) {}

◆ ~CaloClusterTritonTool()

virtual CaloClusterTritonTool::~CaloClusterTritonTool ( )
virtualdefault

Member Function Documentation

◆ buildInputs()

StatusCode CaloClusterTritonTool::buildInputs ( const xAOD::CaloCluster & cluster,
AthInfer::InputDataMap & inputData,
std::size_t & nCells ) const
private

Fill the input tensor map for one cluster; nCells is the number of cells retained after the energy threshold.

Definition at line 28 of file CaloClusterTritonTool.cxx.

31{
32 nCells = 0;
33
34 const CaloClusterCellLink *links = cluster.getCellLinks();
35 if (!links) {
36 ATH_MSG_DEBUG("Cluster " << cluster.index() << " has no cell links.");
37 return StatusCode::SUCCESS;
38 }
39 // The links store indices into a CaloCellContainer (normally AllCalo).
40 // If that container is not available, dereferencing a link is a null access.
41 if (!links->getCellContainer()) {
42 ATH_MSG_ERROR("Cell links of cluster " << cluster.index()
43 << " point to cell container '" << links->getCellContainerLink().dataID()
44 << "', which is not available in the event store.");
45 return StatusCode::FAILURE;
46 }
47
48 std::vector<int64_t> cellIds;
49 std::vector<float> cellEnergies;
50 cellIds.reserve(cluster.size());
51 cellEnergies.reserve(cluster.size());
52
53 for (auto itCell = cluster.cell_begin(); itCell != cluster.cell_end(); ++itCell) {
54 const CaloCell *cell = *itCell;
55 if (!cell) continue;
56
57 const float cellE = cell->e() * itCell.weight() / Gaudi::Units::GeV;
58 if (cellE < m_cellEThreshold) continue;
59
60 cellIds.push_back(static_cast<int64_t>(cell->ID().get_identifier32().get_compact()));
61 cellEnergies.push_back(cellE);
62 }
63
64 nCells = cellIds.size();
65 const int64_t n = static_cast<int64_t>(nCells);
66
67 std::vector<float> globalFeatures{static_cast<float>(cluster.rawE() / Gaudi::Units::GeV)};
68
69 inputData[m_cellIdsName.value()] =
70 std::make_pair(std::vector<int64_t>{n, 1}, std::move(cellIds));
71 inputData[m_cellFeaturesName.value()] =
72 std::make_pair(std::vector<int64_t>{n, 1}, std::move(cellEnergies));
73 inputData[m_globalFeaturesName.value()] =
74 std::make_pair(std::vector<int64_t>{1}, std::move(globalFeatures));
75
76 return StatusCode::SUCCESS;
77}
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
Gaudi::Property< std::string > m_cellIdsName
Gaudi::Property< std::string > m_globalFeaturesName
Gaudi::Property< float > m_cellEThreshold
Gaudi::Property< std::string > m_cellFeaturesName
flt_t rawE() const
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version).
size_t size() const
size method (forwarded from CaloClusterCellLink obj)
const_cell_iterator cell_end() const
const_cell_iterator cell_begin() const
Iterator of the underlying CaloClusterCellLink (const version).
setRawEt setRawPhi nCells

◆ inferCluster()

StatusCode CaloClusterTritonTool::inferCluster ( const xAOD::CaloCluster & cluster,
double & energyGeV,
bool & valid ) const
private

Run inference for one cluster. energyGeV is meaningful only if valid.

Definition at line 79 of file CaloClusterTritonTool.cxx.

82{
83 energyGeV = 0.0;
84 valid = false;
85
86 AthInfer::InputDataMap inputData;
87 std::size_t nCells = 0;
88 ATH_CHECK(buildInputs(cluster, inputData, nCells));
89 if (nCells == 0) return StatusCode::SUCCESS;
90
91 AthInfer::OutputDataMap outputData;
92 outputData[m_outputName.value()] =
93 std::make_pair(std::vector<int64_t>{1, 1}, std::vector<float>{});
94
95 ATH_CHECK(m_tritonTool->inference(inputData, outputData));
96
97 const auto itOut = outputData.find(m_outputName.value());
98 if (itOut == outputData.end()) {
99 ATH_MSG_ERROR("Output tensor '" << m_outputName.value() << "' not returned by server.");
100 return StatusCode::FAILURE;
101 }
102
103 const auto &data = itOut->second.second;
104 if (const auto *vf = std::get_if<std::vector<float>>(&data); vf && !vf->empty()) {
105 energyGeV = vf->front();
106 valid = true;
107 } else if (const auto *vi = std::get_if<std::vector<int64_t>>(&data); vi && !vi->empty()) {
108 energyGeV = static_cast<double>(vi->front());
109 valid = true;
110 }
111
112 return StatusCode::SUCCESS;
113}
#define ATH_CHECK
Evaluate an expression and check for errors.
Gaudi::Property< std::string > m_outputName
StatusCode buildInputs(const xAOD::CaloCluster &cluster, AthInfer::InputDataMap &inputData, std::size_t &nCells) const
Fill the input tensor map for one cluster; nCells is the number of cells retained after the energy th...
ToolHandle< AthInfer::IAthInferenceTool > m_tritonTool
std::map< std::string, InferenceData > OutputDataMap
std::map< std::string, InferenceData > InputDataMap
list valid
Definition calibdata.py:44

◆ inference()

StatusCode CaloClusterTritonTool::inference ( const xAOD::CaloClusterContainer & clusters,
std::vector< double > & clusterE_GNN_vec ) const
overridevirtual

Definition at line 115 of file CaloClusterTritonTool.cxx.

117{
118 ATH_MSG_DEBUG("Executing " << name() << "...");
119
120 clusterE_GNN_vec.clear();
121 clusterE_GNN_vec.reserve(clusters.size());
122
123 std::size_t nFallback = 0;
124
125 for (const xAOD::CaloCluster *cluster : clusters) {
126 const double rawE = cluster->rawE(); // MeV
127
128 double energyGeV = 0.0;
129 bool valid = false;
130 ATH_CHECK(inferCluster(*cluster, energyGeV, valid));
131
132 if (valid && std::isfinite(energyGeV) && energyGeV > 0.0) {
133 clusterE_GNN_vec.push_back(energyGeV * Gaudi::Units::GeV);
134 } else {
135 clusterE_GNN_vec.push_back(rawE);
136 ++nFallback;
137 }
138 }
139
140 if (nFallback > 0) {
141 ATH_MSG_DEBUG(nFallback << " of " << clusters.size()
142 << " clusters fell back to raw energy (no cells above threshold or invalid prediction).");
143 }
144
145 return StatusCode::SUCCESS;
146}
StatusCode inferCluster(const xAOD::CaloCluster &cluster, double &energyGeV, bool &valid) const
Run inference for one cluster. energyGeV is meaningful only if valid.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.

◆ initialize()

StatusCode CaloClusterTritonTool::initialize ( )
overridevirtual

Definition at line 20 of file CaloClusterTritonTool.cxx.

21{
22 ATH_MSG_DEBUG("Initializing " << name() << "...");
23 ATH_CHECK(m_tritonTool.retrieve());
24 ATH_MSG_INFO("Cell energy threshold for graph construction: " << m_cellEThreshold.value() << " GeV");
25 return StatusCode::SUCCESS;
26}
#define ATH_MSG_INFO(x,...)

Member Data Documentation

◆ m_cellEThreshold

Gaudi::Property<float> CaloClusterTritonTool::m_cellEThreshold
private
Initial value:
{
this, "CellEnergyThreshold", 0.005f,
"Minimum weighted cell energy [GeV] for a cell to enter the graph"}

Definition at line 57 of file CaloClusterTritonTool.h.

57 {
58 this, "CellEnergyThreshold", 0.005f,
59 "Minimum weighted cell energy [GeV] for a cell to enter the graph"};

◆ m_cellFeaturesName

Gaudi::Property<std::string> CaloClusterTritonTool::m_cellFeaturesName
private
Initial value:
{
this, "CellFeaturesInputName", "CELL_FEATURES", "Name of the cell-feature input tensor"}

Definition at line 63 of file CaloClusterTritonTool.h.

63 {
64 this, "CellFeaturesInputName", "CELL_FEATURES", "Name of the cell-feature input tensor"};

◆ m_cellIdsName

Gaudi::Property<std::string> CaloClusterTritonTool::m_cellIdsName
private
Initial value:
{
this, "CellIdsInputName", "CELL_IDS", "Name of the cell-ID input tensor"}

Definition at line 61 of file CaloClusterTritonTool.h.

61 {
62 this, "CellIdsInputName", "CELL_IDS", "Name of the cell-ID input tensor"};

◆ m_globalFeaturesName

Gaudi::Property<std::string> CaloClusterTritonTool::m_globalFeaturesName
private
Initial value:
{
this, "GlobalFeaturesInputName", "GLOBAL_FEATURES", "Name of the global-feature input tensor"}

Definition at line 65 of file CaloClusterTritonTool.h.

65 {
66 this, "GlobalFeaturesInputName", "GLOBAL_FEATURES", "Name of the global-feature input tensor"};

◆ m_outputName

Gaudi::Property<std::string> CaloClusterTritonTool::m_outputName
private
Initial value:
{
this, "OutputName", "OUTPUT", "Name of the output tensor"}

Definition at line 67 of file CaloClusterTritonTool.h.

67 {
68 this, "OutputName", "OUTPUT", "Name of the output tensor"};

◆ m_tritonTool

ToolHandle<AthInfer::IAthInferenceTool> CaloClusterTritonTool::m_tritonTool
private
Initial value:
{
this, "TritonInferenceTool", "AthInfer::TritonTool",
"Inference tool forwarding requests to the Triton server"}

Definition at line 70 of file CaloClusterTritonTool.h.

70 {
71 this, "TritonInferenceTool", "AthInfer::TritonTool",
72 "Inference tool forwarding requests to the Triton server"};

The documentation for this class was generated from the following files: