Loading [MathJax]/jax/output/SVG/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RatesEmulationExample.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 if __name__=='__main__':
7  import sys
8  from argparse import ArgumentParser
9  parser = ArgumentParser()
10  #
11  parser.add_argument('--disableHistograms', action='store_false', help='Turn off histograming')
12  parser.add_argument('--disableGlobalGroups', action='store_false', help='Turn off global groups')
13  parser.add_argument('--disableTriggerGroups', action='store_false', help='Turn off per-trigger groups')
14  parser.add_argument('--disableExpressGroup', action='store_false', help='Turn off express stream rates')
15  parser.add_argument('--disableUniqueRates', action='store_false', help='Turn off unique rates (much faster!)')
16  parser.add_argument('--disableLumiExtrapolation', action='store_false', help='Turn off luminosity extrapolation')
17  #
18  parser.add_argument('--MCDatasetName', default='', type=str, help='For MC input: Name of the dataset, can be used instead of MCCrossSection, MCFilterEfficiency')
19  parser.add_argument('--MCCrossSection', default=0.0, type=float, help='For MC input: Cross section of process in nb')
20  parser.add_argument('--MCFilterEfficiency', default=1.0, type=float, help='For MC input: Filter efficiency of any MC filter (0.0 - 1.0)')
21  parser.add_argument('--MCKFactor', default=1.0, type=float, help='For MC input: Additional multiplicitive fudge-factor to the supplied cross section.')
22  parser.add_argument('--MCIgnoreGeneratorWeights', action='store_true', help='For MC input: Flag to disregard any generator weights.')
23  #
24  parser.add_argument('--outputHist', default='RatesHistograms.root', type=str, help='Histogram output ROOT file')
25  #
26  parser.add_argument('--targetLuminosity', default=2e34, type=float)
27  #
28  parser.add_argument('--doRatesVsPositionInTrain', action='store_true', help='Study rates vs BCID position in bunch train')
29  parser.add_argument('--vetoStartOfTrain', default=0, type=int, help='Number of BCIDs at the start of the train to veto, implies doRatesVsPositionInTrain')
30  #
31  parser.add_argument('--maxEvents', type=int, help='Maximum number of events to process')
32  parser.add_argument('--loglevel', type=int, default=3, help='Verbosity level')
33  parser.add_argument('flags', nargs='*', help='Config flag overrides')
34  args = parser.parse_args()
35 
36  # Set the Athena configuration flags
37  from AthenaConfiguration.AllConfigFlags import initConfigFlags
38 
39  # Set the Athena configuration flags
40  flags = initConfigFlags()
41  flags.Input.Files = ["root://eosatlas.cern.ch//eos/atlas/atlasdatadisk/rucio/data16_13TeV/8d/de/AOD.10654269._000566.pool.root.1"]
42  flags.Exec.OutputLevel = args.loglevel
43  flags.Exec.EventPrintoutInterval = 1000
44  flags.fillFromArgs(args.flags)
45  useBunchCrossingData = (args.doRatesVsPositionInTrain or args.vetoStartOfTrain > 0)
46 
47  flags.lock()
48 
49  # Initialize configuration object, add accumulator, merge, and run.
50  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
51  from AthenaConfiguration.ComponentFactory import CompFactory
52 
53  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
54  cfg = MainServicesCfg(flags)
55  cfg.merge(PoolReadCfg(flags))
56 
57  histSvc = CompFactory.THistSvc()
58  histSvc.Output += ["RATESTREAM DATAFILE='" + args.outputHist + "' OPT='RECREATE'"]
59  cfg.addService(histSvc)
60 
61  # Minimal config needed to read metadata: MetaDataSvc & ProxyProviderSvc
62  from AthenaServices.MetaDataSvcConfig import MetaDataSvcCfg
63  cfg.merge(MetaDataSvcCfg(flags))
64 
65  cfgsvc = CompFactory.TrigConf.xAODConfigSvc('xAODConfigSvc')
66  cfg.addService(cfgsvc)
67 
68  tdt = CompFactory.Trig.TrigDecisionTool('TrigDecisionTool')
69  tdt.TrigConfigSvc = cfgsvc
70  tdt.NavigationFormat = "TrigComposite"
71  cfg.addPublicTool(tdt)
72 
73  # If the dataset name is in the input files path, then it will be fetched from there
74  # Note to enable autolookup, first run "lsetup pyami; voms-proxy-init -voms atlas" and enter your grid pass phrase
75  xsec = args.MCCrossSection
76  fEff = args.MCFilterEfficiency
77  dset = args.MCDatasetName
78  if flags.Input.isMC and xsec == 0: # If the input file is MC then make sure we have the needed info
79  from RatesAnalysis.GetCrossSectionAMITool import GetCrossSectionAMI
80  amiTool = GetCrossSectionAMI()
81  if dset == "": # Can we get the dataset name from the input file path?
82  dset = amiTool.getDatasetNameFromPath(flags.Input.Files[0])
83  amiTool.queryAmi(dset)
84  xsec = amiTool.crossSection
85  fEff = amiTool.filterEfficiency
86 
87  ebw = CompFactory.EnhancedBiasWeighter('EnhancedBiasRatesTool')
88  ebw.RunNumber = flags.Input.RunNumbers[0]
89  ebw.UseBunchCrossingData = useBunchCrossingData
90  ebw.IsMC = flags.Input.isMC
91  # The following three are only needed if isMC == true
92  ebw.MCCrossSection = xsec
93  ebw.MCFilterEfficiency = fEff
94  ebw.MCKFactor = args.MCKFactor
95  ebw.MCIgnoreGeneratorWeights = args.MCIgnoreGeneratorWeights
96  cfg.addPublicTool(ebw)
97 
98  rates = CompFactory.RatesEmulationExample()
99  rates.DoTriggerGroups = args.disableTriggerGroups
100  rates.DoGlobalGroups = args.disableGlobalGroups
101  rates.DoExpressRates = args.disableExpressGroup
102  rates.DoUniqueRates = args.disableUniqueRates
103  rates.UseBunchCrossingData = useBunchCrossingData
104  rates.TargetLuminosity = args.targetLuminosity
105  rates.VetoStartOfTrain = args.vetoStartOfTrain
106  rates.EnableLumiExtrapolation = args.disableLumiExtrapolation
107  rates.EnhancedBiasRatesTool = ebw
108  rates.OutputLevel = args.loglevel
109  rates.TrigDecisionTool = tdt
110  rates.TrigConfigSvc = cfgsvc
111 
112  cfg.addEventAlgo(rates)
113 
114  # Setup for accessing bunchgroup data from the DB
115  # if useBunchCrossingData:
116  # from LumiBlockComps.BunchCrossingCondAlgConfig import BunchCrossingCondAlgCfg
117  # cfg.merge(BunchCrossingCondAlgCfg(flags))
118 
119  # If you want to turn on more detailed messages ...
120  # exampleMonitorAcc.getEventAlgo('ExampleMonAlg').OutputLevel = 2 # DEBUG
121  cfg.printConfig(withDetails=False) # set True for exhaustive info
122 
123  sc = cfg.run(args.maxEvents)
124  sys.exit(0 if sc.isSuccess() else 1)
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
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:69