ATLAS Offline Software
L1CaloFEXAlgosConfig.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.ComponentAccumulator import ComponentAccumulator
6 from AthenaConfiguration.ComponentFactory import CompFactory
7 from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import jFexInputByteStreamToolCfg
8 from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import gFexInputByteStreamToolCfg
9 from AthenaConfiguration.Enums import Format
10 
11 
12 def L1CalojFEXDecoratorCfg(flags, name="jFexTower2SCellDecorator", jTowersReadKey="L1_jFexDataTowers", ExtraInfo = False, SCMasking = True):
13 
15 
16  decorator = CompFactory.LVL1.jFexTower2SCellDecorator(name)
17  decorator.SCell = flags.Trigger.L1.L1CaloSuperCellContainerName
18  decorator.jTowersReadKey = jTowersReadKey
19  decorator.ExtraInfo = ExtraInfo
20  decorator.SCellMasking = SCMasking
21  acc.addEventAlgo(decorator)
22 
23  return acc
24 
25 def L1CaloGTowerDecoratorCfg(flags, name, gTowersReadKey = 'L1_gFexDataTowers'):
26 
28  acc.addEventAlgo( CompFactory.LVL1.gFexTower2SCellDecorator(name, gTowersReadKey=gTowersReadKey) )
29 
30  return acc
31 
32 def eFexTOBDecoratorCfg(flags, name, eFexEMRoIContainer = "L1_eEMRoI", eFexTauRoIContainer = "L1_eTauRoI", ExtraInputs = []):
33  """
34  Configure the eFEX TOB decorator algorithm
35  Requires the eFEXTOBEtTool
36  """
37  acc = ComponentAccumulator()
38 
39  decorator = CompFactory.LVL1.eFexTOBDecorator(name, eFexEMRoIContainer = eFexEMRoIContainer, eFexTauRoIContainer = eFexTauRoIContainer)
40 
41  # in case the TOB containers are different from default we also have to change the write handles
42  if eFexEMRoIContainer != "L1_eEMRoI":
43  decorator.RetaCoreDecDecorKey = eFexEMRoIContainer+".RetaCoreDec"
44  decorator.RetaEnvDecDecorKey = eFexEMRoIContainer+".RetaEnvDec"
45  decorator.RetaEMDecDecorKey = eFexEMRoIContainer+".RhadEMDec"
46  decorator.RhadHadDecDecorKey = eFexEMRoIContainer+".RhadHadDec"
47  decorator.WstotDenDecDecorKey = eFexEMRoIContainer+".WstotDenDec"
48  decorator.WstotNumDecDecorKey = eFexEMRoIContainer+".WstotNumDec"
49  decorator.ClusterSCellEtSumsDecorKey = eFexEMRoIContainer+".ClusterSCellEtSums"
50 
51  if eFexEMRoIContainer != "L1_eTauRoI":
52  decorator.RCoreDecorKey = eFexTauRoIContainer+".RCoreDec"
53  decorator.REnvDecorKey = eFexTauRoIContainer+".REnvDec"
54  decorator.REMCoreDecorKey = eFexTauRoIContainer+".REMCoreDec"
55  decorator.REMHadDecorKey = eFexTauRoIContainer+".REMHadDec"
56 
57  decorator.ExtraInputs = ExtraInputs
58 
59  acc.addEventAlgo(decorator)
60 
61  return acc
62 
63 
64 def eFexTOBSuperCellDecoratorCfg(flags, name, eFexEMRoIContainer = "L1_eEMRoI", eFexTauRoIContainer = "L1_eTauxRoI"):
65  """
66  Configure the eFEX TOB decorator algorithm
67  Requires the eFEXTOBEtTool
68  """
69  acc = ComponentAccumulator()
70 
71  decorator = CompFactory.LVL1.eFexTOBSuperCellDecorator(name, eFexEMRoIContainer = eFexEMRoIContainer, eFexTauRoIContainer = eFexTauRoIContainer)
72 
73  acc.addEventAlgo(decorator)
74 
75  return acc
76 
77 
78 
79 if __name__ == '__main__':
80  from AthenaConfiguration.AllConfigFlags import initConfigFlags
81  from AthenaCommon.Logging import logging
82  import glob
83  import sys
84 
85  import argparse
86  parser = argparse.ArgumentParser(prog='python -m L1CaloFEXAlgos.L1CaloFEXAlgosConfig',
87  description="""Decorator tool for FEX towers athena script.\n\n
88  Example: python -m L1CaloFEXAlgos.L1CaloFEXAlgosConfig --filesInput "data22*" --evtMax 10 --outputs eTOBs """)
89  parser.add_argument('--evtMax',type=int,default=-1,help="number of events")
90  parser.add_argument('--filesInput',nargs='+',help="input files",required=True)
91  parser.add_argument('--outputLevel',default="WARNING",choices={ 'INFO','WARNING','DEBUG','VERBOSE'})
92  parser.add_argument('--outputs',nargs='+',choices={"jTowers", "gTowers", "jTOBs","eTOBs", "eTOBsML"},required=True, help="What data to decode and output.")
93  args = parser.parse_args()
94 
95 
96  log = logging.getLogger('L1CaloFEXAlgosConfig')
97  log.setLevel(logging.DEBUG)
98 
99  from AthenaCommon import Constants
100  algLogLevel = getattr(Constants,args.outputLevel)
101 
102  flags = initConfigFlags()
103  if any(["data" in f for f in args.filesInput]):
104  flags.Trigger.triggerConfig='DB'
105 
106  flags.Exec.OutputLevel = algLogLevel
107  flags.Exec.MaxEvents = args.evtMax
108  flags.Input.Files = [file for x in args.filesInput for file in glob.glob(x)]
109  flags.Concurrency.NumThreads = 1
110  flags.Concurrency.NumConcurrentEvents = 1
111 
112  if not flags.Input.isMC:
113  from AthenaConfiguration.TestDefaults import defaultGeometryTags
114  flags.GeoModel.AtlasVersion = defaultGeometryTags.autoconfigure(flags)
115 
116  if any(["data" in f for f in args.filesInput]):
117  s=args.filesInput[0].replace('*','').replace('.data','')
118  flags.Output.AODFileName = "AOD."+(s.split("/")[-1]).split('_SFO')[0]+"pool.root"
119  else:
120  flags.Output.AODFileName = 'AOD.pool.root'
121 
122  flags.Trigger.EDMVersion = 3
123  flags.Trigger.doLVL1 = True
124  flags.Trigger.enableL1CaloPhase1 = True
125 
126  # Enable only calo for this test
127  from AthenaConfiguration.DetectorConfigFlags import setupDetectorsFromList
128  setupDetectorsFromList(flags,['LAr','Tile','MBTS'],True)
129 
130  flags.lock()
131 
132 
133  # Set up the main service "acc"
134  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
135  acc = MainServicesCfg(flags)
136 
137  # The decoderAlg needs to load ByteStreamMetadata for the detector mask
138  from TriggerJobOpts.TriggerByteStreamConfig import ByteStreamReadCfg
139  acc.merge(ByteStreamReadCfg(flags))
140 
141  # Generate run3 L1 menu
142  from TrigConfigSvc.TrigConfigSvcCfg import L1ConfigSvcCfg
143  acc.merge(L1ConfigSvcCfg(flags))
144 
145  decoderTools = []
146  outputEDM = []
147  maybeMissingRobs = []
148 
149  def addEDM(edmType, edmName):
150  auxType = edmType.replace('Container','AuxContainer')
151  return [f'{edmType}#{edmName}',
152  f'{auxType}#{edmName}Aux.']
153 
154 
157  if 'jTOBs' in args.outputs:
158  from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import jFexRoiByteStreamToolCfg
159  jFexTool = acc.popToolsAndMerge(jFexRoiByteStreamToolCfg(flags, 'jFexBSDecoder'))
160  for module_id in jFexTool.ROBIDs:
161  maybeMissingRobs.append(module_id)
162 
163  decoderTools += [jFexTool]
164 
165 
166 
169  if 'jTowers' in args.outputs:
170  inputjFexTool = acc.popToolsAndMerge(jFexInputByteStreamToolCfg(flags, 'jFexInputBSDecoder'))
171  for module_id in inputjFexTool.ROBIDs:
172  maybeMissingRobs.append(module_id)
173 
174  decoderTools += [inputjFexTool]
175  # saving/adding the jTower xAOD container
176  outputEDM += addEDM('xAOD::jFexTowerContainer', inputjFexTool.jTowersWriteKey.Path)
177 
178 
179 
182  if 'eTOBs' in args.outputs:
183  from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import eFexByteStreamToolCfg
184  eFexTool = acc.popToolsAndMerge(eFexByteStreamToolCfg(flags, 'eFexBSDecoder', TOBs=True, xTOBs=False, decodeInputs=False))
185  for module_id in eFexTool.ROBIDs:
186  maybeMissingRobs.append(module_id)
187 
188  decoderTools += [eFexTool]
189  # saving/adding EDM
190  outputEDM += addEDM('xAOD::eFexEMRoIContainer', eFexTool.eEMContainerWriteKey.Path)
191  outputEDM += addEDM('xAOD::eFexTauRoIContainer', eFexTool.eTAUContainerWriteKey.Path)
192 
193 
194  # Add the decoder tools
195  decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name="L1TriggerByteStreamDecoder",
196  DecoderTools=decoderTools, OutputLevel=algLogLevel, MaybeMissingROBs=maybeMissingRobs)
197  acc.addEventAlgo(decoderAlg, sequenceName='AthAlgSeq')
198 
199 
202  if 'gTOBs' in args.outputs:
203  from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import gFexByteStreamToolCfg
204  gFexTool = acc.popToolsAndMerge(gFexByteStreamToolCfg(flags, 'gFexBSDecoder'))
205  decoderTools += [gFexTool]
206 
207 
208 
211  if 'gTowers' in args.outputs:
212  inputgFexTool = acc.popToolsAndMerge(gFexInputByteStreamToolCfg(flags, 'gFexInputBSDecoder'))
213  decoderTools += [inputgFexTool]
214  # saving/adding the gTower xAOD container
215  outputEDM += addEDM('xAOD::gFexTowerContainer', inputgFexTool.gTowersWriteKey.Path)
216 
217  decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name="L1TriggerByteStreamDecoder",
218  DecoderTools=decoderTools, OutputLevel=algLogLevel)
219 
220  acc.addEventAlgo(decoderAlg, sequenceName='AthAlgSeq')
221 
222 
225 
226  # Decodes LATOME into SCell container
227  from L1CaloFEXSim.L1CaloFEXSimCfg import ReadSCellFromByteStreamCfg,TriggerTowersInputCfg
228  acc.merge(ReadSCellFromByteStreamCfg(flags))
229 
230  # Creates the TriggerTower container
231  acc.merge(TriggerTowersInputCfg(flags))
232 
233  # Uses SCell to decorate the jTowers (with extra info)
234  if 'jTowers' in args.outputs:
235  DecoratorAlgo = L1CalojFEXDecoratorCfg(flags, ExtraInfo = True)
236  acc.merge(DecoratorAlgo)
237 
238  # Decorate eFEX RoIs
239  if 'eTOBs' in args.outputs:
240  DecoratorAlgo = eFexTOBDecoratorCfg(flags,'eFexTOBDecorator')
241  acc.merge(DecoratorAlgo)
242 
243  #Decorate eFEX SCs for ML
244  if 'eTOBsML' in args.outputs:
245  DecoratorAlgo = eFexTOBSuperCellDecoratorCfg(flags,'eFexTOBSuperCellDecorator')
246  acc.merge(DecoratorAlgo)
247 
248  # Uses SCell to decorate the gTowers
249  if 'gTowers' in args.outputs:
250  gTowerDecoratorAlgo = L1CaloGTowerDecoratorCfg(flags, 'gFexTower2SCellDecorator')
251  acc.merge(gTowerDecoratorAlgo)
252 
253 
254  # Saving containers
255  from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
256  log.debug('Adding the following output EDM to ItemList: %s', outputEDM)
257  acc.merge(OutputStreamCfg(flags, 'AOD', ItemList=outputEDM))
258 
259  acc.getEventAlgo("EventInfoTagBuilder").PropagateInput = (flags.Input.Format != Format.BS)
260 
261  if acc.run().isFailure():
262  sys.exit(1)
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
L1CaloFEXSimCfg.ReadSCellFromByteStreamCfg
def ReadSCellFromByteStreamCfg(flags, key='SCell', SCmask=True)
Definition: L1CaloFEXSimCfg.py:24
L1CaloFEXAlgosConfig.L1CalojFEXDecoratorCfg
def L1CalojFEXDecoratorCfg(flags, name="jFexTower2SCellDecorator", jTowersReadKey="L1_jFexDataTowers", ExtraInfo=False, SCMasking=True)
Definition: L1CaloFEXAlgosConfig.py:12
L1CaloFEXAlgosConfig.addEDM
def addEDM(edmType, edmName)
Definition: L1CaloFEXAlgosConfig.py:149
L1CaloFEXSimCfg.TriggerTowersInputCfg
def TriggerTowersInputCfg(flags)
Definition: L1CaloFEXSimCfg.py:64
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.OutputStreamConfig.OutputStreamCfg
def OutputStreamCfg(flags, streamName, ItemList=[], MetadataItemList=[], disableEventTag=False, trigNavThinningSvc=None, takeItemsFromInput=False, extendProvenanceRecord=True, AcceptAlgs=[], HelperTools=[])
Definition: OutputStreamConfig.py:12
L1CaloFEXAlgosConfig.eFexTOBSuperCellDecoratorCfg
def eFexTOBSuperCellDecoratorCfg(flags, name, eFexEMRoIContainer="L1_eEMRoI", eFexTauRoIContainer="L1_eTauxRoI")
Definition: L1CaloFEXAlgosConfig.py:64
python.ByteStreamConfig.ByteStreamReadCfg
def ByteStreamReadCfg(flags, type_names=None)
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:25
L1CaloFEXByteStreamConfig.jFexInputByteStreamToolCfg
def jFexInputByteStreamToolCfg(flags, name, *writeBS=False)
Definition: L1CaloFEXByteStreamConfig.py:232
python.DetectorConfigFlags.setupDetectorsFromList
def setupDetectorsFromList(flags, detectors, toggle_geometry=False, validate_only=False)
Definition: DetectorConfigFlags.py:354
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
L1CaloFEXByteStreamConfig.gFexByteStreamToolCfg
def gFexByteStreamToolCfg(flags, name, *writeBS=False)
Definition: L1CaloFEXByteStreamConfig.py:148
L1CaloFEXByteStreamConfig.gFexInputByteStreamToolCfg
def gFexInputByteStreamToolCfg(flags, name, *writeBS=False)
Definition: L1CaloFEXByteStreamConfig.py:275
L1CaloFEXAlgosConfig.eFexTOBDecoratorCfg
def eFexTOBDecoratorCfg(flags, name, eFexEMRoIContainer="L1_eEMRoI", eFexTauRoIContainer="L1_eTauRoI", ExtraInputs=[])
Definition: L1CaloFEXAlgosConfig.py:32
python.TrigConfigSvcCfg.L1ConfigSvcCfg
def L1ConfigSvcCfg(flags)
Definition: TrigConfigSvcCfg.py:198
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
L1CaloFEXByteStreamConfig.jFexRoiByteStreamToolCfg
def jFexRoiByteStreamToolCfg(flags, name, *writeBS=False, xTOBs=False)
Definition: L1CaloFEXByteStreamConfig.py:87
L1CaloFEXAlgosConfig.L1CaloGTowerDecoratorCfg
def L1CaloGTowerDecoratorCfg(flags, name, gTowersReadKey='L1_gFexDataTowers')
Definition: L1CaloFEXAlgosConfig.py:25
L1CaloFEXByteStreamConfig.eFexByteStreamToolCfg
def eFexByteStreamToolCfg(flags, name, *writeBS=False, TOBs=True, xTOBs=False, multiSlice=False, decodeInputs=False)
Definition: L1CaloFEXByteStreamConfig.py:8
Trk::split
@ split
Definition: LayerMaterialProperties.h:38