7__version__ =
'$Revision: 505706 $'
8__author__ =
'Radist Morse radist.morse@gmail.com'
9__doc__ =
'Script for drawing LArG4Validation N tuples'
13 if (hname ==
"erec") :
14 return event.DepositedEnergy
15 elif (hname ==
"egen") :
16 return event.TrackEnergy
17 elif (hname ==
"cpu") :
19 elif (hname ==
"eta") :
21 elif (hname ==
"phi") :
23 elif (hname ==
"pt") :
25 elif (hname ==
"FC1_DeltaR") :
26 return sqrt(event.FC1_DeltaX*event.FC1_DeltaX+event.FC1_DeltaY*event.FC1_DeltaY)
27 if (hname ==
"erecegen") :
28 return event.DepositedEnergy / event.TrackEnergy
33 if (hname ==
"erec") :
35 elif (hname ==
"egen") :
37 elif (hname ==
"cpu") :
39 elif (hname ==
"eta") :
41 elif (hname ==
"phi") :
43 elif (hname ==
"pt") :
45 elif (hname ==
"FC1_DeltaR") :
47 elif (hname ==
"erecegen") :
48 return "#frac{E_{rec}}{E_{gen}}"
53from os.path
import isfile
54from optparse
import OptionParser
57usage =
"usage: %prog [options] root1 [root2 ...]"
59parser = OptionParser(usage=usage, version=
"%prog v1.0 $Id: LArG4ValidationPlotter.py 505706 2012-06-15 11:48:02Z gsedov $")
61parser.add_option(
"-s",
"--split",dest=
"split_canvas", help=
"Split canvas, format: 'HORIZ:VERT' (default = %default)")
62parser.add_option(
"-p",
"--plots",dest=
"plots", help=
"input file with histogram parameters")
63parser.add_option(
"-f",
"--files",dest=
"files", help=
"input file with files parameters")
64parser.add_option(
"-o",
"--output",dest=
"outputfile", help=
"output ps file")
65parser.add_option(
"-d",
"--divide",dest=
"divide",action=
"store_true", help=
"Calculate ratio between root files (divide all roots to first")
66parser.add_option(
"-m",
"--mean",dest=
"mean",action=
"store_true",help=
"Print mean value in the legend")
67parser.add_option(
"-z",
"--zero",dest=
"zero",action=
"store_true",help=
"Set minimums to zero")
69parser.set_defaults(split_canvas=
"1:1",plots=
"",files=
"",outputfile=
"DISPLAY",divide=
False, zero=
False)
71(options, args) = parser.parse_args()
73split_canv = options.split_canvas.split(
":")
74split_canv =
map(int,split_canv)
76from LArG4Validation.LArG4PlottingScript
import parseRoots, defaultRoots, \
77 parsePlots, fillPlots, dividePlots, savePlots, drawPlots, PlotEntry, \
80if (len(split_canv) != 2) :
81 print (
"ERROR: wrong split parameter")
84if (options.divide
and len(args) < 2) :
85 print (
"ERROR: must be at least two input files for ratio calculation")
88if isfile(options.files) :
89 print (
"Parsing file with root parameters:",options.files)
90 parsedRoots = parseRoots(options.files)
92 print (
"No root parameters provided, using default")
93 parsedRoots = defaultRoots(args)
95if isfile(options.plots) :
96 print (
"Parsing file with plots parameters:",options.plots)
97 parsedPlots = parsePlots(options.plots,varname)
99 print (
"No plots parameters provided, using default")
102 for var
in [
"erec",
"cpu"] :
104 pe.vars_to_draw = [var]
105 pe.axis_captions[var] =
varname(var)
106 pe.display_name = var
107 parsedPlots.append(pe)
109 pe.vars_to_draw = [
"eta",
"erec"]
110 pe.axis_captions[
"eta"] =
varname(
"eta")
111 pe.axis_captions[
"erec"] =
varname(
"erec")
112 pe.display_name =
"Energy vs Eta"
114 parsedPlots.append(pe)
116 pe.vars_to_draw = [
"egen",
"erec"]
117 pe.axis_captions[
"egen"] =
varname(
"egen")
118 pe.axis_captions[
"erec"] =
varname(
"erec")
119 pe.display_name =
"Energy vs Truth Energy"
121 parsedPlots.append(pe)
126maxperlist = split_canv[0]*split_canv[1]
129numplots = len(parsedPlots)
131if (options.outputfile ==
"DISPLAY")
and (numplots > maxperlist) :
132 print (
"ERROR: too many hists to print to display")
135from ROOT
import TFile
138for rootopt
in parsedRoots :
139 if not isfile(rootopt.filename) :
140 print (
"ERROR: unexistent file:",rootopt.filename)
142 root = TFile(rootopt.filename,
"read")
143 if root.IsOpen() == 0 :
144 print (
"ERROR: can't open the file:",rootopt.filename)
146 rootopt.rootfile = root
147 rootopt.tree = root.Get(
"COL/1")
149print (
"Creating plots...")
150plots = createPlots(parsedPlots,parsedRoots)
152print (
"Filling plots...")
153fillPlots(plots,parsedPlots,parsedRoots,eventext)
156 print (
"Calculating ratio")
157 rootopt1 = parsedRoots.pop(0)
158 dividePlots(plots,rootopt1)
159 for rootopt
in parsedRoots :
160 rootopt.legendname +=
" / " + rootopt1.legendname
164if options.outputfile.endswith(
".root") :
165 savePlots(plots,options.outputfile)
167 canv,leg = drawPlots(plots,parsedPlots,parsedRoots,options.outputfile,options.zero,options.mean,split_canv[0],split_canv[1])
169if (options.outputfile ==
"DISPLAY") :
170 from time
import sleep
171 while not not(canv) :