]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTrackExtrap.cxx
o add Reset function to CalPad and CalROC o Add functionality to AliTPCdataQA - Reset...
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackExtrap.cxx
index a91c5a4b6783311a7207a93fa64dbc0ca5b79a0a..45dcc35c0c02e311e4bd3aba9bec84d1b19baf5f 100644 (file)
 #include "AliMUONTrackParam.h"
 #include "AliMUONConstants.h"
 #include "AliMUONReconstructor.h"
-#include "AliMUONRecoParam.h"
 
-#include "AliMagF.h" 
+#include "AliMagF.h"
+#include "AliExternalTrackParam.h"
 
-#include <TMath.h>
+#include <TGeoGlobalMagField.h>
 #include <TGeoManager.h>
+#include <TMath.h>
+#include <TDatabasePDG.h>
 
 #include <Riostream.h>
 
+using std::endl;
+using std::cout;
 /// \cond CLASSIMP
 ClassImp(AliMUONTrackExtrap) // Class implementation in ROOT context
 /// \endcond
 
-const AliMagF* AliMUONTrackExtrap::fgkField = 0x0;
+const Double_t AliMUONTrackExtrap::fgkSimpleBPosition = 0.5 * (AliMUONConstants::CoilZ() + AliMUONConstants::YokeZ());
+const Double_t AliMUONTrackExtrap::fgkSimpleBLength = 0.5 * (AliMUONConstants::CoilL() + AliMUONConstants::YokeL());
+      Double_t AliMUONTrackExtrap::fgSimpleBValue = 0.;
+      Bool_t   AliMUONTrackExtrap::fgFieldON = kFALSE;
 const Bool_t   AliMUONTrackExtrap::fgkUseHelix = kFALSE;
 const Int_t    AliMUONTrackExtrap::fgkMaxStepNumber = 5000;
 const Double_t AliMUONTrackExtrap::fgkHelixStepLength = 6.;
 const Double_t AliMUONTrackExtrap::fgkRungeKuttaMaxResidue = 0.002;
 
