# Fitting multiple sub ranges

Hi,

I’m trying to fit multiple sub ranges, but I just don’t succeed… I"m trying to stick to the example given in the ROOT user guide, but I guess I don’t understand how it’s supposed to work…

The histogram which I’d like to fit is defined in the following way:
TH1F *to_all = new TH1F(“to_all”,“turn on EM_HI all”,80,0.,80.);

Then I’m basically doing the followin (compare to the user guide, page 65/66):

TF1 *t1 = new TF1(“t1”,turnon_func,0,20);
t1->SetParameters(12.0,1.0,0.2); //halfpoint,slope,plateau
TF1 *t2 = new TF1(“t2”,turnon_func,20,40);
t2->SetParameters(25.0,1.0,1.0); //halfpoint,slope,plateau
TF1 *total = new TF1(“total”,turnon_func+turnon_func,5,40,6); <-THIS LINE IS THE PROBLEM

Double_t par;
to_all->Fit(“t1”,“R”);
to_all->Fit(“t2”,“R+”);
t1->GetParameters(&par);
t2->GetParameters(&par);
total->SetParameters(par);
to_all->Fit(total,“R+”);

The function I’d like to fit (“turnon_func”) is defined in the following way:
Double_t turnon_func(Double_t *x, Double_t *par)
{
double halfpoint = par;
double slope = par;
double plateau = par;
double offset = 0;

double pt = TMath::Max(x,0.000001);

double arg = 0;
arg = (pt - halfpoint)/(TMath::Sqrt(pt)slope);
double fitval = offset+0.5
plateau*(1+TMath::Erf(arg));
return fitval;
}

Above I’ve marked the line where I’m running into trouble. I can compile the program, but when running I get the error message that “total” cannot be compiled. Any ideas what I have to change to make it work?

Cheers,
Carsten

Carsten,

See the documentation of class TF1, in particular:

TF1 objects can reference other TF1 objects (thanks John Odonnell)
of type A or B defined above.This excludes CINT interpreted functions
and compiled functions.

Proceed like in tutorial FittingDemo.C

Rene

Hi Rene,

I’ve tried to do combine functions as described, however the results are not very encouraging. Maybe I’m doing something wrong, but the resulting fit doesn’t look as expected.

What I want to do is to fit a turn on curve using TMath::ERG function. However now I have an overlap of two turn-on curves, hence I’ll just define a new function which is returns turnon(x,par)+turnon(x,&par) (as described in the FittingDemo.C example). However I don’t see the first turn-on starting and going into saturation, and then the second turn-on kicking in, but just one turn-on curve (which of course doesn’t describe the data). I’ve tried setting a couple of parameters without any success, and finally I set all six parameters hoping that I would get a good fit now. Also without success.

So what’s the secret in doing a good fit? Am I doind something wrong? Do I just have to be lucky by setting the right parameters?

Cheers,
Carsten

Hi Carsten,

In your combination function, you actually probably need to take in consideration the range. Instead of

shouldn’t you have something similar to:

```if (x<20) return turnon(x,par); else return turnon(x,&(par)); ```

Cheers,
Philippe.