Discontinuity in multiple fit

Dear experts,

I have a global fit which performs fit on different sub-range with different functions, and I noticed that at the connection, I have discontinuity (big variation). I wonder if there is a smart easy way to solve that. Shouldn’t the fit handle that?

For ex. as you can see in the plots:
btw the gray and black line I fit with an expo
btw the black and the red a gaussian
btw red and to the end a sum of gauss

and we can see that at the black and red line we have discontinuity.

My global fit look look this [*]:


double modified_fnc_dscb(double
… // get parameters from xx and par

double result(1);

if ( x<gray_line ) result = p0_left + p1_leftx + p2_leftpow(x,2) +
pow(x,3) + p4_leftpow(x,4) +
pow(x,5) + p6_leftpow(x,6) +
pow(x,7) ;

else if ( x<black_line ) result = exp( normExp_left + xslopeExp_left );

else if ( x<red_line ) result = normGaus1 * exp(-0.5pow(((x-meanGaus1)/sigGaus1_left),2) );

else result *= sumGaus(&x, pp);

return result;


do you have any idea how to do that or any other forum where I can ask to solve this problem?



the fitting procedure finds the minimum value of a certain function of the parameters (e.g. a likelihood) given a model and a dataset: it does not have any information about the first derivatives of the functional form of the model and their potential discontinuities.
If you want to avoid those, you should embed this constraint in your fit, e.g. with penalty terms in the likelihood i.e. increasing it when the derivatives differ or with a different model if the Physics of your problem allows you to do that.


Dear Danilo,

  1. thank you for your answer. Unfortunately I did not understood what you mean.
    Could you please tell me how I can “embed this constraint in your fit, e.g. with penalty terms in the likelihood i.e. increasing it when the derivatives differ”. I’m just using a simple hist->Fit() method.

  2. So far I plan to solve the equation at the discontinuity. For ex where the gauss and the exponential join, I could solve:

exp( normExp_left + xslopeExp_left ) =
normGaus1 * exp(-0.5
pow(((x-meanGaus1)/sigGaus1_left),2) )

so I would get if I solve for normExp_left:
normExp_left = ln( normGaus1 * exp(-0.5pow(((x-meanGaus1)/sigGaus1_left),2) )) - xslopeExp_left

then I could used normExp_left directly in the fit. Would that make sense?



  1. I mean building your own likelihood given your model and data and add additional terms not to have the minimiser settling in minima where the derivatives are different, e.g. where the difference of the derivatives is non negligible.

  2. Did you try this strategy?


Dear Danilo,

no I did not try this method, actually I do not want to rebuild a likelihood, I want to keep using the root simple fit method tools.
Maybe do you have another simple idea one how to achieve that?


No, I do not see any other trivial way of accomplishing this.

Dear dpiparo,

ok, thank you for your help.