Why when I make my function to fit my data does the Fit method change the values?


_ROOT Version: 6.19
_Platform: OS 10.14.3


I have some data i want to fit to a function, this function is a gausian EXCEPT its standard deviation is equal to the square root of the mean, so I did this:

def fitHist(hist,name):
    print '################# MY FIT ##########################'
    f = TF1('f'+name, '[0]*exp(-0.5*((x-[1])/[2])**2)', -10000, 10000)
    print hist, name
    cons = hist.GetFunction('gaus').GetParameter(0)
    f.SetParameter(0, cons)
    mean = hist.GetFunction('gaus').GetParameter(1)
    f.SetParameter(1, mean)
    print ''
    print 'the mean is '+str(mean)
    print 'sqrt(mean) is '+str(sqrt(mean))
    print ''
    f.SetParameter(2, sqrt(mean))
    hist.Fit('f'+name)

However look at this, if I just use Fit(‘gaus’) I get a sigma of ~135, but I want to know how well would a gausian with a sigma of 139 fit that same data, however when I try to fit the funtion I did with that sigma, it changes it to 135, look:

Maybe what is happening is that my data doesn’t quite match the function I did, but that’s the point!, I want to know how closely the data fits my function, I don’t want to know what other function would fit it better.

What should I do?, how do I fix this?

Try:

f.FixParameter(2, sqrt(mean))
hist.Fit('f'+name)
f.ReleaseParameter(2)

it didn’t work, I was thinking of doing:

f = TF1('f'+name, '[0]*exp(-0.5*((x-[1])/sqrt([1]))**2)', 0, 50000)

but still not understanding why the Fit method changes my function makes me distrust it .

Do I understand correctly that you are asking why fit parameters change when you fit a function to the data?

From what I see, your code snippet initialises the fit parameters, and then you fit to data. This will change all three parameters.

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