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 
33 
34 if __name__ == '__main__':
35  from AthenaConfiguration.AllConfigFlags import initConfigFlags
36  from AthenaCommon.Logging import logging
37  import glob
38  import sys
39 
40  import argparse
41  parser = argparse.ArgumentParser(prog='python -m L1CaloFEXAlgos.L1CaloFEXAlgosConfig',
42  description="""Decorator tool for FEX towers athena script.\n\n
43  Example: python -m L1CaloFEXAlgos.L1CaloFEXAlgosConfig --filesInput "data22*" --evtMax 10 --outputs eTOBs """)
44  parser.add_argument('--evtMax',type=int,default=-1,help="number of events")
45  parser.add_argument('--filesInput',nargs='+',help="input files",required=True)
46  parser.add_argument('--outputLevel',default="WARNING",choices={ 'INFO','WARNING','DEBUG','VERBOSE'})
47  parser.add_argument('--outputs',nargs='+',choices={"jTowers", "gTowers", "jTOBs","eTOBs", "eTOBsML"},required=True, help="What data to decode and output.")
48  args = parser.parse_args()
49 
50 
51  log = logging.getLogger('L1CaloFEXAlgosConfig')
52  log.setLevel(logging.DEBUG)
53 
54  from AthenaCommon import Constants
55  algLogLevel = getattr(Constants,args.outputLevel)
56 
57  flags = initConfigFlags()
58  if any(["data" in f for f in args.filesInput]):
59  flags.Trigger.triggerConfig='DB'
60 
61  flags.Exec.OutputLevel = algLogLevel
62  flags.Exec.MaxEvents = args.evtMax
63  flags.Input.Files = [file for x in args.filesInput for file in glob.glob(x)]
64  flags.Concurrency.NumThreads = 1
65  flags.Concurrency.NumConcurrentEvents = 1
66 
67  if not flags.Input.isMC:
68  from AthenaConfiguration.TestDefaults import defaultGeometryTags
69  flags.GeoModel.AtlasVersion = defaultGeometryTags.autoconfigure(flags)
70 
71  if any(["data" in f for f in args.filesInput]):
72  s=args.filesInput[0].replace('*','').replace('.data','')
73  flags.Output.AODFileName = "AOD."+(s.split("/")[-1]).split('_SFO')[0]+"pool.root"
74  else:
75  flags.Output.AODFileName = 'AOD.pool.root'
76 
77  flags.Trigger.EDMVersion = 3
78  flags.Trigger.doLVL1 = True
79  flags.Trigger.enableL1CaloPhase1 = True
80 
81  # Enable only calo for this test
82  from AthenaConfiguration.DetectorConfigFlags import setupDetectorsFromList
83  setupDetectorsFromList(flags,['LAr','Tile','MBTS'],True)
84 
85  flags.lock()
86 
87 
88  # Set up the main service "acc"
89  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
90  acc = MainServicesCfg(flags)
91 
92  # The decoderAlg needs to load ByteStreamMetadata for the detector mask
93  from TriggerJobOpts.TriggerByteStreamConfig import ByteStreamReadCfg
94  acc.merge(ByteStreamReadCfg(flags))
95 
96  # Generate run3 L1 menu
97  from TrigConfigSvc.TrigConfigSvcCfg import L1ConfigSvcCfg
98  acc.merge(L1ConfigSvcCfg(flags))
99 
100  decoderTools = []
101  outputEDM = []
102  maybeMissingRobs = []
103 
104  def addEDM(edmType, edmName):
105  auxType = edmType.replace('Container','AuxContainer')
106  return [f'{edmType}#{edmName}',
107  f'{auxType}#{edmName}Aux.']
108 
109 
112  if 'jTOBs' in args.outputs:
113  from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import jFexRoiByteStreamToolCfg
114  jFexTool = acc.popToolsAndMerge(jFexRoiByteStreamToolCfg(flags, 'jFexBSDecoder'))
115  for module_id in jFexTool.ROBIDs:
116  maybeMissingRobs.append(module_id)
117 
118  decoderTools += [jFexTool]
119 
120 
121 
124  if 'jTowers' in args.outputs:
125  inputjFexTool = acc.popToolsAndMerge(jFexInputByteStreamToolCfg(flags, 'jFexInputBSDecoder'))
126  for module_id in inputjFexTool.ROBIDs:
127  maybeMissingRobs.append(module_id)
128 
129  decoderTools += [inputjFexTool]
130  # saving/adding the jTower xAOD container
131  outputEDM += addEDM('xAOD::jFexTowerContainer', inputjFexTool.jTowersWriteKey.Path)
132 
133 
134 
137  if 'eTOBs' in args.outputs:
138  from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import eFexByteStreamToolCfg
139  eFexTool = acc.popToolsAndMerge(eFexByteStreamToolCfg(flags, 'eFexBSDecoder', TOBs=True, xTOBs=False, decodeInputs=False))
140  for module_id in eFexTool.ROBIDs:
141  maybeMissingRobs.append(module_id)
142 
143  decoderTools += [eFexTool]
144  # saving/adding EDM
145  outputEDM += addEDM('xAOD::eFexEMRoIContainer', eFexTool.eEMContainerWriteKey.Path)
146  outputEDM += addEDM('xAOD::eFexTauRoIContainer', eFexTool.eTAUContainerWriteKey.Path)
147 
148 
149  # Add the decoder tools
150  decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name="L1TriggerByteStreamDecoder",
151  DecoderTools=decoderTools, OutputLevel=algLogLevel, MaybeMissingROBs=maybeMissingRobs)
152  acc.addEventAlgo(decoderAlg, sequenceName='AthAlgSeq')
153 
154 
157  if 'gTOBs' in args.outputs:
158  from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import gFexByteStreamToolCfg
159  gFexTool = acc.popToolsAndMerge(gFexByteStreamToolCfg(flags, 'gFexBSDecoder'))
160  decoderTools += [gFexTool]
161 
162 
163 
166  if 'gTowers' in args.outputs:
167  inputgFexTool = acc.popToolsAndMerge(gFexInputByteStreamToolCfg(flags, 'gFexInputBSDecoder'))
168  decoderTools += [inputgFexTool]
169  # saving/adding the gTower xAOD container
170  outputEDM += addEDM('xAOD::gFexTowerContainer', inputgFexTool.gTowersWriteKey.Path)
171 
172  decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name="L1TriggerByteStreamDecoder",
173  DecoderTools=decoderTools, OutputLevel=algLogLevel)
174 
175  acc.addEventAlgo(decoderAlg, sequenceName='AthAlgSeq')
176 
177 
180 
181  # Decodes LATOME into SCell container
182  from L1CaloFEXSim.L1CaloFEXSimCfg import ReadSCellFromByteStreamCfg,TriggerTowersInputCfg
183  acc.merge(ReadSCellFromByteStreamCfg(flags))
184 
185  # Creates the TriggerTower container
186  acc.merge(TriggerTowersInputCfg(flags))
187 
188  # Uses SCell to decorate the jTowers (with extra info)
189  if 'jTowers' in args.outputs:
190  DecoratorAlgo = L1CalojFEXDecoratorCfg(flags, ExtraInfo = True)
191  acc.merge(DecoratorAlgo)
192 
193  # Decorate eFEX RoIs
194  if 'eTOBs' in args.outputs:
195  acc.addEventAlgo( CompFactory.LVL1.eFexTOBDecorator('eFexTOBDecorator') )
196 
197  #Decorate eFEX SCs for ML
198  if 'eTOBsML' in args.outputs:
199  acc.addEventAlgo( CompFactory.LVL1.eFexTOBDecorator('eFexTOBSuperCellDecorator') )
200 
201  # Uses SCell to decorate the gTowers
202  if 'gTowers' in args.outputs:
203  gTowerDecoratorAlgo = L1CaloGTowerDecoratorCfg(flags, 'gFexTower2SCellDecorator')
204  acc.merge(gTowerDecoratorAlgo)
205 
206 
207  # Saving containers
208  from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
209  log.debug('Adding the following output EDM to ItemList: %s', outputEDM)
210  acc.merge(OutputStreamCfg(flags, 'AOD', ItemList=outputEDM))
211 
212  acc.getEventAlgo("EventInfoTagBuilder").PropagateInput = (flags.Input.Format != Format.BS)
213 
214  if acc.run().isFailure():
215  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:104
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
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
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