43 int iter, iterMax = 20;
48 double M0, Mx, My, Mz, Mxy, Mxx, Myy, Mxz, Myz, Mzz, Mxz2, Myz2, Cov_xy;
49 double A0, A1, A2, A22, A3, A33, epsilon = 0.000000000001;
50 double Dy, xnew, xold, ynew, yold = 100000000000.;
58 const double copt = 0.2;
59 const double zero = 0.0001;
60 const double SigmaMin = 0.18;
61 double amax = -100000;
82 for (
int i = 0; i < nofHits; i++) {
88 for (
int i = 0; i < nofHits; i++) {
89 if (a[i] > amax) amax = a[i];
90 if (a[i] < amin) amin = a[i];
93 for (
int i = 0; i < nofHits; i++)
96 for (
int riter = 0; riter < riterMax; riter++) {
100 for (
int i = 0; i < nofHits; i++) {
110 Mxx = Myy = Mxy = Mxz = Myz = Mzz = 0.;
112 for (
int i = 0; i < nofHits; i++) {
115 Zi = Xi * Xi + Yi * Yi;
117 Mxy += Xi * Yi * w[i];
118 Mxx += Xi * Xi * w[i];
119 Myy += Yi * Yi * w[i];
120 Mxz += Xi * Zi * w[i];
121 Myz += Yi * Zi * w[i];
122 Mzz += Zi * Zi * w[i];
133 Cov_xy = Mxx * Myy - Mxy * Mxy;
138 A2 = -3. * Mz * Mz - Mzz;
139 A1 = Mzz * Mz + 4. * Cov_xy * Mz - Mxz2 - Myz2 - Mz * Mz * Mz;
140 A0 = Mxz2 * Myy + Myz2 * Mxx - Mzz * Cov_xy - 2. * Mxz * Myz * Mxy + Mz * Mz * Cov_xy;
148 for (iter = 0; iter < iterMax; iter++) {
149 ynew = A0 + xnew * (A1 + xnew * (A2 + xnew * A3));
151 if (fabs(ynew) > fabs(yold)) {
156 Dy = A1 + xnew * (A22 + xnew * A33);
158 xnew = xold - ynew / Dy;
160 if (fabs((xnew - xold) / xnew) < epsilon)
break;
163 if (iter == iterMax - 1) {
174 DET = xnew * xnew - xnew * Mz + Cov_xy;
175 centerX = (Mxz * (Myy - xnew) - Myz * Mxy) / DET / 2.;
176 centerY = (Myz * (Mxx - xnew) - Mxz * Mxy) / DET / 2.;
177 radius =
sqrt(centerX * centerX + centerY * centerY - GAM);
178 centerX = (Mxz * (Myy - xnew) - Myz * Mxy) / DET / 2. + Mx;
179 centerY = (Myz * (Mxx - xnew) - Mxz * Mxy) / DET / 2. + My;
181 if (riter < riterMax - 1) {
182 for (
int i = 0; i < nofHits; i++) {
183 dist =
sqrt(pow((centerX -
x[i]), 2) + pow((centerY -
y[i]), 2)) - radius;
188 for (
unsigned int i = 0; i < d.size(); i++) {
189 sig1 += w[i] * d[i] * d[i];
192 sigma =
sqrt(sig1 / sig2);
193 if (sigma < SigmaMin) sigma = SigmaMin;
194 ctsigma = ct * sigma;
199 for (
unsigned int i = 0; i < d.size(); i++) {
201 if (d[i] <= ctsigma) {
202 weight = pow((1 - pow((d[i] / ctsigma), 2)), 2);
203 if (weight < zero) weight = zero;
213 weight /= 1 + copt *
exp(pow((d[i] / sigma), 2));
214 if (weight < zero) weight = zero;