ATLAS Offline Software
Loading...
Searching...
No Matches
MuonEfficiencyCorrectionsCfg.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3
4from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
5from AthenaConfiguration.ComponentFactory import CompFactory
6
7def MuonScaleFactorTestAlgCfg(flags, name="MuonScaleFactorTestAlg", **kwargs):
8 result = ComponentAccumulator()
9 from MuonSelectorTools.MuonSelectorToolsConfig import MuonSelectionToolCfg
10 kwargs.setdefault("MuonSelectionTool", result.popToolsAndMerge(MuonSelectionToolCfg(flags)))
11 from AsgAnalysisAlgorithms.PileupReweightingAlgConfig import PileupReweightingToolCfg
12 kwargs.setdefault("PileupReweightingTool", result.popToolsAndMerge(PileupReweightingToolCfg(flags)))
13 the_alg = CompFactory.CP.MuonScaleFactorTestAlg(name, **kwargs)
14 result.addEventAlgo(the_alg, primary = True)
15 return result
16
17def MuonEfficiencyCorrectionsCfg(flags, name="MuonEffiCorrections", **kwargs):
18 result = ComponentAccumulator()
19 kwargs.setdefault("ApplyKinematicSystematic", False)
20 eff_tool = CompFactory.CP.MuonEfficiencyScaleFactors(name, **kwargs)
21 result.setPrivateTools(eff_tool)
22 return result
23
24def setupHistSvcCfg(flags, out_file="EffTester.root"):
25 result = ComponentAccumulator()
26 if len(out_file) == 0: return result
27 histSvc = CompFactory.THistSvc(Output=["MUONEFFTESTER DATAFILE='{out_file}', OPT='RECREATE'".format(out_file = out_file)])
28 result.addService(histSvc, primary=True)
29 return result
30
32 from argparse import ArgumentParser
33
34 parser = ArgumentParser()
35 parser.add_argument("--threads", type=int, help="number of threads", default=1)
36 parser.add_argument("--inputFile", "-i", default=[
37 "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/Tier0ChainTests/mc20_13TeV.361107.PowhegPythia8EvtGen_AZNLOCTEQ6L1_Zmumu.recon.AOD.e3601_s3681_r13167/AOD.27312826._000061.pool.root.1"
38 ],
39 help="Input file to run on ", nargs="+")
40 parser.add_argument("--outRootFile", default="EffiDump.root", help="Output ROOT file to dump the geomerty")
41 parser.add_argument("--maxEvents", type=int, help="Maximum events to run on", default = -1)
42 return parser
43
44
45
46if __name__ == "__main__":
47 from AthenaConfiguration.AllConfigFlags import initConfigFlags
48
49 args = setupArgParser().parse_args()
50
51 flags = initConfigFlags()
52 flags.Concurrency.NumThreads = args.threads
53 flags.Concurrency.NumConcurrentEvents = args.threads # Might change this later, but good enough for the moment.
54 flags.Input.Files = args.inputFile
55 flags.Scheduler.ShowDataDeps = True
56 flags.Scheduler.ShowDataFlow = True
57 flags.lock()
58 flags.dump(evaluate=True)
59
60
61 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
62 cfg = MainServicesCfg(flags)
63
64 from AthenaConfiguration.Enums import Format
65 if flags.Input.Format == Format.POOL:
66 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
67 cfg.merge(PoolReadCfg(flags))
68
69 cfg.merge(setupHistSvcCfg(flags, out_file = args.outRootFile))
70 sf_tools= [cfg.popToolsAndMerge(MuonEfficiencyCorrectionsCfg(flags,
71 WorkingPoint="Loose"))]
72 cfg.merge(MuonScaleFactorTestAlgCfg(flags, EfficiencyTools = sf_tools))
73
74 cfg.printConfig(withDetails=True, summariseProps=True)
75
76 sc = cfg.run(args.maxEvents)
77 if not sc.isSuccess():
78 import sys
79 sys.exit("Execution failed")
80
81
82
83
84
85
86
87
MuonScaleFactorTestAlgCfg(flags, name="MuonScaleFactorTestAlg", **kwargs)
setupHistSvcCfg(flags, out_file="EffTester.root")