TF1::IntegralError fails


I have problems to get a reasonable IntegralError for some fits and fit functions. Sometimes the function seems to return reasonable numbers, sometimes it returns crap. Here is a code example

void testinterr(bool add=false)
  TH1F *h1 = new TH1F("h1","",100,0.98,1.1);
  TF1 *f1 = new TF1("f1","[0]*(x>[1])*(x<[3])*(abs(x-[1]))^[2]*(abs(x-[3]))^[4]",0.98,1.1);

  if (add) {
    // with these lines in I get Err = 0
  TFitResultPtr pfit = h1->Fit("f1","ms");
  double n  = f1->Integral(1,1.04);
  double dn = f1->IntegralError(1,1.04,pfit->GetParams(), pfit->GetCovarianceMatrix().GetMatrixArray());
  cout <<n<<" +- "<<dn<<endl;

which gives in my case

root [0] .x testinterr.C(0)
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
 FCN=64.9812 FROM HESSE     STATUS=NOT POSDEF     33 CALLS         336 TOTAL
                     EDM=4.81713e-08    STRATEGY= 1      ERR MATRIX NOT POS-DEF
  EXT PARAMETER                APPROXIMATE        STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0           2.50059e+00   3.25677e-01   9.95067e-05  -2.09580e-03
   2  p1           9.87771e-01   3.57446e-05   4.71006e-07   4.91257e+00
   3  p2           4.78138e-01   1.44689e-02   1.35182e-05   1.60692e-02
   4  p3           3.63503e+02   5.37157e+01   1.63897e-02  -8.33421e-06
   5  p4           8.80006e-01   2.22002e-02   6.75196e-06  -3.26871e-02
3.39934 +- 0.0443608


root [1] .x testinterr.C(1)
Warning in <TROOT::Append>: Replacing existing TH1: h1 (Potential memory leak).
Warning in <Fit>: Abnormal termination of minimization.
 FCN=80.6087 FROM MIGRAD    STATUS=CALL LIMIT   1631 CALLS        1632 TOTAL
                     EDM=0.000483126    STRATEGY= 1  ERROR MATRIX UNCERTAINTY  39.0 per cent
  EXT PARAMETER                APPROXIMATE        STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0           7.19014e+00   2.31244e+00   4.12053e-02  -4.37627e-01
   2  p1           9.87753e-01   5.17554e-05   4.37660e-07   1.18930e+02
   3  p2           5.47573e-01   1.46104e-02   5.23733e-05   9.36261e+00
   4  p3           1.35637e+01   5.08601e+00   8.97266e-02  -4.60816e-01
   5  p4           1.81669e+00   4.26753e-01  -7.46502e-03  -7.92311e+00
4.26503 +- 0

The first error looks fine I guess, but in the second case, err = 0 is obviously wrong. The fit output prints “Warning in <Fit>: Abnormal termination of minimization.” in the second case, perhaps this is connected to the problem.

Does somebody know what’s going wrong, and how to fix it? I would like to use this rather complicated function to describe a phase space border background shape (of a phi(1020)) and have no good idea how to alternatively estimate the error of the integral. Other functions (except polynomials as it seems) show a similar behavior anyways, so replacing the function didn’t help until now. Polys unfortunately don’t fit sufficiently well.

Best and thanks,

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.24-04
Platform: Not Provided
Compiler: Not Provided

I think @moneta can help you.

One of the problems is that, before fitting, you need to:

  // set reasonable initial parameters values
  f1->SetParameter(0, f1->GetParameter(0) / f1->Integral(h1->GetXaxis()->GetXmin(), h1->GetXaxis()->GetXmax()) * h1->Integral() * h1->GetBinWidth(1));

Why that?

Unfortunately this doesn’t help, I still get 0 as error.

When your fit fails, do not expect anything useful.

If you are interested in the integral between 1.0 and 1.04, then use, e.g.:

h1->Fit("pol4", "L", "", 0.995, 1.095)
TF1 *f1 = h1->GetFunction("pol4");

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