ATLAS Offline Software
Loading...
Searching...
No Matches
LArG4AODNtuplePlotter.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3#
4# python script for drawing LArG4Validation ntuples
5#
6
7__version__ = '$Revision: 505706 $'
8__author__ = 'Radist Morse radist.morse@gmail.com'
9__doc__ = 'Script for drawing LArG4Validation N tuples'
10
11#list of accessible variables
12def eventext(event,hname) :
13 if (hname == "hadrleak") :
14 return event.ethad1/event.et
15 elif (hname == "e237oe277") :
16 if (event.e277 > 0) :
17 return event.e237/event.e277
18 else :
19 return 0
20 elif (hname == "e2tsts1") :
21 return event.e2tsts1/(1000. + 0.009 * event.et)
22 elif (hname == "e2tsts1demins") :
23 return event.e2tsts1 - event.emins1
24 elif (hname == "erec") :
25 return event.energy
26 elif (hname == "erecegen") :
27 return event.energy / event.truth_energy
28 elif (hname == "eta") :
29 return event.eta
30 elif (hname == "pt") :
31 return event.pt
32 elif (hname == "egen") :
33 return event.truth_energy
34 else :
35 return "False"
36
37def varname(hname) :
38 if (hname == "hadrleak") :
39 return "Hadron Leak"
40 elif (hname == "e237oe277") :
41 return "#frac{E_{237}}{E_{277}}"
42 elif (hname == "e2tsts1") :
43 return "E_{2}tsts_{1}"
44 elif (hname == "e2tsts1demins") :
45 return "e2tsts1demins"
46 elif (hname == "erec") :
47 return "E_{rec}"
48 elif (hname == "erecegen") :
49 return "#frac{E_{rec}}{E_{gen}}"
50 elif (hname == "eta") :
51 return "#eta"
52 elif (hname == "pt") :
53 return "P_{t}"
54 elif (hname == "egen") :
55 return "E_{gen}"
56 else :
57 return ""
58
59import sys
60from os.path import isfile
61from optparse import OptionParser
62
63usage = "usage: %prog [options] root1 [root2 ...]"
64
65parser = OptionParser(usage=usage, version="%prog v1.0 $Id: LArG4AODNtuplePlotter.py 505706 2012-06-15 11:48:02Z gsedov $")
66
67parser.add_option("-s","--split",dest="split_canvas", help="Split canvas, format: 'HORIZ:VERT' (default = %default)")
68parser.add_option("-p","--plots",dest="plots", help="input file with histogram parameters")
69parser.add_option("-f","--files",dest="files", help="input file with files parameters")
70parser.add_option("-o","--output",dest="outputfile", help="output ps file")
71parser.add_option("-d","--divide",dest="divide",action="store_true", help="Calculate ratio between root files (divide all roots to first")
72parser.add_option("-m","--mean",dest="mean",action="store_true",help="Print mean value in the legend")
73parser.add_option("-z","--zero",dest="zero",action="store_true",help="Set minimums to zero")
74
75parser.set_defaults(split_canvas="1:1",plots="",files="",outputfile="DISPLAY",divide=False, zero=False)
76
77(options, args) = parser.parse_args()
78
79split_canv = options.split_canvas.split(":")
80split_canv = map(int,split_canv)
81
82from LArG4Validation.LArG4PlottingScript import parseRoots, defaultRoots, \
83 parsePlots, fillPlots, dividePlots, savePlots, drawPlots, PlotEntry, \
84 createPlots
85
86if (len(split_canv) != 2) :
87 print ("ERROR: wrong split parameter")
88 sys.exit(1)
89
90if (options.divide and len(args) < 2) :
91 print ("ERROR: must be at least two input files for ratio calculation")
92 sys.exit(1)
93
94if isfile(options.files) :
95 print ("Parsing file with root parameters:",options.files)
96 parsedRoots = parseRoots(options.files)
97else :
98 print ("No root parameters provided, using default")
99 parsedRoots = defaultRoots(args)
100
101if isfile(options.plots) :
102 print ("Parsing file with plots parameters:",options.plots)
103 parsedPlots = parsePlots(options.plots,varname)
104else :
105 print ("No plots parameters provided, using default")
106 parsedPlots = []
107 parsedRestricts = []
108 listvars = ["hadrleak","e237oe277","weta2","f1","e2tsts1","e2tsts1demins","wtots1","fracs1","weta1"]
109 capvars = {}
110 for var in listvars :
111 capvars[var] = varname(var)
112 listmax = [0.02,1.0,0.015,0.7,3.0,1500.0,4.0,0.6,0.8]
113 listmin = [-0.007,0.84,0.005,0.0,0.0,0.0,1.0,0.0,0.4]
114 listlogy = [0,0,0,0,1,1,0,0,0]
115 for var,mmax,mmin,logy in zip(listvars,listmax,listmin,listlogy) :
116 pe = PlotEntry()
117 pe.vars_to_draw.append(var)
118 pe.axis_captions[var] = capvars[var]
119 pe.display_name = var
120 pe.givenmin = mmin
121 pe.givenmax = mmax
122 pe.logy = logy
123 parsedPlots.append(pe)
124 split_canv[0] = 3
125 split_canv[1] = 3
126
127#number of pads
128maxperlist = split_canv[0]*split_canv[1]
129
130#can't make NewPage for display
131numplots = len(parsedPlots)
132
133if (options.outputfile == "DISPLAY") and (numplots > maxperlist) :
134 print ("ERROR: too many hists to print to display")
135 sys.exit(1)
136
137from ROOT import TFile
138
139#opening root files
140for rootopt in parsedRoots :
141 if not isfile(rootopt.filename) :
142 print ("ERROR: unexistent file:",rootopt.filename)
143 sys.exit(1)
144 root = TFile(rootopt.filename,"read")
145 if root.IsOpen() == 0 :
146 print ("ERROR: can't open the file:",rootopt.filename)
147 sys.exit(1)
148 rootopt.rootfile = root
149 rootopt.tree = root.Get("AOD")
150
151print ("Creating plots...")
152plots = createPlots(parsedPlots,parsedRoots)
153
154print ("Filling plots...")
155fillPlots(plots,parsedPlots,parsedRoots,eventext)
156
157
158if (options.divide) :
159 print ("Calculating ratio")
160 rootopt1 = parsedRoots.pop(0)
161 dividePlots(plots,rootopt1)
162 for rootopt in parsedRoots :
163 rootopt.legendname += " / " + rootopt1.legendname
164
165print ("Done!")
166
167if options.outputfile.endswith(".root") :
168 savePlots(plots,options.outputfile)
169else :
170 canv,leg = drawPlots(plots,parsedPlots,parsedRoots,options.outputfile,options.zero,options.mean,split_canv[0],split_canv[1])
171
172if (options.outputfile == "DISPLAY") :
173 from time import sleep
174 while not not(canv) :
175 sleep(1)
STL class.