#!/usr/bin/python from ROOT import TH1D, TCanvas, TGraphErrors, TLegend import ROOT import sys, math, re def plot_results(args): ROOT.gStyle.SetOptStat(0) ROOT.gStyle.SetOptFit(111) ROOT.gStyle.SetPalette(1) ROOT.gStyle.SetCanvasColor(10) ROOT.gStyle.SetLabelFont(132) ROOT.gStyle.SetLabelFont(132,'X') ROOT.gStyle.SetLabelFont(132,'Y') ROOT.gStyle.SetLabelSize(0.06,'X') ROOT.gStyle.SetLabelSize(0.06,'Y') ROOT.gStyle.SetLabelFont(132,'Z') ROOT.gStyle.SetTitleFont(132) ROOT.gStyle.SetTitleFont(132,'X') ROOT.gStyle.SetTitleFont(132,'Y') ROOT.gStyle.SetTitleSize(0.06,'X') ROOT.gStyle.SetTitleSize(0.06,'Y') ROOT.gStyle.SetTitleFont(132,'Z') ROOT.gStyle.SetTextFont(132) ROOT.gStyle.SetStatFont(132) ROOT.gStyle.SetTitleFillColor(10) ROOT.gStyle.SetStatColor(10) ROOT.gStyle.SetPadLeftMargin(0.15) ROOT.gStyle.SetPadRightMargin(0.15) ROOT.gStyle.SetPadTopMargin(0.05) ROOT.gStyle.SetPadBottomMargin(0.15) graphs = [] for a in args: fr = open(a, 'r') hr = TGraphErrors(14) hr.SetMarkerColor(2) hr.SetMarkerStyle(20) hr.SetLineColor(2) c = 0 name = '' for line in fr: m = line.split() print line if len(m): if m[0] == '#': continue else: print m name = m[4] if name == 'chi2/ndof': hr.SetPoint(c, float(m[0]), (float(m[8]))) hr.SetPointError(c, 0, 1./12.) else: hr.SetPoint(c, float(m[0]), (float(m[6]))) hr.SetPointError(c, 0, float(m[8])) c+=1 if name == 'chi2/ndof': hr.SetTitle(';Data Set Number; Endpoint '+name) else : hr.SetTitle(';Data Set Number; Endpoint '+name+' (in keV/c)') graphs.append(hr) c = TCanvas('c','c',800,800) c.Divide(1,len(graphs)/2) for i in range(len(graphs)/2): c_1 = c.cd(i + 1) c_1.SetGridx() c_1.SetGridy() graphs[i*2].SetMarkerColor(2) graphs[i*2].SetMarkerStyle(20) graphs[i*2+1].SetLineColor(4) graphs[i*2+1].SetMarkerColor(4) graphs[i*2+1].SetMarkerStyle(21) leg = TLegend(0.7,0.7, 0.85, 0.85) leg.SetFillColor(10) leg.AddEntry(graphs[i*2],'Upstream','p') leg.AddEntry(graphs[i*2 + 1], 'Downstream','p') max = graphs[i*2].GetHistogram().GetYaxis().GetXmax() + 5 min = graphs[i*2].GetHistogram().GetYaxis().GetXmin() - 5 graphs[i*2].GetHistogram().GetYaxis().SetRangeUser(min,max) graphs[i*2].Draw('ap') graphs[i*2 + 1].Draw('psame') leg.Draw('same') c.Print('TWIST_final_results.eps') def plot_EcalModeDiffs(args): ROOT.gStyle.SetOptStat(0) ROOT.gStyle.SetOptFit(111) ROOT.gStyle.SetPalette(1) ROOT.gStyle.SetCanvasColor(10) ROOT.gStyle.SetLabelFont(132) ROOT.gStyle.SetLabelFont(132,'X') ROOT.gStyle.SetLabelFont(132,'Y') ROOT.gStyle.SetLabelFont(132,'Z') ROOT.gStyle.SetTitleFont(132) ROOT.gStyle.SetTitleFont(132,'X') ROOT.gStyle.SetTitleFont(132,'Y') ROOT.gStyle.SetLabelSize(0.06) ROOT.gStyle.SetLabelSize(0.06,'X') ROOT.gStyle.SetLabelSize(0.06,'Y') ROOT.gStyle.SetLabelSize(0.06,'Z') ROOT.gStyle.SetTitleSize(0.06) ROOT.gStyle.SetTitleSize(0.06,'X') ROOT.gStyle.SetTitleSize(0.06,'Y') ROOT.gStyle.SetTitleOffset(1.,'X') ROOT.gStyle.SetTitleOffset(1.,'Y') ROOT.gStyle.SetTitleFont(132,'Z') ROOT.gStyle.SetTextFont(132) ROOT.gStyle.SetStatFont(132) ROOT.gStyle.SetTitleFillColor(10) ROOT.gStyle.SetStatColor(10) ROOT.gStyle.SetPadLeftMargin(0.15) ROOT.gStyle.SetPadRightMargin(0.15) ROOT.gStyle.SetPadTopMargin(0.10) ROOT.gStyle.SetPadBottomMargin(0.20) fr = open(args[0], 'r') hr = TGraphErrors(14) hr.SetMarkerColor(2) hr.SetMarkerStyle(20) hr.SetLineColor(2) hr.SetTitle(';Data Set Number;#Delta#rho (Shifted - Scaled)/2 #times 10^{4}') c = 0 for line in fr: m = line.split() if m[0] == '#': continue else: print m hr.SetPoint(c, float(m[0]), (float(m[1]) + float(m[3]) \ - float(m[4]) - float(m[6]))/2.) hr.SetPointError(c, 0, float(m[2])*0.03) c+=1 hr.Fit('pol0') fd = open(args[1], 'r') hd = TGraphErrors(14) hd.SetTitle(';Data Set Number;#Delta#delta (Shifted - Scaled)/2 #times 10^{4}') hd.SetMarkerColor(2) hd.SetMarkerStyle(20) hd.SetLineColor(2) c = 0 for line in fd: m = line.split() if m[0] == '#': continue else: print m hd.SetPoint(c, float(m[0]), (float(m[1]) - float(m[4]) + \ float(m[3]) - float(m[6]))/2.) hd.SetPointError(c, 0, float(m[2])*0.03) c+=1 hd.Fit('pol0') fx = open(args[2], 'r') hx = TGraphErrors(9) hx.SetTitle(';Data Set Number;#Delta#xi (Shifted - Scaled)/2 #times 10^{4}') hx.SetMarkerColor(2) hx.SetMarkerStyle(20) hx.SetLineColor(2) c = 0 for line in fx: m = line.split() if m[0] == '#': continue else: print m hx.SetPoint(c, float(m[0]), (float(m[1]) + float(m[3]) - \ float(m[4]) - float(m[6]))/2.) hx.SetPointError(c, 0, float(m[2])*0.03) c+=1 hx.Fit('pol0') c = TCanvas('c','c',800,800) c.Divide(1,3) c_1 = c.cd(1) c_1.SetGridx() c_1.SetGridy() hr.Draw('ap') c_2 = c.cd(2) c_2.SetGridx() c_2.SetGridy() hd.Draw('ap') c_3 = c.cd(3) c_3.SetGridx() c_3.SetGridy() hx.Draw('ap') c.Print('TWIST_ecal_diffs.eps') if __name__ == "__main__": print sys.argv if sys.argv[1] == '0': plot_results(sys.argv[2:]) elif sys.argv[1] == '1': plot_EcalModeDiffs(sys.argv[2:])