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);
81 ATH_MSG_WARNING(
"ApplyTo = TruthPhotons but truthType not available — skipping photon");
84 int truthType = acc_truthType(photon);
85 if (truthType < 13 || truthType > 15)
return false;
96 if (
ss[0] <= -10.f ||
ss[0] >= 10.f)
return false;
98 if (
ss[1] <= -10.f ||
ss[1] >= 10.f)
return false;
100 if (
ss[2] <= -10.f ||
ss[2] >= 10.f)
return false;
102 if (
ss[3] <= -10.f ||
ss[3] >= 10.f)
return false;
104 if (
ss[4] < -2.f ||
ss[4] >= 10.f)
return false;
106 if (
ss[5] < -2.f ||
ss[5] > 2.f)
return false;
108 if (
ss[6] < -2.f ||
ss[6] > 2.f)
return false;
110 if (
ss[7] <= -2.f ||
ss[7] >= 2.f)
return false;
112 if (
ss[8] <= -2.f ||
ss[8] >= 5.f)
return false;
114 if (
ss[9] < 0.f ||
ss[9] >= 5000.f)
return false;
116 if (
ss[10] < 0.f ||
ss[10] > 1.f)
return false;
123 const std::vector<float>&
ss)
const
126 ATH_MSG_ERROR(
"Fallback fudge tool failed to correct photon");
131 for (
size_t i : {size_t(1), size_t(4)}) {
138 photon.setShowerShapeValue(0.f,
s_ssEnums[8]);
141 ATH_MSG_DEBUG(
"Photon failed shower shape cuts: fallback fudge correction applied");
150 ATH_MSG_ERROR(
"ConfigFile property is empty. Please provide a config file to the tool.");
151 return StatusCode::FAILURE;
155 if (resolvedConfig.empty()) {
157 return StatusCode::FAILURE;
162 env.ReadFile(resolvedConfig.c_str(), kEnvLocal);
163 env.IgnoreDuplicates(
false);
165 const int nFoldsConfig = env.GetValue(
"NFolds", 0);
166 if (nFoldsConfig <= 0) {
167 ATH_MSG_ERROR(
"NFolds not set or invalid in config: " << resolvedConfig);
168 return StatusCode::FAILURE;
174 return StatusCode::FAILURE;
181 TString pattern = env.GetValue(
"ONNXnamePattern",
"");
182 if (pattern.IsNull()) {
183 ATH_MSG_ERROR(
"ONNXnamePattern not set in config: " << resolvedConfig);
184 return StatusCode::FAILURE;
189 TString
fs = env.GetValue(
"FoldStrategy",
"eventNumber");
190 std::string fsStr =
fs.Data();
195 ATH_MSG_ERROR(
"FoldStrategy must be 'eventNumber' or 'eventNumber_phi', but got '" << fsStr <<
"' in config: " << resolvedConfig);
196 return StatusCode::FAILURE;
205 return StatusCode::FAILURE;
213 return StatusCode::FAILURE;
231 for (
int i = 0; i <
m_nFolds; ++i) {
243 m_accessors[i].original = std::make_unique<SG::Accessor<float>>(var +
"_original");
250 return StatusCode::SUCCESS;
259 std::vector<float>
ss(nSS);
262 for (
size_t i = 0; i < nSS; ++i) {
276 dec_pass(photon) = passSS ? 1 : 0;
277 dec_fudged(photon) = fallback ? 1 : 0;
297 const unsigned long long eventNumber =
h->eventNumber();
298 float ptGeV = photon.pt() / 1000.0f;
299 const float phi =
static_cast<float>(photon.phi());
311 std::vector<float> kinematic = {
313 static_cast<float>(photon.eta()),
314 static_cast<float>(photon.phi()),
315 static_cast<float>(isConv)
319 std::vector<Ort::Value> inputTensors;
324 int64_t batchSizeKin = onnxToolForward->getBatchSize(
325 static_cast<int64_t
>(kinematic.size()), 0);
326 if (onnxToolForward->addInput(inputTensors, kinematic, 0, batchSizeKin).isFailure()) {
327 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add kinematic input tensor");
332 int64_t batchSizeSS = onnxToolForward->getBatchSize(
333 static_cast<int64_t
>(
ss.size()), 1);
334 if (onnxToolForward->addInput(inputTensors,
ss, 1, batchSizeSS).isFailure()) {
335 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add shower shape input tensor");
339 std::vector<Ort::Value> outputTensors;
340 std::vector<float> outputData;
341 if (onnxToolForward->addOutput(outputTensors, outputData, 0, batchSizeKin).isFailure()) {
342 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add forward output tensor");
346 if (onnxToolForward->inference(inputTensors, outputTensors).isFailure()) {
347 ATH_MSG_ERROR(
"Fold " << fold <<
": forward inference failed");
351 float* zPtr = outputTensors[0].GetTensorMutableData<
float>();
352 std::vector<float> zVec(zPtr, zPtr + nSS);
356 std::vector<Ort::Value> inputTensorsBack;
357 std::vector<Ort::Value> outputTensorsBack;
358 std::vector<float> outputDataBack;
363 int64_t batchSizeKinBack = onnxToolBackward->getBatchSize(
364 static_cast<int64_t
>(kinematic.size()), 0);
365 if (onnxToolBackward->addInput(inputTensorsBack, kinematic, 0, batchSizeKinBack).isFailure()) {
366 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add kinematic input tensor for backward model");
371 int64_t batchSizeZBack = onnxToolBackward->getBatchSize(
static_cast<int64_t
>(zVec.size()), 1);
373 if (onnxToolBackward->addInput(inputTensorsBack, zVec, 1, batchSizeZBack).isFailure()) {
374 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add z input tensor for backward model");
379 if (onnxToolBackward->addInput(inputTensorsBack,
ss, 2, batchSizeKinBack).isFailure()) {
380 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add original SS input tensor for backward model");
384 if (onnxToolBackward->addOutput(outputTensorsBack, outputDataBack, 0, batchSizeZBack).isFailure()) {
385 ATH_MSG_ERROR(
"Fold " << fold <<
": failed to add backward output tensor");
389 if (onnxToolBackward->inference(inputTensorsBack, outputTensorsBack).isFailure()) {
390 ATH_MSG_ERROR(
"Fold " << fold <<
": backward inference failed");
394 const auto infoB = outputTensorsBack[0].GetTensorTypeAndShapeInfo();
395 const auto nElB = infoB.GetElementCount();
397 ATH_MSG_ERROR(
"Fold "<<fold <<
": backward output has " <<nElB<<
" elements, expected "<<nSS);
402 float* corrPtr = outputTensorsBack[0].GetTensorMutableData<
float>();
403 for (
size_t i = 0; i < nSS; ++i) {
404 photon.setShowerShapeValue(corrPtr[i],
s_ssEnums[i]);
409 photon.setShowerShapeValue(0.f,
s_ssEnums[8]);
421 ATH_MSG_ERROR(
"ElectronPhotonVariableNFCorrectionTool does not support electrons.");
438 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_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(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.
Helper class to provide type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
@ 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".