3from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
4from AthenaConfiguration.ComponentFactory
import CompFactory
6DEFAULT_BUCKET_MODEL_PATH =
"dev/MuonRecRTT/edgecnn_mu200.onnx"
7DEFAULT_BUCKET_SCORE_THRESHOLD = 0.160
8DEFAULT_BUCKET_SINGLE_OUTPUT_MODE =
"logit"
11 """Configure the shared ONNX Runtime service used by MuonLearning tools."""
12 result = ComponentAccumulator()
13 kwargs.setdefault(
"LogLevel", 3)
14 svc = CompFactory.AthOnnx.OnnxRuntimeSvc(name, **kwargs)
15 result.addService(svc, primary=
False, create=
True)
19 result = ComponentAccumulator()
20 the_alg = CompFactory.MuonML.InferenceAlg(name, **kwargs)
21 result.addEventAlgo(the_alg, primary =
True)
26 from AthOnnxComps.OnnxRuntimeSessionConfig
import OnnxRuntimeSessionToolCfg
28 result = ComponentAccumulator()
29 kwargs.setdefault(
"ModelSession", result.popToolsAndMerge(OnnxRuntimeSessionToolCfg(flags, model_fname=
"/eos/atlas/atlascerngroupdisk/data-art/grid-input/MuonRecRTT/TestModel.onnx")))
30 kwargs.setdefault(
"MLFilterCut", -3.6)
32 the_tool = CompFactory.MuonML.GraphSPFilterTool(name, **kwargs)
33 result.setPrivateTools(the_tool)
38 from AthOnnxComps.OnnxRuntimeSessionConfig
import OnnxRuntimeSessionToolCfg
40 result = ComponentAccumulator()
41 model_path = kwargs.pop(
"ModelPath", DEFAULT_BUCKET_MODEL_PATH)
42 single_output_mode = kwargs.pop(
"SingleOutputMode",
None)
43 if single_output_mode
is not None:
44 if "SingleOutputIsLogit" in kwargs:
46 "Specify either SingleOutputMode or SingleOutputIsLogit, not both."
48 if single_output_mode
not in (
"logit",
"prob"):
50 "SingleOutputMode must be 'logit' or 'prob', got "
51 f
"{single_output_mode!r}."
53 kwargs[
"SingleOutputIsLogit"] = (single_output_mode ==
"logit")
56 kwargs.setdefault(
"ModelSession", result.popToolsAndMerge(
57 OnnxRuntimeSessionToolCfg(flags, model_fname=model_path,
58 OnnxRuntimeSvc=result.getService(
"OnnxRuntimeSvc"))))
59 kwargs.setdefault(
"OutputLevel", 3)
60 kwargs.setdefault(
"ScoreThreshold", DEFAULT_BUCKET_SCORE_THRESHOLD)
61 kwargs.setdefault(
"OutputName",
"logits")
62 kwargs.setdefault(
"SingleOutputIsLogit", DEFAULT_BUCKET_SINGLE_OUTPUT_MODE ==
"logit")
64 the_tool = CompFactory.MuonML.GraphBucketFilterTool(name, **kwargs)
65 result.setPrivateTools(the_tool)
70 from AthOnnxComps.OnnxRuntimeSessionConfig
import OnnxRuntimeSessionToolCfg
72 result = ComponentAccumulator()
73 model_path = kwargs.pop(
"ModelPath",
"MuonInference/models/edge_gnn_refit_top01_from_t0020.onnx")
75 kwargs.setdefault(
"ModelSession", result.popToolsAndMerge(
76 OnnxRuntimeSessionToolCfg(flags, model_fname=model_path,
77 OnnxRuntimeSvc=result.getService(
"OnnxRuntimeSvc"))))
79 kwargs.setdefault(
"InputNodeName",
"x")
80 kwargs.setdefault(
"InputEdgeIndexName",
"edge_index")
81 kwargs.setdefault(
"InputEdgeAttrName",
"edge_attr")
82 kwargs.setdefault(
"OutputName",
"logits")
83 kwargs.setdefault(
"MaxDeltaThetaDeg", 35.0)
84 kwargs.setdefault(
"MaxDeltaSector", 1)
85 kwargs.setdefault(
"SectorModulo", 16)
86 kwargs.setdefault(
"ReadSpacePoints",
"MuonSpacePoints")
87 tool = CompFactory.MuonML.SegmentEdgeClassifierTool(name, **kwargs)
88 result.setPrivateTools(tool)
93 result = ComponentAccumulator()
97 kwargs.setdefault(
"EdgeThreshold", 0.25)
98 kwargs.setdefault(
"OverlapThreshold", 0.8)
99 kwargs.setdefault(
"UseRecoveryComponents",
True)
100 kwargs.setdefault(
"SymmetrizeDirectedEdges",
True)
101 kwargs.setdefault(
"AddAllSegmentsRecoveryCandidate",
False)
102 kwargs.setdefault(
"KeepIsolatedSegments",
False)
103 kwargs.setdefault(
"MinCandidateSize", 2)
104 tool = CompFactory.MuonML.SegmentTrackCandidateBuilderTool(name, **kwargs)
105 result.setPrivateTools(tool)
110 result = ComponentAccumulator()
114 edge_tool_kwargs = {}
115 if "EdgeModelPath" in kwargs:
116 edge_tool_kwargs[
"ModelPath"] = kwargs.pop(
"EdgeModelPath")
118 if isinstance(kwargs.get(
"EdgeClassifierTool"), dict):
119 edge_tool_kwargs.update(kwargs.pop(
"EdgeClassifierTool"))
121 candidate_builder_kwargs = {}
122 for key
in (
"EdgeThreshold",
124 "UseRecoveryComponents",
125 "SymmetrizeDirectedEdges",
126 "AddAllSegmentsRecoveryCandidate",
127 "KeepIsolatedSegments",
130 candidate_builder_kwargs[key] = kwargs.pop(key)
132 if isinstance(kwargs.get(
"CandidateBuilderTool"), dict):
133 candidate_builder_kwargs.update(kwargs.pop(
"CandidateBuilderTool"))
135 if "EdgeClassifierTool" not in kwargs:
136 kwargs[
"EdgeClassifierTool"] = result.popToolsAndMerge(
138 kwargs.setdefault(
"CandidateBuilderTool", result.popToolsAndMerge(
140 kwargs.setdefault(
"SegmentKey",
"MuonSegmentsFromR4")
141 kwargs.setdefault(
"CandidateDecoration",
"MuonSegmentsFromR4.trackCandidateIds")
142 alg = CompFactory.MuonML.SegmentEdgeInferenceAlg(name=name, **kwargs)
143 result.addEventAlgo(alg, primary=
True)
148 """Configure the DisplacedVertex graph-level ONNX inference tool.
149 The current DV ONNX export consumes raw graph tensors with the contract
150 x [N,7], edge_index [2,E], edge_attr [E,5], n_muon_nodes [1] -> logits [1]
152 from AthOnnxComps.OnnxRuntimeSessionConfig
import OnnxRuntimeSessionToolCfg
154 result = ComponentAccumulator()
155 model_path = kwargs.pop(
"ModelPath",
"MuonInference/models/edge_class_dv_mu200.onnx")
158 kwargs.setdefault(
"ModelSession", result.popToolsAndMerge(
159 OnnxRuntimeSessionToolCfg(flags, model_fname=model_path,
160 OnnxRuntimeSvc=result.getService(
"OnnxRuntimeSvc"))))
161 kwargs.setdefault(
"InputNodeName",
"x")
162 kwargs.setdefault(
"InputEdgeIndexName",
"edge_index")
163 kwargs.setdefault(
"InputEdgeAttrName",
"edge_attr")
164 kwargs.setdefault(
"InputNMuonNodesName",
"n_muon_nodes")
165 kwargs.setdefault(
"OutputName",
"logits")
166 kwargs.setdefault(
"SingleOutputMode",
"logit")
167 if "SpacePointKeys" not in kwargs:
169 if flags.Detector.GeometryMDT
or flags.Detector.GeometryRPC
or flags.Detector.GeometryTGC:
170 sp_containers.append(
"MuonSpacePoints")
171 elif flags.Detector.GeometryMM
or flags.Detector.GeometrysTGC:
172 sp_containers.append(
"NswSpacePoints")
173 kwargs.setdefault(
"SpacePointKeys", sp_containers)
174 kwargs.setdefault(
"UseBucketSegmentSelection",
True)
175 kwargs.setdefault(
"MinTowerEnergyMeV", 1000.0)
176 kwargs.setdefault(
"MaxTowerSegmentDR", 0.4)
177 kwargs.setdefault(
"CaloRMaxMm", 4250.0)
178 kwargs.setdefault(
"CaloZMaxMm", 6500.0)
179 kwargs.setdefault(
"SectorModulo", 16)
180 kwargs.setdefault(
"RequireEdges",
False)
181 tool = CompFactory.MuonML.DVInferenceToolBase(name, **kwargs)
182 result.setPrivateTools(tool)
187 """Configure the calorimeter reconstruction used by the DV training converter.
189 result = ComponentAccumulator()
192 from CaloRec.CaloRecoConfig
import CaloRecoCfg
193 result.merge(CaloRecoCfg(flags))
195 from CaloRec.CaloTowerMakerConfig
import CaloTowerMakerCfg
196 result.getPrimaryAndMerge(CaloTowerMakerCfg(flags))
202 """Configure a runnable event-level DisplacedVertex inference algorithm."""
203 result = ComponentAccumulator()
204 do_calo_tower_build = kwargs.pop(
"DoCaloTowerBuild",
True)
205 do_ml_bucket_filter = kwargs.pop(
"DoMLBucketFilter",
True)
206 bucket_model_path = kwargs.pop(
"BucketModelPath",
None)
207 bucket_threshold = kwargs.pop(
"BucketThreshold",
None)
208 filtered_bucket_key = kwargs.pop(
"FilteredBucketKey",
"FilteredMlBuckets")
209 use_filtered_buckets_for_dv_graph = kwargs.pop(
"UseFilteredBucketsForDVGraph",
False)
210 alg_output_level = kwargs.get(
"OutputLevel",
None)
215 "InputEdgeIndexName",
217 "InputNMuonNodesName",
222 "UseBucketSegmentSelection",
231 "FallbackToAllSegments",
232 "DebugDumpFirstNNodes",
233 "DebugDumpFirstNEdges",
235 "UseBucketSegmentSelection",
239 tool_kwargs[key] = kwargs.pop(key)
241 if isinstance(kwargs.get(
"InferenceTool"), dict):
242 tool_kwargs.update(kwargs.pop(
"InferenceTool"))
244 tower_key = tool_kwargs.get(
"TowerContainerKey",
"CombinedTower")
245 if do_calo_tower_build
and tower_key:
248 if do_ml_bucket_filter:
249 bucket_filter_kwargs = {
250 "WriteSpacePointKey": filtered_bucket_key,
251 "ReadSpacePoints":
"MuonSpacePoints",
253 if bucket_model_path
is not None:
254 bucket_filter_kwargs[
"ModelPath"] = bucket_model_path
255 if bucket_threshold
is not None:
256 bucket_filter_kwargs[
"ScoreThreshold"] = bucket_threshold
257 bucket_tool = result.popToolsAndMerge(
263 name=
"DVBucketPrefilterAlg",
264 InferenceTools=[bucket_tool],
267 if use_filtered_buckets_for_dv_graph:
268 tool_kwargs.setdefault(
"SpacePointKeys", [filtered_bucket_key])
269 tool_kwargs.setdefault(
"UseBucketSegmentSelection",
True)
271 if "InferenceTool" not in kwargs:
272 kwargs[
"InferenceTool"] = result.popToolsAndMerge(
276 if alg_output_level
is not None:
277 kwargs[
"OutputLevel"] = alg_output_level
279 kwargs.setdefault(
"ScoreDecoration",
"EventInfo.dv_score")
280 kwargs.setdefault(
"RawOutputDecoration",
"EventInfo.dv_rawOutput")
281 kwargs.setdefault(
"PassDecoration",
"EventInfo.dv_pass")
282 kwargs.setdefault(
"NNodesDecoration",
"EventInfo.dv_nNodes")
283 kwargs.setdefault(
"NEdgesDecoration",
"EventInfo.dv_nEdges")
284 alg = CompFactory.MuonML.DVInferenceAlg(name=name, **kwargs)
285 result.addEventAlgo(alg, primary=
True)
DisplacedVertexInferenceAlgCfg(flags, name="DisplacedVertexInferenceAlg", **kwargs)
GraphInferenceAlgCfg(flags, name="GraphInferenceAlg", **kwargs)
DisplacedVertexCaloTowerCfg(flags)
SegmentEdgeClassifierToolCfg(flags, name="SegmentEdgeClassifierTool", **kwargs)
MuonLearningOnnxRuntimeSvcCfg(flags, name="OnnxRuntimeSvc", **kwargs)
GraphBucketFilterToolCfg(flags, name="GraphBucketFilterTool", **kwargs)
SegmentTrackCandidateBuilderToolCfg(flags, name="SegmentTrackCandidateBuilderTool", **kwargs)
DisplacedVertexInferenceToolCfg(flags, name="DisplacedVertexInferenceTool", **kwargs)
SegmentEdgeInferenceAlgCfg(flags, name="SegmentEdgeInferenceAlg", **kwargs)
GraphSPFilterToolCfg(flags, name="GraphSPFilterTool", **kwargs)