ATLAS Offline Software
Loading...
Searching...
No Matches
InferenceUtils.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef MUONINFERENCE_INFERENCEUTILS_H
5#define MUONINFERENCE_INFERENCEUTILS_H
6
10
11#include <algorithm>
12#include <cmath>
13
15
17 bool isCuda{false};
19};
20
21template <class SessionToolHandle>
22SessionBackend sessionBackend(const SessionToolHandle& sessionTool) {
23 if (const auto* cudaTool = dynamic_cast<const AthOnnx::OnnxRuntimeSessionToolCUDA*>(sessionTool.get())) {
24 return SessionBackend{true, cudaTool->deviceId()};
25 }
26 return SessionBackend{};
27}
28
29inline float sigmoid(float x) {
30 if (x >= 0.f) {
31 const float z = std::exp(-x);
32 return 1.f / (1.f + z);
33 }
34 const float z = std::exp(x);
35 return z / (1.f + z);
36}
37
38inline float reducedChi2(const xAOD::MuonSegment& segment) {
39 return segment.chiSquared() / std::max(1.f, segment.numberDoF());
40}
41
43inline int compareFloat(float first, float second) {
44 if (std::isnan(first)) return std::isnan(second) ? 0 : 1;
45 if (std::isnan(second)) return -1;
46 if (first < second) return -1;
47 if (first > second) return 1;
48 return 0;
49}
50
52inline int compareFloatDescending(float first, float second) {
53 if (std::isnan(first)) return std::isnan(second) ? 0 : 1;
54 if (std::isnan(second)) return -1;
55 if (first > second) return -1;
56 if (first < second) return 1;
57 return 0;
58}
59
63
64} // namespace MuonML::InferenceUtils
65
66#endif // MUONINFERENCE_INFERENCEUTILS_H
#define x
#define z
float numberDoF() const
Returns the numberDoF.
float chiSquared() const
int compareFloat(float first, float second)
Three-way float comparison which orders NaN after all numeric values.
SessionBackend sessionBackend(const SessionToolHandle &sessionTool)
MuonR4::SegmentQualitySorter SegmentQualityOrder
Common quality ordering for segment representatives, shared with MlMsTrackSeeder so that graph constr...
int compareFloatDescending(float first, float second)
Three-way descending comparison which also orders NaN last.
float reducedChi2(const xAOD::MuonSegment &segment)
MuonSegment_v1 MuonSegment
Reference the current persistent version:
Auxiliary class to rank segments by quality: more precision hits first, then more phi layers,...