3 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory
import CompFactory
5 from AthenaConfiguration.Enums
import Format
6 from TrigT1ResultByteStream.TrigT1ResultByteStreamConfig
import L1TriggerByteStreamDecoderCfg
7 from TrigConfigSvc.TrigConfigSvcCfg
import TrigConfigSvcCfg
8 from TriggerJobOpts.TriggerByteStreamConfig
import ByteStreamReadCfg
9 from TrigEDMConfig.TriggerEDM
import getTriggerEDMList
10 from TrigEDMConfig.Utils
import edmDictToList
11 from OutputStreamAthenaPool.OutputStreamConfig
import addToAOD, addToESD
13 from AthenaCommon.Logging
import logging
14 log = logging.getLogger(
'TriggerRecoConfig')
25 Configures trigger data decoding
27 HLTResultMTByteStreamDecoderAlg -> TriggerEDMDeserialiserAlg
30 TrigBSExtraction -> TrigDecisionMaker -> DecisionConv to xAOD -> NavigationConv to xAOD
33 as for Run 2 + Run 1 EDM to xAOD conversion
35 log.debug(
"TriggerRecoCfgData: Preparing the trigger handling of reconstruction of data")
38 if flags.Trigger.L1.doMuon
or flags.Trigger.L1.doCalo
or flags.Trigger.L1.doTopo
or flags.Trigger.L1.doCTP:
42 acc.merge( metadataAcc )
45 if flags.Trigger.EDMVersion >= 3:
48 from TrigDecisionMaker.TrigDecisionMakerConfig
import Run3DecisionMakerCfg
51 if flags.Trigger.doNavigationSlimming:
52 from TrigNavSlimmingMT.TrigNavSlimmingMTConfig
import TrigNavSlimmingMTCfg
56 elif flags.Trigger.EDMVersion
in [1, 2]:
59 from TrigDecisionMaker.TrigDecisionMakerConfig
import Run1Run2DecisionMakerCfg
64 raise RuntimeError(
"Invalid EDMVersion=%s " % flags.Trigger.EDMVersion)
67 if flags.Trigger.enableL1CaloLegacy:
68 from AnalysisTriggerAlgs.AnalysisTriggerAlgsConfig
import RoIBResultToxAODCfg
70 acc.merge( xRoIBResultAcc )
72 if flags.Input.Format
is Format.BS
and flags.Input.DataYear < 2024:
73 from L1TopoByteStream.L1TopoByteStreamConfig
import L1TopoRawDataContainerBSCnvCfg
75 topoEDM = [
'xAOD::L1TopoRawDataContainer#L1TopoRawData',
76 'xAOD::L1TopoRawDataAuxContainer#L1TopoRawDataAux.']
86 Configures trigger MC handing during reconstruction
87 Note that a lot of the T0 handling of the trigger output for data is bundled into
88 the RDO to RDO_TRIG sub-step for MC, hence there is much less to do here for MC.
89 Notably: the xAOD::TrigDecision and all metadata should already be in the RDO_TRIG.
92 Propagation of Run 3 HLT collections from input RDO_TRIG to output POOL files.
93 Execution of Run-3 reconstruction-level trigger navigation slimming.
96 Propagation of Run 2 HLT collections from input RDO_TRIG to output POOL files.
97 Execution of Run 2 style reconstruction-level trigger navigation slimming.
98 Optional conversion of Run 2 navigation to Run 3 navigation.
99 Optional execution of Run 3 reconstruction-level trigger navigation slimming on conversion output.
102 No current workflows are able to run the Run 1 trigger MC simulation. Unsupported.
103 Work would be needed here to do the xAOD conversion (see Run1xAODConversionCfg for how this is done for data)
107 if flags.Input.Format
is Format.BS:
108 log.warning(
"TriggerRecoCfgMC does not currently support MC files encoded as bytestream. Switching off handling of trigger inputs.")
110 if flags.Trigger.EDMVersion == 1:
111 log.warning(
"TriggerRecoCfgMC does not currently support MC files with Run 1 trigger payload. Switching off handling of trigger inputs.")
114 log.debug(
"TriggerRecoCfgMC: Preparing the trigger handling of reconstruction of MC")
121 from TrigNavTools.NavConverterConfig
import NavConverterCfg
125 from TrigNavSlimmingMT.TrigNavSlimmingMTConfig
import TrigNavSlimmingMTCfg
133 """Sets up access to HLT, L1, BGRP, Monitoring, HLT PS and L1 PS JSON files from 'FILE' or 'DB', writes JSON to metaStore and keys to eventStore"""
136 if flags.Trigger.triggerConfig !=
'INFILE':
138 keyWriterTool = CompFactory.TrigConf.KeyWriterTool(
"KeyWriterToolOffline")
139 keyWriterOutput =
str(keyWriterTool.ConfKeys)
140 acc.addEventAlgo( CompFactory.TrigConf.xAODMenuWriter(
"xAODMenuWriter", KeyWriterTool = keyWriterTool) )
141 return acc, keyWriterOutput
144 """Configures which trigger collections are recorded"""
148 if flags.Output.doWriteESD
is False and flags.Output.doWriteAOD
is False:
149 log.debug(
"TriggerEDMCfg: Nothing to do as both Output.doWriteAOD and Output.doWriteESD are False")
155 menuMetadata = [
"xAOD::TriggerMenuJsonContainer#*",
"xAOD::TriggerMenuJsonAuxContainer#*",]
156 if flags.Trigger.EDMVersion
in [1,2]:
157 menuMetadata += [
'xAOD::TriggerMenuAuxContainer#*',
'xAOD::TriggerMenuContainer#*',]
159 from TrigEDMConfig.TriggerEDM
import getLvl1ESDList, getLvl1AODList
163 edmVersion =
max(2, flags.Trigger.EDMVersion)
164 _TriggerESDList =
getTriggerEDMList(flags, key=flags.Trigger.ESDEDMSet, runVersion=edmVersion)
165 _TriggerAODList =
getTriggerEDMList(flags, key=flags.Trigger.AODEDMSet, runVersion=edmVersion)
166 log.debug(
"ESD EDM list: %s", _TriggerESDList)
167 log.debug(
"AOD EDM list: %s", _TriggerAODList)
173 not_in = [ element
for element
in _TriggerAODList
if element
not in _TriggerESDList ]
175 log.warning(
"In AOD list but not in ESD list: ")
178 log.info(
"AOD list is subset of ESD list - good.")
184 log.info(
"AOD content set according to the AODEDMSet flag: %s and EDM version %d", flags.Trigger.AODEDMSet, flags.Trigger.EDMVersion)
186 if flags.Trigger.EDMVersion == 3
and not flags.Trigger.doOnlineNavigationCompactification
and not flags.Trigger.doNavigationSlimming:
187 nav = [
'xAOD::TrigCompositeContainer#HLTNav*',
'xAOD::TrigCompositeAuxContainer#HLTNav*',]
191 jetSpecials = [
"JetKeyDescriptor#JetKeyMap",
"JetMomentMap#TrigJetRecMomentMap",]
192 acc.merge(
addToESD(flags, jetSpecials))
193 acc.merge(
addToAOD(flags, jetSpecials))
196 if flags.Output.doWriteAOD
and flags.Trigger.EDMVersion == 2:
197 from TrigRoiConversion.TrigRoiConversionConfig
import RoiWriterCfg
203 """Configures legacy Run1/2 navigation slimming"""
206 if flags.Trigger.decodeHLT
is False:
207 log.debug(
"Run2Run1NavigationSlimmingCfg: Nothing to do as Trigger.decodeHLT is False")
210 if flags.Trigger.doNavigationSlimming
is False:
211 log.debug(
"Run2Run1NavigationSlimmingCfg: Nothing to do as Trigger.doNavigationSlimming is False")
214 if flags.Trigger.EDMVersion >= 3:
215 log.debug(
"Run2Run1NavigationSlimmingCfg: Nothing to do for EDMVersion >= 3.")
218 if flags.Trigger.ExtraEDMList:
219 log.warning(
"Run2Run1NavigationSlimmingCfg: ExtraEDMList only works for Run 3 and beyond")
222 return list(y.split(
'-')[0]
for x
in edm.values()
for y
in x)
223 from TrigNavTools.TrigNavToolsConfig
import TrigNavigationThinningSvcCfg
225 from OutputStreamAthenaPool.OutputStreamConfig
import OutputStreamCfg
227 if flags.Output.doWriteAOD:
230 {
'name' :
'HLTNav_StreamAOD',
231 'mode' :
'cleanup_noreload',
232 'result' :
'HLTResult_HLT',
233 'features' :
_flatten(_TriggerAODList)}))
234 acc.merge(
OutputStreamCfg(flags,
"AOD", trigNavThinningSvc = thinningSvc))
236 if flags.Output.doWriteESD:
239 {
'name' :
'HLTNav_StreamESD',
240 'mode' :
'cleanup_noreload',
241 'result' :
'HLTResult_HLT',
242 'features' :
_flatten(_TriggerESDList)}))
243 acc.merge(
OutputStreamCfg(flags,
"ESD", trigNavThinningSvc = thinningSvc))
249 """Configures Trigger data from BS extraction """
250 from SGComps.AddressRemappingConfig
import InputRenameCfg
253 extr = CompFactory.TrigBSExtraction()
257 extr.ExtraOutputs.add((
"TrigBSExtractionOutput",
"StoreGateSvc+TrigBSExtractionOutput"))
259 if flags.Trigger.decodeHLT:
261 if flags.Trigger.EDMVersion == 1
and flags.Trigger.doxAODConversion:
264 serialiserTool = CompFactory.TrigTSerializer()
265 acc.addPublicTool(serialiserTool)
266 extr.NavigationForL2 = CompFactory.HLT.Navigation(
"NavigationForL2",
267 ClassesFromPayloadIgnore = [
"TrigPassBits#passbits"])
269 extr.Navigation = CompFactory.HLT.Navigation(
"Navigation")
270 from TrigEDMConfig.TriggerEDM
import getEDMLibraries
272 from TrigEDMConfig.TriggerEDM
import getPreregistrationList
273 extr.Navigation.ClassesToPreregister =
getPreregistrationList(flags.Trigger.EDMVersion, flags.Trigger.doxAODConversion)
274 from eformat
import helper
as efh
276 if flags.Trigger.EDMVersion == 1:
277 acc.merge(
InputRenameCfg(
"HLT::HLTResult",
"HLTResult_L2",
"HLTResult_L2_BS"))
278 acc.merge(
InputRenameCfg(
"HLT::HLTResult",
"HLTResult_EF",
"HLTResult_EF_BS"))
279 robIDMap[
"HLTResult_L2_BS"] = efh.SourceIdentifier(efh.SubDetector.TDAQ_LVL2, 0).
code()
280 robIDMap[
"HLTResult_EF_BS"] = efh.SourceIdentifier(efh.SubDetector.TDAQ_EVENT_FILTER, 0).
code()
281 extr.L2ResultKeyIn =
"HLTResult_L2_BS"
282 extr.L2ResultKeyOut =
"HLTResult_L2"
283 extr.HLTResultKeyIn =
"HLTResult_EF_BS"
284 extr.HLTResultKeyOut =
"HLTResult_EF"
286 acc.merge(
InputRenameCfg(
"HLT::HLTResult",
"HLTResult_HLT",
"HLTResult_HLT_BS"))
287 robIDMap[
"HLTResult_HLT_BS"] = efh.SourceIdentifier(efh.SubDetector.TDAQ_HLT, 0).
code()
288 extr.HLTResultKeyIn =
"HLTResult_HLT_BS"
289 extr.HLTResultKeyOut =
"HLTResult_HLT"
292 if flags.Trigger.EDMVersion == 2:
293 stream = flags.Input.TriggerStream
294 if stream.startswith(
'calibration_DataScouting_'):
295 ds_tag =
'_'.
join(stream.split(
'_')[1:3])
296 ds_id =
int(stream.split(
'_')[2])
298 robIDMap[ds_tag+
"_BS"] = efh.SourceIdentifier(efh.SubDetector.TDAQ_HLT, ds_id).
code()
299 extr.DSResultKeysIn += [ ds_tag+
"_BS" ]
300 extr.DSResultKeysOut += [ ds_tag ]
303 log.info(
"Will not schedule real HLT bytestream extraction, instead EDM gap filling is running")
306 extr.HLTResultKeyIn =
""
307 extr.HLTResultKeyOut =
""
309 HLTResults = [ f
"HLT::HLTResult/{k}" for k
in robIDMap.keys() ]
310 acc.addService( CompFactory.ByteStreamAddressProviderSvc( TypeNames = HLTResults) )
312 from TrigEDMConfig.TriggerEDM
import getTPList
313 acc.addPublicTool( CompFactory.TrigSerTPTool(TPMap =
getTPList((flags.Trigger.EDMVersion))) )
315 acc.addPublicTool( CompFactory.TrigSerializeConvHelper(doTP =
True) )
317 acc.addPublicTool( CompFactory.HLT.HLTResultByteStreamTool(HLTResultRobIdMap = robIDMap))
319 acc.addEventAlgo(extr)
324 """Convert Run 1 EDM collections to xAOD classes"""
327 log.info(
"Will configure Run 1 trigger EDM to xAOD conversion")
328 from TrigEDMConfig.TriggerEDM
import getEFRun1BSList,getEFRun2EquivalentList,getL2Run1BSList,getL2Run2EquivalentList
330 from TrkConfig.TrkParticleCreatorConfig
import TrackParticleCreatorToolCfg
335 acc.addPublicTool(partCreatorTool)
337 from xAODTrackingCnv.xAODTrackingCnvConfig
import TrackCollectionCnvToolCfg,RecTrackParticleContainerCnvToolCfg
339 name=
"TrackCollectionCnvTool",
340 TrackParticleCreator= partCreatorTool
345 name=
"RecParticleCnv",
346 TrackParticleCreator=partCreatorTool
350 bstoxaodTool = CompFactory.TrigBStoxAODTool(
"BStoxAOD",
353 TrackCollectionCnvTool = trackCollCnvTool,
354 TrackParticleContainerCnvTool = recPartCnvTool
356 acc.setPrivateTools(bstoxaodTool)
365 """Configures conversions BS -> HLTResultMT -> Collections """
368 if flags.Trigger.decodeHLT
is False:
369 log.debug(
"Run3TriggerBSUnpackingCfg: Nothing to do as Trigger.decodeHLT is False")
372 from AthenaCommon.CFElements
import seqAND
373 from TrigEDMConfig.DataScoutingInfo
import (
374 getDataScoutingStreams, getDataScoutingTypeFromStream,
375 getFullHLTResultID, getDataScoutingResultID,
377 from TriggerJobOpts.TriggerConfig
import triggerEDMGapFillerCfg
378 from TrigDecisionTool.TrigDecisionToolConfig
import getRun3NavigationContainerFromInput
385 log.info(f
'Configuring BS decoding/deserialisation of HLT result for \'{dstype}\' only')
394 log.debug(
'Configuring BS decoding of all HLT results and deserialisation of full HLT')
395 partialHLT_streams = [
398 partialHLT_dstypes = [
404 log.debug(f
'Configuring BS decoding and deserialisation of all HLT results: full HLT + {partialHLT_dstypes}')
406 ids_to_decode += partialHLT_dsids
408 id_to_deserialise.update({
409 dstype:dsid
for dstype,dsid
in zip(partialHLT_dstypes, partialHLT_dsids)
412 decoder = CompFactory.HLTResultMTByteStreamDecoderAlg(ModuleIdsToDecode=ids_to_decode)
413 acc.addSequence(
seqAND(
"HLTDecodingSeq"))
414 acc.addEventAlgo( decoder,
"HLTDecodingSeq")
415 for dstype, id
in id_to_deserialise.items():
416 deserialiser = CompFactory.TriggerEDMDeserialiserAlg(
417 f
"TrigDeserialiser{dstype}",
422 deserialiser.ExtraOutputs.add((
'xAOD::TrigCompositeContainer' ,
'StoreGateSvc+DummyForGapFiller'))
424 deserialiser.SkipDuplicateRecords =
True
425 deserialiser.PermitMissingModule =
True
426 acc.addEventAlgo( deserialiser,
"HLTDecodingSeq")
432 flags, edmSet=[
'BS'],
433 extraInputs=[(
'xAOD::TrigCompositeContainer' ,
'StoreGateSvc+DummyForGapFiller')],
435 'xAOD::TrigCompositeContainer',
441 acc.merge( gapFiller,
"HLTDecodingSeq" )
443 log.debug(
"Configured HLT result BS decoding sequence")
447 if __name__ ==
'__main__':
448 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
449 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
452 args = flags.fillFromArgs()
454 if not args.filesInput:
455 from AthenaConfiguration.TestDefaults
import defaultTestFiles
456 flags.Input.Files = defaultTestFiles.RAW_RUN3
457 flags.Exec.MaxEvents = 5
458 log.info(
'Checking setup for EDMVersion %d with default input files', flags.Trigger.EDMVersion)
459 if flags.Trigger.EDMVersion==1:
460 flags.Input.Files = defaultTestFiles.RAW_RUN1
461 elif flags.Trigger.EDMVersion==2:
462 flags.Input.Files = defaultTestFiles.RAW_RUN2
463 elif flags.Trigger.EDMVersion==3:
464 flags.Input.Files = defaultTestFiles.RAW_RUN3
466 from AthenaConfiguration.TestDefaults
import defaultGeometryTags
467 flags.GeoModel.AtlasVersion = defaultGeometryTags.autoconfigure(flags)
473 if log.getEffectiveLevel() <= logging.DEBUG:
474 acc.printConfig(withDetails=
True)
477 sys.exit(acc.run().isFailure())