[ROOT] Fitting problems on Alpha

From: Bertalan Juhasz (Bertalan.Juhasz@cern.ch)
Date: Wed Jul 25 2001 - 06:14:25 MEST


Dear Rooters,

The following simple program

===========================================================

#include <stdlib.h>

#include "TROOT.h"
#include "TApplication.h"
#include "TH1.h"
#include "TF1.h"

   TROOT test("test","Fit test");

Double_t FitFunc(Double_t*, Double_t*);

int main(int argc, char **argv) {
   TApplication *theApp = new TApplication("test", &argc, argv);
   
   TH1F *ahist = new TH1F("aa", "bb", 1000, 0.0, 1000.0);
   for (Int_t bn = 1; bn <= 1000; bn++) {
      ahist->Fill(bn, rand()/1000.0*bn);
   }
   TF1* afunc = new TF1("afunc",FitFunc,0.0,1000.0,2);
   afunc->SetParameter(0, 1.0);
   afunc->SetParameter(1, 1.0);
   ahist->Fit(afunc, "ewr0");
}

Double_t FitFunc(Double_t *x, Double_t *par) {
   Double_t result = par[0] + par[1] * x[0];
   return result;
}

==========================================================

produces the following result after compiled on OSF1:

> test
 FCN=2.92464e+10 FROM MINOS     STATUS=SUCCESSFUL     16 CALLS          58
TOTAL
                     EDM=1.22447e-10    STRATEGY= 1      ERROR MATRIX 
ACCURATE 
  EXT PARAMETER                  PARABOLIC         MINOS ERRORS        
  NO.   NAME      VALUE            ERROR      NEGATIVE      POSITIVE   
   1  p0          -3.22038e+02   6.33722e-02  -6.33716e-02   6.33720e-02
   2  p1           1.76026e+01   1.09709e-04  -1.09708e-04   1.09708e-04

 *** Break *** segmentation violation
Unaligned access pid=3320 <test> va=0x3ffc00871bc pc=0x3ff81548938
ra=0x3ff81485c6c inst=0xa570fff8
Unaligned access pid=3320 <test> va=0x3ffc00871a4 pc=0x3ff815485c0
ra=0x3ff81548e2c inst=0xa630ffe0
Abort (core dumped)

Apparently, the fit is done correctly but then the program crashes even
though the fitting is the last line of code. The problem does not happen
when the program exits - if I insert some code after the fitting those are
never executed. The same thing happens if I run the program as a macro.  
The compiler is
> cxx -V
Compaq C++ V6.2-040 for Digital UNIX V4.0D  (Rev. 878)

ROOT version is 3.01/06, the libs are from the ROOT website.

What makes things strange is that the above code runs nicely on Linux
with gcc (e.g. RedHat 6.1). What is even more strange is that if I write

   ahist->Fit("[0]+x*[1]", "ewr0");

which is essentially the same function, the program runs nicely. But what
is VERY strange is that if I write 

   TF1* afunc = new TF1("afunc",FitFunc,0.0,1000.0,1);
   ...
   ahist->Fit(afunc, "ewr0");

and
   
   Double_t result = par[0] + x[0];

the program again runs nicely. Has anyone experienced a similar behaviour
or have solution for it? Or did I bump into a bug in ROOT/Minuit?

Thank you very much in advance,

Bertalan



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:52 MET