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  tool = CompFactory.RoIPEBInfoWriterTool(
72  name,
73  RegionSelectorTools = acc_regsel.popPrivateTools(),
74  ExtraROBs = [int(robid) for robid in ROBs],
75  ExtraSubDets = [int(detid) for detid in subDets],
76  **kwargs )
77 
78  acc.merge(acc_regsel)
79  acc.setPrivateTools(tool)
80  return acc
81 
82 
83 def StaticPEBInfoWriterToolCfg(flags, name='StaticPEBInfoWriterTool',
84  ROBs: list[SourceIdentifier] = [],
85  subDets : list[SubDetector] = [],
86  **kwargs):
87  """Configure the StaticPEBInfoWriterTool"""
88 
89  acc = ComponentAccumulator()
90  tool = CompFactory.StaticPEBInfoWriterTool(
91  name,
92  ROBList = [int(robid) for robid in ROBs],
93  SubDetList = [int(detid) for detid in subDets],
94  **kwargs )
95 
96  acc.setPrivateTools(tool)
97  return acc
98 
99 
100 if __name__ == '__main__':
101  from AthenaConfiguration.TestDefaults import defaultTestFiles, defaultGeometryTags
102  from AthenaConfiguration.AllConfigFlags import initConfigFlags
103  flags = initConfigFlags()
104  flags.Input.Files = defaultTestFiles.RAW_RUN3
105  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
106  flags.lock()
107 
110  regSelDets = ['Pixel', 'SCT', 'TRT'],
111  subDets = [SubDetector.TDAQ_CTP] )
112  acc.popPrivateTools()
113  cfg.merge(acc)
114 
115  acc = StaticPEBInfoWriterToolCfg(flags,
116  subDets = [SubDetector.TDAQ_HLT],
117  ROBs = [SourceIdentifier(SubDetector.TDAQ_CTP, 0)])
118  acc.popPrivateTools()
119  cfg.merge(acc)
120 
121  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:83
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19