Fitting points to a section of a sphere


I am using root v4.00.06.
I have 600 data points which I would like to fit to a section of a sphere to obtain the radius of curvature and the the center of the sphere.

I read in the data points into an ntuple, and then create a 3D histo.


I use the macro below to do the fit, but it takes a long time and Root
is terminated automatically because it is consuming too much CPU time.

What could be done?



#include “TF3.h”
#include “TH3.h”

Double_t func3(Double_t *x, Double_t *par) {
Double_t r2 = x[0]*x[0] + x[1]*x[1] +x[2]x[2];
Double_t arg = (TMath::Sqrt(r2) - par[1])/par[2];
Double_t val = par[0]TMath::Exp(-0.5arg
return val;

void fitorig() {
TF3 *f3 = new TF3(“f3”,func3,-0.25,0.25,-0.3,0.35,2.6,2.71,3);

TH3F h3a = (TH3F)f->Get(“h3”);



You forgot to send the data file (Tree).
Why do you project to a TH3 to fit.
You can fit directly from a TTree. See … nbinnedFit



I agree with Rene that you should directly fit your tree data but
I go one step further :

  1. The function func does not reflect your description .
    I was expecting to see 4 parameters center_x,center_y
    center_z and radius .

    At the end you take the exponent ?

  2. By invoking the “Fit” in a histogram you are minimizing something

    Sum_i (y -f(x))^2 _i where x is your controled variable and

    f(x) is your func3

    This is not what you want ! You want to find a circle with the
    smallest possible distance to each data point :

    minimize Sum_i (sqrt((x-xc)^2+(y-yc)^2+(z-zc)^2)-r)^2 _i

    see for instamce

  3. So what to do ?

    Follow closely
    and specify your objective function (see 2)
    through SetFCN(…)