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}}"
53 from os.path
import isfile
54 from optparse
import OptionParser
57 usage =
"usage: %prog [options] root1 [root2 ...]"
59 parser = OptionParser(usage=usage, version=
"%prog v1.0 $Id: LArG4ValidationPlotter.py 505706 2012-06-15 11:48:02Z gsedov $")
61 parser.add_option(
"-s",
"--split",dest=
"split_canvas", help=
"Split canvas, format: 'HORIZ:VERT' (default = %default)")
62 parser.add_option(
"-p",
"--plots",dest=
"plots", help=
"input file with histogram parameters")
63 parser.add_option(
"-f",
"--files",dest=
"files", help=
"input file with files parameters")
64 parser.add_option(
"-o",
"--output",dest=
"outputfile", help=
"output ps file")
65 parser.add_option(
"-d",
"--divide",dest=
"divide",action=
"store_true", help=
"Calculate ratio between root files (divide all roots to first")
66 parser.add_option(
"-m",
"--mean",dest=
"mean",action=
"store_true",help=
"Print mean value in the legend")
67 parser.add_option(
"-z",
"--zero",dest=
"zero",action=
"store_true",help=
"Set minimums to zero")
69 parser.set_defaults(split_canvas=
"1:1",plots=
"",files=
"",outputfile=
"DISPLAY",divide=
False, zero=
False)
71 (options, args) = parser.parse_args()
73 split_canv = options.split_canvas.split(
":")
74 split_canv = map(int,split_canv)
76 from LArG4Validation.LArG4PlottingScript
import parseRoots, defaultRoots, \
77 parsePlots, fillPlots, dividePlots, savePlots, drawPlots, PlotEntry, \
80 if (len(split_canv) != 2) :
81 print (
"ERROR: wrong split parameter")
84 if (options.divide
and len(args) < 2) :
85 print (
"ERROR: must be at least two input files for ratio calculation")
88 if isfile(options.files) :
89 print (
"Parsing file with root parameters:",options.files)
92 print (
"No root parameters provided, using default")
95 if isfile(options.plots) :
96 print (
"Parsing file with plots parameters:",options.plots)
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)
126 maxperlist = split_canv[0]*split_canv[1]
129 numplots = len(parsedPlots)
131 if (options.outputfile ==
"DISPLAY")
and (numplots > maxperlist) :
132 print (
"ERROR: too many hists to print to display")
135 from ROOT
import TFile
138 for 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")
149 print (
"Creating plots...")
152 print (
"Filling plots...")
153 fillPlots(plots,parsedPlots,parsedRoots,eventext)
155 if (options.divide) :
156 print (
"Calculating ratio")
157 rootopt1 = parsedRoots.pop(0)
159 for rootopt
in parsedRoots :
160 rootopt.legendname +=
" / " + rootopt1.legendname
164 if options.outputfile.endswith(
".root") :
167 canv,leg =
drawPlots(plots,parsedPlots,parsedRoots,options.outputfile,options.zero,options.mean,split_canv[0],split_canv[1])
169 if (options.outputfile ==
"DISPLAY") :
170 from time
import sleep
171 while not not(canv) :