Fit to an ellipse


I would like to fit a TGraph to a generic ellipse and I’m not sure how to do it… Since the ellipse is defined implicitly as f(x,y) = 0, I don’t know if I should define a TF1 or a TF2 and how it works.
Maybe it is a very simple problem, but I’m a bit lost right now.

Thank you for the help


Hi Paola,

TGraph is a “single valued function”, i.e. for a X-value you can have only 1 Y-value.
An ellipse in x-y space is not single valued.
I made an example which fits an ellipse to a TH2D:

Some (hopefully useful) ROOT macros

which you may use as a guide how to use Minuit directly.


Attached are two example macros which fit an ellipse to a set of data points from a TGraph:

  • “EllipseTGraphDLSF” uses the “Direct Least Squares Fitting” algorithm
  • “EllipseTGraphRMM” uses the “ROOT::Math::Minimizer” interface

EllipseTGraphDLSF.cxx (9.88 KB)
EllipseTGraphRMM.cxx (9.77 KB)

The above statement is of course not correct. TGraph is n o t a “TF1”.


Thanks to everybody!