ATLAS Offline Software
Loading...
Searching...
No Matches
run_gep.py
Go to the documentation of this file.
2# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3#
4
5if __name__ == '__main__':
6 import sys
7
8
11 from AthenaCommon.Logging import logging
12 local_log = logging.getLogger('run_gep')
13 info = local_log.info
14 error = local_log.error
15
16 import argparse
17 p = argparse.ArgumentParser()
18 p.add_argument('-i', '--input',
19 metavar='KEY',
20 default='ttbar',
21 help='Key of the input from TrigValInputs to be used, default=%(default)s')
22 p.add_argument('-e', '--execute',
23 action='store_true',
24 help='After building the configuration, also process a few events')
25 p.add_argument('-n', '--nevents',
26 metavar='N',
27 type=int,
28 default=25,
29 help='Number of events to process if --execute is used, default=%(default)s')
30 p.add_argument('-g', '--gepInput',
31 metavar='N',
32 type=bool,
33 default=False,
34 help='use input files previously used for GEP jobs')
35 p.add_argument('-f', '--gepInputRun3',
36 action='store_true',
37 help='use Run3 (with jFexJetRoI) input file')
38
39 p.add_argument('-c', '--clusterAlgs',
40 default='WFS',
41 help='commma separated list of stategies for GepClusterAlg: [WFS, Calo420]')
42
43 p.add_argument('-j', '--jetAlgs',
44 default='Cone',
45 help='commma separated list of stategies for GepJetAlg:[Cone, ModAntikT]')
46
47 p.add_argument('-ett', '--enableTopoTower',
48 action='store_true',
49 help='Enable GepTopoTower algorithm'
50 )
51
52 p.add_argument('-ect', '--enableCellTower',
53 action='store_true',
54 help='Enable GepCellTower algorithm'
55 )
56
57 p.add_argument('-etct', '--enableTCTower',
58 action='store_true',
59 help='Enable GepTCTower algorithm'
60 )
61
62 p.add_argument('-cell', '--cellCollection',
63 default='GepCells',
64 help='commma separated list of input cell Collection for CellTower algorithm: [GepCells,CaloCells]')
65
66 args = p.parse_args()
67
68 clusterAlgNames = args.clusterAlgs.split(',')
69 jetAlgNames = args.jetAlgs.split(',')
70 enable_topo_tower = args.enableTopoTower # Boolean flag
71 enable_tc_tower = args.enableTCTower # Boolean flag
72 enable_cell_tower = args.enableCellTower # Boolean flag
73 cellCollectionName = args.cellCollection
74 info('GEP clusterAlgs: ' + str(clusterAlgNames))
75 info('GEP jetAlgs: ' + str(jetAlgNames))
76
77 # Print Tower statuses
78 info(f'GEP TopoTower enabled: {"Yes" if enable_topo_tower else "No"}')
79 info(f'GEP TCTower enabled: {"Yes" if enable_tc_tower else "No"}')
80 info(f'GEP CellTower enabled: {"Yes" if enable_cell_tower else "No"}')
81
82 # Print which cell collection is being used
83 info(f'GEP CellTower collection: {cellCollectionName}')
84
85
88 from AthenaConfiguration.AllConfigFlags import initConfigFlags
89 from TrigValTools.TrigValSteering import Input
90
91 assert not (args.gepInput and args.gepInputRun3)
92
93 flags = initConfigFlags()
94
95 if args.gepInput:
96 ifile = (
97 "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/RecExRecoTest/mc20e_13TeV/"
98 "valid1.410000.PowhegPythiaEvtGen_P2012_ttbar_hdamp172p5_nonallhad.ESD.e4993_s3227_r12689/myESD.pool.root")
99 flags.Input.Files = [ifile]
100 elif args.gepInputRun3:
101 # ifile = (
102 # '/afs/cern.ch/work/m/martyniu/public/forPeter/'
103 # 'mc21.601229.PhPy8EG_A14_ttbar_hdamp258p75_SingleLep.recon.AOD.e8357_e7400_s3775_r13614_r13614/'
104 #'AOD.29004489._000039.pool.root.1')
105
106 ifile = '/afs/cern.ch/work/m/martyniu/public/forPeter/RDO/tmp.RDO'
107 flags.Input.Files = [ifile]
108 else:
109 flags.Input.Files = Input.get_input(args.input).paths
110
111 if not flags.Input.isMC:
112 from AthenaConfiguration.TestDefaults import defaultGeometryTags
113 flags.GeoModel.AtlasVersion = defaultGeometryTags.autoconfigure(flags)
114
115 info('Command line args: ' + str(args))
116
117 flags.Output.AODFileName = 'AOD.pool.root'
118 flags.Common.isOnline = not flags.Input.isMC
119 flags.Exec.MaxEvents = args.nevents
120 flags.Concurrency.NumThreads = 1
121 flags.Concurrency.NumConcurrentEvents = 1
122 flags.Scheduler.ShowDataDeps = True
123 flags.Scheduler.CheckDependencies = True
124 flags.Scheduler.ShowDataFlow = True
125 flags.Trigger.EDMVersion = 3
126 flags.Trigger.doLVL1 = True
127 flags.Trigger.enableL1CaloPhase1 = True
128
129 # Enable only calo for this test
130 from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
131 setupDetectorFlags(flags, ['LAr','Tile','MBTS'], toggle_geometry=True)
132
133 flags.lock()
134 flags.dump()
135
136
139 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
140 acc = MainServicesCfg(flags)
141
142 from AthenaConfiguration.Enums import Format
143 if flags.Input.Format == Format.POOL:
144 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
145 acc.merge(PoolReadCfg(flags))
146 else:
147 from TriggerJobOpts.TriggerByteStreamConfig import ByteStreamReadCfg
148 acc.merge(ByteStreamReadCfg(flags))
149
150 from TrigConfigSvc.TrigConfigSvcCfg import L1ConfigSvcCfg, generateL1Menu, createL1PrescalesFileFromMenu
151 acc.merge(L1ConfigSvcCfg(flags))
152 generateL1Menu(flags)
153 createL1PrescalesFileFromMenu(flags)
154
155 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
156 FexEDMList = [
157 'xAOD::eFexEMRoIContainer#L1_eEMRoI','xAOD::eFexEMRoIAuxContainer#L1_eEMRoIAux.',
158 'xAOD::eFexTauRoIContainer#L1_eTauRoI','xAOD::eFexTauRoIAuxContainer#L1_eTauRoIAux.',
159 'xAOD::jFexTauRoIContainer#L1_jFexTauRoI','xAOD::jFexTauRoIAuxContainer#L1_jFexTauRoIAux.',
160 'xAOD::jFexSRJetRoIContainer#L1_jFexSRJetRoI','xAOD::jFexSRJetRoIAuxContainer#L1_jFexSRJetRoIAux.',
161 'xAOD::jFexLRJetRoIContainer#L1_jFexLRJetRoI','xAOD::jFexLRJetRoIAuxContainer#L1_jFexLRJetRoIAux.',
162 'xAOD::jFexMETRoIContainer#L1_jFexMETRoI','xAOD::jFexMETRoIAuxContainer#L1_jFexMETRoIAux.',
163 'xAOD::jFexSumETRoIContainer#L1_jFexSumETRoI','xAOD::jFexSumETRoIAuxContainer#L1_jFexSumETRoIAux.',
164 'xAOD::gFexJetRoIContainer#L1_gFexSRJetRoI','xAOD::gFexJetRoIAuxContainer#L1_gFexSRJetRoIAux.',
165 'xAOD::gFexJetRoIContainer#L1_gFexLRJetRoI','xAOD::gFexJetRoIAuxContainer#L1_gFexLRJetRoIAux.',
166 'xAOD::gFexJetRoIContainer#L1_gFexRhoRoI','xAOD::gFexJetRoIAuxContainer#L1_gFexRhoRoIAux.',
167 'xAOD::gFexGlobalRoIContainer#L1_gScalarEJwoj','xAOD::gFexGlobalRoIAuxContainer#L1_gScalarEJwojAux.',
168 'xAOD::gFexGlobalRoIContainer#L1_gMETComponentsJwoj','xAOD::gFexGlobalRoIAuxContainer#L1_gMETComponentsJwojAux.',
169 'xAOD::gFexGlobalRoIContainer#L1_gMHTComponentsJwoj','xAOD::gFexGlobalRoIAuxContainer#L1_gMHTComponentsJwojAux.',
170 'xAOD::gFexGlobalRoIContainer#L1_gMSTComponentsJwoj','xAOD::gFexGlobalRoIAuxContainer#L1_gMSTComponentsJwojAux.',
171 'xAOD::gFexGlobalRoIContainer#L1_gMETComponentsNoiseCut','xAOD::gFexGlobalRoIAuxContainer#L1_gMETComponentsNoiseCutAux.',
172 'xAOD::gFexGlobalRoIContainer#L1_gMETComponentsRms','xAOD::gFexGlobalRoIAuxContainer#L1_gMETComponentsRmsAux.',
173 'xAOD::gFexGlobalRoIContainer#L1_gScalarENoiseCut','xAOD::gFexGlobalRoIAuxContainer#L1_gScalarENoiseCutAux.',
174 'xAOD::gFexGlobalRoIContainer#L1_gScalarERms','xAOD::gFexGlobalRoIAuxContainer#L1_gScalarERmsAux.',
175 ]
176 acc.merge(OutputStreamCfg(flags, 'AOD', ItemList=FexEDMList))
177
178
181
182 from L1CaloFEXSim.L1CaloFEXSimCfg import L1CaloFEXSimCfg
183 acc.merge(L1CaloFEXSimCfg(flags))
184
185 # Add in CellMaking, outputs a CaloCellContainer named AllCalo
186 from CaloRec.CaloCellMakerConfig import CaloCellMakerCfg
187 acc.merge(CaloCellMakerCfg(flags))
188
189
190
191 # add the creation of standard 420 Topoclusters
192 from CaloRec.CaloTopoClusterConfig import CaloTopoClusterCfg
193 calo_acc420 = CaloTopoClusterCfg(flags) # default clusters: 420
194 acc.merge(calo_acc420)
195
196 # Also create 422 topoclusters
197 # PS: cannot find a "civilised" way to set the calorimeter cell energy
198 # cut at 2*sigma cell noise, so do it by force.
199 # Note:
200 # Executing <ComponentAccumator>,printConfig(withDetails=True,
201 # summariseProps=True)
202 # helped to work this out.
203
204 # 1. set up cluster making with cell energy cut.
205 # 2. avoid container name clashes
206
207 doLCCalib = flags.Calo.TopoCluster.doTopoClusterLocalCalib
208 clustersname = 'CaloCalTopoClusters422' if doLCCalib else 'CaloTopoClusters422'
209 calo_acc422 = CaloTopoClusterCfg(flags,
210 clustersname=clustersname)
211
212 def getAlg422(cfg):
213 for comp in cfg.getSequence().Members:
214 if comp.name == 'CaloCalTopoClusters422Maker':
215 return comp
216 return None
217
219 if not hasattr(alg, 'ClusterMakerTools'):
220 return False
221
222 for tool in alg.ClusterMakerTools:
223 if tool.name == 'TopoMaker':
224 assert tool.CellThresholdOnEorAbsEinSigma == 0
225 tool.CellThresholdOnEorAbsEinSigma = 2.0
226 return True
227
228 return False
229
231 if not hasattr(alg, 'ClusterCorrectionTools'):
232 return False
233
234 for tool in alg.ClusterCorrectionTools:
235
236 if tool.name == 'CaloClusterSnapshot':
237 assert tool.OutputName == 'CaloTopoClusters'
238 if doLCCalib:
239 tool.OutputName = 'CaloCalTopoClusters422Snap'
240 else:
241 tool.OutputName = 'CaloTopoClusters422Snap'
242 return True
243
244 return False
245
246
247 alg = getAlg422(calo_acc422)
248 if alg is None:
249 error('no 422 cluster alg')
250 sys.exit(1)
251
252 assert fixMakerTool422(alg)
253 assert fixSnapshotTool422(alg)
254
255 acc.merge(calo_acc422)
256
257 from AthenaCommon.Constants import DEBUG
258 gepAlgs_output_level = DEBUG
259
260 from TrigGepPerf.GepClusterTimingAlgConfig import GepClusterTimingAlgCfg
261 acc.merge(GepClusterTimingAlgCfg(flags,
262 OutputLevel=gepAlgs_output_level))
263
264
270
271 # Produce the GEP cell map
272
273 # Defining the Energy encoding scheme used in GEP
274 NumberOfEnergyBits = 6 # Two bits for energy range, rest to encode energy
275 ValueOfLeastSignificantBit = 10 # in MeV
276 ValueG = 4 # Multiplier for high energy ranges
277
278 gepEnergyEncodingScheme = str(NumberOfEnergyBits)+"-"+str(ValueOfLeastSignificantBit)+"-"+str(ValueG)
279
280 from TrigGepPerf.GepCellsHandlerAlgConfig import GepCellsHandlerAlgCfg
281
282 gepcellhandler_cfg = GepCellsHandlerAlgCfg(
283 flags,
284 outputGepCellsKey="GepCells",
285 GEPEnergyEncodingScheme = gepEnergyEncodingScheme,
286 HardwareStyleEnergyEncoding = True,
287 TruncationOfOverflowingFEBs = True,
288 OutputLevel=gepAlgs_output_level)
289
290 info('gepclustering_cfg dump:')
291 gepcellhandler_cfg.printConfig(withDetails=True,
292 summariseProps=True)
293
294 acc.merge(gepcellhandler_cfg)
295
296 from TrigGepPerf.GepPi0AlgConfig import GepPi0AlgCfg
297 # currently caloCellsProducer can be caloCellsFromCaloCells or
298 # caloCellsFromCaloClusters
299 acc.merge(GepPi0AlgCfg(flags,
300 name='GepPi0Alg',
301 caloCellsProducer="caloCellsFromCaloCells",
302 OutputLevel=gepAlgs_output_level))
303
304 # PS not yet tested: topoclAlgs = ['Calo422']
305 known_cluster_algs = ['WFS', 'Calo420', 'Calo422']
306 for a in clusterAlgNames:
307 assert a in known_cluster_algs
308
309 known_jet_algs = ['Cone', 'ModAntikT']
310 for a in jetAlgNames:
311 assert a in known_jet_algs
312
313 # Create a number of Algorithms equal to the size of the product
314 # len(ClusterAlgs) x len(JetAlgs). Will eventually add in
315 # > 1 MET alg, and pileup suppression Algs.
316
317 caloclustercolls = {('Calo420', False) : 'CaloTopoClusters',
318 ('Calo420', True) : 'CaloCalTopoClusters',
319 ('Calo422', False) : 'CaloTopoClusters422',
320 ('Calo422', True) : 'CaloCalTopoClusters422'}
321
322 # Add CellTower creation using GepCellTowerAlg
323 from TrigGepPerf.GepCellTowerAlgConfig import GepCellTowerAlgCfg
324
325 if enable_cell_tower:
326 cell_tower_key = 'GEPCellTower'
327 alg_name = 'GepCellTowerAlg'
328
329 # Configure GepCellTowerAlg
330 gep_cell_tower_cfg = GepCellTowerAlgCfg(
331 flags,
332 outputCellTowerKey=cell_tower_key,
333 gepCellMapKey=cellCollectionName,
334 OutputLevel=gepAlgs_output_level)
335
336 info('Configuring GepCellTowerAlg')
337 gep_cell_tower_cfg.printConfig(withDetails=True, summariseProps=True)
338
339 # Merge the configuration
340 acc.merge(gep_cell_tower_cfg)
341
342 for cluster_alg in clusterAlgNames:
343 caloClustersKey = caloclustercolls.get((cluster_alg, doLCCalib), None)
344 if caloClustersKey is None:
345 from TrigGepPerf.GepClusteringAlgConfig import GepClusteringAlgCfg
346
347 caloClustersKey='GEP'+cluster_alg+'Clusters'
348 gepclustering_cfg = GepClusteringAlgCfg(
349 flags,
350 TopoClAlg=cluster_alg,
351 gepCellMapKey="GepCells",
352 outputCaloClustersKey=caloClustersKey,
353 OutputLevel=gepAlgs_output_level)
354
355
356 info('gepclustering_cfg dump:')
357 gepclustering_cfg.printConfig(withDetails=True,
358 summariseProps=True)
359
360 acc.merge(gepclustering_cfg)
361
362 if enable_topo_tower:
363 from TrigGepPerf.GepTopoTowerAlgConfig import GepTopoTowerAlgCfg
364 alg_name='GepTopoTower'+ cluster_alg +'Alg'
365 acc.merge(GepTopoTowerAlgCfg(
366 flags,
367 name=alg_name,
368 caloClustersKey=caloClustersKey,
369 outputCaloClustersKey='GEP'+ cluster_alg +'TopoTower',
370 gepCellMapKey="GepCells",
371 OutputLevel=gepAlgs_output_level))
372
373 if enable_tc_tower:
374 from TrigGepPerf.GepTCTowerAlgConfig import GepTCTowerAlgCfg
375 alg_name='GepTCTower'+ cluster_alg +'Alg'
376 acc.merge(GepTCTowerAlgCfg(
377 flags,
378 name=alg_name,
379 caloClustersKey=caloClustersKey,
380 outputCaloClustersKey='GEP'+ cluster_alg +'TCTower',
381 OutputLevel=gepAlgs_output_level))
382
383 puSuppressionAlgs = ['']
384
385 for puSuppressionAlg in puSuppressionAlgs:
386
387 tcLabel = cluster_alg + puSuppressionAlg
388
389 for jetAlg in jetAlgNames:
390
391 from TrigGepPerf.GepJetAlgConfig import GepJetAlgCfg
392 alg_name='Gep'+cluster_alg + jetAlg + 'JetAlg'
393 acc.merge(GepJetAlgCfg(
394 flags,
395 name=alg_name,
396 jetAlgName=jetAlg,
397 caloClustersKey=caloClustersKey,
398 outputJetsKey='GEP' + cluster_alg + jetAlg +'Jets',
399 OutputLevel=gepAlgs_output_level))
400
401 info('\nGepJetAlg properties dump\n')
402 info(str(acc.getEventAlgo(alg_name)._properties))
403
404 # Custom jets for TopoTowers using the correct key
405 if enable_topo_tower:
406 topoTowerKey = 'GEP' + cluster_alg + 'TopoTower'
407 ttalg_name = 'Gep' + cluster_alg + 'TopoTower' + jetAlg + 'JetAlg'
408 acc.merge(GepJetAlgCfg(
409 flags,
410 name=ttalg_name,
411 jetAlgName=jetAlg,
412 caloClustersKey=topoTowerKey,
413 outputJetsKey='GEP' + cluster_alg + 'TopoTower' + jetAlg + 'Jets',
414 OutputLevel=gepAlgs_output_level))
415
416 info('\nGepJetAlg properties dump for TopoTowers\n')
417 info(str(acc.getEventAlgo(ttalg_name)._properties))
418
419 # Custom jets for TCTowers using the correct key
420 if enable_tc_tower:
421 tcTowerKey = 'GEP' + cluster_alg + 'TCTower'
422 tctalg_name = 'Gep' + cluster_alg + 'TCTower' + jetAlg + 'JetAlg'
423 acc.merge(GepJetAlgCfg(
424 flags,
425 name=tctalg_name,
426 jetAlgName=jetAlg,
427 caloClustersKey=tcTowerKey,
428 outputJetsKey='GEP' + cluster_alg + 'TCTower' + jetAlg + 'Jets',
429 OutputLevel=gepAlgs_output_level))
430
431 info('\nGepJetAlg properties dump for TCTowers\n')
432 info(str(acc.getEventAlgo(tctalg_name)._properties))
433
434 # CellTowers
435 if enable_cell_tower:
436 ctalg_name = 'GepCellTower' + jetAlg + 'JetAlg'
437 acc.merge(GepJetAlgCfg(
438 flags,
439 name=ctalg_name,
440 jetAlgName=jetAlg,
441 caloClustersKey=cell_tower_key,
442 outputJetsKey='GEPCellTower' + jetAlg + 'Jets',
443 OutputLevel=gepAlgs_output_level))
444
445 info('\nGepJetAlg properties dump for CellTower\n')
446 info(str(acc.getEventAlgo(ctalg_name)._properties))
447
448 from TrigGepPerf.GepMETAlgConfig import GepMETAlgCfg
449 alg_name='GepMET'+ cluster_alg +'Alg'
450 acc.merge(GepMETAlgCfg(
451 flags,
452 name=alg_name,
453 caloClustersKey=caloClustersKey,
454 outputMETKey='GEP'+ cluster_alg +'MET',
455 OutputLevel=gepAlgs_output_level))
456
457 # MET for TopoTowers using the correct key
458 if enable_topo_tower:
459 topoTowerMETKey = 'GEP' + cluster_alg + 'TopoTower'
460 ttMETalg_name = 'GepMET' + cluster_alg + 'TopoTower' + 'Alg'
461 acc.merge(GepMETAlgCfg(
462 flags,
463 name=ttMETalg_name,
464 caloClustersKey=topoTowerMETKey,
465 outputMETKey='GEP' + cluster_alg + 'TopoTower' + 'MET',
466 OutputLevel=gepAlgs_output_level))
467
468 # MET for TCTowers using the correct key
469 if enable_tc_tower:
470 tcTowerMETKey = 'GEP' + cluster_alg + 'TCTower'
471 tctMETalg_name = 'GepMET' + cluster_alg + 'TCTower' + 'Alg'
472 acc.merge(GepMETAlgCfg(
473 flags,
474 name=tctMETalg_name,
475 caloClustersKey=tcTowerMETKey,
476 outputMETKey='GEP' + cluster_alg + 'TCTower' + 'MET',
477 OutputLevel=gepAlgs_output_level))
478
479 # MET for CellTower using the correct key
480 if enable_cell_tower:
481 ctMETalg_name = 'GepMETCellTowerAlg'
482 acc.merge(GepMETAlgCfg(
483 flags,
484 name=ctMETalg_name,
485 caloClustersKey=cell_tower_key,
486 outputMETKey='GEPCellTowerMET',
487 OutputLevel=gepAlgs_output_level))
488
489 from TrigGepPerf.GepMETPufitAlgConfig import GepMETPufitAlgCfg
490 alg_name='GepMET' + cluster_alg + 'PufitAlg'
491 acc.merge(GepMETPufitAlgCfg(
492 flags,
493 name=alg_name,
494 caloClustersKey=caloClustersKey,
495 outputMETPufitKey='GEP'+ cluster_alg + 'METPufit',
496 OutputLevel=gepAlgs_output_level))
497
498 if enable_topo_tower:
499 ttPufitMETalg_name = 'GepMET' + cluster_alg + 'TopoTower' + 'PufitAlg'
500 acc.merge(GepMETPufitAlgCfg(
501 flags,
502 name=ttPufitMETalg_name,
503 caloClustersKey=topoTowerMETKey,
504 outputMETKey='GEP' + cluster_alg + 'TopoTower' + 'METPufit',
505 OutputLevel=gepAlgs_output_level))
506
507 if enable_tc_tower:
508 tctPufitMETalg_name = 'GepMET' + cluster_alg + 'TCTower' + 'PufitAlg'
509 acc.merge(GepMETPufitAlgCfg(
510 flags,
511 name=tctPufitMETalg_name,
512 caloClustersKey=tcTowerMETKey,
513 outputMETKey='GEP' + cluster_alg + 'TCTower' + 'METPufit',
514 OutputLevel=gepAlgs_output_level))
515
516 if enable_cell_tower:
517 ctPufitMETalg_name = 'GepMETCellTowerPufitAlg'
518 acc.merge(GepMETPufitAlgCfg(
519 flags,
520 name=ctPufitMETalg_name,
521 caloClustersKey=cell_tower_key,
522 outputMETKey='GEPCellTowerMETPufit',
523 OutputLevel=gepAlgs_output_level))
524
525
528 with open("L1Sim.pkl", "wb") as f:
529 acc.store(f)
530 f.close()
531
532 if args.execute:
533 sc = acc.run()
534 if sc.isFailure():
535 exit(1)
getAlg422(cfg)
Definition run_gep.py:212
fixMakerTool422(alg)
Definition run_gep.py:218
fixSnapshotTool422(alg)
Definition run_gep.py:230