4from AthenaConfiguration.AthConfigFlags
import AthConfigFlags
6from AthenaCommon.Logging
import logging
7log = logging.getLogger(__name__)
16 flags: AthConfigFlags,
17 key: str |
None =
None,
18 alt_key: str |
None =
None,
19 algs: dict[str, list[str]] | list[str] |
None =
None,
20 mc_algs: dict[str, list[str]] | list[str] |
None =
None,
21 dev_algs: dict[str, list[str]] | list[str] |
None =
None,
23 '''Get the list of algorithms for a specific menu key; if not found, the alternate key will be tried if provided.'''
24 def _getAlgs(key: str |
None):
25 if algs
is None: ret =
None
26 elif isinstance(algs, dict): ret = algs[key]
if key
in algs
else None
28 if any(pfx
in flags.Trigger.triggerMenuSetup
for pfx
in [
'MC_',
'Dev_'])
and mc_algs
and (isinstance(mc_algs, list)
or key
in mc_algs):
29 if ret
is None: ret = []
30 ret += mc_algs[key]
if isinstance(mc_algs, dict)
else mc_algs
31 if 'Dev_' in flags.Trigger.triggerMenuSetup
and dev_algs
and (isinstance(dev_algs, list)
or key
in dev_algs):
32 if ret
is None: ret = []
33 ret += dev_algs[key]
if isinstance(dev_algs, dict)
else dev_algs
36 ret_algs = _getAlgs(key)
37 if ret_algs
is None and alt_key
is not None:
38 ret_algs = _getAlgs(alt_key)
44 '''Check if the TauJet's built-in RNN score and WP variables have to be used, instead of the decorator-based variables'''
46 return tau_id
in [
'DeepSet',
'RNNLLP']
50 '''Return the (score, score_sig_trans) variable name pair for a given TauID/Sequence configuration'''
54 return (f
'{tau_id}_Score', f
'{tau_id}_ScoreSigTrans')
57def getTauIDAlgorithm(flags: AthConfigFlags, selection: str, name_mapping: dict[str, str] |
None =
None) -> str:
59 tau_ids = sorted(list(flags.Trigger.Offline.Tau), key=len, reverse=
True)
60 for tau_id
in tau_ids:
61 if selection.endswith(tau_id):
return tau_id
65 name_mapping = dict(sorted(name_mapping.items(), key=
lambda p: len(p[0]), reverse=
True))
66 for short_name, long_name
in name_mapping.items():
67 if selection.endswith(short_name):
return long_name
77def getHitZAlgs(flags: AthConfigFlags, precision_sequence: str, alt_precision_sequence: str |
None =
None) -> list[str]:
79 Get the list of HitZ algorithms for the CaloHits reco sequence.
80 The configuration for each algorithm is contained in flags.Trigger.Offline.Tau.<alg>.
84 key=precision_sequence,
85 alt_key=alt_precision_sequence,
98def getHitZConfig(flags: AthConfigFlags, chainPart: dict[str, Any]) -> tuple[str, float] |
None:
100 Get the HLT HitZ configuration tuple: (algorithm name, sigma cut value in mm)
102 if not chainPart[
'hitz']:
return None
106 match = re.match(
r'((?P<sigma>(\d|p)+)mm)?(X(\d|p)+mm)?(?P<alg>.+)', chainPart[
'hitz'])
108 alg = match.group(
'alg')
110 alg_flags = getattr(flags.Trigger.Offline.Tau, alg,
None)
111 if alg_flags
is None:
112 raise ValueError(f
'HitZ algorithm "{alg}" configuration not found in flags.Trigger.Offline.Tau.{alg}')
114 sigma = match.group(
'sigma')
115 if sigma
is None: sigma = alg_flags.DefaultMaxZ0Sigma
116 else: sigma = float(sigma.replace(
'p',
'.'))
120 raise ValueError(f
'Invalid HitZ configuration string: {chainPart["hitz"]}')
124 '''Return the (z, sigma) variable name pair for a given HitZ algorithm'''
125 return (f
'{alg}_z0', f
'{alg}_z0_sigma')
128def getCaloHitsPreselAlgs(flags: AthConfigFlags, precision_sequence: str, alt_precision_sequence: str |
None =
None) -> list[str]:
130 Get the list of CaloHits preselection TauID inferences to be executed for the CaloHits reco sequence.
131 The configuration for each algorithm is contained in flags.Trigger.Offline.Tau.<alg>.
135 key=precision_sequence,
136 alt_key=alt_precision_sequence,
150 '''Clean the CaloHits preselection configuration for a chainPart dict'''
151 sel = chainPart[
'calohitsPresel']
153 if not sel
or sel ==
'idperfCHP':
return 'idperf'
158 name_mapping={
'CHTP':
'GNCaloHitsTauPresel'},
163 '''Get the HLT Tau CaloHits sequence name suffix'''
164 if not chainPart[
'hitz']
and not chainPart[
'calohitsPresel']:
return None
169 if chainPart[
'hitz']: parts.append(chainPart[
'hitz'])
171 if not parts: parts = [
'CaloHitsBase']
172 return '_'.join(parts)
182 Get the list of precision TauID inferences to be executed for each HLT tau trigger reco sequence
183 The configuration for each algorithm is contained in flags.Trigger.Offline.Tau.<alg>.
187 key=precision_sequence,
188 alt_key=alt_precision_sequence,
192 'MVA': [
'GNTau',
'MesonCuts',
'GNTauDev1'],
210rnn_wps = [
'verylooseRNN',
'looseRNN',
'mediumRNN',
'tightRNN']
211noid_selections = [
'perf',
'idperf']
212meson_selections = [
'kaonpi1',
'kaonpi2',
'dipion1',
'dipion2',
'dipion3',
'dipion4',
'dikaonmass',
'singlepion']
215 '''Clean the ID configuration for a chainPart dict'''
216 sel = chainPart[
'selection']
219 if chainPart[
'reconstruction'] ==
'tracktwoMVA':
222 elif sel
in meson_selections:
224 elif chainPart[
'reconstruction']
in [
'tracktwoLLP',
'trackLRT']
and sel
in rnn_wps:
238 Get the HLT Tau Precision sequence name suffix.
239 This is also used for the HLT_TrigTauRecMerged_... and HLT_tautrack_... EDM collection names.
241 ret = chainPart[
'reconstruction']
244 if ret ==
'tracktwoMVA':
return 'MVA'
245 elif ret ==
'tracktwoLLP':
return 'LLP'
246 elif ret ==
'trackLRT':
return 'LRT'
248 if include_calohits_seq_name:
250 ret += f
'_{calohits_seq}' if calohits_seq
else ''
261 '''Get the HLT Tau signature global menu sequence name (e.g. ptonly, tracktwo, trackLRT, etc...)'''
264 if chainPart[
'hitz']
or chainPart[
'calohitsPresel']:
265 name.append(
'CaloHits')
267 name.append(chainPart[
'reconstruction'])
269 return '_'.join(name)