]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliKFParticleBase.cxx
syntax correction in comments
[u/mrichter/AliRoot.git] / STEER / AliKFParticleBase.cxx
index de44c615390e45ddfdc4690b573e099ed0e6b924..b13602789d88e1f2d680d45cf8f7b8d54f30ef3c 100644 (file)
@@ -28,7 +28,53 @@ AliKFParticleBase::AliKFParticleBase() :fQ(0), fNDF(-3), fChi2(0), fSFromDecay(0
 
   Initialize();
 }
+
+void AliKFParticleBase::Initialize( const Double_t Param[], const Double_t Cov[], Int_t Charge, Double_t Mass )
+{
+  // Constructor from "cartesian" track, particle mass hypothesis should be provided
+  //
+  // Param[6] = { X, Y, Z, Px, Py, Pz } - position and momentum
+  // Cov [21] = lower-triangular part of the covariance matrix:
+  //
+  //                (  0  .  .  .  .  . )
+  //                (  1  2  .  .  .  . )
+  //  Cov. matrix = (  3  4  5  .  .  . ) - numbering of covariance elements in Cov[]
+  //                (  6  7  8  9  .  . )
+  //                ( 10 11 12 13 14  . )
+  //                ( 15 16 17 18 19 20 )
+
+
+  for( Int_t i=0; i<6 ; i++ ) fP[i] = Param[i];
+  for( Int_t i=0; i<21; i++ ) fC[i] = Cov[i];
+
+  Double_t energy = TMath::Sqrt( Mass*Mass + fP[3]*fP[3] + fP[4]*fP[4] + fP[5]*fP[5]);
+  fP[6] = energy;
+  fP[7] = 0;
+  fQ = Charge;
+  fNDF = 0;
+  fChi2 = 0;
+  fAtProductionVertex = 0;
+  fIsLinearized = 0;
+  fSFromDecay = 0;
+
+  Double_t energyInv = 1./energy;
+  Double_t 
+    h0 = fP[3]*energyInv,
+    h1 = fP[4]*energyInv,
+    h2 = fP[5]*energyInv;
+
+  fC[21] = h0*fC[ 6] + h1*fC[10] + h2*fC[15];
+  fC[22] = h0*fC[ 7] + h1*fC[11] + h2*fC[16];
+  fC[23] = h0*fC[ 8] + h1*fC[12] + h2*fC[17];
+  fC[24] = h0*fC[ 9] + h1*fC[13] + h2*fC[18];
+  fC[25] = h0*fC[13] + h1*fC[14] + h2*fC[19];
+  fC[26] = h0*fC[18] + h1*fC[19] + h2*fC[20];
+  fC[27] = ( h0*h0*fC[ 9] + h1*h1*fC[14] + h2*h2*fC[20] 
+            + 2*(h0*h1*fC[13] + h0*h2*fC[18] + h1*h2*fC[19] ) );
+  for( Int_t i=28; i<36; i++ ) fC[i] = 0;
+  fC[35] = 1.;
+}
+
 void AliKFParticleBase::Initialize()
 {
   //* Initialise covariance matrix and set current parameters to 0.0 
@@ -57,7 +103,7 @@ void AliKFParticleBase::SetVtxGuess( Double_t x, Double_t y, Double_t z )
 }
 
 
