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  from L1CaloFEXSim.L1CaloFEXSimCfg import eFEXTOBEtToolCfg
40  acc.popToolsAndMerge(eFEXTOBEtToolCfg(flags))
41 
42  decorator = CompFactory.LVL1.eFexTOBDecorator(name, eFexEMRoIContainer = eFexEMRoIContainer, eFexTauRoIContainer = eFexTauRoIContainer)
43 
44  # in case the TOB containers are different from default we also have to change the write handles
45  if eFexEMRoIContainer != "L1_eEMRoI":
46  decorator.RetaCoreDecDecorKey = eFexEMRoIContainer+".RetaCoreDec"
47  decorator.RetaEnvDecDecorKey = eFexEMRoIContainer+".RetaEnvDec"
48  decorator.RetaEMDecDecorKey = eFexEMRoIContainer+".RhadEMDec"
49  decorator.RhadHadDecDecorKey = eFexEMRoIContainer+".RhadHadDec"
50  decorator.WstotDenDecDecorKey = eFexEMRoIContainer+".WstotDenDec"
51  decorator.WstotNumDecDecorKey = eFexEMRoIContainer+".WstotNumDec"
52  decorator.ClusterEtSumPSDecorKey = eFexEMRoIContainer+".ClusterEtSumPS"
53  decorator.ClusterEtSumL1DecorKey = eFexEMRoIContainer+".ClusterEtSumL1"
54  decorator.ClusterEtSumL2DecorKey = eFexEMRoIContainer+".ClusterEtSumL2"
55  decorator.ClusterEtSumL3DecorKey = eFexEMRoIContainer+".ClusterEtSumL3"
56 
57  if eFexEMRoIContainer != "L1_eTauRoI":
58  decorator.RCoreDecorKey = eFexTauRoIContainer+".RCoreDec"
59  decorator.REnvDecorKey = eFexTauRoIContainer+".REnvDec"
60  decorator.REMCoreDecorKey = eFexTauRoIContainer+".REMCoreDec"
61  decorator.REMHadDecorKey = eFexTauRoIContainer+".REMHadDec"
62 
63  decorator.ExtraInputs = ExtraInputs
64 
65  acc.addEventAlgo(decorator)
66 
67  return acc
68 
69 if __name__ == '__main__':
70  from AthenaConfiguration.AllConfigFlags import initConfigFlags
71  from AthenaCommon.Logging import logging
72  import glob
73  import sys
74 
75  import argparse
76  parser = argparse.ArgumentParser(prog='python -m L1CaloFEXAlgos.L1CaloFEXAlgosConfig',
77  description="""Decorator tool for FEX towers athena script.\n\n
78  Example: python -m L1CaloFEXAlgos.L1CaloFEXAlgosConfig --filesInput "data22*" --evtMax 10 --outputs eTOBs """)
79  parser.add_argument('--evtMax',type=int,default=-1,help="number of events")
80  parser.add_argument('--filesInput',nargs='+',help="input files",required=True)
81  parser.add_argument('--outputLevel',default="WARNING",choices={ 'INFO','WARNING','DEBUG','VERBOSE'})
82  parser.add_argument('--outputs',nargs='+',choices={"jTowers", "gTowers", "jTOBs","eTOBs"},required=True, help="What data to decode and output.")
83  args = parser.parse_args()
84 
85 
86  log = logging.getLogger('L1CaloFEXAlgosConfig')
87  log.setLevel(logging.DEBUG)
88 
89  from AthenaCommon import Constants
90  algLogLevel = getattr(Constants,args.outputLevel)
91 
92  flags = initConfigFlags()
93  if any(["data" in f for f in args.filesInput]):
94  flags.Trigger.triggerConfig='DB'
95 
96  flags.Exec.OutputLevel = algLogLevel
97  flags.Exec.MaxEvents = args.evtMax
98  flags.Input.Files = [file for x in args.filesInput for file in glob.glob(x)]
99  flags.Concurrency.NumThreads = 1
100  flags.Concurrency.NumConcurrentEvents = 1
101 
102  if not flags.Input.isMC:
103  from AthenaConfiguration.TestDefaults import defaultGeometryTags
104  flags.GeoModel.AtlasVersion = defaultGeometryTags.autoconfigure(flags)
105 
106  if any(["data" in f for f in args.filesInput]):
107  s=args.filesInput[0].replace('*','').replace('.data','')
108  flags.Output.AODFileName = "AOD."+(s.split("/")[-1]).split('_SFO')[0]+"pool.root"
109  else:
110  flags.Output.AODFileName = 'AOD.pool.root'
111 
112  flags.Trigger.EDMVersion = 3
113  flags.Trigger.doLVL1 = True
114  flags.Trigger.enableL1CaloPhase1 = True
115 
116  # Enable only calo for this test
117  from AthenaConfiguration.DetectorConfigFlags import setupDetectorsFromList
118  setupDetectorsFromList(flags,['LAr','Tile','MBTS'],True)
119 
120  flags.lock()
121 
122 
123  # Set up the main service "acc"
124  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
125  acc = MainServicesCfg(flags)
126 
127  # The decoderAlg needs to load ByteStreamMetadata for the detector mask
128  from TriggerJobOpts.TriggerByteStreamConfig import ByteStreamReadCfg
129  acc.merge(ByteStreamReadCfg(flags))
130 
131  # Generate run3 L1 menu
132  from TrigConfigSvc.TrigConfigSvcCfg import L1ConfigSvcCfg
133  acc.merge(L1ConfigSvcCfg(flags))
134 
135  decoderTools = []
136  outputEDM = []
137  maybeMissingRobs = []
138 
139  def addEDM(edmType, edmName):
140  auxType = edmType.replace('Container','AuxContainer')
141  return [f'{edmType}#{edmName}',
142  f'{auxType}#{edmName}Aux.']
143 
144 
147  if 'jTOBs' in args.outputs:
148  from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import jFexRoiByteStreamToolCfg
149  jFexTool = acc.popToolsAndMerge(jFexRoiByteStreamToolCfg(flags, 'jFexBSDecoder'))
150  for module_id in jFexTool.ROBIDs:
151  maybeMissingRobs.append(module_id)
152 
153  decoderTools += [jFexTool]
154 
155 
156 
159  if 'jTowers' in args.outputs:
160  inputjFexTool = acc.popToolsAndMerge(jFexInputByteStreamToolCfg(flags, 'jFexInputBSDecoder'))
161  for module_id in inputjFexTool.ROBIDs:
162  maybeMissingRobs.append(module_id)
163 
164  decoderTools += [inputjFexTool]
165  # saving/adding the jTower xAOD container
166  outputEDM += addEDM('xAOD::jFexTowerContainer', inputjFexTool.jTowersWriteKey.Path)
167 
168 
169 
172  if 'eTOBs' in args.outputs:
173  from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import eFexByteStreamToolCfg
174  eFexTool = acc.popToolsAndMerge(eFexByteStreamToolCfg(flags, 'eFexBSDecoder', TOBs=True, xTOBs=False, decodeInputs=False))
175  for module_id in eFexTool.ROBIDs:
176  maybeMissingRobs.append(module_id)
177 
178  decoderTools += [eFexTool]
179  # saving/adding EDM
180  outputEDM += addEDM('xAOD::eFexEMRoIContainer', eFexTool.eEMContainerWriteKey.Path)
181  outputEDM += addEDM('xAOD::eFexTauRoIContainer', eFexTool.eTAUContainerWriteKey.Path)
182 
183 
184  # Add the decoder tools
185  decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name="L1TriggerByteStreamDecoder",
186  DecoderTools=decoderTools, OutputLevel=algLogLevel, MaybeMissingROBs=maybeMissingRobs)
187  acc.addEventAlgo(decoderAlg, sequenceName='AthAlgSeq')
188 
189 
192  if 'gTOBs' in args.outputs:
193  from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import gFexByteStreamToolCfg
194  gFexTool = acc.popToolsAndMerge(gFexByteStreamToolCfg(flags, 'gFexBSDecoder'))
195  decoderTools += [gFexTool]
196 
197 
198 
201  if 'gTowers' in args.outputs:
202  inputgFexTool = acc.popToolsAndMerge(gFexInputByteStreamToolCfg(flags, 'gFexInputBSDecoder'))
203  decoderTools += [inputgFexTool]
204  # saving/adding the gTower xAOD container
205  outputEDM += addEDM('xAOD::gFexTowerContainer', inputgFexTool.gTowersWriteKey.Path)
206 
207  decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name="L1TriggerByteStreamDecoder",
208  DecoderTools=decoderTools, OutputLevel=algLogLevel)
209 
210  acc.addEventAlgo(decoderAlg, sequenceName='AthAlgSeq')
211 
212 
215 
216  # Decodes LATOME into SCell container
217  from L1CaloFEXSim.L1CaloFEXSimCfg import ReadSCellFromByteStreamCfg,TriggerTowersInputCfg
218  acc.merge(ReadSCellFromByteStreamCfg(flags))
219 
220  # Creates the TriggerTower container
221  acc.merge(TriggerTowersInputCfg(flags))
222 
223  # Uses SCell to decorate the jTowers (with extra info)
224  if 'jTowers' in args.outputs:
225  DecoratorAlgo = L1CalojFEXDecoratorCfg(flags, ExtraInfo = True)
226  acc.merge(DecoratorAlgo)
227 
228  # Decorate eFEX RoIs
229  if 'eTOBs' in args.outputs:
230  DecoratorAlgo = eFexTOBDecoratorCfg(flags,'eFexTOBDecorator')
231  acc.merge(DecoratorAlgo)
232 
233  # Uses SCell to decorate the gTowers
234  if 'gTowers' in args.outputs:
235  gTowerDecoratorAlgo = L1CaloGTowerDecoratorCfg(flags, 'gFexTower2SCellDecorator')
236  acc.merge(gTowerDecoratorAlgo)
237 
238 
239  # Saving containers
240  from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
241  log.debug('Adding the following output EDM to ItemList: %s', outputEDM)
242  acc.merge(OutputStreamCfg(flags, 'AOD', ItemList=outputEDM))
243 
244  acc.getEventAlgo("EventInfoTagBuilder").PropagateInput = (flags.Input.Format != Format.BS)
245 
246  if acc.run().isFailure():
247  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:139
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:351
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
L1CaloFEXByteStreamConfig.gFexByteStreamToolCfg
def gFexByteStreamToolCfg(flags, name, *writeBS=False)
Definition: L1CaloFEXByteStreamConfig.py:148
L1CaloFEXSimCfg.eFEXTOBEtToolCfg
def eFEXTOBEtToolCfg(flags)
Definition: L1CaloFEXSimCfg.py:47
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