ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
9namespace MuonML {
10
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
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 }
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
37StatusCode 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;
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
72 const xAOD::EventInfo* eventInfo{};
73 ATH_CHECK(SG::get(eventInfo, m_eventInfoKey, ctx));
74
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Gaudi::Property< std::string > m_thresholdMode
SG::WriteDecorHandleKey< xAOD::EventInfo > m_nNodesDecorKey
Gaudi::Property< bool > m_decorateEventInfo
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_scoreDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_passDecorKey
ToolHandle< MuonML::DVInferenceToolBase > m_inferenceTool
Gaudi::Property< bool > m_printEveryEvent
std::string m_thresholdModeName
StatusCode initialize() override
SG::WriteDecorHandleKey< xAOD::EventInfo > m_rawDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_nEdgesDecorKey
StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< float > m_scoreThreshold
Handle class for adding a decoration to an object.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
EventInfo_v1 EventInfo
Definition of the latest event info version.