Return value of TH1::Fit


Checking the possible return values of a Fit() function (in vers 4.04/02), I perused the code and found:

in TH1::Fit(…):

Int_t fitResult = 0; if( various input errors ) { return 0; } .... fitResult = hFitter->ExecuteCommand("MIGRAD",arglist,2); // calling at the end TMinuit::mnexcm(...) .... return fitResult;
while in TMinuit::mnexcm(…):

*-* IERFLG is now (94.5) defined the same as ICONDN in MNCOMD *-* = 0: command executed normally *-* 1: command is blank, ignored *-* 2: command line unreadable, ignored *-* 3: unknown command, ignored *-* 4: abnormal termination (e.g., MIGRAD not converged) *-* 9: reserved *-* 10: END command *-* 11: EXIT or STOP command *-* 12: RETURN command

So TH1::Fit returns 0 on error in TH1::Fit or when the fit succeeds.

Could this be changed (e.g. negative values for err in Th1::Fit) ?

Best Regards, Vincent.

You have

if (fitResult != 0) {
     //   Abnormal termination, MIGRAD might not have converged on a
     //   minimum.
     if (!Foption.Quiet) {
        Warning("Fit","Abnormal termination of minimization.");

I then have a message on my screen, but in a macro I cannot simply rely on the return value to know if the fit suceeded of not.

Is Zdrawej russian ? What does it mean exactely ?

Hi, Zdrawej means the same as Bonjour but in Bulgarian in Russian its Priwet

Int_t TFitter::ExecuteCommand(const char *command, Double_t *args, Int_t nargs)
   // Execute a fitter command;
   //   command : command string
   //   args    : list of nargs command arguments

   Int_t ierr = 0;
   return ierr;

so you see that the return value is the same as in fortran

I’m sorry now I get it I was looking only when fitResult was 0 but I missed this checks

//   - Get pointer to the function by searching in the list of functions in ROOT
   gF1 = f1;
   if (!f1) { Error("Fit", "Pointer to function is null"); return 0; }
   if (f1->IsZombie()) { Error("Fit", "Function is zombie"); return 0; }
   npar = f1->GetNpar();
   if (npar <=0) { Error("Fit", "Illegal number of parameters = %d",npar); return 0; }
//   - Check that function has same dimension as histogram
   if (f1->GetNdim() != GetDimension()) {
      Error("Fit","Function dimension:%d does not match histogram dimension:%d",f1->GetNdim(),GetDimension());
      return 0;
   if (xxmin != xxmax) f1->SetRange(xxmin,ymin,zmin,xxmax,ymax,zmax);

//   - Decode list of options into Foption
   Foption_t Foption;
   if (!FitOptionsMake(option,Foption)) return 0;

You are probably right -1 is good value