ATLAS Offline Software
TrigTauHypoTool.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from typing import Any
4 
5 from AthenaCommon.SystemOfUnits import GeV
6 
7 from .TrigTauHypoMonitoring import getTrigTauPrecisionIDHypoToolMonitoring, getTrigTauPrecisionDiKaonHypoToolMonitoring
8 
9 from AthenaCommon.Logging import logging
10 log = logging.getLogger('TrigHLTTauHypoTool')
11 
12 #============================================================================================
13 # Precision step hypothesis tool
14 #============================================================================================
15 def TrigTauPrecisionHypoToolFromDict(flags, chainDict):
16  chainPart = chainDict['chainParts'][0]
17 
18  from TriggerMenuMT.HLT.Tau.TauConfigurationTools import getChainIDConfigName
19  identification = getChainIDConfigName(chainPart)
20 
21  if identification == 'MesonCuts':
22  # Meson cut-based triggers (ATR-22644)
23  return TrigTauPrecisionDiKaonHypoToolFromDict(flags, chainDict)
24  else:
25  # Everything else
26  return TrigTauPrecisionIDHypoToolFromDict(flags, chainDict)
27 
28 #-----------------------------------------------------------------
29 # Standard tau triggers configuration
30 #-----------------------------------------------------------------
31 class TauCuts:
32  def __init__(self, chain_part: dict[str, Any]):
33  self._chain_part = chain_part
34 
35  @property
36  def n_track_max(self) -> int: return 3
37 
38  @property
39  def n_iso_track_max(self) -> int: return 999 if self._chain_part['selection'] == 'idperf' else 1
40 
41  @property
42  def pt_min(self) -> float: return float(self._chain_part['threshold']) * GeV
43 
44  @property
45  def id_wp(self) -> int:
46  sel = self._chain_part['selection']
47 
48  if sel == 'perf' or sel == 'idperf': return -1 # disabled
49  elif sel.startswith('veryloose'): return 0
50  elif sel.startswith('loose'): return 1
51  elif sel.startswith('medium'): return 2
52  elif sel.startswith('tight'): return 3
53 
54  raise ValueError(f'Invalid selection: {sel}')
55 
56 def TrigTauPrecisionIDHypoToolFromDict(flags, chainDict):
57  '''TrigTauPrecisionIDHypoTool configuration for the standard Tau triggers'''
58  name = chainDict['chainName']
59  chainPart = chainDict['chainParts'][0]
60  cuts = TauCuts(chainPart)
61 
62  # Setup the Hypothesis tool
63  from AthenaConfiguration.ComponentFactory import CompFactory
64  currentHypo = CompFactory.TrigTauPrecisionIDHypoTool(
65  name,
66  PtMin=cuts.pt_min,
67  NTracksMax=cuts.n_track_max,
68  NIsoTracksMax=cuts.n_iso_track_max,
69  IDWP=cuts.id_wp,
70  )
71 
72  from TriggerMenuMT.HLT.Tau.TauConfigurationTools import getChainIDConfigName, getChainPrecisionSeqName, useBuiltInTauJetRNNScore, getPrecisionSequenceTauIDs, getTauIDScoreVariables
73 
74  id_score_monitoring = {}
75 
76  precision_seq_name = getChainPrecisionSeqName(chainPart)
77  identification = getChainIDConfigName(chainPart)
78  if identification in ['perf', 'idperf']:
79  if identification == 'idperf':
80  currentHypo.AcceptAll = True
81 
82  # Monitor all the included algorithms
83  used_builtin_rnnscore = False
84  for tau_id in getPrecisionSequenceTauIDs(precision_seq_name):
85  # Skip algs without inference scores
86  if tau_id in ['MesonCuts']: continue
87 
88  # We can only have at most one alg. using the built-in TauJet RNN score variables
89  if useBuiltInTauJetRNNScore(tau_id, precision_seq_name):
90  if used_builtin_rnnscore:
91  raise ValueError('Cannot have two TauID algorithms with scores stored in the built-in TauJet RNN score variables')
92  used_builtin_rnnscore = True
93 
94  id_score_monitoring[tau_id] = getTauIDScoreVariables(tau_id, precision_seq_name)
95 
96  else:
97  if useBuiltInTauJetRNNScore(identification, precision_seq_name):
98  # To support the legacy tracktwoMVA/LLP/LRT chains, only in those cases we store the
99  # ID score and passed WPs in the native TauJet variables
100  currentHypo.IDMethod = 1 # TauJet built-in RNN score
101  else:
102  # Decorator-based triggers
103  currentHypo.IDMethod = 2 # Use decorators
104  currentHypo.IDWPNames = [f'{identification}_{wp}' for wp in getattr(flags.Trigger.Offline.Tau, identification).WPNames]
105 
106  # Monitor this algorithm only
107  id_score_monitoring[identification] = getTauIDScoreVariables(identification, precision_seq_name)
108 
109  # For any triggers following the tracktwo reconstruction (2023 DeepSet)
110  if chainPart['reconstruction'] == 'tracktwoMVA':
111  currentHypo.TrackPtCut = 1.5*GeV
112  currentHypo.HighPtSelectionLooseIDThr = 200*GeV
113  currentHypo.HighPtSelectionJetThr = 430*GeV
114 
115  # Only monitor chains with the 'tauMon:online' groups
116  if 'tauMon:online' in chainDict['monGroups']:
117  currentHypo.MonTool = getTrigTauPrecisionIDHypoToolMonitoring(flags, name, id_score_monitoring.keys())
118 
119  # TauID Score monitoring
120  currentHypo.MonitoredIDScores = id_score_monitoring
121 
122  return currentHypo
123 
124 
125 #-----------------------------------------------------------------
126 # Meson cut-based triggers configuration (ATR-22644 + ATR-23239)
127 #-----------------------------------------------------------------
128 from collections import namedtuple
129 
130 DiKaonCuts = namedtuple('DiKaonCuts', 'massTrkSysMin massTrkSysMax massTrkSysKaonMin massTrkSysKaonMax massTrkSysKaonPiMin massTrkSysKaonPiMax targetMassTrkSysKaonPi leadTrkPtMin PtMin EMPOverTrkSysPMax')
131 thresholds_dikaon = {
132  ('dikaonmass', 25): DiKaonCuts(0.0*GeV, 1000.0*GeV, 0.987*GeV, 1.060*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 15.0*GeV, 25.0*GeV, 1.5),
133  ('dikaonmass', 35): DiKaonCuts(0.0*GeV, 1000.0*GeV, 0.987*GeV, 1.060*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 25.0*GeV, 35.0*GeV, 1.5),
134 
135  ('kaonpi1', 25): DiKaonCuts(0.0*GeV, 1000.0*GeV, 0.0*GeV, 1000.0*GeV, 0.79*GeV, 0.99*GeV, 0.89*GeV, 15.0*GeV, 25.0*GeV, 1.0),
136  ('kaonpi1', 35): DiKaonCuts(0.0*GeV, 1000.0*GeV, 0.0*GeV, 1000.0*GeV, 0.79*GeV, 0.99*GeV, 0.89*GeV, 25.0*GeV, 35.0*GeV, 1.0),
137 
138  ('kaonpi2', 25): DiKaonCuts(0.0*GeV, 1000.0*GeV, 0.0*GeV, 1000.0*GeV, 1.8*GeV, 1.93*GeV, 1.865*GeV, 15.0*GeV, 25.0*GeV, 1.0),
139  ('kaonpi2', 35): DiKaonCuts(0.0*GeV, 1000.0*GeV, 0.0*GeV, 1000.0*GeV, 1.8*GeV, 1.93*GeV, 1.865*GeV, 25.0*GeV, 35.0*GeV, 1.0),
140 
141  ('dipion1', 25): DiKaonCuts(0.475*GeV, 1.075*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 15.0*GeV, 25.0*GeV, 1.0),
142  ('dipion2', 25): DiKaonCuts(0.460*GeV, 0.538*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 15.0*GeV, 25.0*GeV, 1.0),
143  ('dipion3', 25): DiKaonCuts(0.279*GeV, 0.648*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 25.0*GeV, 25.0*GeV, 2.2),
144  ('dipion4', 25): DiKaonCuts(0.460*GeV, 1.075*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 1000.0*GeV, 0.0*GeV, 15.0*GeV, 25.0*GeV, 1.0),
145 }
146 
147 SinglePionCuts = namedtuple('SinglePionCuts', 'leadTrkPtMin PtMin NTracksMax NIsoTracksMax dRmaxMax etOverPtLeadTrkMin etOverPtLeadTrkMax')
148 thresholds_singlepion = {
149  ('singlepion', 25): SinglePionCuts(30.0*GeV, 25.0*GeV, 1, 0, 0.06, 0.4, 0.85),
150 }
151 
153  '''TrigTauPrecisionDiKaonHypoTool configuration for the meson cut-based Tau triggers (ATR-22644)'''
154  name = chainDict['chainName']
155  chainPart = chainDict['chainParts'][0]
156 
157  # Setup the Hypothesis tool
158  from AthenaConfiguration.ComponentFactory import CompFactory
159  currentHypo = CompFactory.TrigTauPrecisionDiKaonHypoTool(name)
160 
161  key = (chainPart['selection'], int(chainPart['threshold']))
162  if key in thresholds_dikaon:
163  thr = thresholds_dikaon[key]
164  currentHypo.PtMin = thr.PtMin
165  currentHypo.leadTrkPtMin = thr.leadTrkPtMin
166  currentHypo.massTrkSysMin = thr.massTrkSysMin
167  currentHypo.massTrkSysMax = thr.massTrkSysMax
168  currentHypo.massTrkSysKaonMin = thr.massTrkSysKaonMin
169  currentHypo.massTrkSysKaonMax = thr.massTrkSysKaonMax
170  currentHypo.massTrkSysKaonPiMin = thr.massTrkSysKaonPiMin
171  currentHypo.massTrkSysKaonPiMax = thr.massTrkSysKaonPiMax
172  currentHypo.targetMassTrkSysKaonPi = thr.targetMassTrkSysKaonPi
173  currentHypo.EMPOverTrkSysPMax = thr.EMPOverTrkSysPMax
174 
175  elif key in thresholds_singlepion:
176  thr = thresholds_singlepion[key]
177  currentHypo.PtMin = thr.PtMin
178  currentHypo.NTracksMax = thr.NTracksMax
179  currentHypo.NIsoTracksMax = thr.NIsoTracksMax
180  currentHypo.leadTrkPtMin = thr.leadTrkPtMin
181  currentHypo.dRmaxMax = thr.dRmaxMax
182  currentHypo.etOverPtLeadTrkMin = thr.etOverPtLeadTrkMin
183  currentHypo.etOverPtLeadTrkMax = thr.etOverPtLeadTrkMax
184 
185  currentHypo.MonTool = getTrigTauPrecisionDiKaonHypoToolMonitoring(flags, name)
186 
187  return currentHypo
188 
189 
190 
191 #============================================================================================
192 # Precision Tracking step hypothesis tool (without selection)
193 #============================================================================================
195  name = chainDict['chainName']
196 
197  from AthenaConfiguration.ComponentFactory import CompFactory
198  currentHypo = CompFactory.TrigTauPrecTrackHypoTool(name)
199 
200  return currentHypo
201 
202 
203 
204 #============================================================================================
205 # FTF steps hypothesis tools (without selection)
206 #============================================================================================
208  name = chainDict['chainName']
209 
210  from AthenaConfiguration.ComponentFactory import CompFactory
211  currentHypo = CompFactory.TrigTauFastTrackHypoTool(name)
212 
213  return currentHypo
214 
215 
216 
217 #============================================================================================
218 # CaloMVA step hypothesis tool
219 #============================================================================================
221  name = chainDict['chainName']
222  threshold = float(chainDict['chainParts'][0]['threshold'])
223 
224  from AthenaConfiguration.ComponentFactory import CompFactory
225  currentHypo = CompFactory.TrigTauCaloHypoTool(name)
226  currentHypo.PtMin = threshold * GeV
227 
228  return currentHypo
229 
TrigTauHypoTool.TauCuts.n_iso_track_max
int n_iso_track_max(self)
Definition: TrigTauHypoTool.py:39
SystemOfUnits
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TrigTauHypoTool.TrigTauPrecisionDiKaonHypoToolFromDict
def TrigTauPrecisionDiKaonHypoToolFromDict(flags, chainDict)
Definition: TrigTauHypoTool.py:152
python.HLT.Tau.TauConfigurationTools.useBuiltInTauJetRNNScore
bool useBuiltInTauJetRNNScore(str tau_id, str precision_sequence)
Definition: TauConfigurationTools.py:82
TrigTauHypoTool.TauCuts.pt_min
float pt_min(self)
Definition: TrigTauHypoTool.py:42
TrigTauHypoTool.TauCuts
Definition: TrigTauHypoTool.py:31
TrigTauHypoTool.TrigTauPrecisionIDHypoToolFromDict
def TrigTauPrecisionIDHypoToolFromDict(flags, chainDict)
Definition: TrigTauHypoTool.py:56
TrigTauHypoTool.TauCuts._chain_part
_chain_part
Definition: TrigTauHypoTool.py:33
TrigTauHypoTool.TrigTauFastTrackHypoToolFromDict
def TrigTauFastTrackHypoToolFromDict(chainDict)
Definition: TrigTauHypoTool.py:207
TrigTauHypoMonitoring.getTrigTauPrecisionIDHypoToolMonitoring
def getTrigTauPrecisionIDHypoToolMonitoring(flags, str name, list[str] tau_ids)
Definition: TrigTauHypoMonitoring.py:5
TrigTauHypoTool.DiKaonCuts
DiKaonCuts
Definition: TrigTauHypoTool.py:130
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
TrigTauHypoMonitoring.getTrigTauPrecisionDiKaonHypoToolMonitoring
def getTrigTauPrecisionDiKaonHypoToolMonitoring(flags, str name)
Definition: TrigTauHypoMonitoring.py:35
TrigTauHypoTool.TauCuts.__init__
def __init__(self, dict[str, Any] chain_part)
Definition: TrigTauHypoTool.py:32
TrigTauHypoTool.TrigTauPrecisionHypoToolFromDict
def TrigTauPrecisionHypoToolFromDict(flags, chainDict)
Definition: TrigTauHypoTool.py:15
python.HLT.Tau.TauConfigurationTools.getChainIDConfigName
str getChainIDConfigName(chainPart)
Definition: TauConfigurationTools.py:35
TrigTauHypoTool.TauCuts.n_track_max
int n_track_max(self)
Definition: TrigTauHypoTool.py:36
TrigTauHypoTool.TrigTauPrecTrackHypoToolFromDict
def TrigTauPrecTrackHypoToolFromDict(chainDict)
Definition: TrigTauHypoTool.py:194
TrigTauHypoTool.SinglePionCuts
SinglePionCuts
Definition: TrigTauHypoTool.py:147
TrigTauHypoTool.TauCuts.id_wp
int id_wp(self)
Definition: TrigTauHypoTool.py:45
TrigTauHypoTool.TrigTauCaloMVAHypoToolFromDict
def TrigTauCaloMVAHypoToolFromDict(chainDict)
Definition: TrigTauHypoTool.py:220
readCCLHist.float
float
Definition: readCCLHist.py:83