]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliESDtrack.cxx
just Fixing Log info
[u/mrichter/AliRoot.git] / STEER / AliESDtrack.cxx
index de33b519e3ab9443192e8848ca112699e6c03693..d04ebff5c6e32393a5a8ce2b328b0cf98098759f 100644 (file)
 
 #include "TMath.h"
 
+#include "AliESDVertex.h"
 #include "AliESDtrack.h"
 #include "AliKalmanTrack.h"
+#include "AliTrackPointArray.h"
 #include "AliLog.h"
 
 ClassImp(AliESDtrack)
 
+void SetPIDValues(Float_t * dest, const Double_t * src, Int_t n) {
+  // This function copies "n" PID weights from "scr" to "dest"
+  // and normalizes their sum to 1 thus producing conditional probabilities.
+  // The negative weights are set to 0.
+  // In case all the weights are non-positive they are replaced by
+  // uniform probabilities
+
+  if (n<=0) return;
+
+  Float_t uniform = 1./(Float_t)n;
+
+  Float_t sum = 0;
+  for (Int_t i=0; i<n; i++) 
+    if (src[i]>=0) {
+      sum+=src[i];
+      dest[i] = src[i];
+    }
+    else {
+      dest[i] = 0;
+    }
+
+  if(sum>0)
+    for (Int_t i=0; i<n; i++) dest[i] /= sum;
+  else
+    for (Int_t i=0; i<n; i++) dest[i] = uniform;
+}
+
 //_______________________________________________________________________
 AliESDtrack::AliESDtrack() : 
-  TObject(),
+  AliExternalTrackParam(),
   fFlags(0),
   fLabel(0),
   fID(0),
   fTrackLength(0),
-  fD(0),
-  fZ(0),
+  fD(0),fZ(0),
+  fCdd(0),fCdz(0),fCzz(0),
   fStopVertex(0),
-  fRalpha(0),
-  fRx(0),
-  fCalpha(0),
-  fCx(0),
+  fCp(0),
   fCchi2(1e10),
-  fIalpha(0),
-  fIx(0),
-  fTalpha(0),
-  fTx(0),
+  fIp(0),
+  fOp(0),
   fITSchi2(0),
   fITSncls(0),
   fITSsignal(0),
@@ -64,6 +88,7 @@ AliESDtrack::AliESDtrack() :
   fTRDsignal(0),
   fTRDLabel(0),
   fTRDQuality(0),
+  fTRDBudget(0),
   fTRDtrack(0),
   fTOFchi2(0),
   fTOFindex(0),
@@ -77,7 +102,8 @@ AliESDtrack::AliESDtrack() :
   fRICHtheta(0),
   fRICHphi(0),
   fRICHdx(0),
