Fit a circle using data points with errors

Hi,

I am attempting to fit a circle to 4 or 5 data points using Minuit, based on the example at https://root.cern.ch/doc/v608/fitCircle_8C.html. 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);
  fitter.Config().ParSettings(0).SetName("x0");
  fitter.Config().ParSettings(1).SetName("y0");
  fitter.Config().ParSettings(2).SetName("R");
  
  // do the fit 
  bool ok = fitter.FitFCN();
  if (!ok) {
    return ok;
  }   
  const ROOT::Fit::FitResult & result = fitter.Result();
  result.Print(std::cout);
  
  // Create a circle object with the results
  circ = MAUS::SimpleCircle(result.Parameter(0), result.Parameter(1), 
                            result.Parameter(2));
  circ.set_x0_err(result.Error(0));
  circ.set_y0_err(result.Error(1));
  circ.set_R_err(result.Error(2));
  circ.set_chisq(result.Chi2());
  result.GetCovarianceMatrix(cov_matrix);
  
  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.

HI,

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

Lorenzo

1 Like

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