]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTrackExtrap.cxx
Bug fix for loading the LUT for chambers 1 to 6. (Indra)
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackExtrap.cxx
index 09bef71649ee2bc5019bcd51a75aa6f673e945f5..a9cc2a2f50040157782c04cc0dec0cd5ead692b8 100644 (file)
@@ -154,21 +154,24 @@ void AliMUONTrackExtrap::LinearExtrapToZCov(AliMUONTrackParam* trackParam, Doubl
 }
 
 //__________________________________________________________________________
-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 (!fgFieldON) AliMUONTrackExtrap::LinearExtrapToZ(trackParam,zEnd);
-  else 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;
@@ -214,14 +217,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;
@@ -232,17 +236,22 @@ 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 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 ++;
@@ -251,13 +260,42 @@ void AliMUONTrackExtrap::ExtrapToZRungekutta(AliMUONTrackParam* trackParam, Doub
       residue = zEnd - v3New[2];
       step *= dZ/(v3New[2]-trackParam->GetZ());
     } while (residue*dZ < 0 && TMath::Abs(residue) > fgkRungeKuttaMaxResidue);
-    RecoverTrackParam(v3New, chargeExtrap * forwardBackward, trackParam);
+    
+    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 (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;
+    
+  }
+  
 }
 
 //__________________________________________________________________________
@@ -293,24 +331,23 @@ void AliMUONTrackExtrap::RecoverTrackParam(Double_t *v3, Double_t charge, AliMUO
 }
 
 //__________________________________________________________________________
-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;
+    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
@@ -322,12 +359,14 @@ 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);
@@ -350,7 +389,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);
@@ -365,13 +407,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();
@@ -379,8 +423,9 @@ 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;
   
   // Set MCS covariance matrix
@@ -424,8 +469,8 @@ 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);
@@ -657,8 +702,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();
@@ -667,17 +714,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.;
+  Double_t covCorrSlope = (x0 > 0.) ? signedPathLength * theta02 / 2. : 0.;
   
   // Set MCS covariance matrix
   TMatrixD newParamCov(param->GetCovariances());
@@ -805,7 +852,7 @@ void AliMUONTrackExtrap::ExtrapToVertex(AliMUONTrackParam* trackParam,
       
       // Correct for energy loss add multiple scattering dispersion in covariance matrix
       CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
-      AddMCSEffectInAbsorber(trackParam, pathLength, f0, f1, f2);
+      AddMCSEffectInAbsorber(trackParam, -pathLength, f0, f1, f2); // (spectro. (z<0))
       ExtrapToZCov(trackParam, trackXYZIn[2]);
       CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
       ExtrapToZCov(trackParam, zVtx);
@@ -813,7 +860,7 @@ void AliMUONTrackExtrap::ExtrapToVertex(AliMUONTrackParam* trackParam,
     } 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);
       
     }