ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterMLCalibToolLiteCfg.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4from AthenaConfiguration.ComponentFactory import CompFactory
5from AthOnnxComps.OnnxRuntimeInferenceConfig import OnnxRuntimeInferenceToolCfg
6from AthenaConfiguration.Enums import LHCPeriod
7from PathResolver import PathResolver
8import yaml
9
10
12 # MC23 is the default
13 config_file = "CaloClusterCorrection/config_hgm_mc23.yaml"
14
15 if flags.Input.isMC:
16 # MC simulation: check campaign
17 if flags.Input.MCCampaign.value.startswith("mc20"):
18 config_file = "CaloClusterCorrection/config_hgm_mc20.yaml"
19
20 else:
21 # Real data: check LHC run period
22 if flags.GeoModel.Run == LHCPeriod.Run2:
23 config_file = "CaloClusterCorrection/config_hgm_mc20.yaml"
24
25 return config_file
26
28 flags,
29 name="CaloClusterMLCalibToolLite",
30 config_file=None,
31):
32 if config_file is None:
33 config_file = getMLCalibrationConfig(flags)
34
35 with open(PathResolver.FindCalibFile(config_file)) as f:
36 config = yaml.safe_load(f)
37
38 onnx_model_path = config["model"]["onnx_path"]
39 features = config["data"]["features"]
40 sorted_features = sorted(features.items(), key=lambda item: item[1]["position"])
41 transform_names = [
42 item[1]["preprocessing"]["processors"][0] for item in sorted_features
43 ]
44 transform_params = [
45 [float(x) for x in item[1]["preprocessing"]["parameters"]]
46 for item in sorted_features
47 ]
48
49 ca = ComponentAccumulator()
50 onnx_tool = ca.popToolsAndMerge(OnnxRuntimeInferenceToolCfg(flags, onnx_model_path))
51 CaloClusterMLCalibToolLite = CompFactory.CaloClusterMLCalibToolLite(name)
52 CaloClusterMLCalibToolLite.ORTInferenceTool = onnx_tool
53 CaloClusterMLCalibToolLite.PreprocessingTransformNames = transform_names
54 CaloClusterMLCalibToolLite.PreprocessingTransformParams = transform_params
55 ca.setPrivateTools(CaloClusterMLCalibToolLite)
56
57 return ca
static std::string FindCalibFile(const std::string &logical_file_name)