-Int_t AliKFParticleBase::GetMomentum( Double_t &P, Double_t &Error )  const 
+Int_t AliKFParticleBase::GetMomentum( Double_t &p, Double_t &error )  const 
 {
   //* Calculate particle momentum
 
@@ -68,16 +114,105 @@ Int_t AliKFParticleBase::GetMomentum( Double_t &P, Double_t &Error )  const
   Double_t y2 = y*y;
   Double_t z2 = z*z;
   Double_t p2 = x2+y2+z2;
-  P = TMath::Sqrt(p2);
-  Error = (x2*fC[9]+y2*fC[14]+z2*fC[20] + 2*(x*y*fC[13]+x*z*fC[18]+y*z*fC[19]) );
-  if( Error>0 && P>1.e-4 ){
-    Error = TMath::Sqrt(Error)/P;
+  p = TMath::Sqrt(p2);
+  error = (x2*fC[9]+y2*fC[14]+z2*fC[20] + 2*(x*y*fC[13]+x*z*fC[18]+y*z*fC[19]) );
+  if( error>0 && p>1.e-4 ){
+    error = TMath::Sqrt(error)/p;
+    return 0;
+  }
+  return 1;
+}
+
+Int_t AliKFParticleBase::GetPt( Double_t &pt, Double_t &error )  const 
+{
+  //* Calculate particle transverse momentum
+
+  Double_t px = fP[3];
+  Double_t py = fP[4];
+  Double_t px2 = px*px;
+  Double_t py2 = py*py;
+  Double_t pt2 = px2+py2;
+  pt = TMath::Sqrt(pt2);
+  error = (px2*fC[9] + py2*fC[14] + 2*px*py*fC[13] );
+  if( error>0 && pt>1.e-4 ){
+    error = TMath::Sqrt(error)/pt;
+    return 0;
+  }
+  error = 1.e10;
+  return 1;
+}
+
+Int_t AliKFParticleBase::GetEta( Double_t &eta, Double_t &error )  const 
+{
+  //* Calculate particle pseudorapidity
+
+  Double_t px = fP[3];
+  Double_t py = fP[4];
+  Double_t pz = fP[5];
+  Double_t pt2 = px*px + py*py;
+  Double_t p2 = pt2 + pz*pz;
+  Double_t p = TMath::Sqrt(p2);
+  Double_t a = p + pz;
+  Double_t b = p - pz;
+  eta = 1.e10;
+  if( b > 1.e-8 ){
+    Double_t c = a/b;
+    if( c>1.e-8 ) eta = 0.5*TMath::Log(a/b);
+  }
+  Double_t h3 = -px*pz;
+  Double_t h4 = -py*pz;
+  Double_t p2pt2 = p2*pt2;
+
+  error = (h3*h3*fC[9] + h4*h4*fC[14] + pt2*fC[20] + 
+          2*( h3*(h4*fC[13] + fC[18]) + h4*fC[19] )
+          );
+
+  if( error>0 && p2pt2>1.e-4 ){
+    error = TMath::Sqrt(error/p2pt2);
+    return 0;
+  }
+  error = 1.e10;
+  return 1;
+}
+
+Int_t AliKFParticleBase::GetPhi( Double_t &phi, Double_t &error )  const 
+{
+  //* Calculate particle polar angle
+
+  Double_t px = fP[3];
+  Double_t py = fP[4];
+  Double_t px2 = px*px;
+  Double_t py2 = py*py;
+  Double_t pt2 = px2 + py2;
+  phi = TMath::ATan2(py,px);
+  error = (py2*fC[9] + px2*fC[14] - 2*px*py*fC[13] );
+  if( error>0 && pt2>1.e-4 ){
+    error = TMath::Sqrt(error)/pt2;
+    return 0;
+  }
+  error = 1.e10;
+  return 1;
+}
+
+Int_t AliKFParticleBase::GetR( Double_t &r, Double_t &error )  const 
+{
+  //* Calculate distance to the origin
+
+  Double_t x = fP[0];
+  Double_t y = fP[1];
+  Double_t x2 = x*x;
+  Double_t y2 = y*y;
+  r = TMath::Sqrt(x2 + y2);
+  error = (x2*fC[0] + y2*fC[2] - 2*x*y*fC[1] );
+  if( error>0 && r>1.e-4 ){
+    error = TMath::Sqrt(error)/r;
     return 0;
   }
+  error = 1.e10;
   return 1;
 }
 
-Int_t AliKFParticleBase::GetMass( Double_t &M, Double_t &Error ) const 
+Int_t AliKFParticleBase::GetMass( Double_t &m, Double_t &error ) const 
 {
   //* Calculate particle mass
   
@@ -88,19 +223,20 @@ Int_t AliKFParticleBase::GetMass( Double_t &M, Double_t &Error ) const
                +2*( + fP[3]*fP[4]*fC[13] + fP[5]*(fP[3]*fC[18] + fP[4]*fC[19]) 
                     - fP[6]*( fP[3]*fC[24] + fP[4]*fC[25] + fP[5]*fC[26] )   )
                 ); 
-  Double_t m2 = fP[6]*fP[6] - fP[3]*fP[3] - fP[4]*fP[4] - fP[5]*fP[5];
-  if( s>=0 && m2>1.e-20 ){
-    M = TMath::Sqrt(m2);
-    Error = TMath::Sqrt(s/m2);
-    return 0;
+  Double_t m2 = TMath::Abs(fP[6]*fP[6] - fP[3]*fP[3] - fP[4]*fP[4] - fP[5]*fP[5]);
+  m  = TMath::Sqrt(m2);
+  if( m>1.e-10 ){
+    if( s>=0 ){
+      error = TMath::Sqrt(s)/m;
+      return 0;
+    }
   }
-  M     = 0;
-  Error = 1.e20;
+  error = 1.e20;
   return 1;
 }
 
 
-Int_t AliKFParticleBase::GetDecayLength( Double_t &L, Double_t &Error ) const 
+Int_t AliKFParticleBase::GetDecayLength( Double_t &l, Double_t &error ) const 
 {
   //* Calculate particle decay length [cm]
 
@@ -112,32 +248,32 @@ Int_t AliKFParticleBase::GetDecayLength( Double_t &L, Double_t &Error ) const
   Double_t y2 = y*y;
   Double_t z2 = z*z;
   Double_t p2 = x2+y2+z2;
-  L = t*TMath::Sqrt(p2);
+  l = t*TMath::Sqrt(p2);
   if( p2>1.e-4){
-    Error = p2*fC[35] + t*t/p2*(x2*fC[9]+y2*fC[14]+z2*fC[20]
+    error = p2*fC[35] + t*t/p2*(x2*fC[9]+y2*fC[14]+z2*fC[20]
                                + 2*(x*y*fC[13]+x*z*fC[18]+y*z*fC[19]) )
       + 2*t*(x*fC[31]+y*fC[32]+z*fC[33]);
-    Error = TMath::Sqrt(TMath::Abs(Error));
+    error = TMath::Sqrt(TMath::Abs(error));
     return 0;
   }
-  Error = 1.e20;
+  error = 1.e20;
   return 1;
 }
 
-Int_t AliKFParticleBase::GetLifeTime( Double_t &TauC, Double_t &Error ) const 
+Int_t AliKFParticleBase::GetLifeTime( Double_t &tauC, Double_t &error ) const 
 {
   //* Calculate particle decay time [s]
 
   Double_t m, dm;
   GetMass( m, dm );
   Double_t cTM = (-fP[3]*fC[31] - fP[4]*fC[32] - fP[5]*fC[33] + fP[6]*fC[34]);
-  TauC = fP[7]*m;
-  Error = m*m*fC[35] + 2*fP[7]*cTM + fP[7]*fP[7]*dm*dm;
-  if( Error > 0 ){
-    Error = TMath::Sqrt( Error );
+  tauC = fP[7]*m;
+  error = m*m*fC[35] + 2*fP[7]*cTM + fP[7]*fP[7]*dm*dm;
+  if( error > 0 ){
+    error = TMath::Sqrt( error );
     return 0;
   }
-  Error = 1.e20;
+  error = 1.e20;
   return 1;
 }
 
@@ -149,10 +285,78 @@ void AliKFParticleBase::operator +=( const AliKFParticleBase &Daughter )
   AddDaughter( Daughter );
 }
   
+Double_t AliKFParticleBase::GetSCorrection( const Double_t Part[], const Double_t XYZ[] ) 
+{
+  //* Get big enough correction for S error to let the particle Part be fitted to XYZ point
+  
+  Double_t d[3] = { XYZ[0]-Part[0], XYZ[1]-Part[1], XYZ[2]-Part[2] };
+  Double_t p2 = Part[3]*Part[3]+Part[4]*Part[4]+Part[5]*Part[5];
+  Double_t sigmaS = (p2>1.e-4) ? ( .1+3.*TMath::Sqrt( d[0]*d[0]+d[1]*d[1]+d[2]*d[2]) )/TMath::Sqrt(p2) : 1.;
+  return sigmaS;
+}
+
+void AliKFParticleBase::GetMeasurement( const Double_t XYZ[], Double_t m[], Double_t V[] ) const
+{
+  //* Get additional covariances V used during measurement
+
+  Double_t b[3];
+  GetFieldValue( XYZ, b );
+  const Double_t kCLight =  0.000299792458;
+  b[0]*=kCLight; b[1]*=kCLight; b[2]*=kCLight;
+
+  Transport( GetDStoPoint(XYZ), m, V );
+
+  Double_t sigmaS = GetSCorrection( m, XYZ );
+
+  Double_t h[6];
+
+  h[0] = m[3]*sigmaS;
+  h[1] = m[4]*sigmaS;
+  h[2] = m[5]*sigmaS;
+  h[3] = ( h[1]*b[2]-h[2]*b[1] )*GetQ();
+  h[4] = ( h[2]*b[0]-h[0]*b[2] )*GetQ();
+  h[5] = ( h[0]*b[1]-h[1]*b[0] )*GetQ();
+    
+  V[ 0]+= h[0]*h[0];
+  V[ 1]+= h[1]*h[0];
+  V[ 2]+= h[1]*h[1];
+  V[ 3]+= h[2]*h[0];
+  V[ 4]+= h[2]*h[1];
+  V[ 5]+= h[2]*h[2];
+
+  V[ 6]+= h[3]*h[0];
+  V[ 7]+= h[3]*h[1];
+  V[ 8]+= h[3]*h[2];
+  V[ 9]+= h[3]*h[3];
+
+  V[10]+= h[4]*h[0];
+  V[11]+= h[4]*h[1];
+  V[12]+= h[4]*h[2];
+  V[13]+= h[4]*h[3];
+  V[14]+= h[4]*h[4];
+
+  V[15]+= h[5]*h[0];
+  V[16]+= h[5]*h[1];
+  V[17]+= h[5]*h[2];
+  V[18]+= h[5]*h[3];
+  V[19]+= h[5]*h[4];
+  V[20]+= h[5]*h[5];
+}
+
+  
 void AliKFParticleBase::AddDaughter( const AliKFParticleBase &Daughter )
 {
   //* Add daughter 
 
+  if( fNDF<-1 ){ // first daughter -> just copy
+    fNDF   = -1;
+    fQ     =  Daughter.GetQ();
+    for( Int_t i=0; i<7; i++) fP[i] = Daughter.fP[i];
+    for( Int_t i=0; i<28; i++) fC[i] = Daughter.fC[i];
+    fSFromDecay = 0;
+    return;
+  }
+
   TransportToDecayVertex();
 
   Double_t b[3]; 
@@ -161,12 +365,19 @@ void AliKFParticleBase::AddDaughter( const AliKFParticleBase &Daughter )
   if( !fIsLinearized ){
     if( fNDF==-1 ){
       Double_t ds, ds1;
-      GetDStoParticle(Daughter, ds, ds1);
+      GetDStoParticle(Daughter, ds, ds1);      
       TransportToDS( ds );
+      Double_t m[8];
+      Double_t mCd[36];       
+      Daughter.Transport( ds1, m, mCd );    
+      fVtxGuess[0] = .5*( fP[0] + m[0] );
+      fVtxGuess[1] = .5*( fP[1] + m[1] );
+      fVtxGuess[2] = .5*( fP[2] + m[2] );
+    } else {
+      fVtxGuess[0] = fP[0];
+      fVtxGuess[1] = fP[1];
+      fVtxGuess[2] = fP[2]; 
     }
-    fVtxGuess[0] = fP[0];
-    fVtxGuess[1] = fP[1];
-    fVtxGuess[2] = fP[2]; 
     maxIter = 3;
   }
 
@@ -177,124 +388,29 @@ void AliKFParticleBase::AddDaughter( const AliKFParticleBase &Daughter )
       const Double_t kCLight =  0.000299792458;
       b[0]*=kCLight; b[1]*=kCLight; b[2]*=kCLight;
     }
-    if( fNDF==-1 ) TransportToDS( GetDStoPoint(fVtxGuess) );
-    
-    fSFromDecay = 0;
-
-    Double_t m[8];
-    Double_t mCd[36];
-    
-    Double_t dds = Daughter.GetDStoPoint(fVtxGuess);
-    
-    Daughter.Transport( Daughter.GetDStoPoint(fVtxGuess), m, mCd );
-
-    Double_t d[3] = { fVtxGuess[0]-m[0], fVtxGuess[1]-m[1], fVtxGuess[2]-m[2] };
-    Double_t sigmaS = .1+10.*TMath::Sqrt( (d[0]*d[0]+d[1]*d[1]+d[2]*d[2])/
-                                         (m[3]*m[3]+m[4]*m[4]+m[5]*m[5])  );
 
-    Double_t h[6];
-
-    h[0] = m[3]*sigmaS;
-    h[1] = m[4]*sigmaS;
-    h[2] = m[5]*sigmaS; 
-    h[3] = ( h[1]*b[2]-h[2]*b[1] )*Daughter.GetQ();
-    h[4] = ( h[2]*b[0]-h[0]*b[2] )*Daughter.GetQ();
-    h[5] = ( h[0]*b[1]-h[1]*b[0] )*Daughter.GetQ();
-    
-    //* Fit of daughter momentum (Px,Py,Pz) to fVtxGuess vertex
-    {
-      Double_t zeta[3] = { fVtxGuess[0]-m[0], fVtxGuess[1]-m[1], fVtxGuess[2]-m[2] };
-      
-      Double_t mVv[6] = 
-       { mCd[ 0] + h[0]*h[0], 
-         mCd[ 1] + h[1]*h[0], mCd[ 2] + h[1]*h[1],                          
-         mCd[ 3] + h[2]*h[0], mCd[ 4] + h[2]*h[1], mCd[ 5] + h[2]*h[2] };
-      
-      Double_t mVvp[9]=
-       { mCd[ 6] + h[0]*h[3], mCd[ 7] + h[1]*h[3], mCd[ 8] + h[2]*h[3],
-         mCd[10] + h[0]*h[4], mCd[11] + h[1]*h[4], mCd[12] + h[2]*h[4],
-         mCd[15] + h[0]*h[5], mCd[16] + h[1]*h[5], mCd[17] + h[2]*h[5] };
-      
-      Double_t mS[6] = 
-       { mVv[2]*mVv[5] - mVv[4]*mVv[4],
-         mVv[3]*mVv[4] - mVv[1]*mVv[5], mVv[0]*mVv[5] - mVv[3]*mVv[3],
-         mVv[1]*mVv[4] - mVv[2]*mVv[3], mVv[1]*mVv[3] - mVv[0]*mVv[4], 
-         mVv[0]*mVv[2] - mVv[1]*mVv[1] };               
-      
-      Double_t s = ( mVv[0]*mS[0] + mVv[1]*mS[1] + mVv[3]*mS[3] );
-      s = ( s > 1.E-20 )  ?1./s :0;
-      
-      mS[0]*=s; mS[1]*=s; mS[2]*=s; mS[3]*=s; mS[4]*=s; mS[5]*=s;
-      
-      Double_t mSz[3] = { (mS[0]*zeta[0]+mS[1]*zeta[1]+mS[3]*zeta[2]),
-                        (mS[1]*zeta[0]+mS[2]*zeta[1]+mS[4]*zeta[2]),
-                        (mS[3]*zeta[0]+mS[4]*zeta[1]+mS[5]*zeta[2]) };
-      
-      Double_t px = m[3] + mVvp[0]*mSz[0] + mVvp[1]*mSz[1] + mVvp[2]*mSz[2];
-      Double_t py = m[4] + mVvp[3]*mSz[0] + mVvp[4]*mSz[1] + mVvp[5]*mSz[2];
-      Double_t pz = m[5] + mVvp[6]*mSz[0] + mVvp[7]*mSz[1] + mVvp[8]*mSz[2];
-      
-      h[0] = px*sigmaS;
-      h[1] = py*sigmaS;
-      h[2] = pz*sigmaS; 
-      h[3] = ( h[1]*b[2]-h[2]*b[1] )*Daughter.GetQ();
-      h[4] = ( h[2]*b[0]-h[0]*b[2] )*Daughter.GetQ();
-      h[5] = ( h[0]*b[1]-h[1]*b[0] )*Daughter.GetQ();
+    Double_t *ffP = fP, *ffC = fC, tmpP[8], tmpC[36];
+    if( fNDF==-1 ){      
+      GetMeasurement( fVtxGuess, tmpP, tmpC );
+      ffP = tmpP;
+      ffC = tmpC;
     }
-   
-    Double_t mV[28];
-    
-    mV[ 0] = mCd[ 0] + h[0]*h[0];
-    mV[ 1] = mCd[ 1] + h[1]*h[0];
-    mV[ 2] = mCd[ 2] + h[1]*h[1];
-    mV[ 3] = mCd[ 3] + h[2]*h[0];
-    mV[ 4] = mCd[ 4] + h[2]*h[1];
-    mV[ 5] = mCd[ 5] + h[2]*h[2];
-    
-    mV[ 6] = mCd[ 6] + h[3]*h[0];
-    mV[ 7] = mCd[ 7] + h[3]*h[1];
-    mV[ 8] = mCd[ 8] + h[3]*h[2];
-    mV[ 9] = mCd[ 9] + h[3]*h[3];
-
-    mV[10] = mCd[10] + h[4]*h[0];
-    mV[11] = mCd[11] + h[4]*h[1];
-    mV[12] = mCd[12] + h[4]*h[2];
-    mV[13] = mCd[13] + h[4]*h[3];
-    mV[14] = mCd[14] + h[4]*h[4];
-    
-    mV[15] = mCd[15] + h[5]*h[0];
-    mV[16] = mCd[16] + h[5]*h[1];
-    mV[17] = mCd[17] + h[5]*h[2];
-    mV[18] = mCd[18] + h[5]*h[3];
-    mV[19] = mCd[19] + h[5]*h[4];
-    mV[20] = mCd[20] + h[5]*h[5];        
-    
-    mV[21] = mCd[21];
-    mV[22] = mCd[22];
-    mV[23] = mCd[23];
-    mV[24] = mCd[24];
-    mV[25] = mCd[25];
-    mV[26] = mCd[26];
-    mV[27] = mCd[27];
-  
-   //* 
-           
-    if( fNDF<-1 ){ // first daughter -> just copy
-      fNDF   = -1;
-      fQ     =  Daughter.GetQ();
-      for( Int_t i=0; i<7; i++) fP[i] = m[i];
-      for( Int_t i=0; i<28; i++) fC[i] = mV[i];
-      fSFromDecay = 0;
-      return;
+
+    Double_t m[8], mV[36];
+    if( Daughter.fC[35]>0 ){
+      Daughter.GetMeasurement( fVtxGuess, m, mV );
+    } else {
+      for( Int_t i=0; i<8; i++ ) m[i] = Daughter.fP[i];
+      for( Int_t i=0; i<36; i++ ) mV[i] = Daughter.fC[i];
     }
 
     //*
 
     Double_t mS[6];
     {
-      Double_t mSi[6] = { fC[0]+mV[0], 
-                      fC[1]+mV[1], fC[2]+mV[2], 
-                      fC[3]+mV[3], fC[4]+mV[4], fC[5]+mV[5] };
+      Double_t mSi[6] = { ffC[0]+mV[0], 
+                         ffC[1]+mV[1], ffC[2]+mV[2], 
+                         ffC[3]+mV[3], ffC[4]+mV[4], ffC[5]+mV[5] };
       
       mS[0] = mSi[2]*mSi[5] - mSi[4]*mSi[4];
       mS[1] = mSi[3]*mSi[4] - mSi[1]*mSi[5];
@@ -303,7 +419,8 @@ void AliKFParticleBase::AddDaughter( const AliKFParticleBase &Daughter )
       mS[4] = mSi[1]*mSi[3] - mSi[0]*mSi[4];
       mS[5] = mSi[0]*mSi[2] - mSi[1]*mSi[1];    
       
-      Double_t s = ( mSi[0]*mS[0] + mSi[1]*mS[1] + mSi[3]*mS[3] );
+      Double_t s = ( mSi[0]*mS[0] + mSi[1]*mS[1] + mSi[3]*mS[3] );      
+
       s = ( s > 1.E-20 )  ?1./s :0;      
       mS[0]*=s;
       mS[1]*=s;
@@ -315,20 +432,19 @@ void AliKFParticleBase::AddDaughter( const AliKFParticleBase &Daughter )
     
     //* Residual (measured - estimated)
     
-    Double_t zeta[3] = { m[0]-fP[0], m[1]-fP[1], m[2]-fP[2] };
-    
+    Double_t zeta[3] = { m[0]-ffP[0], m[1]-ffP[1], m[2]-ffP[2] };    
     
     //* CHt = CH' - D'
     
     Double_t mCHt0[7], mCHt1[7], mCHt2[7];
     
-    mCHt0[0]=fC[ 0] ;      mCHt1[0]=fC[ 1] ;      mCHt2[0]=fC[ 3] ;
-    mCHt0[1]=fC[ 1] ;      mCHt1[1]=fC[ 2] ;      mCHt2[1]=fC[ 4] ;
-    mCHt0[2]=fC[ 3] ;      mCHt1[2]=fC[ 4] ;      mCHt2[2]=fC[ 5] ;
-    mCHt0[3]=fC[ 6]-mV[ 6]; mCHt1[3]=fC[ 7]-mV[ 7]; mCHt2[3]=fC[ 8]-mV[ 8];
-    mCHt0[4]=fC[10]-mV[10]; mCHt1[4]=fC[11]-mV[11]; mCHt2[4]=fC[12]-mV[12];
-    mCHt0[5]=fC[15]-mV[15]; mCHt1[5]=fC[16]-mV[16]; mCHt2[5]=fC[17]-mV[17];
-    mCHt0[6]=fC[21]-mV[21]; mCHt1[6]=fC[22]-mV[22]; mCHt2[6]=fC[23]-mV[23];
+    mCHt0[0]=ffC[ 0] ;       mCHt1[0]=ffC[ 1] ;       mCHt2[0]=ffC[ 3] ;
+    mCHt0[1]=ffC[ 1] ;       mCHt1[1]=ffC[ 2] ;       mCHt2[1]=ffC[ 4] ;
+    mCHt0[2]=ffC[ 3] ;       mCHt1[2]=ffC[ 4] ;       mCHt2[2]=ffC[ 5] ;
+    mCHt0[3]=ffC[ 6]-mV[ 6]; mCHt1[3]=ffC[ 7]-mV[ 7]; mCHt2[3]=ffC[ 8]-mV[ 8];
+    mCHt0[4]=ffC[10]-mV[10]; mCHt1[4]=ffC[11]-mV[11]; mCHt2[4]=ffC[12]-mV[12];
+    mCHt0[5]=ffC[15]-mV[15]; mCHt1[5]=ffC[16]-mV[16]; mCHt2[5]=ffC[17]-mV[17];
+    mCHt0[6]=ffC[21]-mV[21]; mCHt1[6]=ffC[22]-mV[22]; mCHt2[6]=ffC[23]-mV[23];
   
     //* Kalman gain K = mCH'*S
     
@@ -344,7 +460,7 @@ void AliKFParticleBase::AddDaughter( const AliKFParticleBase &Daughter )
 
     if( iter<maxIter-1 ){
       for(Int_t i=0; i<3; ++i) 
-       fVtxGuess[i]= fP[i] + k0[i]*zeta[0]+k1[i]*zeta[1]+k2[i]*zeta[2];
+       fVtxGuess[i]= ffP[i] + k0[i]*zeta[0]+k1[i]*zeta[1]+k2[i]*zeta[2];
       continue;
     }
 
@@ -352,32 +468,32 @@ void AliKFParticleBase::AddDaughter( const AliKFParticleBase &Daughter )
 
     //* Add the daughter momentum to the particle momentum
     
-    fP[ 3] += m[ 3];
-    fP[ 4] += m[ 4];
-    fP[ 5] += m[ 5];
-    fP[ 6] += m[ 6];
+    ffP[ 3] += m[ 3];
+    ffP[ 4] += m[ 4];
+    ffP[ 5] += m[ 5];
+    ffP[ 6] += m[ 6];
   
-    fC[ 9] += mV[ 9];
-    fC[13] += mV[13];
-    fC[14] += mV[14];
-    fC[18] += mV[18];
-    fC[19] += mV[19];
-    fC[20] += mV[20];
-    fC[24] += mV[24];
-    fC[25] += mV[25];
-    fC[26] += mV[26];
-    fC[27] += mV[27];
+    ffC[ 9] += mV[ 9];
+    ffC[13] += mV[13];
+    ffC[14] += mV[14];
+    ffC[18] += mV[18];
+    ffC[19] += mV[19];
+    ffC[20] += mV[20];
+    ffC[24] += mV[24];
+    ffC[25] += mV[25];
+    ffC[26] += mV[26];
+    ffC[27] += mV[27];
     
     //* New estimation of the vertex position r += K*zeta
     
     for(Int_t i=0;i<7;++i) 
-      fP[i] += k0[i]*zeta[0] + k1[i]*zeta[1] + k2[i]*zeta[2];
+      fP[i] = ffP[i] + k0[i]*zeta[0] + k1[i]*zeta[1] + k2[i]*zeta[2];
     
     //* New covariance matrix C -= K*(mCH')'
    
     for(Int_t i=0, k=0;i<7;++i){
       for(Int_t j=0;j<=i;++j,++k) 
-       fC[k] -= k0[i]*mCHt0[j] + k1[i]*mCHt1[j] + k2[i]*mCHt2[j];
+       fC[k] = ffC[k] - (k0[i]*mCHt0[j] + k1[i]*mCHt1[j] + k2[i]*mCHt2[j] );
     }
     
     //* Calculate Chi^2 
@@ -387,26 +503,37 @@ void AliKFParticleBase::AddDaughter( const AliKFParticleBase &Daughter )
     fSFromDecay = 0;    
     fChi2 += (mS[0]*zeta[0] + mS[1]*zeta[1] + mS[3]*zeta[2])*zeta[0]
       +      (mS[1]*zeta[0] + mS[2]*zeta[1] + mS[4]*zeta[2])*zeta[1]
-      +      (mS[3]*zeta[0] + mS[4]*zeta[1] + mS[5]*zeta[2])*zeta[2];  
+      +      (mS[3]*zeta[0] + mS[4]*zeta[1] + mS[5]*zeta[2])*zeta[2];     
   }
 }
 
 
 void AliKFParticleBase::SetProductionVertex( const AliKFParticleBase &Vtx )
 {
-  //* Set production vertex for the particle
+  //* Set production vertex for the particle, when the particle was not used in the vertex fit
 
   const Double_t *m = Vtx.fP, *mV = Vtx.fC;
 
-  TransportToDS( GetDStoPoint( m ) );
-  fP[7] = -fSFromDecay;
-  Convert(1);
+  Bool_t noS = ( fC[35]<=0 ); // no decay length allowed
+
+  if( noS ){ 
+    TransportToDecayVertex();
+    fP[7] = 0;
+    fC[28] = fC[29] = fC[30] = fC[31] = fC[32] = fC[33] = fC[35] = fC[35] = 0;
+  } else {
+    TransportToDS( GetDStoPoint( m ) );
+    fP[7] = -fSFromDecay;
+    Convert(1);
+  }
+
   Double_t mAi[6];
-  mAi[0] = fC[4]*fC[4] - fC[2]*fC[5];
-  mAi[1] = fC[1]*fC[5] - fC[3]*fC[4];
-  mAi[3] = fC[2]*fC[3] - fC[1]*fC[4];
-  Double_t det = 1./(fC[0]*mAi[0] + fC[1]*mAi[1] + fC[3]*mAi[3]);
+  mAi[0] = fC[2]*fC[5] - fC[4]*fC[4];
+  mAi[1] = fC[3]*fC[4] - fC[1]*fC[5];
+  mAi[3] = fC[1]*fC[4] - fC[2]*fC[3];
+  Double_t det = (fC[0]*mAi[0] + fC[1]*mAi[1] + fC[3]*mAi[3]);
+  if( det>1.e-8 ) det = 1./det;    
+  else det = 0;
+
   mAi[0] *= det;
   mAi[1] *= det;
   mAi[3] *= det;
@@ -441,21 +568,29 @@ void AliKFParticleBase::SetProductionVertex( const AliKFParticleBase &Vtx )
   {
     Double_t mAV[6] = { fC[0]-mV[0], fC[1]-mV[1], fC[2]-mV[2], 
                        fC[3]-mV[3], fC[4]-mV[4], fC[5]-mV[5] };
+    
     Double_t mAVi[6];
-    mAVi[0] = mAV[4]*mAV[4] - mAV[2]*mAV[5];
-    mAVi[1] = mAV[1]*mAV[5] - mAV[3]*mAV[4];
-    mAVi[2] = mAV[3]*mAV[3] - mAV[0]*mAV[5] ;
-    mAVi[3] = mAV[2]*mAV[3] - mAV[1]*mAV[4];
-    mAVi[4] = mAV[0]*mAV[4] - mAV[1]*mAV[3] ;
-    mAVi[5] = mAV[1]*mAV[1] - mAV[0]*mAV[2] ;
+    mAVi[0] = mAV[2]*mAV[5] - mAV[4]*mAV[4];
+    mAVi[1] = mAV[3]*mAV[4] - mAV[1]*mAV[5];
+    mAVi[2] = mAV[0]*mAV[5] - mAV[3]*mAV[3];
+    mAVi[3] = mAV[1]*mAV[4] - mAV[2]*mAV[3];
+    mAVi[4] = mAV[1]*mAV[3] - mAV[0]*mAV[4];
+    mAVi[5] = mAV[0]*mAV[2] - mAV[1]*mAV[1];
+
+    det = ( mAV[0]*mAVi[0] + mAV[1]*mAVi[1] + mAV[3]*mAVi[3] );
 
-    det = 1./( mAV[0]*mAVi[0] + mAV[1]*mAVi[1] + mAV[3]*mAVi[3] );
+    if( TMath::Abs(det) > 1.E-8 ){
 
+      Double_t dChi2 = ( +(mAVi[0]*z[0] + mAVi[1]*z[1] + mAVi[3]*z[2])*z[0]
+                        +(mAVi[1]*z[0] + mAVi[2]*z[1] + mAVi[4]*z[2])*z[1]
+                        +(mAVi[3]*z[0] + mAVi[4]*z[1] + mAVi[5]*z[2])*z[2] )/det ;
+      
+      // Take Abs(dChi2) here. Negative value of 'det' or 'dChi2' shows that the particle 
+      // was not used in the production vertex fit
+      
+      fChi2+= TMath::Abs( dChi2 );
+    }
     fNDF  += 2;
-    fChi2 += 
-      ( +(mAVi[0]*z[0] + mAVi[1]*z[1] + mAVi[3]*z[2])*z[0]
-       +(mAVi[1]*z[0] + mAVi[2]*z[1] + mAVi[4]*z[2])*z[1]
-       +(mAVi[3]*z[0] + mAVi[4]*z[1] + mAVi[5]*z[2])*z[2] )*det;
   }
   
   fP[0] = m[0];
@@ -531,64 +666,116 @@ void AliKFParticleBase::SetProductionVertex( const AliKFParticleBase &Vtx )
   fC[34]+= d0*mB[3][0] + d1*mB[3][1] + d2*mB[3][2];
   fC[35]+= d0*mB[4][0] + d1*mB[4][1] + d2*mB[4][2];
   
-  TransportToDS( fP[7] );
+  if( noS ){ 
+    fP[7] = 0;
+    fC[28] = fC[29] = fC[30] = fC[31] = fC[32] = fC[33] = fC[35] = fC[35] = 0;
+  } else {
+    TransportToDS( fP[7] );
+    Convert(0);
+  }
+
   fSFromDecay = 0;
-  Convert(0);
 }
 
 
 
-
-void AliKFParticleBase::SetMassConstraint( Double_t Mass )
+void AliKFParticleBase::SetMassConstraint( Double_t Mass, Double_t SigmaMass )
 {  
-  //* Set hard mass constraint 
+  //* Set hard( SigmaMass=0 ) or soft (SigmaMass>0) mass constraint 
+
+  Double_t m2 = Mass*Mass;            // measurement, weighted by Mass 
+  Double_t s2 = m2*SigmaMass*SigmaMass; // sigma^2
+
+  Double_t p2 = fP[3]*fP[3] + fP[4]*fP[4] + fP[5]*fP[5]; 
+  Double_t e0 = TMath::Sqrt(m2+p2);
 
   Double_t mH[8];
   mH[0] = mH[1] = mH[2] = 0.;
   mH[3] = -2*fP[3]; 
   mH[4] = -2*fP[4]; 
   mH[5] = -2*fP[5]; 
-  mH[6] =  2*fP[6];
+  mH[6] =  2*fP[6];//e0;
   mH[7] = 0; 
-  Double_t m2 = ( fP[6]*fP[6] 
-               - fP[3]*fP[3] - fP[4]*fP[4] - fP[5]*fP[5] ); 
 
-  Double_t zeta = Mass*Mass - m2;
-  for(Int_t i=0;i<8;++i) zeta -= mH[i]*(fP[i]-fP[i]);
+  Double_t zeta = e0*e0 - e0*fP[6];
+  zeta = m2 - (fP[6]*fP[6]-p2);
   
-  Double_t s = 0.;
-  Double_t mCHt[8];
-  for (Int_t i=0;i<8;++i ){
+  Double_t mCHt[8], s2_est=0;
+  for( Int_t i=0; i<8; ++i ){
     mCHt[i] = 0.0;
     for (Int_t j=0;j<8;++j) mCHt[i] += Cij(i,j)*mH[j];
-    s += mH[i]*mCHt[i];
+    s2_est += mH[i]*mCHt[i];
   }
   
-  if( s<1.e-20 ) return;
-  s = 1./s;
-  fChi2 += zeta*zeta*s;
+  if( s2_est<1.e-20 ) return; // calculated mass error is already 0, 
+                              // the particle can not be constrained on mass
+
+  Double_t w2 = 1./( s2 + s2_est );
+  fChi2 += zeta*zeta*w2;
   fNDF  += 1;
   for( Int_t i=0, ii=0; i<8; ++i ){
-    Double_t ki = mCHt[i]*s;
+    Double_t ki = mCHt[i]*w2;
     fP[i]+= ki*zeta;
     for(Int_t j=0;j<=i;++j) fC[ii++] -= ki*mCHt[j];    
   }
 }
 
 
+void AliKFParticleBase::SetNoDecayLength()
+{  
+  //* Set no decay length for resonances
+
+  TransportToDecayVertex();
+
+  Double_t h[8];
+  h[0] = h[1] = h[2] = h[3] = h[4] = h[5] = h[6] = 0;
+  h[7] = 1; 
+
+  Double_t zeta = 0 - fP[7];
+  for(Int_t i=0;i<8;++i) zeta -= h[i]*(fP[i]-fP[i]);
+  
+  Double_t s = fC[35];   
+  if( s>1.e-20 ){
+    s = 1./s;
+    fChi2 += zeta*zeta*s;
+    fNDF  += 1;
+    for( Int_t i=0, ii=0; i<7; ++i ){
+      Double_t ki = fC[28+i]*s;
+      fP[i]+= ki*zeta;
+      for(Int_t j=0;j<=i;++j) fC[ii++] -= ki*fC[28+j];    
+    }
+  }
+  fP[7] = 0;
+  fC[28] = fC[29] = fC[30] = fC[31] = fC[32] = fC[33] = fC[35] = fC[35] = 0;
+}
+
+
 void AliKFParticleBase::Construct( const AliKFParticleBase* vDaughters[], Int_t NDaughters,
-                                  const AliKFParticleBase *Parent,  Double_t Mass         )
+                                  const AliKFParticleBase *Parent,  Double_t Mass, Bool_t IsConstrained         )
 { 
   //* Full reconstruction in one go
 
   Int_t maxIter = 1;
   bool wasLinearized = fIsLinearized;
-  if( !fIsLinearized ){
-    fVtxGuess[0] = fVtxGuess[1] = fVtxGuess[2] = 0; 
+  if( !fIsLinearized || IsConstrained ){
+    //fVtxGuess[0] = fVtxGuess[1] = fVtxGuess[2] = 0;  //!!!!
+    fVtxGuess[0] = GetX();
+    fVtxGuess[1] = GetY();
+    fVtxGuess[2] = GetZ();
     fIsLinearized = 1;
     maxIter = 3;
   }
 
+  Double_t constraintC[6];
+
+  if( IsConstrained ){
+    for(Int_t i=0;i<6;++i) constraintC[i]=fC[i];
+  } else {
+    for(Int_t i=0;i<6;++i) constraintC[i]=0.;
+    constraintC[0] = constraintC[2] = constraintC[5] = 100.;    
+  }
+
+
   for( Int_t iter=0; iter<maxIter; iter++ ){
     fAtProductionVertex = 0;
     fSFromDecay = 0;
@@ -600,13 +787,12 @@ void AliKFParticleBase::Construct( const AliKFParticleBase* vDaughters[], Int_t
     fP[5] = 0;
     fP[6] = 0;
     fP[7] = 0;
-  
-    for(Int_t i=0;i<36;++i) fC[i]=0.;
-
-    fC[0] = fC[2] = fC[5] = 100.;
+   
+    for(Int_t i=0;i<6; ++i) fC[i]=constraintC[i];
+    for(Int_t i=6;i<36;++i) fC[i]=0.;
     fC[35] = 1.;
     
-    fNDF  = -3;
+    fNDF  = IsConstrained ?0 :-3;
     fChi2 =  0.;
     fQ = 0;
 
@@ -709,7 +895,7 @@ void AliKFParticleBase::TransportToDecayVertex()
 void AliKFParticleBase::TransportToProductionVertex()
 {
   //* Transport the particle to its production vertex 
-
+  
   if( fSFromDecay != -fP[7] ) TransportToDS( -fSFromDecay-fP[7] );
   if( !fAtProductionVertex ) Convert( 1 );
   fAtProductionVertex = 1;
@@ -719,7 +905,7 @@ void AliKFParticleBase::TransportToProductionVertex()
 void AliKFParticleBase::TransportToDS( Double_t dS )
 { 
   //* Transport the particle on dS parameter (SignedPath/Momentum) 
-
   Transport( dS, fP, fC );
   fSFromDecay+= dS;
 }
@@ -738,6 +924,7 @@ Double_t AliKFParticleBase::GetDStoPointLine( const Double_t xyz[] ) const
 Double_t AliKFParticleBase::GetDStoPointBz( Double_t B, const Double_t xyz[] ) 
   const
 { 
+  
   //* Get dS to a certain space point for Bz field
   const Double_t kCLight = 0.000299792458;
   Double_t bq = B*fQ*kCLight;
@@ -746,13 +933,70 @@ Double_t AliKFParticleBase::GetDStoPointBz( Double_t B, const Double_t xyz[] )
   Double_t dx = xyz[0] - fP[0];
   Double_t dy = xyz[1] - fP[1]; 
   Double_t a = dx*fP[3]+dy*fP[4];
-  if( TMath::Abs(bq)<1.e-8 ) return a/pt2;
-  return  TMath::ATan2( bq*a, pt2 + bq*(dy*fP[3] -dx*fP[4]) )/bq;
+  Double_t dS;
+
+  if( TMath::Abs(bq)<1.e-8 ) dS = a/pt2;  
+  else dS =  TMath::ATan2( bq*a, pt2 + bq*(dy*fP[3] -dx*fP[4]) )/bq;
+
+  if(0){
+
+    Double_t px = fP[3];
+    Double_t py = fP[4];
+    Double_t pz = fP[5];
+    Double_t ss[2], g[2][5];
+  
+    ss[0] = dS;
+    ss[1] = -dS;
+    for( Int_t i=0; i<2; i++){
+      Double_t bs = bq*ss[i];
+      Double_t c = TMath::Cos(bs), s = TMath::Sin(bs);
+      Double_t cB,sB;
+      if( TMath::Abs(bq)>1.e-8){
+       cB= (1-c)/bq;     
+       sB= s/bq;  
+      }else{
+       sB = (1. - bs*bs/6.)*ss[i];
+       cB = .5*sB*bs;
+      }
+      g[i][0] = fP[0] + sB*px + cB*py;
+      g[i][1] = fP[1] - cB*px + sB*py;
+      g[i][2] = fP[2] + ss[i]*pz;
+      g[i][3] =       + c*px + s*py;
+      g[i][4] =       - s*px + c*py;      
+    }
+
+    Int_t i=0;
+  
+    Double_t dMin = 1.e10;
+    for( Int_t j=0; j<2; j++){
+      Double_t xx = g[j][0]-xyz[0];
+      Double_t yy = g[j][1]-xyz[1];
+      Double_t zz = g[j][2]-xyz[2];
+      Double_t d = xx*xx + yy*yy + zz*zz;
+      if( d<dMin ){
+       dMin = d;
+       i = j;
+      }
+    }
+
+    dS = ss[i];
+
+    Double_t x= g[i][0], y= g[i][1], z= g[i][2], ppx= g[i][3], ppy= g[i][4];      
+    Double_t ddx = x-xyz[0];
+    Double_t ddy = y-xyz[1];
+    Double_t ddz = z-xyz[2];
+    Double_t c = ddx*ppx  + ddy*ppy  + ddz*pz ;
+    Double_t pp2 = ppx*ppx + ppy*ppy + pz*pz;    
+    if( TMath::Abs(pp2)>1.e-8 ){
+      dS+=c/pp2;
+    }
+  }
+  return dS;
 }
 
 
 void AliKFParticleBase::GetDStoParticleBz( Double_t B, const AliKFParticleBase &p, 
-                                   Double_t &DS, Double_t &DS1 ) 
+                                          Double_t &DS, Double_t &DS1 ) 
   const
 { 
   //* Get dS to another particle for Bz field
@@ -794,6 +1038,7 @@ void AliKFParticleBase::GetDStoParticleBz( Double_t B, const AliKFParticleBase &
   
     Double_t sa = 4*l2*p2 - ca*ca;
     Double_t sa1 = 4*l2*p21 - ca1*ca1;
+
     if(sa<0) sa=0;
     if(sa1<0)sa1=0;
 
@@ -826,11 +1071,11 @@ void AliKFParticleBase::GetDStoParticleBz( Double_t B, const AliKFParticleBase &
   ss1[1] = s1 - ds1;
   for( Int_t i=0; i<2; i++){
     Double_t bs = bq*ss[i];
-    Double_t c = TMath::Cos(bs), s = TMath::Sin(bs);
+    Double_t c = TMath::Cos(bs), sss = TMath::Sin(bs);
     Double_t cB,sB;
     if( TMath::Abs(bq)>1.e-8){
       cB= (1-c)/bq;     
-      sB= s/bq;  
+      sB= sss/bq;  
     }else{
       sB = (1. - bs*bs/6.)*ss[i];
       cB = .5*sB*bs;
@@ -838,24 +1083,24 @@ void AliKFParticleBase::GetDStoParticleBz( Double_t B, const AliKFParticleBase &
     g[i][0] = fP[0] + sB*px + cB*py;
     g[i][1] = fP[1] - cB*px + sB*py;
     g[i][2] = fP[2] + ss[i]*pz;
-    g[i][3] =       + c*px + s*py;
-    g[i][4] =       - s*px + c*py;
+    g[i][3] =       + c*px + sss*py;
+    g[i][4] =       - sss*px + c*py;
 
     bs = bq1*ss1[i];  
-    c =  TMath::Cos(bs); s = TMath::Sin(bs);
+    c =  TMath::Cos(bs); sss = TMath::Sin(bs);
     if( TMath::Abs(bq1)>1.e-8){
       cB= (1-c)/bq1;   
-      sB= s/bq1;  
+      sB= sss/bq1;  
     }else{
       sB = (1. - bs*bs/6.)*ss1[i];
       cB = .5*sB*bs;
     }
       
-    g[i][0] = p.fP[0] + sB*px1 + cB*py1;
-    g[i][1] = p.fP[1] - cB*px1 + sB*py1;
-    g[i][2] = p.fP[2] + ss[i]*pz1;
-    g[i][3] =         + c*px1 + s*py1;
-    g[i][4] =         - s*px1 + c*py1;
+    g1[i][0] = p.fP[0] + sB*px1 + cB*py1;
+    g1[i][1] = p.fP[1] - cB*px1 + sB*py1;
+    g1[i][2] = p.fP[2] + ss[i]*pz1;
+    g1[i][3] =         + c*px1 + sss*py1;
+    g1[i][4] =         - sss*px1 + c*py1;
   }
 
   Int_t i=0, i1=0;
@@ -877,21 +1122,22 @@ void AliKFParticleBase::GetDStoParticleBz( Double_t B, const AliKFParticleBase &
 
   DS = ss[i];
   DS1 = ss1[i1];
-
-  Double_t x= g[i][0], y= g[i][1], z= g[i][2], ppx= g[i][3], ppy= g[i][4];  
-  Double_t x1=g[i1][0], y1= g[i1][1], z1= g[i1][2], ppx1= g[i1][3], ppy1= g[i1][4];  
-  Double_t dx = x1-x;
-  Double_t dy = y1-y;
-  Double_t dz = z1-z;
-  Double_t a = ppx*ppx1 + ppy*ppy1 + pz*pz1;
-  Double_t b = dx*ppx1 + dy*ppy1 + dz*pz1;
-  Double_t c = dx*ppx  + dy*ppy  + dz*pz ;
-  Double_t pp2 = ppx*ppx + ppy*ppy + pz*pz;
-  Double_t pp21= ppx1*ppx1 + ppy1*ppy1 + pz1*pz1;
-  Double_t det = pp2*pp21 - a*a;
-  if( TMath::Abs(det)>1.e-8 ){
-    DS+=(a*b-pp21*c)/det;
-    DS1+=(a*c-pp2*b)/det;
+  if(0){
+    Double_t x= g[i][0], y= g[i][1], z= g[i][2], ppx= g[i][3], ppy= g[i][4];  
+    Double_t x1=g1[i1][0], y1= g1[i1][1], z1= g1[i1][2], ppx1= g1[i1][3], ppy1= g1[i1][4];  
+    Double_t dx = x1-x;
+    Double_t dy = y1-y;
+    Double_t dz = z1-z;
+    Double_t a = ppx*ppx1 + ppy*ppy1 + pz*pz1;
+    Double_t b = dx*ppx1 + dy*ppy1 + dz*pz1;
+    Double_t c = dx*ppx  + dy*ppy  + dz*pz ;
+    Double_t pp2 = ppx*ppx + ppy*ppy + pz*pz;
+    Double_t pp21= ppx1*ppx1 + ppy1*ppy1 + pz1*pz1;
+    Double_t det = pp2*pp21 - a*a;    
+    if( TMath::Abs(det)>1.e-8 ){
+      DS+=(a*b-pp21*c)/det;
+      DS1+=(a*c-pp2*b)/det;
+    }
   }
 }
 
@@ -1024,21 +1270,21 @@ void AliKFParticleBase::TransportCBM( Double_t dS,
 }
 
 
-void AliKFParticleBase::TransportBz( Double_t B, Double_t S,
-                                      Double_t P[], Double_t C[] ) const 
+void AliKFParticleBase::TransportBz( Double_t b, Double_t ss,
+                                    Double_t p[], Double_t cc[] ) const 
 { 
   //* Transport the particle on dS, output to P[],C[], for Bz field
-
   const Double_t kCLight = 0.000299792458;
-  B = B*fQ*kCLight;
-  Double_t bs= B*S;
+  b = b*fQ*kCLight;
+  Double_t bs= b*ss;
   Double_t s = TMath::Sin(bs), c = TMath::Cos(bs);
   Double_t sB, cB;
-  if( TMath::Abs(bs)>1.e-8){
-    sB= s/B;
-    cB= (1-c)/B;
+  if( TMath::Abs(bs)>1.e-10){
+    sB= s/b;
+    cB= (1-c)/b;
   }else{
-    sB = (1. - bs*bs/6.)*S;
+    sB = (1. - bs*bs/6.)*ss;
     cB = .5*sB*bs;
   }
   
@@ -1046,23 +1292,23 @@ void AliKFParticleBase::TransportBz( Double_t B, Double_t S,
   Double_t py = fP[4];
   Double_t pz = fP[5];
   
-  P[0] = fP[0] + sB*px + cB*py;
-  P[1] = fP[1] - cB*px + sB*py;
-  P[2] = fP[2] +  S*pz;
-  P[3] =          c*px + s*py;
-  P[4] =         -s*px + c*py;
-  P[5] = fP[5];
-  P[6] = fP[6];
-  P[7] = fP[7];
+  p[0] = fP[0] + sB*px + cB*py;
+  p[1] = fP[1] - cB*px + sB*py;
+  p[2] = fP[2] +  ss*pz;
+  p[3] =          c*px + s*py;
+  p[4] =         -s*px + c*py;
+  p[5] = fP[5];
+  p[6] = fP[6];
+  p[7] = fP[7];
  
   Double_t mJ[8][8] = { {1,0,0,   sB, cB,  0, 0, 0 },
-                      {0,1,0,  -cB, sB,  0, 0, 0 },
-                      {0,0,1,    0,  0,  S, 0, 0 },
-                      {0,0,0,    c,  s,  0, 0, 0 },
-                      {0,0,0,   -s,  c,  0, 0, 0 },
-                      {0,0,0,    0,  0,  1, 0, 0 },
-                      {0,0,0,    0,  0,  0, 1, 0 },
-                      {0,0,0,    0,  0,  0, 0, 1 }  };
+                       {0,1,0,  -cB, sB,  0, 0, 0 },
+                       {0,0,1,    0,  0, ss, 0, 0 },
+                       {0,0,0,    c,  s,  0, 0, 0 },
+                       {0,0,0,   -s,  c,  0, 0, 0 },
+                       {0,0,0,    0,  0,  1, 0, 0 },
+                       {0,0,0,    0,  0,  0, 1, 0 },
+                       {0,0,0,    0,  0,  0, 0, 1 }  };
   Double_t mA[8][8];
   for( Int_t k=0,i=0; i<8; i++)
     for( Int_t j=0; j<=i; j++, k++ ) mA[i][j] = mA[j][i] = fC[k]; 
@@ -1076,8 +1322,8 @@ void AliKFParticleBase::TransportBz( Double_t B, Double_t S,
   
   for( Int_t k=0,i=0; i<8; i++)
     for( Int_t j=0; j<=i; j++, k++ ){
-      C[k] = 0;
-      for( Int_t l=0; l<8; l++ ) C[k]+=mJC[i][l]*mJ[j][l];
+      cc[k] = 0;
+      for( Int_t l=0; l<8; l++ ) cc[k]+=mJC[i][l]*mJ[j][l];
     }
   
   return;
@@ -1141,17 +1387,16 @@ Double_t AliKFParticleBase::GetDistanceFromVertex( const Double_t vtx[] ) const
   return TMath::Sqrt( d[0]*d[0]+d[1]*d[1]+d[2]*d[2] );
 }
 
-Double_t AliKFParticleBase::GetDistanceFromParticleBz( Double_t B, 
-                                               const AliKFParticleBase &p ) 
+Double_t AliKFParticleBase::GetDistanceFromParticle( const AliKFParticleBase &p ) 
   const
 { 
-  //* Calculate distance other particle [cm] for Bz field
+  //* Calculate distance to other particle [cm]
 
   Double_t dS, dS1;
-  GetDStoParticleBz( B, p, dS, dS1 );   
+  GetDStoParticle( p, dS, dS1 );   
   Double_t mP[8], mC[36], mP1[8], mC1[36];
-  TransportBz( B, dS, mP, mC ); 
-  p.TransportBz( B, dS1, mP1, mC1 ); 
+  Transport( dS, mP, mC ); 
+  p.Transport( dS1, mP1, mC1 ); 
   Double_t dx = mP[0]-mP1[0]; 
   Double_t dy = mP[1]-mP1[1]; 
   Double_t dz = mP[2]-mP1[2]; 
@@ -1216,21 +1461,20 @@ Double_t AliKFParticleBase::GetDeviationFromVertex( const Double_t v[], const Do
 }
 
 
-Double_t AliKFParticleBase::GetDeviationFromParticleBz( Double_t B, 
-                                                const AliKFParticleBase &p ) 
+Double_t AliKFParticleBase::GetDeviationFromParticle( const AliKFParticleBase &p ) 
   const
 { 
-  //* Calculate sqrt(Chi2/ndf) deviation from other particle, for Bz field
+  //* Calculate sqrt(Chi2/ndf) deviation from other particle
 
   Double_t dS, dS1;
-  GetDStoParticleBz( B, p, dS, dS1 );   
+  GetDStoParticle( p, dS, dS1 );   
   Double_t mP1[8], mC1[36];
-  p.TransportBz( B, dS1, mP1, mC1 ); 
+  p.Transport( dS1, mP1, mC1 ); 
 
   Double_t d[3]={ fP[0]-mP1[0], fP[1]-mP1[1], fP[2]-mP1[2]};
 
   Double_t sigmaS = .1+10.*TMath::Sqrt( (d[0]*d[0]+d[1]*d[1]+d[2]*d[2])/
-                                (mP1[3]*mP1[3]+mP1[4]*mP1[4]+mP1[5]*mP1[5])  );
+                                       (mP1[3]*mP1[3]+mP1[4]*mP1[4]+mP1[5]*mP1[5])  );
 
   Double_t h[3] = { mP1[3]*sigmaS, mP1[4]*sigmaS, mP1[5]*sigmaS };