#!/usr/bin/python # -*- coding: iso-8859-15 -*- 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 # import psyco # psyco.full() # from time import sleep # from optparse import OptionParser # from ROOT_Tools import RootHandler # from CommandLineMod import CommandLine if __name__ == "__main__": gStyle.SetTitleBorderSize ( 0 ) # duh # gStyle.SetTitleBorderSize ( 1 ) gStyle.SetPadBorderMode ( 0 ) gStyle.SetOptStat ( 111111 ) # Good standard stats display. gStyle.SetOptFit ( 1111 ) # Display fit info if available. # gStyle.SetMarkerStyle ( 24 ) # Open circle. gStyle.SetOptTitle ( 1 ) # Display histogram titles. gStyle.SetCanvasColor ( 10 ) # Background color (white) gStyle.SetPadColor ( 10 ) # Background color (white) gStyle.SetFillColor ( 10 ) # Background color (white) # gStyle.SetHistFillColor ( 10 ) # Background color (white) gStyle.SetFrameFillColor ( 10 ) # Background color (white) gStyle.SetStatColor ( 10 ) # Background color (white) gStyle.SetTextFont ( 132 ) gStyle.SetPadLeftMargin (0.15) gStyle.SetPadBottomMargin (0.13) gStyle.SetPadTopMargin (0.07) gStyle.SetPadRightMargin (0.05) gStyle.SetTitleFillColor ( 10 ) # Background color (white) gStyle.SetTitleFontSize ( 0.08 ) # Title Font Size gStyle.SetTitleX ( 0.10 ) # Title box width gStyle.SetTitleW ( 0.50 ) # Title box width gStyle.SetTitleH ( 0.09 ) # Title box width gStyle.SetStatX ( 0.95 ) # Statistic box width gStyle.SetStatW ( 0.2 ) # Statistic box width gStyle.SetStatBorderSize ( 1 ) gStyle.SetLegendBorderSize ( 1 ) gStyle.SetPalette ( 1 ) # Nicer colour scale for 2D histograms. gStyle.SetPaperSize ( 20., 24. ) gStyle.SetHistLineWidth ( 1 ) gStyle.SetLabelFont(132) gStyle.SetLabelFont(132,"X") gStyle.SetLabelFont(132,"Y") gStyle.SetLabelFont(132,"Z") gStyle.SetLabelFont(132,"T") gStyle.SetTitleFont(132) gStyle.SetTitleFont(132,"X") gStyle.SetTitleFont(132,"Y") gStyle.SetTitleFont(132,"Z") gStyle.SetTitleFont(132,"T") gStyle.SetLabelSize(0.04) gStyle.SetLabelSize(0.04,"X") gStyle.SetLabelSize(0.04,"Y") gStyle.SetLabelSize(0.04,"Z") gStyle.SetLabelSize(0.04,"T") gStyle.SetTitleSize(0.04 ) gStyle.SetTitleSize(0.04,"X") gStyle.SetTitleSize(0.04,"Y") gStyle.SetTitleSize(0.04,"Z") gStyle.SetTitleSize(0.04,"T") gStyle.SetTextFont(132) gStyle.SetStatFont(132) gROOT.SetBatch() gROOT.ForceStyle() # No Stats ! gStyle.SetOptStat ( 0 ) # Good standard stats display. gStyle.SetOptFit ( 0 ) # Display fit info if available. gStyle.SetTitleW ( 0.70 ) # Title box width gStyle.SetPaperSize(17,19) gStyle.SetCanvasDefW(900) # Defaults gStyle.SetCanvasDefH(1100) # Defaults # We can have many files in input # FileList = ['TCS2006B_Charac_Ph4_Pa3.root'] FileList = ['s73a8s3_raw.root', 'g473a1s2_raw.root'] HistName = 'Fiducail/dpcosth_fid' OutputFile = ['../dpcosth_s73.eps'] F=[] Canv = TCanvas() # Leg = TLegend(0.38, 0.35,0.72,0.5) Leg = TLegend(0.70, 0.85,0.90,0.95) Leg2 = TLegend(0.36, 0.34,0.71,0.39) MinX = -0.7 MaxX = 2.55 # MinX = -0.049 # MaxX = 0.049 MinY = 100 MaxY = 353000 # Title = 'TDC time versus TDC width, wire 12;Width [ns];Hit time [ns]' Title = ';;Count' LegName = ['Data','MC','(Data - MC) / MC'] t=0 H = [] # H = [TH1D(),TH1D(),TH1D(),TH1D()] Canv.cd() MainPad = TPad("MainPad","MainPad", 0., 0.4, 1., 1.) MainPad.SetLogy() MainPad.Draw() DiffPad = TPad("DiffPad", "DiffPad", 0., 0.0, 1., 0.4) DiffPad.Draw() for i,f in enumerate(FileList): F.append( TFile(f) ) H.append(F[i].Get(HistName)) MainPad.cd() MainPad.SetBottomMargin (0.0) MainPad.SetGrid(1,3) # gPad.SetLogY() if ( i == 0): H[i].SetLineColor(4) H[i].SetLineWidth(1) H[i].SetMarkerColor(4) H[i].SetMarkerStyle(4) H[i].SetMarkerSize(0.6) H[i].Rebin(5) H[i].Scale(2000000/H[i].Integral()) H[i].Draw('E') # H[i].SetLabelSize(0) H[i].SetTitle(Title) H[i].SetAxisRange(MinX,MaxX,'X') H[i].SetAxisRange(MinY,MaxY,'Y') # H.SetLineWidth(1) H[i].SetTitleSize(0.05,"Y") H[i].SetTitleOffset( 1.2, 'Y') # H.Fit('pol1', "Q","", 20.0, 150.0) # H.GetFunction('pol1').SetLineWidth(1) # Hdiff = H[i].Clone() Hdiff = TH1D("PercDiff",H[i].GetTitle(), H[i].GetNbinsX(), H[i].GetXaxis().GetXmin(), H[i].GetXaxis().GetXmax()) else: H[i].SetLineColor(2) H[i].SetMarkerColor(2) # Htmp[t].SetLineWidth(1) H[i].SetMarkerStyle(5) H[i].SetMarkerSize(0.6) H[i].Rebin(5) #H[i].Scale(1/H[i].Integral()) H[i].Scale(2000000/H[i].Integral()) #H[i].Scale(H[0].Integral()/H[i].Integral()) H[i].Draw('sameE') for j in range(Hdiff.GetNbinsX()): if ( H[0].GetBinContent(j) != 0 and H[1].GetBinContent(j) != 0 ): Val = ( H[0].GetBinContent(j) - H[1].GetBinContent(j)) / H[1].GetBinContent(j) Err = ( H[0].GetBinContent(j)/H[1].GetBinContent(j)) * sqrt( ( H[0].GetBinError(j) * H[0].GetBinError(j) / (H[0].GetBinContent(j)*H[0].GetBinContent(j))) + ( H[1].GetBinError(j) * H[1].GetBinError(j) / (H[1].GetBinContent(j)*H[1].GetBinContent(j)))) # Err = sqrt( ( H[0].GetBinError(j) * H[0].GetBinError(j) ) + ( H[1].GetBinError(j) * H[1].GetBinError(j) )) # print H[0].GetBinCenter(j), Err, Val, sqrt( ( H[0].GetBinError(j) * H[0].GetBinError(j) / (H[0].GetBinContent(j)*H[0].GetBinContent(j))) + ( H[1].GetBinError(j) * H[1].GetBinError(j) / (H[1].GetBinContent(j)*H[1].GetBinContent(j)))) else: Val = 0 Err = 0 Hdiff.SetBinContent(j, Val * 100) Hdiff.SetBinError(j, Err * 100) # print Hdiff.GetBinError(j) # Hdiff.Scale(100.) DiffPad.cd() DiffPad.SetGrid() Hdiff.SetTitleSize(0.07) Hdiff.SetTitleSize(0.07,"X") Hdiff.SetTitleSize(0.09,"Y") Hdiff.SetTitleSize(0.07,"Z") Hdiff.SetTitleSize(0.07,"T") Hdiff.SetTitleOffset(0.5,"Y") Hdiff.SetTitle(';#Delta p |cos#theta| = (p^{US} - p^{DS}) |cos#theta| [Mev/c];%') Hdiff.SetLabelSize(0.07) Hdiff.SetLabelSize(0.07,"X") Hdiff.SetLabelSize(0.07,"Y") Hdiff.SetLabelSize(0.07,"Z") Hdiff.SetLabelSize(0.07,"T") DiffPad.SetTopMargin (0.0) DiffPad.SetBottomMargin (0.20) Hdiff.Draw('E1') Hdiff.SetMarkerStyle(0) Hdiff.SetAxisRange(MinX,MaxX,'X') Hdiff.SetAxisRange(-36,34,'Y') # Leg.AddEntry(H[i], LegName[i]+' '+str(H[i].GetEntries()), 'p') Leg.AddEntry(H[i], LegName[i], 'p') # for j,H in enumerate([H2D.ProjectionX(LegName[i]+'_X'), H2D.ProjectionY(LegName[i]+'_Y')]): # # Shift to change the X axis from mofia coordinates to drift distance # Htmp[t].SetName('TmpHisto'+str(i)+str(j)) # Htmp[t].SetBins(H.GetNbinsX(),H.GetXaxis().GetXmin()+3.368,H.GetXaxis().GetXmax()+3.368) # for b in range(1, (H.GetNbinsX()+1) ): # Htmp[t].SetBinContent(b, H.GetBinContent(b)) # Canv[j].cd() # if ( i == 0): # Htmp[t].Draw() # Htmp[t].SetTitle(Title[j]) # Htmp[t].SetAxisRange(MinX,MaxX,'X') # Htmp[t].SetAxisRange(MinY,MaxY,'Y') # Htmp[t].SetLineWidth(1) # Htmp[t].SetTitleOffset( 1.2, 'Y') # # H.Fit('pol1', "Q","", 20.0, 150.0) # # H.GetFunction('pol1').SetLineWidth(1) # else: # if ( i > 3 ): # Htmp[t].SetLineColor(i+2) # Htmp[t].SetMarkerColor(i+2) # else: # Htmp[t].SetLineColor(i+1) # Htmp[t].SetMarkerColor(i+1) # Htmp[t].SetLineWidth(1) # Htmp[t].Draw('same') # if ( j == 0 ): # Leg.AddEntry(Htmp[t], LegName[i], 'l') # t = t + 1 Leg2.AddEntry(Hdiff, LegName[2], 'l') Canv.cd() Leg.Draw() Leg2.Draw() # For eps Canv.Print(OutputFile[0]) # Canv[1].cd() # Leg.Draw() # # For eps # Canv[1].Print(OutputFile[1])