#!/usr/bin/python import os,sys,glob pmin = 52.7 pmax = 52.9 fit_diff_plot = False def show_usage(): print 'usage: make_plot.py file1.root file2.root' print data_files = glob.glob('/home/e614/analysis_2006_2007/treesum/data/*/*ecal*edge*root') sim_files = glob.glob('/home/e614/analysis_2006_2007/treesum/mc/*/*ecal*edge*root') for d in data_files+sim_files: print d sys.exit(-1) return None def make_histo(hi,(pmin,pmax),(othermin,othermax),(binfirst,binlast),col,mark,tit): hi.SetMinimum(pmin) hi.SetMaximum(pmax) hi.GetXaxis().SetRange(binfirst,binlast) hi.SetLineColor(col) hi.SetMarkerColor(col) hi.SetMarkerStyle(mark) hi.SetMarkerSize(0.5) hi.GetYaxis().SetDecimals() hi.GetYaxis().SetTitleOffset(1.7) hi.SetTitle(tit) return hi def make_diff_histo(dh1,dh2,xaxis_title): di = dh2.Clone() di.Add(dh1,-1.) di.SetMinimum(-0.099) di.SetMaximum(0.1) di.SetMarkerColor(1) di.SetLineColor(1) di.GetYaxis().SetNdivisions(404) di.GetYaxis().SetLabelSize(.10) di.GetXaxis().SetLabelSize(.10) di.GetYaxis().SetTitleSize(.10) di.GetYaxis().SetTitleOffset(.6) di.GetXaxis().SetTitleSize(.10) di.SetTitle('; '+xaxis_title+'; #Deltap (MeV/c)') return di if __name__=='__main__': ## __________ checking usage __________ if len(sys.argv)!=3: show_usage() fn1 = sys.argv[1] fn2 = sys.argv[2] nice_fn1 = fn1.split('/')[-1] nice_fn2 = fn2.split('/')[-1] ## __________ importing root __________ print 'importing ROOT...', from ROOT import * from clean_canvas import * from nice_colours import * gStyle = makegstyle(gStyle) gStyle = nice_colours(gStyle) if fit_diff_plot: gStyle.SetOptFit(1) print '... done' f1 = TFile(fn1) h = f1.Get('best_iteration/edgea') h_ang_DS_fn1 = make_histo(h.Clone(),(pmin,pmax),(20.,70.),(0,80), 2,20,'downstream; angle (#circ); momentum (MeV/c)') h_ang_US_fn1 = make_histo(h.Clone(),(pmin,pmax),(81.,200.),(82,160), 2,20,'upstream; angle (#circ); momentum (MeV/c)') h = f1.Get('best_iteration/edget') h_cos_DS_fn1 = make_histo(h.Clone(),(pmin,pmax),(-3.5,-0.5),(0,80), 2,20,'upstream; 1/cos#theta; momentum (MeV/c)') h_cos_US_fn1 = make_histo(h.Clone(),(pmin,pmax),(1.2,3.5),(87,180), 2,20,'downstream; 1/cos#theta; momentum (MeV/c)') f2 = TFile(fn2) h = f2.Get('best_iteration/edgea') h_ang_DS_fn2 = make_histo(h.Clone(),(pmin,pmax),(20.,70.),(0,80), 4,21,'downstream; angle (#circ); momentum (MeV/c)') h_ang_US_fn2 = make_histo(h.Clone(),(pmin,pmax),(81.,200.),(82,160), 4,21,'upstream; angle (#circ); momentum (MeV/c)') h = f2.Get('best_iteration/edget') h_cos_DS_fn2 = make_histo(h.Clone(),(pmin,pmax),(-3.5,-0.5),(0,80), 4,21,'upstream; 1/cos#theta; momentum (MeV/c)') h_cos_US_fn2 = make_histo(h.Clone(),(pmin,pmax),(1.2,3.5),(87,180), 4,21,'downstream; 1/cos#theta; momentum (MeV/c)') c1 = TCanvas('c1','c1',0,72,700,500) c1.SetGridx() c1.SetGridy() c1.Range(20.,pmin,70.,pmax) c1.SetLeftMargin(0.15) h_ang_DS_fn1.Draw() h_ang_DS_fn2.Draw('same') l1 = TLegend(.8,.8,.9,.9) l1.SetBorderSize(1) l1.AddEntry(h_ang_DS_fn1,nice_fn1,'pl') l1.AddEntry(h_ang_DS_fn2,nice_fn2,'pl') l1.Draw() li1 = TLine(26.,52.828,64.,52.828) li1.SetLineStyle(9) li1.SetLineWidth(2) li1.Draw() diff_histo1 = make_diff_histo(h_ang_DS_fn1,h_ang_DS_fn2,'angle (#circ)') c1_diff = TCanvas('c1_diff','c1_diff',0,72,700,200) c1_diff.SetGridx() c1_diff.SetGridy() c1_diff.SetLeftMargin(0.15) c1_diff.SetBottomMargin(0.25) diff_histo1.Draw() c1_cos = TCanvas('c1_cos','c1_cos',0,72,700,500) c1_cos.SetGridx() c1_cos.SetGridy() c1_cos.Range(-3.5,pmin,-0.5,pmax) c1_cos.SetLeftMargin(0.15) h_cos_DS_fn1.Draw() h_cos_DS_fn2.Draw('same') l1_cos = TLegend(.8,.8,.9,.9) l1_cos.SetBorderSize(1) l1_cos.AddEntry(h_cos_DS_fn1,nice_fn1,'pl') l1_cos.AddEntry(h_cos_DS_fn2,nice_fn2,'pl') l1_cos.Draw() li1_cos = TLine(-2.36,52.828,-1.12,52.828) li1_cos.SetLineStyle(9) li1_cos.SetLineWidth(2) li1_cos.Draw() diff_cos_histo1 = make_diff_histo(h_cos_DS_fn1,h_cos_DS_fn2,'1/cos#theta') c1_diff_cos = TCanvas('c1_diff_cos','c1_diff_cos',0,72,700,200) c1_diff_cos.SetGridx() c1_diff_cos.SetGridy() c1_diff_cos.SetLeftMargin(0.15) c1_diff_cos.SetBottomMargin(0.25) # diff_cos_histo1.Fit('pol0','EM','',-2.36,-1.12) if fit_diff_plot: diff_cos_histo1.Fit('pol1','EM','',-2.36,-1.12) diff_cos_histo1.Draw() c2 = TCanvas('c2','c2',0,72,700,500) c2.SetGridx() c2.SetGridy() c2.Range(81.,pmin,200.,pmax) c2.SetLeftMargin(0.15) h_ang_US_fn1.Draw() h_ang_US_fn2.Draw('same') l2 = TLegend(.8,.8,.9,.9) l2.SetBorderSize(1) l2.AddEntry(h_ang_US_fn1,nice_fn1,'pl') l2.AddEntry(h_ang_US_fn2,nice_fn2,'pl') l2.Draw() li2 = TLine(116.,52.828,154.,52.828) li2.SetLineStyle(9) li2.SetLineWidth(2) li2.Draw() diff_histo2 = make_diff_histo(h_ang_US_fn1,h_ang_US_fn2,'angle (#circ)') c2_diff = TCanvas('c2_diff','c2_diff',0,72,700,200) c2_diff.SetGridx() c2_diff.SetGridy() c2_diff.SetLeftMargin(0.15) c2_diff.SetBottomMargin(0.25) diff_histo2.Draw() c2_cos = TCanvas('c2_cos','c2_cos',0,72,700,500) c2_cos.SetGridx() c2_cos.SetGridy() c2_cos.Range(1.0,pmin,3.5,pmax) c1_cos.SetLeftMargin(0.15) h_cos_US_fn1.Draw() h_cos_US_fn2.Draw('same') l2_cos = TLegend(.8,.8,.9,.9) l2_cos.SetBorderSize(1) l2_cos.AddEntry(h_cos_US_fn1,nice_fn1,'pl') l2_cos.AddEntry(h_cos_US_fn2,nice_fn2,'pl') l2_cos.Draw() li2_cos = TLine(1.01,52.828,2.36,52.828) li2_cos.SetLineStyle(9) li2_cos.SetLineWidth(2) li2_cos.Draw() diff_cos_histo2 = make_diff_histo(h_cos_US_fn1,h_cos_US_fn2,'1/cos#theta') c2_diff_cos = TCanvas('c2_diff_cos','c2_diff_cos',0,72,700,200) c2_diff_cos.SetGridx() c2_diff_cos.SetGridy() c2_diff_cos.SetLeftMargin(0.15) c2_diff_cos.SetBottomMargin(0.25) # diff_cos_histo2.Fit('pol0','EM','',1.01,2.36) if fit_diff_plot: diff_cos_histo2.Fit('pol1','EM','',1.01,2.36) diff_cos_histo2.Draw() au = raw_input('>')