Python
BookHistos.py
Go to the documentation of this file.
1 import ROOT,os,sys,getopt
2 import rootUtils as ut
3 import shipunit as u
4 import RecoSettings
5 def SetGrid(pad):
6  pad.SetGridx()
7  pad.SetGridy()
8 
9 def SetAxis(histo):
10  histo.GetXaxis().SetTitleSize(.06)
11  histo.GetYaxis().SetTitleSize(.06)
12  histo.GetXaxis().SetTitleOffset(1.3)
13  histo.GetYaxis().SetTitleOffset(1.3)
14  histo.GetXaxis().SetNdivisions(5)
15  histo.GetYaxis().SetNdivisions(5)
16 
17 
18 ###################################################################################
19 ###################################################################################
20 ###################################################################################
22  #ax0 = ';#chi^{2}/ndf;(P_{MCthuth}-P_{RECO})/P_{MCtruth}'
23  #ax = ';P_{MCthuth} [GeV];(P_{MCthuth}-P_{RECO})/P_{MCtruth}'
24  colour = {"fit":2, "sim":1}
25  for fall in ["fit", "sim"] :
26  ut.bookHist(h,'magZ' +fall, 'Field.Mag() vs Z at (0,0)'+fall+';z [cm];|B| [T]', 3000, 1000, 4000,200,0,2)
27  h['magZ'+fall].SetLineColor(colour[fall])
28  h['magZ'+fall].SetMarkerColor(colour[fall])
29  ut.bookHist(h,'magXY1'+fall, 'Field.Mag() vs (X,Y) at Z=2500 cm, '+fall+';x [cm];y [cm]', 60, -300.,300.,60,-300,300)
30  ut.bookHist(h,'magXY2'+fall, 'Field.Mag() vs (X,Y) at Z=2800 cm, '+fall+';x [cm];y [cm]', 60, -300.,300.,60,-300,300)
31  ut.bookHist(h,'magXY3'+fall, 'Field.Mag() vs (X,Y) at Z=3000 cm, '+fall+';x [cm];y [cm]', 60, -300.,300.,60,-300,300)
32  for histo in h:
33  SetAxis(h[histo])
34  h[histo].SetLineColor(1)
35  h[histo].SetMarkerStyle(20)
36 
37 ###################################################################################
39  ROOT.gStyle.SetStatY(0.9)
40  ROOT.gStyle.SetStatX(0.9)
41  ROOT.gStyle.SetStatW(0.3)
42  ROOT.gStyle.SetStatH(0.2)
43  ROOT.gStyle.SetPadBottomMargin(0.2)
44  ROOT.gStyle.SetPadLeftMargin(0.2)
45  ROOT.gStyle.SetPadRightMargin(0.2)
46 
47  ROOT.gStyle.SetOptStat(0)
48  ut.bookCanvas(h,"mfield1","mfield1",nx=600,ny=600,cx=1,cy=1)
49  cv = h['mfield1'].cd(1)
50  h['magZsim'].Draw("")
51  h['magZfit'].Draw("sames")
52  h['mfield1'].Print('mfield1.gif')
53 
54  ut.bookCanvas(h,"mfield2","mfield2",nx=1200,ny=800,cx=3,cy=2)
55  pad = 0
56  for fall in ["fit", "sim"] :
57  for ci in range (1,4):
58  pad+=1
59  cv = h['mfield2'].cd(pad)
60  h['magXY'+str(ci)+fall].Draw("colz")
61  h['mfield2'].Print('mfield2.gif')
62 
63 
64 ###################################################################################
65 ###################################################################################
66 ###################################################################################
67 def bookMomentumHistos(h,prefix=""):
68  ax0 = ';#chi^{2}/ndf;(P_{MCthuth}-P_{RECO})/P_{MCtruth}'
69  ax = ';P_{MCthuth} [GeV];(P_{MCthuth}-P_{RECO})/P_{MCtruth}'
70  ut.bookHist(h,'delPOverP0'+prefix, 'dP/P vs #chi^{2}/ndf'+prefix+ax0, 500,0.,50.,100,-0.5,0.5)
71  ut.bookHist(h,'delPOverP1'+prefix, 'dP/P'+prefix+ax,100,0.,50.,100,-0.5,0.5)
72  ut.bookHist(h,'delPOverP2'+prefix, 'dP/P ndf>'+str(RecoSettings.trackMinNofHits)+prefix+ax,100,0.,50.,100,-0.5,0.5)
73  ut.bookHist(h,'delPOverP3'+prefix, 'dP/P cleaned #chi^{2}/ndf<'+str(RecoSettings.chi2CutOff)+prefix+ax,100,0.,50.,100,-0.5,0.5)
74  ut.bookHist(h,'MomRes'+prefix, 'MomRes'+prefix+';P_{MCthuth} [GeV];#sigma_{Gauss}(#DeltaP/P)',5,0.,50.)
75  for i in range (1,6):
76  hhname='delPOverP3_'+str(i)+prefix
77  cond ='P_{MCtruth} < '+str(i*10)+" GeV"
78  ut.bookHist(h, hhname, cond+';(P_{MCthuth}-P_{RECO})/P_{MCtruth}', 200, -.2, .2)
79  h[hhname].StatOverflows(True) # to include overflow/underflow in mean/sigma (range independence)
80 
81  for histo in h:
82  h[histo].Sumw2()
83  h[histo].SetLineColor(1)
84  h[histo].SetMarkerStyle(20)
85 
86 ###################################################################################
87 def plotMomentumHistos(h,prefix=""):
88  ROOT.gStyle.SetStatY(0.9)
89  ROOT.gStyle.SetStatX(0.9)
90  ROOT.gStyle.SetStatW(0.3)
91  ROOT.gStyle.SetStatH(0.2)
92  ROOT.gStyle.SetPadBottomMargin(0.2)
93  ROOT.gStyle.SetPadLeftMargin(0.2)
94 
95  ROOT.gStyle.SetOptStat(10)
96  ut.bookCanvas(h,key='momentum1'+prefix,title='momentum1'+prefix,nx=1000,ny=800,cx=2,cy=2)
97  for cid in range (1,5):
98  cv = h['momentum1'+prefix].cd(cid)
99  hname = 'delPOverP'+str(cid-1)+prefix
100  h[hname].Draw("box")
101  SetAxis(h[hname])
102  if(cid==1):
103  cv.SetLogx()
104  h[hname].GetXaxis().SetRangeUser(.01,50)
105  h['momentum1'+prefix].Print('momentum1'+prefix+'.gif')
106 
107  ROOT.gStyle.SetStatY(0.93)
108  ROOT.gStyle.SetStatX(0.99)
109  ROOT.gStyle.SetStatW(0.4)
110  ROOT.gStyle.SetStatH(0.35)
111  f={}
112  key='momentum2'+prefix
113  ut.bookCanvas(h,key,title=key,nx=1200,ny=1200,cx=3,cy=2)
114  rname = 'MomRes'+prefix
115  for cvn in range (1,6):
116  hname='delPOverP3_'+str(cvn)+prefix
117  cv = h[key].cd(cvn)
118  h[hname].Draw("E")
119  SetAxis(h[hname])
120  ROOT.gStyle.SetOptFit(11111)
121  f[hname] = ROOT.TF1(hname,'gaus',-.05, .05)
122  f[hname].SetParameter(1,0.)
123  f[hname].SetNpx(1000)
124  h[hname].Fit(f[hname],"R")
125  print "fit", f[hname].GetParameter(2), f[hname].GetParError(2)
126  h[rname].SetBinContent(cvn, f[hname].GetParameter(2))
127  h[rname].SetBinError (cvn, f[hname].GetParError(2))
128  h[key].Print(key+'.gif')
129 
130  ROOT.gStyle.SetOptStat(0)
131  ROOT.gStyle.SetOptTitle(0)
132  ut.bookCanvas(h,'momentum3'+prefix,title='momentum3'+prefix,nx=600,ny=600,cx=1,cy=1)
133  h[rname].Draw('E')
134  SetAxis(h[rname])
135  h[hname].GetYaxis().SetTitleOffset(1.5)
136  h['momentum3'+prefix].Print('momentum3'+prefix+'.gif')
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 ###################################################################################
147 ###################################################################################
148 ###################################################################################
150  ut.bookHist(h,'dNFoldFNnew', 'Number of fitted tracks;N(old);N(new)',
151  10, -1, 9, 10, -1, 9)
152  h['dNFoldFNnew'].SetMarkerSize(1.8)
153  ut.bookHist(h,'FitCorrespondence', 'CorrespondenceBins: 0,5-ok',
154  10, -1, 9)
155  ut.bookHist(h,'NDFold', 'NDF old Fit;NDF', 140, 0, 70)
156  ut.bookHist(h,'NDFnew', 'NDF new Fit;NDF', 140, 0, 70)
157  ut.bookHist(h,'Chi2NDFold', '#chi^{2}/NDF old Fit;#chi^{2}/NDF', 200, 0, 20)
158  ut.bookHist(h,'Chi2NDFnew', '#chi^{2}.NDF old Fit;#chi^{2}/NDF', 200, 0, 20)
159  style={'old':0,'new':1}
160  for name in ('NDF','Chi2NDF'):
161  for st in style:
162  h[name+st].SetLineColor(1+style[st])
163  h[name+st].SetMarkerColor(1+style[st])
164  h[name+st].SetMarkerStyle(22+style[st])
165  for histo in h:
166  h[histo].Sumw2()
167  h[histo].SetLineWidth(2)
168 
169 
170 ###################################################################################
172  ROOT.gStyle.SetStatY(0.9)
173  ROOT.gStyle.SetStatX(0.9)
174  ROOT.gStyle.SetStatW(0.3)
175  ROOT.gStyle.SetStatH(0.2)
176  ROOT.gStyle.SetOptStat(11)
177  ut.bookCanvas(h,key='FitCompare',title='FitCompare',nx=800,ny=800,cx=2,cy=2)
178  cv = h['FitCompare'].cd(1)
179  cv.SetLogz()
180  h['dNFoldFNnew'].Draw('coltext')
181  cv = h['FitCompare'].cd(2)
182  cv.SetLogy()
183  h['FitCorrespondence'].Draw()
184  cv = h['FitCompare'].cd(3)
185  cv.SetLogy()
186  h['NDFold'].Draw()
187  h['NDFnew'].Draw("sames")
188  cv = h['FitCompare'].cd(4)
189  cv.SetLogx()
190  cv.SetLogy()
191  h['Chi2NDFold'].Draw()
192  h['Chi2NDFnew'].Draw("sames")
193  h['FitCompare'].Print('FitCompare.gif')
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 ###################################################################################
204 ###################################################################################
205 ###################################################################################
207  ut.bookHist(h,'dxdyALLTrHm', 'dxdy(MCtr,firstHit)@firstHitZ - all-;dx [cm];dy [cm]',
208  2000, -100, 100, 2000, -100, 100)
209  ut.bookHist(h,'dxdyALLTrHp', 'dxdy(MCtr,firstHit)@firstHitZ - all+;dx [cm];dy [cm]',
210  2000, -100, 100, 2000, -100, 100)
211 
212  ut.bookHist(h,'dxdyHNLTrHm', 'dxdy(MCtr,firstHit)@firstHitZ - HNL-;dx [cm];dy [cm]',
213  2000, -100, 100, 2000, -100, 100)
214  ut.bookHist(h,'dxdyHNLTrHp', 'dxdy(MCtr,firstHit)@firstHitZ - HNL+;dx [cm];dy [cm]',
215  2000, -100, 100, 2000, -100, 100)
216 
217  ut.bookHist(h,'dRvsPz', 'dR(MCtr,firstHit)@firstHitZ vs Pz;Pz_{MC} [GeV];dR [cm]',
218  1000, 0, 50, 1000, 0, 100)
219  ut.bookHist(h,'dRvsZhit', 'dR(MCtr,firstHit)@firstHitZ vs firstHitZ;Z_{Hit0} [cm];dR [cm]',
220  2400, 2500, 3700, 1000, 0, 100)
221 
222  ut.bookHist(h,'YMC2dZMCVer', 'abs(YMCprop)/dZMCVer - HNL', 2000, 0,10)
223 
224  for histo in h:
225  h[histo].Sumw2()
226  h[histo].SetLineColor(1)
227 
228 ###################################################################################
230  ROOT.gStyle.SetStatY(0.9)
231  ROOT.gStyle.SetStatX(0.9)
232  ROOT.gStyle.SetStatW(0.3)
233  ROOT.gStyle.SetStatH(0.2)
234  ROOT.gStyle.SetOptStat(11)
235 
236  ut.bookCanvas(h,key='dRCanvas',title='dRCanvas',nx=1200,ny=600,cx=2,cy=1)
237  ROOT.gStyle.SetOptStat(1)
238  cv = h['dRCanvas'].cd(1)
239  h['dRvsPz'].Draw('colzbox')
240  cv = h['dRCanvas'].cd(2)
241  h['dRvsZhit'].Draw('colzbox')
242  h['dRCanvas'].Print('dRCanvas.gif')
243 
244  ROOT.gStyle.SetOptStat(11)
245  ut.bookCanvas(h,key='ratioYZ',title='ratioYZ',nx=600,ny=600,cx=1,cy=1)
246  ROOT.gStyle.SetOptStat(1)
247  cv = h['ratioYZ'].cd(1)
248  h['YMC2dZMCVer'].Draw()
249  h['ratioYZ'].Print('ratioYZ.gif')
250 
251  for x in ['ALL','HNL']:
252  ut.bookCanvas(h,key='MCTrackHit'+x,title='MCTrackHit'+x,nx=800,ny=800,cx=2,cy=2)
253  ROOT.gStyle.SetOptStat(1)
254  cv = h['MCTrackHit'+x].cd(1)
255  h['dxdy'+x+'TrHp'].Draw('colz')
256  cv = h['MCTrackHit'+x].cd(2)
257  h['dxdy'+x+'TrHm'].Draw('colz')
258  cv = h['MCTrackHit'+x].cd(3)
259  SetGrid(cv)
260  hh=h['dxdy'+x+'TrHp'].DrawCopy('colz')
261  for ax in [hh.GetXaxis(), hh.GetYaxis()]:
262  ax.SetRangeUser(-5,5)
263  cv = h['MCTrackHit'+x].cd(4)
264  SetGrid(cv)
265  hh=h['dxdy'+x+'TrHm'].DrawCopy('colz')
266  for ax in [hh.GetXaxis(), hh.GetYaxis()]:
267  ax.SetRangeUser(-5,5)
268  h['MCTrackHit'+x].Print('MCTrackHit'+x+'.gif')
269 
270 
271 
272 
273 
274 
275 
276 
277 ###################################################################################
278 ###################################################################################
279 ###################################################################################
280 def bookVertexHistos(h, prefix=""):
281  if prefix=="NEW":
282  ut.bookHist(h,'docaRel'+prefix, 'docaRel'+prefix+";step;doca/doca0", 5, 0, 5, 2000, 0., 2.)
283  ut.bookHist(h,'doca' +prefix, 'doca' +prefix+";doca [cm]", 500, 0., 100.)
284  h['doca'+prefix].SetLineColor(2)
285  ut.bookHist(h,'doca0' +prefix, 'doca0' +prefix+";doca0 [cm]", 500, 0., 100.)
286  ut.bookHist(h,'vdx2'+prefix, 'vdx2'+prefix, 500, 0, 5000, 400, -20., 20.)
287  ut.bookHist(h,'vdy2'+prefix, 'vdy2'+prefix, 500, 0, 5000, 400, -20., 20.)
288  ut.bookHist(h,'vdz2'+prefix, 'vdz2'+prefix, 500, 0, 5000, 4000, -400., 400.)
289  ut.bookHist(h,'vdx2ndf'+prefix, 'vdx2ndf'+prefix, 500, 0, 5000, 400, -20., 20.)
290  ut.bookHist(h,'vdy2ndf'+prefix, 'vdy2ndf'+prefix, 500, 0, 5000, 400, -20., 20.)
291  ut.bookHist(h,'vdz2ndf'+prefix, 'vdz2ndf'+prefix, 500, 0, 5000, 4000, -400., 400.)
292  if ( (prefix=="mUP") or (prefix=="mDN") ) : return
293  for i in range (1,11):
294  hhname='vdx2_'+str(i)+prefix
295  ut.bookHist(h, hhname, hhname, 100, -20., 20.)
296  h[hhname].StatOverflows(True) # to include overflow/underflow in mean/sigma (range independence)
297  hhname='vdy2_'+str(i)+prefix
298  ut.bookHist(h, hhname, hhname, 100, -20., 20.)
299  h[hhname].StatOverflows(True)
300  hhname='vdz2_'+str(i)+prefix
301  ut.bookHist(h, hhname, hhname, 200, -400., 400.)
302  h[hhname].StatOverflows(True)
303  for coord in ('x','y','z') :
304  hname = "vres"+coord+prefix
305  ut.bookHist(h, hname, hname+"z_{0}-z_{truth} [cm];", 10, 0., 5000.)
306  for histo in h:
307  h[histo].Sumw2()
308  h[histo].SetLineColor(1)
309 
310 
311 ###################################################################################
312 def plotVertexHistos(h,prefix=""):
313  ROOT.gStyle.SetStatY(0.9)
314  ROOT.gStyle.SetStatX(0.9)
315  ROOT.gStyle.SetStatW(0.3)
316  ROOT.gStyle.SetStatH(0.1)
317  ROOT.gStyle.SetOptStat(1)
318 
319  coordTitle = {1:'x',2:'y',3:'z'}
320  cut = {0:'',1:'ndf'}
321  ut.bookCanvas(h,key='vertex2'+prefix,title='vertex2'+prefix,nx=600,ny=1200,cx=2,cy=3)
322  for fall in cut:
323  for cid in coordTitle.keys():
324  cv = h['vertex2'+prefix].cd(cid*2-1+fall)
325  cv.SetBottomMargin(0.2)
326  cv.SetLeftMargin(0.2)
327  hname = 'vd'+coordTitle[cid]+'2'+cut[fall]+prefix
328  h[hname].Draw("box")
329  h[hname].GetXaxis().SetTitle("z_{0}-z_{truth} [cm]")
330  ytitle = coordTitle[cid]+"_{truth}-v"+coordTitle[cid]+"_{reco} [cm]"
331  h[hname].GetXaxis().SetTitleSize(.06)
332  h[hname].GetYaxis().SetTitleSize(.06)
333  h[hname].GetYaxis().SetTitleOffset(1.3)
334  h[hname].GetYaxis().SetNdivisions(5)
335  h['vertex2'+prefix].Print('vertex2'+prefix+'.gif')
336  if ( (prefix=="mUP") or (prefix=="mDN") ) : return
337 
338  f={}
339  for ct in coordTitle.values():
340  key =ct+prefix
341  ut.bookCanvas(h,key,title=key,nx=1600,ny=1200,cx=5,cy=2)
342  f[key]={}
343  for cvn in range (1,11):
344  hname='vd'+ct+'2_'+str(cvn)+prefix
345  cv = h[key].cd(cvn)
346  cv.SetBottomMargin(0.2)
347  h[hname].Draw("E")
348  xtitle = "v"+ct+"_{truth}-v"+ct+"_{reco} [cm]"
349  h[hname].GetXaxis().SetTitle(xtitle)
350  h[hname].GetXaxis().SetTitleSize(.06)
351  ROOT.gStyle.SetOptFit(11111)
352  f[key][hname] = ROOT.TF1(hname,'gaus')
353  f[key][hname].SetNpx(1000)
354  f[key][hname].SetParameter(1,0.)
355  f[key][hname].SetParameter(2,0.2*cvn)
356  h[hname].Fit(f[key][hname])
357  rmsht='vres'+key
358  #h[rmsht].SetBinContent(cvn, h[hname].GetRMS())
359  #h[rmsht].SetBinError (cvn, h[hname].GetRMSError())
360  h[rmsht].SetBinContent(cvn, f[key][hname].GetParameter(2))
361  h[rmsht].SetBinError (cvn, f[key][hname].GetParError(2))
362  h[key].Print(ct+prefix+'.gif')
363 
364  key='vRes'+prefix
365  ut.bookCanvas(h,key,title='vRes'+prefix,nx=800,ny=800,cx=2,cy=2)
366  for cti in coordTitle :
367  cv = h[key].cd(cti)
368  rmsht ="vres"+coordTitle[cti]+prefix
369  h[rmsht].SetTitle("vertex "+coordTitle[cti]+" resolution;z_{0}-z_{truth} [cm];#sigma_{Gauss}(#Delta"+coordTitle[cti]+") [cm]")
370  h[rmsht].Draw("E")
371  h[key].Print(key+'.gif')
372 
373  if ( prefix=='NEW' ) :
374  key='docaPlots'+prefix
375  ut.bookCanvas(h,key,key,nx=1200,ny=600,cx=2,cy=1)
376  cv = h[key].cd(1)
377  h['doca'+prefix].Draw()
378  h['doca0'+prefix].Draw("sames")
379  cv = h[key].cd(2)
380  h['docaRel'+prefix].Draw()
381  h[key].Print(key+'.gif')
def plotCompareFitHistos
Definition: BookHistos.py:171
def plotMomentumHistos
Definition: BookHistos.py:87
def plotMCTrackHitCorrelation
Definition: BookHistos.py:229
def plotVertexHistos
Definition: BookHistos.py:312
def SetAxis
Definition: BookHistos.py:9
def SetGrid
Definition: BookHistos.py:5
def bookVertexHistos
Definition: BookHistos.py:280
def plotMFieldHistos
Definition: BookHistos.py:38
def bookMFieldHistos
Definition: BookHistos.py:21
def bookTrackingHistos
Definition: BookHistos.py:206
def bookCompareFitHistos
Definition: BookHistos.py:149
def bookMomentumHistos
Definition: BookHistos.py:67