Fit a circle using data points with errors


I am attempting to fit a circle to 4 or 5 data points using Minuit, based on the example at I have adapted the example to take the input data from vectors, rather than a TGraph:

bool FitCircle(const std::vector<double>& x, const std::vector<double>& y,
               MAUS::SimpleCircle& circ, TMatrixD& cov_matrix) {

  auto Chi2Function = [&x, &y](const double *par) {
    // Minimisation function computing the sum of squares of residuals
    // looping over the points
    double f = 0.0;
    for (size_t i = 0; i < x.size(); i++) {
        double u = x[i] - par[0];
        double v = y[i] - par[1];
        double dr = par[2] - std::sqrt(u*u+v*v);
        f += dr*dr;
    return f;

  // Wrap chi2 funciton in a function object for the fit
  // 3 is the number of fit parameters (size of array par)
  ROOT::Math::Functor fcn(Chi2Function, 3);
  ROOT::Fit::Fitter fitter;
  double pStart[3] = {0, 0, 1};
  fitter.SetFCN(fcn, pStart);
  // do the fit 
  bool ok = fitter.FitFCN();
  if (!ok) {
    return ok;
  const ROOT::Fit::FitResult & result = fitter.Result();
  // Create a circle object with the results
  circ = MAUS::SimpleCircle(result.Parameter(0), result.Parameter(1), 
  return true;

It works well but, after some searching, I cannot see any obvious way of supplying the errors on the input data points to the fit. Could someone give me some pointers please? Thanks.


You would need to weight the distance between the point and the circle by using the inverse of the point uncertainty. You might need to propagate the uncertainty in x and y of the data points along the distance between the circle and the points

Best Regards


1 Like

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