ATLAS Offline Software
RatesAnalysisFullMenu.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 #
5 
6 if __name__=='__main__':
7  import sys
8 
9  # Initialise Athena config flags to get and customise the argument parser
10  from AthenaConfiguration.AllConfigFlags import initConfigFlags
11  flags = initConfigFlags()
12  parser = flags.getArgumentParser()
13  #
14  parser.add_argument('--disableGlobalGroups', action='store_true', help='Turn off global groups')
15  parser.add_argument('--disableTriggerGroups', action='store_true', help='Turn off per-trigger groups')
16  parser.add_argument('--disableExpressGroup', action='store_true', help='Turn off express stream rates')
17  parser.add_argument('--disableUniqueRates', action='store_true', help='Turn off unique rates (much faster!)')
18  parser.add_argument('--disableLumiExtrapolation', action='store_true', help='Turn off luminosity extrapolation')
19  #
20  parser.add_argument('--MCDatasetName', default='', type=str, help='For MC input: Name of the dataset, can be used instead of MCCrossSection, MCFilterEfficiency')
21  parser.add_argument('--MCCrossSection', default=0.0, type=float, help='For MC input: Cross section of process in nb')
22  parser.add_argument('--MCFilterEfficiency', default=1.0, type=float, help='For MC input: Filter efficiency of any MC filter (0.0 - 1.0)')
23  parser.add_argument('--MCKFactor', default=1.0, type=float, help='For MC input: Additional multiplicitive fudge-factor to the supplied cross section.')
24  parser.add_argument('--MCIgnoreGeneratorWeights', action='store_true', help='For MC input: Flag to disregard any generator weights.')
25  #
26  parser.add_argument('--doRatesVsPositionInTrain', action='store_true', help='Study rates vs BCID position in bunch train')
27  parser.add_argument('--vetoStartOfTrain', default=0, type=int, help='Number of BCIDs at the start of the train to veto, implies doRatesVsPositionInTrain')
28  #
29  parser.add_argument('--targetLuminosity', default=2e34, type=float)
30  #
31  parser.add_argument('--outputHist', default='RatesHistograms.root', type=str, help='Histogram output ROOT file')
32  parser.add_argument('--inputPrescalesHLTJSON', default='', type=str, help='JSON of HLT prescales to simulate applying when computing rates')
33  parser.add_argument('--inputPrescalesL1JSON', default='', type=str, help='JSON of L1 prescales to simulate applying when computing rates')
34  parser.add_argument('--ebWeightsDirectory', default='', type=str, help='Path to directory with local EB xml files')
35  #
36  parser.add_argument('flags', nargs='*', help='Config flag overrides')
37  #
38 
39  args = parser.parse_args()
40 
41  flags.Exec.EventPrintoutInterval = 1000
42  flags.Common.MsgSuppression = False
43  flags.Concurrency.NumThreads = 1
44 
45  args = flags.fillFromArgs(parser=parser)
46  flags.lock()
47 
48  useBunchCrossingData = (args.doRatesVsPositionInTrain or args.vetoStartOfTrain > 0)
49 
50  # Initialize configuration object, add accumulator, merge, and run.
51  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
52  from AthenaConfiguration.ComponentFactory import CompFactory
53 
54  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
55  cfg = MainServicesCfg(flags)
56  cfg.merge(PoolReadCfg(flags))
57 
58  histSvc = CompFactory.THistSvc()
59  histSvc.Output += ["RATESTREAM DATAFILE='" + args.outputHist + "' OPT='RECREATE'"]
60  cfg.addService(histSvc)
61 
62  # Minimal config needed to read metadata: MetaDataSvc & ProxyProviderSvc
63  from AthenaServices.MetaDataSvcConfig import MetaDataSvcCfg
64  cfg.merge(MetaDataSvcCfg(flags))
65 
66  from TrigConfxAOD.TrigConfxAODConfig import getxAODConfigSvc
67  cfgsvc = cfg.getPrimaryAndMerge(getxAODConfigSvc(flags))
68 
69  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
70  tdt = cfg.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
71 
72  # If the dataset name is in the input files path, then it will be fetched from there
73  # Note to enable autolookup, first run "lsetup pyami; voms-proxy-init -voms atlas" and enter your grid pass phrase
74  xsec = args.MCCrossSection
75  fEff = args.MCFilterEfficiency
76  dset = args.MCDatasetName
77  if flags.Input.isMC and xsec == 0: # If the input file is MC then make sure we have the needed info
78  from RatesAnalysis.GetCrossSectionAMITool import GetCrossSectionAMI
79  amiTool = GetCrossSectionAMI()
80  if dset == "": # Can we get the dataset name from the input file path?
81  dset = amiTool.getDatasetNameFromPath(flags.Input.Files[0])
82  amiTool.queryAmi(dset)
83  xsec = amiTool.crossSection
84  fEff = amiTool.filterEfficiency
85 
86  ebw = CompFactory.EnhancedBiasWeighter('EnhancedBiasRatesTool')
87  ebw.RunNumber = flags.Input.RunNumbers[0]
88  ebw.UseBunchCrossingData = useBunchCrossingData
89  ebw.IsMC = flags.Input.isMC
90  # The following three are only needed if isMC == true
91  ebw.MCCrossSection = xsec
92  ebw.MCFilterEfficiency = fEff
93  ebw.MCKFactor = args.MCKFactor
94  ebw.DoMultiSliceDiJet = False # Use the emulation example for this
95  ebw.MCIgnoreGeneratorWeights = args.MCIgnoreGeneratorWeights
96  ebw.EBWeightsDirectory = args.ebWeightsDirectory if args.ebWeightsDirectory else ""
97  cfg.addPublicTool(ebw)
98 
99  rates = CompFactory.FullMenu()
100  #rates.PrescalesJSON = args.inputPrescalesJSON
101  rates.DoTriggerGroups = not args.disableTriggerGroups
102  rates.DoGlobalGroups = not args.disableGlobalGroups
103  rates.DoExpressRates = not args.disableExpressGroup
104  rates.DoUniqueRates = not args.disableUniqueRates
105  rates.UseBunchCrossingData = useBunchCrossingData
106  rates.TargetLuminosity = args.targetLuminosity
107  rates.VetoStartOfTrain = args.vetoStartOfTrain
108  rates.EnableLumiExtrapolation = not args.disableLumiExtrapolation
109  rates.EnhancedBiasRatesTool = ebw
110  rates.TrigDecisionTool = tdt
111  rates.TrigConfigSvc = cfgsvc
112  rates.DoMultiSliceDiJet = False # Use the emulation example for this
113  rates.histogramSuffix = "" # Use the emulation example for this
114 
115  """Return all of the HLT items, and their lower chains
116  in a JSON menu
117  """
118  import json
119  from collections import OrderedDict as odict
120 
121  prescales = {}
122  #ESprescalesHLT = {} #TVS: to be done
123 
124  inputFilePSL1JSON=args.inputPrescalesL1JSON
125  inputFilePSHLTJSON=args.inputPrescalesHLTJSON
126 
127  if (inputFilePSL1JSON!="" and inputFilePSHLTJSON!=""):
128  with open(inputFilePSL1JSON,'r') as fh:
129  l1ps_json_file = json.load(fh, object_pairs_hook = odict)
130 
131  with open(inputFilePSHLTJSON,'r') as fh:
132  hltps_json_file = json.load(fh, object_pairs_hook = odict)
133 
134  for chain_name, ch in l1ps_json_file['cutValues'].items():
135  prescaleL1_input = ch['info'].split()[1]
136  p = {'prescale': float(prescaleL1_input)}
137  prescales[chain_name] = p
138 
139  for chain_name, ch in hltps_json_file['prescales'].items():
140  prescaleHLT_input = ch['prescale']
141  prescaleExpressHLT_input = ch['prescale_express'] if 'prescale_express' in ch else -1
142 
143  p = {
144  'prescale': float(prescaleHLT_input),
145  'prescale_express': float(prescaleExpressHLT_input)
146  }
147  prescales[chain_name] = p
148 
149 
150  rates.PrescalesJSON = prescales
151 
152 
153  cfg.addEventAlgo(rates)
154 
155  # Setup for accessing bunchgroup data from the DB
156  if useBunchCrossingData:
157  from LumiBlockComps.BunchCrossingCondAlgConfig import BunchCrossingCondAlgCfg
158  cfg.merge(BunchCrossingCondAlgCfg(flags))
159 
160  # If you want to turn on more detailed messages ...
161  # exampleMonitorAcc.getEventAlgo('ExampleMonAlg').OutputLevel = 2 # DEBUG
162  cfg.printConfig(withDetails=False) # set True for exhaustive info
163 
164  sc = cfg.run(flags.Exec.MaxEvents)
165  sys.exit(0 if sc.isSuccess() else 1)
python.RatesAnalysisFullMenu.float
float
Definition: RatesAnalysisFullMenu.py:21
TrigConfxAODConfig.getxAODConfigSvc
def getxAODConfigSvc(flags)
Definition: TrigConfxAODConfig.py:5
python.BunchCrossingCondAlgConfig.BunchCrossingCondAlgCfg
def BunchCrossingCondAlgCfg(flags)
Definition: BunchCrossingCondAlgConfig.py:8
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:312
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:71
python.TriggerInterface.TrigDecisionToolCfg
def TrigDecisionToolCfg(flags)
Definition: TriggerInterface.py:14
Trk::open
@ open
Definition: BinningType.h:40
python.MetaDataSvcConfig.MetaDataSvcCfg
def MetaDataSvcCfg(flags, toolNames=[], tools=[])
Definition: MetaDataSvcConfig.py:6
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:71
Trk::split
@ split
Definition: LayerMaterialProperties.h:38