#include #include #include #include using namespace std; void momentum() { Int_t n = 8; Float_t datax[] = {3.1025,3.1349,3.1665,3.1829,3.1989,3.2149,3.2309,3.2469}; Float_t datay[] = {557,2285,5471,8197,7789,6915,4470,1280}; Float_t dataex[] = {0,0,0,0,0,0,0,0}; Float_t dataey[] = {2.997,10.530,16.636,61.685,61.815,90.740,61.804,52.636}; TCanvas *c1 = new TCanvas("c1","55Ni momentum distribution",1); gr1 = new TGraphErrors(n,datax,datay,dataex,dataey); gr1->SetTitle("Momentum Distribution"); gr1->SetMarkerStyle(21); gr1->SetMarkerColor(2); gr1->Draw("AP"); Double_t par[5]; TF1 *g1 = new TF1("g1","expo",3.0,3.172); TF1 *g2 = new TF1("g2","gaus",3.170,3.26); TF1 *total = new TF1("total","exp([0]+[1]*x)+[2]*exp(-0.5*((x-[3])/[4])^2)",3.0,3.26); total->SetLineColor(2); gr1->Fit(g1,"R"); gr1->Fit(g2,"R+"); g1->GetParameters(&par[0]); g2->GetParameters(&par[2]); total->SetParameters(par); //total->FixParameter(0,par[0]); //total->FixParameter(1,par[1]); //total->FixParameter(2,par[2]); //total->FixParameter(3,par[3]); //total->FixParameter(4,par[4]); gr1->Fit(total,"R+"); Double_t chi2_gaus = g2->GetChisquare(); cout << "chi2 for fit gaussian " << chi2_gaus << endl; Double_t chi2_expo = g1->GetChisquare(); cout << "chi2 for fit exponential " << chi2_expo << endl; Double_t chi2_total = total->GetChisquare(); cout << "chi2 for fit total " << chi2_total << endl; }