Fixing boundaries of fit

Hi,

I am looking to do a piecewise continuous fit across regions 0 to 0.2, 0.2 to 0.4, and 0.4 to 0.5 (three different pol3s). I need it to be without discontinuities. So my question is how can I set one function to start where the previous one ends? Or in another way how can fit1(0.2)==fit2(0.2)?

Best,
Rjseen

For future reference, anyone looking to do a PW Continuous fit without discontinuities, this is how I solved it:

double sec1end = 0.02; double sec2end = 0.09; double sec3end= 0.18; TF1 *sec1 = new TF1("sec1","pol3",0,sec1end); TF1 *sec2 = new TF1("sec2","pol3",sec1end,sec2end); TF1 *sec3 = new TF1("sec3","pol3",sec2end,0.18); hrt1->Fit("sec1","FEBR+"); hrt1->Fit("sec2","FEBR+"); double sec2current = sec2->GetParameter(0); double sec2sec2 = sec2(sec1end); double sec2sec1 = sec1(sec1end); double sec2NEW = sec2current + (sec2sec1 - sec2sec2); sec2->SetParameter(0,sec2NEW); hrt1->Fit("sec3","FEBR+"); double sec3current = sec3->GetParameter(0); double sec3sec3 = sec3(sec2end); double sec3sec2 = sec2(sec2end); double sec3NEW = sec3current + (sec3sec2 - sec3sec2); sec3->SetParameter(0,sec3NEW);

I then use the parameters in a function defined using boolean expressions to turn the three separate fits into one function.

Hi,

Thanks for sharing!

Your approach has the disadvantage that the chi2 (or in general minimization goal) is not equally distributed across the different regions. If you want to find a global minimum, over the whole range, you need to provide a new minimization function. See tutorials/fit/fitExclude.C for an example doing something completely different (exclusion) that you can use here, too. In your case, the new minimization function is similar to fline() in the tutorial.

Then you need to cast the polynomials and parameters into a form that allows you to make the polynomials continuous (by having the second pol’s start point depend on the first pol’s end point, like you do). You might even want to require the derivative to be the same at the cross-over points…

None of that is trivial, but it’s not black magic either :wink:

Cheers, Axel.