# Fit function with a fixed parameter

Good Afternoon everyone,
I’m trying to perform some fit of a generated histogram, the function is a sum of two gaussians and an exponential.
To perform the fit I define the function

``````  TF1 my_func("my_func","[0]*([1] * TMath::Gaus(x,[2],[3], true) + [4] * TMath::Gaus(x,[5],[6],true) + (1-[1]-[4]) * TMath::Exp(x*[7]))",0,2);
my_func.SetParNames("Norm", "alpha", "mean1", "sigma1", "beta", "mean2", "sigma2", "tau");
my_func.SetParameters(2000, 0.3, 1, 0.2, 0.2, 1.5, 0.1, -3);
``````

Now, because I know the number of events I generate in the histogram, I should know the value of the parameter [0], being it the number of the generated eventrs multiplied by the width of the bin.
But, if I do

``````my_func->FixParameter(0, 2500);
``````

And then I fit the histogram I obtain a different value of the parameter [0]
How may I make it work?

Riccardo

I guess @moneta can help.

Hi,
In order to be what you say about the parameter [0], the integral of the function needs to be equal to 1.
This is not the case for you, for example the exponential component is not normalized.
Also the definition of your parameter is not good, you might have [1] and [4] larger than 1.

Note you can do a fit to normalized components in ROOT using the `TFNormSum` class

An example is available here:

Lorenzo

Hi,
I’m looking into the documentation, I don’t understand some things about the TF1NormSum.
In the tutorial it is built

``````TF1NormSum *fnorm_exp_cb = new TF1NormSum(f_cb,f_exp,nsig,nbkg);
``````

where nsig and nbkg are integers, not fractions. I don’t understand how is it normalized. Here both are not bound to be less then 1.
Thank you,
Riccardo

Hi,

The class fits number of events and not fractions. This is the correct way of doing it if the fit is extended, i.e. when also the normalization is fitted. In this way you don’t have the problem that fraction values must be set larger than zero and smaller than 1.
You can always calculate the fraction afterwards from the fitted number of events.

Lorenzo

Thank you!

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