ATLAS Offline Software
Loading...
Searching...
No Matches
FexEmulatedTowersConfig.py
Go to the documentation of this file.
2# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3#
4
5from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6from AthenaConfiguration.ComponentFactory import CompFactory
7from AthenaConfiguration.Enums import Format
8
9def gFexEmulatedTowersCfg(flags, name="L1_gFexEmulatedTowers", writeKey="L1_gFexEmulatedTowers"):
10 """
11 Config for emulating gFex input data from LATOME readout
12 """
13 acc=ComponentAccumulator()
14
15 acc.addEventAlgo( CompFactory.LVL1.gFexTowerBuilder(name=name,
16 SCell=flags.Trigger.L1.L1CaloSuperCellContainerName,
17 gTowersWriteKey = writeKey,
18 isDATA = not flags.Input.isMC,
19 gFEX2SCmapping = "Run3L1CaloSimulation/L1CaloFEXAlgos/gFEX/gCaloTowers_to_scells_v1.txt",
20 gFEX2Tilemapping = "Run3L1CaloSimulation/L1CaloFEXAlgos/gFEX/gCaloTowers_to_tile_v1.txt",
21 gFexFiberTowerMapping = "Run3L1CaloSimulation/L1CaloFEXAlgos/gFEX/gFex_gCaloTowerMap_weighted_v1.txt") )
22 return acc
23
24def jFexEmulatedTowersCfg(flags, name="jFexEmulatedTowerMaker", writeKey="L1_jFexEmulatedTowers", SCin="", OfflineCaloCell=""):
25 """
26 Config for emulating jFex input data from LATOME readout
27 Supply SCin to build from non-standard SCell container
28 Supply OfflineCaloCell e.g. AllCalo to add offline cell energy decoration
29 """
30 acc=ComponentAccumulator()
31
32 emulator = CompFactory.LVL1.jFexEmulatedTowers(name)
33 emulator.SCell = flags.Trigger.L1.L1CaloSuperCellContainerName if not SCin else SCin
34 emulator.jTowersWriteKey = writeKey
35 emulator.isDATA = not flags.Input.isMC
36 # only set the necessary containers, tools, decorations for non empty OfflineCaloCell
37 emulator.CaloCell = OfflineCaloCell
38 emulator.CaloSuperCellIDTool = "CaloSuperCellIDTool" if OfflineCaloCell else ""
39 emulator.TileOfflineETKey = "CaloCellETByLayer" if (OfflineCaloCell and not flags.Input.isMC) else ""
40 emulator.CaloCellSumEtdecorKey = "CaloCellSumEt" if OfflineCaloCell else ""
41
42 acc.addEventAlgo(emulator)
43
44 return acc
45
46def eFexEmulatedTowersCfg(flags, name, writeKey = "L1_eFexEmulatedTowers"):
47 """
48 Config for emulating eFex input data from LATOME readout
49 """
50 acc=ComponentAccumulator()
51
52 emulator = CompFactory.LVL1.eFexTowerBuilder(name,ApplyMasking=not flags.Input.isMC)
53 emulator.eFexContainerWriteKey = writeKey
54 acc.addEventAlgo(emulator)
55
56 return acc
57
58
59if __name__ == '__main__':
60 from AthenaConfiguration.AllConfigFlags import initConfigFlags
61 from AthenaCommon.Logging import logging
62 import glob
63 import sys
64
65 import argparse
66 parser = argparse.ArgumentParser(prog='python -m L1CaloFEXAlgos.FexEmulatedTowersConfig',
67 description="""Emulator tools for FEX towers athena script.\n\n
68 Example: python -m L1CaloFEXAlgos.FexEmulatedTowersConfig --filesInput "data22*" --evtMax 10 --outputs jTowers """)
69 parser.add_argument('--evtMax',type=int,default=-1,help="number of events")
70 parser.add_argument('--filesInput',nargs='+',help="input files",required=True)
71 parser.add_argument('--outputs',nargs='+',choices={"jTowers","eTowers"},required=True, help="What data to decode and emulate")
72 parser.add_argument('--outputLevel',default="WARNING",choices={ 'INFO','WARNING','DEBUG','VERBOSE'})
73 args = parser.parse_args()
74
75
76 log = logging.getLogger('FexEmulatedTowersConfig')
77 log.setLevel(logging.DEBUG)
78
79 from AthenaCommon import Constants
80 algLogLevel = getattr(Constants,args.outputLevel)
81
82 flags = initConfigFlags()
83 if any(["data" in f for f in args.filesInput]):
84 flags.Trigger.triggerConfig='DB'
85
86 flags.Exec.OutputLevel = algLogLevel
87 flags.Exec.MaxEvents = args.evtMax
88 flags.Input.Files = [file for x in args.filesInput for file in glob.glob(x)]
89 flags.Concurrency.NumThreads = 1
90 flags.Concurrency.NumConcurrentEvents = 1
91
92 if not flags.Input.isMC:
93 from AthenaConfiguration.TestDefaults import defaultGeometryTags
94 flags.GeoModel.AtlasVersion = defaultGeometryTags.autoconfigure(flags)
95
96 if any(["data" in f for f in args.filesInput]):
97 s=args.filesInput[0].replace('*','').replace('.data','')
98 flags.Output.AODFileName = "AOD."+(s.split("/")[-1]).split('_SFO')[0]+"pool.root"
99 else:
100 flags.Output.AODFileName = 'AOD.pool.root'
101
102 flags.Trigger.EDMVersion = 3
103 flags.Trigger.doLVL1 = True
104 flags.Trigger.enableL1CaloPhase1 = True
105
106 # Enable only calo for this test
107 from AthenaConfiguration.DetectorConfigFlags import setupDetectorsFromList
108 setupDetectorsFromList(flags,['LAr','Tile','MBTS'],True)
109
110 flags.lock()
111
112
113 # Set up the main service "acc"
114 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
115 acc = MainServicesCfg(flags)
116
117 # The decoderAlg needs to load ByteStreamMetadata for the detector mask
118 from TriggerJobOpts.TriggerByteStreamConfig import ByteStreamReadCfg
119 acc.merge(ByteStreamReadCfg(flags))
120
121
122 # Generate run3 L1 menu
123 from TrigConfigSvc.TrigConfigSvcCfg import L1ConfigSvcCfg
124 acc.merge(L1ConfigSvcCfg(flags))
125
126 decoderTools = []
127 outputEDM = []
128 maybeMissingRobs = []
129
130 def addEDM(edmType, edmName):
131 auxType = edmType.replace('Container','AuxContainer')
132 return [f'{edmType}#{edmName}',
133 f'{auxType}#{edmName}Aux.']
134
135
136
139
140 # Decodes LATOME into SCell container
141 from L1CaloFEXSim.L1CaloFEXSimCfg import ReadSCellFromByteStreamCfg,TriggerTowersInputCfg
142 acc.merge(ReadSCellFromByteStreamCfg(flags))
143
144 # Creates the TriggerTower container
145 acc.merge(TriggerTowersInputCfg(flags))
146
147
148
151 if 'jTowers' in args.outputs:
152 acc.merge(jFexEmulatedTowersCfg(flags,'jFexEmulatedTowers'))
153 outputEDM += addEDM('xAOD::jFexTowerContainer', 'L1_jFexEmulatedTowers')
154
155 # decode any data towers for comparison with emulated
156 from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import jFexInputByteStreamToolCfg
157 inputjFexTool = acc.popToolsAndMerge(jFexInputByteStreamToolCfg(flags, 'jFexInputBSDecoder'))
158 for module_id in inputjFexTool.ROBIDs:
159 maybeMissingRobs.append(module_id)
160
161 decoderTools += [inputjFexTool]
162 # saving/adding the jTower xAOD container
163 outputEDM += addEDM('xAOD::jFexTowerContainer', inputjFexTool.jTowersWriteKey.Path)
164
165
168 if 'eTowers' in args.outputs:
169 acc.merge(eFexEmulatedTowersCfg(flags,'L1_eFexEmulatedTowers'))
170 outputEDM += addEDM('xAOD::eFexTowerContainer', 'L1_eFexEmulatedTowers')
171
172 # decode any data towers for comparison with emulated
173 from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import eFexByteStreamToolCfg
174 inputeFexTool = acc.popToolsAndMerge(eFexByteStreamToolCfg(
175 flags,'eFexBSDecoder',TOBs=False,xTOBs=False,decodeInputs=True))
176 for module_id in inputeFexTool.ROBIDs:
177 maybeMissingRobs.append(module_id)
178
179 decoderTools += [inputeFexTool]
180 # saving/adding the eTower xAOD container
181 outputEDM += addEDM('xAOD::eFexTowerContainer', 'L1_eFexDataTowers')
182
183 #
184 decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name="L1TriggerByteStreamDecoder",
185 DecoderTools=decoderTools, OutputLevel=algLogLevel,
186 MaybeMissingROBs=maybeMissingRobs)
187
188 acc.addEventAlgo(decoderAlg, sequenceName='AthAlgSeq')
189
190
191 # Saving containers
192 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
193 log.debug('Adding the following output EDM to ItemList: %s', outputEDM)
194 acc.merge(OutputStreamCfg(flags, 'AOD', ItemList=outputEDM))
195
196 acc.getEventAlgo("EventInfoTagBuilder").PropagateInput = (flags.Input.Format != Format.BS)
197
198 if acc.run().isFailure():
199 sys.exit(1)
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
eFexEmulatedTowersCfg(flags, name, writeKey="L1_eFexEmulatedTowers")
jFexEmulatedTowersCfg(flags, name="jFexEmulatedTowerMaker", writeKey="L1_jFexEmulatedTowers", SCin="", OfflineCaloCell="")
gFexEmulatedTowersCfg(flags, name="L1_gFexEmulatedTowers", writeKey="L1_gFexEmulatedTowers")