5 from optparse
import OptionParser
10 __author__ =
'James Walder'
12 __usage__ =
'%prog [options] '
15 names = s.split(token)
18 parser = OptionParser(usage=__usage__, version=__version__)
19 parser.add_option(
'-f',
'--files',dest=
'files', default=
'vtx.root', help=
'Root files for data vertex plots')
20 parser.add_option(
'-g',
'--bs',dest=
'beamspotFile', default=
'', help=
'Root files for data beamspot plots')
22 parser.add_option(
'-d',
'--dir',dest=
'dir', default=
'Beamspot', help=
'Root directory for beamspots')
23 parser.add_option(
'-b',
'--batch', dest=
'batch', action=
'store_true', default=
False, help=
'Run in batch mode')
25 (options,args) = parser.parse_args()
28 os.unsetenv(
'DISPLAY')
31 from ROOT
import TH1D, TCanvas
32 from ROOT
import gSystem, gROOT, TFile, TH1D, TH2D, TCanvas, TTree, TChain
33 from ROOT
import TGraphErrors
34 from ROOT
import TMultiGraph
35 from ROOT
import EColor
36 from ROOT
import TLegend,TLine
37 from ROOT
import TLatex,TGaxis, gFile
50 colours = [ EColor.kRed+1, EColor.kBlue+1, EColor.kGreen-8, EColor.kYellow+2]
51 markers = [20,25,22,27,23,28,30,21]
54 gROOT.ProcessLine(
".L AtlasStyle.C")
55 gROOT.ProcessLine(
".L AtlasUtils.C")
56 gROOT.ProcessLine(
"SetAtlasStyle();")
60 from ROOT
import gDirectory
62 p = re.compile(pattern)
64 n = gDirectory.GetListOfKeys().GetSize()
68 name = gDirectory.GetListOfKeys().At(i).GetName()
73 h = gDirectory.Get(gDirectory.GetListOfKeys().At(i).GetName())
80 def makePoint( tree,prefix ,xval='x0',xlow=-8, xhigh=8, xbins=100, doGausFit=True, cuts=""):
81 h = TH1D(prefix+
"_"+xval,
"h_"+tree.GetName()+
"_"+xval, xbins, xlow,xhigh)
82 p =
'(%(x)s) >> %(h)s' % {
'x':xval,
'h':h.GetName()}
84 ylabel =
"Entries / XXX"
87 s = ylabel.replace(
"XXX",l)
95 meanErr = h.GetMeanError()
97 rmsErr = h.GetRMSError()
100 f = h.GetFunction(
"gaus")
101 mean = f.GetParameter(1)
102 meanErr = f.GetParError(1)
103 rms = f.GetParameter(2)
104 rmsErr = f.GetParError(2)
106 print h.GetName(), mean, meanErr, rms, rmsErr
107 return (mean, meanErr, rms, rmsErr,h)
110 def AddText(xmin,ymin,text,size=0.015, font=None):
114 m.SetTextColor(EColor.kBlack);
118 m.DrawLatex(xmin,ymin,text);
123 subs = {
'p':
'.',
'm':
'-' }
134 t = title.split(cutToken)
135 namestring = t[0].strip(
'_')
136 cutstring = t[-1].strip(
'_')
137 cuts = cutstring.split(
'_')
139 for i
in range(0,len(cuts),2):
142 return output,namestring
145 tr = file.Get(dir +
"/" + name)
156 fii = TFile(files[0])
158 print "Multiple files not yet supported"
170 print "No object in ", chain.GetName(), dir,name
175 def AddStatText(h, minx=0.7,miny=0.7,title="",units="",pars=['Mean','RMS']):
180 Em = h.GetMeanError()
188 AddText(minx, ypos, title,plotTextSize)
190 if "Entries" in pars:
191 nsig =
'N = %(v).0f #pm %(ev).0f' % {
'v': n,
'ev': En}
192 AddText(minx, ypos, nsig,plotTextSize)
195 mass =
'#mu= %(v).04f #pm %(ev).04f %(u)s'% {
'v': m,
'ev': Em,
'u':units}
196 AddText(minx, ypos, mass,plotTextSize)
199 sigma=
'RMS = %(v)2.4f #pm %(ev)2.4f %(u)s'% {
'v': r,
'ev': Er,
'u':units}
200 AddText(minx, ypos, sigma,plotTextSize)
207 cuts=
'nEvents>5000&&fitID==1&&fitStatus==1'
209 xpos =
makePoint( tree,name, xval=
'xc',xbins=100,xlow=-0.16,xhigh=-0.12,doGausFit=
False,cuts=cuts)[-1]
210 ypos =
makePoint( tree,name, xval=
'yc',xbins=100,xlow=0.99,xhigh=1.02,doGausFit=
False,cuts=cuts)[-1]
211 zpos =
makePoint( tree,name, xval=
'z', xbins=50,xlow=-2,xhigh=3,doGausFit=
False,cuts=cuts)[-1]
213 sx =
makePoint( tree,name,xval=
'sx',xbins=100,xlow=0.06,xhigh=0.1,doGausFit=
False,cuts=cuts)[-1]
214 sy =
makePoint( tree,name, xval=
'sy',xbins=100,xlow=0.06,xhigh=0.1,doGausFit=
False,cuts=cuts)[-1]
215 sz =
makePoint( tree,name, xval=
'sz',xbins=100,xlow=55,xhigh=65,doGausFit=
False,cuts=cuts)[-1]
216 ax =
makePoint( tree,name, xval=
'ax',xbins=50,xlow=400e-6,xhigh=700e-6,doGausFit=
False,cuts=cuts)[-1]
217 ay =
makePoint( tree,name, xval=
'ay',xbins=50,xlow=-20e-6,xhigh=100e-6,doGausFit=
False,cuts=cuts)[-1]
218 k =
makePoint( tree,name, xval=
'k', xbins=100,xlow=0.9,xhigh=1.3,doGausFit=
False,cuts=cuts)[-1]
219 rhoxy =
makePoint( tree,name, xval=
'rhoxy',xbins=100,xlow=-0.3,xhigh=0.3,doGausFit=
False,cuts=cuts)[-1]
221 return (xpos, ypos, zpos, sx, sy, sz, ax, ay, k, rhoxy)
225 def makeCanvas(name, hists, xlabel, ylabel, doStats=True,doLegend=True, units="", logy=False,setMinZero=True,drawOptions="",histLabels=[]):
226 canv = TCanvas(name,
"",800,600)
232 max = ( m
if m>max
else max)
234 min = (m
if m < min
else min)
236 if setMinZero
and not logy:
247 i.SetMarkerColor(colours[c])
248 i.SetLineColor(colours[c])
249 i.SetMarkerStyle(markers[m])
251 if c == len(colours):
254 if m == len(markers):
259 i.SetMaximum( max*1.5)
261 if "XXX" not in ylabel :
267 l =
'%(n).4f'%{
'n':n}
268 s = ylabel.replace(
"XXX",l)
273 i.Draw(drawOptions+
"sames")
278 for i
in range(len(hists)):
279 if len(histLabels) == 0:
280 AddStatText(hists[i], minx=0.7, miny=pos, title = hists[i].GetName())
282 AddStatText(hists[i], minx=0.7, miny=pos, title = histLabels[i])
285 leg = TLegend(0.2,0.7,0.4,0.9)
288 leg.SetBorderSize(0);
289 for i
in range(len(hists)):
290 if len(histLabels) == 0:
291 leg.AddEntry(hists[i], hists[i].GetName())
293 leg.AddEntry(hists[i], histLabels[i])
311 , xlabel=
"nTracks", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
314 , xlabel=
"chi2", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
316 , xlabel=
"prob", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
318 , xlabel=
"sumpt", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
321 ,xlabel=
"x [mm]", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
323 ,xlabel=
"y [mm]", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
325 ,xlabel=
"z [mm]", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
328 ,xlabel=
"#sigma(x) [mm]", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
330 ,xlabel=
"#sigma(y) [mm]", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
332 ,xlabel=
"#sigma(z) [mm]", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
336 ,xlabel=
"Pull x", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
338 ,xlabel=
"Pull y", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
340 ,xlabel=
"Pull z", ylabel =
"Entries/ XXX", logy=logy,histLabels=nameLabels))
349 , xlabel=
"#DeltanTracks", ylabel =
"Entries/ XXX", logy=
True,histLabels=nameLabels))
351 , xlabel=
"#Deltasumpt", ylabel =
"Entries/ XXX", logy=
True,histLabels=nameLabels))
354 ,xlabel=
"#Deltax [mm]", ylabel =
"Entries/ XXX", logy=
True,histLabels=nameLabels))
356 ,xlabel=
"#Deltay [mm]", ylabel =
"Entries/ XXX", logy=
True,histLabels=nameLabels))
358 ,xlabel=
"#Deltaz [mm]", ylabel =
"Entries/ XXX", logy=
True,histLabels=nameLabels))
361 ,xlabel=
"#Delta#sigma(x) [mm]", ylabel =
"Entries/ XXX", logy=
True,histLabels=nameLabels))
363 ,xlabel=
"#Delta#sigma(y) [mm]", ylabel =
"Entries/ XXX", logy=
True,histLabels=nameLabels))
365 ,xlabel=
"#Delta#sigma(z) [mm]", ylabel =
"Entries/ XXX", logy=
True,histLabels=nameLabels))
377 fii = TFile(files[0])
379 print "Multiple files not yet supported"
388 fii = TFile(files[0])
398 cs.extend(
makeStandardPlots(fii,prefix=
"VtxAllCombRespixsct", names=[
'AllDefault',
'AllRes',
'AllPix',
'AllSCT'],nameLabels=[
'Combined',
'Resolved',
'Pix',
'SCT']) )
399 cs.extend(
makeStandardPlots(fii,prefix=
"VtxMatcombrespixsct", names=[
'MatchedDefault',
'resMatched',
'pixMatched',
'sctMatched'],nameLabels=[
'Combined',
'resMatched',
'Pix',
'SCT'],doMC=
True) )
400 cs.extend(
makeStandardPlots(fii,prefix=
"VtxMatcombrespixsctNoLog", names=[
'MatchedDefault',
'resMatched',
'pixMatched',
'sctMatched'],nameLabels=[
'Combined',
'resMatched',
'Pix',
'SCT'],doMC=
True,logy=
False) )
402 cs.extend(
makeDeltaPlots(fii, prefix=
"VtxDpixcomb", names=[
'pixMatchedComb'],nameLabels=[
'Comb-Pix']) )
403 cs.extend(
makeDeltaPlots(fii, prefix=
"VtxDrescomb", names=[
'resMatchedComb'],nameLabels=[
'Comb-Res']) )
404 cs.extend(
makeDeltaPlots(fii, prefix=
"VtxDsctcomb", names=[
'sctMatchedComb'],nameLabels=[
'Comb-SCT']) )
405 cs.extend(
makeDeltaPlots(fii, prefix=
"VtxDpixsct", names=[
'sctMatchedPix'], nameLabels=[
'Pix-SCT']) )
407 cs.extend(
makeDeltaPlots(fii, prefix=
"VtxDrespixsctcomb", names=[
'resMatchedComb',
'pixMatchedComb',
'sctMatchedComb'],nameLabels=[
'Res-Comb',
'Pix-Comb',
'SCT-Comb']) )
414 if len(options.beamspotFile):
415 bsfii = TFile(options.beamspotFile)
420 type = [
'Adaptive',
'InDetPriVxFinderFastFinder',
'InDetPriVxFinderFullFinder']
438 if "TRT" in i.GetName():
440 if "SCT" in i.GetName():
442 elif "Pix" in i.GetName():
444 elif "Combined" in i.GetName():
446 elif "Res" in i.GetName():
462 hrhoxy.append(hists[9])
464 cs.append(
makeCanvas(t+
"_x",hx,
"x [mm]",
"Entries / (XXX mm)"))
465 cs.append(
makeCanvas(t+
"_y",hy,
"y [mm]",
"Entries / (XXX mm)"))
466 cs.append(
makeCanvas(t+
"_z",hz,
"z [mm]",
"Entries / (XXX mm)"))
467 cs.append(
makeCanvas(t+
"_sx",hsx,
"sx [mm]",
"Entries / (XXX mm)"))
468 cs.append(
makeCanvas(t+
"_sy",hsy,
"sy [mm]",
"Entries / (XXX mm)"))
469 cs.append(
makeCanvas(t+
"_sz",hsz,
"sz [mm]",
"Entries / (XXX mm)"))
470 cs.append(
makeCanvas(t+
"_ax",hax,
"ax [mm]",
"Entries / (XXX mm)"))
471 cs.append(
makeCanvas(t+
"_ay",hay,
"ay [mm]",
"Entries / (XXX mm)"))
472 cs.append(
makeCanvas(t+
"_k",hk,
"k [mm]",
"Entries / (XXX mm)"))
473 cs.append(
makeCanvas(t+
"_rhoxy",hrhoxy,
"rhoxy [mm]",
"Entries / (XXX mm)"))
476 i.SaveAs(
"plots/"+i.GetName()+
".eps")
477 i.SaveAs(
"plots/"+i.GetName()+
".png")
481 s = raw_input(
'--> ')