Used defined fit functions and boundary conditions

Hi Rooters,

It’s been a while since I’ve had to fit curves and I’m new to how Root does it. My issue is how to handle boundary conditions between two fit functions. Attached is my macro and a graphic showing my results. I do a Gaussian fit inside the peak, then a Lorentzian fit outside the peak. The two fits are discontinuous at the boundary.

Intuition tells me that I should define the requirement f(a) = g(a) and f’(a) = g’(a) in the definitions of the fit functions. But, this doesn’t seem to be that simple. I’m not sure how to proceed.



fit.C (18.8 KB)

I’m sure @moneta will be able to help you


My original code, as you’ll see, uses an if else statement to compute one or the other function. I removed that and that has gotten rid of the discontinuity. However, the functions do not have a common maximum, which introduces a “bump” at the top.

Your data in the range -15<x<15 can be perfectly fitted by a simple function, see the attached macrofit1.C (19.1 KB)

Thank you! That was an excellent solution. I’m curious about parameter p[3], which is used in

Double_t D = abs(x[0] - p[1])/p[2]; 
return p[0]*exp(-pow(D,p[3])) + p[4];

Normally, in a gaussian, p[3] would be 2, but you set it as less than two. Moreover, you use the absolute value, which I assume is because p[3] is not 2. I have not seen this approach before.

Yes, it is not a gaussian. The peak in your data can not be fitted with one gaussian. But you can fit it with two gaussians, see the attached macrofit2.C (19.7 KB)

Thanks, smgrig!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.