ATLAS Offline Software
Loading...
Searching...
No Matches
HistNtupConfig.py
Go to the documentation of this file.
1#!/usr/bin/env athena.py
2# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
4from AthenaConfiguration.ComponentFactory import CompFactory
5from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6from AthenaCommon.Constants import DEBUG, INFO
7
8# --------------------------------------------------------------------
9# Configure HistAlg and NtupAlg algorithms
10
11# helper function to add xAOD::EventInfo creating algorythm
12# both HistAlg and NtupAlg access it as input data
14 result = ComponentAccumulator()
15 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
16 EICA = EventInfoCnvAlgCfg(flags, inputKey="McEventInfo", outputKey="EventInfo", disableBeamSpot=True, OutputLevel=DEBUG)
17 result.merge(EICA, sequenceName="AthAlgSeq")
18 # Select HBOOK or ROOT persistency (ROOT is default)
19 result.setAppProperty("HistogramPersistency","ROOT")
20 return result
21
22
23def HistAlgConf(flags):
24 result = ComponentAccumulator()
25
26 result.merge( addEventInfoConv(flags) )
27
28 alg = CompFactory.AthEx.Hist("Hist", OutputLevel=DEBUG )
29 result.addEventAlgo(alg)
30
31 # Configure the histogram output file, alias 'stat'
32 svc = CompFactory.THistSvc("THistSvc", OutputLevel=INFO)
33 svc.Output += [ "stat DATAFILE='hist.root' OPT='RECREATE'" ]
34 result.addService(svc)
35
36 return result
37
38def NtupAlgConf(flags):
39 result = ComponentAccumulator()
40
41 result.merge( addEventInfoConv(flags) )
42
43 alg = CompFactory.AthEx.Ntup("Ntup", OutputLevel=DEBUG)
44 result.addEventAlgo(alg)
45
46 svc = CompFactory.THistSvc("THistSvc", OutputLevel=INFO)
47 # Ntuples output file, alias 'rec'
48 svc.Output += [ "rec DATAFILE='ntuple.root' OPT='RECREATE'" ]
49
50 result.addService(svc)
51 return result
52
53
54# _______________ main _______________
55if __name__ == "__main__":
56 # Setup configuration flags
57 from AthenaConfiguration.AllConfigFlags import initConfigFlags
58 flags = initConfigFlags()
59 flags.Input.Files = []
60 flags.Input.RunNumbers = [12345]
61 flags.Input.TimeStamps = [1] # dummy value
62 flags.Input.TypedCollections = [] # workaround for building xAOD::EventInfo without input files
63 flags.Exec.MaxEvents = 10
64 flags.Scheduler.ShowControlFlow = True
65 flags.Scheduler.ShowDataDeps = True
66 flags.fillFromArgs()
67 flags.lock()
68
69 # Setup python logging level
70 from AthenaCommon.Logging import log
71 log.setLevel(flags.Exec.OutputLevel)
72
73 # The example runs with no input file. We configure it with the McEventSelector
74 from AthenaConfiguration.MainServicesConfig import MainEvgenServicesCfg
75 cfg = MainEvgenServicesCfg(flags,withSequences=True)
76
77 # Configure the C++ message service
78 msgSvc = CompFactory.MessageSvc("MessageSvc", useColors=True)
79 cfg.addService(msgSvc)
80
81 # Configure all algorithms used by the example
82 cfg.merge(HistAlgConf(flags))
83 cfg.merge(NtupAlgConf(flags))
84
85 # Run the example
86 import sys
87 sys.exit(cfg.run().isFailure())
88
addEventInfoConv(flags)