How can i fitting more accurately?

Hi expert!
I have a problem when i was fitting histogram.
Here is my code.

TFile *f = new TFile("NaI37_bdtcut.root");
TH1F *N_new = new TH1F("N_new","N_new",19,1,20);
Double_t xbins[100];
TH1F *N_37 = (TH1F*)f->Get("N_37");
N_37->Draw("E");

Double_t par1[13];

double r1 = 1;
double r2 = 8;
double r3 = 2;
double r4 = 4;

TF1 *fp = new TF1("fp","pol0",r1,r2);
N_37->Fit(fp,"R");

TF1 *fg = new TF1("fg","gaus",r3,r4);
fg->FixParameter(1, 3.5);
fg->FixParameter(2, 6.76268e-1);
N_37->Fit(fg,"B","R+");



TF1 *f1 = new TF1("f1","pol0(0)+gaus(1)",r1,r2);
f1->Draw("same");
f1->SetLineColor(kRed);
fp->GetParameters(&par1[0]);
fg->GetParameters(&par1[1]);
f1->SetParameters(par1);
f1->FixParameter(2, f1->GetParameter(2));
f1->FixParameter(3, f1->GetParameter(3));

f1->SetLineColor(kRed);
N_37->Fit(f1,"B","R+",1,8);


TF1 *f2 = new TF1("f2","pol0",r1,r2);
f2->Draw("same");
f2->SetLineColor(kBlue);
f2->SetParameters(par1);


N_37->Fit(f2,"B","R+",1,8);

auto fitresult1 = N_37->Fit(f1,"S","",1,8);
auto fitresult2 = N_37->Fit(f2,"S+","",1,8);

and result is below picture.

This is not the fitting result i expected.
I want the graph fitted to a peak of 3.5.
And also want to fitting the pol0 graph and pol0+gaus graph in unison.

What should i do?

Hi,
I think the fit is correct, given your limited data points. Maybe an unbinned fit will be better, if you have the original data. You can also try to use option ā€œIā€ (integral of the functgion in the bin).
If I need to look in more detail, I would need the input ROOT file to be posted as well.

Cheers

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.