ATLAS Offline Software
Loading...
Searching...
No Matches
JetCalibToolsCfg Namespace Reference

Functions

 load_calib_cfg ()
str full_calib_path (str rel_path)
str get_jet_collection_name (str name)
str get_calib_cfg_path (str context, str jetcollection)
 get_calib_cfg (str context, str jetcollection)
 defineJetCalibTool (jetdef, modspec)
 getJetCalibToolPrereqs (jetdef, modspec)
 getJetCalibToolSettings (jetdef, modspec)

Variables

 jetcaliblog = Logging.logging.getLogger('JetCalibToolsConfig')
list all = ['getJetCalibTool']
str CONFIG_FILE = "JetCalibTools/calibDict.yaml"
str COMMONPATH_KEY = "commonPath"

Function Documentation

◆ defineJetCalibTool()

defineJetCalibTool ( jetdef,
modspec )

Definition at line 66 of file JetCalibToolsCfg.py.

66def defineJetCalibTool(jetdef, modspec):
67 from JetCalibTools.JetCalibStepsConfig import calibToolFromConfigFile
68
69 # Get the yaml file and calibration sequence
70 cfg, calibSeqKey = getJetCalibToolSettings(jetdef, modspec)
71 path_configFile = PathResolver.FindCalibFile(cfg)
72 toolname = "jetcalib_new_{0}_{1}".format(jetdef.basename,modspec)
73 jct = calibToolFromConfigFile(jetdef._cflags, path_configFile, toolname, calibSeqKey)
74
75 return jct
76
77# This method extends the basic config getter to specify the requisite jet
78# moments or other inputs
static std::string FindCalibFile(const std::string &logical_file_name)

◆ full_calib_path()

str full_calib_path ( str rel_path)

Definition at line 30 of file JetCalibToolsCfg.py.

30def full_calib_path(rel_path: str) -> str:
31 commonPath = load_calib_cfg().get(COMMONPATH_KEY)
32 if not commonPath or rel_path.startswith("/"):
33 return rel_path
34 return commonPath.rstrip("/") + "/" + rel_path
35
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132

◆ get_calib_cfg()

get_calib_cfg ( str context,
str jetcollection )

Definition at line 61 of file JetCalibToolsCfg.py.

61def get_calib_cfg(context: str, jetcollection: str):
62 from JetCalibTools.JetCalibStepsConfig import load_yaml_cfg
63 return load_yaml_cfg(get_calib_cfg_path(context, jetcollection))
64
65# This method actually sets up the tool

◆ get_calib_cfg_path()

str get_calib_cfg_path ( str context,
str jetcollection )
 Look up the calibration config file for a jet collection and context.
The config file itself holds any run-dependent settings, in 'RunX:' blocks. 

Definition at line 43 of file JetCalibToolsCfg.py.

43def get_calib_cfg_path(context: str, jetcollection: str) -> str:
44 """ Look up the calibration config file for a jet collection and context.
45 The config file itself holds any run-dependent settings, in 'RunX:' blocks. """
46 data = load_calib_cfg()
47
48 contexts = data.get(jetcollection)
49 if contexts is None or jetcollection == COMMONPATH_KEY:
50 known = [k for k in data if k != COMMONPATH_KEY]
51 raise KeyError(f"No calibrations listed in {CONFIG_FILE} for jet collection "
52 f"'{jetcollection}'. Known collections: {known}")
53
54 rel = contexts.get(context)
55 if rel is None:
56 raise KeyError(f"No '{context}' calibration listed in {CONFIG_FILE} for jet collection "
57 f"'{jetcollection}'. Known contexts: {list(contexts)}")
58
59 return full_calib_path(rel)
60

◆ get_jet_collection_name()

str get_jet_collection_name ( str name)

Definition at line 36 of file JetCalibToolsCfg.py.

36def get_jet_collection_name(name: str) -> str:
37 # For some specific jet collections, e.g. lepton-free PFlow jets,
38 # we want to apply the calibrations of the default PFlow jets
39 for suffix in ("_noElectrons", "_noMuons", "_noLeptons", "_tauSeedEleRM"):
40 name = name.replace(suffix, "")
41 return name
42

◆ getJetCalibToolPrereqs()

getJetCalibToolPrereqs ( jetdef,
modspec )

Definition at line 79 of file JetCalibToolsCfg.py.

79def getJetCalibToolPrereqs(jetdef, modspec):
80 from JetCalibTools.JetCalibStepsConfig import load_yaml_cfg
81
82 cfg, _ = getJetCalibToolSettings(jetdef, modspec)
83 configDic = load_yaml_cfg(cfg)
84
85 prereqs = ["mod:ConstitFourMom"]
86 pvname = "PrimaryVertices" # this can be set dinamically in future
87
88 for step, step_config in configDic.items():
89 # JetArea
90 if step_config.get("DoJetArea", False):
91 if modspec.startswith("Trig"):
92 prereqs.append("input:HLT_EventDensity")
93 elif pvname == "PrimaryVertices_initial":
94 prereqs.append("input:EventDensityCustomVtxGNN")
95 elif pvname != "PrimaryVertices":
96 prereqs.append("input:EventDensityCustomVtx")
97 else:
98 prereqs.append(inputsFromContext("EventDensity")(jetdef))
99
100 # read prereqs from context or default config block
101 prereq_block = step_config.get("prereqs", {})
102 step_prereqs = prereq_block.get(modspec, prereq_block.get("default", []))
103 prereqs.extend(step_prereqs)
104
105 # remove duplication and keep order
106 seen = set()
107 prereqs_unique = []
108 for p in prereqs:
109 if p not in seen:
110 prereqs_unique.append(p)
111 seen.add(p)
112
113 return prereqs_unique
114
115# Get specific settings for JetCalibTools
STL class.

◆ getJetCalibToolSettings()

getJetCalibToolSettings ( jetdef,
modspec )

Definition at line 116 of file JetCalibToolsCfg.py.

116def getJetCalibToolSettings(jetdef, modspec):
117
118 calibspecs = modspec.split(':')
119
120 context = calibspecs[0] # T0/Trigger/etc. - used to extract calbration sequence from YAML config file
121
122 jetcollection = get_jet_collection_name(jetdef.basename)
123
124 cfg = get_calib_cfg_path(context, jetcollection)
125
126 return cfg, context

◆ load_calib_cfg()

load_calib_cfg ( )

Definition at line 23 of file JetCalibToolsCfg.py.

23def load_calib_cfg():
24 path = PathResolver.FindCalibFile(CONFIG_FILE)
25 if not path:
26 raise FileNotFoundError("Could not locate %s via PathResolver" % CONFIG_FILE)
27 with open(path, "r", encoding="utf-8") as f:
28 return yaml.safe_load(f)
29

Variable Documentation

◆ all

list JetCalibToolsCfg.all = ['getJetCalibTool']

Definition at line 10 of file JetCalibToolsCfg.py.

◆ COMMONPATH_KEY

str JetCalibToolsCfg.COMMONPATH_KEY = "commonPath"

Definition at line 20 of file JetCalibToolsCfg.py.

◆ CONFIG_FILE

str JetCalibToolsCfg.CONFIG_FILE = "JetCalibTools/calibDict.yaml"

Definition at line 16 of file JetCalibToolsCfg.py.

◆ jetcaliblog

JetCalibToolsCfg.jetcaliblog = Logging.logging.getLogger('JetCalibToolsConfig')

Definition at line 7 of file JetCalibToolsCfg.py.