#!/usr/bin/python import os,sys units = 'z (cm); u or v (cm); fit residual (ns)' ## __________ def read_in_file(fn): coords = [] for l in file(fn,'r').readlines(): ls = l.split() z,uv,res = float(ls[0]),float(ls[1]),float(ls[4]) coords.append((z,uv,res)) return coords ## __________ def make_tg2d(coords,ti): gr = TGraph2D() i = 0 for (z,uv,res) in coords: if res > -999.: i+=1 gr.SetPoint(i,z,uv,-1.*res) # gr.SetPoint(i,z,uv,res) ## style-time gr.SetTitle(ti+';'+units) return gr.Clone() #important! ## ____________________ if __name__=='__main__': data_coords = read_in_file('data_res_of_res.txt') sim_coords = read_in_file('sim_res_of_res.txt') diff_coords = [] for (z_d,uv_d,res_d),(z_s,uv_s,res_s) in zip(data_coords,sim_coords): if z_d!=z_s and uv_d!=uv_s: print 'serious error' sys.exit(-1) if res_d>-999. and res_s>-999.: diff_coords.append((z_d,uv_d,res_d-res_s)) from ROOT import * # ================ Display (Canvas, pads ...) =================== # # Canvas gStyle.SetCanvasColor ( 10 ) # Background color (white) gStyle.SetCanvasDefH(500) # Default = 500 gStyle.SetCanvasDefW(500) # Default = 700 # Output size # gStyle.SetPaperSize ( 20., 24. ) # Default = 20.,26. # For eps: # gStyle.SetPaperSize ( 7., 7. ) # Default = 20.,26. gStyle.SetPaperSize ( 10., 10. ) # Default = 20.,26. # Pads gStyle.SetPadBorderMode ( 0 ) gStyle.SetPadColor ( 10 ) # Background color (white) # gStyle.SetPadLeftMargin (0.13) # gStyle.SetPadBottomMargin (0.13) # gStyle.SetPadRightMargin (0.14) # gStyle.SetPadTopMargin (0.05) gStyle.SetPadLeftMargin (0.14) gStyle.SetPadBottomMargin (0.13) gStyle.SetPadRightMargin (0.10) gStyle.SetPadTopMargin (0.05) # Miscellaneous gStyle.SetFillColor ( 10 ) # Background color (white) gStyle.SetFrameFillColor ( 10 ) # Background color (white) # ================ Fonts variable ================= # Font = 132 # Times roman FontSize = 0.05 # ================ Plots =================== # gStyle.SetOptTitle ( 1 ) # Display histogram titles. gStyle.SetMarkerStyle ( 5 ) # Cross gStyle.SetMarkerSize ( 1 ) # size gStyle.SetPalette ( 1 ) # Nicer colour scale for 2D histograms. gStyle.SetHistLineWidth ( 1 ) # ================ Stat Box =================== # # Display name of the histogram, entries, mean, RMS, underflow, overflow gStyle.SetOptStat ( 111111 ) # Good standard stats display. gStyle.SetOptFit ( 1111 ) # Display fit info if available. gStyle.SetStatColor ( 10 ) # Background color (white) gStyle.SetStatX ( 0.99 ) # Statistic box X gStyle.SetStatY ( 0.98 ) # Statistic box Y gStyle.SetStatW ( 0.25 ) # Statistic box width gStyle.SetStatH ( 0.3 ) # Statistic box height gStyle.SetStatBorderSize ( 1 ) gStyle.SetStatFont(Font) # No Stat box ! # gStyle.SetOptStat ( 0 ) # Good standard stats display. # gStyle.SetOptFit ( 0 ) # Display fit info if available. # ================ Title =================== # gStyle.SetTitleFillColor ( 10 ) # Background color (white) gStyle.SetTitleX ( 0.10 ) # Title box Y gStyle.SetTitleY ( 0.10 ) # Title box Y gStyle.SetTitleW ( 0.50 ) # Title box width gStyle.SetTitleH ( 0.09 ) # Title box height gStyle.SetTitleBorderSize ( 0 ) gStyle.SetTitleFont(Font) gStyle.SetTitleFont(Font, "X") gStyle.SetTitleFont(Font, "Y") gStyle.SetTitleFont(Font, "Z") gStyle.SetTitleFont(Font, "T") gStyle.SetTitleSize(FontSize ) gStyle.SetTitleSize(FontSize,"X") gStyle.SetTitleSize(FontSize,"Y") gStyle.SetTitleSize(FontSize,"Z") gStyle.SetTitleSize(FontSize,"T") # ================ Labels =================== # gStyle.SetLabelFont(Font) gStyle.SetLabelFont(Font, "X") gStyle.SetLabelFont(Font, "Y") gStyle.SetLabelFont(Font, "Z") gStyle.SetLabelFont(Font, "T") gStyle.SetLabelSize(FontSize) gStyle.SetLabelSize(FontSize,"X") gStyle.SetLabelSize(FontSize,"Y") gStyle.SetLabelSize(FontSize,"Z") gStyle.SetLabelSize(FontSize,"T") gStyle.SetStripDecimals(kFALSE) # =============== Text & Legends ================== # gStyle.SetTextFont(Font) gStyle.SetLegendBorderSize ( 1 ) # ============================================= # # Do not display the canvas in a window, plot in a postscript gROOT.SetBatch() # Needed to make sure that all the gStyle parameters are passed to the plots gROOT.ForceStyle() g_data = make_tg2d(data_coords,'data') g_sim = make_tg2d(sim_coords,'simulation') g_diff = make_tg2d(diff_coords,'difference') g_diff2 = make_tg2d(diff_coords,'difference') c1 = TCanvas() c1.Divide(2,2) c1.cd(1) g_data.Draw('surf2') c1.cd(2) g_sim.Draw('surf2') c1.cd(3) g_diff.Draw('surf2') c1.cd(4) g_diff2.SetTitle('difference on #pm 4ns scale;'+units) g_diff2.SetMaximum(4.) g_diff2.SetMinimum(-4.) g_diff2.Draw('surf2') c1.Print("Test.eps") # # now alex's fit function # def ff(x,a): # return -1.*(a[1]*x[1]**2+a[0]*x[0]**2+a[3]*x[1]+a[2]*x[0]) ## return a[1]*x[1]**2+a[0]*x[0]**2+a[3]*x[1]+a[2]*x[0] # # alex_ff = TF2('alexs fit function; '+units,ff,-1.5,1.7,0.0,1.8,4) ## alex_ff.SetParameter(0,-0.31257219) ## alex_ff.SetParameter(1,-0.96603435) ## alex_ff.SetParameter(2,-0.0034988) ## alex_ff.SetParameter(3,1.08264566) ## alex_ff.SetParNames('a0','a1','a2','a3') # alex_ff.SetParameters(-0.31257219, -0.96603435, -0.0034988 , 1.08264566) # # c2 = TCanvas() # alex_ff.Draw('surf2') # # au = raw_input('>')