+Double_t AliExternalTrackParam::
+GetPredictedChi2(Double_t p[3],Double_t covyz[3],Double_t covxyz[3]) const {
+ //----------------------------------------------------------------
+ // Estimate the chi2 of the 3D space point "p" and
+ // the full covariance matrix "covyz" and "covxyz"
+ //
+ // Cov(x,x) ... : covxyz[0]
+ // Cov(y,x) ... : covxyz[1] covyz[0]
+ // Cov(z,x) ... : covxyz[2] covyz[1] covyz[2]
+ //----------------------------------------------------------------
+
+ Double_t res[3] = {
+ GetX() - p[0],
+ GetY() - p[1],
+ GetZ() - p[2]
+ };
+
+ Double_t f=GetSnp();
+ if (TMath::Abs(f) >= kAlmost1) return kVeryBig;
+ Double_t r=TMath::Sqrt((1.-f)*(1.+f));
+ Double_t a=f/r, b=GetTgl()/r;
+
+ Double_t s2=333.*333.; //something reasonably big (cm^2)
+
+ TMatrixDSym v(3);
+ v(0,0)= s2; v(0,1)= a*s2; v(0,2)= b*s2;;
+ v(1,0)=a*s2; v(1,1)=a*a*s2 + GetSigmaY2(); v(1,2)=a*b*s2 + GetSigmaZY();
+ v(2,0)=b*s2; v(2,1)=a*b*s2 + GetSigmaZY(); v(2,2)=b*b*s2 + GetSigmaZ2();
+
+ v(0,0)+=covxyz[0]; v(0,1)+=covxyz[1]; v(0,2)+=covxyz[2];
+ v(1,0)+=covxyz[1]; v(1,1)+=covyz[0]; v(1,2)+=covyz[1];
+ v(2,0)+=covxyz[2]; v(2,1)+=covyz[1]; v(2,2)+=covyz[2];
+
+ v.Invert();
+ if (!v.IsValid()) return kVeryBig;
+
+ Double_t chi2=0.;
+ for (Int_t i = 0; i < 3; i++)
+ for (Int_t j = 0; j < 3; j++) chi2 += res[i]*res[j]*v(i,j);
+
+ return chi2;
+}
+
+Double_t AliExternalTrackParam::
+GetPredictedChi2(const AliExternalTrackParam *t) const {
+ //----------------------------------------------------------------
+ // Estimate the chi2 (5 dof) of this track with respect to the track
+ // given by the argument.
+ // The two tracks must be in the same reference system
+ // and estimated at the same reference plane.
+ //----------------------------------------------------------------
+
+ if (TMath::Abs(1. - t->GetAlpha()/GetAlpha()) > FLT_EPSILON) {
+ AliError("The reference systems of the tracks differ !");
+ return kVeryBig;
+ }
+ if (TMath::Abs(1. - t->GetX()/GetX()) > FLT_EPSILON) {
+ AliError("The reference of the tracks planes differ !");
+ return kVeryBig;
+ }
+
+ TMatrixDSym c(5);
+ c(0,0)=GetSigmaY2();
+ c(1,0)=GetSigmaZY(); c(1,1)=GetSigmaZ2();
+ c(2,0)=GetSigmaSnpY(); c(2,1)=GetSigmaSnpZ(); c(2,2)=GetSigmaSnp2();
+ c(3,0)=GetSigmaTglY(); c(3,1)=GetSigmaTglZ(); c(3,2)=GetSigmaTglSnp(); c(3,3)=GetSigmaTgl2();
+ c(4,0)=GetSigma1PtY(); c(4,1)=GetSigma1PtZ(); c(4,2)=GetSigma1PtSnp(); c(4,3)=GetSigma1PtTgl(); c(4,4)=GetSigma1Pt2();
+
+ c(0,0)+=t->GetSigmaY2();
+ c(1,0)+=t->GetSigmaZY(); c(1,1)+=t->GetSigmaZ2();
+ c(2,0)+=t->GetSigmaSnpY();c(2,1)+=t->GetSigmaSnpZ();c(2,2)+=t->GetSigmaSnp2();
+ c(3,0)+=t->GetSigmaTglY();c(3,1)+=t->GetSigmaTglZ();c(3,2)+=t->GetSigmaTglSnp();c(3,3)+=t->GetSigmaTgl2();
+ c(4,0)+=t->GetSigma1PtY();c(4,1)+=t->GetSigma1PtZ();c(4,2)+=t->GetSigma1PtSnp();c(4,3)+=t->GetSigma1PtTgl();c(4,4)+=t->GetSigma1Pt2();
+ c(0,1)=c(1,0);
+ c(0,2)=c(2,0); c(1,2)=c(2,1);
+ c(0,3)=c(3,0); c(1,3)=c(3,1); c(2,3)=c(3,2);
+ c(0,4)=c(4,0); c(1,4)=c(4,1); c(2,4)=c(4,2); c(3,4)=c(4,3);
+
+ c.Invert();
+ if (!c.IsValid()) return kVeryBig;
+
+
+ Double_t res[5] = {
+ GetY() - t->GetY(),
+ GetZ() - t->GetZ(),
+ GetSnp() - t->GetSnp(),
+ GetTgl() - t->GetTgl(),
+ GetSigned1Pt() - t->GetSigned1Pt()
+ };
+
+ Double_t chi2=0.;
+ for (Int_t i = 0; i < 5; i++)
+ for (Int_t j = 0; j < 5; j++) chi2 += res[i]*res[j]*c(i,j);
+
+ return chi2;
+}
+
+Bool_t AliExternalTrackParam::
+PropagateTo(Double_t p[3],Double_t covyz[3],Double_t covxyz[3],Double_t bz) {
+ //----------------------------------------------------------------
+ // Propagate this track to the plane
+ // the 3D space point "p" (with the covariance matrix "covyz" and "covxyz")
+ // belongs to.
+ // The magnetic field is "bz" (kG)
+ //
+ // The track curvature and the change of the covariance matrix
+ // of the track parameters are negleted !
+ // (So the "step" should be small compared with 1/curvature)
+ //----------------------------------------------------------------
+
+ Double_t f=GetSnp();
+ if (TMath::Abs(f) >= kAlmost1) return kFALSE;
+ Double_t r=TMath::Sqrt((1.-f)*(1.+f));
+ Double_t a=f/r, b=GetTgl()/r;
+
+ Double_t s2=333.*333.; //something reasonably big (cm^2)
+
+ TMatrixDSym tV(3);
+ tV(0,0)= s2; tV(0,1)= a*s2; tV(0,2)= b*s2;
+ tV(1,0)=a*s2; tV(1,1)=a*a*s2; tV(1,2)=a*b*s2;
+ tV(2,0)=b*s2; tV(2,1)=a*b*s2; tV(2,2)=b*b*s2;
+
+ TMatrixDSym pV(3);
+ pV(0,0)=covxyz[0]; pV(0,1)=covxyz[1]; pV(0,2)=covxyz[2];
+ pV(1,0)=covxyz[1]; pV(1,1)=covyz[0]; pV(1,2)=covyz[1];
+ pV(2,0)=covxyz[2]; pV(2,1)=covyz[1]; pV(2,2)=covyz[2];
+
+ TMatrixDSym tpV(tV);
+ tpV+=pV;
+ tpV.Invert();
+ if (!tpV.IsValid()) return kFALSE;
+
+ TMatrixDSym pW(3),tW(3);
+ for (Int_t i=0; i<3; i++)
+ for (Int_t j=0; j<3; j++) {
+ pW(i,j)=tW(i,j)=0.;
+ for (Int_t k=0; k<3; k++) {
+ pW(i,j) += tV(i,k)*tpV(k,j);
+ tW(i,j) += pV(i,k)*tpV(k,j);
+ }
+ }
+
+ Double_t t[3] = {GetX(), GetY(), GetZ()};
+
+ Double_t x=0.;
+ for (Int_t i=0; i<3; i++) x += (tW(0,i)*t[i] + pW(0,i)*p[i]);
+ Double_t crv=GetC(bz);
+ if (TMath::Abs(b) < kAlmost0Field) crv=0.;
+ f += crv*(x-fX);
+ if (TMath::Abs(f) >= kAlmost1) return kFALSE;
+ fX=x;
+
+ fP[0]=0.;
+ for (Int_t i=0; i<3; i++) fP[0] += (tW(1,i)*t[i] + pW(1,i)*p[i]);
+ fP[1]=0.;
+ for (Int_t i=0; i<3; i++) fP[1] += (tW(2,i)*t[i] + pW(2,i)*p[i]);
+
+ return kTRUE;
+}
+
+Double_t *AliExternalTrackParam::GetResiduals(
+Double_t *p,Double_t *cov,Bool_t updated) const {
+ //------------------------------------------------------------------
+ // Returns the track residuals with the space point "p" having
+ // the covariance matrix "cov".
+ // If "updated" is kTRUE, the track parameters expected to be updated,
+ // otherwise they must be predicted.
+ //------------------------------------------------------------------
+ static Double_t res[2];
+
+ Double_t r00=cov[0], r01=cov[1], r11=cov[2];
+ if (updated) {
+ r00-=fC[0]; r01-=fC[1]; r11-=fC[2];
+ } else {
+ r00+=fC[0]; r01+=fC[1]; r11+=fC[2];
+ }
+ Double_t det=r00*r11 - r01*r01;
+
+ if (TMath::Abs(det) < kAlmost0) return 0;
+
+ Double_t tmp=r00; r00=r11/det; r11=tmp/det;
+
+ if (r00 < 0.) return 0;
+ if (r11 < 0.) return 0;
+
+ Double_t dy = fP[0] - p[0];
+ Double_t dz = fP[1] - p[1];
+
+ res[0]=dy*TMath::Sqrt(r00);
+ res[1]=dz*TMath::Sqrt(r11);
+
+ return res;
+}
+