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.

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]->Draw("");

fit_rest_PP_MB[ipt]= f1_subt_hSignalD_pp_MC_tof_MB[ipt]->GetFunction("template_function_MB_PP");



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,
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.

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.

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

See my second to last post here.