ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Calorimeter
CaloClusterCorrection
python
CaloClusterMLCalibToolLiteCfg.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3
from
AthenaConfiguration.ComponentAccumulator
import
ComponentAccumulator
4
from
AthenaConfiguration.ComponentFactory
import
CompFactory
5
from
AthOnnxComps.OnnxRuntimeInferenceConfig
import
OnnxRuntimeInferenceToolCfg
6
from
AthenaConfiguration.Enums
import
LHCPeriod
7
from
PathResolver
import
PathResolver
8
import
yaml
9
10
11
def
getMLCalibrationConfig
(flags):
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
27
def
CaloClusterMLCalibToolLiteCfg
(
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
PathResolver::FindCalibFile
static std::string FindCalibFile(const std::string &logical_file_name)
Definition
PathResolver.h:63
CaloClusterMLCalibToolLiteCfg
Definition
CaloClusterMLCalibToolLiteCfg.py:1
CaloClusterMLCalibToolLiteCfg.getMLCalibrationConfig
getMLCalibrationConfig(flags)
Definition
CaloClusterMLCalibToolLiteCfg.py:11
Generated on
for ATLAS Offline Software by
1.17.0