ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
CaloClusterMLCalibToolLite Class Reference

#include <CaloClusterMLCalibToolLite.h>

Inheritance diagram for CaloClusterMLCalibToolLite:
Collaboration diagram for CaloClusterMLCalibToolLite:

Public Member Functions

 CaloClusterMLCalibToolLite (const std::string &type, const std::string &name, const IInterface *parent)
 
 ~CaloClusterMLCalibToolLite ()
 
virtual StatusCode initialize () override
 
virtual StatusCode finalize () override
 
virtual StatusCode inference (const xAOD::CaloClusterContainer &clusters, const int &nPrimVtx, const double &avgMu, std::vector< double > &clusterE_ML_vec, std::vector< double > &clusterE_ML_Unc_vec) const override
 

Private Attributes

Gaudi::Property< std::vector< std::string > > m_preprocessingTransformNames {this, "PreprocessingTransformNames", {}, "Names of preprocessing transforms"}
 
Gaudi::Property< std::vector< std::vector< double > > > m_preprocessingTransformParams {this, "PreprocessingTransformParams", {}, "Parameters for preprocessing transforms"}
 
int m_numFeatures = 0
 
std::vector< PreprocessTransformm_featurePreprocessingTransforms
 
ToolHandle< AthInfer::IAthInferenceToolm_onnxTool
 

Detailed Description

Definition at line 24 of file CaloClusterMLCalibToolLite.h.

Constructor & Destructor Documentation

◆ CaloClusterMLCalibToolLite()

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

Definition at line 12 of file CaloClusterMLCalibToolLite.cxx.

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

◆ ~CaloClusterMLCalibToolLite()

CaloClusterMLCalibToolLite::~CaloClusterMLCalibToolLite ( )

Definition at line 14 of file CaloClusterMLCalibToolLite.cxx.

14 {}

Member Function Documentation

◆ finalize()

StatusCode CaloClusterMLCalibToolLite::finalize ( )
overridevirtual

Definition at line 194 of file CaloClusterMLCalibToolLite.cxx.

195 {
196  ATH_MSG_DEBUG("Finalizing " << name() << "...");
197  return StatusCode::SUCCESS;
198 }

◆ inference()

StatusCode CaloClusterMLCalibToolLite::inference ( const xAOD::CaloClusterContainer clusters,
const int &  nPrimVtx,
const double &  avgMu,
std::vector< double > &  clusterE_ML_vec,
std::vector< double > &  clusterE_ML_Unc_vec 
) const
overridevirtual

Definition at line 46 of file CaloClusterMLCalibToolLite.cxx.

