Not getting right mean and sigma from the distribution

Dear All,

I have a function that is gauss+linear function. I want to fit my data with this function and extract mean and sigma for each bin. When the function plotted on the distribution it looks good but the values are wrong definitely. How can it be happen? I add the syntax below the message.

Any help will be appreciated.
Regards.

Here it is :

TF1 *fit_template_PP_MB[npt];
TF1 *fit_rest_PP_MB[npt];
TH1D *f1_subt_hSignalD_pp_MC_tof_MB[npt];
double mean_PP_MB[npt]={};
double mean_error_PP_MB[npt]={};
double sigma_PP_MB[npt]={};
double sigma_error_PP_MB[npt]={};

for (int ipt=0; ipt<npt;ipt++) {
fit_template_PP_MB[ipt] = new TF1(“template_function_MB_PP”,“gaus(0)+x*[3]+[4]”,1.059,1.90);
fit_template_PP_MB[ipt]->SetParameter(0,5880.405);
fit_template_PP_MB[ipt]->SetParLimits(0,0,10000000);
fit_template_PP_MB[ipt]->SetParameter(1,1.291424);
fit_template_PP_MB[ipt]->SetParLimits(1,0,10.0);
fit_template_PP_MB[ipt]->SetParameter(2,0.1108336);
fit_template_PP_MB[ipt]->SetParLimits(2,0,1.302835);
fit_template_PP_MB[ipt]->SetParameter(3,521.7006);
fit_template_PP_MB[ipt]->SetParLimits(3,0,100000);

fit_template_PP_MB[ipt]->SetParName(0,"const");
fit_template_PP_MB[ipt]->SetParName(1,"Mean");
fit_template_PP_MB[ipt]->SetParName(2,"sigma");
// fit_template_PP_MB[ipt]->Draw("");
  

f1_subt_hSignalD_pp_MC_tof_MB[ipt]->Fit("template_function_MB_PP","QR");
fit_rest_PP_MB[ipt]= f1_subt_hSignalD_pp_MC_tof_MB[ipt]->GetFunction("template_function_MB_PP");
fit_rest_PP_MB[ipt]->SetLineColor(kRed);
fit_rest_PP_MB[ipt]->SetLineWidth(2);

fit_rest_PP_MB[ipt]->SetName(Form("template_function_PP_MB_pt_%02d",ipt));
fit_rest_PP_MB[ipt]->Write();
f1_subt_hSignalD_pp_MC_tof_MB[ipt]->Write();
mean_PP_MB[ipt]=fit_rest_PP_MB[ipt]->GetParameter(1);
mean_error_PP_MB[ipt]=fit_rest_PP_MB[ipt]->GetParError(1);
sigma_PP_MB[ipt]=fit_rest_PP_MB[ipt]->GetParameter(2);
sigma_error_PP_MB[ipt]=fit_rest_PP_MB[ipt]->GetParError(2);

}

Try: f1_subt_hSignalD_pp_MC_tof_MB[ipt]->Fit(fit_template_PP_MB[ipt], "QR");
If you still see problems, remove the “Q” option and see if the fit was successful.

Hi Wile_E,

I tried but I still have the problem. What can be the reason of this?

Many thanks and kind regards,

Remove the “Q” option and compare the values of parameters that you get printed on your screen with these that you retrieve. See also the “STATUS” field (is it always “CONVERGED”?).

I removed Q but it did not changed anything.I checked if i print out the wrong number but it is right number. I do not know what makes it do grab wrong mean.

Attach your file with histograms here plus your macro so that we can “debug” it.

Here is the code full code and the prototype.Kind regards
problem_macro.C (18.1 KB)

problematic_fit_example.C (8.9 KB)

“input.root” is missing

Yes. It is very big to attach. So I attached the macro as a prototype. If u
run it you will see root output and the problem.

Kind regards

şunu yazdı:

The “problematic_fit_example.C” uses just 9x6 TH1D histograms, so prepare a small "input.root” which contains just these histograms (so that one can run this macro).
If you have ROOT 6, try: rootcp --help

I attached the right input file and right macro. Please use these two for diagnosis. I really appreciate your help.

Kind regards,
S.
just_subt.root (25.9 KB)
fitting_justsubt.C (4.0 KB)

All fits ended with an “Abnormal termination of minimization”, reporting either “STATUS=CALL LIMIT” or “STATUS=NOT POSDEF” (I did tell you to check the “STATUS”, didn’t I).

I tried to improve it so that one gets “STATUS=CONVERGED”, but it seems to me that you need to improve your “data model” (i.e. “improve” the fitting function).

fitting_justsubt.C (3.7 KB)

1 Like

Many thanks for your help. I want to ask what does line71 to 77 do?

Again many thanks for your all help.
S,

And one more question if I used another function as 2nd or 3rd order polynomial what should I do?

Try to change the first line into “#if 1” and run again.

Instead of "gaus(0)+x*[3]+[4]" try "gaus(0)+pol1(3)" (equal to "gaus(0)+[3]+x*[4]") or "gaus(0)+pol2(3)" or "gaus(0)+pol3(3)".

My aim of in this work is just get mean and sigma of the curve and use in the analysis. Could you please explain me briefly what lines 71 to line 77 does?Sorry I am new and did not understand it clearly. If I change the linear part to another function what should I consider?Many thanks and kind regards.
S.

C preprocessor

I have a question: If I want to use 2nd or 3rd order polynomial what should I do?

I have a question. I know gauss+lineer function does not define my data
well. If I want to use gaus+2nd or 3rd order how can I implement this
correction?

See my second to last post here.