ATLAS Offline Software
Loading...
Searching...
No Matches
SegmentEdgeInferenceAlg.cxx
Go to the documentation of this file.
4#include <algorithm>
5#include <limits>
6
7namespace MuonML {
8
10 ATH_CHECK(m_segmentKey.initialize());
11 ATH_CHECK(m_candidateDecorKey.initialize());
12 ATH_CHECK(m_edgeClassifier.retrieve());
13 ATH_CHECK(m_candidateBuilder.retrieve());
14 return StatusCode::SUCCESS;
15}
16
17StatusCode SegmentEdgeInferenceAlg::execute(const EventContext& ctx) const {
18 const xAOD::MuonSegmentContainer* segments{};
19 ATH_CHECK(SG::get(segments, m_segmentKey, ctx));
20 ATH_MSG_DEBUG("Event " << ctx.eventID().event_number()
21 << ": input segments in '" << m_segmentKey.key() << "' = " << segments->size());
22
23 SegmentEdgeGraph graph{};
24 std::vector<SegmentEdgeScore> scores{};
25 std::vector<std::vector<unsigned>> ids{};
26 ATH_CHECK(m_edgeClassifier->buildGraph(ctx, *segments, graph));
27 ATH_MSG_DEBUG("Event " << ctx.eventID().event_number()
28 << ": built graph with nodes=" << graph.nNodes << ", edges=" << graph.nEdges);
29
30 ATH_CHECK(m_edgeClassifier->classifyEdges(ctx, graph, scores));
31 if (!scores.empty()) {
32 float minProb = std::numeric_limits<float>::max();
33 float maxProb = std::numeric_limits<float>::lowest();
34 for (const SegmentEdgeScore& s : scores) {
35 minProb = std::min(minProb, s.probability);
36 maxProb = std::max(maxProb, s.probability);
37 }
38 ATH_MSG_DEBUG("Event " << ctx.eventID().event_number()
39 << ": edge scores=" << scores.size()
40 << ", prob range=[" << minProb << ", " << maxProb << "]");
41 } else {
42 ATH_MSG_DEBUG("Event " << ctx.eventID().event_number() << ": no edge scores produced");
43 }
44
45 ATH_CHECK(m_candidateBuilder->buildCandidates(ctx, graph, scores, ids));
46 std::size_t nonEmptyCandidates = 0;
47 std::size_t maxCandidateList = 0;
48 for (const auto& segIds : ids) {
49 if (!segIds.empty()) ++nonEmptyCandidates;
50 maxCandidateList = std::max(maxCandidateList, segIds.size());
51 }
52 ATH_MSG_DEBUG("Event " << ctx.eventID().event_number()
53 << ": decorated segments=" << ids.size()
54 << ", non-empty candidate lists=" << nonEmptyCandidates
55 << ", max candidates/segment=" << maxCandidateList);
56
58 // Initializing on one element creates the aux decoration column; remaining
59 // entries are default-constructed by the EDM unless overwritten below.
60 if (!segments->empty()) {
61 decor(*(*segments)[0]) = {};
62 }
63 for (std::size_t i = 0; i < graph.segments.size(); ++i) {
64 decor(*graph.segments[i]) = ids[i];
65 }
66 return StatusCode::SUCCESS;
67}
68} // namespace MuonML
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
SG::WriteDecorHandleKey< xAOD::MuonSegmentContainer > m_candidateDecorKey
ToolHandle< ISegmentEdgeClassifierTool > m_edgeClassifier
StatusCode execute(const EventContext &ctx) const override
ToolHandle< ISegmentTrackCandidateBuilderTool > m_candidateBuilder
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segmentKey
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.
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
std::vector< const xAOD::MuonSegment_v1 * > segments