void SecondFitFunc() { TCanvas *c1 = new TCanvas("c1", "c1", 800, 600); c1->cd(); gPad->SetLogy(); TGraphErrors *graph = new TGraphErrors("without_target.csv", "%lg, %lg, %*lg, %lg"); graph->SetMarkerStyle(21); graph->SetMarkerColor(kBlue); graph->SetLineColor(kBlue); graph->Draw("APE"); graph->SetTitle("without_target;Bin Center;Counts"); graph->Draw("AP"); graph->GetXaxis()->SetLimits(-50, 50); graph->SetMinimum(1); graph->SetMaximum(1000000); TF1 *fitFunc = new TF1("fitFunc", "[0]*( (1-[1])*ROOT::Math::normal_pdf(x - [2], [3]) + [1]*ROOT::Math::tdistribution_pdf( (x-[2])/[4], [5]) ) ", -50, 50); fitFunc->SetNpx(1000); fitFunc->SetParLimits(0,1e5,1e6); fitFunc->SetParLimits(1,0,1.); fitFunc->SetParLimits(2,-1.,1.); fitFunc->SetParLimits(3,0,5); fitFunc->SetParLimits(4,0,5); fitFunc->SetParLimits(5,0,5); fitFunc->SetParameters(300000, 0.05, 0.1, 0.6, 3, 3); graph->Fit(fitFunc, "L", "", -50, 50); double params[6]; fitFunc->GetParameters(params); TCanvas *c2 = new TCanvas("c2", "c2", 800, 600); c2->cd(); gPad->SetLogy(); TGraphErrors *graph2 = new TGraphErrors("with_target.csv", "%lg, %lg, %*lg, %lg"); graph2->SetMarkerStyle(21); graph2->SetMarkerColor(kBlue); graph2->SetLineColor(kBlue); graph2->Draw("APE"); graph2->SetTitle("with_target;Bin Center;Counts"); graph2->Draw("AP"); graph2->GetXaxis()->SetLimits(-50, 50); graph2->SetMinimum(1); graph2->SetMaximum(1000000); TF1Convolution *f_conv = new TF1Convolution("fitFunc", "ROOT::Math::tdistribution_pdf(x/[1],[0])", -50,50, true); f_conv->SetRange(-50,50.); f_conv->SetNofPointsFFT(1000); TF1 *f = new TF1("f_conv", *f_conv, -50., 50., f_conv->GetNpar()); f->SetParLimits(0,5e4,1e6); f->SetParLimits(1,0,1.); f->SetParLimits(2,-1.,1.); f->SetParLimits(3,0,10); f->SetParLimits(4,0,10); f->SetParLimits(5,0,10); // f->SetParameters(6e5, 0.26, 0.004, 1, 1., 1., 5,5); f->SetParameters(params); f->SetNpx(1000); graph2->Fit(f, "L", "", -50, 50); f = graph2->GetFunction("f_conv"); f->GetNDF(); f->GetChisquare(); f->GetProb(); std::cout << "Chi-squared: " << f->GetChisquare() << std::endl; std::cout << "NDF: " << f->GetNDF() << std::endl; std::cout << "Probability: " << f->GetProb() << std::endl; }