ATLAS Offline Software
Loading...
Searching...
No Matches
SegmentEdgeClassifierTool.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_SEGMENTEDGECLASSIFIERTOOL_H
5#define MUONINFERENCE_SEGMENTEDGECLASSIFIERTOOL_H
6
9#include "MuonMLEvent.h"
10#include "Gaudi/Property.h"
13
14#include <atomic>
15#include <cstdint>
16#include <mutex>
17#include <string>
18#include <unordered_set>
19#include <vector>
20
21namespace MuonML {
22
31 int chamberIndex{0};
32 int layers{0};
33 int sector{0};
34 int nSegments{0};
35 };
36
65 virtual public ISegmentEdgeClassifierTool {
66 public:
67 using BucketInferenceToolBase::BucketInferenceToolBase;
68
70 StatusCode initialize() override;
71
73 StatusCode finalize() override;
74
77 StatusCode runGraphInference(const EventContext& ctx,
78 GraphRawData& graphData) const override;
79
82 StatusCode buildGraph(const EventContext& ctx,
83 const xAOD::MuonSegmentContainer& segments,
84 SegmentEdgeGraph& graph) const override;
85
88 StatusCode classifyEdges(const EventContext& ctx,
89 const SegmentEdgeGraph& graph,
90 std::vector<SegmentEdgeScore>& scores) const override;
91
93 bool enableTruthDiagnostics() const override { return m_enableTruthDiagnostics; }
94
95 private:
96 StatusCode dumpDebugEvent(const EventContext& ctx,
97 const SegmentEdgeGraph& graph,
98 const std::vector<SegmentEdgeScore>& scores) const;
99
104 const xAOD::MuonSegmentContainer& segments,
105 const std::unordered_set<const xAOD::MuonSegment*>& bucketRetained,
106 SegmentEdgeGraph& graph) const;
107
108 Gaudi::Property<float> m_maxDeltaThetaDeg{this, "MaxDeltaThetaDeg", 35.f};
109 Gaudi::Property<int> m_maxDeltaSector{this, "MaxDeltaSector", 1};
110 Gaudi::Property<int> m_sectorModulo{this, "SectorModulo", 16,
111 "Number of muon sectors used when applying wrap-around sector distance"};
112 Gaudi::Property<unsigned int> m_maxSegmentsPerBucket{this, "MaxSegmentsPerBucket", 0,
113 "Keep at most this many quality-ranked segments per (sector, chamber, eta) bucket before inference; 0 keeps all"};
114 Gaudi::Property<unsigned int> m_maxEdgesPerNodeBeforeInference{this, "MaxEdgesPerNodeBeforeInference", 0,
115 "Keep at most this many geometrical neighbour pairs per node before ONNX inference; 0 keeps all"};
116 Gaudi::Property<unsigned int> m_maxEdgesPerTargetChamberBeforeInference{
117 this, "MaxEdgesPerTargetChamberBeforeInference", 0,
118 "Keep at most this many pre-ONNX neighbours from one target chamber per node; 0 keeps all"};
119 Gaudi::Property<bool> m_dropSameChamberEdgesBeforeInference{this, "DropSameChamberEdgesBeforeInference", true,
120 "Drop same-chamber segment pairs before ONNX inference"};
121 Gaudi::Property<bool> m_dropIsolatedNodesBeforeInference{this, "DropIsolatedNodesBeforeInference", true,
122 "Remove nodes without a retained pre-ONNX edge before creating ONNX tensors"};
123 Gaudi::Property<std::string> m_inputNodeName{this, "InputNodeName", "x"};
124 Gaudi::Property<std::string> m_inputEdgeIndexName{this, "InputEdgeIndexName", "edge_index"};
125 Gaudi::Property<std::string> m_inputEdgeAttrName{this, "InputEdgeAttrName", "edge_attr"};
126 Gaudi::Property<std::string> m_outputName{this, "OutputName", "logits"};
127 Gaudi::Property<std::string> m_debugDumpFile{this, "DebugDumpFile", ""};
128 Gaudi::Property<unsigned int> m_debugDumpMaxEvents{this, "DebugDumpMaxEvents", 0};
129 Gaudi::Property<bool> m_enableTruthDiagnostics{
130 this, "EnableTruthDiagnostics", false,
131 "MC-only: fill SegmentEdgeGraph's truth diagnostics."};
133 this, "TruthLinkKey", "MuonSegmentsFromR4.truthParticleLink"};
134 float m_cosMin{0.f};
135
137 std::vector<std::string> m_nodeFeatureNames{};
138 std::vector<SegmentNodeFeatureId> m_nodeFeatureIds{};
139 mutable std::mutex m_debugDumpMutex;
140 mutable std::atomic<unsigned int> m_debugDumpEvents{0};
141
143 mutable std::atomic<std::size_t> m_sumInputSegments{0};
144 mutable std::atomic<std::size_t> m_sumCandidatePairs{0};
145 mutable std::atomic<std::size_t> m_sumRetainedPairs{0};
146 mutable std::atomic<std::size_t> m_sumNodesBeforeIsolatedDrop{0};
147 mutable std::atomic<std::size_t> m_sumNodesAfterIsolatedDrop{0};
148 };
149}
150#endif
std::vector< std::vector< float > > scores
Generic feature definitions and utilities shared across ML inference tools.
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Interface for segment-edge GNN classification.
Runs a segment-level GNN on reconstructed muon segments to classify segment-pair edges as "good" or "...
std::atomic< std::size_t > m_sumInputSegments
Job-summed pre-ONNX pruning counters (see buildGraph()).
void fillTruthDiagnostics(const xAOD::MuonSegmentContainer &segments, const std::unordered_set< const xAOD::MuonSegment * > &bucketRetained, SegmentEdgeGraph &graph) const
MC-only diagnostics: record, for every input segment and every pair of input segments sharing a truth...
Gaudi::Property< unsigned int > m_debugDumpMaxEvents
Gaudi::Property< unsigned int > m_maxEdgesPerNodeBeforeInference
Gaudi::Property< unsigned int > m_maxEdgesPerTargetChamberBeforeInference
std::atomic< std::size_t > m_sumNodesBeforeIsolatedDrop
Gaudi::Property< std::string > m_outputName
std::atomic< std::size_t > m_sumRetainedPairs
std::atomic< unsigned int > m_debugDumpEvents
Gaudi::Property< std::string > m_inputEdgeAttrName
bool enableTruthDiagnostics() const override
Whether this tool was configured to fill SegmentEdgeGraph's truth diagnostics.
StatusCode runGraphInference(const EventContext &ctx, GraphRawData &graphData) const override
Not supported by this tool; returns FAILURE.
StatusCode finalize() override
Log a pre-ONNX candidate-edge pruning.
Gaudi::Property< unsigned int > m_maxSegmentsPerBucket
SG::ReadDecorHandleKey< xAOD::MuonSegmentContainer > m_truthLinkKey
StatusCode classifyEdges(const EventContext &ctx, const SegmentEdgeGraph &graph, std::vector< SegmentEdgeScore > &scores) const override
Run ONNX inference on graph and populate scores with logit and probability for each edge; called afte...
Gaudi::Property< std::string > m_debugDumpFile
StatusCode buildGraph(const EventContext &ctx, const xAOD::MuonSegmentContainer &segments, SegmentEdgeGraph &graph) const override
Build a GNN graph from segments, computing node and edge features and storing the graph structure in ...
std::vector< std::string > m_nodeFeatureNames
Node feature order expected by the model metadata (resolved at initialize).
Gaudi::Property< std::string > m_inputEdgeIndexName
Gaudi::Property< bool > m_dropSameChamberEdgesBeforeInference
Gaudi::Property< std::string > m_inputNodeName
std::vector< SegmentNodeFeatureId > m_nodeFeatureIds
StatusCode initialize() override
Retrieve the ONNX model and resolve node feature ordering from metadata.
std::atomic< std::size_t > m_sumCandidatePairs
Gaudi::Property< bool > m_dropIsolatedNodesBeforeInference
StatusCode dumpDebugEvent(const EventContext &ctx, const SegmentEdgeGraph &graph, const std::vector< SegmentEdgeScore > &scores) const
std::atomic< std::size_t > m_sumNodesAfterIsolatedDrop
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
Segment features derived from or stored in bucket metadata.
int chamberIndex
Muon chamber index of the segment.
int sector
Sector number (typically 0–15).
int layers
Total number of active layers in the segment.
int nSegments
Count of segments in the same chamber/sector/eta group.
Helper struct to ship the Graph from the space point buckets to ONNX.
Definition GraphData.h:25