47 {
48  ATH_MSG_DEBUG("Executing " << name() << "...");
49 
50  double clusterE = 0;
51  double clusterEta = 0;
52  double cluster_SIGNIFICANCE = 0;
53  double cluster_time = 0;
54  double cluster_SECOND_TIME = 0;
55  double cluster_CENTER_LAMBDA = 0;
56  double cluster_CENTER_MAG = 0;
57  double cluster_ENG_FRAC_EM_INCL = 0;
58  double cluster_FIRST_ENG_DENS = 0;
59  double cluster_LONGITUDINAL = 0;
60  double cluster_LATERAL = 0;
61  double cluster_PTD = 0;
62  double cluster_ISOLATION = 0;
63  double clusterE_TRUTH = 0;
64 
65  std::vector<float> transformedFeatures;
66  bool ok{}; //for checking return value of cluster->retrieveMoment
67  for (const xAOD::CaloCluster *cluster : clusters)
68  {
69  clusterE = cluster->e(xAOD::CaloCluster::UNCALIBRATED) / Gaudi::Units::GeV;
70  clusterEta = cluster->eta(xAOD::CaloCluster::UNCALIBRATED);
71  //set ok to first return value
72  ok = cluster->retrieveMoment(xAOD::CaloCluster::MomentType::ENG_CALIB_TOT, clusterE_TRUTH);
73  clusterE_TRUTH /= Gaudi::Units::GeV;
74  ok &= cluster->retrieveMoment(xAOD::CaloCluster::MomentType::SIGNIFICANCE, cluster_SIGNIFICANCE);
75  ok &= cluster->retrieveMoment(xAOD::CaloCluster::MomentType::SECOND_TIME, cluster_SECOND_TIME);
76  cluster_SECOND_TIME /= (Gaudi::Units::nanosecond * Gaudi::Units::nanosecond);
77  ok &= cluster->retrieveMoment(xAOD::CaloCluster::MomentType::CENTER_LAMBDA, cluster_CENTER_LAMBDA);
78  cluster_CENTER_LAMBDA /= Gaudi::Units::millimeter;
79  ok &= cluster->retrieveMoment(xAOD::CaloCluster::MomentType::CENTER_MAG, cluster_CENTER_MAG);
80  ok &= cluster->retrieveMoment(xAOD::CaloCluster::MomentType::FIRST_ENG_DENS, cluster_FIRST_ENG_DENS);
81  cluster_FIRST_ENG_DENS /= (Gaudi::Units::GeV / Gaudi::Units::millimeter3);
82  ok &= cluster->retrieveMoment(xAOD::CaloCluster::MomentType::LONGITUDINAL, cluster_LONGITUDINAL);
83  ok &= cluster->retrieveMoment(xAOD::CaloCluster::MomentType::LATERAL, cluster_LATERAL);
84  ok &= cluster->retrieveMoment(xAOD::CaloCluster::MomentType::PTD, cluster_PTD);
85  ok &= cluster->retrieveMoment(xAOD::CaloCluster::MomentType::ISOLATION, cluster_ISOLATION);
86  cluster_time = cluster->time() / Gaudi::Units::nanosecond;
87  if (not ok) {
88  ATH_MSG_WARNING("CaloClusterMLCalibToolLite: retrieveMoment failed for "<<cluster);
89  }
90  float e_EM = 0.0;
92  {
94  {
95  e_EM += cluster->eSample(static_cast<xAOD::CaloCluster::CaloSample>(s));
96  }
97  }
98  cluster_ENG_FRAC_EM_INCL = e_EM / cluster->rawE();
99 
100  std::vector<float> rawValues;
101 
102  rawValues.push_back(clusterE);
103  rawValues.push_back(clusterEta);
104  rawValues.push_back(cluster_SIGNIFICANCE);
105  rawValues.push_back(cluster_time);
106  rawValues.push_back(cluster_SECOND_TIME);
107  rawValues.push_back(cluster_CENTER_LAMBDA);
108  rawValues.push_back(cluster_CENTER_MAG);
109  rawValues.push_back(cluster_ENG_FRAC_EM_INCL);
110  rawValues.push_back(cluster_FIRST_ENG_DENS);
111  rawValues.push_back(cluster_LONGITUDINAL);
112  rawValues.push_back(cluster_LATERAL);
113  rawValues.push_back(cluster_PTD);
114  rawValues.push_back(cluster_ISOLATION);
115  rawValues.push_back(nPrimVtx);
116  rawValues.push_back(avgMu);
117 
118  for (int i = 0; i < m_numFeatures; i++)
119  {
121  const float &raw = rawValues.at(i);
122  float transformed = transform.processor(raw, transform.parameters);
123  transformedFeatures.push_back(transformed);
124  }
125  }
126 
127  int numClusters = clusters.size();
128  std::vector<int64_t> inputShape = {numClusters, 15};
129 
130  AthInfer::InputDataMap inputData;
131  inputData["features"] = std::make_pair(
132  inputShape, std::move(transformedFeatures));
133 
134  AthInfer::OutputDataMap outputData; // Looks like there is bug in AthInfer at this moment,
135  // using actual names for the output layers doesn't ensure correct mapping.
136  outputData["0"] = std::make_pair( // Hence using dummy names like "0", "1" and "2" to avoid confusion.
137  std::vector<int64_t>{numClusters, 3}, std::vector<float>{});
138  outputData["1"] = std::make_pair(
139  std::vector<int64_t>{numClusters, 3}, std::vector<float>{});
140  outputData["2"] = std::make_pair(
141  std::vector<int64_t>{numClusters, 3}, std::vector<float>{});
142 
143  ATH_CHECK(m_onnxTool->inference(inputData, outputData));
144 
145  std::vector<float> &onnx_mus = std::get<std::vector<float>>(outputData["0"].second);
146  std::vector<float> &onnx_sigma2s = std::get<std::vector<float>>(outputData["1"].second);
147  std::vector<float> &onnx_alphas = std::get<std::vector<float>>(outputData["2"].second);
148 
149  for (float val : onnx_mus)
150  {
151  if (std::isnan(val))
152  {
153  ATH_MSG_WARNING("NaN value found in `mus` output layer during ONNX inference");
154  }
155  }
156  for (float val : onnx_sigma2s)
157  {
158  if (std::isnan(val))
159  {
160  ATH_MSG_WARNING("NaN value found in `sigma2s` output layer during ONNX inference");
161  }
162  }
163  for (float val : onnx_alphas)
164  {
165  if (std::isnan(val))
166  {
167  ATH_MSG_WARNING("NaN value found in `alphas` output layer during ONNX inference");
168  }
169  }
170 
171  clusterE_ML_vec.clear();
172  clusterE_ML_Unc_vec.clear();
173  clusterE_ML_vec.reserve(numClusters);
174  clusterE_ML_Unc_vec.reserve(numClusters);
175 
176  for (int i = 0; i < numClusters; ++i)
177  {
178  std::vector<float> current_mus = {onnx_mus[i * 3], onnx_mus[i * 3 + 1], onnx_mus[i * 3 + 2]};
179  std::vector<float> current_sigma2s = {onnx_sigma2s[i * 3], onnx_sigma2s[i * 3 + 1], onnx_sigma2s[i * 3 + 2]};
180  std::vector<float> current_alphas = {onnx_alphas[i * 3], onnx_alphas[i * 3 + 1], onnx_alphas[i * 3 + 2]};
181 
182  float mode = CaloClusterMLCalib::modes(current_mus, current_sigma2s, current_alphas);
183  float r = std::pow(10, mode);
184  float onnx_s = CaloClusterMLCalib::sigma_stoch(current_mus, current_sigma2s, current_alphas);
185  float s = std::abs(std::log(10) * r) * onnx_s;
186 
187  clusterE_ML_vec.push_back((clusters[i]->e(xAOD::CaloCluster::UNCALIBRATED) / static_cast<double>(r)));
188  clusterE_ML_Unc_vec.push_back(static_cast<double>(s));
189  }
190 
191  return StatusCode::SUCCESS;
192 }

