]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITStrackV2.cxx
Fixing FORWARD_NULL defects reported by Coverity
[u/mrichter/AliRoot.git] / ITS / AliITStrackV2.cxx
index 657841884355d75c6949088c2b1aaace3c2dcd84..c4478c5d742a915f60ade0336f518f265d3cf2e0 100644 (file)
@@ -13,6 +13,8 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+/* $Id$ */
+
 ///////////////////////////////////////////////////////////////////////////
 //                Implementation of the ITS track class
 //
 #include <TMath.h>
 
 #include "AliCluster.h"
-#include "AliTracker.h"
-#include "AliESDtrack.h"
+#include "AliESDVertex.h"
+#include "AliITSReconstructor.h"
 #include "AliITStrackV2.h"
+#include "AliTracker.h"
 
 const Int_t AliITStrackV2::fgkWARN = 5;
 
@@ -33,17 +36,19 @@ ClassImp(AliITStrackV2)
 
 //____________________________________________________________________________
 AliITStrackV2::AliITStrackV2() : AliKalmanTrack(),
+  fCheckInvariant(kTRUE),
   fdEdx(0),
   fESDtrack(0)
 {
-    for(Int_t i=0; i<2*kMaxLayer; i++) fIndex[i]=-1;
-    for(Int_t i=0; i<4; i++) fdEdxSample[i]=0;
+  for(Int_t i=0; i<2*AliITSgeomTGeo::kNLayers; i++) {fIndex[i]=-1; fModule[i]=-1;}
+  for(Int_t i=0; i<4; i++) fdEdxSample[i]=0;
 }
 
 
 //____________________________________________________________________________
-AliITStrackV2::AliITStrackV2(AliESDtrack& t,Bool_t c) throw (const Char_t *) :
+AliITStrackV2::AliITStrackV2(AliESDtrack& t,Bool_t c):
   AliKalmanTrack(),
+  fCheckInvariant(kTRUE),
   fdEdx(t.GetITSsignal()),
   fESDtrack(&t)
 {
@@ -54,12 +59,10 @@ AliITStrackV2::AliITStrackV2(AliESDtrack& t,Bool_t c) throw (const Char_t *) :
   const AliExternalTrackParam *par=&t;
   if (c) {
     par=t.GetConstrainedParam();
-    if (!par) throw "AliITStrackV2: conversion failed !\n";
+    if (!par) AliError("AliITStrackV2: conversion failed !\n");
   }
   Set(par->GetX(),par->GetAlpha(),par->GetParameter(),par->GetCovariance());
 
-  //if (!Invariant()) throw "AliITStrackV2: conversion failed !\n";
-
   SetLabel(t.GetLabel());
   SetMass(t.GetMass());
   SetNumberOfClusters(t.GetITSclusters(fIndex));
@@ -73,13 +76,35 @@ AliITStrackV2::AliITStrackV2(AliESDtrack& t,Bool_t c) throw (const Char_t *) :
   for(Int_t i=0; i<4; i++) fdEdxSample[i]=0;
 }
 
+//____________________________________________________________________________
+void AliITStrackV2::ResetClusters() {
+  //------------------------------------------------------------------
+  // Reset the array of attached clusters.
+  //------------------------------------------------------------------
+  for (Int_t i=0; i<2*AliITSgeomTGeo::kNLayers; i++) fIndex[i]=-1;
+  SetChi2(0.); 
+  SetNumberOfClusters(0);
+} 
+
+//____________________________________________________________________________
 void AliITStrackV2::UpdateESDtrack(ULong_t flags) const {
+  // Update track params
   fESDtrack->UpdateTrackParams(this,flags);
+  // copy the module indices
+  for(Int_t i=0;i<12;i++) {
+    //   printf("     %d\n",GetModuleIndex(i));
+    fESDtrack->SetITSModuleIndex(i,GetModuleIndex(i));
+  }
+  // copy the 4 dedx samples
+  Double_t sdedx[4]={0.,0.,0.,0.};
+  for(Int_t i=0; i<4; i++) sdedx[i]=fdEdxSample[i];
+  fESDtrack->SetITSdEdxSamples(sdedx);
 }
 
 //____________________________________________________________________________
 AliITStrackV2::AliITStrackV2(const AliITStrackV2& t) : 
   AliKalmanTrack(t),
