ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonPhaseII
MuonLearning
MuonInference
src
DVInferenceAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
DVInferenceAlg.h
"
5
6
#include "
StoreGate/ReadHandle.h
"
7
#include "
StoreGate/WriteDecorHandle.h
"
8
9
namespace
MuonML
{
10
11
StatusCode
DVInferenceAlg::initialize
() {
12
ATH_CHECK
(
m_inferenceTool
.retrieve());
13
const
bool
decorateEventInfo =
m_decorateEventInfo
;
14
ATH_CHECK
(
m_eventInfoKey
.initialize(decorateEventInfo));
15
ATH_CHECK
(
m_scoreDecorKey
.initialize(decorateEventInfo));
16
ATH_CHECK
(
m_rawDecorKey
.initialize(decorateEventInfo));
17
ATH_CHECK
(
m_passDecorKey
.initialize(decorateEventInfo));
18
ATH_CHECK
(
m_nNodesDecorKey
.initialize(decorateEventInfo));
19
ATH_CHECK
(
m_nEdgesDecorKey
.initialize(decorateEventInfo));
20
21
m_thresholdModeName
=
m_thresholdMode
;
22
if
(
m_thresholdModeName
!=
"score"
&&
m_thresholdModeName
!=
"raw"
) {
23
ATH_MSG_ERROR
(
"ThresholdMode must be either 'score' or 'raw', got "
<<
m_thresholdModeName
);
24
return
StatusCode::FAILURE;
25
}
26
m_useRawThreshold
= (
m_thresholdModeName
==
"raw"
);
27
const
float
scoreThreshold =
m_scoreThreshold
;
28
ATH_MSG_INFO
(
"Initialized DVInferenceAlg with ScoreThreshold="
<< scoreThreshold
29
<<
", ThresholdMode="
<<
m_thresholdModeName
30
<<
", DecorateEventInfo="
<< decorateEventInfo);
31
if
(decorateEventInfo) {
32
ATH_MSG_INFO
(
"EventInfo DV decorations are enabled for validation/debug output only"
);
33
}
34
return
StatusCode::SUCCESS;
35
}
36
37
StatusCode
DVInferenceAlg::execute
(
const
EventContext& ctx)
const
{
38
DVInferenceResult
result{};
39
ATH_CHECK
(
m_inferenceTool
->inferEvent(ctx, result));
40
41
if
(!result.valid) {
42
ATH_MSG_WARNING
(
"DV event classifier did not produce a finite score for event "
43
<< ctx.eventID().event_number());
44
}
45
46
const
float
decisionValue =
m_useRawThreshold
? result.rawOutput : result.probability;
47
const
float
cutValue =
m_scoreThreshold
;
48
const
bool
pass = result.valid && decisionValue >= cutValue;
49
if
(
m_printEveryEvent
) {
50
ATH_MSG_INFO
(
"DV event classifier: event="
<< ctx.eventID().event_number()
51
<<
" score="
<< result.probability
52
<<
" raw="
<< result.rawOutput
53
<<
" decisionValue="
<< decisionValue
54
<<
" cutValue="
<< cutValue
55
<<
" thresholdMode="
<<
m_thresholdModeName
56
<<
" pass="
<< pass
57
<<
" nodes="
<< result.nNodes
58
<<
" edges="
<< result.nEdges);
59
}
else
{
60
ATH_MSG_DEBUG
(
"DV event classifier: event="
<< ctx.eventID().event_number()
61
<<
" score="
<< result.probability
62
<<
" raw="
<< result.rawOutput
63
<<
" decisionValue="
<< decisionValue
64
<<
" cutValue="
<< cutValue
65
<<
" thresholdMode="
<<
m_thresholdModeName
66
<<
" pass="
<< pass
67
<<
" nodes="
<< result.nNodes
68
<<
" edges="
<< result.nEdges);
69
}
70
71
if
(
m_decorateEventInfo
) {
72
const
xAOD::EventInfo
* eventInfo{};
73
ATH_CHECK
(
SG::get
(eventInfo,
m_eventInfoKey
, ctx));
74
75
SG::WriteDecorHandle<xAOD::EventInfo, float>
scoreDecor{
m_scoreDecorKey
, ctx};
76
SG::WriteDecorHandle<xAOD::EventInfo, float>
rawDecor{
m_rawDecorKey
, ctx};
77
SG::WriteDecorHandle<xAOD::EventInfo, char>
passDecor{
m_passDecorKey
, ctx};
78
SG::WriteDecorHandle<xAOD::EventInfo, unsigned int>
nNodesDecor{
m_nNodesDecorKey
, ctx};
79
SG::WriteDecorHandle<xAOD::EventInfo, unsigned int>
nEdgesDecor{
m_nEdgesDecorKey
, ctx};
80
81
scoreDecor(*eventInfo) = result.valid ? result.probability : -1.f;
82
rawDecor(*eventInfo) = result.valid ? result.rawOutput : -1.f;
83
passDecor(*eventInfo) = pass ? 1 : 0;
84
nNodesDecor(*eventInfo) =
static_cast<
unsigned
int
>
(result.nNodes);
85
nEdgesDecor(*eventInfo) =
static_cast<
unsigned
int
>
(result.nEdges);
86
}
87
88
return
StatusCode::SUCCESS;
89
}
90
91
}
// namespace MuonML
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
DVInferenceAlg.h
ReadHandle.h
Handle class for reading from StoreGate.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
MuonML::DVInferenceAlg::m_thresholdMode
Gaudi::Property< std::string > m_thresholdMode
Definition
DVInferenceAlg.h:55
MuonML::DVInferenceAlg::m_nNodesDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_nNodesDecorKey
Definition
DVInferenceAlg.h:48
MuonML::DVInferenceAlg::m_decorateEventInfo
Gaudi::Property< bool > m_decorateEventInfo
Definition
DVInferenceAlg.h:39
MuonML::DVInferenceAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition
DVInferenceAlg.h:36
MuonML::DVInferenceAlg::m_scoreDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_scoreDecorKey
Definition
DVInferenceAlg.h:42
MuonML::DVInferenceAlg::m_useRawThreshold
bool m_useRawThreshold
Definition
DVInferenceAlg.h:59
MuonML::DVInferenceAlg::m_passDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_passDecorKey
Definition
DVInferenceAlg.h:46
MuonML::DVInferenceAlg::m_inferenceTool
ToolHandle< MuonML::DVInferenceToolBase > m_inferenceTool
Definition
DVInferenceAlg.h:33
MuonML::DVInferenceAlg::m_printEveryEvent
Gaudi::Property< bool > m_printEveryEvent
Definition
DVInferenceAlg.h:57
MuonML::DVInferenceAlg::m_thresholdModeName
std::string m_thresholdModeName
Definition
DVInferenceAlg.h:60
MuonML::DVInferenceAlg::initialize
StatusCode initialize() override
Definition
DVInferenceAlg.cxx:11
MuonML::DVInferenceAlg::m_rawDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_rawDecorKey
Definition
DVInferenceAlg.h:44
MuonML::DVInferenceAlg::m_nEdgesDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_nEdgesDecorKey
Definition
DVInferenceAlg.h:50
MuonML::DVInferenceAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition
DVInferenceAlg.cxx:37
MuonML::DVInferenceAlg::m_scoreThreshold
Gaudi::Property< float > m_scoreThreshold
Definition
DVInferenceAlg.h:53
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
MuonML
Definition
BucketGraphUtils.h:19
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition
ReadCondHandle.h:282
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition
IEventInfoCnvTool.h:16
MuonML::DVInferenceResult
Definition
DVInferenceToolBase.h:30
Generated on
for ATLAS Offline Software by
1.17.0