ATLAS Offline Software
Loading...
Searching...
No Matches
muonEdgeSegmentInference.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3"""Run segment-edge ONNX inference with an optional JSONL parity dump.
4"""
5
6def main(args):
7 from MuonGeoModelTestR4.testGeoModel import setupGeoR4TestCfg
8 from MuonConfig.MuonConfigUtils import executeTest
9 from AthenaConfiguration.AllConfigFlags import initConfigFlags
10 flags = initConfigFlags()
11
12 if args.athenaDebug:
13 flags.Exec.DebugMessageComponents = [
14 "SegmentEdgeInferenceAlg",
15 "SegmentEdgeInferenceAlg.SegmentEdgeClassifierTool",
16 "SegmentEdgeInferenceAlg.SegmentTrackCandidateBuilderTool",
17 "SegmentEdgeInferenceAlg.SegmentEdgeClassifierTool.OnnxRuntimeSessionToolCPU",
18 "SegmentEdgeInferenceAlg.SegmentEdgeClassifierTool.OnnxRuntimeSessionToolCUDA",
19 "GraphInferenceAlg",
20 "GraphBucketFilterTool",
21 ]
22 print("INFO: Exec.DebugMessageComponents configured:", flags.Exec.DebugMessageComponents)
23
24 from AthOnnxComps.OnnxRuntimeFlags import OnnxRuntimeType
25 if args.use_cpu:
26 flags.AthOnnx.ExecutionProvider = OnnxRuntimeType.CPU
27 else:
28 flags.AthOnnx.ExecutionProvider = OnnxRuntimeType.CUDA
29
30 flags, cfg = setupGeoR4TestCfg(args, flags)
31
32 from MuonConfig.MuonDataPrepConfig import xAODUncalibMeasPrepCfg
33 cfg.merge(xAODUncalibMeasPrepCfg(flags))
34
35 from MuonSpacePointFormation.SpacePointFormationConfig import MuonSpacePointFormationCfg
36 cfg.merge(MuonSpacePointFormationCfg(flags))
37
38 from MuonPatternRecognitionAlgs.MuonPatternRecognitionConfig import MuonPatternRecognitionCfg
39 if args.doMLBucketFilter:
40 from MuonInference.InferenceConfig import GraphBucketFilterToolCfg, GraphInferenceAlgCfg
41 bucket_tool = cfg.popToolsAndMerge(
42 GraphBucketFilterToolCfg(
43 flags,
44 ModelPath=args.bucket_model_path,
45 ScoreThreshold=args.score_threshold,
46 OutputName=args.output_name,
47 SingleOutputMode=args.single_output_mode,
48 )
49 )
50 cfg.merge(GraphInferenceAlgCfg(flags, InferenceTools=[bucket_tool]))
51 cfg.merge(MuonPatternRecognitionCfg(flags))
52 cfg.getEventAlgo("MuonEtaHoughTransformAlg").SpacePointContainer = "FilteredMlBuckets"
53 else:
54 cfg.merge(MuonPatternRecognitionCfg(flags))
55
56 output_level = 1 if args.athenaDebug else 3
57 edge_space_point_key = "FilteredMlBuckets" if args.doMLBucketFilter else "MuonSpacePoints"
58
59 edge_classifier_kwargs = {
60 "ModelPath": args.edgeModel,
61 "ReadSpacePoints": edge_space_point_key,
62 "DebugDumpFile": args.segment_edge_debug_dump_file,
63 "DebugDumpMaxEvents": args.segment_edge_debug_dump_max_events,
64 "MaxDeltaThetaDeg": args.max_delta_theta_deg,
65 "MaxDeltaSector": args.max_delta_sector,
66 "SectorModulo": args.sector_modulo,
67 "OutputLevel": output_level,
68 }
69 from MuonInference.InferenceConfig import SegmentEdgeInferenceAlgCfg
70 cfg.merge(
71 SegmentEdgeInferenceAlgCfg(
72 flags,
73 EdgeClassifierTool=edge_classifier_kwargs,
74 EdgeThreshold=args.edge_threshold,
75 OutputLevel=output_level,
76 )
77 )
78
79 executeTest(cfg)
80
81if __name__ == "__main__":
82 from MuonGeoModelTestR4.testGeoModel import SetupArgParser, MuonPhaseIITestDefaults
83 parser = SetupArgParser()
84 parser.set_defaults(nEvents=-1)
85 parser.set_defaults(inputFile=MuonPhaseIITestDefaults.HITS_PG_R3)
86 parser.add_argument("--edgeModel", "--edge-model", required=True, dest="edgeModel",
87 help="ONNX segment-edge classifier")
88 parser.add_argument("--edge-threshold", type=float, default=0.00013,
89 help="Candidate-builder edge probability threshold")
90 parser.add_argument("--max-delta-theta-deg", type=float, default=35.0,
91 help="Graph edge direction window in degrees")
92 parser.add_argument("--max-delta-sector", type=int, default=1,
93 help="Graph edge sector window")
94 parser.add_argument("--sector-modulo", type=int, default=16,
95 help="Sector wrap-around modulo")
96
97 from MuonInference.InferenceConfig import (
98 DEFAULT_BUCKET_MODEL_PATH,
99 DEFAULT_BUCKET_SCORE_THRESHOLD,
100 DEFAULT_BUCKET_SINGLE_OUTPUT_MODE,
101 )
102 parser.add_argument("--doMLBucketFilter", dest="doMLBucketFilter", action="store_true", default=True)
103 parser.add_argument("--noMLBucketFilter", dest="doMLBucketFilter", action="store_false")
104 parser.add_argument("--bucket-model-path", dest="bucket_model_path", default=DEFAULT_BUCKET_MODEL_PATH)
105 parser.add_argument("--score-threshold", type=float, default=DEFAULT_BUCKET_SCORE_THRESHOLD)
106 parser.add_argument("--output-name", default="logits", dest="output_name",
107 help="Bucket filter ONNX output tensor name")
108 score_mode = parser.add_mutually_exclusive_group()
109 score_mode.add_argument("--single-output-mode", choices=("logit", "prob"), default=DEFAULT_BUCKET_SINGLE_OUTPUT_MODE, dest="single_output_mode",
110 help="Scalar ONNX-output interpretation. 'logit' applies sigmoid before thresholding.")
111 score_mode.add_argument("--is-logit", action="store_const", const="logit", dest="single_output_mode",
112 help="Alias for --single-output-mode logit.")
113 score_mode.add_argument("--is-prob", action="store_const", const="prob", dest="single_output_mode",
114 help="Alias for --single-output-mode prob.")
115
116 parser.add_argument("--segment-edge-debug-dump-file", default="",
117 help="Optional JSONL with exact x, edge_index, edge_attr, logits and probabilities")
118 parser.add_argument("--segment-edge-debug-dump-max-events", type=int, default=0,
119 help="Maximum graph events written to the segment-edge JSONL dump; 0 means all")
120 parser.add_argument("--athenaDebug", action="store_true",
121 help="Enable Athena DEBUG verbosity")
122 parser.add_argument("--use-cpu", action="store_true", default=False, help="Force CPU for ONNX inference")
123
124 args = parser.parse_args()
125 main(args)
void print(char *figname, TCanvas *c1)
int main()
Definition hello.cxx:18