ATLAS Offline Software
TrigPartialEventBuildingConfig.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 from AthenaConfiguration.ComponentFactory import CompFactory
6 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
7 from libpyeformat_helper import SourceIdentifier, SubDetector
8 from RegionSelector import RegSelToolConfig
9 
10 from AthenaCommon.Logging import logging
11 _log = logging.getLogger(__name__)
12 
13 
14 def getRegSelTools(flags, detNames):
15  '''
16  Get a list of RegionSelector tools for given detector look-up tables to build list of ROBs
17  in these detectors that intersect with the RoI. Special value 'All' can be also given
18  in the detNames list to include all detectors available in RegionSelector.
19  '''
20  # To check Detector flags before adding RegSel tool configs, we need to map RegSel det names to Detector flag names
21  _regSelToDetFlagMap = {
22  # Calo
23  'TTEM': 'Calo',
24  'TTHEC': 'Calo',
25  'FCALEM': 'LAr',
26  'FCALHAD': 'LAr',
27  'TILE': 'Tile',
28  }
29  # ID
30  _regSelToDetFlagMap |= dict([(d,d) for d in ['Pixel', 'SCT', 'TRT']])
31  # Muon
32  _regSelToDetFlagMap |= dict([(d,d) for d in ['MDT', 'RPC', 'TGC', 'CSC', 'MM']])
33  _regSelToDetFlagMap['STGC'] = 'sTGC' # inconsistent capitalisation, regSelTool_STGC_Cfg should be regSelTool_sTGC_Cfg
34  if 'All' in detNames:
35  detNames = _regSelToDetFlagMap.keys()
36 
37  acc = ComponentAccumulator()
38  regSelTools = []
39  for det in detNames:
40  if det=='sTGC':
41  det='STGC' # inconsistent capitalisation, regSelTool_STGC_Cfg should be regSelTool_sTGC_Cfg
42  if det not in _regSelToDetFlagMap:
43  raise RuntimeError('Cannot add detector "' + det + '" because it is not in _regSelToDetFlagMap')
44  detFlag = 'Enable'+_regSelToDetFlagMap[det]
45  detEnabled = getattr(flags.Detector, detFlag)
46  if not detEnabled:
47  _log.debug('addRegSelDets: skip adding detector "%s" because the flag Detector.%s is False', det, detFlag)
48  continue
49  funcName = f'regSelTool_{det}_Cfg'
50  if not hasattr(RegSelToolConfig, funcName):
51  raise RuntimeError('Cannot add detector "' + det + '", RegSelToolConfig does not have a function ' + funcName)
52  func = getattr(RegSelToolConfig, funcName)
53  if not callable(func):
54  raise RuntimeError('Cannot add detector "' + det + '", RegSelToolConfig.' + funcName + ' is not callable')
55  regSelTools += [acc.popToolsAndMerge(func(flags))]
56 
57  acc.setPrivateTools(regSelTools)
58  return acc
59 
60 
61 def RoIPEBInfoWriterToolCfg(flags, name='RoIPEBInfoWriterTool',
62  regSelDets : list[str] = [],
63  ROBs: list[SourceIdentifier] = [],
64  subDets: list[SubDetector] = [],
65  **kwargs):
66  """Configure the RoIPEBInfoWriterTool"""
67 
68  acc = ComponentAccumulator()
69  acc_regsel = getRegSelTools(flags, regSelDets)
70 
71  kwargs.setdefault("MatchTriggerType", [])
72 
73  tool = CompFactory.RoIPEBInfoWriterTool(
74  name,
75  RegionSelectorTools = acc_regsel.popPrivateTools(),
76  ExtraROBs = [int(robid) for robid in ROBs],
77  ExtraSubDets = [int(detid) for detid in subDets],
78  **kwargs )
79 
80  acc.merge(acc_regsel)
81  acc.setPrivateTools(tool)
82  return acc
83 
84 
85 def StaticPEBInfoWriterToolCfg(flags, name='StaticPEBInfoWriterTool',
86  ROBs: list[SourceIdentifier] = [],
87  subDets : list[SubDetector] = [],
88  **kwargs):
89  """Configure the StaticPEBInfoWriterTool"""
90 
91  acc = ComponentAccumulator()
92 
93  kwargs.setdefault("MatchTriggerType", [])
94 
95  tool = CompFactory.StaticPEBInfoWriterTool(
96  name,
97  ROBList = [int(robid) for robid in ROBs],
98  SubDetList = [int(detid) for detid in subDets],
99  **kwargs )
100 
101  acc.setPrivateTools(tool)
102  return acc
103 
104 
105 if __name__ == '__main__':
106  from AthenaConfiguration.TestDefaults import defaultTestFiles, defaultGeometryTags
107  from AthenaConfiguration.AllConfigFlags import initConfigFlags
108  flags = initConfigFlags()
109  flags.Input.Files = defaultTestFiles.RAW_RUN3
110  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
111  flags.lock()
112 
115  regSelDets = ['Pixel', 'SCT', 'TRT'],
116  subDets = [SubDetector.TDAQ_CTP] )
117  acc.popPrivateTools()
118  cfg.merge(acc)
119 
120  acc = StaticPEBInfoWriterToolCfg(flags,
121  subDets = [SubDetector.TDAQ_HLT],
122  ROBs = [SourceIdentifier(SubDetector.TDAQ_CTP, 0)])
123  acc.popPrivateTools()
124  cfg.merge(acc)
125 
126  cfg.wasMerged()
TrigPartialEventBuildingConfig.RoIPEBInfoWriterToolCfg
def RoIPEBInfoWriterToolCfg(flags, name='RoIPEBInfoWriterTool', list[str] regSelDets=[], list[SourceIdentifier] ROBs=[], list[SubDetector] subDets=[], **kwargs)
Definition: TrigPartialEventBuildingConfig.py:61
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TrigPartialEventBuildingConfig.getRegSelTools
def getRegSelTools(flags, detNames)
Definition: TrigPartialEventBuildingConfig.py:14
TrigPartialEventBuildingConfig.StaticPEBInfoWriterToolCfg
def StaticPEBInfoWriterToolCfg(flags, name='StaticPEBInfoWriterTool', list[SourceIdentifier] ROBs=[], list[SubDetector] subDets=[], **kwargs)
Definition: TrigPartialEventBuildingConfig.py:85
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19