Re: Proper fitting of integers

Rene Brun (Rene.Brun@cern.ch)
Thu, 10 Sep 1998 23:19:10 +0200


Tadeusz,
A correct error estimation for the fit parameters implies
a good definition of the errors on the fit data.
In your case, you fill a histogram and directly fit.
the Root fitter will take by default the sqrt(bin content)
as the error along y. This clearly not what you want.
You MUST set the errors for your bins, for example like in
the example below:

TH1F *h2=new TH1F("h2","h2",4,-0.5,3.5);
Float_t err = 0.0001;
h2.Fill(0,4); h2.SetBinError(1,err);
h2.Fill(1,3); h2.SetBinError(2,err);
h2.Fill(2,2); h2.SetBinError(3,err);
h2.Fill(3,1); h2.SetBinError(4,err);
h2.Fit("pol1");

Concerning your attempt with TGraph, note that TGraph accepts
floats not ints. You should have:

Float_t x[4]={0,1,2,3};
Float_t y[4]={4,3,2,1};
TGraph *g1=new TGraph(4,x,y);

Rene Brun

Tadeusz Pytlos wrote:
>
> Dear Rooters,
> My problem seems to be easy, but I lost a lot of time with it.
> Let's assume I have got a histogram of integers
>
> -
> - -
> - - -
> - - - -
> 0 1 2 3
>
> According to simple matematics fitting by y=p0+p1*x should give
> p0=4 and p1=-1, errors=0.
> How could I fix a range or sth other
> to receive the best fiting results?
> I'm using ROOT 2.00/11 RedHat 5.0.
> Best wishes,
> Tadeusz
>
> root [0] TH1S *h1=new TH1S("h1","h1",4,0,4)
> root [1] h1.Fill(0,4)
> root [2] h1.Fill(1,3)
> root [3] h1.Fill(2,2)
> root [4] h1.Fill(3,1)
> root [5] h1.Fit("pol1")
> **********
> ** 1 **SET ERR 1
> **********
> FCN=0 FROM MIGRAD STATUS=CONVERGED 22 CALLS 23 TOTAL
> EDM=8.30088e-33 STRATEGY= 1 ERROR MATRIX
> ACCURATE
> EXT PARAMETER STEP FIRST
> NO. NAME VALUE ERROR SIZE DERIVATIVE
> 1 p0 4.50000e+00 1.83007e+00 -0.00000e+00 0.00000e+00
> 2 p1 -1.00000e+00 6.56532e-01 0.00000e+00 -2.77547e-16
> Warning in <MakeDefCanvas>: creating a default canvas with name c1
>
> root [6] TH1F *h2=new TH1F("h2","h2",4,-0.5,3.5)
> root [7] h2.Fill(0,4)
> root [8] h2.Fill(1,3)
> root [9] h2.Fill(2,2)
> root [10] h2.Fill(3,1)
> root [11] h2.Fit("pol1")
> FCN=0 FROM MIGRAD STATUS=CONVERGED 20 CALLS 21 TOTAL
> EDM=1.00357e-30 STRATEGY= 1 ERROR MATRIX
> ACCURATE
> EXT PARAMETER STEP FIRST
> NO. NAME VALUE ERROR SIZE DERIVATIVE
> 1 p0 4.00000e+00 1.53128e+00 1.20000e-03 -9.25194e-16
> 2 p1 -1.00000e+00 6.56532e-01 3.00000e-04 0.00000e+00
>
> root [12] Int_t x[4]={0,1,2,3}
> root [13] Int_t y[4]={4,3,2,1}
> root [14] TGraph *g1=new TGraph(4,x,y)
> Error: Can't call TGraph::TGraph() in current scope FILE:/tmp/19719caa
> LINE:1
>
> --
> Tadeusz Pytlos
> mailto:pytlos@fizwe5.fic.uni.lodz.pl
> Lodz, Poland