23 "weta2",
"weta1",
"Rphi",
"Reta",
"wtots1",
"Rhad",
"Rhad1",
"f1",
"fracs1",
"DeltaE",
"Eratio"
52 unsigned long long key = eventNumber;
55 const long long phiBin =
static_cast<long long>(std::floor((
phi +
static_cast<float>(
M_PI)) * 100.0f));
56 key = eventNumber +
static_cast<unsigned long long>(phiBin);
59 return static_cast<int>(key %
m_nFolds);
74 const std::vector<float>&
ss)
const
81 static const SG::AuxElement::Accessor<int> acc_truthType(
"truthType");
82 if (!acc_truthType.isAvailable(photon)) {
83 ATH_MSG_WARNING(
"ApplyTo = TruthPhotons but truthType not available — skipping photon");
86 int truthType = acc_truthType(photon);
87 if (truthType < 13 || truthType > 15)
return false;
93 if (
ss[0] <= -10.f ||
ss[0] >= 10.f)
return false;
95 if (
ss[1] <= -10.f ||
ss[1] >= 10.f)
return false;
97 if (
ss[2] <= -10.f ||
ss[2] >= 10.f)
return false;
99 if (
ss[3] <= -10.f ||
ss[3] >= 10.f)
return false;
101 if (
ss[4] < -2.f ||
ss[4] >= 10.f)
return false;
103 if (
ss[5] < -2.f ||
ss[5] > 2.f)
return false;
105 if (
ss[6] < -2.f ||
ss[6] > 2.f)
return false;
107 if (
ss[7] <= -2.f ||
ss[7] >= 2.f)
return false;
109 if (
ss[8] <= -2.f ||
ss[8] >= 5.f)
return false;
111 if (
ss[9] < 0.f ||
ss[9] >= 5000.f)
return false;
113 if (
ss[10] < 0.f ||
ss[10] > 1.f)
return false;
125 ATH_MSG_ERROR(
"ConfigFile property is empty. Please provide a config file to the tool.");
126 return StatusCode::FAILURE;
130 if (resolvedConfig.empty()) {
132 return StatusCode::FAILURE;
137 env.ReadFile(resolvedConfig.c_str(), kEnvLocal);
138 env.IgnoreDuplicates(
false);
140 const int nFoldsConfig = env.GetValue(
"NFolds", 0);
141 if (nFoldsConfig <= 0) {
142 ATH_MSG_ERROR(
"NFolds not set or invalid in config: " << resolvedConfig);
143 return StatusCode::FAILURE;
149 return StatusCode::FAILURE;
156 TString pattern = env.GetValue(
"ONNXnamePattern",
"");
157 if (pattern.IsNull()) {
158 ATH_MSG_ERROR(
"ONNXnamePattern not set in config: " << resolvedConfig);
159 return StatusCode::FAILURE;
164 TString
fs = env.GetValue(
"FoldStrategy",
"eventNumber");
165 std::string fsStr =
fs.Data();
170 ATH_MSG_ERROR(
"FoldStrategy must be 'eventNumber' or 'eventNumber_phi', but got '" << fsStr <<
"' in config: " << resolvedConfig);
171 return StatusCode::FAILURE;
180 return StatusCode::FAILURE;
188 return StatusCode::FAILURE;
201 for (
int i = 0; i <
m_nFolds; ++i) {
213 m_accessors[i].original = std::make_unique<SG::AuxElement::Accessor<float>>(var +
"_original");
220 return StatusCode::SUCCESS;
229 std::vector<float>
ss(nSS);
232 for (
size_t i = 0; i < nSS; ++i) {
238 static const SG::AuxElement::Decorator<char> dec_pass(
"NFCorrectedShowerShapes");
243 dec_pass(photon) = pass ? 1 : 0;
258 const unsigned long long eventNumber =
h->eventNumber();
259 float ptGeV = photon.pt() / 1000.0f;
260 const float phi =
static_cast<float>(photon.phi());
272 std::vector<float> kinematic = {
274 static_cast<float>(photon.eta()),
275 static_cast<float>(photon.phi()),
276 static_cast<float>(isConv)
280 std::vector<Ort::Value> inputTensors;
285 int64_t batchSizeKin = onnxToolForward->getBatchSize(
286 static_cast<int64_t
>(kinematic.size()), 0);
287 if (onnxToolForward->addInput(inputTensors, kinematic, 0, batchSizeKin).isFailure()) {
288 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add kinematic input tensor");
293 int64_t batchSizeSS = onnxToolForward->getBatchSize(
294 static_cast<int64_t
>(
ss.size()), 1);
295 if (onnxToolForward->addInput(inputTensors,
ss, 1, batchSizeSS).isFailure()) {
296 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add shower shape input tensor");
300 std::vector<Ort::Value> outputTensors;
301 std::vector<float> outputData;
302 if (onnxToolForward->addOutput(outputTensors, outputData, 0, batchSizeKin).isFailure()) {
303 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add forward output tensor");
307 if (onnxToolForward->inference(inputTensors, outputTensors).isFailure()) {
308 ATH_MSG_ERROR(
"Fold " << fold <<
": forward inference failed");
312 float* zPtr = outputTensors[0].GetTensorMutableData<
float>();
313 std::vector<float> zVec(zPtr, zPtr + nSS);
317 std::vector<Ort::Value> inputTensorsBack;
318 std::vector<Ort::Value> outputTensorsBack;
319 std::vector<float> outputDataBack;
324 int64_t batchSizeKinBack = onnxToolBackward->getBatchSize(
325 static_cast<int64_t
>(kinematic.size()), 0);
326 if (onnxToolBackward->addInput(inputTensorsBack, kinematic, 0, batchSizeKinBack).isFailure()) {
327 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add kinematic input tensor for backward model");
332 int64_t batchSizeZBack = onnxToolBackward->getBatchSize(
static_cast<int64_t
>(zVec.size()), 1);
334 if (onnxToolBackward->addInput(inputTensorsBack, zVec, 1, batchSizeZBack).isFailure()) {
335 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add z input tensor for backward model");
340 if (onnxToolBackward->addInput(inputTensorsBack,
ss, 2, batchSizeKinBack).isFailure()) {
341 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add original SS input tensor for backward model");
345 if (onnxToolBackward->addOutput(outputTensorsBack, outputDataBack, 0, batchSizeZBack).isFailure()) {
346 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add backward output tensor");
350 if (onnxToolBackward->inference(inputTensorsBack, outputTensorsBack).isFailure()) {
351 ATH_MSG_ERROR(
"Fold " << fold <<
": backward inference failed");
355 const auto infoB = outputTensorsBack[0].GetTensorTypeAndShapeInfo();
356 const auto nElB = infoB.GetElementCount();
358 ATH_MSG_ERROR(
"Fold "<<fold <<
": backward output has " <<nElB<<
" elements, expected "<<nSS);
363 float* corrPtr = outputTensorsBack[0].GetTensorMutableData<
float>();
364 for (
size_t i = 0; i < nSS; ++i) {
365 photon.setShowerShapeValue(corrPtr[i],
s_ssEnums[i]);
377 ATH_MSG_ERROR(
"ElectronPhotonVariableNFCorrectionTool does not support electrons.");
394 ATH_MSG_ERROR(
"ElectronPhotonVariableNFCorrectionTool cannot correct electrons.");
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
bool msgLvl(const MSG::Level lvl) const
Header file for AthHistogramAlgorithm.
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ Ok
The correction was done successfully.
@ unconverted
unconverted photon
@ wtots1
shower width is determined in a window detaxdphi = 0,0625 ×~0,2, corresponding typically to 20 strips...
@ f1
E1/E = fraction of energy reconstructed in the first sampling, where E1 is energy in all strips belon...
@ Eratio
(emaxs1-e2tsts1)/(emaxs1+e2tsts1)
@ fracs1
shower shape in the shower core : [E(+/-3)-E(+/-1)]/E(+/-1), where E(+/-n) is the energy in ± n strip...
@ weta2
the lateral width is calculated with a window of 3x5 cells using the energy weighted sum over all cel...
@ weta1
shower width using +/-3 strips around the one with the maximal energy deposit: w3 strips = sqrt{sum(E...
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".