ATLAS Offline Software
Loading...
Searching...
No Matches
MaterialValidation Namespace Reference

Classes

class  Usage

Functions

 main (argv=None)
 splitInputArgs (argstring)
 plotProfile (canvas, pad, tree, param, fileNum)
 plotStack (canvas, pad, tree1, tree2, param, fileNum, outpath)

Variables

str help_message

Detailed Description

MaterialValidation.py

Created by Andreas Salzburger on 2009-04-16.
Updated by Wolfgang Lukas     on 2011-04-29.
Copyright (c) 2009-2011 The ATLAS Collaboration. All rights reserved.

Function Documentation

◆ main()

MaterialValidation.main ( argv = None)

Definition at line 28 of file MaterialValidation.py.

28def main(argv=None):
29 if argv is None:
30 argv = sys.argv
31 try:
32 try:
33 opts, args = getopt.getopt(argv[1:], "ho:v", ["help", "output="])
34 except getopt.error as msg:
35 raise Usage(msg)
36
37 # option processing
38 for option, value in opts:
39 if option == "-v":
40 verbose = True
41 if option in ("-h", "--help"):
42 raise Usage(help_message)
43 if option in ("-o", "--output"):
44 output = value
45
46 except Usage as err:
47 print (sys.argv[0].split("/")[-1] + ": " + str(err.msg),file=sys.stderr)
48 print ("\t for help use --help", file=sys.stderr)
49 return 2
50
51 inputfiles =''
52 inputtrees =''
53 inputparams =''
54 saveasfiles =''
55 # argument list given
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]
65
66 filelist = splitInputArgs(inputfiles)
67 treelist = splitInputArgs(inputtrees)
68 parslist = splitInputArgs(inputparams)
69 saveaslist = splitInputArgs(saveasfiles)
70
71 # prepare the output directory
72 if len(saveaslist) > 0:
73 if not os.path.isdir('./output/'):
74 os.mkdir('./output/')
75 # make the output directory
76 outputdir = './output/mval_'+str(time.time())+'/'
77 if not os.path.isdir(outputdir):
78 os.mkdir(outputdir)
79 # save according to the given parameters
80 for saveas in saveaslist :
81 # check whether the directory exists
82 if not os.path.isdir(outputdir+saveas+'/'):
83 os.mkdir(outputdir+saveas+'/')
84
85 # draw numbering
86 numPlots = len(parslist)
87 numRows = 1
88 numCols = numPlots
89 if numPlots > 2 :
90 numRows = 2
91 numCols = numPlots//2 + numPlots%2
92
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)
98
99 # get the file and the associated dictionaries
100 canvasDict = {}
101 canvasTotalDict = {}
102
103 fileNum = 0
104 #filename = argv[1]
105 for filename in filelist :
106 # get the tree selector and the dictionary
107 singleSelector = TTreeSelector(filename)
108 singleDict = singleSelector.loadTrees(treelist[0])
109
110 # create the canvas list
111 for entry in singleDict :
112 iden = entry.lstrip('TVolume_').replace('::','_')
113 # create the canvas for this
114 if iden not in canvasDict :
115 canvas = TCanvas(iden,'TrackingVolume:'+iden,100,100,numCols*300,numRows*300)
116 if numCols > 1 :
117 canvas.Divide(numCols,numRows)
118 # fill into canvas dictionary
119 canvasDict[iden] = canvas
120 else :
121 canvas = canvasDict[iden]
122
123 # now loop over the parameter list
124 pad = 0
125 if len(parslist) > 1 : pad = 1
126
127 for par in parslist :
128 tree = singleDict[entry]
129 plotProfile(canvas,pad,tree,par,fileNum)
130 pad += 1
131
132 # save according to the given parameters
133 for saveas in saveaslist :
134 canvas.SaveAs(outputdir+saveas+'/'+iden+'.'+saveas)
135
136 # create the canvas list for stacked plots
137 for entry in singleDict :
138 iden = entry.lstrip('TVolume_').replace('::','_') + '_TOTAL'
139 # take only mapped trees as a basis
140 if '_UNMAPPED' in entry : continue
141 # do stack only if unmapped trees are also available
142 if (entry+'_UNMAPPED') not in singleDict : continue
143 # create the canvas for this
144 if iden not in canvasTotalDict :
145 canvas = TCanvas(iden,'TrackingVolume:'+iden,100,100,numCols*300,numRows*300)
146 if numCols > 1 :
147 canvas.Divide(numCols,numRows)
148 # fill into canvas dictionary
149 canvasTotalDict[iden] = canvas
150 else :
151 canvas = canvasTotalDict[iden]
152
153 # now loop over the parameter list
154 pad = 0
155 if len(parslist) > 1 : pad = 1
156
157 for par in parslist :
158 tree1 = singleDict[entry]
159 tree2 = singleDict[entry+'_UNMAPPED']
160 # TODO: also give saveaslist ... or rewrite and only give persistent THStack and save as above
161 outpath = outputdir+saveas+'/'+iden+'.'+saveas
162 plotStack(canvas,pad,tree1,tree2,par,fileNum,outpath)
163 pad += 1
164
165
166 # fileNum
167 fileNum += 1
168 print ('[>] Next file, switching to same option (',fileNum,')')
169
170
int Usage(const char *prog)
Definition HephProf.cxx:26
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
int main()
Definition hello.cxx:18

◆ plotProfile()

MaterialValidation.plotProfile ( canvas,
pad,
tree,
param,
fileNum )

Definition at line 180 of file MaterialValidation.py.

