46 int i_iter, i_max_Robust = 4;
47 const int MinNuberOfHits = 3;
48 const int MaxNuberOfHits = 2000;
50 double M0,Mx,My,Mz,Mxy,Mxx,Myy,Mxz,Myz,Mzz,Mxz2,Myz2,Cov_xy;
51 double A0,A1,
A2,A22,
epsilon=0.000000000001;
52 double Dy,xnew,xold,ynew,yold=100000000000.;
54 double SumS1 = 0., SumS2 = 0.;
57 double sigma_min = 0.05;
59 double d[MaxNuberOfHits];
60 double w[MaxNuberOfHits];
63 for(
int i = 0; i < MaxNuberOfHits; i++) w[i] = 1.;
66 for(
int i = 0; i < nofHits; i++) {
75 for(i_iter = 0; i_iter < i_max_Robust; i_iter++){
78 for(
int i = 0; i < nofHits; i++){
81 d[i] = sqrt(dx*dx + dy*dy) -
radius;
82 SumS1 += w[i]*d[i]*d[i];
85 if(SumS2 == 0.){ sigma = sigma_min; }
else{ sigma = sqrt(SumS1/SumS2);}
86 if(sigma < sigma_min) sigma = sigma_min;
90 for(
int i = 0; i < nofHits; i++){
92 w[i] = (1 - (d[i]/(ctsigma))*(d[i]/(ctsigma)))*(1 - (d[i]/(ctsigma))*(d[i]/(ctsigma)));
98 Mxx=Myy=Mxy=Mxz=Myz=Mzz=0.;
99 for (
int i = 0; i < nofHits; i++) {
113 if(M0 < MinNuberOfHits){
115 Mxx=Myy=Mxy=Mxz=Myz=Mzz=0.;
117 for (
int i = 0; i < nofHits; i++) {
139 Cov_xy = Mxx*Myy - Mxy*Mxy;
143 A2 = 4.*Cov_xy - 3.*Mz*Mz - Mzz;
144 A1 = Mzz*Mz + 4.*Cov_xy*Mz - Mxz2 - Myz2 - Mz*Mz*Mz;
145 A0 = Mxz2*Myy + Myz2*Mxx - Mzz*Cov_xy - 2.*Mxz*Myz*Mxy + Mz*Mz*Cov_xy;
152 for(iter = 0; iter < iterMax; iter++) {
153 ynew = A0 + xnew*(A1 + xnew*(A2 + 4.*xnew*xnew));
155 if (fabs(ynew)>fabs(yold))
162 Dy = A1 + xnew*(A22 + 16.*xnew*xnew);
164 xnew = xold - ynew/
Dy;
166 if (fabs((xnew-xold)/xnew) <
epsilon)
break;
169 if (iter == iterMax-1) {
179 GAM = - Mz - xnew - xnew;
180 DET = xnew*xnew - xnew*Mz + Cov_xy;
181 centerX = (Mxz*(Myy-xnew) - Myz*Mxy)/DET/2.;
182 centerY = (Myz*(Mxx-xnew) - Mxz*Mxy)/DET/2.;
183 radius = sqrt(centerX * centerX + centerY * centerY - GAM);
184 centerX = centerX + Mx;
185 centerY = centerY + My;