49 std::vector<double> &clusterE_ML_vec,
50 std::vector<double> &clusterE_ML_Unc_vec)
const
55 double clusterEta = 0;
56 double cluster_SIGNIFICANCE = 0;
57 double cluster_time = 0;
58 double cluster_SECOND_TIME = 0;
59 double cluster_CENTER_LAMBDA = 0;
60 double cluster_CENTER_MAG = 0;
61 double cluster_ENG_FRAC_EM_INCL = 0;
62 double cluster_FIRST_ENG_DENS = 0;
63 double cluster_LONGITUDINAL = 0;
64 double cluster_LATERAL = 0;
65 double cluster_PTD = 0;
66 double cluster_ISOLATION = 0;
68 std::vector<float> transformedFeatures;
69 std::vector<bool> clusterInputsValid;
70 clusterInputsValid.reserve(clusters.size());
79 cluster_SECOND_TIME /= (Gaudi::Units::nanosecond * Gaudi::Units::nanosecond);
81 cluster_CENTER_LAMBDA /= Gaudi::Units::millimeter;
84 cluster_FIRST_ENG_DENS /= (Gaudi::Units::GeV / Gaudi::Units::millimeter3);
89 cluster_time = cluster->time() / Gaudi::Units::nanosecond;
93 return StatusCode::FAILURE;
97 for (
size_t s = CaloSampling::PreSamplerB; s < CaloSampling::Unknown; s++)
99 if (s == CaloSampling::EMB1 || s == CaloSampling::EMB2 || s == CaloSampling::EMB3 || s == CaloSampling::EME1 || s == CaloSampling::EME2 || s == CaloSampling::EME3 || s == CaloSampling::FCAL0)
104 cluster_ENG_FRAC_EM_INCL = e_EM / cluster->rawE();
106 std::vector<float> rawValues = {
107 static_cast<float>(clusterE),
108 static_cast<float>(clusterEta),
109 static_cast<float>(cluster_SIGNIFICANCE),
110 static_cast<float>(cluster_time),
111 static_cast<float>(cluster_SECOND_TIME),
112 static_cast<float>(cluster_CENTER_LAMBDA),
113 static_cast<float>(cluster_CENTER_MAG),
114 static_cast<float>(cluster_ENG_FRAC_EM_INCL),
115 static_cast<float>(cluster_FIRST_ENG_DENS),
116 static_cast<float>(cluster_LONGITUDINAL),
117 static_cast<float>(cluster_LATERAL),
118 static_cast<float>(cluster_PTD),
119 static_cast<float>(cluster_ISOLATION),
120 static_cast<float>(nPrimVtx),
124 bool inputsValid =
true;
128 const float raw = rawValues.at(i);
130 if (!std::isfinite(transformed)) {
136 transformedFeatures.push_back(transformed);
138 clusterInputsValid.push_back(inputsValid);
141 int numClusters = clusters.size();
142 std::vector<int64_t> inputShape = {numClusters, 15};
145 inputData[
"features"] = std::make_pair(
146 inputShape, std::move(transformedFeatures));
150 outputData[
"mus"] = std::make_pair(
151 std::vector<int64_t>{numClusters, 3}, std::vector<float>{});
152 outputData[
"sigmas"] = std::make_pair(
153 std::vector<int64_t>{numClusters, 3}, std::vector<float>{});
154 outputData[
"alphas"] = std::make_pair(
155 std::vector<int64_t>{numClusters, 3}, std::vector<float>{});
159 std::vector<float> &onnx_mus = std::get<std::vector<float>>(outputData[
"mus"].second);
160 std::vector<float> &onnx_sigma2s = std::get<std::vector<float>>(outputData[
"sigmas"].second);
161 std::vector<float> &onnx_alphas = std::get<std::vector<float>>(outputData[
"alphas"].second);
163 if (msgLvl(MSG::DEBUG)) {
165 int nan_in_sigma2s = 0;
166 int nan_in_alphas = 0;
168 for (
float val : onnx_mus)
172 for (
float val : onnx_sigma2s)
176 for (
float val : onnx_alphas)
181 ATH_MSG_DEBUG(nan_in_mus <<
" NaN value found in `mus` output layer during ONNX inference");
184 ATH_MSG_DEBUG(nan_in_sigma2s <<
" NaN value found in `sigmas` output layer during ONNX inference");
187 ATH_MSG_DEBUG(nan_in_alphas <<
" NaN value found in `alphas` output layer during ONNX inference");
190 clusterE_ML_vec.clear();
191 clusterE_ML_Unc_vec.clear();
192 clusterE_ML_vec.reserve(numClusters);
193 clusterE_ML_Unc_vec.reserve(numClusters);
195 for (
int i = 0; i < numClusters; ++i)
197 bool calibrateCluster = clusterInputsValid.at(i);
198 for (
size_t j=0; j<3; ++j) {
199 if (std::isnan(onnx_mus[i*3+j]) || std::isnan(onnx_sigma2s[i*3+j]) || std::isnan(onnx_alphas[i*3+j])) {
200 calibrateCluster =
false;
206 if (calibrateCluster) {
207 std::vector<float> current_mus = {onnx_mus[i * 3], onnx_mus[i * 3 + 1], onnx_mus[i * 3 + 2]};
208 std::vector<float> current_sigma2s = {onnx_sigma2s[i * 3], onnx_sigma2s[i * 3 + 1], onnx_sigma2s[i * 3 + 2]};
209 std::vector<float> current_alphas = {onnx_alphas[i * 3], onnx_alphas[i * 3 + 1], onnx_alphas[i * 3 + 2]};
212 r = std::pow(10, mode);
214 s = std::abs(std::log(10) *
r) * onnx_s;
216 if (!std::isfinite(
r) || std::abs(
r) < 1e-6) {
217 ATH_MSG_WARNING(
"ML-correction factor to cluster energy (used as denominator) is " <<
r <<
"; The ML-correction factor is reset to 1. Uncertainty is set to 0.");
225 clusterE_ML_vec.push_back(cluster_energy);
226 clusterE_ML_Unc_vec.push_back(
static_cast<double>(s));
229 return StatusCode::SUCCESS;