#!/usr/bin/python # -*- coding: iso-8859-15 -*- # Anthony Hillairet # April 2009 import os,sys # import getopt ##maybe it's supposed to be sys.argv[:] ... maybe tmpargv = sys.argv sys.argv = [ '-n' ] from ROOT import * sys.argv = tmpargv from fpformat import fix if __name__ == "__main__": # ================ Display (Canvas, pads ...) =================== # # Canvas gStyle.SetCanvasColor ( 10 ) # Background color (white) gStyle.SetCanvasDefH(700) # Default = 500 gStyle.SetCanvasDefW(900) # Default = 700 # Output size # gStyle.SetPaperSize ( 20., 24. ) # Default = 20.,26. # For eps: gStyle.SetPaperSize ( 15., 17. ) # 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.13) gStyle.SetPadBottomMargin (0.13) gStyle.SetPadRightMargin (0.05) gStyle.SetPadTopMargin (0.03) # Miscellaneous gStyle.SetFillColor ( 10 ) # Background color (white) gStyle.SetFrameFillColor ( 10 ) # Background color (white) # ================ Fonts variable ================= # Font = 132 # Times roman FontSize = 0.07 # ================ 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 ( 2 ) # ================ 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 ( 1.00 ) # Title box Y gStyle.SetTitleW ( 0.85 ) # Title box width gStyle.SetTitleH ( 0.13 ) # Title box height gStyle.SetTitleBorderSize ( 1 ) 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() fu = '../../../5/pic/Inefficiency_source/g473a1s2_raw_s73a8s3_rawUSineff.root' fd = '../../../5/pic/Inefficiency_source/g473a1s2_raw_s73a8s3_rawDSineff.root' out = '../Ineff_DataMCDiff.eps' title=', silver upstream stops (set73)' # fu = 'g580a1s3_raw_s80a1s3_rawUSineff.root' # fd = 'g580a1s3_raw_s80a1s3_rawDSineff.root' # out = 'g580a1s3_raw_s80a1s3_raw_Ineff.eps' # title=', aluminium upstream stops (set80)' # fu = 's89a1s7_raw_g689a1s3_rawUSineff.root' # fd = 's89a1s7_raw_g689a1s3_rawDSineff.root' # out = 's89a1s7_raw_g689a1s3_raw_Ineff.eps' fuf = TFile(fu) iup = fuf.Get('hdiff_pflx').Clone() iuct = fuf.Get('hdiff_pfly').Clone() fud = TFile(fd) idp = fud.Get('hdiff_pflx').Clone() idct = fud.Get('hdiff_pfly').Clone() #change ranges iup.GetXaxis().SetRangeUser(15.,55.) idp.GetXaxis().SetRangeUser(15.,55.) iuct.GetXaxis().SetRangeUser(0.5001,1.00) idct.GetXaxis().SetRangeUser(0.5001,1.00) hs = [iup,idp,iuct,idct] for h in hs: # h.Scale(1000.) # h.SetMinimum(-.999) # h.SetMaximum(1.) h.SetMinimum(-0.999e-3) h.SetMaximum(1e-3) h.SetMarkerStyle(2) # h.GetXaxis().SetMaxDigits(2) #only for tgaxis damn you # h.GetYaxis().SetMaxDigits(2) h.GetXaxis().SetDecimals() h.GetYaxis().SetDecimals() h.GetXaxis().SetTitleOffset(1.0) h.GetYaxis().SetTitleOffset(1.8) # h.SetTitleSize(0.07) # h.GetXaxis().SetTitleSize(0.07) # h.GetYaxis().SetTitleSize(0.07) # h.GetXaxis().SetLabelSize(0.07) # h.GetYaxis().SetLabelSize(0.07) h.GetXaxis().SetNdivisions(505) h.GetYaxis().SetNdivisions(505) for h in [iup,idp]: h.SetTitle('; p (MeV/c); #Delta efficiency (data-sim)') for h in [iuct,idct]: h.SetTitle('; |cos#theta|; #Delta efficiency (data-sim)') # h.GetXaxis().SetLabelSize(FontSize) h.GetXaxis().SetTitleSize(0.085) h.GetYaxis().SetTitleSize(0.085) h.GetXaxis().SetLabelSize(0.085) h.GetYaxis().SetLabelSize(0.085) h.GetXaxis().SetTitleOffset(1.0) h.GetYaxis().SetTitleOffset(1.5) iup.SetTitle('Upstream'+title) idp.SetTitle('Downstream'+title) for h in [iup,idp]: h.Fit('pol0','EM') g = h.GetFunction('pol0') g.SetLineWidth(2) g.SetLineStyle(7) pa = 1E4*g.GetParameter(0) epa = 1E4*g.GetParError(0) print 2*'\n' print 'momentum plot: diff = (',fix(pa,2),'+-',fix(epa,2),') x 10^{-4}' print 2*'\n' for h in [iuct,idct]: h.Fit('pol1','EM') g = h.GetFunction('pol1') g.SetLineWidth(2) g.SetLineStyle(7) pa0 = 1E4*g.GetParameter(0) epa0 = 1E4*g.GetParError(0) pa1 = 1E4*g.GetParameter(1) epa1 = 1E4*g.GetParError(1) print 2*'\n' print 'momentum plot: diff =(',fix(pa0,1),'+-',fix(epa0,1),') + (',fix(pa1,1),'+-',fix(epa1,1),')cos-theta x 10^{-4}' print 2*'\n' Canv = TCanvas('Canv','Canv') Canv_1 = TPad("Canvas_1","Canvas_1", 0.0, 0.45, 0.5, 1.0) Canv_2 = TPad("Canvas_2","Canvas_2", 0.5, 0.45, 1.0, 1.0) Canv_3 = TPad("Canvas_3","Canvas_3", 0.0, 0.0, 0.5, 0.45) Canv_4 = TPad("Canvas_4","Canvas_4", 0.5, 0.0, 1.0, 0.45) Canv_1.Draw() Canv_2.Draw() Canv_3.Draw() Canv_4.Draw() for ci in [Canv_1,Canv_2,Canv_3,Canv_4]: ci.SetGridx() ci.SetGridy() ci.SetLeftMargin(.25) ci.SetRightMargin(.05) ci.SetBottomMargin(.2) for ci in [Canv_1,Canv_2]: ci.SetTopMargin(.18) Canv_1.cd() iup.Draw() Canv_2.cd() idp.Draw() Canv_3.cd() iuct.Draw() Canv_4.cd() idct.Draw() Canv.Print(out) # # We can have many files in input # File = 'run_50691_to_50705.root' # # HistName = 'Graph' # # OutputFile = 'output.ps' # # eps is preferable because one can change the size of the output # OutputFile = '../EdgeScan.eps' # # Canv = TCanvas() # # # Axis range # # MinX = 0.0 # # MaxX = 10 # # MinY = -100. # # MaxY = 100. # gStyle.SetOptStat ( 0 ) # gStyle.SetOptFit ( 0 ) # # Title = ';P [MeV];M scintillator counts, normalized' # F = TFile(File) # # H = F.Get(HistName) # # H.Draw("AP") # # H.GetHistogram().SetNdivisions(505) # # # Plots title # H.SetTitle(Title) # # # f1 = TF1("f1","gaus", 29.0,30.6) # # f1.SetParameter(0,1.2) # # f1.SetParameter(1,29.6) # # f1.SetParameter(2,0.12569) # # # f1.SetLineWidth(1) # # f1.SetLineColor(3) # # f1.Draw("same") # # # # # Change the axis range # # H.SetAxisRange(MinX,MaxX,'X') # # H.SetAxisRange(MinY,MaxY,'Y') # # # Change the position of the axis labels # # H.SetTitleOffset( 1.2, 'Y') # # # If you want to fit a straight line or something else # # H.Fit('pol1', "Q","", 20.0, 150.0) # # # # For Postscript # # Canv.Print(OutputFile,"Landscape") # # For eps # Canv.Print(OutputFile)