4from AthenaConfiguration.AthConfigFlags
import AthConfigFlags
5from AthenaConfiguration.AccumulatorCache
import AccumulatorCache
7from AthenaCommon.Logging
import logging
8log = logging.getLogger(__name__)
17 flags: AthConfigFlags,
18 key: str |
None =
None,
19 alt_key: str |
None =
None,
20 algs: dict[str, list[str]] | list[str] |
None =
None,
21 mc_algs: dict[str, list[str]] | list[str] |
None =
None,
22 dev_algs: dict[str, list[str]] | list[str] |
None =
None,
24 '''Get the list of algorithms for a specific menu key; if not found, the alternate key will be tried if provided.'''
25 def _getAlgs(key: str |
None):
26 if algs
is None: ret =
None
27 elif isinstance(algs, dict): ret = algs[key]
if key
in algs
else None
29 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):
30 if ret
is None: ret = []
31 ret += mc_algs[key]
if isinstance(mc_algs, dict)
else mc_algs
32 if 'Dev_' in flags.Trigger.triggerMenuSetup
and dev_algs
and (isinstance(dev_algs, list)
or key
in dev_algs):
33 if ret
is None: ret = []
34 ret += dev_algs[key]
if isinstance(dev_algs, dict)
else dev_algs
37 ret_algs = _getAlgs(key)
38 if ret_algs
is None and alt_key
is not None:
39 ret_algs = _getAlgs(alt_key)
45 '''Check if the TauJet's built-in RNN score and WP variables have to be used, instead of the decorator-based variables'''
47 return tau_id
in [
'DeepSet',
'RNNLLP']
51 '''Return the (score, score_sig_trans) variable name pair for a given TauID/Sequence configuration'''
55 return (f
'{tau_id}_Score', f
'{tau_id}_ScoreSigTrans')
60 name_mapping: tuple[tuple[str, str], ...] |
None =
None) -> str:
63 tau_ids = sorted(flags.Trigger.Offline.Tau, key=len, reverse=
True)
64 for tau_id
in tau_ids:
65 if selection.endswith(tau_id):
return tau_id
69 name_mapping = sorted(name_mapping, key=
lambda p: len(p[0]), reverse=
True)
70 for short_name, long_name
in name_mapping:
71 if selection.endswith(short_name):
return long_name
81def getHitZAlgs(flags: AthConfigFlags, precision_sequence: str, alt_precision_sequence: str |
None =
None) -> list[str]:
83 Get the list of HitZ algorithms for the CaloHits reco sequence.
84 The configuration for each algorithm is contained in flags.Trigger.Offline.Tau.<alg>.
88 key=precision_sequence,
89 alt_key=alt_precision_sequence,
102def getHitZConfig(flags: AthConfigFlags, chainPart: dict[str, Any]) -> tuple[str, float] |
None:
104 Get the HLT HitZ configuration tuple: (algorithm name, sigma cut value in mm)
106 if not chainPart[
'hitz']:
return None
110 match = re.match(
r'((?P<sigma>(\d|p)+)mm)?(X(\d|p)+mm)?(?P<alg>.+)', chainPart[
'hitz'])
112 alg = match.group(
'alg')
114 alg_flags = getattr(flags.Trigger.Offline.Tau, alg,
None)
115 if alg_flags
is None:
116 raise ValueError(f
'HitZ algorithm "{alg}" configuration not found in flags.Trigger.Offline.Tau.{alg}')
118 sigma = match.group(
'sigma')
119 if sigma
is None: sigma = alg_flags.DefaultMaxZ0Sigma
120 else: sigma = float(sigma.replace(
'p',
'.'))
124 raise ValueError(f
'Invalid HitZ configuration string: {chainPart["hitz"]}')
128 '''Return the (z, sigma) variable name pair for a given HitZ algorithm'''
129 return (f
'{alg}_z0', f
'{alg}_z0_sigma')
132def getCaloHitsPreselAlgs(flags: AthConfigFlags, precision_sequence: str, alt_precision_sequence: str |
None =
None) -> list[str]:
134 Get the list of CaloHits preselection TauID inferences to be executed for the CaloHits reco sequence.
135 The configuration for each algorithm is contained in flags.Trigger.Offline.Tau.<alg>.
139 key=precision_sequence,
140 alt_key=alt_precision_sequence,
154 '''Clean the CaloHits preselection configuration for a chainPart dict'''
155 sel = chainPart[
'calohitsPresel']
157 if not sel
or sel ==
'idperfCHP':
return 'idperf'
162 name_mapping=((
'CHTP',
'GNCaloHitsTauPresel')),
167 '''Get the HLT Tau CaloHits sequence name suffix'''
168 if not chainPart[
'hitz']
and not chainPart[
'calohitsPresel']:
return None
173 if chainPart[
'hitz']: parts.append(chainPart[
'hitz'])
175 if not parts: parts = [
'CaloHitsBase']
176 return '_'.join(parts)
186 Get the list of precision TauID inferences to be executed for each HLT tau trigger reco sequence
187 The configuration for each algorithm is contained in flags.Trigger.Offline.Tau.<alg>.
191 key=precision_sequence,
192 alt_key=alt_precision_sequence,
196 'MVA': [
'GNTau',
'MesonCuts',
'GNTauDev1'],
214rnn_wps = [
'verylooseRNN',
'looseRNN',
'mediumRNN',
'tightRNN']
215noid_selections = [
'perf',
'idperf']
216meson_selections = [
'kaonpi1',
'kaonpi2',
'dipion1',
'dipion2',
'dipion3',
'dipion4',
'dikaonmass',
'singlepion']
219 '''Clean the ID configuration for a chainPart dict'''
220 sel = chainPart[
'selection']
223 if chainPart[
'reconstruction'] ==
'tracktwoMVA':
226 elif sel
in meson_selections:
228 elif chainPart[
'reconstruction']
in [
'tracktwoLLP',
'trackLRT']
and sel
in rnn_wps:
241 Get the HLT Tau Precision sequence name suffix.
242 This is also used for the HLT_TrigTauRecMerged_... and HLT_tautrack_... EDM collection names.
244 ret = chainPart[
'reconstruction']
247 if ret ==
'tracktwoMVA':
return 'MVA'
248 elif ret ==
'tracktwoLLP':
return 'LLP'
249 elif ret ==
'trackLRT':
return 'LRT'
251 if include_calohits_seq_name:
253 ret += f
'_{calohits_seq}' if calohits_seq
else ''
264 '''Get the HLT Tau signature global menu sequence name (e.g. ptonly, tracktwo, trackLRT, etc...)'''
267 if chainPart[
'hitz']
or chainPart[
'calohitsPresel']:
268 name.append(
'CaloHits')
270 name.append(chainPart[
'reconstruction'])
272 return '_'.join(name)