# [ROOT] fitting

From: Alexander B³rger (buerger@iskp.uni-bonn.de)
Date: Thu Oct 28 2004 - 21:35:19 MEST

```Hi,

I have a problem with fitting using TGraphErrors / TF1. I have the
following code:

Double_t efffun(Double_t *X, Double_t *pars)
{
// par[] = { 0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=E1, 8=E2, 9=scale }
Double_t x1 = /*log*/(X / pars);
Double_t x2 = /*log*/(X / pars);
if( x1 > exp(-100) ) x1 = log( x1 ); else x1 = -100;
if( x2 > exp(-100) ) x2 = log( x2 ); else x2 = -100;
Double_t g  = pars;
Double_t f1 = pars + pars*x1 + pars*x1*x1;
Double_t f2 = pars + pars*x2 + pars*x2*x2;
return pars*exp( pow( pow( f1, -g ) + pow( f2, -g ), -1.0 / g));
}

TF1* func = new TF1("eff", efffun, 200, 2500, 10);
func->SetParNames("A", "B", "C", "D", "E", "F", "G", "E1", "E2", "scale");
func->SetParameters(2.9, 2.2, 0, 5.179, -0.302, -0.17, 15, 100, 1000, 1);
func->FixParameter( 2, 0 );    // C=0
//func->FixParameter( 6, 15 );   // G=15
func->FixParameter( 7, 100 );  // E1 = 100
func->FixParameter( 8, 1000 ); // E2 = 1000
g->Fit( func, "" );

The graph has these values:

x=244.454, y=121.118, ex=2.44454, ey=1.21118
x=344.061, y=178.907, ex=3.44061, ey=1.78907
x=367.594, y=189.898, ex=3.67594, ey=1.89898
x=410.915, y=192.414, ex=4.10915, ey=1.92414
x=443.769, y=198.059, ex=4.43769, ey=1.98059
x=688.482, y=185.509, ex=6.88482, ey=1.85509
x=778.677, y=189.777, ex=7.78677, ey=1.89777
x=867.135, y=186.262, ex=8.67135, ey=1.86262
x=963.785, y=182.018, ex=9.63785, ey=1.82018
x=1111.76, y=172.064, ex=11.1176, ey=1.72064
x=1212.64, y=166.903, ex=12.1264, ey=1.66903
x=1298.83, y=157.176, ex=12.9883, ey=1.57176
x=1407.69, y=157.646, ex=14.0769, ey=1.57646

Now the problem is that before fitting, the TF1 fits really well (I
adjusted the initial values), but after fitting it's "worse", I mean it
fits anything but not the graph (it looks a bit like the fitter is trying
to put the TF1 to 0 outside the graph).

How can I solve this problem?

Best wishes,

Alexander
```

This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET