ATLAS Offline Software
Loading...
Searching...
No Matches
MTCalibPebConfig.py
Go to the documentation of this file.
2# Copyright (C) 2002-2026 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
8from AthenaCommon.CFElements import seqOR, parOR
9from AthenaCommon.Logging import logging
10log = logging.getLogger('MTCalibPebConfig.py')
11
12_menu_name = 'MTCalibPeb'
13_menu_file_name = 'HLTMenu_{:s}.json'.format(_menu_name)
14
15# LAR-EMB* ROBs from the file
16# /cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/TrigP1Test/ATLASros2rob2018-r22format.py
17rob_list = [
18 0x420024, 0x420025, 0x420026, 0x420027, 0x420034, 0x420035, 0x420036, 0x420037,
19 0x42005c, 0x42005d, 0x42005e, 0x42005f, 0x42006c, 0x42006d, 0x42006e, 0x42006f,
20 0x42000c, 0x42000d, 0x420001, 0x42000f, 0x420014, 0x420015, 0x420016, 0x420017,
21 0x42001c, 0x42001d, 0x420030, 0x420031, 0x420002, 0x420003, 0x420011, 0x420013,
22 0x420018, 0x420019, 0x42001a, 0x42001b, 0x42001e, 0x42001f, 0x420032, 0x420033,
23 0x420004, 0x420005, 0x420006, 0x420007, 0x420000, 0x42000e, 0x420020, 0x420021,
24 0x420028, 0x420029, 0x42002c, 0x42002d, 0x420008, 0x420009, 0x42000a, 0x42000b,
25 0x420010, 0x420012, 0x420022, 0x420023, 0x42002a, 0x42002b, 0x42002e, 0x42002f,
26 0x41003c, 0x41003d, 0x41003e, 0x41003f, 0x410038, 0x410046, 0x410058, 0x410059,
27 0x410060, 0x410061, 0x410064, 0x410065, 0x410040, 0x410041, 0x410042, 0x410043,
28 0x410048, 0x41004a, 0x41005a, 0x41005b, 0x410062, 0x410063, 0x410066, 0x410067,
29 0x41007c, 0x41007d, 0x410071, 0x41007f, 0x410084, 0x410085, 0x410086, 0x410087,
30 0x41008c, 0x41008d, 0x4100a0, 0x4100a1, 0x410072, 0x410073, 0x410081, 0x410083,
31 0x410088, 0x410089, 0x41008a, 0x41008b, 0x41008e, 0x41008f, 0x4100a2, 0x4100a3,
32 0x410074, 0x410075, 0x410076, 0x410077, 0x410070, 0x41007e, 0x410090, 0x410091,
33 0x410098, 0x410099, 0x41009c, 0x41009d, 0x410078, 0x410079, 0x41007a, 0x41007b,
34 0x410080, 0x410082, 0x410092, 0x410093, 0x41009a, 0x41009b, 0x41009e, 0x41009f,
35 0x410094, 0x410095, 0x410096, 0x410097, 0x4100a4, 0x4100a5, 0x4100a6, 0x4100a7,
36 0x4100cc, 0x4100cd, 0x4100ce, 0x4100cf, 0x4100dc, 0x4100dd, 0x4100de, 0x4100df,
37 0x41000c, 0x41000d, 0x410001, 0x41000f, 0x410014, 0x410015, 0x410016, 0x410017,
38 0x41001c, 0x41001d, 0x410030, 0x410031, 0x410002, 0x410003, 0x410011, 0x410013,
39 0x410018, 0x410019, 0x41001a, 0x41001b, 0x41001e, 0x41001f, 0x410032, 0x410033,
40 0x410004, 0x410005, 0x410006, 0x410007, 0x410000, 0x41000e, 0x410020, 0x410021,
41 0x410028, 0x410029, 0x41002c, 0x41002d, 0x410008, 0x410009, 0x41000a, 0x41000b,
42 0x410010, 0x410012, 0x410022, 0x410023, 0x41002a, 0x41002b, 0x41002e, 0x41002f,
43 0x410024, 0x410025, 0x410026, 0x410027, 0x410034, 0x410035, 0x410036, 0x410037,
44 0x41005c, 0x41005d, 0x41005e, 0x41005f, 0x41006c, 0x41006d, 0x41006e, 0x41006f,
45 0x410044, 0x410045, 0x410039, 0x410047, 0x41004c, 0x41004d, 0x41004e, 0x41004f,
46 0x410054, 0x410055, 0x410068, 0x410069, 0x41003a, 0x41003b, 0x410049, 0x41004b,
47 0x410050, 0x410051, 0x410052, 0x410053, 0x410056, 0x410057, 0x41006a, 0x41006b,
48 0x4100b4, 0x4100b5, 0x4100a9, 0x4100b7, 0x4100bc, 0x4100bd, 0x4100be, 0x4100bf,
49 0x4100c4, 0x4100c5, 0x4100d8, 0x4100d9, 0x4100aa, 0x4100ab, 0x4100b9, 0x4100bb,
50 0x4100c0, 0x4100c1, 0x4100c2, 0x4100c3, 0x4100c6, 0x4100c7, 0x4100da, 0x4100db,
51 0x4100ac, 0x4100ad, 0x4100ae, 0x4100af, 0x4100a8, 0x4100b6, 0x4100c8, 0x4100c9,
52 0x4100d0, 0x4100d1, 0x4100d4, 0x4100d5, 0x4100b0, 0x4100b1, 0x4100b2, 0x4100b3,
53 0x4100b8, 0x4100ba, 0x4100ca, 0x4100cb, 0x4100d2, 0x4100d3, 0x4100d6, 0x4100d7,
54 0x420044, 0x420045, 0x420039, 0x420047, 0x42004c, 0x42004d, 0x42004e, 0x42004f,
55 0x420054, 0x420055, 0x420068, 0x420069, 0x42003a, 0x42003b, 0x420049, 0x42004b,
56 0x420050, 0x420051, 0x420052, 0x420053, 0x420056, 0x420057, 0x42006a, 0x42006b,
57 0x420074, 0x420075, 0x420076, 0x420077, 0x420070, 0x42007e, 0x420090, 0x420091,
58 0x420098, 0x420099, 0x42009c, 0x42009d, 0x420078, 0x420079, 0x42007a, 0x42007b,
59 0x420080, 0x420082, 0x420092, 0x420093, 0x42009a, 0x42009b, 0x42009e, 0x42009f,
60 0x420094, 0x420095, 0x420096, 0x420097, 0x4200a4, 0x4200a5, 0x4200a6, 0x4200a7,
61 0x4200cc, 0x4200cd, 0x4200ce, 0x4200cf, 0x4200dc, 0x4200dd, 0x4200de, 0x4200df,
62 0x42003c, 0x42003d, 0x42003e, 0x42003f, 0x420038, 0x420046, 0x420058, 0x420059,
63 0x420060, 0x420061, 0x420064, 0x420065, 0x420040, 0x420041, 0x420042, 0x420043,
64 0x420048, 0x42004a, 0x42005a, 0x42005b, 0x420062, 0x420063, 0x420066, 0x420067,
65 0x42007c, 0x42007d, 0x420071, 0x42007f, 0x420084, 0x420085, 0x420086, 0x420087,
66 0x42008c, 0x42008d, 0x4200a0, 0x4200a1, 0x420072, 0x420073, 0x420081, 0x420083,
67 0x420088, 0x420089, 0x42008a, 0x42008b, 0x42008e, 0x42008f, 0x4200a2, 0x4200a3,
68 0x4200b4, 0x4200b5, 0x4200a9, 0x4200b7, 0x4200bc, 0x4200bd, 0x4200be, 0x4200bf,
69 0x4200c4, 0x4200c5, 0x4200d8, 0x4200d9, 0x4200aa, 0x4200ab, 0x4200b9, 0x4200bb,
70 0x4200c0, 0x4200c1, 0x4200c2, 0x4200c3, 0x4200c6, 0x4200c7, 0x4200da, 0x4200db,
71 0x4200ac, 0x4200ad, 0x4200ae, 0x4200af, 0x4200a8, 0x4200b6, 0x4200c8, 0x4200c9,
72 0x4200d0, 0x4200d1, 0x4200d4, 0x4200d5, 0x4200b0, 0x4200b1, 0x4200b2, 0x4200b3,
73 0x4200b8, 0x4200ba, 0x4200ca, 0x4200cb, 0x4200d2, 0x4200d3, 0x4200d6, 0x4200d7,
74]
75
76rob_access_dict = {
77 '01 :GET:RND20:': rob_list, # Retrieve 20 random ROBs from rob_list
78 '02 :GET:RND10:': rob_list, # Retrieve 10 random ROBs from rob_list
79 '03 :GET:RND5:': rob_list, # Retrieve 5 random ROBs from rob_list
80 '04 :GET:RND10:': rob_list, # Retrieve 10 random ROBs from rob_list
81 '05 :GET:RND20:': rob_list, # Retrieve 20 random ROBs from rob_list
82 '06 :GET:RND50:': rob_list, # Retrieve 50 random ROBs from rob_list
83 '07 :GET:RND10:': rob_list, # Retrieve 10 random ROBs from rob_list
84 '08 :GET:RND5:': rob_list, # Retrieve 5 random ROBs from rob_list
85 '09 :GET:RND20:': rob_list, # Retrieve 20 random ROBs from rob_list
86 '10 :GET:RND20:': rob_list, # Retrieve 20 random ROBs from rob_list
87 '11 :GET:RND10:': rob_list, # Retrieve 10 random ROBs from rob_list
88 '12 :GET:RND10:': rob_list # Retrieve 10 random ROBs from rob_list
89}
90
92 def __init__(self):
93 self.UseRandomSeed = False
94 self.RandomAcceptRate = -1.0
97 self.BurnTimeRandomly = True
98 self.Crunch = False
100 self.ROBAccessDict = rob_access_dict
102 self.PEBROBList = []
105
106
107default_options = MTCalibPebHypoOptions()
108
109
110def set_flags(flags, options=default_options):
111 flags.Common.isOnline = True
112 flags.Input.Files = []
113 flags.Input.Format = Format.BS
114 flags.Input.isMC = False
115 flags.Trigger.doHLT = True
116 flags.Trigger.EDMVersion = 3
117 flags.Trigger.Online.isPartition = True
118 flags.Trigger.triggerMenuSetup = 'Dev_pp_run3_v1'
119 flags.Trigger.forceEnableAllChains = True
120 # Disable signature-specific detector configuration parts
121 flags.Trigger.doID = False
122 flags.Trigger.doCalo = False
123 flags.Trigger.doMuon = False
124 # Disable L1 data decoding (except for CTP)
125 flags.Trigger.L1.doMuon = False
126 flags.Trigger.L1.doCalo = False
127 flags.Trigger.L1.doTopo = False
128
129
130def l1_seq_cfg(flags, options=default_options):
131 from HLTSeeding.HLTSeedingConfig import HLTSeedingCfg
132 acc = HLTSeedingCfg(flags)
133
134 l1_decoder_alg = acc.getEventAlgo('HLTSeeding')
135 l1_decoder_alg.prescaler = CompFactory.PrescalingEmulationTool()
136
137 # Generate L1 menu
138 from TrigConfigSvc.TrigConfigSvcCfg import generateL1Menu
139 generateL1Menu(flags)
140
141 # Need to set HLT menu file name here to avoid conflict when merging with HLT sequence CA
142 acc.getService("HLTConfigSvc").HLTJsonFileName = _menu_file_name
143
144 return acc
145
146
148 hypo = CompFactory.MTCalibPebHypoAlg(name)
149 hypo.HypoInputDecisions = 'HLTSeedingSummary'
150 hypo.HypoOutputDecisions = 'MTCalibPebDecisions_'+name
151 return hypo
152
153
154def make_hypo_tool(name, options=default_options):
155 hypo_tool = CompFactory.MTCalibPebHypoTool(name)
156 hypo_tool.UseRandomSeed = options.UseRandomSeed
157 hypo_tool.RandomAcceptRate = options.RandomAcceptRate
158 hypo_tool.BurnTimePerCycleMillisec = options.BurnTimePerCycleMillisec
159 hypo_tool.NumBurnCycles = options.NumBurnCycles
160 hypo_tool.BurnTimeRandomly = options.BurnTimeRandomly
161 hypo_tool.Crunch = options.Crunch
162 hypo_tool.CheckDataConsistency = options.CheckDataConsistency
163 hypo_tool.ROBAccessDict = options.ROBAccessDict
164 hypo_tool.TimeBetweenROBReqMillisec = options.TimeBetweenROBReqMillisec
165 hypo_tool.PEBROBList = options.PEBROBList
166 hypo_tool.PEBSubDetList = options.PEBSubDetList
167 hypo_tool.CreateRandomData = options.CreateRandomData
168 return hypo_tool
169
170
171def make_all_hypo_algs(num_chains, concurrent=False):
172 hypo_tools = []
173 for chain_index in range(1, 1+num_chains):
174 # Default hypo tool for chains 1, 4, 7, 10, ...
175 hypoTool = make_hypo_tool('HLT_MTCalibPeb{:d}'.format(chain_index))
176 hypoTool.PEBROBList = rob_list
177 hypoTool.PEBSubDetList = []
178 # Hypo for chains 2, 5, 8, 11, ...
179 if chain_index % 3 == 2:
180 hypoTool.PEBROBList = [0x420024, 0x420025, 0x420026, 0x420027] # example LAr EMB ROBs
181 hypoTool.PEBSubDetList = [0x53, 0x54] # TILECAL_EXT A and C
182 # Hypo for chains 3, 6, 9, 12, ...
183 elif chain_index % 3 == 0:
184 hypoTool.CreateRandomData = {
185 'ExampleCollection_{:d}_1'.format(chain_index): 5,
186 'ExampleCollection_{:d}_2'.format(chain_index): 3,
187 }
188 hypoTool.PEBROBList = [0x420034, 0x420035, 0x420036, 0x420037] # example LAr EMB ROBs
189 hypoTool.PEBROBList.extend([0x7c0001]) # extra HLT result for data scouting
190 hypo_tools.append(hypoTool)
191
192 # Add the hypo tools to algorithm(s)
193 hypo_algs = []
194 if concurrent:
195 for tool in hypo_tools:
196 hypo = make_hypo_alg('HypoAlg{:d}'.format(len(hypo_algs)+1))
197 hypo.HypoTools += [tool]
198 hypo_algs.append(hypo)
199 else:
200 hypo = make_hypo_alg('HypoAlg1')
201 for tool in hypo_tools:
202 hypo.HypoTools += [tool]
203 hypo_algs.append(hypo)
204
205 return hypo_algs
206
207
208def hlt_result_cfg(flags, hypo_algs):
209 from TrigEDMConfig.DataScoutingInfo import getFullHLTResultID
210 from TrigEDMConfig.TriggerEDMRun3 import EDMDetailsRun3
211 from TrigEDMConfig.TriggerEDM import getRawTriggerEDMList
212 from TrigOutputHandling.TrigOutputHandlingConfig import TriggerEDMSerialiserToolCfg, StreamTagMakerToolCfg, TriggerBitsMakerToolCfg
213
214 # Tool serialising EDM objects to fill the HLT result
215 serialiser = TriggerEDMSerialiserToolCfg(flags, 'Serialiser')
216 # Add some framework EDM to the output, but skip the ones in EDMDetailsRun3 to avoid the fuss
217 serialiser.addCollectionListToMainResult([
218 coll[0] for coll in getRawTriggerEDMList(flags, runVersion=3) if 'BS' in coll[1] and coll[2]=='Steer' and not coll[0].split('#')[0] in EDMDetailsRun3
219 ])
220 for hypo in hypo_algs:
221 serialiser.addCollectionListToMainResult([
222 'xAOD::TrigCompositeContainer#%s' % hypo.HypoOutputDecisions,
223 'xAOD::TrigCompositeAuxContainer#%sAux.' % hypo.HypoOutputDecisions,
224 ])
225
226 # Data scouting example
227 resultList = [getFullHLTResultID(), 1]
228 collections = set()
229 chain_names = []
230 for hypo in hypo_algs:
231 for hypo_tool in hypo.HypoTools:
232 chain_names.append(hypo_tool.name)
233 if hasattr(hypo_tool,'CreateRandomData'):
234 for coll_name in hypo_tool.CreateRandomData.keys():
235 collections.add(coll_name)
236 for coll_name in collections:
237 serialiser.addCollectionListToResults([
238 'xAOD::TrigCompositeContainer#{:s}'.format(coll_name),
239 'xAOD::TrigCompositeAuxContainer#{:s}Aux.'.format(coll_name)
240 ], resultList)
241
242 # StreamTag definitions
243 streamPhysicsMain = {
244 'name': 'Main',
245 'type': 'physics',
246 'obeyLB': True,
247 'forceFullEventBuilding': True
248 }
249 streamExamplePEB = {
250 'name': 'ExamplePEB',
251 'type': 'calibration',
252 'obeyLB': True,
253 'forceFullEventBuilding': False
254 }
255 streamExampleDataScoutingPEB = {
256 'name': 'ExampleDataScoutingPEB',
257 'type': 'physics',
258 'obeyLB': True,
259 'forceFullEventBuilding': False
260 }
261 chain_to_streams = {}
262 for counter, ch in enumerate(chain_names, start=1):
263 if counter % 3 == 1:
264 chain_to_streams[ch] = [streamPhysicsMain]
265 elif counter % 3 == 2:
266 chain_to_streams[ch] = [streamExamplePEB]
267 elif counter % 3 == 0:
268 chain_to_streams[ch] = [streamExampleDataScoutingPEB]
269
270 menu_json = write_dummy_menu_json(flags, chain_to_streams.keys(), chain_to_streams)
271
272 acc = ComponentAccumulator()
273
274 # Give the menu json name to HLTConfigSvc
275 from TrigConfigSvc.TrigConfigSvcCfg import HLTConfigSvcCfg
276 hltConfigSvcCfg = HLTConfigSvcCfg(flags)
277 hltConfigSvcCfg.getService("HLTConfigSvc").HLTJsonFileName = menu_json
278 acc.merge(hltConfigSvcCfg)
279
280 # Tool adding stream tags to HLT result
281 stmaker = StreamTagMakerToolCfg()
282 stmaker.ChainDecisions = 'HLTNav_Summary'
283 stmaker.PEBDecisionKeys = [str(hypo.HypoOutputDecisions) for hypo in hypo_algs]
284
285 # Tool adding HLT bits to HLT result
286 bitsmaker = TriggerBitsMakerToolCfg()
287 bitsmaker.ChainDecisions = 'HLTNav_Summary'
288
289 # Configure the HLT result maker to use the above tools
290 from TrigServices.TrigServicesConfig import TrigServicesCfg
291 trigServicesCfg = TrigServicesCfg(flags)
292 hltEventLoopMgr = trigServicesCfg.getPrimary()
293 hltEventLoopMgr.ResultMaker.StreamTagMaker = stmaker
294 hltEventLoopMgr.ResultMaker.MakerTools = [bitsmaker, serialiser]
295 acc.merge(trigServicesCfg)
296
297 return acc
298
299
300def make_summary_algs(hypo_algs):
301 summary = CompFactory.TriggerSummaryAlg('TriggerSummaryAlg')
302 summary.InputDecision = 'HLTSeedingSummary'
303 summary.FinalDecisions = [str(hypo.HypoOutputDecisions) for hypo in hypo_algs]
304
305 summMaker = CompFactory.DecisionSummaryMakerAlg()
306 summMaker.FinalDecisionKeys = [str(hypo.HypoOutputDecisions) for hypo in hypo_algs]
307 summMaker.FinalStepDecisions = {}
308 for hypo in hypo_algs:
309 for tool in hypo.HypoTools:
310 summMaker.FinalStepDecisions[tool.getName()] = [str(hypo.HypoOutputDecisions)]
311 log.info('summMaker = %s', summMaker)
312 return [summary, summMaker]
313
314
315def hlt_seq_cfg(flags, num_chains, concurrent=False, hypo_algs=None):
316 acc = ComponentAccumulator()
317
318 # Load these objects from StoreGate
319 loadFromSG = [('xAOD::EventInfo', 'StoreGateSvc+EventInfo'),
320 ('TrigConf::L1Menu','DetectorStore+L1TriggerMenu'),
321 ('TrigConf::HLTMenu','DetectorStore+HLTTriggerMenu')]
322
323 from SGComps.SGInputLoaderConfig import SGInputLoaderCfg
324 acc.merge(SGInputLoaderCfg(flags, loadFromSG))
325
326 # Sequences need to ensure that summary algs run after all hypos
327 acc.addSequence(seqOR('hltTop'))
328 acc.addSequence(parOR('hltHypoSeq'), parentName='hltTop')
329 acc.addSequence(parOR('hltEndSeq'), parentName='hltTop')
330
331 if not hypo_algs:
332 hypo_algs = make_all_hypo_algs(num_chains, concurrent)
333 summary_algs = make_summary_algs(hypo_algs)
334 hlt_result_ca = hlt_result_cfg(flags, hypo_algs)
335
336 acc.addEventAlgo(hypo_algs, sequenceName='hltHypoSeq')
337 acc.addEventAlgo(summary_algs, sequenceName='hltEndSeq')
338 acc.merge(hlt_result_ca)
339
340 return acc
341
342
343def write_dummy_menu_json(flags, chains, chain_to_streams):
344 import json
345 from TrigConfHLTUtils.HLTUtils import string2hash
346 from TrigConfigSvc.TrigConfigSvcCfg import getHLTPrescalesSetFileName
347 menu_dict = dict([
348 ("filetype", "hltmenu"),
349 ("name", _menu_name),
350 ("chains", dict()),
351 ("streams", dict()),
352 ("sequencers", dict())
353 ])
354 hlt_ps_dict = dict([
355 ("filetype", "hltprescale"),
356 ("name", _menu_name),
357 ("prescales", dict())
358 ])
359 counter = 0
360 for chain in chains:
361 # Prepare information for stream list and fill separate dictionary
362 chain_streams = []
363 for stream in chain_to_streams[chain]:
364 stream_name = stream['name']
365 chain_streams.append(stream_name)
366 # If not already listed, add stream details to stream dictionary
367 if stream_name not in menu_dict["streams"]:
368 menu_dict["streams"][stream_name] = dict([
369 ("name", stream_name),
370 ("type", stream['type']),
371 ("obeyLB", stream['obeyLB']),
372 ("forceFullEventBuilding", stream['forceFullEventBuilding'])
373 ])
374
375 menu_dict["chains"][chain] = dict([
376 ("counter", counter),
377 ("nameHash", string2hash(chain)),
378 ("legMultiplicities", [1]),
379 ("l1item", ''),
380 ("l1thresholds", ['FSNOSEED']),
381 ("groups", []),
382 ("streams", chain_streams),
383 ("sequencers", [] )
384 ])
385 hlt_ps_dict["prescales"][chain] = dict([
386 ("counter", counter),
387 ("hash", string2hash(chain)),
388 ("prescale", 1),
389 ("enabled", True),
390 ])
391
392 counter += 1
393
394 log.info('Writing trigger menu to %s', _menu_file_name)
395 with open(_menu_file_name, 'w') as json_file:
396 json.dump(menu_dict, json_file, indent=4, sort_keys=False)
397
398 hlt_ps_file_name = getHLTPrescalesSetFileName(flags)
399 log.info('Writing HLT prescales to %s', hlt_ps_file_name)
400 with open(hlt_ps_file_name, 'w') as json_file:
401 json.dump(hlt_ps_dict, json_file, indent=4, sort_keys=False)
402
403 return _menu_file_name
404
405
406# unit test
407if __name__ == '__main__':
408 from AthenaConfiguration.AllConfigFlags import initConfigFlags
409 flags = initConfigFlags()
410 set_flags(flags)
411 flags.lock()
412
413 acc = l1_seq_cfg(flags)
414 acc.merge(hlt_seq_cfg(flags,num_chains=3))
415 acc.printConfig(withDetails=True)
416 with open("MTCalibPebConfigTest.pkl", "wb") as file:
417 acc.store(file)
STL class.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179
hlt_result_cfg(flags, hypo_algs)
l1_seq_cfg(flags, options=default_options)
write_dummy_menu_json(flags, chains, chain_to_streams)
hlt_seq_cfg(flags, num_chains, concurrent=False, hypo_algs=None)
make_summary_algs(hypo_algs)
make_all_hypo_algs(num_chains, concurrent=False)
set_flags(flags, options=default_options)
make_hypo_tool(name, options=default_options)