+  fCheckInvariant(t.fCheckInvariant),
   fdEdx(t.fdEdx),
   fESDtrack(t.fESDtrack) 
 {
@@ -88,7 +113,10 @@ AliITStrackV2::AliITStrackV2(const AliITStrackV2& t) :
   //------------------------------------------------------------------
   Int_t i;
   for (i=0; i<4; i++) fdEdxSample[i]=t.fdEdxSample[i];
-  for (i=0; i<2*kMaxLayer; i++) fIndex[i]=t.fIndex[i];
+  for (i=0; i<2*AliITSgeomTGeo::GetNLayers(); i++) {
+    fIndex[i]=t.fIndex[i];
+    fModule[i]=t.fModule[i];
+  }
 }
 
 //_____________________________________________________________________________
@@ -114,19 +142,22 @@ AliITStrackV2::PropagateToVertex(const AliESDVertex *v,Double_t d,Double_t x0)
   //This function propagates a track to the minimal distance from the origin
   //------------------------------------------------------------------  
   Double_t bz=GetBz();
-  if (PropagateToDCA(v,bz,kVeryBig))
-   if (AliExternalTrackParam::CorrectForMaterial(d,x0,GetMass())) return kTRUE;
+  if (PropagateToDCA(v,bz,kVeryBig)) {
+    Double_t xOverX0,xTimesRho; 
+    xOverX0 = d; xTimesRho = d*x0;
+    if (CorrectForMeanMaterial(xOverX0,xTimesRho,kTRUE)) return kTRUE;
+  }
   return kFALSE;
 }
 
 //____________________________________________________________________________
 Bool_t AliITStrackV2::
