ATLAS Offline Software
Loading...
Searching...
No Matches
muonSegmentDump.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3def main(args):
4 from MuonGeoModelTestR4.testGeoModel import setupGeoR4TestCfg
5 from MuonConfig.MuonConfigUtils import executeTest, setupHistSvcCfg
6 from AthenaConfiguration.AllConfigFlags import initConfigFlags
7 flags = initConfigFlags()
8 flags.PerfMon.doFullMonMT = False
9 includeG4TrackTruth = bool(getattr(args, "includeG4TrackTruth", False))
10 minG4TrackTruthSegments = int(getattr(args, "minG4TrackTruthSegments", 2))
11 if minG4TrackTruthSegments < 1:
12 raise ValueError("--minG4TrackTruthSegments must be >= 1")
13 if includeG4TrackTruth:
14 flags.Muon.includePileUpTruth = True
15
16 from AthOnnxComps.OnnxRuntimeFlags import OnnxRuntimeType
17
18 if getattr(args, "use_cpu", False):
19 flags.AthOnnx.ExecutionProvider = OnnxRuntimeType.CPU
20 else:
21 flags.AthOnnx.ExecutionProvider = OnnxRuntimeType.CUDA
22
23 flags, cfg = setupGeoR4TestCfg(args)
24
25 cfg.merge(setupHistSvcCfg(flags, outFile=args.outRootFile, outStream="MuonSegmentDump"))
26
27 from MuonConfig.MuonDataPrepConfig import xAODUncalibMeasPrepCfg
28 cfg.merge(xAODUncalibMeasPrepCfg(flags))
29
30 from MuonSpacePointFormation.SpacePointFormationConfig import MuonSpacePointFormationCfg
31 cfg.merge(MuonSpacePointFormationCfg(flags))
32
33 from MuonPatternRecognitionAlgs.MuonPatternRecognitionConfig import MuonPatternRecognitionCfg
34
35 do_ml_bucket_filter = bool(getattr(args, "doMLBucketFilter", False) or
36 getattr(args, "bucketModel", None) is not None or
37 getattr(args, "bucketThreshold", None) is not None)
38 if do_ml_bucket_filter:
39 from MuonInference.InferenceConfig import GraphBucketFilterToolCfg, GraphInferenceAlgCfg
40 bucket_tool_kwargs: dict[str, object] = {"WriteSpacePointKey": "FilteredMlBuckets"}
41 if getattr(args, "bucketModel", None) is not None:
42 bucket_tool_kwargs["ModelPath"] = args.bucketModel
43 if getattr(args, "bucketThreshold", None) is not None:
44 bucket_tool_kwargs["ScoreThreshold"] = args.bucketThreshold
45 bucket_tool_kwargs["OutputName"] = args.output_name
46 bucket_tool_kwargs["SingleOutputIsLogit"] = args.is_logit if hasattr(args, "is_logit") else False
47 bucket_tool = cfg.popToolsAndMerge(
48 GraphBucketFilterToolCfg(
49 flags,
50 **bucket_tool_kwargs,
51 )
52 )
53 cfg.merge(
54 GraphInferenceAlgCfg(
55 flags,
56 InferenceTools=[bucket_tool],
57 )
58 )
59 # Re-run pattern recognition on filtered buckets so dumped segments
60 # correspond to the same filtered container.
61 cfg.merge(MuonPatternRecognitionCfg(flags))
62 cfg.getEventAlgo("MuonEtaHoughTransformAlg").SpacePointContainer = "FilteredMlBuckets"
63 else:
64 cfg.merge(MuonPatternRecognitionCfg(flags))
65
66 # Truth information if MC
67 if flags.Input.isMC:
68 from MuonTruthAlgsR4.MuonTruthAlgsConfig import MuonTruthAlgsCfg
69 cfg.merge(MuonTruthAlgsCfg(flags))
70
71 from MuonBucketDump.MuonBucketDumpConfig import MuonSegmentDumpCfg
72 dumper_kwargs = {
73 "IncludeG4TrackTruth": includeG4TrackTruth,
74 "MinG4TrackTruthSegments": minG4TrackTruthSegments,
75 }
76
77 if do_ml_bucket_filter:
78 cfg.merge(MuonSegmentDumpCfg(flags, SpacePointKeys=["FilteredMlBuckets"],
79 **dumper_kwargs))
80 else:
81 cfg.merge(MuonSegmentDumpCfg(flags, **dumper_kwargs))
82
83 executeTest(cfg)
84
85
86if __name__ == "__main__":
87 from MuonGeoModelTestR4.testGeoModel import SetupArgParser, MuonPhaseIITestDefaults
88 parser = SetupArgParser()
89 parser.set_defaults(nEvents=-1)
90 parser.set_defaults(outRootFile="MuonSegmentDump_R3SimHits.root")
91
92 parser.set_defaults(inputFile=MuonPhaseIITestDefaults.HITS_PG_R3)
93 parser.add_argument("--doMLBucketFilter", action="store_true", default=False,
94 help="Run ML bucket filtering and dump segments from filtered buckets.")
95 parser.add_argument("--bucketModel", type=str, default=None,
96 help="Path to ONNX model used by the ML bucket filter.")
97 parser.add_argument("--bucketThreshold", type=float, default=None,
98 help="Score threshold for single-output bucket filtering.")
99 parser.add_argument("--output-name", type=str, default="logits", dest="output_name",
100 help="Name of the ONNX output node used by the ML bucket filter.")
101 parser.add_argument("--is-logit", dest="is_logit", action="store_true", default=False,
102 help="Interpret the single output directly and do not apply sigmoid")
103 parser.add_argument("--use-cpu", action="store_true", default=False,
104 help="Force CPU for ONNX inference")
105 parser.add_argument("--includeG4TrackTruth", action="store_true", default=False,
106 help="Use sim-hit HepMC/G4 track identifiers for unmatched segment labels.")
107 parser.add_argument("--minG4TrackTruthSegments", type=int, default=2,
108 help="Minimum number of reco segments that must share the same G4/HepMC id.")
109
110
111 args = parser.parse_args()
112 main(args)
int main()
Definition hello.cxx:18