Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TauConfigurationTools.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon.Logging import logging
4 log = logging.getLogger(__name__)
5 
6 
9 
10 # List of Tau ID inference algorithms to be executed in each reco sequence
11 # Since the TrigTauRecMerged reco (TES, track association, variable calculation, etc.) is very fast,
12 # we split the reconstruction according to the primary ID algorithm to be used, to avoid running unnecesary long inferences
13 # The configuration for each TauID algorithm is contained in the flags.Trigger.Offline.Tau.<TauID> subdirectory
14 
15 def getPrecisionSequenceTauIDs(flags, precision_sequence: str) -> list[str]:
16  '''Get the list of TauIDs for each HLT tau trigger sequence'''
17  tau_ids = {
18  'MVA': ['DeepSet', 'GNTau', 'MesonCuts'],
19  'LLP': ['RNNLLP'],
20  'LRT': ['RNNLLP'],
21  }
22 
23  # Additional Tau ID algorithms to run ONLY if we're using the Dev menu
24  dev_tau_ids = {
25  }
26 
27  ret = tau_ids[precision_sequence]
28  if 'Dev_' in flags.Trigger.triggerMenuSetup and precision_sequence in dev_tau_ids: ret += dev_tau_ids[precision_sequence]
29  return ret
30 
31 
32 
35 
36 # The following functions are only required while we still have triggers
37 # with the RNN/DeepSet naming scheme in the Menu (e.g. mediumRNN_tracktwoMVA/LLP)
38 rnn_wps = ['verylooseRNN', 'looseRNN', 'mediumRNN', 'tightRNN']
39 noid_selections = ['perf', 'idperf']
40 meson_selections = ['kaonpi1', 'kaonpi2', 'dipion1', 'dipion2', 'dipion3', 'dipion4', 'dikaonmass', 'singlepion']
41 
42 def getChainIDConfigName(chainPart) -> str:
43  '''Clean the ID configuration for a chainPart dict'''
44  sel = chainPart['selection']
45 
46  # Support for the Legacy trigger names:
47  if chainPart['reconstruction'] == 'tracktwoMVA':
48  if sel in rnn_wps:
49  return 'DeepSet'
50  elif sel in meson_selections:
51  return 'MesonCuts'
52  elif chainPart['reconstruction'] in ['tracktwoLLP', 'trackLRT'] and sel in rnn_wps:
53  return 'RNNLLP'
54 
55 
56  # Retrieve the TauID name from the selection string
57  if sel.startswith('veryloose'): sel = sel.removeprefix('veryloose')
58  if sel.startswith('loose'): sel = sel.removeprefix('loose')
59  if sel.startswith('medium'): sel = sel.removeprefix('medium')
60  if sel.startswith('tight'): sel = sel.removeprefix('tight')
61 
62  # Remap names (e.g. DS -> DeepSet)
63  name_mapping: dict[str, str] = {'DS': 'DeepSet', 'GNT': 'GNTau'}
64  if sel in name_mapping: sel = name_mapping[sel]
65 
66  return sel
67 
68 
69 def getChainSequenceConfigName(chainPart) -> str:
70  '''Get the HLT Tau signature sequence name (e.g. ptonly, tracktwo, trackLRT, etc...)'''
71  return chainPart['reconstruction']
72 
73 
74 def getChainPrecisionSeqName(chainPart) -> str:
75  '''
76  Get the HLT Tau Precision sequence name suffix.
77  This is also used for the HLT_TrigTauRecMerged_... and HLT_tautrack_... EDM collection names.
78  '''
79  ret = chainPart['reconstruction']
80 
81  # Support for the Legacy trigger names:
82  if ret == 'tracktwoMVA': return 'MVA'
83  elif ret == 'tracktwoLLP': return 'LLP'
84  elif ret == 'trackLRT': return 'LRT'
85 
86  return ret
87 
88 
89 def useBuiltInTauJetRNNScore(tau_id: str, precision_sequence: str) -> bool:
90  '''Check if the TauJet's built-in RNN score and WP variables have to be used, instead of the decorator-based variables'''
91  # Support for "legacy" algorithms, where the scores are stored in the built-in TauJet aux variables
92  if (tau_id == 'DeepSet' and precision_sequence == 'MVA') or (tau_id == 'RNNLLP' and precision_sequence in ['LLP', 'LRT']):
93  return True
94 
95  return False
96 
97 
98 def getTauIDScoreVariables(tau_id: str, precision_sequence: str) -> tuple[str, str]:
99  '''Return the (score, score_sig_trans) variable name pair for a given TauID/Sequence configuration'''
100  # Support for "legacy" algorithms, where the scores are stored in the built-in TauJet aux variables
101  if useBuiltInTauJetRNNScore(tau_id, precision_sequence):
102  return ('RNNJetScore', 'RNNJetScoreSigTrans')
103 
104  return (f'{tau_id}_Score', f'{tau_id}_ScoreSigTrans')
python.HLT.Tau.TauConfigurationTools.useBuiltInTauJetRNNScore
bool useBuiltInTauJetRNNScore(str tau_id, str precision_sequence)
Definition: TauConfigurationTools.py:89
python.HLT.Tau.TauConfigurationTools.getPrecisionSequenceTauIDs
list[str] getPrecisionSequenceTauIDs(flags, str precision_sequence)
Sequence TauIDs.
Definition: TauConfigurationTools.py:15
python.HLT.Tau.TauConfigurationTools.getChainPrecisionSeqName
str getChainPrecisionSeqName(chainPart)
Definition: TauConfigurationTools.py:74
python.HLT.Tau.TauConfigurationTools.getTauIDScoreVariables
tuple[str, str] getTauIDScoreVariables(str tau_id, str precision_sequence)
Definition: TauConfigurationTools.py:98
python.HLT.Tau.TauConfigurationTools.getChainIDConfigName
str getChainIDConfigName(chainPart)
Definition: TauConfigurationTools.py:42
python.HLT.Tau.TauConfigurationTools.getChainSequenceConfigName
str getChainSequenceConfigName(chainPart)
Definition: TauConfigurationTools.py:69