180def plotProfile(canvas,pad,tree,param,fileNum):
181 # the name
182 tprofname = tree.GetName()+param+str(fileNum)
183 # draw it and get it
184 tmpCanv = TCanvas(tprofname)
185 tmpCanv.cd()
186 tree.Draw(param+'>>'+tprofname+'(200)','','prof,goff')
187
188 print ('[>] In plotProfile() with option :',fileNum)
189
190 if pad > 0:
191 canvas.cd(pad)
192 else :
193 canvas.cd()
194
195 tprofile = gDirectory.Get(tprofname)
196
197# lower = tprofile.GetBinLowEdge(1)
198# upper = tprofile.GetBinLowEdge(201)
199# print (lower,upper)
200# h1 = tprofile.ProjectionX('h1')
201
202# if fileNum == 1 # for full comparison plot with 2 histos
203# tprofile.SetFillColor(5)
204# tprofile.Draw("hist,same")
205# elif fileNum :
206 title = tree.GetName().split('_')[1]
207 color = 5
208 if '_UNMAPPED' in tree.GetName() :
209 title += ' UNMAPPED'
210 color = 17
211 tprofile.SetTitle(title)
212 tprofile.GetXaxis().SetTitle(param.split(':')[1])
213 tprofile.GetYaxis().SetTitle(param.split(':')[0])
214# h1.SetTitle(title)
215# h1.GetXaxis().SetTitle(param.split(':')[1])
216# h1.GetYaxis().SetTitle(param.split(':')[0])
217 if fileNum :
218 tprofile.SetLineColor(fileNum)
219 tprofile.SetMarkerColor(fileNum)
220 tprofile.SetMarkerStyle(8)
221 tprofile.SetMarkerSize(0.35)
222 tprofile.Draw("p,same")
223# h1.SetLineColor(fileNum)
224# h1.SetMarkerColor(fileNum)
225# h1.SetMarkerStyle(8)
226# h1.SetMarkerSize(0.35)
227# h1.Draw("p,same")
228 else :
229 tprofile.SetLineColor(1)
230 tprofile.SetFillColor(color)
231 tprofile.Draw('hist')
232# h1.SetFillColor(color)
233# h1.Draw('hist')
234
235

◆ plotStack()

MaterialValidation.plotStack ( canvas,
pad,
tree1,
tree2,
param,
fileNum,
outpath )

Definition at line 236 of file MaterialValidation.py.

236def plotStack(canvas,pad,tree1,tree2,param,fileNum,outpath):
237 # the name
238 tprofname1 = tree1.GetName()+param+str(fileNum)
239 tprofname2 = tree2.GetName()+param+str(fileNum)
240 # they already exist in gDirectory, get them
241 tmpCanv = TCanvas(tprofname1+'stack')
242 tmpCanv.cd()
243 tprofile1 = gDirectory.Get(tprofname1)
244 tprofile2 = gDirectory.Get(tprofname2)
245
246 # get the overall upper and lower bin limits
247 lower1 = tprofile1.GetBinLowEdge(1)
248 lower2 = tprofile2.GetBinLowEdge(1)
249# lower2 = tprofile2.GetBinCenter(1) - tprofile2.GetXAxis.GetBinWidth()/2.
250# upper1 = tprofile1.GetBinCenter(200) + tprofile1.GetXAxis.GetBinWidth()/2.
251 upper1 = tprofile1.GetBinLowEdge(201)
252 upper2 = tprofile2.GetBinLowEdge(201)
253
254 newmin = min(lower1,lower2)
255 newmax = max(upper1,upper2)
256
257 # draw the plots again with new binning
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)
264
265 print ('[>] In plotStack() with option :',fileNum)
266
267 if pad > 0:
268 canvas.cd(pad)
269 else :
270 canvas.cd()
271
272 # projection to TH1F for stacking
273 h1st = tprofile1new.ProjectionX(tprofname1new+'h1')
274 h2st = tprofile2new.ProjectionX(tprofname2new+'h2')
275 ts = THStack()
276
277 title = tree1.GetName().split('_')[1] + ' TOTAL'
278 ts.SetTitle(title)
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])
284
285 if fileNum :
286 h1st.SetLineColor(fileNum)
287 h1st.SetMarkerColor(fileNum)
288 h1st.SetMarkerStyle(8)
289 h1st.SetMarkerSize(0.35)
290 h1st.Draw("p,same")
291 h2st.SetLineColor(fileNum+10)
292 h2st.SetMarkerColor(fileNum+10)
293 h2st.SetMarkerStyle(8)
294 h2st.SetMarkerSize(0.35)
295 h2st.Draw("p,same")
296 ts.Add(h1st)
297 ts.Add(h2st)
298 ts.Draw()
299 else :
300 h1st.SetLineColor(1)
301 h1st.SetFillColor(5)
302 h1st.Draw('hist')
303 h2st.SetLineColor(1)
304 h2st.SetFillColor(17)
305 h2st.Draw('hist')
306 ts.Add(h1st,'hist')
307 ts.Add(h2st,'hist')
308 ts.Draw()
309
310 canvas.SaveAs(outpath)
311
312
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41

◆ splitInputArgs()

MaterialValidation.splitInputArgs ( argstring)

Definition at line 171 of file MaterialValidation.py.

171def splitInputArgs(argstring):
172 # split the keyword off
173 splitlist = argstring.split('=')
174 inputlist = []
175 if len(splitlist) is 2 :
176 inputlist = splitlist[1].split(",")
177 return inputlist
178
179

Variable Documentation

◆ help_message

str MaterialValidation.help_message
Initial value:
1= '''
2The help message goes here.
3'''

Definition at line 20 of file MaterialValidation.py.