ATLAS Offline Software
TrigGenericAlgsConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 from TrigPartialEventBuilding.TrigPartialEventBuildingConfig import getRegSelTools
6 from AthenaCommon.Logging import logging
7 _log = logging.getLogger( __name__ )
8 
9 
10 def TimeBurnerCfg(flags, name="TimeBurner", **kwargs):
11  return CompFactory.TimeBurner(name, **kwargs)
12 
13 def TimeBurnerHypoToolGen(chainDict):
14  # Dummy HypoTool (it is not even called by TimeBurner)
15  return CompFactory.TrigGenericHypoTool(chainDict['chainName'],
16  PassString = "")
17 
19  return CompFactory.EndOfEventROIConfirmerAlg(name)
20 
21 def EndOfEventFilterAlgCfg(name, chainName):
22  return CompFactory.EndOfEventFilterAlg(name, ChainName=chainName)
23 
24 def TrigEventInfoRecorderAlgCfg(flags, name, trigEventInfoKey, decoratePFlowInfo, decorateEMTopoInfo, renounceAll=False, primaryVertexInputName="HLT_IDVertex_FS", RhoKey_PFlow = 'HLT_Kt4EMPFlowEventShape', RhoKey_EMTopo = 'HLT_Kt4EMTopoEventShape'):
25  acc = ComponentAccumulator()
26  alg = CompFactory.TrigEventInfoRecorderAlg(name,
27  trigEventInfoKey = trigEventInfoKey,
28  decoratePFlowInfo = decoratePFlowInfo,
29  decorateEMTopoInfo = decorateEMTopoInfo,
30  renounceAll = renounceAll,
31  primaryVertexInputName = primaryVertexInputName,
32  RhoKey_PFlow = RhoKey_PFlow,
33  RhoKey_EMTopo = RhoKey_EMTopo,
34  )
35  acc.addEventAlgo(alg, primary=True)
36  return acc
37 
38 def L1CorrelationMonitoringCfg(flags, name):
39  from AthenaMonitoringKernel.GenericMonitoringTool import GenericMonitoringTool
40  monTool = GenericMonitoringTool(flags, 'MonTool')
41  monTool.defineHistogram('EF_L1Corr_beforeafterflag', path='EXPERT', type='TH1F', title='beforeafterflag', xbins=4, xmin=-1.5, xmax=2.5)
42  monTool.defineHistogram('EF_L1Corr_l1a_type, EF_L1Corr_other_type', path='EXPERT', type='TH2F', title="typeMatrix ; L1A; Other", xbins=8, xmin=-0.5, xmax=7.5, ybins=8, ymin=-0.5, ymax=7.5)
43  return monTool
44 
45 def L1CorrelationAlgCfg(flags, name, **kwargs):
46  kwargs.setdefault("MonTool",L1CorrelationMonitoringCfg(flags, "L1CorrelationAlg"))
47  return CompFactory.L1CorrelationAlg(name, **kwargs)
48 
49 def ROBPrefetchingAlgCfg(flags, name, regSelDets=[], **kwargs):
50  acc = ComponentAccumulator()
51  alg = CompFactory.ROBPrefetchingAlg(name, **kwargs)
52  alg.RegionSelectorTools = acc.popToolsAndMerge(getRegSelTools(flags, regSelDets))
53  acc.addEventAlgo(alg, primary=True)
54 
55  return acc
56 
57 def ROBPrefetchingAlgCfg_Si(flags, nameSuffix, **kwargs):
58  return ROBPrefetchingAlgCfg(flags, 'ROBPrefetchingAlg_Si_'+nameSuffix, ['Pixel', 'SCT'], **kwargs)
59 
60 def ROBPrefetchingAlgCfg_Calo(flags, nameSuffix, **kwargs):
61  return ROBPrefetchingAlgCfg(flags, 'ROBPrefetchingAlg_Calo_'+nameSuffix, ['TTEM', 'TTHEC', 'FCALEM', 'FCALHAD', 'TILE'], **kwargs)
62 
63 def ROBPrefetchingAlgCfg_Muon(flags, nameSuffix, **kwargs):
64  return ROBPrefetchingAlgCfg(flags, 'ROBPrefetchingAlg_Muon_'+nameSuffix, ['MDT', 'RPC', 'TGC', 'CSC', 'MM', 'sTGC'], **kwargs)
65 
67  from TrigConfHLTUtils.HLTUtils import string2hash
68  from AthenaCommon.CFElements import getSequenceChildren, isSequence
69  from collections import defaultdict
70  def sequenceAlgs(seq):
71  algs = []
72  for alg in getSequenceChildren(seq):
73  if isSequence(alg):
74  algs.extend(sequenceAlgs(alg))
75  elif alg.getName().startswith('IMEmpty'):
76  # skip empty probe step in tag&probe chains
77  continue
78  else:
79  algs.append(alg.getName())
80 
81  return algs
82 
83  def firstNonEmptyStepAlgs(CF_list):
84  algsMap = defaultdict(list) # {chainLegName, algsInFirstNonEmptyStep}
85  firstSequence = []
86 
87  for cfseq_per_step in CF_list:
88  for cfseq in cfseq_per_step: # all the steps with same step number
89  step = cfseq.sequenceCA.step
90  foundFirstSequence = False
91  for ileg, menuSeq in enumerate(step.sequences):
92  seqA = sequenceAlgs(menuSeq.sequence.Alg)
93  if seqA: # found not empty sequence in this step
94  for stepD, chain in zip(cfseq.stepDicts, cfseq.chains): # loop over chains
95  if chain in firstSequence:
96  continue
97  legName = stepD[ileg]['chainName']
98  if legName not in algsMap: # add only the first time
99  algsMap[legName] = seqA
100  firstSequence.append(chain)
101  foundFirstSequence = True
102 
103  if foundFirstSequence:
104  break
105 
106  return algsMap
107 
108  detGroupIdentifierAlgs = {
109  'Si' : ['PixelRawDataProvider','SCTRawDataProvider'],
110  'Calo' : ['HLTCaloCellMaker','FastCaloL2EgammaAlg'],
111  'Muon' : ['RpcRawDataProvider','TgcRawDataProvider','MdtRawDataProvider','sTgcRawDataProvider','MMRawDataProvider']
112  }
113 
114  def algsToDetGroup(algs):
115  groups = []
116  for group,idAlgs in detGroupIdentifierAlgs.items():
117  if any([ida in algName for algName in algs for ida in idAlgs]):
118  groups.append(group)
119  if len(groups)>1:
120  raise RuntimeError(f'Multiple detector groups: {groups:s} matched to the list of algs: {algs:s}')
121  return groups[0] if groups else None
122 
123  chainFilterMap = { # {DetGroup, list of chain leg hashes}
124  'Si': [],
125  'Calo': [],
126  'Muon': []
127  }
128 
129 
130  algsMap = firstNonEmptyStepAlgs(CF_list)
131  for legName,algs in algsMap.items():
132  det = algsToDetGroup(algs)
133  if not det:
134  continue
135  _log.debug("%s initialRoI will prefetch %s", legName, det)
136  chainFilterMap[det].append(string2hash(legName))
137  return chainFilterMap
138 
139 # Legacy searches for the algs through the top level sequence
141  from AthenaCommon.AlgSequence import AlgSequence
142  from AthenaCommon.CFElements import findSubSequence, findAlgorithm
143  chainFilterMap = getChainsForPrefetching(chains)
144 
145  hltBeginSeq = findSubSequence(AlgSequence(), 'HLTBeginSeq')
146  for det,chainFilter in chainFilterMap.items():
147  prefetchAlg = findAlgorithm(hltBeginSeq, f'ROBPrefetchingAlg_{det}_initialRoI')
148  if not chainFilter:
149  # Empty filter means unconditional prefetching
150  # - prevent this by adding a non-existent hash to the list which effectively disables the prefetching alg
151  _log.info('No chains matched to %s - forcing ChainFilter=[0] to disable this alg\'s prefetching', prefetchAlg.getName())
152  chainFilter = [0]
153 
154  prefetchAlg.ChainFilter = chainFilter
155 
156 # In CA we have no access to the HLTBeginSeq in here
157 # Instead generate the prefetching alg configs and append the ChainFilter,
158 # to be merged into the global config.
159 def prefetchingInitialRoIConfig(flags, CFseq_list):
160  chainFilterMap = getChainsForPrefetching(CFseq_list)
161  configurators = {
162  'Si': ROBPrefetchingAlgCfg_Si,
163  'Calo': ROBPrefetchingAlgCfg_Calo,
164  'Muon': ROBPrefetchingAlgCfg_Muon,
165  }
166 
167  prefetchCfg = ComponentAccumulator()
168 
169  for det,chainFilter in chainFilterMap.items():
170  if not chainFilter:
171  # Empty filter means unconditional prefetching
172  # - prevent this by adding a non-existent hash to the list which effectively disables the prefetching alg
173  _log.info('No chains matched to ROBPrefetchingAlg_%s_initialRoI - forcing ChainFilter=[0] to disable this alg\'s prefetching', det)
174  chainFilter = [0]
175  prefetchAlg = configurators[det](flags, 'initialRoI', ChainFilter=chainFilter)
176  prefetchCfg.merge(prefetchAlg)
177 
178  return prefetchCfg
179 
180 
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.TrigGenericAlgsConfig.ROBPrefetchingAlgCfg_Muon
def ROBPrefetchingAlgCfg_Muon(flags, nameSuffix, **kwargs)
Definition: TrigGenericAlgsConfig.py:63
python.AlgSequence.AlgSequence
AlgSequence
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py:7
TrigPartialEventBuildingConfig.getRegSelTools
def getRegSelTools(flags, detNames)
Definition: TrigPartialEventBuildingConfig.py:14
GenericMonitoringTool
Definition: GenericMonitoringTool.h:53
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.TrigGenericAlgsConfig.TimeBurnerHypoToolGen
def TimeBurnerHypoToolGen(chainDict)
Definition: TrigGenericAlgsConfig.py:13
python.TrigGenericAlgsConfig.ROBPrefetchingAlgCfg_Calo
def ROBPrefetchingAlgCfg_Calo(flags, nameSuffix, **kwargs)
Definition: TrigGenericAlgsConfig.py:60
python.TrigGenericAlgsConfig.getChainsForPrefetching
def getChainsForPrefetching(CF_list)
Definition: TrigGenericAlgsConfig.py:66
python.TrigGenericAlgsConfig.configurePrefetchingInitialRoI
def configurePrefetchingInitialRoI(flags, chains)
Definition: TrigGenericAlgsConfig.py:140
python.TrigGenericAlgsConfig.ROBPrefetchingAlgCfg
def ROBPrefetchingAlgCfg(flags, name, regSelDets=[], **kwargs)
Definition: TrigGenericAlgsConfig.py:49
python.TrigGenericAlgsConfig.TrigEventInfoRecorderAlgCfg
def TrigEventInfoRecorderAlgCfg(flags, name, trigEventInfoKey, decoratePFlowInfo, decorateEMTopoInfo, renounceAll=False, primaryVertexInputName="HLT_IDVertex_FS", RhoKey_PFlow='HLT_Kt4EMPFlowEventShape', RhoKey_EMTopo='HLT_Kt4EMTopoEventShape')
Definition: TrigGenericAlgsConfig.py:24
python.TrigGenericAlgsConfig.ROBPrefetchingAlgCfg_Si
def ROBPrefetchingAlgCfg_Si(flags, nameSuffix, **kwargs)
Definition: TrigGenericAlgsConfig.py:57
python.TrigGenericAlgsConfig.L1CorrelationAlgCfg
def L1CorrelationAlgCfg(flags, name, **kwargs)
Definition: TrigGenericAlgsConfig.py:45
python.TrigGenericAlgsConfig.L1CorrelationMonitoringCfg
def L1CorrelationMonitoringCfg(flags, name)
Definition: TrigGenericAlgsConfig.py:38
python.TrigGenericAlgsConfig.prefetchingInitialRoIConfig
def prefetchingInitialRoIConfig(flags, CFseq_list)
Definition: TrigGenericAlgsConfig.py:159
HLTUtils.string2hash
def string2hash(string)
Definition: HLTUtils.py:5
python.CFElements.isSequence
def isSequence(obj)
Definition: CFElements.py:96
python.CFElements.findSubSequence
def findSubSequence(start, nameToLookFor)
Definition: CFElements.py:100
python.TrigGenericAlgsConfig.EndOfEventROIConfirmerAlgCfg
def EndOfEventROIConfirmerAlgCfg(name)
Definition: TrigGenericAlgsConfig.py:18
python.CFElements.findAlgorithm
def findAlgorithm(startSequence, nameToLookFor, depth=1000000)
Definition: CFElements.py:145
python.CFElements.getSequenceChildren
def getSequenceChildren(comp)
Definition: CFElements.py:44
python.TrigGenericAlgsConfig.TimeBurnerCfg
def TimeBurnerCfg(flags, name="TimeBurner", **kwargs)
Definition: TrigGenericAlgsConfig.py:10
python.TrigGenericAlgsConfig.EndOfEventFilterAlgCfg
def EndOfEventFilterAlgCfg(name, chainName)
Definition: TrigGenericAlgsConfig.py:21