◆ initialize()

StatusCode CaloClusterMLCalibToolLite::initialize ( )
overridevirtual

Definition at line 16 of file CaloClusterMLCalibToolLite.cxx.

17 {
18  ATH_MSG_DEBUG("Initializing " << name() << "...");
20  for (int i = 0; i < m_numFeatures; i++)
21  {
25  {
26  transform.processor = funcIt->second;
27  std::vector<float> floatParams;
28  for (double param : m_preprocessingTransformParams[i])
29  {
30  floatParams.push_back(static_cast<float>(param));
31  }
32  transform.parameters = std::move(floatParams);
33  m_featurePreprocessingTransforms.push_back(std::move(transform));
34  }
35  else
36  {
37  ATH_MSG_WARNING("Undefined transformation " << m_preprocessingTransformNames[i]);
38  return StatusCode::FAILURE;
39  }
40  }
41 
42  ATH_CHECK(m_onnxTool.retrieve());
43  return StatusCode::SUCCESS;
44 }

Member Data Documentation

◆ m_featurePreprocessingTransforms

std::vector<PreprocessTransform> CaloClusterMLCalibToolLite::m_featurePreprocessingTransforms
private

Definition at line 42 of file CaloClusterMLCalibToolLite.h.

◆ m_numFeatures

int CaloClusterMLCalibToolLite::m_numFeatures = 0
private

Definition at line 41 of file CaloClusterMLCalibToolLite.h.

◆ m_onnxTool

