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 PathResolver import PathResolver
7import yaml
8
9
11 flags,
12 name="CaloClusterMLCalibToolLite",
13 config_file="CaloClusterCorrection/config_hgm_mc20.yaml",
14):
15 with open(PathResolver.FindCalibFile(config_file)) as f:
16 config = yaml.safe_load(f)
17
18 onnx_model_path = config["model"]["onnx_path"]
19 features = config["data"]["features"]
20 sorted_features = sorted(features.items(), key=lambda item: item[1]["position"])
21 transform_names = [
22 item[1]["preprocessing"]["processors"][0] for item in sorted_features
23 ]
24 transform_params = [
25 [float(x) for x in item[1]["preprocessing"]["parameters"]]
26 for item in sorted_features
27 ]
28
29 ca = ComponentAccumulator()
30 onnx_tool = ca.popToolsAndMerge(OnnxRuntimeInferenceToolCfg(flags, onnx_model_path))
31 CaloClusterMLCalibToolLite = CompFactory.CaloClusterMLCalibToolLite(name)
32 CaloClusterMLCalibToolLite.ORTInferenceTool = onnx_tool
33 CaloClusterMLCalibToolLite.PreprocessingTransformNames = transform_names
34 CaloClusterMLCalibToolLite.PreprocessingTransformParams = transform_params
35 ca.setPrivateTools(CaloClusterMLCalibToolLite)
36
37 return ca
static std::string FindCalibFile(const std::string &logical_file_name)