Vector fit

Hello,

I have a templated function taking a std::vector as argument and I would like to fit a TF1 using Least Mean Square method ROOT.

Would you have a suggestion how to fit without creating an histogram? :thinking:

Hi @meyerma ,

we need @moneta here, let’s ping him.

Hi,

You can create a TF1 easily from whatever function you have, but what are your data ? Do you have a simple vector of data points X and their associated value Y ? In this case you should use the TGraph class.
Please explain with more detail your problem

Lorenzo

Hi,

Thank you for your help!

My use case is a set of points Y spanning a frequency range from 0 to 1024Hz with regular bins. So I wanted to find a way to fit a pol0,pol1 and pol2 with minimal effort. My understanding is that I still need to shape my values within a TH1 or TGraph if I want to fit a TF1.

Perhaps, I can go just filling an histogram using SetBinContent; calling TH1::Sumw2(false) and just fit my functions…

Marco

Hi,
If you have regular bins it is easier to use an histogram, otherwise a TGraph is fine too. If your frequency values do not come with an error, if you use the histogram, you should use the fit option W or WW, see the documentation.

You can also fit directly the data, without histogram or Graph, but you need to use directly the Fitter class, see the documentation here.

Cheers

Lorenzo

1 Like

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