# integral using TF1

From: Shamim, Mansoora <shamimm_at_phys.ksu.edu>
Date: Tue, 26 Apr 2005 16:24:28 -0500

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+x*par);

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 Tue Apr 26 2005 - 23:24:52 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:07 MET