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