#include "TCanvas.h" #include "TGraphErrors.h" #include "TF1.h" #include "TLegend.h" /********************************************/ /* Cameron Dean */ /* University of Glasgow */ /* 22/09/2017 */ /* General Script To Plot Graphs */ /********************************************/ void Graph_Plotter(){ TCanvas *c1 = new TCanvas("c1","A Simple Graph",200,10,700,500); //c1->SetFillColor(42); c1->SetGrid(); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderSize(12); /* IBIAS = 64, ITHR = 50 const Int_t n = 14; Double_t x[n] = {0.75, 1.25, 2.25, 3.25, 4.25, 4.50, 4.75, 5.00, 5.25, 5.50, 5.75, 6.00, 6.25, 6.50}; Double_t ex[n] = {0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02}; Double_t y[n] = {2.31, 2.40, 2.37, 2.34, 2.13, 2.06, 1.88, 1.39, 0.83, 0.43, 0.25, 0.16, 0.10, 0.09}; Double_t y_2[n] = {2.79, 2.74, 2.68, 2.64, 2.42, 2.36, 2.16, 1.73, 1.16, 0.64, 0.40, 0.24, 0.16, 0.13}; Double_t y_3[n] = {3.08, 3.21, 3.14, 3.12, 2.90, 2.87, 2.78, 2.48, 1.74, 0.94, 0.56, 0.33, 0.25, 0.17}; Double_t y_4[n] = {2.33, 2.44, 2.41, 2.36, 2.11, 1.91, 1.61, 1.13, 0.68, 0.38, 0.24, 0.15, 0.10, 0.10}; Double_t ey[n] = {0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01}; */ const Int_t n = 14; Double_t x[n] = {1.00, 2.00, 4.00, 6.00, 6.50, 7.00, 7.50, 8.00, 8.50, 9.00, 10.0, 11.0, 12.0, 13.0}; Double_t y[n] = {3.43, 3.54, 3.40, 3.28, 3.27, 3.31, 3.27, 2.98, 2.36, 1.89, 1.40, 1.29, 1.19, 1.10}; Double_t y_2[n] = {3.93, 3.95, 3.79, 3.67, 3.67, 3.70, 3.69, 3.47, 2.93, 2.40, 1.69, 1.49, 1.34, 1.23}; Double_t y_3[n] = {4.40, 4.55, 4.43, 4.29, 4.27, 4.33, 4.49, 4.63, 4.29, 3.61, 2.17, 1.73, 1.55, 1.43}; Double_t y_4[n] = {3.51, 3.65, 3.53, 3.36, 3.34, 3.37, 3.28, 2.91, 2.33, 1.95, 1.50, 1.33, 1.22, 1.14}; Double_t ex[n] = {0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02}; Double_t ey[n] = {0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01}; TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey); gr->SetMarkerSize(2); gr->Draw("A*"); TGraphErrors *gr_2 = new TGraphErrors(n,x,y_2,ex,ey); gr_2->Draw("A*"); TGraphErrors *gr_3 = new TGraphErrors(n,x,y_3,ex,ey); gr_3->Draw("A*"); TGraphErrors *gr_4 = new TGraphErrors(n,x,y_4,ex,ey); gr_4->SetMarkerSize(2); gr_4->Draw("A*"); gPad->SetLogy(); gr_4->GetXaxis()->SetTitleFont(132); gr_4->GetXaxis()->SetLabelFont(132); gr_4->GetYaxis()->SetTitleFont(132); gr_4->GetYaxis()->SetLabelFont(132); gr_4->SetTitle("Strobe Delay"); gr_4->GetXaxis()->SetTitle("Time [#mus]"); gr_4->GetYaxis()->SetTitle("N Pixels / Event"); gPad->Update(); gr->Draw(); gr_2->Draw("SAME"); gr_3->Draw("SAME"); gr_4->Draw("SAME"); gPad->Update(); //gr->Fit("pol1"); /* TF1 *f1 = new TF1("fa1","[0] + [1]*x",0,0.22); gr->Fit(f1); double gradient = f1->GetParameter(1); double gradErr = f1->GetParError(1); double k = 4.231e-3; double r = 0.26; double eOm = gradient*2/(k*r*k*r); double eOmErr = eOm*(gradErr/gradient); cout<<"The ratio is "<SetBorderSize(0); legend->AddEntry(gr, "E103", "pl"); legend->AddEntry(gr_2, "C105", "pl"); legend->AddEntry(gr_3, "C104", "pl"); legend->AddEntry(gr_4, "A105", "pl"); legend->SetTextFont(132); legend->SetFillStyle(0); legend->Draw(); TPaveText *pt = new TPaveText(.2,1.1,4,3.3); pt->AddText("VPULSEH = 170"); pt->AddText("VPULSEL = 100"); pt->AddText("VRESETP = 147"); pt->AddText("VCASN = 50"); pt->AddText("VCASP = 86"); pt->AddText("VCASN2 = 57"); pt->AddText("VCLIP = 0"); pt->AddText("IDB = 29"); pt->AddText("#bf{IBIAS = 44}"); pt->AddText("#bf{ITHR = 21}"); pt->SetTextFont(132); pt->SetBorderSize(1); pt->SetFillColor(0); pt->Draw(); gr_4->SetTitle("Strobe Delay"); gr->SetMarkerColor(4); gr->SetLineColor(4); gr->SetLineStyle(2); gr->SetMarkerStyle(1); gr_2->SetMarkerColor(1); gr_2->SetLineColor(1); gr_2->SetLineStyle(3); gr_2->SetMarkerStyle(1); gr_2->SetMarkerSize(2); gr_3->SetMarkerColor(2); gr_3->SetLineColor(2); gr_3->SetLineStyle(4); gr_3->SetMarkerStyle(1); gr_3->SetMarkerSize(2); gr_4->SetLineColor(6); gr_4->SetMarkerColor(6); gr_4->SetMarkerStyle(0); gr_4->SetMarkerSize(2); gr_4->GetYaxis()->SetRangeUser( 1, 10); gr_3->GetXaxis()->SetRangeUser(0, 10); gPad->Update(); gPad->Modified(); }