TFitResultPtr not valid check

Dear experts,

I am trying to optimize a fitting function and I use a TFitPointer object to access the result of a fit (the type of the fir varies with respect to the given function). At some points the fit might fail and then the TFitPointer will be empty. I try to avoid such occasions by doing the followinf checks:

          TFitPointer fitResult = 0;
          ...... // Fitting code here //........
          if (fitResult->IsEmpty() || !(fitResult->IsValid())) {return -3;}
          else {  ... saving the fit ...... }

Somehow though, just by doing the operation fitResult->IsEmpty() or fitResult->IsValid() root is trying to access the pointer which is i guess Null and I get an error:

Warning in : Fit data is empty
Error in : TFitResult is empty - use the fit option S

Is there any way to protect against this? I tried using using using :

if (fitResult == NULL) {…}
if (!fitresult) {…}

but neither seems to work. Any suggestions??

Thanks a lot!!!

_ROOT Version: 5.34 / 36
Platform: Windows
Compiler: MSVS 2013

as the message suggests:
“Error in : TFitResult is empty - use the fit option S”
for details see:


Hi Otto,

Thanks for the reply but that’s not the issue here, for four simple reasons:

  1. I am using option S (one would think i would already done the obvious before posting here)
  2. The problem seems to be related with the fit data as well and not only with the fit results (as the message indicated)
  3. Apparently the issue only appears when all fit data are only in the two extreme bins of the fitted TH1 histogram. By doing a simple check:

if (TH1F::Integral(firstbin+1, lastbin-1) ==0) continue;

the issue goes away.

  1. It will cause root 6 to crash (at least at lxplus) but not root 5

I still don’t understand what I am missing.

att a little macro, it works (i.e. it doesnt crash with 6.18.00)
as long as at least 1 bin is filled.
if all are empty it results in:

Warning in <Fit>: Fit data is empty 
Error in <TFitResultPtr>: TFitResult is empty - use the fit option S

as in your case.
As you see I tried different cases.

tfit.C (535 Bytes)


I forgot:
Before using TFitResultPtr as pointer you may
check its (int) value which is 0 if ok, -1 if not.
See att example

tfit.C (660 Bytes)

1 Like

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