37 int iter, iterMax = 20;
38 int i_iter, i_max_Robust = 4;
39 const int MinNuberOfHits = 3;
40 const int MaxNuberOfHits = 2000;
42 double M0, Mx, My, Mz, Mxy, Mxx, Myy, Mxz, Myz, Mzz, Mxz2, Myz2,
44 double A0, A1, A2, A22, epsilon = 0.000000000001;
45 double Dy, xnew, xold, ynew, yold = 100000000000.;
47 double SumS1 = 0., SumS2 = 0.;
50 double sigma_min = 0.05;
52 double d[MaxNuberOfHits];
53 double w[MaxNuberOfHits];
56 for (
int i = 0;
i < MaxNuberOfHits;
i++)
60 for (
int i = 0;
i < nofHits;
i++) {
69 for (i_iter = 0; i_iter < i_max_Robust; i_iter++) {
72 for (
int i = 0;
i < nofHits;
i++) {
75 d[
i] =
sqrt(dx * dx + dy * dy) - radius;
76 SumS1 += w[
i] *
d[
i] *
d[
i];
82 sigma =
sqrt(SumS1 / SumS2);
84 if (sigma < sigma_min) sigma = sigma_min;
88 for (
int i = 0;
i < nofHits;
i++) {
89 if (
d[
i] <= ctsigma) {
90 w[
i] = (1 - (
d[
i] / (ctsigma)) * (
d[
i] / (ctsigma)))
91 * (1 - (
d[
i] / (ctsigma)) * (
d[
i] / (ctsigma)));
99 Mxx = Myy = Mxy = Mxz = Myz = Mzz = 0.;
100 for (
int i = 0;
i < nofHits;
i++) {
104 Zi = Xi * Xi + Yi * Yi;
114 if (M0 < MinNuberOfHits) {
116 Mxx = Myy = Mxy = Mxz = Myz = Mzz = 0.;
118 for (
int i = 0;
i < nofHits;
i++) {
121 Zi = Xi * Xi + Yi * Yi;
140 Cov_xy = Mxx * Myy - Mxy * Mxy;
144 A2 = 4. * Cov_xy - 3. * Mz * Mz - Mzz;
145 A1 = Mzz * Mz + 4. * Cov_xy * Mz - Mxz2 - Myz2 - Mz * Mz * Mz;
146 A0 = Mxz2 * Myy + Myz2 * Mxx - Mzz * Cov_xy - 2. * Mxz * Myz * Mxy
154 for (iter = 0; iter < iterMax; iter++) {
155 ynew = A0 + xnew * (A1 + xnew * (A2 + 4. * xnew * xnew));
163 Dy = A1 + xnew * (A22 + 16. * xnew * xnew);
165 xnew = xold - ynew / Dy;
167 if (
fabs((xnew - xold) / xnew) < epsilon)
break;
170 if (iter == iterMax - 1) {
180 GAM = -Mz - xnew - xnew;
181 DET = xnew * xnew - xnew * Mz + Cov_xy;
182 centerX = (Mxz * (Myy - xnew) - Myz * Mxy) / DET / 2.;
183 centerY = (Myz * (Mxx - xnew) - Mxz * Mxy) / DET / 2.;
184 radius =
sqrt(centerX * centerX + centerY * centerY - GAM);
185 centerX = centerX + Mx;
186 centerY = centerY + My;