Histogram Fitting: Can I simultaneously fit a step function?

Hi ROOTers,

Fitting Question: Is it possible to simultaneously fit a step function?

What I mean by this is that I want to simultaneously fit something like:
f = f1 + f2 0<x<90
f = f1 90<x<180

It must be simultaneous so that f1 (the background) is the same function for the whole histogram. If f2 is allowed to be in the other region then the fit is messed up.

I was looking to do something like:
TF1 *fSpectrum = new TF1(“fSpectrum”,“gaus+pol2(3)”,0.,180.);
but I don’t want the gaussian to be in the region 90<x<180, for example. The actual functions are more complicated - This is just a simple example.

Any help would be GREATLY appreciated! I’m afraid that I’m new to root, so simple explanations would be best.

Will :smiley:

You can define your TF1 as

TF1 *fSpectrum = new TF1("fSpectrum","gaus+(x<90)*pol2(3)",0.,180.)

1 Like

Thanks Rene!,

Thats exactly the sort of thing I’m looking for!

So the syntax:

TF1 *fSpectrum = new TF1(“fSpectrum”,“gaus+(x<90)*pol2(3)”,0.,180.);

means that pol2 is only included a x<90? (x<90) is a step function is this context?

So would:

TF1 fSpectrum = new TF1(“fSpectrum”,gaus+(x<90)(x>30)*pol2(3)",0.,180.);

mean that pol2 is only included at 30<x<90? Where can I learn about this syntax?

Thanks a bunch!


Use the notation as shown in the example below


{ TF1 *f1 = new TF1("f1","gaus+(x>30 && x<90)*pol2(3)",0.,180.); f1->SetParameters(16000,90,10,1,1,1); f1->SetNpx(1000); f1->Draw(); }