+
+Double_t AliKFParticle::GetDistanceFromVertexXY( const Double_t vtx[] ) const
+{
+ //* Calculate distance from vertex [cm] in XY-plane
+
+ Double_t mP[8], mC[36];
+ Transport( GetDStoPoint(vtx), mP, mC );
+ Double_t d[2]={ vtx[0]-mP[0], vtx[1]-mP[1] };
+ Double_t dist = TMath::Sqrt( d[0]*d[0]+d[1]*d[1] );
+ Double_t sign = d[0]*mP[3] - d[1]*mP[4];
+ return (sign>=0) ?dist :-dist;
+}
+
+Double_t AliKFParticle::GetDistanceFromVertexXY( const AliKFParticle &Vtx ) const
+{
+ //* Calculate distance from vertex [cm] in XY-plane
+
+ return GetDistanceFromVertexXY( Vtx.fP );
+}
+
+Double_t AliKFParticle::GetDistanceFromVertexXY( const AliVVertex &Vtx ) const
+{
+ //* Calculate distance from vertex [cm] in XY-plane
+
+ return GetDistanceFromVertexXY( AliKFParticle(Vtx).fP );
+}
+
+Double_t AliKFParticle::GetDistanceFromParticleXY( const AliKFParticle &p ) const
+{
+ //* Calculate distance to other particle [cm]
+
+ Double_t dS, dS1;
+ GetDStoParticleXY( p, dS, dS1 );
+ Double_t mP[8], mC[36], mP1[8], mC1[36];
+ Transport( dS, mP, mC );
+ p.Transport( dS1, mP1, mC1 );
+ Double_t dx = mP[0]-mP1[0];
+ Double_t dy = mP[1]-mP1[1];
+ return TMath::Sqrt(dx*dx+dy*dy);
+}
+
+Double_t AliKFParticle::GetDeviationFromParticleXY( const AliKFParticle &p ) const
+{
+ //* Calculate sqrt(Chi2/ndf) deviation from other particle
+
+ Double_t dS, dS1;
+ GetDStoParticleXY( p, dS, dS1 );
+ Double_t mP1[8], mC1[36];
+ p.Transport( dS1, mP1, mC1 );
+
+ Double_t d[2]={ fP[0]-mP1[0], fP[1]-mP1[1] };
+
+ Double_t sigmaS = .1+10.*TMath::Sqrt( (d[0]*d[0]+d[1]*d[1] )/
+ (mP1[3]*mP1[3]+mP1[4]*mP1[4] ) );
+
+ Double_t h[2] = { mP1[3]*sigmaS, mP1[4]*sigmaS };
+
+ mC1[0] +=h[0]*h[0];
+ mC1[1] +=h[1]*h[0];
+ mC1[2] +=h[1]*h[1];
+
+ return GetDeviationFromVertexXY( mP1, mC1 )*TMath::Sqrt(2./1.);
+}
+
+
+Double_t AliKFParticle::GetDeviationFromVertexXY( const Double_t v[], const Double_t Cv[] ) const
+{
+ //* Calculate sqrt(Chi2/ndf) deviation from vertex
+ //* v = [xyz], Cv=[Cxx,Cxy,Cyy,Cxz,Cyz,Czz]-covariance matrix
+
+ Double_t mP[8];
+ Double_t mC[36];
+
+ Transport( GetDStoPoint(v), mP, mC );
+
+ Double_t d[2]={ v[0]-mP[0], v[1]-mP[1] };
+
+ Double_t sigmaS = .1+10.*TMath::Sqrt( (d[0]*d[0]+d[1]*d[1] )/
+ (mP[3]*mP[3]+mP[4]*mP[4] ) );
+
+ Double_t h[2] = { mP[3]*sigmaS, mP[4]*sigmaS };
+
+ Double_t mSi[3] = { mC[0] +h[0]*h[0],
+ mC[1] +h[1]*h[0], mC[2] +h[1]*h[1] };
+
+ if( Cv ){
+ mSi[0]+=Cv[0];
+ mSi[1]+=Cv[1];
+ mSi[2]+=Cv[2];
+ }
+ Double_t s = ( mSi[0]*mSi[2] - mSi[1]*mSi[1] );
+ s = ( s > 1.E-20 ) ?1./s :0;
+
+ Double_t mS[3] = { mSi[2],
+ -mSi[1], mSi[0] };
+
+ return TMath::Sqrt( TMath::Abs(s*( ( mS[0]*d[0] + mS[1]*d[1] )*d[0]
+ +(mS[1]*d[0] + mS[2]*d[1] )*d[1] ))/1);
+}
+
+
+Double_t AliKFParticle::GetDeviationFromVertexXY( const AliKFParticle &Vtx ) const
+{
+ //* Calculate sqrt(Chi2/ndf) deviation from vertex
+ //* v = [xyz], Cv=[Cxx,Cxy,Cyy,Cxz,Cyz,Czz]-covariance matrix
+
+ return GetDeviationFromVertexXY( Vtx.fP, Vtx.fC );
+}
+
+Double_t AliKFParticle::GetDeviationFromVertexXY( const AliVVertex &Vtx ) const
+{
+ //* Calculate sqrt(Chi2/ndf) deviation from vertex
+ //* v = [xyz], Cv=[Cxx,Cxy,Cyy,Cxz,Cyz,Czz]-covariance matrix
+
+ AliKFParticle v(Vtx);
+ return GetDeviationFromVertexXY( v.fP, v.fC );
+}
+
+
+Double_t AliKFParticle::GetAngle ( const AliKFParticle &p ) const
+{
+ //* Calculate the opening angle between two particles
+
+ Double_t dS, dS1;
+ GetDStoParticle( p, dS, dS1 );
+ Double_t mP[8], mC[36], mP1[8], mC1[36];
+ Transport( dS, mP, mC );
+ p.Transport( dS1, mP1, mC1 );
+ Double_t n = TMath::Sqrt( mP[3]*mP[3] + mP[4]*mP[4] + mP[5]*mP[5] );
+ Double_t n1= TMath::Sqrt( mP1[3]*mP1[3] + mP1[4]*mP1[4] + mP1[5]*mP1[5] );
+ n*=n1;
+ Double_t a = 0;
+ if( n>1.e-8 ) a = ( mP[3]*mP1[3] + mP[4]*mP1[4] + mP[5]*mP1[5] )/n;
+ if (TMath::Abs(a)<1.) a = TMath::ACos(a);
+ else a = (a>=0) ?0 :TMath::Pi();
+ return a;
+}
+
+Double_t AliKFParticle::GetAngleXY( const AliKFParticle &p ) const
+{
+ //* Calculate the opening angle between two particles in XY plane
+
+ Double_t dS, dS1;
+ GetDStoParticleXY( p, dS, dS1 );
+ Double_t mP[8], mC[36], mP1[8], mC1[36];
+ Transport( dS, mP, mC );
+ p.Transport( dS1, mP1, mC1 );
+ Double_t n = TMath::Sqrt( mP[3]*mP[3] + mP[4]*mP[4] );
+ Double_t n1= TMath::Sqrt( mP1[3]*mP1[3] + mP1[4]*mP1[4] );
+ n*=n1;
+ Double_t a = 0;
+ if( n>1.e-8 ) a = ( mP[3]*mP1[3] + mP[4]*mP1[4] )/n;
+ if (TMath::Abs(a)<1.) a = TMath::ACos(a);
+ else a = (a>=0) ?0 :TMath::Pi();
+ return a;
+}
+
+Double_t AliKFParticle::GetAngleRZ( const AliKFParticle &p ) const
+{
+ //* Calculate the opening angle between two particles in RZ plane
+
+ Double_t dS, dS1;
+ GetDStoParticle( p, dS, dS1 );
+ Double_t mP[8], mC[36], mP1[8], mC1[36];
+ Transport( dS, mP, mC );
+ p.Transport( dS1, mP1, mC1 );
+ Double_t nr = TMath::Sqrt( mP[3]*mP[3] + mP[4]*mP[4] );
+ Double_t n1r= TMath::Sqrt( mP1[3]*mP1[3] + mP1[4]*mP1[4] );
+ Double_t n = TMath::Sqrt( nr*nr + mP[5]*mP[5] );
+ Double_t n1= TMath::Sqrt( n1r*n1r + mP1[5]*mP1[5] );
+ n*=n1;
+ Double_t a = 0;
+ if( n>1.e-8 ) a = ( nr*n1r +mP[5]*mP1[5])/n;
+ if (TMath::Abs(a)<1.) a = TMath::ACos(a);
+ else a = (a>=0) ?0 :TMath::Pi();
+ return a;
+}
+
+
+/*
+
+#include "AliExternalTrackParam.h"
+