9 @brief Script to print out truth events for HepMC (HITS, RDO) or TruthEvent (AOD)
12 if __name__==
'__main__':
14 from argparse
import RawTextHelpFormatter
15 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
17 parser = flags.getArgumentParser(description=
'Run ASCII dumper of Truth on files with either HepMC or TruthEvent format.\
18 User MUST provide file(s) to read (--filesInput).\
19 Also, use --doPtEtaPhi for pt/eta/phi printout, and --skipEvents, --evtMax to select events.')
20 parser.add_argument(
'--doPUEventPrintout', action=
'store_true',
21 help=
'Print out PU event for xAODTruthReader')
22 parser.add_argument(
'--doPtEtaPhi', action=
'store_true',
23 help=
'Print out particle 4-mom as pt,eta,phi. Default is px,py,pz.')
24 parser.set_defaults(threads=1)
25 args, _ = parser.parse_known_args()
27 from AthenaCommon.Logging
import log
29 flags.Input.Files = args.filesInput
30 log.info(
"Checking collections in the input file")
31 collTypes = [ c.split(
"#")[0]
for c
in flags.Input.TypedCollections]
32 MCCollectionName =
None
33 TruthCollectionName =
None
34 getName =
lambda t: [ c.split(
"#")[1]
for c
in flags.Input.TypedCollections
if c.split(
"#")[0] == t][0]
36 if "McEventCollection" in collTypes:
37 MCCollectionName =
getName(
"McEventCollection")
38 log.info(
"Found McEventCollection#%s in the input, assuming it is HepMC", MCCollectionName)
39 elif "xAOD::TruthEventContainer" in collTypes:
40 TruthCollectionName =
getName(
"xAOD::TruthEventContainer")
41 log.info(
"Found xAOD::TruthEventContainer#%s in the input", TruthCollectionName)
43 log.error(
"Neither McEventCollection or xAOD::TruthEventContainer in the input file, can not dump truth")
50 flags.addFlag(
"HepMCContainerKey", MCCollectionName)
52 flags.addFlag(
"xAODTruthEventContainerKey",
"TruthEvents")
53 flags.addFlag(
"xAODTruthPileupEventContainerKey",
"TruthPileupEvents")
54 if args.doPUEventPrintout:
55 flags.addFlag(
"DoPUEventPrintout",
True)
57 flags.addFlag(
"DoPUEventPrintout",
False)
60 flags.Input.Files = [
'truth.pool.root']
62 flags.addFlag(
"Do4momPtEtaPhi",
True)
64 flags.addFlag(
"Do4momPtEtaPhi",
False)
66 flags.fillFromArgs(parser=parser)
69 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
70 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
74 from xAODTruthCnv.xAODTruthCnvConfig
import HepMCTruthReaderCfg
77 from xAODTruthCnv.xAODTruthCnvConfig
import xAODTruthReaderCfg
80 acc.store(
open(
"HepMCTruthReader.pkl",
"wb"))
82 from AthenaConfiguration.Utils
import setupLoggingLevels
85 statusCode = acc.run()
86 assert statusCode.isSuccess()
is True,
"Application execution did not succeed"