Belle II Software development
embedding_merge.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12from mdst import add_mdst_output
13import argparse
14
15
16def prepare_path(File1, File2, FileOut):
17 """Prepare path for event embedding.
18 Input:
19 File1: primary input file (ROE)
20 File2: secondary input file (truth-matched signal)
21 FileOut: output embedded file.
22 """
23 main = basf2.Path()
24 indep = basf2.Path()
25 input1 = basf2.register_module('RootInput')
26 input1.param('inputFileName', File1)
27 main.add_module(input1).set_name("input1")
28
29 # and the other input
30 input2 = basf2.register_module('RootInput')
31 input2.param('inputFileName', File2)
32 input2.param('isSecondaryInput', True)
33 indep.add_module(input2).set_name("input2")
34
35 branches = ['ALL']
36
37 # merge it!
38 main.add_independent_merge_path(
39 indep,
40 merge_back_event=branches)
41
42 main.add_module('FixMergedObjects')
43 main.add_module("PostMergeUpdater")
44
45 # write out further reduced set
46
47 additionalBranches = ['MergedArrayIndices',
48 'EventLevelClusteringInfo_indepPath',
49 'EventLevelTrackingInfo_indepPath',
50 'EventMetaData_indepPath',
51 'TRGSummary_indepPath',
52 'SoftwareTriggerResult_indepPath'
53 ]
54
55 # output
56 add_mdst_output(main, filename=FileOut, additionalBranches=additionalBranches)
57
58 return main
59
60
61def get_parser():
62 """Handles the command-line argument parsing.
63
64 Returns:
65 argparse.Namespace: The parsed arguments.
66 """
67 parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
68 parser.add_argument('--filePrimary', help='Input file to be used as a primary (tag-side data or MC)', required=True)
69 parser.add_argument('--fileSecondary', help='Input file to be used as a secondary (signal-side MC)', required=True)
70 parser.add_argument("--fileOut", default='merged.root', help='Output file name')
71 return parser
72
73
74if __name__ == '__main__':
75 args = get_parser().parse_args()
76
77 path = prepare_path(args.filePrimary, args.fileSecondary, args.fileOut)
78
79 path.add_module('Progress')
80 basf2.process(path)
81 print(basf2.statistics)