15 parser = argparse.ArgumentParser(
16 formatter_class=argparse.RawDescriptionHelpFormatter, prog=
'rootdrawtree',
17 description=textwrap.dedent(
'''\
18Python script that loops over a chain to create histograms.
19There are two ways to do it: one is parsing the name of the configuration file as argument,
20that must have a proper syntax as shown in the class documentation of TSimpleAnalysis.
23user@users-desktop:~$ rootdrawtree input_file.txt # input_file.txt is the configuration file
25The other way is to pass as arguments the name of the output file, the name of the .root input
26files, the expressions (that will be shown in the histograms) and the name of the tree (that
27is optional if there is only one tree inside the first .root input file).
30user@users-desktop:~$ rootdrawtree --output output.root --input hsimple.root --tree ntuple --histo 'hpxpy=px:py if px>2'
31user@users-desktop:~$ rootdrawtree --output output.root --input hsimple.root hsimple2.root --histo 'hpx=px' 'hpxpy=px:py if px>2'
35 parser.add_argument(
'configFile', nargs=
'?', default=
'', help =
"Configuration file")
36 parser.add_argument(
'-o',
'--output', default=
'', action=
'store', dest=
'output', help=
'Name of the output file in which will be stored the histograms')
37 parser.add_argument(
'-i',
'--input', default=[], nargs=
'*', dest=
'inputFiles', help=
'.root input files')
38 parser.add_argument(
'-t',
'--tree', default=
'', action=
'store', dest=
'tree', help=
'Name of the tree')
39 parser.add_argument(
'-hs',
'--histo', default=[], nargs=
'*', dest=
'histoExpr', help=
'Expressions to build the histograms in the form "NAME = EXPRESSION if CUT"')
42if __name__ ==
"__main__":
45 args = parser.parse_args()
48 if (args.configFile !=
'' and (args.output !=
'' or args.inputFiles != []
or args.histoExpr != []
or args.tree !=
'')):
49 stderr.write(
"Error: both configuration file and options are provided \n")
51 if (args.configFile !=
''):
52 a = ROOT.TSimpleAnalysis(args.configFile)
56 if len(args.inputFiles) == 0:
57 stderr.write(
"Error: neither configuration file nor input files are provided\n")
59 inputfile = ROOT.vector(
"string")(len(args.inputFiles))
60 for i,s
in enumerate(args.inputFiles):
62 if len(args.histoExpr) == 0:
63 stderr.write(
"Error: neither configuration file nor expression is provided\n")
65 expr = ROOT.vector(
"string")(len(args.histoExpr))
66 for k,l
in enumerate(args.histoExpr):
68 a = ROOT.TSimpleAnalysis(args.output, inputfile, expr, args.tree)