-GetGlobalXYZat(Double_t xk, Double_t &x, Double_t &y, Double_t &z) const {
+GetGlobalXYZat(Double_t xloc, Double_t &x, Double_t &y, Double_t &z) const {
   //------------------------------------------------------------------
   //This function returns a track position in the global system
   //------------------------------------------------------------------
   Double_t r[3];
-  Bool_t rc=GetXYZAt(xk, AliTracker::GetBz(), r);
+  Bool_t rc=GetXYZAt(xloc, GetBz(), r);
   x=r[0]; y=r[1]; z=r[2]; 
   return rc;
 }
@@ -149,9 +180,13 @@ Bool_t AliITStrackV2::PropagateTo(Double_t xk, Double_t d, Double_t x0) {
 
   Double_t oldX=GetX(), oldY=GetY(), oldZ=GetZ();
   
-  Double_t bz=GetBz();
-  if (!AliExternalTrackParam::PropagateTo(xk,bz)) return kFALSE;
-  if (!AliExternalTrackParam::CorrectForMaterial(d,x0,GetMass())) return kFALSE;
+  //Double_t bz=GetBz();
+  //if (!AliExternalTrackParam::PropagateTo(xk,bz)) return kFALSE;
+  Double_t b[3]; GetBxByBz(b);
+  if (!AliExternalTrackParam::PropagateToBxByBz(xk,b)) return kFALSE;
+  Double_t xOverX0,xTimesRho; 
+  xOverX0 = d; xTimesRho = d*x0;
+  if (!CorrectForMeanMaterial(xOverX0,xTimesRho,kTRUE)) return kFALSE;
 
   Double_t x=GetX(), y=GetY(), z=GetZ();
   if (IsStartedTimeIntegral() && x>oldX) {
@@ -163,7 +198,7 @@ Bool_t AliITStrackV2::PropagateTo(Double_t xk, Double_t d, Double_t x0) {
 }
 
 //____________________________________________________________________________
-Bool_t AliITStrackV2::PropagateToTGeo(Double_t xToGo, Int_t nstep) {
+Bool_t AliITStrackV2::PropagateToTGeo(Double_t xToGo, Int_t nstep, Double_t &xOverX0, Double_t &xTimesRho, Bool_t addTime) {
   //-------------------------------------------------------------------
   //  Propagates the track to a reference plane x=xToGo in n steps.
   //  These n steps are only used to take into account the curvature.
@@ -174,7 +209,11 @@ Bool_t AliITStrackV2::PropagateToTGeo(Double_t xToGo, Int_t nstep) {
   Double_t sign = (startx<xToGo) ? -1.:1.;
   Double_t step = (xToGo-startx)/TMath::Abs(nstep);
 
-  Double_t start[3], end[3], mparam[7], bz = GetBz();
+  Double_t start[3], end[3], mparam[7];
+  //Double_t bz = GetBz();
+  Double_t b[3]; GetBxByBz(b);
+  Double_t bz = b[2];
+
   Double_t x = startx;
   
   for (Int_t i=0; i<nstep; i++) {
@@ -182,19 +221,20 @@ Bool_t AliITStrackV2::PropagateToTGeo(Double_t xToGo, Int_t nstep) {
     GetXYZ(start);   //starting global position
     x += step;
     if (!GetXYZAt(x, bz, end)) return kFALSE;
-    if (!AliExternalTrackParam::PropagateTo(x, bz)) return kFALSE;
+    //if (!AliExternalTrackParam::PropagateTo(x, bz)) return kFALSE;
+    if (!AliExternalTrackParam::PropagateToBxByBz(x, b)) return kFALSE;
     AliTracker::MeanMaterialBudget(start, end, mparam);
-    //printf("mparam: %f %f %f %f %f %f %f\n",mparam[0],mparam[1],mparam[2],mparam[3],mparam[4],mparam[5],mparam[6]);
+    xTimesRho = sign*mparam[4]*mparam[0];
+    xOverX0   = mparam[1];
     if (mparam[1]<900000) {
-      Double_t lengthTimesMeanDensity = sign*mparam[4]*mparam[0];
-      Double_t xOverX0 = mparam[1];
-      //printf("%f %f %f CorrectForMeanMaterial(%f,%f)\n",startx,xToGo,sign,xOverX0,lengthTimesMeanDensity);
       if (!AliExternalTrackParam::CorrectForMeanMaterial(xOverX0,
-                                     lengthTimesMeanDensity,GetMass())) return kFALSE;
+                          xTimesRho,GetMass())) return kFALSE;
+    } else { // this happens when MeanMaterialBudget cannot cross a boundary
+      return kFALSE;
     }
   }
 
-  if (IsStartedTimeIntegral() && GetX()>startx) {
+  if (addTime && IsStartedTimeIntegral() && GetX()>startx) {
     Double_t l2 = ( (GetX()-startx)*(GetX()-startx) +
                    (GetY()-starty)*(GetY()-starty) +
                    (GetZ()-startz)*(GetZ()-startz) );
@@ -211,18 +251,25 @@ Bool_t AliITStrackV2::Update(const AliCluster* c, Double_t chi2, Int_t index)
   //This function updates track parameters
   //------------------------------------------------------------------
   Double_t p[2]={c->GetY(), c->GetZ()};
-  Double_t cov[3]={c->GetSigmaY2(), 0., c->GetSigmaZ2()};
+  Double_t cov[3]={c->GetSigmaY2(), c->GetSigmaYZ(), c->GetSigmaZ2()};
 
   if (!AliExternalTrackParam::Update(p,cov)) return kFALSE;
 
+  Int_t n=GetNumberOfClusters();
   if (!Invariant()) {
-     AliWarning("Wrong invariant !");
+     if (n>fgkWARN) AliWarning("Wrong invariant !");
      return kFALSE;
   }
 
   if (chi2<0) return kTRUE;
 
-  Int_t n=GetNumberOfClusters();
+  // fill residuals for ITS+TPC tracks 
+  if (fESDtrack) {
+    if (fESDtrack->GetStatus()&AliESDtrack::kTPCin) {
+      AliTracker::FillResiduals(this,p,cov,c->GetVolumeId());
+    }
+  }
+
   fIndex[n]=index;
   SetNumberOfClusters(n+1);
   SetChi2(GetChi2()+chi2);
@@ -234,20 +281,35 @@ Bool_t AliITStrackV2::Invariant() const {
   //------------------------------------------------------------------
   // This function is for debugging purpose only
   //------------------------------------------------------------------
+  if(!fCheckInvariant) return kTRUE;
+
   Int_t n=GetNumberOfClusters();
 
+  // take into account the misalignment error
+  Float_t maxMisalErrY2=0,maxMisalErrZ2=0;
+  for (Int_t lay=0; lay<AliITSgeomTGeo::kNLayers; lay++) {
+    maxMisalErrY2 = TMath::Max(maxMisalErrY2,AliITSReconstructor::GetRecoParam()->GetClusterMisalErrorY(lay,GetBz()));
+    maxMisalErrZ2 = TMath::Max(maxMisalErrZ2,AliITSReconstructor::GetRecoParam()->GetClusterMisalErrorZ(lay,GetBz()));
+  }
+  maxMisalErrY2 *= maxMisalErrY2;
+  maxMisalErrZ2 *= maxMisalErrZ2;
+  // this is because when we reset before refitting, we multiply the
+  // matrix by 10
+  maxMisalErrY2 *= 10.; 
+  maxMisalErrZ2 *= 10.;
+
   Double_t sP2=GetParameter()[2];
   if (TMath::Abs(sP2) >= kAlmost1){
      if (n>fgkWARN) Warning("Invariant","fP2=%f\n",sP2);
      return kFALSE;
   }
   Double_t sC00=GetCovariance()[0];
-  if (sC00<=0 || sC00>9.) {
+  if (sC00<=0 || sC00>(9.+maxMisalErrY2)) {
      if (n>fgkWARN) Warning("Invariant","fC00=%f\n",sC00); 
      return kFALSE;
   }
   Double_t sC11=GetCovariance()[2];
-  if (sC11<=0 || sC11>9.) {
+  if (sC11<=0 || sC11>(9.+maxMisalErrZ2)) {
      if (n>fgkWARN) Warning("Invariant","fC11=%f\n",sC11); 
      return kFALSE;
   }
@@ -275,12 +337,15 @@ Bool_t AliITStrackV2::Propagate(Double_t alp,Double_t xk) {
   //------------------------------------------------------------------
   //This function propagates a track
   //------------------------------------------------------------------
-  Double_t bz=GetBz();
-  if (!AliExternalTrackParam::Propagate(alp,xk,bz)) return kFALSE;
+  //Double_t bz=GetBz();
+  //if (!AliExternalTrackParam::Propagate(alp,xk,bz)) return kFALSE;
+  Double_t b[3]; GetBxByBz(b);
+  if (!AliExternalTrackParam::PropagateBxByBz(alp,xk,b)) return kFALSE;
 
   if (!Invariant()) {
-     AliWarning("Wrong invariant !");
-     return kFALSE;
+    Int_t n=GetNumberOfClusters();
+    if (n>fgkWARN) AliWarning("Wrong invariant !");
+    return kFALSE;
   }
 
   return kTRUE;
@@ -326,12 +391,36 @@ Bool_t AliITStrackV2::Improve(Double_t x0,Double_t xyz[3],Double_t ers[3]) {
   //------------------------------------------------------------------
   //This function improves angular track parameters
   //------------------------------------------------------------------
+  //Store the initail track parameters
+
+  Double_t x = GetX();
+  Double_t alpha = GetAlpha();
+  Double_t par[] = {GetY(),GetZ(),GetSnp(),GetTgl(),GetSigned1Pt()};
+  Double_t cov[] = {
+    GetSigmaY2(),
+    GetSigmaZY(),
+    GetSigmaZ2(),
+    GetSigmaSnpY(),
+    GetSigmaSnpZ(),
+    GetSigmaSnp2(),
+    GetSigmaTglY(),
+    GetSigmaTglZ(),
+    GetSigmaTglSnp(),
+    GetSigmaTgl2(),
+    GetSigma1PtY(),
+    GetSigma1PtZ(),
+    GetSigma1PtSnp(),
+    GetSigma1PtTgl(),
+    GetSigma1Pt2()
+  }; 
+
+
   Double_t cs=TMath::Cos(GetAlpha()), sn=TMath::Sin(GetAlpha());
 //Double_t xv = xyz[0]*cs + xyz[1]*sn; // vertex
   Double_t yv =-xyz[0]*sn + xyz[1]*cs; // in the
   Double_t zv = xyz[2];                // local frame
 
-  Double_t dy = Par(0) - yv, dz = Par(1) - zv;
+  Double_t dy = par[0] - yv, dz = par[1] - zv;
   Double_t r2=GetX()*GetX() + dy*dy;
   Double_t p2=(1.+ GetTgl()*GetTgl())/(GetSigned1Pt()*GetSigned1Pt());
   Double_t beta2=p2/(p2 + GetMass()*GetMass());
@@ -344,29 +433,34 @@ Bool_t AliITStrackV2::Improve(Double_t x0,Double_t xyz[3],Double_t ers[3]) {
     Double_t dummy = 4/r2 - GetC()*GetC();
     if (dummy < 0) return kFALSE;
     Double_t parp = 0.5*(GetC()*GetX() + dy*TMath::Sqrt(dummy));
-    Double_t sigma2p = theta2*(1.- GetSnp()*GetSnp())*(1. + GetTgl()*GetTgl());
-    sigma2p += Cov(0)/r2*(1.- dy*dy/r2)*(1.- dy*dy/r2);
+    Double_t sigma2p = theta2*(1.-GetSnp())*(1.+GetSnp())*(1. + GetTgl()*GetTgl());
+    Double_t ovSqr2 = 1./TMath::Sqrt(r2);
+    Double_t tfact = ovSqr2*(1.-dy*ovSqr2)*(1.+dy*ovSqr2);
+    sigma2p += cov[0]*tfact*tfact;
     sigma2p += ers[1]*ers[1]/r2;
-    sigma2p += 0.25*Cov(14)*cnv*cnv*GetX()*GetX();
-    Double_t eps2p=sigma2p/(Cov(5) + sigma2p);
-    Par(0) += Cov(3)/(Cov(5) + sigma2p)*(parp - GetSnp());
-    Par(2)  = eps2p*GetSnp() + (1 - eps2p)*parp;
-    Cov(5) *= eps2p;
-    Cov(3) *= eps2p;
+    sigma2p += 0.25*cov[14]*cnv*cnv*GetX()*GetX();
+    Double_t eps2p=sigma2p/(cov[5] + sigma2p);
+    par[0] += cov[3]/(cov[5] + sigma2p)*(parp - GetSnp());
+    par[2]  = eps2p*GetSnp() + (1 - eps2p)*parp;
+    cov[5] *= eps2p;
+    cov[3] *= eps2p;
   }
   {
     Double_t parl=0.5*GetC()*dz/TMath::ASin(0.5*GetC()*TMath::Sqrt(r2));
     Double_t sigma2l=theta2;
-    sigma2l += Cov(2)/r2 + Cov(0)*dy*dy*dz*dz/(r2*r2*r2);
+    sigma2l += cov[2]/r2 + cov[0]*dy*dy*dz*dz/(r2*r2*r2);
     sigma2l += ers[2]*ers[2]/r2;
-    Double_t eps2l = sigma2l/(Cov(9) + sigma2l);
-    Par(1) += Cov(7 )/(Cov(9) + sigma2l)*(parl - Par(3));
-    Par(4) += Cov(13)/(Cov(9) + sigma2l)*(parl - Par(3));
-    Par(3)  = eps2l*Par(3) + (1-eps2l)*parl;
-    Cov(9) *= eps2l; 
-    Cov(13)*= eps2l; 
-    Cov(7) *= eps2l; 
+    Double_t eps2l = sigma2l/(cov[9] + sigma2l);
+    par[1] += cov[7 ]/(cov[9] + sigma2l)*(parl - par[3]);
+    par[4] += cov[13]/(cov[9] + sigma2l)*(parl - par[3]);
+    par[3]  = eps2l*par[3] + (1-eps2l)*parl;
+    cov[9] *= eps2l; 
+    cov[13]*= eps2l; 
+    cov[7] *= eps2l; 
   }
+
+  Set(x,alpha,par,cov);
+
   if (!Invariant()) return kFALSE;
 
   return kTRUE;
@@ -376,64 +470,106 @@ void AliITStrackV2::CookdEdx(Double_t low, Double_t up) {
   //-----------------------------------------------------------------
   // This function calculates dE/dX within the "low" and "up" cuts.
   // Origin: Boris Batyunya, JINR, Boris.Batiounia@cern.ch 
+  // Updated: F. Prino 8-June-2009
   //-----------------------------------------------------------------
-  // The clusters order is: SSD-2, SSD-1, SDD-2, SDD-1, SPD-2, SPD-1
+  // The cluster order is: SDD-1, SDD-2, SSD-1, SSD-2
 
-  Int_t i;
   Int_t nc=0;
-  for (i=0; i<GetNumberOfClusters(); i++) {
-    Int_t idx=GetClusterIndex(i);
-    idx=(idx&0xf0000000)>>28;
-    if (idx>1) nc++; // Take only SSD and SDD
+  Float_t dedx[4];
+  for (Int_t il=0; il<4; il++) { // count good (>0) dE/dx values
+    if(fdEdxSample[il]>0.){
+      dedx[nc]= fdEdxSample[il];
+      nc++;
+    }
+  }
+  if(nc<1){
+    SetdEdx(0.);
+    return;
   }
 
-  Int_t swap;//stupid sorting
+  Int_t swap; // sort in ascending order
   do {
     swap=0;
-    for (i=0; i<nc-1; i++) {
-      if (fdEdxSample[i]<=fdEdxSample[i+1]) continue;
-      Float_t tmp=fdEdxSample[i];
-      fdEdxSample[i]=fdEdxSample[i+1]; fdEdxSample[i+1]=tmp;
+    for (Int_t i=0; i<nc-1; i++) {
+      if (dedx[i]<=dedx[i+1]) continue;
+      Float_t tmp=dedx[i];
+      dedx[i]=dedx[i+1]; 
+      dedx[i+1]=tmp;
       swap++;
     }
   } while (swap);
 
-  Int_t nl=Int_t(low*nc), nu=Int_t(up*nc); //b.b. to take two lowest dEdX
-                                           // values from four ones choose
-                                           // nu=2
-  Float_t dedx=0;
-  for (i=nl; i<nu; i++) dedx += fdEdxSample[i];
-  if (nu-nl>0) dedx /= (nu-nl);
 
-  SetdEdx(dedx);
-}
-
-Double_t AliITStrackV2::GetBz() const {
-  //
-  // returns Bz component of the magnetic field (kG)
-  //
-  if (AliTracker::UniformField()) return AliTracker::GetBz();
-  Double_t r[3]; GetXYZ(r); 
-  return AliTracker::GetBz(r);
+  Double_t nl=low*nc, nu =up*nc;
+  Float_t sumamp = 0;
+  Float_t sumweight =0;
+  for (Int_t i=0; i<nc; i++) {
+    Float_t weight =1;
+    if (i<nl+0.1)     weight = TMath::Max(1.-(nl-i),0.);
+    if (i>nu-1)     weight = TMath::Max(nu-i,0.);
+    sumamp+= dedx[i]*weight;
+    sumweight+=weight;
+  }
+  SetdEdx(sumamp/sumweight);
 }
 
 //____________________________________________________________________________
 Bool_t AliITStrackV2::
-GetPhiZat(Double_t rk, Double_t &phik, Double_t &zk) const {
+GetPhiZat(Double_t r, Double_t &phi, Double_t &z) const {
   //------------------------------------------------------------------
-  // This function returns the global cylindrical (phik,zk) of the track 
-  // position estimated at the radius rk
+  // This function returns the global cylindrical (phi,z) of the track 
+  // position estimated at the radius r. 
   // The track curvature is neglected.
   //------------------------------------------------------------------
   Double_t d=GetD(0.,0.);
-  if (TMath::Abs(d) > rk) return kFALSE; 
+  if (TMath::Abs(d) > r) {
+    if (r>1e-1) return kFALSE;
+    r = TMath::Abs(d);
+  }
 
-  Double_t r=TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
-  Double_t phi=GetAlpha()+TMath::ASin(GetSnp());
+  Double_t rcurr=TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
+  if (TMath::Abs(d) > rcurr) return kFALSE;
+  Double_t globXYZcurr[3]; GetXYZ(globXYZcurr); 
+  Double_t phicurr=TMath::ATan2(globXYZcurr[1],globXYZcurr[0]);
 
-  phik=phi+TMath::ASin(d/rk)-TMath::ASin(d/r);
-  zk=GetZ()+GetTgl()*(TMath::Sqrt(rk*rk-d*d) - TMath::Sqrt(r*r-d*d));
+  if (GetX()>=0.) {
+    phi=phicurr+TMath::ASin(d/r)-TMath::ASin(d/rcurr);
+  } else {
+    phi=phicurr+TMath::ASin(d/r)+TMath::ASin(d/rcurr)-TMath::Pi();
+  }
 
+  // return a phi in [0,2pi[ 
+  if (phi<0.) phi+=2.*TMath::Pi();
+  else if (phi>=2.*TMath::Pi()) phi-=2.*TMath::Pi();
+  z=GetZ()+GetTgl()*(TMath::Sqrt((r-d)*(r+d))-TMath::Sqrt((rcurr-d)*(rcurr+d)));
   return kTRUE;
 }
+//____________________________________________________________________________
+Bool_t AliITStrackV2::
+GetLocalXat(Double_t r,Double_t &xloc) const {
+  //------------------------------------------------------------------
+  // This function returns the local x of the track 
+  // position estimated at the radius r. 
+  // The track curvature is neglected.
+  //------------------------------------------------------------------
+  Double_t d=GetD(0.,0.);
+  if (TMath::Abs(d) > r) { 
+    if (r>1e-1) return kFALSE; 
+    r = TMath::Abs(d); 
+  } 
+
+  Double_t rcurr=TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
+  Double_t globXYZcurr[3]; GetXYZ(globXYZcurr); 
+  Double_t phicurr=TMath::ATan2(globXYZcurr[1],globXYZcurr[0]);
+  Double_t phi;
+  if (GetX()>=0.) {
+    phi=phicurr+TMath::ASin(d/r)-TMath::ASin(d/rcurr);
+  } else {
+    phi=phicurr+TMath::ASin(d/r)+TMath::ASin(d/rcurr)-TMath::Pi();
+  }
 
+  xloc=r*(TMath::Cos(phi)*TMath::Cos(GetAlpha())
+         +TMath::Sin(phi)*TMath::Sin(GetAlpha())); 
+
+  return kTRUE;
+}