Skip to content
Snippets Groups Projects
Commit e01b1ba5 authored by Luca Giommi's avatar Luca Giommi Committed by Danilo Piparo
Browse files

Changes in the doc, change in the error message and in calling TSimpleAnalysis functions

parent 5c68ab5c
Branches
Tags
No related merge requests found
#!/usr/bin/env @python@ #!/usr/bin/env @python@
# ROOT command line tools: rootdrawtree
# Author: Luca Giommi
# Mail: luca.giommi2@studio.unibo.it
# Date: 08/09/16
import ROOT import ROOT
import sys
import argparse import argparse
parser = argparse.ArgumentParser() import textwrap
parser.add_argument('inputFile', nargs='?', default='', help = "inputFile is the input file") from sys import stderr
parser.add_argument('-o', '--output', default='', action='store', dest='output', help='Output name')
parser.add_argument('-r', '--root', default=[], nargs='*', dest='root', help='Input root files') parser = argparse.ArgumentParser(
parser.add_argument('-nt', '--ntuple', default='', action='store', dest='ntupla', help='Name of the ntuple') formatter_class=argparse.RawDescriptionHelpFormatter,
parser.add_argument('-hs', '--histo', default=[], nargs='*', dest='histoName', help='Expression to build histograms in the form "histoName=histo if histoCut"') description=textwrap.dedent('''\
Python script that loops over a chain to create histograms.
There are two ways to do it: one is parsing the name of the configuration file as argument,
that must have a proper syntax as shown in the class documentation of TSimpleAnalysis.
Example:
user@users-desktop:~$ rootdrawtree input_file.txt # input_file.txt is the configuration file
The other way is to pass as arguments the name of the output file, the name of the .root input
files, the expressions (that will be shown in the histograms) and the name of the tree (that
is optional if there is only one tree inside the first .root input file).
Examples:
user@users-desktop:~$ rootdrawtree --output output.root --input hsimple.root --tree ntuple --histo 'hpxpy=px:py if px>2'
user@users-desktop:~$ rootdrawtree --output output.root --input hsimple.root hsimple2.root --histo 'hpx=px' 'hpxpy=px:py if px>2'
'''))
parser.add_argument('configFile', nargs='?', default='', help = "Configuration file")
parser.add_argument('-o', '--output', default='', action='store', dest='output', help='Name of the output file in which will be stored the histograms')
parser.add_argument('-i', '--input', default=[], nargs='*', dest='inputFiles', help='.root input files')
parser.add_argument('-t', '--tree', default='', action='store', dest='tree', help='Name of the tree')
parser.add_argument('-hs', '--histo', default=[], nargs='*', dest='histoExpr', help='Expressions to build the histograms in the form "NAME = EXPRESSION if CUT"')
args = parser.parse_args() args = parser.parse_args()
if (args.inputFile != '' and args.output=='' or args.root==[] or args.ntupla=='' or args.histoName==[]):
ROOT.gInterpreter.ProcessLine("#include \"TSimpleAnalysis.h\"") if (args.configFile != '' and (args.output != '' or args.inputFiles != [] or args.histoExpr != [] or args.tree != '')):
ROOT.RunSimpleAnalysis(args.inputFile) stderr.write("Error: both configuration file and options are provided \n")
elif (args.inputFile=='' and args.output!='' and args.root!=[] and args.ntupla!='' and args.histoName!=[]): if (args.configFile != ''):
ROOT.gInterpreter.ProcessLine("#include \"TSimpleAnalysis.h\"") a = ROOT.TSimpleAnalysis(args.configFile)
inputfile=ROOT.vector("string")(len(args.root)) a.Configure()
for i,s in enumerate(args.root):
inputfile[i]=s
expr=ROOT.vector("string")(len(args.histoName))
for k,l in enumerate(args.histoName):
expr[k]=l
a = ROOT.TSimpleAnalysis(args.output, inputfile, args.ntupla, expr)
a.Run() a.Run()
else: else:
print "Invalid argument set" inputfile = ROOT.vector("string")(len(args.inputFiles))
for i,s in enumerate(args.inputFiles):
inputfile[i] = s
expr = ROOT.vector("string")(len(args.histoExpr))
for k,l in enumerate(args.histoExpr):
expr[k]=l
a = ROOT.TSimpleAnalysis(args.output, inputfile, expr, args.tree)
a.Run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment