#include #include //#define N 4 void beam_calibration(){ TGraph *gr = new TGraph(); TMultiGraph *mg = new TMultiGraph(); Double_t slope, intercept; const Int_t N = 4; Double_t fc_current[N] = {6.912664851, 12.79845209, 18.76219677, 32.40474996}; Double_t dose[N] = {66.19495288, 128.2179372, 185.7405073, 308.9333599}; Int_t n = sizeof(fc_current) / sizeof(fc_current[0]); cout << "size = " << n << endl; TF1 *function = new TF1("linear", "pol1(0)"); std::ofstream ofs("beam_calibration_cxx.txt"); mg->Add(gr, "p"); gr->SetMarkerStyle(8); gr->SetMarkerSize(1.5); gr->SetMarkerColor(1); for(Int_t i = 0; i < n; i++){ gr->SetPoint(i, fc_current[i], dose[i]); } gr->Fit("linear"); gr->GetFunction("linear")->SetLineColor(1); intercept = function->GetParameter(0); slope = function->GetParameter(1); ofs << "intercept = " << intercept << ", slope = " << slope << endl; ofs.close(); TCanvas *c0 = new TCanvas("c0", "c0", 40, 40, 740, 640); c0->ToggleEditor(); c0->ToggleEventStatus(); c0->ToggleToolBar(); c0->cd(); //gPad.SetLogx(); //gPad.SetLogy(); gStyle->SetLabelFont(42, "xy"); gStyle->SetLabelSize(0.05, "xy"); gStyle->SetLabelOffset(1e-5, "x"); gStyle->SetLabelOffset(5e-3, "y"); gStyle->SetTitleFont(42, "xy"); gStyle->SetTitleSize(0.05, "xy"); gStyle->SetTitleOffset(1.1, "x"); gStyle->SetTitleOffset(1.2, "y"); mg->Draw("APL"); //mg->GetXaxis()->SetLimits(-2*pi, 2*pi); mg->GetXaxis()->SetTitle("FC Current [pnA]"); mg->GetXaxis()->CenterTitle(1); mg->GetYaxis()->SetTitle("Dose [#muSv/h]"); mg->GetYaxis()->CenterTitle(1); //mg->GetYaxis()->SetRangeUser(0, 10); TPaveText *p = new TPaveText(0.40, 0.91, 0.60, 0.95, "NDC"); p->AddText("Beam Calibration"); p->SetTextFont(42); p->SetTextSize(0.05); p->SetBorderSize(0); p->SetFillColor(0); p->Draw("same"); c0->Modified(); c0->Update(); }