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
7
8namespace MuonML {
9
11 ATH_CHECK(m_inferenceTool.retrieve());
13
15 if (m_thresholdModeName != "score" && m_thresholdModeName != "raw") {
16 ATH_MSG_ERROR("ThresholdMode must be either 'score' or 'raw', got " << m_thresholdModeName);
17 return StatusCode::FAILURE;
18 }
20 const float scoreThreshold = m_scoreThreshold;
21 ATH_MSG_INFO("Initialized DVInferenceAlg with ScoreThreshold=" << scoreThreshold
22 << ", ThresholdMode=" << m_thresholdModeName
23 << ", WriteDVoutput=" << m_writeDVoutput);
24 return StatusCode::SUCCESS;
25}
26
27StatusCode DVInferenceAlg::execute(const EventContext& ctx) const {
28 DVInferenceResult result{};
29 ATH_CHECK(m_inferenceTool->inferEvent(ctx, result));
30
31 if (!result.valid) {
32 ATH_MSG_WARNING("DV event classifier did not produce a finite score for event "
33 << ctx.eventID().event_number());
34 }
35
36 const float decisionValue = m_useRawThreshold ? result.rawOutput : result.probability;
37 const float cutValue = m_scoreThreshold;
38 const bool pass = result.valid && decisionValue >= cutValue;
40 ATH_MSG_INFO("DV event classifier: event=" << ctx.eventID().event_number()
41 << " score=" << result.probability
42 << " raw=" << result.rawOutput
43 << " decisionValue=" << decisionValue
44 << " cutValue=" << cutValue
45 << " thresholdMode=" << m_thresholdModeName
46 << " pass=" << pass
47 << " nodes=" << result.nNodes
48 << " edges=" << result.nEdges);
49 } else {
50 ATH_MSG_DEBUG("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 }
60
61 if (m_writeDVoutput) {
63 ATH_CHECK(outputHandle.record(std::make_unique<xAOD::TrigCompositeContainer>(),
64 std::make_unique<xAOD::TrigCompositeAuxContainer>()));
65
66 xAOD::TrigComposite* trigComposite = outputHandle->push_back(std::make_unique<xAOD::TrigComposite>());
67
68 trigComposite->setDetail<float>("Score", result.valid ? result.probability : -1.f);
69 trigComposite->setDetail<float>("RawOutput", result.valid ? result.rawOutput : -1.f);
70 trigComposite->setDetail<char>("Pass", pass ? 1 : 0);
71 trigComposite->setDetail<unsigned int>("NNodes", static_cast<unsigned int>(result.nNodes));
72 trigComposite->setDetail<unsigned int>("NEdges", static_cast<unsigned int>(result.nEdges));
73 }
74
75 return StatusCode::SUCCESS;
76}
77
78} // namespace MuonML
#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_INFO(x,...)
Gaudi::Property< std::string > m_thresholdMode
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_trigCompositeKey
Gaudi::Property< bool > m_writeDVoutput
ToolHandle< MuonML::DVInferenceToolBase > m_inferenceTool
Gaudi::Property< bool > m_printEveryEvent
std::string m_thresholdModeName
StatusCode initialize() override
StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< float > m_scoreThreshold
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
bool setDetail(const std::string &name, const TYPE &value)
Set an TYPE detail on the object.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.