ATLAS Offline Software
Loading...
Searching...
No Matches
AODtoNTUP_PILEUP_Skeleton.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3import sys
4from PyJobTransforms.CommonRunArgsToFlags import commonRunArgsToFlags
5from PyJobTransforms.TransformUtils import processPreExec, processPreInclude, processPostExec, processPostInclude
6
7# force no legacy job properties
8from AthenaCommon import JobProperties
9JobProperties.jobPropertiesDisallowed = True
10
11from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
12from AthenaConfiguration.ComponentFactory import CompFactory
13
14
15def PRWOutputCfg(flags, output_name="NTUP_PILEUP"):
16 from MuonConfig.MuonConfigUtils import setupHistSvcCfg
17 return setupHistSvcCfg(flags, outFile =flags.Output.HISTFileName, outStream = output_name)
18
19
20def PileupReweightingProviderCfg(flags, **kwargs):
21 cfg = ComponentAccumulator()
22 kwargs.setdefault("ConfigOutputStream", "NTUP_PILEUP")
23 from AsgAnalysisAlgorithms.PileupReweightingAlgConfig import PileupReweightingProviderToolCfg
24 kwargs.setdefault("Tool", cfg.addPublicTool(cfg.popToolsAndMerge(PileupReweightingProviderToolCfg(flags))))
25 cfg.addEventAlgo(CompFactory.CP.PileupReweightingProvider(**kwargs))
26 return cfg
27
28
29def PRWSteeringCfg(flags):
30 cfg = ComponentAccumulator()
31 cfg.merge(PileupReweightingProviderCfg(flags))
32
33 #include("AthAnalysisBaseComps/SuppressLogging.py") #Optional include to suppress as much athena output as possible
34 #https://gitlab.cern.ch/atlas/athena/-/blob/release/23.0.20/Control/AthAnalysisBaseComps/share/SuppressLogging.py
35 cfg.merge(PRWOutputCfg(flags))
36 return cfg
37
38
39def fromRunArgs(runArgs):
40 from AthenaCommon.Logging import logging
41 log = logging.getLogger('PRWConfig_tf')
42 log.info( '****************** STARTING AODtoNTUP_PILEUP *****************' )
43
44 log.info('**** Transformation run arguments')
45 log.info(str(runArgs))
46
47 log.info('**** Setting-up configuration flags')
48 from AthenaConfiguration.AllConfigFlags import initConfigFlags
49 flags = initConfigFlags()
50
51 commonRunArgsToFlags(runArgs, flags)
52
53 if hasattr(runArgs, 'inputAODFile'):
54 flags.Input.Files = runArgs.inputAODFile
55 else:
56 raise RuntimeError('No input AOD file defined')
57
58 if hasattr(runArgs, 'outputNTUP_PILEUPFile'):
59 flags.Output.HISTFileName = runArgs.outputNTUP_PILEUPFile # FIXME Add a separate output file type flag??
60 else:
61 log.warning('No output file set')
62 flags.Output.HISTFileName = 'output.NTUP_PILEUP.root' # FIXME Add a separate output file type flag??
63
64 # Pre-include
65 processPreInclude(runArgs, flags)
66
67 # Pre-exec
68 processPreExec(runArgs, flags)
69
70 # To respect --athenaopts
71 flags.fillFromArgs()
72
73 # Lock flags
74 flags.lock()
75
76 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
77 cfg = MainServicesCfg(flags)
78
79 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
80 cfg.merge(PoolReadCfg(flags))
81
82 cfg.merge(PRWSteeringCfg(flags))
83
84 # Post-include
85 processPostInclude(runArgs, flags, cfg)
86
87 # Post-exec
88 processPostExec(runArgs, flags, cfg)
89
90 import time
91 tic = time.time()
92 # Run the final accumulator
93 sc = cfg.run()
94 log.info("Ran PRWConfig_tf in " + str(time.time()-tic) + " seconds")
95
96 sys.exit(not sc.isSuccess())
PRWOutputCfg(flags, output_name="NTUP_PILEUP")