Fitting with a constraint

Hey there,

I would like to fit data series that describe inefficiencies in a system. This however requires me to only use plots that don’t go over 1.00 in the given region. Can I somehow add a constraint to the fitting to achieve this?

For example: what if I want the best fifth order polynomial fit that never goes above 1.00 in the region of [-24.0, +24.0]?

Thank you for your responses!
Adam Hunyadi

I guess it strongly depends of the fitting function you are using. Do you have some preliminary example showing what you are doing ?

Here is a quick dataset example with a pol3 fit. The way I want it to be fitted though is using a fit that never goes above 1 or under 0.99 between [-24.0, 24.0].

of course a simple pol3 will “go above 1” … you need to define your own function that doesn’t. Also it is not clear what you mean by “never goes above 1”… How the function should be on the intervals without data points ? undefined ? content equal to 1 ? 0 ? … you can also limit the range of the function and use pol3 … there is many ways…

I want to extrapolate from this data for the interval, that has no data points, but I also want to make sure to keep it under 1.0. I’m okay with it if its exactly 1.0 at 24.0 or at -24.0 and goes above then, but not inside this region.

Ok. So you need to make your own fitting function.

And how do I make a normal pol3 as fitting function, that has these constraints?

You can define your own TF1.
Here is the Fit method.

My problem is not about lack of knowledge about the basics of the framework. My question was, what is the way to include constraints in the definition the way I already described.

Seems to me you need to include them inside the function code you will use. I will ask our fitting expert to cross check.

Hi Adam,

In a histogram when I need to set a constraint I use:

hist->SetParLimits(i, min, max);

where i is the parameter with the constraint.

Best,
Francisco