ToolHandle<AthInfer::IAthInferenceTool> CaloClusterMLCalibToolLite::m_onnxTool
private
Initial value:
{
this, "ORTInferenceTool", "AthOnnx::OnnxRuntimeInferenceTool"}

Definition at line 44 of file CaloClusterMLCalibToolLite.h.

◆ m_preprocessingTransformNames

Gaudi::Property<std::vector<std::string> > CaloClusterMLCalibToolLite::m_preprocessingTransformNames {this, "PreprocessingTransformNames", {}, "Names of preprocessing transforms"}
private

Definition at line 38 of file CaloClusterMLCalibToolLite.h.

◆ m_preprocessingTransformParams

Gaudi::Property<std::vector<std::vector<double> > > CaloClusterMLCalibToolLite::m_preprocessingTransformParams {this, "PreprocessingTransformParams", {}, "Parameters for preprocessing transforms"}
private

Definition at line 39 of file CaloClusterMLCalibToolLite.h.


The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
beamspotman.r
def r
Definition: beamspotman.py:672
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
CaloClusterMLCalibToolLite::m_featurePreprocessingTransforms
std::vector< PreprocessTransform > m_featurePreprocessingTransforms
Definition: CaloClusterMLCalibToolLite.h:42
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
CaloClusterMLCalibToolLite::m_preprocessingTransformParams
Gaudi::Property< std::vector< std::vector< double > > > m_preprocessingTransformParams
Definition: CaloClusterMLCalibToolLite.h:39
python.SystemOfUnits.nanosecond
float nanosecond
Definition: SystemOfUnits.py:134
PreprocessTransform
Definition: CaloClusterMLCalibToolLite.h:19
python.SystemOfUnits.millimeter
float millimeter
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration # This software is distribute...
Definition: SystemOfUnits.py:62
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
CaloClusterMLCalibToolLite::m_onnxTool
ToolHandle< AthInfer::IAthInferenceTool > m_onnxTool
Definition: CaloClusterMLCalibToolLite.h:44
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
TauClusterVars::CENTER_MAG
bool CENTER_MAG(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, float &out)
Definition: ConstituentLoaderTauCluster.cxx:216
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
CaloClusterMLCalib::TRANSFORMATIONS
const std::map< std::string, TransformFunc > TRANSFORMATIONS
Definition: CaloClusterMLCalibFeatureTransform.h:81
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloClusterMLCalibToolLite::m_preprocessingTransformNames
Gaudi::Property< std::vector< std::string > > m_preprocessingTransformNames
Definition: CaloClusterMLCalibToolLite.h:38
AthInfer::OutputDataMap
std::map< std::string, InferenceData > OutputDataMap
Definition: IAthInferenceTool.h:17
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
test_pyathena.parent
parent
Definition: test_pyathena.py:15
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TauClusterVars::FIRST_ENG_DENS
bool FIRST_ENG_DENS(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, float &out)
Definition: ConstituentLoaderTauCluster.cxx:202
Preparation.mode
mode
Definition: Preparation.py:107
CaloClusterMLCalib::sigma_stoch
float sigma_stoch(const std::vector< float > &mus, const std::vector< float > &log_sigma2s, const std::vector< float > &alphas)
Definition: CaloClusterMLGaussianMixture.h:87
CaloClusterMLCalib::modes
float modes(const std::vector< float > &mus, const std::vector< float > &log_sigma2s, const std::vector< float > &alphas)
Definition: CaloClusterMLGaussianMixture.h:55
xAOD::CaloCluster_v1::UNCALIBRATED
@ UNCALIBRATED
Definition: CaloCluster_v1.h:309
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
CaloClusterMLCalibToolLite::m_numFeatures
int m_numFeatures
Definition: CaloClusterMLCalibToolLite.h:41
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
TauClusterVars::CENTER_LAMBDA
bool CENTER_LAMBDA(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, float &out)
Definition: ConstituentLoaderTauCluster.cxx:138
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
python.SystemOfUnits.millimeter3
float millimeter3
Definition: SystemOfUnits.py:64
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
AthInfer::InputDataMap
std::map< std::string, InferenceData > InputDataMap
Definition: IAthInferenceTool.h:16
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56