Hi Shamin,
Some possible pointers :
- Your histogram is too coarsely binned comapred to the structure
you want to fit .
- Calculate the integral of the expression as a function of par[0] and
par[1]
You know the errors in the pars (and could also get their
correlation) .
Now it is a straightforward error-propagation exercise to ge the
error
in the integral . Maybe the answer is well inside the error .
- You are fitting the histogram points NOT the function integral; if
point 1)
is ok, one would expect also a correct (see 2)) integral . However,
you could re-parametrize your function expression such that it
guarantees
that the function integral equals the histogram sum .
Eddy
- "Shamim, Mansoora" <shamimm_at_phys.ksu.edu> wrote:
>
>
> Hi,
> I am trying to fit a simple exponential function to my histogram.
> Please see the macro.
> Fit range is between 40, 55.
> Total entries in my histogram are 1743. After fitting the function
> when I calculate the integral of teh function between 40 and 55 using
> TF1 it turns out to be 1821.71.
> Does anyone have any idea what I am doing wrong.
> Thanks for help
> Mansoora
>
>
> Double_t fitf(Double_t *x, Double_t *par)
> {
>
> Double_t fitval = TMath::Exp(par[0]+x[0]*par[1]);
>
> return fitval;
> }
> void myfit()
> {
> TFile *f = new TFile("sumdata_all.root");
>
> TCanvas *c1 = new TCanvas("c1","the fit canvas",500,400);
>
> TH1F *hpx = (TH1F*)f->Get("allbmet");
>
> // Creates a Root function based on function fitf above
> TF1 *func = new TF1("fitf",fitf,40,55,2);
>
> // Sets initial values and parameter names
> // func->SetParameters(0,0);
>
>
> func->SetParNames("Constant","slope");
>
> // Fit histogram in range defined by function
> hpx->Fit(func,"r");
>
>
> // Gets integral of function between fit limits
> printf("Integral of function = %g\n",func->Integral(40,55));
> printf("Integral of function = %g\n",hpx->Integral(40,55));
> }
>
>
> The output is the following
>
> FCN=4.40737 FROM MIGRAD STATUS=CONVERGED 490 CALLS 491
> TOTAL
> EDM=9.42813e-12 STRATEGY= 1 ERROR MATRIX
> ACCURATE
> EXT PARAMETER STEP FIRST
> NO. NAME VALUE ERROR SIZE
> DERIVATIVE
> 1 Constant 9.38380e+00 4.56946e-01 4.39444e-05
> 5.63492e-05
> 2 slope -9.83892e-02 1.01634e-02 9.77412e-07
> 2.15489e-03
> Integral of function = 1821.71
> Integral of histogram = 64
>
>
Received on Wed Apr 27 2005 - 03:57:57 MEST
This archive was generated by hypermail 2.2.0
: Tue Jan 02 2007 - 14:45:07 MET