ATLAS Offline Software
RunEBWeightsComputation.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #
5 
6 from AthenaConfiguration.ComponentFactory import CompFactory
7 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
8 from AthenaConfiguration.AutoConfigFlags import GetFileMD
9 
10 from AthenaCommon.Logging import logging
11 log = logging.getLogger('RunEBWeightsComputation.py')
12 
13 
14 def ebComputingAlg(flags, itemsMap = {}):
15  acc = ComponentAccumulator()
16 
17  ebAlg = CompFactory.EnhancedBiasWeightCompAlg()
18  ebAlg.ChainToItemMap = itemsMap
19  ebAlg.OutputLevel = flags.Exec.OutputLevel
20  acc.addEventAlgo(ebAlg)
21 
22  return acc
23 
24 
25 # Read the keys from the COOL database
26 def getConfigKeys(inputFile):
27  run = GetFileMD(inputFile)['runNumbers'][0]
28  lb = GetFileMD(inputFile)['lumiBlockNumbers'][0]
29 
30  from TrigConfigSvc.TrigConfigSvcCfg import getTrigConfFromCool
31  return getTrigConfFromCool(run, lb)
32 
33 
34 # Read the seeds of low and medium chain, not available in the menu (they are hlt seeded)
35 def readHLTSeeds(smk=-1, db=""):
36  from TrigConfIO.HLTTriggerConfigAccess import HLTJobOptionsAccess
37  joData = HLTJobOptionsAccess(dbalias = db, smkey = smk)
38 
39  import ast
40 
41  chainToItem = {}
42  chainToItem["HLT_eb_low_L1RD2_FILLED"] = ast.literal_eval(joData.properties("EnhancedBiasHypo.HLT_eb_low_L1RD2_FILLED")["L1ItemNames"])
43  chainToItem["HLT_eb_medium_L1RD2_FILLED"] = ast.literal_eval(joData.properties("EnhancedBiasHypo.HLT_eb_medium_L1RD2_FILLED")["L1ItemNames"])
44 
45  return chainToItem
46 
47 
48 if __name__=='__main__':
49  import sys
50  from argparse import ArgumentParser
51  parser = ArgumentParser()
52  parser.add_argument('--maxEvents', type=int, help='Maximum number of events to process')
53  parser.add_argument('--skipEvents', type=int, help='Number of events to skip')
54  parser.add_argument('--skipHLTSeeds', action="store_true", help='Read HLT seeds for EB items, used for pp EB runs')
55  parser.add_argument('--loglevel', type=int, default=3, help='Verbosity level: 1 - VERBOSE, 2 - DEBUG, 3 - INFO')
56  parser.add_argument('flags', nargs='*', help='Config flag overrides')
57  args = parser.parse_args()
58 
59  log.setLevel(args.loglevel)
60 
61  # Set the Athena configuration flags
62  from AthenaConfiguration.AllConfigFlags import initConfigFlags
63  from AthenaConfiguration.TestDefaults import defaultGeometryTags
64  # verbosity defined in Control/AthenaCommon/python/Constants.py
65  flags = initConfigFlags()
66  flags.fillFromArgs(args.flags)
67  flags.Trigger.triggerConfig = 'DB'
68  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
69  flags.Exec.OutputLevel = args.loglevel
70  flags.Trigger.doNavigationSlimming = False
71  flags.Exec.EventPrintoutInterval = 1000
72  flags.lock()
73 
74  # Initialize configuration object, add accumulator, merge, and run.
75  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
76  cfg = MainServicesCfg(flags)
77 
78  isRunningFromAOD = True if len(flags.Input.Collections) else False
79  if isRunningFromAOD:
80  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
81  cfg.merge(PoolReadCfg(flags))
82  else:
83  from TriggerJobOpts.TriggerRecoConfig import TriggerRecoCfg
84  cfg.merge(TriggerRecoCfg(flags))
85 
86  configKeys = getConfigKeys(flags.Input.Files)
87  itemsMap = {} if args.skipHLTSeeds else readHLTSeeds(smk = configKeys["SMK"], db = configKeys["DB"])
88  cfg.merge(ebComputingAlg(flags, itemsMap))
89 
90  # If you want to turn on more detailed messages ...
91  # exampleMonitorAcc.getEventAlgo('ExampleMonAlg').OutputLevel = 2 # DEBUG
92  cfg.printConfig(withDetails=False) # set True for exhaustive info
93 
94  sc = cfg.run(args.maxEvents)
95  sys.exit(0 if sc.isSuccess() else 1)
python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True, maxLevel='peeker')
Definition: AutoConfigFlags.py:65
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
RunEBWeightsComputation.readHLTSeeds
def readHLTSeeds(smk=-1, db="")
Definition: RunEBWeightsComputation.py:35
python.TrigConfigSvcCfg.getTrigConfFromCool
def getTrigConfFromCool(runNumber, lumiBlock)
Definition: TrigConfigSvcCfg.py:24
RunEBWeightsComputation.getConfigKeys
def getConfigKeys(inputFile)
Definition: RunEBWeightsComputation.py:26
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
RunEBWeightsComputation.ebComputingAlg
def ebComputingAlg(flags, itemsMap={})
Definition: RunEBWeightsComputation.py:14
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.TriggerRecoConfig.TriggerRecoCfg
def TriggerRecoCfg(flags)
Definition: TriggerRecoConfig.py:17
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69