9 Created by Andreas Salzburger on 2009-04-16.
10 Updated by Wolfgang Lukas on 2011-04-29.
11 Copyright (c) 2009-2011 The ATLAS Collaboration. All rights reserved.
17 from TTreeHelper
import *
18 from ROOT
import TCanvas,TTree,TProfile,gDirectory,TColor,TH1F,THStack
21 The help message goes here.
33 opts, args = getopt.getopt(argv[1:],
"ho:v", [
"help",
"output="])
34 except getopt.error
as msg:
38 for option, value
in opts:
41 if option
in (
"-h",
"--help"):
42 raise Usage(help_message)
43 if option
in (
"-o",
"--output"):
47 print (sys.argv[0].
split(
"/")[-1] +
": " +
str(err.msg),file=sys.stderr)
48 print (
"\t for help use --help", file=sys.stderr)
56 for iarg
in range(len(argv)) :
57 if argv[iarg].
find(
'files') >= 0:
58 inputfiles = argv[iarg]
59 elif argv[iarg].
find(
'trees') >= 0:
60 inputtrees = argv[iarg]
61 elif argv[iarg].
find(
'params') >= 0:
62 inputparams = argv[iarg]
63 elif argv[iarg].
find(
'saveas') >= 0:
64 saveasfiles = argv[iarg]
72 if len(saveaslist) > 0:
73 if not os.path.isdir(
'./output/'):
76 outputdir =
'./output/mval_'+
str(time.time())+
'/'
77 if not os.path.isdir(outputdir):
80 for saveas
in saveaslist :
82 if not os.path.isdir(outputdir+saveas+
'/'):
83 os.mkdir(outputdir+saveas+
'/')
86 numPlots = len(parslist)
91 numCols = numPlots//2 + numPlots%2
93 print (
'[>] Files to be processed :', filelist)
94 print (
'[>] Trees to be drawn :', len(treelist))
95 print (
'[>] Profiles to be made :', parslist)
96 print (
'[>] Going to be saved as :', saveaslist )
97 print (
'[>] Number of cols/rows :',numCols,
', ',numRows)
105 for filename
in filelist :
108 singleDict = singleSelector.loadTrees(treelist[0])
111 for entry
in singleDict :
112 iden = entry.lstrip(
'TVolume_').
replace(
'::',
'_')
114 if iden
not in canvasDict :
115 canvas = TCanvas(iden,
'TrackingVolume:'+iden,100,100,numCols*300,numRows*300)
117 canvas.Divide(numCols,numRows)
119 canvasDict[iden] = canvas
121 canvas = canvasDict[iden]
125 if len(parslist) > 1 : pad = 1
127 for par
in parslist :
128 tree = singleDict[entry]
133 for saveas
in saveaslist :
134 canvas.SaveAs(outputdir+saveas+
'/'+iden+
'.'+saveas)
137 for entry
in singleDict :
138 iden = entry.lstrip(
'TVolume_').
replace(
'::',
'_') +
'_TOTAL'
140 if '_UNMAPPED' in entry :
continue
142 if (entry+
'_UNMAPPED')
not in singleDict :
continue
144 if iden
not in canvasTotalDict :
145 canvas = TCanvas(iden,
'TrackingVolume:'+iden,100,100,numCols*300,numRows*300)
147 canvas.Divide(numCols,numRows)
149 canvasTotalDict[iden] = canvas
151 canvas = canvasTotalDict[iden]
155 if len(parslist) > 1 : pad = 1
157 for par
in parslist :
158 tree1 = singleDict[entry]
159 tree2 = singleDict[entry+
'_UNMAPPED']
161 outpath = outputdir+saveas+
'/'+iden+
'.'+saveas
162 plotStack(canvas,pad,tree1,tree2,par,fileNum,outpath)
168 print (
'[>] Next file, switching to same option (',fileNum,
')')
173 splitlist = argstring.split(
'=')
175 if len(splitlist)
is 2 :
176 inputlist = splitlist[1].
split(
",")
182 tprofname = tree.GetName()+param+
str(fileNum)
184 tmpCanv = TCanvas(tprofname)
186 tree.Draw(param+
'>>'+tprofname+
'(200)',
'',
'prof,goff')
188 print (
'[>] In plotProfile() with option :',fileNum)
195 tprofile = gDirectory.Get(tprofname)
206 title = tree.GetName().
split(
'_')[1]
208 if '_UNMAPPED' in tree.GetName() :
211 tprofile.SetTitle(title)
212 tprofile.GetXaxis().SetTitle(param.split(
':')[1])
213 tprofile.GetYaxis().SetTitle(param.split(
':')[0])
218 tprofile.SetLineColor(fileNum)
219 tprofile.SetMarkerColor(fileNum)
220 tprofile.SetMarkerStyle(8)
221 tprofile.SetMarkerSize(0.35)
222 tprofile.Draw(
"p,same")
229 tprofile.SetLineColor(1)
230 tprofile.SetFillColor(color)
231 tprofile.Draw(
'hist')
236 def plotStack(canvas,pad,tree1,tree2,param,fileNum,outpath):
238 tprofname1 = tree1.GetName()+param+
str(fileNum)
239 tprofname2 = tree2.GetName()+param+
str(fileNum)
241 tmpCanv = TCanvas(tprofname1+
'stack')
243 tprofile1 = gDirectory.Get(tprofname1)
244 tprofile2 = gDirectory.Get(tprofname2)
247 lower1 = tprofile1.GetBinLowEdge(1)
248 lower2 = tprofile2.GetBinLowEdge(1)
251 upper1 = tprofile1.GetBinLowEdge(201)
252 upper2 = tprofile2.GetBinLowEdge(201)
254 newmin =
min(lower1,lower2)
255 newmax =
max(upper1,upper2)
258 tprofname1new = tprofname1 +
'rebin'
259 tprofname2new = tprofname2 +
'rebin'
260 tree1.Draw(param+
'>>'+tprofname1new+
'(200,'+
str(newmin)+
','+
str(newmax)+
')',
'',
'prof,goff')
261 tree2.Draw(param+
'>>'+tprofname2new+
'(200,'+
str(newmin)+
','+
str(newmax)+
')',
'',
'prof,goff')
262 tprofile1new = gDirectory.Get(tprofname1new)
263 tprofile2new = gDirectory.Get(tprofname2new)
265 print (
'[>] In plotStack() with option :',fileNum)
273 h1st = tprofile1new.ProjectionX(tprofname1new+
'h1')
274 h2st = tprofile2new.ProjectionX(tprofname2new+
'h2')
277 title = tree1.GetName().
split(
'_')[1] +
' TOTAL'
279 print (
'[>] Stack:', tree1.GetName().
split(
'_')[1],
' newmin =', newmin,
' newmax =', newmax)
280 h1st.GetXaxis().SetTitle(param.split(
':')[1])
281 h1st.GetYaxis().SetTitle(param.split(
':')[0])
282 h2st.GetXaxis().SetTitle(param.split(
':')[1])
283 h2st.GetYaxis().SetTitle(param.split(
':')[0])
286 h1st.SetLineColor(fileNum)
287 h1st.SetMarkerColor(fileNum)
288 h1st.SetMarkerStyle(8)
289 h1st.SetMarkerSize(0.35)
291 h2st.SetLineColor(fileNum+10)
292 h2st.SetMarkerColor(fileNum+10)
293 h2st.SetMarkerStyle(8)
294 h2st.SetMarkerSize(0.35)
304 h2st.SetFillColor(17)
310 canvas.SaveAs(outpath)
313 if __name__ ==
"__main__":