-  fRICHdy(0)
+  fRICHdy(0),
+  fPoints(0)
 {
   //
   // The default ESD constructor 
@@ -101,24 +127,20 @@ AliESDtrack::AliESDtrack() :
   fPHOSpos[0]=fPHOSpos[1]=fPHOSpos[2]=0.;
   fEMCALpos[0]=fEMCALpos[1]=fEMCALpos[2]=0.;
   Int_t i;
-  for (i=0; i<5; i++)  { 
-    fRp[i]=fCp[i]=fIp[i]=fTp[i]=0.;
-  }
-  for (i=0; i<15; i++) { 
-    fRc[i]=fCc[i]=fIc[i]=fTc[i]=0.;  
-  }
+  for (i=0;i<12;i++) fITSchi2MIP[i] =1e10;
   for (i=0; i<6; i++)  { fITSindex[i]=0; }
   for (i=0; i<180; i++){ fTPCindex[i]=0; }
   for (i=0; i<3;i++)   { fKinkIndexes[i]=0;}
   for (i=0; i<3;i++)   { fV0Indexes[i]=-1;}
   for (i=0; i<130; i++) { fTRDindex[i]=0; }
   for (i=0;i<kNPlane;i++) {fTRDsignals[i]=0.; fTRDTimBin[i]=-1;}
-  for (Int_t i=0;i<4;i++) {fTPCPoints[i]=-1;}
-  for (Int_t i=0;i<3;i++) {fTOFLabel[i]=-1;}
-  for (Int_t i=0;i<10;i++) {fTOFInfo[i]=-1;}
+  for (i=0;i<4;i++) {fTPCPoints[i]=-1;}
+  for (i=0;i<3;i++) {fTOFLabel[i]=-1;}
+  for (i=0;i<10;i++) {fTOFInfo[i]=-1;}
   fTPCLabel = 0;
   fTRDLabel = 0;
   fTRDQuality =0;
+  fTRDBudget =0;
   fITSLabel = 0;
   fITStrack = 0;
   fTRDtrack = 0;  
@@ -126,23 +148,18 @@ AliESDtrack::AliESDtrack() :
 
 //_______________________________________________________________________
 AliESDtrack::AliESDtrack(const AliESDtrack& track):
-  TObject(track),
+  AliExternalTrackParam(track),
   fFlags(track.fFlags),
   fLabel(track.fLabel),
   fID(track.fID),
   fTrackLength(track.fTrackLength),
-  fD(track.fD),
-  fZ(track.fZ),
+  fD(track.fD),fZ(track.fZ),
+  fCdd(track.fCdd),fCdz(track.fCdz),fCzz(track.fCzz),
   fStopVertex(track.fStopVertex),
-  fRalpha(track.fRalpha),
-  fRx(track.fRx),
-  fCalpha(track.fCalpha),
-  fCx(track.fCx),
+  fCp(0),
   fCchi2(track.fCchi2),
-  fIalpha(track.fIalpha),
-  fIx(track.fIx),
-  fTalpha(track.fTalpha),
-  fTx(track.fTx),
+  fIp(0),
+  fOp(0),
   fITSchi2(track.fITSchi2),
   fITSncls(track.fITSncls),
   fITSsignal(track.fITSsignal),
@@ -160,6 +177,7 @@ AliESDtrack::AliESDtrack(const AliESDtrack& track):
   fTRDsignal(track.fTRDsignal),
   fTRDLabel(track.fTRDLabel),
   fTRDQuality(track.fTRDQuality),
+  fTRDBudget(track.fTRDBudget),
   fTRDtrack(0),
   fTOFchi2(track.fTOFchi2),
   fTOFindex(track.fTOFindex),
@@ -173,7 +191,8 @@ AliESDtrack::AliESDtrack(const AliESDtrack& track):
   fRICHtheta(track.fRICHtheta),
   fRICHphi(track.fRICHphi),
   fRICHdx(track.fRICHdx),
-  fRICHdy(track.fRICHdy)
+  fRICHdy(track.fRICHdy),
+  fPoints(track.fPoints)
 {
   //
   //copy constructor
@@ -181,18 +200,6 @@ AliESDtrack::AliESDtrack(const AliESDtrack& track):
   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i] =track.fTrackTime[i];
   for (Int_t i=0;i<AliPID::kSPECIES;i++)  fR[i] =track.fR[i];
   //
-  for (Int_t i=0;i<5;i++) fRp[i] =track.fRp[i];
-  for (Int_t i=0;i<15;i++) fRc[i] =track.fRc[i];
-  //
-  for (Int_t i=0;i<5;i++) fCp[i] =track.fCp[i];
-  for (Int_t i=0;i<15;i++)  fCc[i] =track.fCc[i];
-  //
-  for (Int_t i=0;i<5;i++) fIp[i] =track.fIp[i];
-  for (Int_t i=0;i<15;i++)  fIc[i] =track.fIc[i];
-  //
-  for (Int_t i=0;i<5;i++) fTp[i] =track.fTp[i];
-  for (Int_t i=0;i<15;i++)  fTc[i] =track.fTc[i];
-  //
   for (Int_t i=0;i<12;i++) fITSchi2MIP[i] =track.fITSchi2MIP[i];
   for (Int_t i=0;i<6;i++) fITSindex[i]=track.fITSindex[i];    
   for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=track.fITSr[i]; 
@@ -221,6 +228,10 @@ AliESDtrack::AliESDtrack(const AliESDtrack& track):
   for (Int_t i=0;i<AliPID::kSPECIESN;i++) fEMCALr[i]=track.fEMCALr[i]; 
   //
   for (Int_t i=0;i<AliPID::kSPECIES;i++) fRICHr[i]=track.fRICHr[i];
+
+  if (track.fCp) fCp=new AliExternalTrackParam(*track.fCp);
+  if (track.fIp) fIp=new AliExternalTrackParam(*track.fIp);
+  if (track.fOp) fOp=new AliExternalTrackParam(*track.fOp);
 }
 //_______________________________________________________________________
 AliESDtrack::~AliESDtrack(){ 
@@ -228,8 +239,12 @@ AliESDtrack::~AliESDtrack(){
   // This is destructor according Coding Conventrions 
   //
   //printf("Delete track\n");
+  delete fIp; 
+  delete fOp;
+  delete fCp; 
   delete fITStrack;
-  delete fTRDtrack;  
+  delete fTRDtrack; 
+  delete fPoints;
 }
 
 //_______________________________________________________________________
@@ -252,23 +267,14 @@ void AliESDtrack::MakeMiniESDtrack(){
   fStopVertex = 0;
 
   // Reset track parameters constrained to the primary vertex
-  fCalpha = 0;
-  fCx = 0;
-  for (Int_t i=0;i<5;i++) fCp[i] = 0;
-  for (Int_t i=0;i<15;i++)  fCc[i] = 0;
+  fCp = 0;
   fCchi2 = 0;
 
   // Reset track parameters at the inner wall of TPC
-  fIalpha = 0;
-  fIx = 0;
-  for (Int_t i=0;i<5;i++) fIp[i] = 0;
-  for (Int_t i=0;i<15;i++)  fIc[i] = 0;
+  fIp = 0;
 
   // Reset track parameters at the inner wall of the TRD
-  fTalpha = 0;
-  fTx = 0;
-  for (Int_t i=0;i<5;i++) fTp[i] = 0;
-  for (Int_t i=0;i<15;i++)  fTc[i] = 0;
+  fOp = 0;
 
   // Reset ITS track related information
   fITSchi2 = 0;
@@ -307,6 +313,7 @@ void AliESDtrack::MakeMiniESDtrack(){
   fTRDLabel = 0;       
   fTRDtrack = 0; 
   fTRDQuality  = 0;
+  fTRDBudget  = 0;
 
   // Reset TOF related track information
   fTOFchi2 = 0;        
@@ -337,6 +344,7 @@ void AliESDtrack::MakeMiniESDtrack(){
   fRICHdx = 0;     
   fRICHdy = 0;      
 
+  fPoints = 0;
 } 
 //_______________________________________________________________________
 Double_t AliESDtrack::GetMass() const {
@@ -363,7 +371,7 @@ Double_t AliESDtrack::GetMass() const {
 }
 
 //_______________________________________________________________________
-Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags) {
+Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags){
   //
   // This function updates track's running parameters 
   //
@@ -378,9 +386,7 @@ Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags) {
     SetIntegratedLength(t->GetIntegratedLength());
   }
 
-  fRalpha=t->GetAlpha();
-  t->GetExternalParameters(fRx,fRp);
-  t->GetExternalCovariance(fRc);
+  Set(*t);
 
   switch (flags) {
     
@@ -395,13 +401,9 @@ Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags) {
     
   case kTPCin: case kTPCrefit:
     fTPCLabel = t->GetLabel();
-    fIalpha=fRalpha;
-    fIx=fRx;    
-    {
-      Int_t i;
-      for (i=0; i<5; i++) fIp[i]=fRp[i];
-      for (i=0; i<15;i++) fIc[i]=fRc[i];
-    }
+    if (!fIp) fIp=new AliExternalTrackParam(*t);
+    else fIp->Set(*t);
+
   case kTPCout:
   
     fTPCncls=t->GetNumberOfClusters();
@@ -472,9 +474,8 @@ Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags) {
     fTRDsignal=t->GetPIDsignal();
     break;
   case kTRDbackup:
-    t->GetExternalParameters(fTx,fTp);
-    t->GetExternalCovariance(fTc);
-    fTalpha = t->GetAlpha();
+    if (!fOp) fOp=new AliExternalTrackParam(*t);
+    else fOp->Set(*t);
     fTRDncls0 = t->GetNumberOfClusters(); 
     break;
   case kTOFin: 
@@ -491,51 +492,13 @@ Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags) {
   return rc;
 }
 
-//_______________________________________________________________________
-void 
-AliESDtrack::SetConstrainedTrackParams(const AliKalmanTrack *t, Double_t chi2) {
-  //
-  // This function sets the constrained track parameters 
-  //
-  Int_t i;
-  Double_t x,buf[15];
-  fCalpha=t->GetAlpha();
-  t->GetExternalParameters(x,buf); fCx=x;
-  for (i=0; i<5; i++) fCp[i]=buf[i];
-  t->GetExternalCovariance(buf);
-  for (i=0; i<15; i++) fCc[i]=buf[i];
-  fCchi2=chi2;
-}
-
-
 //_______________________________________________________________________
 void AliESDtrack::GetExternalParameters(Double_t &x, Double_t p[5]) const {
   //---------------------------------------------------------------------
   // This function returns external representation of the track parameters
   //---------------------------------------------------------------------
-  x=fRx;
-  for (Int_t i=0; i<5; i++) p[i]=fRp[i];
-}
-
-//_______________________________________________________________________
-Bool_t AliESDtrack::GetExternalParametersAt(Double_t x, Double_t p[5]) const {
-  //---------------------------------------------------------------------
-  // This function returns external representation of the track parameters
-  // at the position given by the first argument 
-  //---------------------------------------------------------------------
-  Double_t dx=x-fRx;
-  Double_t f1=fRp[2], f2=f1 + dx*fRp[4]/AliKalmanTrack::GetConvConst();
-
-  if (TMath::Abs(f2) >= 0.9999) return kFALSE;
-  
-  Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
-  p[0] = fRp[0] + dx*(f1+f2)/(r1+r2);
-  p[1] = fRp[1] + dx*(f1+f2)/(f1*r2 + f2*r1)*fRp[3];
-  p[2] = f2;
-  p[3] = fRp[3];
-  p[4] = fRp[4];
-
-  return kTRUE;
+  x=GetX();
+  for (Int_t i=0; i<5; i++) p[i]=GetParameter()[i];
 }
 
 //_______________________________________________________________________
@@ -543,247 +506,133 @@ void AliESDtrack::GetExternalCovariance(Double_t cov[15]) const {
   //---------------------------------------------------------------------
   // This function returns external representation of the cov. matrix
   //---------------------------------------------------------------------
-  for (Int_t i=0; i<15; i++) cov[i]=fRc[i];
+  for (Int_t i=0; i<15; i++) cov[i]=AliExternalTrackParam::GetCovariance()[i];
 }
 
-
 //_______________________________________________________________________
-void 
-AliESDtrack::GetConstrainedExternalParameters(Double_t &x, Double_t p[5])const{
+Bool_t AliESDtrack::GetConstrainedExternalParameters
+                 (Double_t &alpha, Double_t &x, Double_t p[5]) const {
   //---------------------------------------------------------------------
   // This function returns the constrained external track parameters
   //---------------------------------------------------------------------
-  x=fCx;
-  for (Int_t i=0; i<5; i++) p[i]=fCp[i];
+  if (!fCp) return kFALSE;
+  alpha=fCp->GetAlpha();
+  x=fCp->GetX();
+  for (Int_t i=0; i<5; i++) p[i]=fCp->GetParameter()[i];
+  return kTRUE;
 }
+
 //_______________________________________________________________________
-void 
+Bool_t 
 AliESDtrack::GetConstrainedExternalCovariance(Double_t c[15]) const {
   //---------------------------------------------------------------------
   // This function returns the constrained external cov. matrix
   //---------------------------------------------------------------------
-  for (Int_t i=0; i<15; i++) c[i]=fCc[i];
+  if (!fCp) return kFALSE;
+  for (Int_t i=0; i<15; i++) c[i]=fCp->GetCovariance()[i];
+  return kTRUE;
 }
 
-
-Double_t AliESDtrack::GetP() const {
+Bool_t
+AliESDtrack::GetInnerExternalParameters
+                 (Double_t &alpha, Double_t &x, Double_t p[5]) const {
   //---------------------------------------------------------------------
-  // This function returns the track momentum
-  // Results for (nearly) straight tracks are meaningless !
+  // This function returns external representation of the track parameters 
+  // at the inner layer of TPC
   //---------------------------------------------------------------------
-  if (TMath::Abs(fRp[4])<=0) return 0;
-  Double_t pt=1./TMath::Abs(fRp[4]);
-  return pt*TMath::Sqrt(1.+ fRp[3]*fRp[3]);
-}
-
-Bool_t Local2GlobalMomentum(Double_t p[3],Double_t alpha) {
-  //----------------------------------------------------------------
-  // This function performs local->global transformation of the
-  // track momentum.
-  // When called, the arguments are:
-  //    p[0] = 1/pt of the track;
-  //    p[1] = sine of local azim. angle of the track momentum;
-  //    p[2] = tangent of the track momentum dip angle;
-  //   alpha - rotation angle. 
-  // The result is returned as:
-  //    p[0] = px
-  //    p[1] = py
-  //    p[2] = pz
-  // Results for (nearly) straight tracks are meaningless !
-  //----------------------------------------------------------------
-  if (TMath::Abs(p[0])<=0)        return kFALSE;
-  if (TMath::Abs(p[1])> 0.999999) return kFALSE;
-
-  Double_t pt=1./TMath::Abs(p[0]);
-  Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha);
-  Double_t r=TMath::Sqrt(1 - p[1]*p[1]);
-  p[0]=pt*(r*cs - p[1]*sn); p[1]=pt*(p[1]*cs + r*sn); p[2]=pt*p[2];
-
+  if (!fIp) return kFALSE;
+  alpha=fIp->GetAlpha();
+  x=fIp->GetX();
+  for (Int_t i=0; i<5; i++) p[i]=fIp->GetParameter()[i];
   return kTRUE;
 }
 
-Bool_t Local2GlobalPosition(Double_t r[3],Double_t alpha) {
-  //----------------------------------------------------------------
-  // This function performs local->global transformation of the
-  // track position.
-  // When called, the arguments are:
-  //    r[0] = local x
-  //    r[1] = local y
-  //    r[2] = local z
-  //   alpha - rotation angle. 
-  // The result is returned as:
-  //    r[0] = global x
-  //    r[1] = global y
-  //    r[2] = global z
-  //----------------------------------------------------------------
-  Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha), x=r[0];
-  r[0]=x*cs - r[1]*sn; r[1]=x*sn + r[1]*cs;
-
+Bool_t 
+AliESDtrack::GetInnerExternalCovariance(Double_t cov[15]) const {
+ //---------------------------------------------------------------------
+ // This function returns external representation of the cov. matrix 
+ // at the inner layer of TPC
+ //---------------------------------------------------------------------
+  if (!fIp) return kFALSE;
+  for (Int_t i=0; i<15; i++) cov[i]=fIp->GetCovariance()[i];
   return kTRUE;
 }
 
-Bool_t AliESDtrack::GetConstrainedPxPyPz(Double_t *p) const {
-  //---------------------------------------------------------------------
-  // This function returns the constrained global track momentum components
-  // Results for (nearly) straight tracks are meaningless !
-  //---------------------------------------------------------------------
-  p[0]=fCp[4]; p[1]=fCp[2]; p[2]=fCp[3];
-  return Local2GlobalMomentum(p,fCalpha);
-}  
-
-Bool_t AliESDtrack::GetConstrainedXYZ(Double_t *r) const {
-  //---------------------------------------------------------------------
-  // This function returns the constrained global track position
-  //---------------------------------------------------------------------
-  r[0]=fCx; r[1]=fCp[0]; r[2]=fCp[1];
-  return Local2GlobalPosition(r,fCalpha);
-}
-
-Bool_t AliESDtrack::GetPxPyPz(Double_t *p) const {
-  //---------------------------------------------------------------------
-  // This function returns the global track momentum components
-  // Results for (nearly) straight tracks are meaningless !
-  //---------------------------------------------------------------------
-  p[0]=fRp[4]; p[1]=fRp[2]; p[2]=fRp[3];
-  return Local2GlobalMomentum(p,fRalpha);
-}
-
-Bool_t AliESDtrack::GetXYZ(Double_t *r) const {
-  //---------------------------------------------------------------------
-  // This function returns the global track position
-  //---------------------------------------------------------------------
-  r[0]=fRx; r[1]=fRp[0]; r[2]=fRp[1];
-  return Local2GlobalPosition(r,fRalpha);
-}
-
-void AliESDtrack::GetCovariance(Double_t cv[21]) const {
-  //---------------------------------------------------------------------
-  // This function returns the global covariance matrix of the track params
-  // 
-  // Cov(x,x) ... :   cv[0]
-  // Cov(y,x) ... :   cv[1]  cv[2]
-  // Cov(z,x) ... :   cv[3]  cv[4]  cv[5]
-  // Cov(px,x)... :   cv[6]  cv[7]  cv[8]  cv[9]
-  // Cov(py,x)... :   cv[10] cv[11] cv[12] cv[13] cv[14]
-  // Cov(pz,x)... :   cv[15] cv[16] cv[17] cv[18] cv[19] cv[20]
-  //
-  // Results for (nearly) straight tracks are meaningless !
-  //---------------------------------------------------------------------
-  if (TMath::Abs(fRp[4])<=0) {
-     for (Int_t i=0; i<21; i++) cv[i]=0.;
-     return;
-  }
-  if (TMath::Abs(fRp[2]) > 0.999999) {
-     for (Int_t i=0; i<21; i++) cv[i]=0.;
-     return;
-  }
-  Double_t pt=1./TMath::Abs(fRp[4]);
-  Double_t cs=TMath::Cos(fRalpha), sn=TMath::Sin(fRalpha);
-  Double_t r=TMath::Sqrt(1-fRp[2]*fRp[2]);
-
-  Double_t m00=-sn, m10=cs;
-  Double_t m23=-pt*(sn + fRp[2]*cs/r), m43=-pt*pt*(r*cs - fRp[2]*sn);
-  Double_t m24= pt*(cs - fRp[2]*sn/r), m44=-pt*pt*(r*sn + fRp[2]*cs);
-  Double_t m35=pt, m45=-pt*pt*fRp[3];
-
-  cv[0]=fRc[0]*m00*m00;
-  cv[1]=fRc[0]*m00*m10; 
-  cv[2]=fRc[0]*m10*m10;
-  cv[3]=fRc[1]*m00; 
-  cv[4]=fRc[1]*m10; 
-  cv[5]=fRc[2];
-  cv[6]=m00*(fRc[3]*m23+fRc[10]*m43); 
-  cv[7]=m10*(fRc[3]*m23+fRc[10]*m43); 
-  cv[8]=fRc[4]*m23+fRc[11]*m43; 
-  cv[9]=m23*(fRc[5]*m23+fRc[12]*m43)+m43*(fRc[12]*m23+fRc[14]*m43);
-  cv[10]=m00*(fRc[3]*m24+fRc[10]*m44); 
-  cv[11]=m10*(fRc[3]*m24+fRc[10]*m44); 
-  cv[12]=fRc[4]*m24+fRc[11]*m44; 
-  cv[13]=m23*(fRc[5]*m24+fRc[12]*m44)+m43*(fRc[12]*m24+fRc[14]*m44);
-  cv[14]=m24*(fRc[5]*m24+fRc[12]*m44)+m44*(fRc[12]*m24+fRc[14]*m44);
-  cv[15]=m00*(fRc[6]*m35+fRc[10]*m45); 
-  cv[16]=m10*(fRc[6]*m35+fRc[10]*m45); 
-  cv[17]=fRc[7]*m35+fRc[11]*m45; 
-  cv[18]=m23*(fRc[8]*m35+fRc[12]*m45)+m43*(fRc[13]*m35+fRc[14]*m45);
-  cv[19]=m24*(fRc[8]*m35+fRc[12]*m45)+m44*(fRc[13]*m35+fRc[14]*m45); 
-  cv[20]=m35*(fRc[9]*m35+fRc[13]*m45)+m45*(fRc[13]*m35+fRc[14]*m45);
-}
-
-Bool_t AliESDtrack::GetInnerPxPyPz(Double_t *p) const {
-  //---------------------------------------------------------------------
-  // This function returns the global track momentum components
-  // af the entrance of the TPC
-  //---------------------------------------------------------------------
-  p[0]=fIp[4]; p[1]=fIp[2]; p[2]=fIp[3];
-  return Local2GlobalMomentum(p,fIalpha);
-}
-
-Bool_t AliESDtrack::GetInnerXYZ(Double_t *r) const {
+Bool_t 
+AliESDtrack::GetOuterExternalParameters
+                 (Double_t &alpha, Double_t &x, Double_t p[5]) const {
   //---------------------------------------------------------------------
-  // This function returns the global track position
-  // af the entrance of the TPC
+  // This function returns external representation of the track parameters 
+  // at the inner layer of TRD
   //---------------------------------------------------------------------
-  if (fIx==0) return kFALSE;
-  r[0]=fIx; r[1]=fIp[0]; r[2]=fIp[1];
-  return Local2GlobalPosition(r,fIalpha);
+  if (!fOp) return kFALSE;
+  alpha=fOp->GetAlpha();
+  x=fOp->GetX();
+  for (Int_t i=0; i<5; i++) p[i]=fOp->GetParameter()[i];
+  return kTRUE;
 }
 
-void AliESDtrack::GetInnerExternalParameters(Double_t &x, Double_t p[5]) const 
-{
-  //skowron
- //---------------------------------------------------------------------
-  // This function returns external representation of the track parameters at Inner Layer of TPC
-  //---------------------------------------------------------------------
-  x=fIx;
-  for (Int_t i=0; i<5; i++) p[i]=fIp[i];
-}
-void AliESDtrack::GetInnerExternalCovariance(Double_t cov[15]) const
-{
- //skowron
+Bool_t 
+AliESDtrack::GetOuterExternalCovariance(Double_t cov[15]) const {
  //---------------------------------------------------------------------
- // This function returns external representation of the cov. matrix at Inner Layer of TPC
+ // This function returns external representation of the cov. matrix 
+ // at the inner layer of TRD
  //---------------------------------------------------------------------
- for (Int_t i=0; i<15; i++) cov[i]=fIc[i];
+  if (!fOp) return kFALSE;
+  for (Int_t i=0; i<15; i++) cov[i]=fOp->GetCovariance()[i];
+  return kTRUE;
 }
 
-void  AliESDtrack::GetTRDExternalParameters(Double_t &x, Double_t&alpha, Double_t p[5], Double_t cov[15]) const
+Int_t AliESDtrack::GetNcls(Int_t idet) const
 {
+  // Get number of clusters by subdetector index
   //
-  //this function returns TRD parameters
-  //
-  x=fTx;
-  alpha = fTalpha; 
-  for (Int_t i=0; i<5; i++) p[i]=fTp[i];
-  for (Int_t i=0; i<15; i++) cov[i]=fTc[i];
-}
-
-Bool_t AliESDtrack::GetPxPyPzAt(Double_t x,Double_t *p) const {
-  //---------------------------------------------------------------------
-  // This function returns the global track momentum components
-  // at the position "x" using the helix track approximation
-  //---------------------------------------------------------------------
-  p[0]=fRp[4]; 
-  p[1]=fRp[2]+(x-fRx)*fRp[4]/AliKalmanTrack::GetConvConst(); 
-  p[2]=fRp[3];
-  return Local2GlobalMomentum(p,fRalpha);
+  Int_t ncls = 0;
+  switch(idet){
+  case 0:
+    ncls = fITSncls;
+    break;
+  case 1:
+    ncls = fTPCncls;
+    break;
+  case 2:
+    ncls = fTRDncls;
+    break;
+  case 3:
+    if (fTOFindex != 0)
+      ncls = 1;
+    break;
+  default:
+    break;
+  }
+  return ncls;
 }
 
-Bool_t AliESDtrack::GetXYZAt(Double_t x, Double_t *r) const {
-  //---------------------------------------------------------------------
-  // This function returns the global track position
-  // af the radius "x" using the helix track approximation
-  //---------------------------------------------------------------------
-  Double_t dx=x-fRx;
-  Double_t f1=fRp[2], f2=f1 + dx*fRp[4]/AliKalmanTrack::GetConvConst();
-
-  if (TMath::Abs(f2) >= 0.9999) return kFALSE;
-  
-  Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
-  r[0] = x;
-  r[1] = fRp[0] + dx*(f1+f2)/(r1+r2);
-  r[2] = fRp[1] + dx*(f1+f2)/(f1*r2 + f2*r1)*fRp[3];
-  return Local2GlobalPosition(r,fRalpha);
+Int_t AliESDtrack::GetClusters(Int_t idet, UInt_t *idx) const
+{
+  // Get cluster index array by subdetector index
+  //
+  Int_t ncls = 0;
+  switch(idet){
+  case 0:
+    ncls = GetITSclusters(idx);
+    break;
+  case 1:
+    ncls = GetTPCclusters((Int_t *)idx);
+    break;
+  case 2:
+    ncls = GetTRDclusters(idx);
+    break;
+  case 3:
+    if (fTOFindex != 0) {
+      idx[0] = GetTOFcluster();
+      ncls = 1;
+    }
+    break;
+  default:
+    break;
+  }
+  return ncls;
 }
 
 //_______________________________________________________________________
@@ -801,7 +650,7 @@ void AliESDtrack::SetIntegratedTimes(const Double_t *times) {
 //_______________________________________________________________________
 void AliESDtrack::SetITSpid(const Double_t *p) {
   // Sets values for the probability of each particle type (in ITS)
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) fITSr[i]=p[i];
+  SetPIDValues(fITSr,p,AliPID::kSPECIES);
   SetStatus(AliESDtrack::kITSpid);
 }
 
@@ -850,25 +699,11 @@ Float_t AliESDtrack::GetTPCdensity(Int_t row0, Int_t row1) const{
   if (good>(row1-row0)*0.5) density = Float_t(found)/Float_t(good);
   return density;
 }
+
 //_______________________________________________________________________
 void AliESDtrack::SetTPCpid(const Double_t *p) {  
   // Sets values for the probability of each particle type (in TPC)
-  // normalize probabiluty to 1
-  // 
-  //
-//   Double_t sump=0;
-//   for (Int_t i=0; i<AliPID::kSPECIES; i++) {
-//     sump+=p[i];
-//   }
-//   for (Int_t i=0; i<AliPID::kSPECIES; i++) {
-//     if (sump>0){
-//       fTPCr[i]=p[i]/sump;
-//     }
-//     else{
-//       fTPCr[i]=p[i];
-//     }
-//   }
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) fTPCr[i] = p[i];
+  SetPIDValues(fTPCr,p,AliPID::kSPECIES);
   SetStatus(AliESDtrack::kTPCpid);
 }
 
@@ -891,7 +726,7 @@ Int_t AliESDtrack::GetTRDclusters(UInt_t *idx) const {
 //_______________________________________________________________________
 void AliESDtrack::SetTRDpid(const Double_t *p) {  
   // Sets values for the probability of each particle type (in TRD)
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) fTRDr[i]=p[i];
+  SetPIDValues(fTRDr,p,AliPID::kSPECIES);
   SetStatus(AliESDtrack::kTRDpid);
 }
 
@@ -917,7 +752,7 @@ Float_t AliESDtrack::GetTRDpid(Int_t iSpecies) const
 //_______________________________________________________________________
 void AliESDtrack::SetTOFpid(const Double_t *p) {  
   // Sets the probability of each particle type (in TOF)
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) fTOFr[i]=p[i];
+  SetPIDValues(fTOFr,p,AliPID::kSPECIES);
   SetStatus(AliESDtrack::kTOFpid);
 }
 
@@ -956,7 +791,7 @@ void AliESDtrack::SetTOFInfo(Float_t*info) {
 //_______________________________________________________________________
 void AliESDtrack::SetPHOSpid(const Double_t *p) {  
   // Sets the probability of each particle type (in PHOS)
-  for (Int_t i=0; i<AliPID::kSPECIESN; i++) fPHOSr[i]=p[i];
+  SetPIDValues(fPHOSr,p,AliPID::kSPECIESN);
   SetStatus(AliESDtrack::kPHOSpid);
 }
 
@@ -969,7 +804,7 @@ void AliESDtrack::GetPHOSpid(Double_t *p) const {
 //_______________________________________________________________________
 void AliESDtrack::SetEMCALpid(const Double_t *p) {  
   // Sets the probability of each particle type (in EMCAL)
-  for (Int_t i=0; i<AliPID::kSPECIESN; i++) fEMCALr[i]=p[i];
+  SetPIDValues(fEMCALr,p,AliPID::kSPECIESN);
   SetStatus(AliESDtrack::kEMCALpid);
 }
 
@@ -982,7 +817,7 @@ void AliESDtrack::GetEMCALpid(Double_t *p) const {
 //_______________________________________________________________________
 void AliESDtrack::SetRICHpid(const Double_t *p) {  
   // Sets the probability of each particle type (in RICH)
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) fRICHr[i]=p[i];
+  SetPIDValues(fRICHr,p,AliPID::kSPECIES);
   SetStatus(AliESDtrack::kRICHpid);
 }
 
@@ -997,7 +832,7 @@ void AliESDtrack::GetRICHpid(Double_t *p) const {
 //_______________________________________________________________________
 void AliESDtrack::SetESDpid(const Double_t *p) {  
   // Sets the probability of each particle type for the ESD track
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) fR[i]=p[i];
+  SetPIDValues(fR,p,AliPID::kSPECIES);
   SetStatus(AliESDtrack::kESDpid);
 }
 
@@ -1007,6 +842,67 @@ void AliESDtrack::GetESDpid(Double_t *p) const {
   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fR[i];
 }
 
+//_______________________________________________________________________
+Bool_t AliESDtrack::RelateToVertex
+(const AliESDVertex *vtx, Double_t b, Double_t maxd) {
+  //
+  // Try to relate this track to the vertex "vtx", 
+  // if the (rough) transverse impact parameter is not bigger then "maxd". 
+  //            Magnetic field is "b" (kG).
+  //
+  // a) The track gets extapolated to the DCA to the vertex.
+  // b) The impact parameters and their covariance matrix are calculated.
+  // c) An attempt to constrain this track to the vertex is done.
+  //
+  //    In the case of success, the returned value is kTRUE
+  //    (otherwise, it's kFALSE)
+  //  
+  Double_t alpha=GetAlpha();
+  Double_t sn=TMath::Sin(alpha), cs=TMath::Cos(alpha);
+  Double_t x=GetX(), y=GetParameter()[0], snp=GetParameter()[2];
+  Double_t xv= vtx->GetXv()*cs + vtx->GetYv()*sn;
+  Double_t yv=-vtx->GetXv()*sn + vtx->GetYv()*cs, zv=vtx->GetZv();
+  x-=xv; y-=yv;
+
+  //Estimate the impact parameter neglecting the track curvature
+  Double_t d=TMath::Abs(x*snp - y*TMath::Sqrt(1.- snp*snp));
+  if (d > maxd) return kFALSE; 
+
+  //Propagate to the DCA
+  Double_t crv=0.299792458e-3*b*GetParameter()[4];
+  Double_t tgfv=-(crv*x - snp)/(crv*y + TMath::Sqrt(1.-snp*snp));
+  sn=tgfv/TMath::Sqrt(1.+ tgfv*tgfv); cs=TMath::Sqrt(1.+ sn*sn);
+
+  x = xv*cs + yv*sn;
+  yv=-xv*sn + yv*cs; xv=x;
+
+  if (!Propagate(alpha+TMath::ASin(sn),xv,b)) return kFALSE;
+
+  fD = GetParameter()[0] - yv;
+  fZ = GetParameter()[1] - zv;
+  
+  Double_t cov[6]; vtx->GetCovMatrix(cov);
+  fCdd = GetCovariance()[0] + cov[2];      // neglecting non-diagonals
+  fCdz = GetCovariance()[1];               //     in the vertex's    
+  fCzz = GetCovariance()[2] + cov[5];      //    covariance matrix
+
+  {//Try to constrain 
+    Double_t p[2]={yv,zv}, c[3]={cov[2],0.,cov[5]};
+    Double_t chi2=GetPredictedChi2(p,c);
+
+    if (chi2>77.) return kFALSE;
+
+    AliExternalTrackParam tmp(*this);
+    if (!tmp.Update(p,c)) return kFALSE;
+
+    fCchi2=chi2;
+    if (!fCp) fCp=new AliExternalTrackParam();
+    new (fCp) AliExternalTrackParam(tmp);
+  }
+
+  return kTRUE;
+}
+
 //_______________________________________________________________________
 void AliESDtrack::Print(Option_t *) const {
   // Prints info on the track
@@ -1043,7 +939,7 @@ void AliESDtrack::Print(Option_t *) const {
     printf("\n           signal = %f\n", GetTOFsignal()) ;
   }
   if( IsOn(kRICHpid) ){
-    printf("From TOF: ") ; 
+    printf("From RICH: ") ; 
     GetRICHpid(p) ; 
     for(index = 0 ; index < AliPID::kSPECIES; index++) 
       printf("%f, ", p[index]) ;