ATLAS Offline Software
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 
66  # If the dataset name is in the input files path, then it will be fetched from there
67  # Note to enable autolookup, first run "lsetup pyami; voms-proxy-init -voms atlas" and enter your grid pass phrase
68  xsec = args.MCCrossSection
69  fEff = args.MCFilterEfficiency
70  dset = args.MCDatasetName
71  if flags.Input.isMC and xsec == 0: # If the input file is MC then make sure we have the needed info
72  from RatesAnalysis.GetCrossSectionAMITool import GetCrossSectionAMI
73  amiTool = GetCrossSectionAMI()
74  if dset == "": # Can we get the dataset name from the input file path?
75  dset = amiTool.getDatasetNameFromPath(flags.Input.Files[0])
76  amiTool.queryAmi(dset)
77  xsec = amiTool.crossSection
78  fEff = amiTool.filterEfficiency
79 
80  ebw = CompFactory.EnhancedBiasWeighter('EnhancedBiasRatesTool')
81  ebw.RunNumber = flags.Input.RunNumbers[0]
82  ebw.UseBunchCrossingData = useBunchCrossingData
83  ebw.IsMC = flags.Input.isMC
84  # The following three are only needed if isMC == true
85  ebw.MCCrossSection = xsec
86  ebw.MCFilterEfficiency = fEff
87  ebw.MCKFactor = args.MCKFactor
88  ebw.MCIgnoreGeneratorWeights = args.MCIgnoreGeneratorWeights
89  cfg.addPublicTool(ebw)
90 
91  rates = CompFactory.RatesEmulationExample()
92  rates.DoTriggerGroups = args.disableTriggerGroups
93  rates.DoGlobalGroups = args.disableGlobalGroups
94  rates.DoExpressRates = args.disableExpressGroup
95  rates.DoUniqueRates = args.disableUniqueRates
96  rates.DoHistograms = args.disableHistograms
97  rates.UseBunchCrossingData = useBunchCrossingData
98  rates.TargetLuminosity = args.targetLuminosity
99  rates.VetoStartOfTrain = args.vetoStartOfTrain
100  rates.EnableLumiExtrapolation = args.disableLumiExtrapolation
101  rates.EnhancedBiasRatesTool = ebw
102  rates.OutputLevel = args.loglevel
103  rates.TrigConfigSvc = ""
104  rates.TrigDecisionTool = ""
105 
106  cfg.addEventAlgo(rates)
107 
108  # Setup for accessing bunchgroup data from the DB
109  # if useBunchCrossingData:
110  # from LumiBlockComps.BunchCrossingCondAlgConfig import BunchCrossingCondAlgCfg
111  # cfg.merge(BunchCrossingCondAlgCfg(flags))
112 
113  # If you want to turn on more detailed messages ...
114  # exampleMonitorAcc.getEventAlgo('ExampleMonAlg').OutputLevel = 2 # DEBUG
115  cfg.printConfig(withDetails=False) # set True for exhaustive info
116 
117  sc = cfg.run(args.maxEvents)
118  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