ATLAS Offline Software
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(precision_sequence: str) -> list[str]:
16  '''Get the list of TauIDs for each HLT tau trigger sequence'''
17  tau_ids = {
18  'MVA': ['DeepSet', 'MesonCuts'],
19  'LLP': ['RNNLLP'],
20  'LRT': ['RNNLLP'],
21  }
22 
23  return tau_ids[precision_sequence]
24 
25 
28 
29 # The following functions are only required while we still have triggers
30 # with the RNN/DeepSet naming scheme in the Menu (e.g. mediumRNN_tracktwoMVA/LLP)
31 rnn_wps = ['verylooseRNN', 'looseRNN', 'mediumRNN', 'tightRNN']
32 noid_selections = ['perf', 'idperf']
33 meson_selections = ['kaonpi1', 'kaonpi2', 'dipion1', 'dipion2', 'dipion3', 'dipion4', 'dikaonmass', 'singlepion']
34 
35 def getChainIDConfigName(chainPart) -> str:
36  '''Clean the ID configuration for a chainPart dict'''
37  sel = chainPart['selection']
38 
39  # Support for the Legacy trigger names:
40  if chainPart['reconstruction'] == 'tracktwoMVA':
41  if sel in rnn_wps:
42  return 'DeepSet'
43  elif sel in meson_selections:
44  return 'MesonCuts'
45  elif chainPart['reconstruction'] in ['tracktwoLLP', 'trackLRT'] and sel in rnn_wps:
46  return 'RNNLLP'
47 
48 
49  # Retrieve the TauID name from the selection string
50  if sel.startswith('veryloose'): sel = sel.removeprefix('veryloose')
51  if sel.startswith('loose'): sel = sel.removeprefix('loose')
52  if sel.startswith('medium'): sel = sel.removeprefix('medium')
53  if sel.startswith('tight'): sel = sel.removeprefix('tight')
54 
55  # Remap names (e.g. DS -> DeepSet)
56  name_mapping: dict[str, str] = {'DS': 'DeepSet', 'GNT': 'GNTau'}
57  if sel in name_mapping: sel = name_mapping[sel]
58 
59  return sel
60 
61 
62 def getChainSequenceConfigName(chainPart) -> str:
63  '''Get the HLT Tau signature sequence name (e.g. ptonly, tracktwo, trackLRT, etc...)'''
64  return chainPart['reconstruction']
65 
66 
67 def getChainPrecisionSeqName(chainPart) -> str:
68  '''
69  Get the HLT Tau Precision sequence name suffix.
70  This is also used for the HLT_TrigTauRecMerged_... and HLT_tautrack_... EDM collection names.
71  '''
72  ret = chainPart['reconstruction']
73 
74  # Support for the Legacy trigger names:
75  if ret == 'tracktwoMVA': return 'MVA'
76  elif ret == 'tracktwoLLP': return 'LLP'
77  elif ret == 'trackLRT': return 'LRT'
78 
79  return ret
80 
81 
82 def useBuiltInTauJetRNNScore(tau_id: str, precision_sequence: str) -> bool:
83  '''Check if the TauJet's built-in RNN score and WP variables have to be used, instead of the decorator-based variables'''
84  # Support for "legacy" algorithms, where the scores are stored in the built-in TauJet aux variables
85  if (tau_id == 'DeepSet' and precision_sequence == 'MVA') or (tau_id == 'RNNLLP' and precision_sequence in ['LLP', 'LRT']):
86  return True
87 
88  return False
89 
90 
91 def getTauIDScoreVariables(tau_id: str, precision_sequence: str) -> tuple[str, str]:
92  '''Return the (score, score_sig_trans) variable name pair for a given TauID/Sequence configuration'''
93  # Support for "legacy" algorithms, where the scores are stored in the built-in TauJet aux variables
94  if useBuiltInTauJetRNNScore(tau_id, precision_sequence):
95  return ('RNNJetScore', 'RNNJetScoreSigTrans')
96 
97  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:82
python.HLT.Tau.TauConfigurationTools.getChainPrecisionSeqName
str getChainPrecisionSeqName(chainPart)
Definition: TauConfigurationTools.py:67
python.HLT.Tau.TauConfigurationTools.getTauIDScoreVariables
tuple[str, str] getTauIDScoreVariables(str tau_id, str precision_sequence)
Definition: TauConfigurationTools.py:91
python.HLT.Tau.TauConfigurationTools.getPrecisionSequenceTauIDs
list[str] getPrecisionSequenceTauIDs(str precision_sequence)
Sequence TauIDs.
Definition: TauConfigurationTools.py:15
python.HLT.Tau.TauConfigurationTools.getChainIDConfigName
str getChainIDConfigName(chainPart)
Definition: TauConfigurationTools.py:35
python.HLT.Tau.TauConfigurationTools.getChainSequenceConfigName
str getChainSequenceConfigName(chainPart)
Definition: TauConfigurationTools.py:62