5 from __future__
import print_function
10 Created by Andreas Salzburger on 2009-04-16.
11 Updated by Wolfgang Lukas on 2011-04-29.
12 Copyright (c) 2009-2011 The ATLAS Collaboration. All rights reserved.
18 from TTreeHelper
import *
19 from ROOT
import TCanvas,TTree,TProfile,gDirectory,TColor,TH1F,THStack
22 The help message goes here.
34 opts, args = getopt.getopt(argv[1:],
"ho:v", [
"help",
"output="])
35 except getopt.error
as msg:
39 for option, value
in opts:
42 if option
in (
"-h",
"--help"):
43 raise Usage(help_message)
44 if option
in (
"-o",
"--output"):
48 print (sys.argv[0].
split(
"/")[-1] +
": " +
str(err.msg),file=sys.stderr)
49 print (
"\t for help use --help", file=sys.stderr)
57 for iarg
in range(len(argv)) :
58 if argv[iarg].
find(
'files') >= 0:
59 inputfiles = argv[iarg]
60 elif argv[iarg].
find(
'trees') >= 0:
61 inputtrees = argv[iarg]
62 elif argv[iarg].
find(
'params') >= 0:
63 inputparams = argv[iarg]
64 elif argv[iarg].
find(
'saveas') >= 0:
65 saveasfiles = argv[iarg]
73 if len(saveaslist) > 0:
74 if not os.path.isdir(
'./output/'):
77 outputdir =
'./output/mval_'+
str(time.time())+
'/'
78 if not os.path.isdir(outputdir):
81 for saveas
in saveaslist :
83 if not os.path.isdir(outputdir+saveas+
'/'):
84 os.mkdir(outputdir+saveas+
'/')
87 numPlots = len(parslist)
92 numCols = numPlots//2 + numPlots%2
94 print (
'[>] Files to be processed :', filelist)
95 print (
'[>] Trees to be drawn :', len(treelist))
96 print (
'[>] Profiles to be made :', parslist)
97 print (
'[>] Going to be saved as :', saveaslist )
98 print (
'[>] Number of cols/rows :',numCols,
', ',numRows)
106 for filename
in filelist :
109 singleDict = singleSelector.loadTrees(treelist[0])
112 for entry
in singleDict :
113 iden = entry.lstrip(
'TVolume_').
replace(
'::',
'_')
115 if iden
not in canvasDict :
116 canvas = TCanvas(iden,
'TrackingVolume:'+iden,100,100,numCols*300,numRows*300)
118 canvas.Divide(numCols,numRows)
120 canvasDict[iden] = canvas
122 canvas = canvasDict[iden]
126 if len(parslist) > 1 : pad = 1
128 for par
in parslist :
129 tree = singleDict[entry]
134 for saveas
in saveaslist :
135 canvas.SaveAs(outputdir+saveas+
'/'+iden+
'.'+saveas)
138 for entry
in singleDict :
139 iden = entry.lstrip(
'TVolume_').
replace(
'::',
'_') +
'_TOTAL'
141 if '_UNMAPPED' in entry :
continue
143 if (entry+
'_UNMAPPED')
not in singleDict :
continue
145 if iden
not in canvasTotalDict :
146 canvas = TCanvas(iden,
'TrackingVolume:'+iden,100,100,numCols*300,numRows*300)
148 canvas.Divide(numCols,numRows)
150 canvasTotalDict[iden] = canvas
152 canvas = canvasTotalDict[iden]
156 if len(parslist) > 1 : pad = 1
158 for par
in parslist :
159 tree1 = singleDict[entry]
160 tree2 = singleDict[entry+
'_UNMAPPED']
162 outpath = outputdir+saveas+
'/'+iden+
'.'+saveas
163 plotStack(canvas,pad,tree1,tree2,par,fileNum,outpath)
169 print (
'[>] Next file, switching to same option (',fileNum,
')')
174 splitlist = argstring.split(
'=')
176 if len(splitlist)
is 2 :
177 inputlist = splitlist[1].
split(
",")
183 tprofname = tree.GetName()+param+
str(fileNum)
185 tmpCanv = TCanvas(tprofname)
187 tree.Draw(param+
'>>'+tprofname+
'(200)',
'',
'prof,goff')
189 print (
'[>] In plotProfile() with option :',fileNum)
196 tprofile = gDirectory.Get(tprofname)
207 title = tree.GetName().
split(
'_')[1]
209 if '_UNMAPPED' in tree.GetName() :
212 tprofile.SetTitle(title)
213 tprofile.GetXaxis().SetTitle(param.split(
':')[1])
214 tprofile.GetYaxis().SetTitle(param.split(
':')[0])
219 tprofile.SetLineColor(fileNum)
220 tprofile.SetMarkerColor(fileNum)
221 tprofile.SetMarkerStyle(8)
222 tprofile.SetMarkerSize(0.35)
223 tprofile.Draw(
"p,same")
230 tprofile.SetLineColor(1)
231 tprofile.SetFillColor(color)
232 tprofile.Draw(
'hist')
237 def plotStack(canvas,pad,tree1,tree2,param,fileNum,outpath):
239 tprofname1 = tree1.GetName()+param+
str(fileNum)
240 tprofname2 = tree2.GetName()+param+
str(fileNum)
242 tmpCanv = TCanvas(tprofname1+
'stack')
244 tprofile1 = gDirectory.Get(tprofname1)
245 tprofile2 = gDirectory.Get(tprofname2)
248 lower1 = tprofile1.GetBinLowEdge(1)
249 lower2 = tprofile2.GetBinLowEdge(1)
252 upper1 = tprofile1.GetBinLowEdge(201)
253 upper2 = tprofile2.GetBinLowEdge(201)
255 newmin =
min(lower1,lower2)
256 newmax =
max(upper1,upper2)
259 tprofname1new = tprofname1 +
'rebin'
260 tprofname2new = tprofname2 +
'rebin'
261 tree1.Draw(param+
'>>'+tprofname1new+
'(200,'+
str(newmin)+
','+
str(newmax)+
')',
'',
'prof,goff')
262 tree2.Draw(param+
'>>'+tprofname2new+
'(200,'+
str(newmin)+
','+
str(newmax)+
')',
'',
'prof,goff')
263 tprofile1new = gDirectory.Get(tprofname1new)
264 tprofile2new = gDirectory.Get(tprofname2new)
266 print (
'[>] In plotStack() with option :',fileNum)
274 h1st = tprofile1new.ProjectionX(tprofname1new+
'h1')
275 h2st = tprofile2new.ProjectionX(tprofname2new+
'h2')
278 title = tree1.GetName().
split(
'_')[1] +
' TOTAL'
280 print (
'[>] Stack:', tree1.GetName().
split(
'_')[1],
' newmin =', newmin,
' newmax =', newmax)
281 h1st.GetXaxis().SetTitle(param.split(
':')[1])
282 h1st.GetYaxis().SetTitle(param.split(
':')[0])
283 h2st.GetXaxis().SetTitle(param.split(
':')[1])
284 h2st.GetYaxis().SetTitle(param.split(
':')[0])
287 h1st.SetLineColor(fileNum)
288 h1st.SetMarkerColor(fileNum)
289 h1st.SetMarkerStyle(8)
290 h1st.SetMarkerSize(0.35)
292 h2st.SetLineColor(fileNum+10)
293 h2st.SetMarkerColor(fileNum+10)
294 h2st.SetMarkerStyle(8)
295 h2st.SetMarkerSize(0.35)
305 h2st.SetFillColor(17)
311 canvas.SaveAs(outpath)
314 if __name__ ==
"__main__":