24 #include "StFastCircleFitter.hh"
27 StFastCircleFitter::StFastCircleFitter()
32 StFastCircleFitter::~StFastCircleFitter() {}
34 void StFastCircleFitter::addPoint(
double x,
double y)
40 void StFastCircleFitter::clear()
51 unsigned int StFastCircleFitter::numberOfPoints()
const {
return mX.size();}
53 double StFastCircleFitter::radius()
const {
return mRadius;}
55 double StFastCircleFitter::xcenter()
const {
return mXCenter;}
57 double StFastCircleFitter::ycenter()
const {
return mYCenter;}
59 double StFastCircleFitter::variance()
const {
return mVariance;}
61 int StFastCircleFitter::rc()
const {
return mRC;}
63 bool StFastCircleFitter::fit()
66 double xx, yy, xx2, yy2;
67 double f, g, h, p, q, t, g0, g02, a, b, c, d;
68 double xroot, ff, fp, xd, yd, g1;
69 double dx, dy, dradius2, xnom;
71 double xgravity = 0.0;
72 double ygravity = 0.0;
83 int npoints = mX.size();
89 for (i=0; i<npoints; i++) {
96 for (i=0; i<npoints; i++) {
104 xx2y2 += xx*(xx2+yy2);
105 yx2y2 += yy*(xx2+yy2);
106 x2y22 += (xx2+yy2)*(xx2+yy2);
112 f = (3.*x2+y2)/npoints;
113 g = (x2+3.*y2)/npoints;
118 g0 = (x2+y2)/npoints;
122 c = (t*(f+g)-2.*(p*p+q*q))/(g02*g0);
123 d = (t*(h*h-f*g)+2.*(p*p*g+q*q*f)-4.*p*q*h)/(g02*g02);
125 for (i=0; i<5; i++) {
126 ff = (((xroot+a)*xroot+b)*xroot+c)*xroot+d;
127 fp = ((4.*xroot+3.*a)*xroot+2.*b)*xroot+c;
131 xnom = (g-g1)*(f-g1)-h*h;
136 yd = (q*(f-g1)-h*p)/xnom;
144 radius2 = xd*xd+yd*yd+g1;
145 mXCenter = xd+xgravity;
146 mYCenter = yd+ygravity;
148 for (i=0; i<npoints; i++) {
149 dx = mX[i]-(mXCenter);
150 dy = mY[i]-(mYCenter);
151 dradius2 = dx*dx+dy*dy;
152 mVariance += dradius2+radius2-2.*::sqrt(dradius2*radius2);
154 mVariance /= npoints-3.0;
156 mRadius = ::sqrt(radius2);