+//__________________________________________________________________________
+void AliMUONTrackExtrap::SetField()
+{
+  /// set field on/off flag;  
+  /// set field at the centre of the dipole
+  const Double_t x[3] = {50.,50.,fgkSimpleBPosition};
+  Double_t b[3] = {0.,0.,0.};
+  TGeoGlobalMagField::Instance()->Field(x,b);
+  fgSimpleBValue = b[0];
+  fgFieldON = (TMath::Abs(fgSimpleBValue) > 1.e-10) ? kTRUE : kFALSE;
+  
+}
+
 //__________________________________________________________________________
 Double_t AliMUONTrackExtrap::GetImpactParamFromBendingMomentum(Double_t bendingMomentum)
 {
@@ -55,22 +75,14 @@ Double_t AliMUONTrackExtrap::GetImpactParamFromBendingMomentum(Double_t bendingM
   
   if (bendingMomentum == 0.) return 1.e10;
   
-  const Double_t kCorrectionFactor = 0.9; // impact parameter is 10% overestimated
-  Double_t simpleBPosition = 0.5 * (AliMUONConstants::CoilZ() + AliMUONConstants::YokeZ());
-  Double_t simpleBLength = 0.5 * (AliMUONConstants::CoilL() + AliMUONConstants::YokeL());
-  Float_t b[3], x[3] = {50.,50.,(Float_t) simpleBPosition};
-  if (fgkField) fgkField->Field(x,b);
-  else {
-    cout<<"F-AliMUONTrackExtrap::GetField: fgkField = 0x0"<<endl;
-    exit(-1);
-  }
-  Double_t simpleBValue = (Double_t) b[0];
+  const Double_t kCorrectionFactor = 1.1; // impact parameter is 10% underestimated
   
-  return kCorrectionFactor * (-0.0003 * simpleBValue * simpleBLength * simpleBPosition / bendingMomentum);
+  return kCorrectionFactor * (-0.0003 * fgSimpleBValue * fgkSimpleBLength * fgkSimpleBPosition / bendingMomentum);
 }
 
 //__________________________________________________________________________
-Double_t AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(Double_t impactParam)
+Double_t 
+AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(Double_t impactParam)
 {
   /// Returns signed bending momentum in bending plane (GeV/c),
   /// the sign being the sign of the charge for particles moving forward in Z,
@@ -80,24 +92,21 @@ Double_t AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(Double_t impactPa
   if (impactParam == 0.) return 1.e10;
   
   const Double_t kCorrectionFactor = 1.1; // bending momentum is 10% underestimated
-  Double_t simpleBPosition = 0.5 * (AliMUONConstants::CoilZ() + AliMUONConstants::YokeZ());
-  Double_t simpleBLength = 0.5 * (AliMUONConstants::CoilL() + AliMUONConstants::YokeL());
-  Float_t b[3], x[3] = {50.,50.,(Float_t) simpleBPosition};
-  if (fgkField) fgkField->Field(x,b);
-  else {
-    cout<<"F-AliMUONTrackExtrap::GetField: fgkField = 0x0"<<endl;
-    exit(-1);
-  }
-  Double_t simpleBValue = (Double_t) b[0];
   
-  if (TMath::Abs(simpleBValue) > 0.01) return kCorrectionFactor * (-0.0003 * simpleBValue * simpleBLength * simpleBPosition / impactParam);
-  else return AliMUONReconstructor::GetRecoParam()->GetMostProbBendingMomentum();
+  if (fgFieldON) 
+  {
+    return kCorrectionFactor * (-0.0003 * fgSimpleBValue * fgkSimpleBLength * fgkSimpleBPosition / impactParam);
+  }
+  else 
+  {
+    return AliMUONConstants::GetMostProbBendingMomentum();
+  }
 }
 
 //__________________________________________________________________________
 void AliMUONTrackExtrap::LinearExtrapToZ(AliMUONTrackParam* trackParam, Double_t zEnd)
 {
-  /// Track parameters (and their covariances if any) linearly extrapolated to the plane at "zEnd".
+  /// Track parameters linearly extrapolated to the plane at "zEnd".
   /// On return, results from the extrapolation are updated in trackParam.
   
   if (trackParam->GetZ() == zEnd) return; // nothing to be done if same z
@@ -107,36 +116,64 @@ void AliMUONTrackExtrap::LinearExtrapToZ(AliMUONTrackParam* trackParam, Double_t
   trackParam->SetNonBendingCoor(trackParam->GetNonBendingCoor() + trackParam->GetNonBendingSlope() * dZ);
   trackParam->SetBendingCoor(trackParam->GetBendingCoor() + trackParam->GetBendingSlope() * dZ);
   trackParam->SetZ(zEnd);
+}
+
+//__________________________________________________________________________
+void AliMUONTrackExtrap::LinearExtrapToZCov(AliMUONTrackParam* trackParam, Double_t zEnd, Bool_t updatePropagator)
+{
+  /// Track parameters and their covariances linearly extrapolated to the plane at "zEnd".
+  /// On return, results from the extrapolation are updated in trackParam.
+  
+  if (trackParam->GetZ() == zEnd) return; // nothing to be done if same z
   
-  // Update track parameters covariances if any
-  if (trackParam->CovariancesExist()) {
-    TMatrixD paramCov(trackParam->GetCovariances());
-    paramCov(0,0) += dZ * dZ * paramCov(1,1) + 2. * dZ * paramCov(0,1);
-    paramCov(0,1) += dZ * paramCov(1,1);
-    paramCov(1,0) = paramCov(0,1);
-    paramCov(2,2) += dZ * dZ * paramCov(3,3) + 2. * dZ * paramCov(2,3);
-    paramCov(2,3) += dZ * paramCov(3,3);
-    paramCov(3,2) = paramCov(2,3);
-    trackParam->SetCovariances(paramCov);
+  // No need to propagate the covariance matrix if it does not exist
+  if (!trackParam->CovariancesExist()) {
+    cout<<"W-AliMUONTrackExtrap::LinearExtrapToZCov: Covariance matrix does not exist"<<endl;
+    // Extrapolate linearly track parameters to "zEnd"
+    LinearExtrapToZ(trackParam,zEnd);
+    return;
   }
   
+  // Compute track parameters
+  Double_t dZ = zEnd - trackParam->GetZ();
+  trackParam->SetNonBendingCoor(trackParam->GetNonBendingCoor() + trackParam->GetNonBendingSlope() * dZ);
+  trackParam->SetBendingCoor(trackParam->GetBendingCoor() + trackParam->GetBendingSlope() * dZ);
+  trackParam->SetZ(zEnd);
+  
+  // Calculate the jacobian related to the track parameters linear extrapolation to "zEnd"
+  TMatrixD jacob(5,5);
+  jacob.UnitMatrix();
+  jacob(0,1) = dZ;
+  jacob(2,3) = dZ;
+  
+  // Extrapolate track parameter covariances to "zEnd"
+  TMatrixD tmp(trackParam->GetCovariances(),TMatrixD::kMultTranspose,jacob);
+  TMatrixD tmp2(jacob,TMatrixD::kMult,tmp);
+  trackParam->SetCovariances(tmp2);
+  
+  // Update the propagator if required
+  if (updatePropagator) trackParam->UpdatePropagator(jacob);
 }
 
 //__________________________________________________________________________
-void AliMUONTrackExtrap::ExtrapToZ(AliMUONTrackParam* trackParam, Double_t zEnd)
+Bool_t AliMUONTrackExtrap::ExtrapToZ(AliMUONTrackParam* trackParam, Double_t zEnd)
 {
   /// Interface to track parameter extrapolation to the plane at "Z" using Helix or Rungekutta algorithm.
   /// On return, the track parameters resulting from the extrapolation are updated in trackParam.
-  if (fgkUseHelix) AliMUONTrackExtrap::ExtrapToZHelix(trackParam,zEnd);
-  else AliMUONTrackExtrap::ExtrapToZRungekutta(trackParam,zEnd);
+  if (!fgFieldON) {
+    AliMUONTrackExtrap::LinearExtrapToZ(trackParam,zEnd);
+    return kTRUE;
+  }
+  else if (fgkUseHelix) return AliMUONTrackExtrap::ExtrapToZHelix(trackParam,zEnd);
+  else return AliMUONTrackExtrap::ExtrapToZRungekutta(trackParam,zEnd);
 }
 
 //__________________________________________________________________________
-void AliMUONTrackExtrap::ExtrapToZHelix(AliMUONTrackParam* trackParam, Double_t zEnd)
+Bool_t AliMUONTrackExtrap::ExtrapToZHelix(AliMUONTrackParam* trackParam, Double_t zEnd)
 {
   /// Track parameter extrapolation to the plane at "Z" using Helix algorithm.
   /// On return, the track parameters resulting from the extrapolation are updated in trackParam.
-  if (trackParam->GetZ() == zEnd) return; // nothing to be done if same Z
+  if (trackParam->GetZ() == zEnd) return kTRUE; // nothing to be done if same Z
   Double_t forwardBackward; // +1 if forward, -1 if backward
   if (zEnd < trackParam->GetZ()) forwardBackward = 1.0; // spectro. z<0 
   else forwardBackward = -1.0;
@@ -182,14 +219,15 @@ void AliMUONTrackExtrap::ExtrapToZHelix(AliMUONTrackParam* trackParam, Double_t
   }
   // Recover track parameters (charge back for forward motion)
   RecoverTrackParam(v3, chargeExtrap * forwardBackward, trackParam);
+  return kTRUE;
 }
 
 //__________________________________________________________________________
-void AliMUONTrackExtrap::ExtrapToZRungekutta(AliMUONTrackParam* trackParam, Double_t zEnd)
+Bool_t AliMUONTrackExtrap::ExtrapToZRungekutta(AliMUONTrackParam* trackParam, Double_t zEnd)
 {
   /// Track parameter extrapolation to the plane at "Z" using Rungekutta algorithm.
   /// On return, the track parameters resulting from the extrapolation are updated in trackParam.
-  if (trackParam->GetZ() == zEnd) return; // nothing to be done if same Z
+  if (trackParam->GetZ() == zEnd) return kTRUE; // nothing to be done if same Z
   Double_t forwardBackward; // +1 if forward, -1 if backward
   if (zEnd < trackParam->GetZ()) forwardBackward = 1.0; // spectro. z<0 
   else forwardBackward = -1.0;
@@ -200,32 +238,71 @@ void AliMUONTrackExtrap::ExtrapToZRungekutta(AliMUONTrackParam* trackParam, Doub
   Double_t dZ, step;
   Int_t stepNumber = 0;
   
-  // Extrapolation loop (until within tolerance)
+  // Extrapolation loop (until within tolerance or the track turn around)
   Double_t residue = zEnd - trackParam->GetZ();
+  Bool_t uturn = kFALSE;
+  Bool_t trackingFailed = kFALSE;
+  Bool_t tooManyStep = kFALSE;
   while (TMath::Abs(residue) > fgkRungeKuttaMaxResidue && stepNumber <= fgkMaxStepNumber) {
+    
     dZ = zEnd - trackParam->GetZ();
     // step lenght assuming linear trajectory
     step = dZ * TMath::Sqrt(1.0 + trackParam->GetBendingSlope()*trackParam->GetBendingSlope() +
                            trackParam->GetNonBendingSlope()*trackParam->GetNonBendingSlope());
     ConvertTrackParamForExtrap(trackParam, forwardBackward, v3);
+    
     do { // reduce step lenght while zEnd oversteped
       if (stepNumber > fgkMaxStepNumber) {
         cout<<"W-AliMUONTrackExtrap::ExtrapToZRungekutta: Too many trials: "<<stepNumber<<endl;
+       tooManyStep = kTRUE;
        break;
       }
       stepNumber ++;
       step = TMath::Abs(step);
-      AliMUONTrackExtrap::ExtrapOneStepRungekutta(chargeExtrap,step,v3,v3New);
+      if (!AliMUONTrackExtrap::ExtrapOneStepRungekutta(chargeExtrap,step,v3,v3New)) {
+       trackingFailed = kTRUE;
+       break;
+      }
       residue = zEnd - v3New[2];
       step *= dZ/(v3New[2]-trackParam->GetZ());
     } while (residue*dZ < 0 && TMath::Abs(residue) > fgkRungeKuttaMaxResidue);
-    RecoverTrackParam(v3New, chargeExtrap * forwardBackward, trackParam);
+    
+    if (trackingFailed) break;
+    else if (v3New[5]*v3[5] < 0) { // the track turned around
+      cout<<"W-AliMUONTrackExtrap::ExtrapToZRungekutta: The track turned around"<<endl;
+      uturn = kTRUE;
+      break;
+    } else RecoverTrackParam(v3New, chargeExtrap * forwardBackward, trackParam);
+    
   }
   
   // terminate the extropolation with a straight line up to the exact "zEnd" value
-  trackParam->SetNonBendingCoor(trackParam->GetNonBendingCoor() + residue * trackParam->GetNonBendingSlope());
-  trackParam->SetBendingCoor(trackParam->GetBendingCoor() + residue * trackParam->GetBendingSlope());
-  trackParam->SetZ(zEnd);
+  if (trackingFailed || uturn) {
+    
+    // track ends +-100 meters away in the bending direction
+    dZ = zEnd - v3[2];
+    Double_t bendingSlope = TMath::Sign(1.e4,-fgSimpleBValue*trackParam->GetInverseBendingMomentum()) / dZ;
+    Double_t pZ = TMath::Abs(1. / trackParam->GetInverseBendingMomentum()) / TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
+    Double_t nonBendingSlope = TMath::Sign(TMath::Abs(v3[3]) * v3[6] / pZ, trackParam->GetNonBendingSlope());
+    trackParam->SetNonBendingCoor(trackParam->GetNonBendingCoor() + dZ * nonBendingSlope);
+    trackParam->SetNonBendingSlope(nonBendingSlope);
+    trackParam->SetBendingCoor(trackParam->GetBendingCoor() + dZ * bendingSlope);
+    trackParam->SetBendingSlope(bendingSlope);
+    trackParam->SetZ(zEnd);
+    
+    return kFALSE;
+    
+  } else {
+    
+    // track extrapolated normally
+    trackParam->SetNonBendingCoor(trackParam->GetNonBendingCoor() + residue * trackParam->GetNonBendingSlope());
+    trackParam->SetBendingCoor(trackParam->GetBendingCoor() + residue * trackParam->GetBendingSlope());
+    trackParam->SetZ(zEnd);
+    
+    return !tooManyStep;
+    
+  }
+  
 }
 
 //__________________________________________________________________________
@@ -254,26 +331,30 @@ void AliMUONTrackExtrap::RecoverTrackParam(Double_t *v3, Double_t charge, AliMUO
   trackParam->SetNonBendingCoor(v3[0]); // X
   trackParam->SetBendingCoor(v3[1]); // Y
   trackParam->SetZ(v3[2]); // Z
-  Double_t pYZ = v3[6] * TMath::Sqrt(1.0 - v3[3] * v3[3]);
+  Double_t pYZ = v3[6] * TMath::Sqrt((1.-v3[3])*(1.+v3[3]));
   trackParam->SetInverseBendingMomentum(charge/pYZ);
   trackParam->SetBendingSlope(v3[4]/v3[5]);
   trackParam->SetNonBendingSlope(v3[3]/v3[5]);
 }
 
 //__________________________________________________________________________
-void AliMUONTrackExtrap::ExtrapToZCov(AliMUONTrackParam* trackParam, Double_t zEnd, Bool_t updatePropagator)
+Bool_t AliMUONTrackExtrap::ExtrapToZCov(AliMUONTrackParam* trackParam, Double_t zEnd, Bool_t updatePropagator)
 {
   /// Track parameters and their covariances extrapolated to the plane at "zEnd".
   /// On return, results from the extrapolation are updated in trackParam.
   
-  if (trackParam->GetZ() == zEnd) return; // nothing to be done if same z
+  if (trackParam->GetZ() == zEnd) return kTRUE; // nothing to be done if same z
+  
+  if (!fgFieldON) { // linear extrapolation if no magnetic field
+    AliMUONTrackExtrap::LinearExtrapToZCov(trackParam,zEnd,updatePropagator);
+    return kTRUE;
+  }
   
   // No need to propagate the covariance matrix if it does not exist
   if (!trackParam->CovariancesExist()) {
     cout<<"W-AliMUONTrackExtrap::ExtrapToZCov: Covariance matrix does not exist"<<endl;
     // Extrapolate track parameters to "zEnd"
-    ExtrapToZ(trackParam,zEnd);
-    return;
+    return ExtrapToZ(trackParam,zEnd);
   }
   
   // Save the actual track parameters
@@ -285,15 +366,18 @@ void AliMUONTrackExtrap::ExtrapToZCov(AliMUONTrackParam* trackParam, Double_t zE
   const TMatrixD& kParamCov = trackParam->GetCovariances();
        
   // Extrapolate track parameters to "zEnd"
-  ExtrapToZ(trackParam,zEnd);
+  // Do not update the covariance matrix if the extrapolation failed
+  if (!ExtrapToZ(trackParam,zEnd)) return kFALSE;
   
   // Get reference to the extrapolated parameters
   const TMatrixD& extrapParam = trackParam->GetParameters();
   
   // Calculate the jacobian related to the track parameters extrapolation to "zEnd"
+  Bool_t extrapStatus = kTRUE;
   TMatrixD jacob(5,5);
   jacob.Zero();
   TMatrixD dParam(5,1);
+  Double_t direction[5] = {-1.,-1.,1.,1.,-1.};
   for (Int_t i=0; i<5; i++) {
     // Skip jacobian calculation for parameters with no associated error
     if (kParamCov(i,i) <= 0.) continue;
@@ -302,7 +386,7 @@ void AliMUONTrackExtrap::ExtrapToZCov(AliMUONTrackParam* trackParam, Double_t zE
     for (Int_t j=0; j<5; j++) {
       if (j==i) {
         dParam(j,0) = TMath::Sqrt(kParamCov(i,i));
-       if (j == 4) dParam(j,0) *= TMath::Sign(1.,-paramSave(4,0)); // variation always in the same direction
+       dParam(j,0) *= TMath::Sign(1.,direction[j]*paramSave(j,0)); // variation always in the same direction
       } else dParam(j,0) = 0.;
     }
     
@@ -312,7 +396,10 @@ void AliMUONTrackExtrap::ExtrapToZCov(AliMUONTrackParam* trackParam, Double_t zE
     trackParamSave.SetZ(zBegin);
     
     // Extrapolate new track parameters to "zEnd"
-    ExtrapToZ(&trackParamSave,zEnd);
+    if (!ExtrapToZ(&trackParamSave,zEnd)) {
+      cout<<"W-AliMUONTrackExtrap::ExtrapToZCov: Bad covariance matrix"<<endl;
+      extrapStatus = kFALSE;
+    }
     
     // Calculate the jacobian
     TMatrixD jacobji(trackParamSave.GetParameters(),TMatrixD::kMinus,extrapParam);
@@ -327,13 +414,15 @@ void AliMUONTrackExtrap::ExtrapToZCov(AliMUONTrackParam* trackParam, Double_t zE
   
   // Update the propagator if required
   if (updatePropagator) trackParam->UpdatePropagator(jacob);
+  
+  return extrapStatus;
 }
 
 //__________________________________________________________________________
-void AliMUONTrackExtrap::AddMCSEffectInAbsorber(AliMUONTrackParam* param, Double_t pathLength, Double_t f0, Double_t f1, Double_t f2)
+void AliMUONTrackExtrap::AddMCSEffectInAbsorber(AliMUONTrackParam* param, Double_t signedPathLength, Double_t f0, Double_t f1, Double_t f2)
 {
   /// Add to the track parameter covariances the effects of multiple Coulomb scattering
-  /// The absorber correction parameters are supposed to be calculated at the current track z-position
+  /// signedPathLength must have the sign of (zOut - zIn) where all other parameters are assumed to be given at zOut.
   
   // absorber related covariance parameters
   Double_t bendingSlope = param->GetBendingSlope();
@@ -341,15 +430,11 @@ void AliMUONTrackExtrap::AddMCSEffectInAbsorber(AliMUONTrackParam* param, Double
   Double_t inverseBendingMomentum = param->GetInverseBendingMomentum();
   Double_t alpha2 = 0.0136 * 0.0136 * inverseBendingMomentum * inverseBendingMomentum * (1.0 + bendingSlope * bendingSlope) /
                     (1.0 + bendingSlope *bendingSlope + nonBendingSlope * nonBendingSlope); // velocity = 1
+  Double_t pathLength = TMath::Abs(signedPathLength);
   Double_t varCoor = alpha2 * (pathLength * pathLength * f0 - 2. * pathLength * f1 + f2);
-  Double_t covCorrSlope = alpha2 * (pathLength * f0 - f1);
+  Double_t covCorrSlope = TMath::Sign(1.,signedPathLength) * alpha2 * (pathLength * f0 - f1);
   Double_t varSlop = alpha2 * f0;
   
-  // compute derivative d(q/Pxy) / dSlopeX and d(q/Pxy) / dSlopeX
-  Double_t dqPxydSlopeX = inverseBendingMomentum * nonBendingSlope / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
-  Double_t dqPxydSlopeY = - inverseBendingMomentum * nonBendingSlope*nonBendingSlope * bendingSlope /
-                            (1. + bendingSlope*bendingSlope) / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
-  
   // Set MCS covariance matrix
   TMatrixD newParamCov(param->GetCovariances());
   // Non bending plane
@@ -358,12 +443,20 @@ void AliMUONTrackExtrap::AddMCSEffectInAbsorber(AliMUONTrackParam* param, Double
   // Bending plane
   newParamCov(2,2) += varCoor;       newParamCov(2,3) += covCorrSlope;
   newParamCov(3,2) += covCorrSlope;  newParamCov(3,3) += varSlop;
-  // Inverse bending momentum (due to dependences with bending and non bending slopes)
-  newParamCov(4,0) += dqPxydSlopeX * covCorrSlope; newParamCov(0,4) += dqPxydSlopeX * covCorrSlope;
-  newParamCov(4,1) += dqPxydSlopeX * varSlop;      newParamCov(1,4) += dqPxydSlopeX * varSlop;
-  newParamCov(4,2) += dqPxydSlopeY * covCorrSlope; newParamCov(2,4) += dqPxydSlopeY * covCorrSlope;
-  newParamCov(4,3) += dqPxydSlopeY * varSlop;      newParamCov(3,4) += dqPxydSlopeY * varSlop;
-  newParamCov(4,4) += (dqPxydSlopeX*dqPxydSlopeX + dqPxydSlopeY*dqPxydSlopeY) * varSlop;
+  
+  // Set momentum related covariances if B!=0
+  if (fgFieldON) {
+    // compute derivative d(q/Pxy) / dSlopeX and d(q/Pxy) / dSlopeY
+    Double_t dqPxydSlopeX = inverseBendingMomentum * nonBendingSlope / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
+    Double_t dqPxydSlopeY = - inverseBendingMomentum * nonBendingSlope*nonBendingSlope * bendingSlope /
+                              (1. + bendingSlope*bendingSlope) / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
+    // Inverse bending momentum (due to dependences with bending and non bending slopes)
+    newParamCov(4,0) += dqPxydSlopeX * covCorrSlope; newParamCov(0,4) += dqPxydSlopeX * covCorrSlope;
+    newParamCov(4,1) += dqPxydSlopeX * varSlop;      newParamCov(1,4) += dqPxydSlopeX * varSlop;
+    newParamCov(4,2) += dqPxydSlopeY * covCorrSlope; newParamCov(2,4) += dqPxydSlopeY * covCorrSlope;
+    newParamCov(4,3) += dqPxydSlopeY * varSlop;      newParamCov(3,4) += dqPxydSlopeY * varSlop;
+    newParamCov(4,4) += (dqPxydSlopeX*dqPxydSlopeX + dqPxydSlopeY*dqPxydSlopeY) * varSlop;
+  }
   
   // Set new covariances
   param->SetCovariances(newParamCov);
@@ -383,12 +476,12 @@ void AliMUONTrackExtrap::CorrectMCSEffectInAbsorber(AliMUONTrackParam* param,
   // Position of the Branson plane (spectro. (z<0))
   Double_t zB = (f1>0.) ? absZBeg - f2/f1 : 0.;
   
-  // Add MCS effects to current parameter covariances
-  AddMCSEffectInAbsorber(param, pathLength, f0, f1, f2);
+  // Add MCS effects to current parameter covariances (spectro. (z<0))
+  AddMCSEffectInAbsorber(param, -pathLength, f0, f1, f2);
   
   // Get track parameters and covariances in the Branson plane corrected for magnetic field effect
   ExtrapToZCov(param,zVtx);
-  LinearExtrapToZ(param,zB);
+  LinearExtrapToZCov(param,zB);
   
   // compute track parameters at vertex
   TMatrixD newParam(5,1);
@@ -449,16 +542,21 @@ void AliMUONTrackExtrap::CorrectELossEffectInAbsorber(AliMUONTrackParam* param,
   TMatrixD newParamCov(param->GetCovariances());
   Cov2CovP(param->GetParameters(),newParamCov);
   
-  // Add effects of energy loss fluctuation to covariances
-  newParamCov(4,4) += sigmaELoss2;
-  
   // Compute new parameters corrected for energy loss
+  Double_t muMass = TDatabasePDG::Instance()->GetParticle("mu-")->Mass(); // GeV
+  Double_t p = param->P();
+  Double_t e = TMath::Sqrt(p*p + muMass*muMass);
+  Double_t eCorr = e + eLoss;
+  Double_t pCorr = TMath::Sqrt(eCorr*eCorr - muMass*muMass);
   Double_t nonBendingSlope = param->GetNonBendingSlope();
   Double_t bendingSlope = param->GetBendingSlope();
-  param->SetInverseBendingMomentum(param->GetCharge() / (param->P() + eLoss) *
+  param->SetInverseBendingMomentum(param->GetCharge() / pCorr *
                                   TMath::Sqrt(1.0 + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope) /
                                   TMath::Sqrt(1.0 + bendingSlope*bendingSlope));
   
+  // Add effects of energy loss fluctuation to covariances
+  newParamCov(4,4) += eCorr * eCorr / pCorr / pCorr * sigmaELoss2;
+  
   // Get new parameter covariances in (X, SlopeX, Y, SlopeY, q/Pyz) coordinate system
   CovP2Cov(param->GetParameters(),newParamCov);
   
@@ -515,8 +613,10 @@ Bool_t AliMUONTrackExtrap::GetAbsorberCorrectionParam(Double_t trackXYZIn[3], Do
   Double_t x0 = 0.;  // radiation-length (cm-1)
   Double_t atomicA = 0.; // A of material
   Double_t atomicZ = 0.; // Z of material
+  Double_t atomicZoverA = 0.; // Z/A of material
   Double_t localPathLength = 0;
   Double_t remainingPathLength = pathLength;
+  Double_t sigmaELoss = 0.;
   Double_t zB = trackXYZIn[2];
   Double_t zE, dzB, dzE;
   do {
@@ -524,9 +624,19 @@ Bool_t AliMUONTrackExtrap::GetAbsorberCorrectionParam(Double_t trackXYZIn[3], Do
     TGeoMaterial *material = currentnode->GetVolume()->GetMedium()->GetMaterial();
     rho = material->GetDensity();
     x0 = material->GetRadLen();
-    if (!material->IsMixture()) x0 /= rho; // different normalization in the modeler for mixture
     atomicA = material->GetA();
     atomicZ = material->GetZ();
+    if(material->IsMixture()){
+      TGeoMixture * mixture = (TGeoMixture*)material;
+      atomicZoverA = 0.;
+      Double_t sum = 0.;
+      for (Int_t iel=0;iel<mixture->GetNelements();iel++){
+       sum  += mixture->GetWmixt()[iel];
+       atomicZoverA += mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
+      }
+      atomicZoverA/=sum;
+    }
+    else atomicZoverA = atomicZ/atomicA;
     
     // Get path length within this material
     gGeoManager->FindNextBoundary(remainingPathLength);
@@ -561,8 +671,8 @@ Bool_t AliMUONTrackExtrap::GetAbsorberCorrectionParam(Double_t trackXYZIn[3], Do
     f1 += (dzE*dzE - dzB*dzB) / b[2] / b[2] / x0 / 2.;
     f2 += (dzE*dzE*dzE - dzB*dzB*dzB) / b[2] / b[2] / b[2] / x0 / 3.;
     meanRho += localPathLength * rho;
-    totalELoss += BetheBloch(pTotal, localPathLength, rho, atomicA, atomicZ);
-    sigmaELoss2 += EnergyLossFluctuation2(pTotal, localPathLength, rho, atomicA, atomicZ);
+    totalELoss += BetheBloch(pTotal, localPathLength, rho, atomicZ, atomicZoverA);
+    sigmaELoss += EnergyLossFluctuation(pTotal, localPathLength, rho, atomicZoverA);
     
     // prepare next step
     zB = zE;
@@ -570,6 +680,7 @@ Bool_t AliMUONTrackExtrap::GetAbsorberCorrectionParam(Double_t trackXYZIn[3], Do
   } while (remainingPathLength > TGeoShape::Tolerance());
   
   meanRho /= pathLength;
+  sigmaELoss2 = sigmaELoss*sigmaELoss;
   
   return kTRUE;
 }
@@ -600,8 +711,10 @@ Double_t AliMUONTrackExtrap::GetMCSAngle2(const AliMUONTrackParam& param, Double
 void AliMUONTrackExtrap::AddMCSEffect(AliMUONTrackParam *param, Double_t dZ, Double_t x0)
 {
   /// Add to the track parameter covariances the effects of multiple Coulomb scattering
-  /// through a material of thickness "dZ" and of radiation length "x0"
+  /// through a material of thickness "Abs(dZ)" and of radiation length "x0"
   /// assuming linear propagation and using the small angle approximation.
+  /// dZ = zOut - zIn (sign is important) and "param" is assumed to be given zOut.
+  /// If x0 <= 0., assume dZ = pathLength/x0 and consider the material thickness as negligible.
   
   Double_t bendingSlope = param->GetBendingSlope();
   Double_t nonBendingSlope = param->GetNonBendingSlope();
@@ -610,22 +723,17 @@ void AliMUONTrackExtrap::AddMCSEffect(AliMUONTrackParam *param, Double_t dZ, Dou
                                    (1.0 + bendingSlope * bendingSlope) /
                                    (1.0 + bendingSlope *bendingSlope + nonBendingSlope * nonBendingSlope); 
   // Path length in the material
-  Double_t pathLength = TMath::Abs(dZ) * TMath::Sqrt(1.0 + bendingSlope*bendingSlope + nonBendingSlope*nonBendingSlope);
-  Double_t pathLength2 = pathLength * pathLength;
+  Double_t signedPathLength = dZ * TMath::Sqrt(1.0 + bendingSlope*bendingSlope + nonBendingSlope*nonBendingSlope);
+  Double_t pathLengthOverX0 = (x0 > 0.) ? TMath::Abs(signedPathLength) / x0 : TMath::Abs(signedPathLength);
   // relativistic velocity
   Double_t velo = 1.;
   // Angular dispersion square of the track (variance) in a plane perpendicular to the trajectory
-  Double_t theta02 = 0.0136 / velo * (1 + 0.038 * TMath::Log(pathLength/x0));
-  theta02 *= theta02 * inverseTotalMomentum2 * pathLength / x0;
+  Double_t theta02 = 0.0136 / velo * (1 + 0.038 * TMath::Log(pathLengthOverX0));
+  theta02 *= theta02 * inverseTotalMomentum2 * pathLengthOverX0;
   
-  Double_t varCoor     = pathLength2 * theta02 / 3.;
+  Double_t varCoor     = (x0 > 0.) ? signedPathLength * signedPathLength * theta02 / 3. : 0.;
   Double_t varSlop     = theta02;
-  Double_t covCorrSlope = pathLength * theta02 / 2.;
-  
-  // compute derivative d(q/Pxy) / dSlopeX and d(q/Pxy) / dSlopeX
-  Double_t dqPxydSlopeX = inverseBendingMomentum * nonBendingSlope / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
-  Double_t dqPxydSlopeY = - inverseBendingMomentum * nonBendingSlope*nonBendingSlope * bendingSlope /
-                           (1. + bendingSlope*bendingSlope) / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
+  Double_t covCorrSlope = (x0 > 0.) ? signedPathLength * theta02 / 2. : 0.;
   
   // Set MCS covariance matrix
   TMatrixD newParamCov(param->GetCovariances());
@@ -635,12 +743,20 @@ void AliMUONTrackExtrap::AddMCSEffect(AliMUONTrackParam *param, Double_t dZ, Dou
   // Bending plane
   newParamCov(2,2) += varCoor;       newParamCov(2,3) += covCorrSlope;
   newParamCov(3,2) += covCorrSlope;  newParamCov(3,3) += varSlop;
-  // Inverse bending momentum (due to dependences with bending and non bending slopes)
-  newParamCov(4,0) += dqPxydSlopeX * covCorrSlope; newParamCov(0,4) += dqPxydSlopeX * covCorrSlope;
-  newParamCov(4,1) += dqPxydSlopeX * varSlop;      newParamCov(1,4) += dqPxydSlopeX * varSlop;
-  newParamCov(4,2) += dqPxydSlopeY * covCorrSlope; newParamCov(2,4) += dqPxydSlopeY * covCorrSlope;
-  newParamCov(4,3) += dqPxydSlopeY * varSlop;      newParamCov(3,4) += dqPxydSlopeY * varSlop;
-  newParamCov(4,4) += (dqPxydSlopeX*dqPxydSlopeX + dqPxydSlopeY*dqPxydSlopeY) * varSlop;
+  
+  // Set momentum related covariances if B!=0
+  if (fgFieldON) {
+    // compute derivative d(q/Pxy) / dSlopeX and d(q/Pxy) / dSlopeY
+    Double_t dqPxydSlopeX = inverseBendingMomentum * nonBendingSlope / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
+    Double_t dqPxydSlopeY = - inverseBendingMomentum * nonBendingSlope*nonBendingSlope * bendingSlope /
+                              (1. + bendingSlope*bendingSlope) / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
+    // Inverse bending momentum (due to dependences with bending and non bending slopes)
+    newParamCov(4,0) += dqPxydSlopeX * covCorrSlope; newParamCov(0,4) += dqPxydSlopeX * covCorrSlope;
+    newParamCov(4,1) += dqPxydSlopeX * varSlop;      newParamCov(1,4) += dqPxydSlopeX * varSlop;
+    newParamCov(4,2) += dqPxydSlopeY * covCorrSlope; newParamCov(2,4) += dqPxydSlopeY * covCorrSlope;
+    newParamCov(4,3) += dqPxydSlopeY * varSlop;      newParamCov(3,4) += dqPxydSlopeY * varSlop;
+    newParamCov(4,4) += (dqPxydSlopeX*dqPxydSlopeX + dqPxydSlopeY*dqPxydSlopeY) * varSlop;
+  }
   
   // Set new covariances
   param->SetCovariances(newParamCov);
@@ -713,8 +829,8 @@ void AliMUONTrackExtrap::ExtrapToVertex(AliMUONTrackParam* trackParam,
     trackXYZIn[2] = trackParamIn.GetZ();
   }
   Double_t pTot = trackParam->P();
-  Double_t pathLength, f0, f1, f2, meanRho, deltaP, sigmaDeltaP2;
-  if (!GetAbsorberCorrectionParam(trackXYZIn,trackXYZOut,pTot,pathLength,f0,f1,f2,meanRho,deltaP,sigmaDeltaP2)) {
+  Double_t pathLength, f0, f1, f2, meanRho, totalELoss, sigmaELoss2;
+  if (!GetAbsorberCorrectionParam(trackXYZIn,trackXYZOut,pTot,pathLength,f0,f1,f2,meanRho,totalELoss,sigmaELoss2)) {
     cout<<"E-AliMUONTrackExtrap::ExtrapToVertex: Unable to take into account the absorber effects"<<endl;
     if (trackParam->CovariancesExist()) ExtrapToZCov(trackParam,zVtx);
     else ExtrapToZ(trackParam,zVtx);
@@ -727,10 +843,10 @@ void AliMUONTrackExtrap::ExtrapToVertex(AliMUONTrackParam* trackParam,
     if (correctForEnergyLoss) {
       
       // Correct for multiple scattering and energy loss
-      CorrectELossEffectInAbsorber(trackParam, 0.5*deltaP, 0.5*sigmaDeltaP2);
+      CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
       CorrectMCSEffectInAbsorber(trackParam, xVtx, yVtx, zVtx, errXVtx, errYVtx,
                                 trackXYZIn[2], pathLength, f0, f1, f2);
-      CorrectELossEffectInAbsorber(trackParam, 0.5*deltaP, 0.5*sigmaDeltaP2);
+      CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
       
     } else {
       
@@ -744,16 +860,16 @@ void AliMUONTrackExtrap::ExtrapToVertex(AliMUONTrackParam* trackParam,
     if (correctForEnergyLoss) {
       
       // Correct for energy loss add multiple scattering dispersion in covariance matrix
-      CorrectELossEffectInAbsorber(trackParam, 0.5*deltaP, 0.5*sigmaDeltaP2);
-      AddMCSEffectInAbsorber(trackParam, pathLength, f0, f1, f2);
+      CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
+      AddMCSEffectInAbsorber(trackParam, -pathLength, f0, f1, f2); // (spectro. (z<0))
       ExtrapToZCov(trackParam, trackXYZIn[2]);
-      CorrectELossEffectInAbsorber(trackParam, 0.5*deltaP, 0.5*sigmaDeltaP2);
+      CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
       ExtrapToZCov(trackParam, zVtx);
       
     } else {
       
       // add multiple scattering dispersion in covariance matrix
-      AddMCSEffectInAbsorber(trackParam, pathLength, f0, f1, f2);
+      AddMCSEffectInAbsorber(trackParam, -pathLength, f0, f1, f2); // (spectro. (z<0))
       ExtrapToZCov(trackParam, zVtx);
       
     }
@@ -824,46 +940,47 @@ Double_t AliMUONTrackExtrap::TotalMomentumEnergyLoss(AliMUONTrackParam* trackPar
   Double_t pathLength, f0, f1, f2, meanRho, totalELoss, sigmaELoss2;
   GetAbsorberCorrectionParam(trackXYZIn,trackXYZOut,pTot,pathLength,f0,f1,f2,meanRho,totalELoss,sigmaELoss2);
   
-  return totalELoss;
+  // total momentum corrected for energy loss
+  Double_t muMass = TDatabasePDG::Instance()->GetParticle("mu-")->Mass(); // GeV
+  Double_t e = TMath::Sqrt(pTot*pTot + muMass*muMass);
+  Double_t eCorr = e + totalELoss;
+  Double_t pTotCorr = TMath::Sqrt(eCorr*eCorr - muMass*muMass);
+  
+  return pTotCorr - pTot;
 }
 
 //__________________________________________________________________________
-Double_t AliMUONTrackExtrap::BetheBloch(Double_t pTotal, Double_t pathLength, Double_t rho, Double_t atomicA, Double_t atomicZ)
+Double_t AliMUONTrackExtrap::BetheBloch(Double_t pTotal, Double_t pathLength, Double_t rho, Double_t atomicZ, Double_t atomicZoverA)
 {
   /// Returns the mean total momentum energy loss of muon with total momentum='pTotal'
   /// in the absorber layer of lenght='pathLength', density='rho', A='atomicA' and Z='atomicZ'
-  Double_t muMass = 0.105658369; // GeV
-  Double_t eMass = 0.510998918e-3; // GeV
-  Double_t k = 0.307075e-3; // GeV.g^-1.cm^2
-  Double_t i = 9.5e-9; // mean exitation energy per atomic Z (GeV)
-  Double_t p2=pTotal*pTotal;
-  Double_t beta2=p2/(p2 + muMass*muMass);
+  Double_t muMass = TDatabasePDG::Instance()->GetParticle("mu-")->Mass(); // GeV
   
-  Double_t w = k * rho * pathLength * atomicZ / atomicA / beta2;
+  // mean exitation energy (GeV)
+  Double_t i;
+  if (atomicZ < 13) i = (12. * atomicZ + 7.) * 1.e-9;
+  else i = (9.76 * atomicZ + 58.8 * TMath::Power(atomicZ,-0.19)) * 1.e-9;
   
-  if (beta2/(1-beta2)>3.5*3.5)
-    return w * (log(2.*eMass*3.5/(i*atomicZ)) + 0.5*log(beta2/(1-beta2)) - beta2);
-  
-  return w * (log(2.*eMass*beta2/(1-beta2)/(i*atomicZ)) - beta2);
+  return pathLength * rho * AliExternalTrackParam::BetheBlochGeant(pTotal/muMass, rho, 0.20, 3.00, i, atomicZoverA);
 }
 
 //__________________________________________________________________________
-Double_t AliMUONTrackExtrap::EnergyLossFluctuation2(Double_t pTotal, Double_t pathLength, Double_t rho, Double_t atomicA, Double_t atomicZ)
+Double_t AliMUONTrackExtrap::EnergyLossFluctuation(Double_t pTotal, Double_t pathLength, Double_t rho, Double_t atomicZoverA)
 {
   /// Returns the total momentum energy loss fluctuation of muon with total momentum='pTotal'
   /// in the absorber layer of lenght='pathLength', density='rho', A='atomicA' and Z='atomicZ'
-  Double_t muMass = 0.105658369; // GeV
+  Double_t muMass = TDatabasePDG::Instance()->GetParticle("mu-")->Mass(); // GeV
   //Double_t eMass = 0.510998918e-3; // GeV
   Double_t k = 0.307075e-3; // GeV.g^-1.cm^2
   Double_t p2=pTotal*pTotal;
   Double_t beta2=p2/(p2 + muMass*muMass);
   
-  Double_t fwhm = 2. * k * rho * pathLength * atomicZ / atomicA / beta2; // FWHM of the energy loss Landau distribution
-  Double_t sigma2 = fwhm * fwhm / (8.*log(2.)); // gaussian: fwmh = 2 * srqt(2*ln(2)) * sigma (i.e. fwmh = 2.35 * sigma)
+  Double_t fwhm = 2. * k * rho * pathLength * atomicZoverA / beta2; // FWHM of the energy loss Landau distribution
+  Double_t sigma = fwhm / TMath::Sqrt(8.*log(2.)); // gaussian: fwmh = 2 * srqt(2*ln(2)) * sigma (i.e. fwmh = 2.35 * sigma)
   
   //sigma2 = k * rho * pathLength * atomicZ / atomicA * eMass; // sigma2 of the energy loss gaussian distribution
   
-  return sigma2;
+  return sigma;
 }
 
 //__________________________________________________________________________
@@ -913,7 +1030,7 @@ void AliMUONTrackExtrap::CovP2Cov(const TMatrixD &param, TMatrixD &covP)
 }
 
  //__________________________________________________________________________
-void AliMUONTrackExtrap::ExtrapOneStepHelix(Double_t charge, Double_t step, Double_t *vect, Double_t *vout)
+void AliMUONTrackExtrap::ExtrapOneStepHelix(Double_t charge, Double_t step, const Double_t *vect, Double_t *vout)
 {
 /// <pre>
 ///    ******************************************************************
@@ -971,7 +1088,7 @@ void AliMUONTrackExtrap::ExtrapOneStepHelix(Double_t charge, Double_t step, Doub
     xyz[2]    = vect[kiz] + 0.5 * step * vect[kipz];
 
     //cmodif: call gufld (xyz, h) changed into:
-    GetField (xyz, h);
+    TGeoGlobalMagField::Instance()->Field(xyz,h);
  
     h2xy = h[0]*h[0] + h[1]*h[1];
     h[3] = h[2]*h[2]+ h2xy;
@@ -1032,7 +1149,7 @@ void AliMUONTrackExtrap::ExtrapOneStepHelix(Double_t charge, Double_t step, Doub
 }
 
  //__________________________________________________________________________
-void AliMUONTrackExtrap::ExtrapOneStepHelix3(Double_t field, Double_t step, Double_t *vect, Double_t *vout)
+void AliMUONTrackExtrap::ExtrapOneStepHelix3(Double_t field, Double_t step, const Double_t *vect, Double_t *vout)
 {
 /// <pre>
 ///    ******************************************************************
@@ -1110,7 +1227,7 @@ void AliMUONTrackExtrap::ExtrapOneStepHelix3(Double_t field, Double_t step, Doub
 }
 
  //__________________________________________________________________________
-void AliMUONTrackExtrap::ExtrapOneStepRungekutta(Double_t charge, Double_t step, Double_t* vect, Double_t* vout)
+Bool_t AliMUONTrackExtrap::ExtrapOneStepRungekutta(Double_t charge, Double_t step, const Double_t* vect, Double_t* vout)
 {
 /// <pre>
 ///    ******************************************************************
@@ -1137,7 +1254,8 @@ void AliMUONTrackExtrap::ExtrapOneStepRungekutta(Double_t charge, Double_t step,
 /// </pre>
 
     Double_t h2, h4, f[4];
-    Double_t xyzt[3], a, b, c, ph,ph2;
+    Double_t xyzt[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
+    Double_t a, b, c, ph,ph2;
     Double_t secxs[4],secys[4],seczs[4],hxp[3];
     Double_t g1, g2, g3, g4, g5, g6, ang2, dxt, dyt, dzt;
     Double_t est, at, bt, ct, cba;
@@ -1188,8 +1306,7 @@ void AliMUONTrackExtrap::ExtrapOneStepRungekutta(Double_t charge, Double_t step,
       rest  = step - tl;
       if (TMath::Abs(h) > TMath::Abs(rest)) h = rest;
       //cmodif: call gufld(vout,f) changed into:
-
-      GetField(vout,f);
+      TGeoGlobalMagField::Instance()->Field(vout,f);
 
       // *
       // *             start of integration
@@ -1233,7 +1350,7 @@ void AliMUONTrackExtrap::ExtrapOneStepRungekutta(Double_t charge, Double_t step,
       xyzt[2] = zt;
 
       //cmodif: call gufld(xyzt,f) changed into:
-      GetField(xyzt,f);
+      TGeoGlobalMagField::Instance()->Field(xyzt,f);
 
       at     = a + secxs[0];
       bt     = b + secys[0];
@@ -1270,7 +1387,7 @@ void AliMUONTrackExtrap::ExtrapOneStepRungekutta(Double_t charge, Double_t step,
       xyzt[2] = zt;
 
       //cmodif: call gufld(xyzt,f) changed into:
-      GetField(xyzt,f);
+      TGeoGlobalMagField::Instance()->Field(xyzt,f);
 
       z      = z + (c + (seczs[0] + seczs[1] + seczs[2]) * kthird) * h;
       y      = y + (b + (secys[0] + secys[1] + secys[2]) * kthird) * h;
@@ -1309,16 +1426,22 @@ void AliMUONTrackExtrap::ExtrapOneStepRungekutta(Double_t charge, Double_t step,
       vout[5] = cba*c;
       rest = step - tl;
       if (step < 0.) rest = -rest;
-      if (rest < 1.e-5*TMath::Abs(step)) return;
+      if (rest < 1.e-5*TMath::Abs(step)) return kTRUE;
 
     } while(1);
 
     // angle too big, use helix
+    cout<<"W-AliMUONTrackExtrap::ExtrapOneStepRungekutta: Ruge-Kutta failed: switch to helix"<<endl;
 
     f1  = f[0];
     f2  = f[1];
     f3  = f[2];
     f4  = TMath::Sqrt(f1*f1+f2*f2+f3*f3);
+    if (f4 < 1.e-10) {
+      cout<<"E-AliMUONTrackExtrap::ExtrapOneStepRungekutta: magnetic field at (";
+      cout<<xyzt[0]<<", "<<xyzt[1]<<", "<<xyzt[2]<<") = "<<f4<<": giving up"<<endl;
+      return kFALSE;
+    }
     rho = -f4*pinv;
     tet = rho * step;
  
@@ -1352,24 +1475,6 @@ void AliMUONTrackExtrap::ExtrapOneStepRungekutta(Double_t charge, Double_t step,
     vout[kipy] = vect[kipy] + g4*vect[kipy] + g5*hxp[1] + g6*f2;
     vout[kipz] = vect[kipz] + g4*vect[kipz] + g5*hxp[2] + g6*f3;
 
-    return;
+    return kTRUE;
 }
 
-//___________________________________________________________
-void  AliMUONTrackExtrap::GetField(Double_t *Position, Double_t *Field)
-{
-  /// interface for arguments in double precision (Why ? ChF)
-  Float_t x[3], b[3];
-  
-  x[0] = Position[0]; x[1] = Position[1]; x[2] = Position[2];
-  
-  if (fgkField) fgkField->Field(x,b);
-  else {
-    cout<<"F-AliMUONTrackExtrap::GetField: fgkField = 0x0"<<endl;
-    exit(-1);
-  }
-  
-  Field[0] = b[0]; Field[1] = b[1]; Field[2] = b[2];
-  
-  return;
-}