// macro to fit function depthdose to data in testem75.root #include using namespace std; #include "TNtuple.h" #include "TCanvas.h" #include "TROOT.h" #include "TF1.h" #include "TH1.h" #include "TLegend.h" #include "TString.h" #include "TLine.h" #include "TPaveText.h" #include #include #include #include #include //open file testem75 and get histogram h2 void dedao() { gROOT->SetStyle("Plain"); //set plain TStyle gStyle->SetOptStat(111111); //draw statistics on plots, 0 for no output gStyle->SetOptFit(1111); //draw fit results on plot, 0 for no output gStyle->SetPalette(57); //set color map gStyle->SetOptTitle(1); //suppress title box //--------------------------------------------------------------------------------------------- TF1* func1 = new TF1("func1", "1/x", .1, 9); // create a canvas, specifying size and position TCanvas *c1 = new TCanvas("c1", "Depth Dose Profiles",700, 500); //c1->Divide(2,2); //set subdivisions //c1->cd(1); //change to pad 1 of canvas c1 TFile *Varian_4MV_Total_8cm = new TFile("Varian_4MV_Total_8cm.root"); TNtuple *ndepth_dose_4MVV_all_8cm; Varian_4MV_Total_8cm->GetObject("RMD_SUB", ndepth_dose_4MVV_all_8cm); Long64_t N = ndepth_dose_4MVV_all_8cm->Draw("B:RMD_sub:RMD_sub_error","","goff"); TGraphErrors *gr1 = new TGraphErrors (N,ndepth_dose_4MVV_all_8cm->GetV1(),ndepth_dose_4MVV_all_8cm->GetV2(),ndepth_dose_4MVV_all_8cm->GetV3()); gr1->GetXaxis()->SetRangeUser(0, 9.1); gr1->GetYaxis()->SetRangeUser(0.0, 1.05); // gr1->GetYaxis()->SetDecimals(3); gr1->GetXaxis()->SetTitle("B (T)"); gr1->GetYaxis()->SetTitle("#beta)"); gr1->GetXaxis()->CenterTitle(); gr1->GetYaxis()->CenterTitle(); gr1->SetName("Graph1"); gr1->SetLineColor(1); gr1->GetYaxis()->SetNdivisions(5,5,0); gr1->GetXaxis()->SetNdivisions(10,2,0); gr1->GetYaxis()->SetTitleOffset(1.5); gr1->SetLineWidth(1); gr1->Draw("alp"); gPad->ls(); //Legend TLegend *legend = new TLegend(.49, 0.69, .89, .89); legend->SetHeader("#alpha(B): Phantom without Cavity"); legend->SetFillColor(0); egend->SetLineColor(0); legend->Draw(); gPad->Modified(); gPad->Update(); Varian_4MV_Total_8cm->Close(); } int main() { dedao(); return 0; }