]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTrackParam.cxx
No effc++ warnings in RALICE
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackParam.cxx
index a7f73594207b01c239bb7394c4e05ed24a0050ad..139aeb1e3163ed25c417b0aac0fa102351f4886d 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.9  2000/10/16 15:30:40  gosset
-TotalMomentumEnergyLoss:
-correction for change in the absorber composition (JP Cussonneau)
-
-Revision 1.8  2000/10/02 21:28:09  fca
-Removal of useless dependecies via forward declarations
-
-Revision 1.7  2000/10/02 16:58:29  egangler
-Cleaning of the code :
--> coding conventions
--> void Streamers
--> some useless includes removed or replaced by "class" statement
-
-Revision 1.6  2000/09/19 09:49:50  gosset
-AliMUONEventReconstructor package
-* track extrapolation independent from reco_muon.F, use of AliMagF...
-* possibility to use new magnetic field (automatic from generated root file)
-
-Revision 1.5  2000/07/18 16:04:06  gosset
-AliMUONEventReconstructor package:
-* a few minor modifications and more comments
-* a few corrections
-  * right sign for Z of raw clusters
-  * right loop over chambers inside station
-  * symmetrized covariance matrix for measurements (TrackChi2MCS)
-  * right sign of charge in extrapolation (ExtrapToZ)
-  * right zEndAbsorber for Branson correction below 3 degrees
-* use of TVirtualFitter instead of TMinuit for AliMUONTrack::Fit
-* no parameter for AliMUONTrack::Fit() but more fit parameters in Track object
-
-Revision 1.4  2000/07/03 07:53:31  morsch
-Double declaration problem on HP solved.
-
-Revision 1.3  2000/06/30 10:15:48  gosset
-Changes to EventReconstructor...:
-precision fit with multiple Coulomb scattering;
-extrapolation to vertex with Branson correction in absorber (JPC)
-
-Revision 1.2  2000/06/15 07:58:49  morsch
-Code from MUON-dev joined
-
-Revision 1.1.2.3  2000/06/09 21:03:09  morsch
-Make includes consistent with new file structure.
-
-Revision 1.1.2.2  2000/06/09 12:58:05  gosset
-Removed comment beginnings in Log sections of .cxx files
-Suppressed most violations of coding rules
-
-Revision 1.1.2.1  2000/06/07 14:44:53  gosset
-Addition of files for track reconstruction in C++
-*/
-
-///////////////////////////////////////////////////
-//
-// Track parameters
-// in
-// ALICE
-// dimuon
-// spectrometer
-//
-///////////////////////////////////////////////////
-
-#include <iostream.h>
-
-#include "AliCallf77.h" 
-#include "AliMUON.h"
-#include "AliMUONTrackParam.h" 
-#include "AliMUONChamber.h"
-#include "AliRun.h" 
-#include "AliMagF.h" 
+/* $Id$ */
 
+//-----------------------------------------------------------------------------
+// Class AliMUONTrackParam
+//-------------------------
+// Track parameters in ALICE dimuon spectrometer
+//-----------------------------------------------------------------------------
+
+#include "AliMUONTrackParam.h"
+#include "AliMUONVCluster.h"
+
+#include "AliESDMuonTrack.h"
+#include "AliLog.h"
+
+#include <TMath.h>
+
+#include <Riostream.h>
+
+/// \cond CLASSIMP
 ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
+/// \endcond
+
+  //_________________________________________________________________________
+AliMUONTrackParam::AliMUONTrackParam()
+  : TObject(),
+    fZ(0.),
+    fParameters(5,1),
+    fCovariances(0x0),
+    fPropagator(0x0),
+    fExtrapParameters(0x0),
+    fExtrapCovariances(0x0),
+    fSmoothParameters(0x0),
+    fSmoothCovariances(0x0),
+    fClusterPtr(0x0),
+    fOwnCluster(kFALSE),
+    fRemovable(kFALSE),
+    fTrackChi2(0.),
+    fLocalChi2(0.)
+{
+  /// Constructor
+}
+
+  //_________________________________________________________________________
+AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& theMUONTrackParam)
+  : TObject(theMUONTrackParam),
+    fZ(theMUONTrackParam.fZ),
+    fParameters(theMUONTrackParam.fParameters),
+    fCovariances(0x0),
+    fPropagator(0x0),
+    fExtrapParameters(0x0),
+    fExtrapCovariances(0x0),
+    fSmoothParameters(0x0),
+    fSmoothCovariances(0x0),
+    fClusterPtr(0x0),
+    fOwnCluster(theMUONTrackParam.fOwnCluster),
+    fRemovable(theMUONTrackParam.fRemovable),
+    fTrackChi2(theMUONTrackParam.fTrackChi2),
+    fLocalChi2(theMUONTrackParam.fLocalChi2)
+{
+  /// Copy constructor
+  if (theMUONTrackParam.fCovariances) fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
+  if (theMUONTrackParam.fPropagator) fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
+  if (theMUONTrackParam.fExtrapParameters) fExtrapParameters = new TMatrixD(*(theMUONTrackParam.fExtrapParameters));
+  if (theMUONTrackParam.fExtrapCovariances) fExtrapCovariances = new TMatrixD(*(theMUONTrackParam.fExtrapCovariances));
+  if (theMUONTrackParam.fSmoothParameters) fSmoothParameters = new TMatrixD(*(theMUONTrackParam.fSmoothParameters));
+  if (theMUONTrackParam.fSmoothCovariances) fSmoothCovariances = new TMatrixD(*(theMUONTrackParam.fSmoothCovariances));
+  
+  if(fOwnCluster) fClusterPtr = static_cast<AliMUONVCluster*>(theMUONTrackParam.fClusterPtr->Clone());
+  else fClusterPtr = theMUONTrackParam.fClusterPtr;
+}
 
-  // A few calls in Fortran or from Fortran (extrap.F).
-  // Needed, instead of calls to Geant subroutines,
-  // because double precision is necessary for track fit converging with Minuit.
-  // The "extrap" functions should be translated into C++ ????
-#ifndef WIN32 
-# define extrap_onestep_helix extrap_onestep_helix_
-# define extrap_onestep_helix3 extrap_onestep_helix3_
-# define extrap_onestep_rungekutta extrap_onestep_rungekutta_
-# define gufld_double gufld_double_
-#else 
-# define extrap_onestep_helix EXTRAP_ONESTEP_HELIX
-# define extrap_onestep_helix3 EXTRAP_ONESTEP_HELIX3
-# define extrap_onestep_rungekutta EXTRAP_ONESTEP_RUNGEKUTTA
-# define gufld_double GUFLD_DOUBLE
-#endif 
-
-extern "C" {
-  void type_of_call extrap_onestep_helix
-  (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
-
-  void type_of_call extrap_onestep_helix3
-  (Double_t &Field, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
-
-  void type_of_call extrap_onestep_rungekutta
-  (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
-
-  void type_of_call gufld_double(Double_t *Position, Double_t *Field) {
-    // interface to "gAlice->Field()->Field" for arguments in double precision
-    Float_t x[3], b[3];
-    x[0] = Position[0]; x[1] = Position[1]; x[2] = Position[2];
-    gAlice->Field()->Field(x, b);
-    Field[0] = b[0]; Field[1] = b[1]; Field[2] = b[2];
+  //_________________________________________________________________________
+AliMUONTrackParam& AliMUONTrackParam::operator=(const AliMUONTrackParam& theMUONTrackParam)
+{
+  /// Asignment operator
+  if (this == &theMUONTrackParam)
+    return *this;
+
+  // base class assignement
+  TObject::operator=(theMUONTrackParam);
+
+  fZ = theMUONTrackParam.fZ; 
+  
+  fParameters = theMUONTrackParam.fParameters;
+  
+  if (theMUONTrackParam.fCovariances) {
+    if (fCovariances) *fCovariances = *(theMUONTrackParam.fCovariances);
+    else fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
+  } else {
+    delete fCovariances;
+    fCovariances = 0x0;
+  }
+  
+  if (theMUONTrackParam.fPropagator) {
+    if (fPropagator) *fPropagator = *(theMUONTrackParam.fPropagator);
+    else fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
+  } else {
+    delete fPropagator;
+    fPropagator = 0x0;
+  }
+  
+  if (theMUONTrackParam.fExtrapParameters) {
+    if (fExtrapParameters) *fExtrapParameters = *(theMUONTrackParam.fExtrapParameters);
+    else fExtrapParameters = new TMatrixD(*(theMUONTrackParam.fExtrapParameters));
+  } else {
+    delete fExtrapParameters;
+    fExtrapParameters = 0x0;
+  }
+  
+  if (theMUONTrackParam.fExtrapCovariances) {
+    if (fExtrapCovariances) *fExtrapCovariances = *(theMUONTrackParam.fExtrapCovariances);
+    else fExtrapCovariances = new TMatrixD(*(theMUONTrackParam.fExtrapCovariances));
+  } else {
+    delete fExtrapCovariances;
+    fExtrapCovariances = 0x0;
+  }
+  
+  if (theMUONTrackParam.fSmoothParameters) {
+    if (fSmoothParameters) *fSmoothParameters = *(theMUONTrackParam.fSmoothParameters);
+    else fSmoothParameters = new TMatrixD(*(theMUONTrackParam.fSmoothParameters));
+  } else {
+    delete fSmoothParameters;
+    fSmoothParameters = 0x0;
+  }
+  
+  if (theMUONTrackParam.fSmoothCovariances) {
+    if (fSmoothCovariances) *fSmoothCovariances = *(theMUONTrackParam.fSmoothCovariances);
+    else fSmoothCovariances = new TMatrixD(*(theMUONTrackParam.fSmoothCovariances));
+  } else {
+    delete fSmoothCovariances;
+    fSmoothCovariances = 0x0;
   }
+  
+  if (fOwnCluster) delete fClusterPtr;
+  fOwnCluster = theMUONTrackParam.fOwnCluster;
+  if(fOwnCluster) fClusterPtr = static_cast<AliMUONVCluster*>(theMUONTrackParam.fClusterPtr->Clone());
+  else fClusterPtr = theMUONTrackParam.fClusterPtr;
+  
+  fRemovable = theMUONTrackParam.fRemovable;
+  
+  fTrackChi2 = theMUONTrackParam.fTrackChi2;
+  fLocalChi2 = theMUONTrackParam.fLocalChi2;
+  
+  return *this;
+}
+
+  //__________________________________________________________________________
+AliMUONTrackParam::~AliMUONTrackParam()
+{
+/// Destructor
+  DeleteCovariances();
+  delete fPropagator;
+  delete fExtrapParameters;
+  delete fExtrapCovariances;
+  delete fSmoothParameters;
+  delete fSmoothCovariances;
+  if(fOwnCluster) delete fClusterPtr;
 }
 
   //__________________________________________________________________________
-void AliMUONTrackParam::ExtrapToZ(Double_t Z)
-{
-  // Track parameter extrapolation to the plane at "Z".
-  // On return, the track parameters resulting from the extrapolation
-  // replace the current track parameters.
-  if (this->fZ == Z) return; // nothing to be done if same Z
-  Double_t forwardBackward; // +1 if forward, -1 if backward
-  if (Z > this->fZ) forwardBackward = 1.0;
-  else forwardBackward = -1.0;
-  Double_t vGeant3[7], vGeant3New[7]; // 7 in parameter ????
-  Int_t iGeant3, stepNumber;
-  Int_t maxStepNumber = 5000; // in parameter ????
-  // For safety: return kTRUE or kFALSE ????
-  // Parameter vector for calling EXTRAP_ONESTEP
-  SetGeant3Parameters(vGeant3, forwardBackward);
-  // sign of charge (sign of fInverseBendingMomentum if forward motion)
-  // must be changed if backward extrapolation
-  Double_t chargeExtrap = forwardBackward *
-    TMath::Sign(Double_t(1.0), this->fInverseBendingMomentum);
-  Double_t stepLength = 6.0; // in parameter ????
-  // Extrapolation loop
-  stepNumber = 0;
-  while (((forwardBackward * (vGeant3[2] - Z)) <= 0.0) &&
-        (stepNumber < maxStepNumber)) {
-    stepNumber++;
-    // Option for switching between helix and Runge-Kutta ???? 
-    // extrap_onestep_rungekutta(chargeExtrap, stepLength, vGeant3, vGeant3New);
-    extrap_onestep_helix(chargeExtrap, stepLength, vGeant3, vGeant3New);
-    if ((forwardBackward * (vGeant3New[2] - Z)) > 0.0) break; // one is beyond Z
-    // better use TArray ????
-    for (iGeant3 = 0; iGeant3 < 7; iGeant3++)
-      {vGeant3[iGeant3] = vGeant3New[iGeant3];}
+void
+AliMUONTrackParam::Clear(Option_t* /*opt*/)
+{
+  /// clear memory
+  DeleteCovariances();
+  delete fPropagator; fPropagator = 0x0;
+  delete fExtrapParameters; fExtrapParameters = 0x0;
+  delete fExtrapCovariances; fExtrapCovariances = 0x0;
+  delete fSmoothParameters; fSmoothParameters = 0x0;
+  delete fSmoothCovariances; fSmoothCovariances = 0x0;
+  if(fOwnCluster) {
+    delete fClusterPtr; fClusterPtr = 0x0;
+  }
+}
+
+  //_________________________________________________________________________
+void AliMUONTrackParam::GetParamFrom(const AliESDMuonTrack& esdMuonTrack)
+{
+  /// Get parameters from ESD track
+  fZ = esdMuonTrack.GetZ(); 
+  fParameters(0,0) = esdMuonTrack.GetNonBendingCoor();
+  fParameters(1,0) = TMath::Tan(esdMuonTrack.GetThetaX());
+  fParameters(2,0) = esdMuonTrack.GetBendingCoor(); 
+  fParameters(3,0) = TMath::Tan(esdMuonTrack.GetThetaY());
+  fParameters(4,0) = esdMuonTrack.GetInverseBendingMomentum();
+}
+
+  //_________________________________________________________________________
+void AliMUONTrackParam::SetParamFor(AliESDMuonTrack& esdMuonTrack) const
+{
+  /// Set parameters in ESD track
+  esdMuonTrack.SetZ(fZ);
+  esdMuonTrack.SetNonBendingCoor(fParameters(0,0));
+  esdMuonTrack.SetThetaX(TMath::ATan(fParameters(1,0)));
+  esdMuonTrack.SetBendingCoor(fParameters(2,0)); 
+  esdMuonTrack.SetThetaY(TMath::ATan(fParameters(3,0)));
+  esdMuonTrack.SetInverseBendingMomentum(fParameters(4,0));
+}
+
+  //_________________________________________________________________________
+void AliMUONTrackParam::GetParamFromDCA(const AliESDMuonTrack& esdMuonTrack)
+{
+  /// Get parameters from ESD track
+  fZ = esdMuonTrack.GetZ(); 
+  fParameters(0,0) = esdMuonTrack.GetNonBendingCoorAtDCA();
+  fParameters(1,0) = TMath::Tan(esdMuonTrack.GetThetaXAtDCA());
+  fParameters(2,0) = esdMuonTrack.GetBendingCoorAtDCA(); 
+  fParameters(3,0) = TMath::Tan(esdMuonTrack.GetThetaYAtDCA());
+  fParameters(4,0) = esdMuonTrack.GetInverseBendingMomentumAtDCA();
+}
+
+  //_________________________________________________________________________
+void AliMUONTrackParam::SetParamForDCA(AliESDMuonTrack& esdMuonTrack) const
+{
+  /// Set parameters in ESD track
+  esdMuonTrack.SetNonBendingCoorAtDCA(fParameters(0,0));
+  esdMuonTrack.SetThetaXAtDCA(TMath::ATan(fParameters(1,0)));
+  esdMuonTrack.SetBendingCoorAtDCA(fParameters(2,0)); 
+  esdMuonTrack.SetThetaYAtDCA(TMath::ATan(fParameters(3,0)));
+  esdMuonTrack.SetInverseBendingMomentumAtDCA(fParameters(4,0));
+}
+
+//_________________________________________________________________________
+void AliMUONTrackParam::GetParamFromUncorrected(const AliESDMuonTrack& esdMuonTrack)
+{
+  /// Get parameters from ESD track
+  fZ = esdMuonTrack.GetZUncorrected(); 
+  fParameters(0,0) = esdMuonTrack.GetNonBendingCoorUncorrected();
+  fParameters(1,0) = TMath::Tan(esdMuonTrack.GetThetaXUncorrected());
+  fParameters(2,0) = esdMuonTrack.GetBendingCoorUncorrected(); 
+  fParameters(3,0) = TMath::Tan(esdMuonTrack.GetThetaYUncorrected());
+  fParameters(4,0) = esdMuonTrack.GetInverseBendingMomentumUncorrected();
+}
+
+//_________________________________________________________________________
+void AliMUONTrackParam::SetParamForUncorrected(AliESDMuonTrack& esdMuonTrack) const
+{
+  /// Set parameters in ESD track
+  esdMuonTrack.SetZUncorrected(fZ);
+  esdMuonTrack.SetNonBendingCoorUncorrected(fParameters(0,0));
+  esdMuonTrack.SetThetaXUncorrected(TMath::ATan(fParameters(1,0)));
+  esdMuonTrack.SetBendingCoorUncorrected(fParameters(2,0)); 
+  esdMuonTrack.SetThetaYUncorrected(TMath::ATan(fParameters(3,0)));
+  esdMuonTrack.SetInverseBendingMomentumUncorrected(fParameters(4,0));
+}
+
+//_________________________________________________________________________
+void AliMUONTrackParam::GetCovFrom(const AliESDMuonTrack& esdMuonTrack)
+{
+  /// Get parameters covariances from ESD track
+  
+  // Get ESD covariance matrix
+  if (!fCovariances) fCovariances = new TMatrixD(5,5);
+  esdMuonTrack.GetCovariances(*fCovariances);
+
+  // compute Jacobian to change the coordinate system
+  // from (X,thetaX,Y,thetaY,c/pYZ) to (X,slopeX,Y,slopeY,c/pYZ)
+  Double_t cosThetaX = TMath::Cos(TMath::ATan(fParameters(1,0)));
+  Double_t cosThetaY = TMath::Cos(TMath::ATan(fParameters(3,0)));
+  TMatrixD jacob(5,5);
+  jacob.Zero();
+  jacob(0,0) = 1.;
+  jacob(1,1) = 1. / cosThetaX / cosThetaX;
+  jacob(2,2) = 1.;
+  jacob(3,3) = 1. / cosThetaY / cosThetaY;
+  jacob(4,4) = 1.;
+  
+  // compute covariance matrix in ESD coordinate system
+  TMatrixD tmp(*fCovariances,TMatrixD::kMultTranspose,jacob);
+  *fCovariances = TMatrixD(jacob,TMatrixD::kMult,tmp);
+  
+}
+
+  //_________________________________________________________________________
+void AliMUONTrackParam::SetCovFor(AliESDMuonTrack& esdMuonTrack) const
+{
+  /// Set parameters covariances in ESD track
+  
+  // set null matrix if covariances does not exist
+  if (!fCovariances) {
+    TMatrixD tmp(5,5);
+    tmp.Zero();
+    esdMuonTrack.SetCovariances(tmp);
+    return;
   }
-  // check maxStepNumber ????
-  // Interpolation back to exact Z (2nd order)
-  // should be in function ???? using TArray ????
-  Double_t dZ12 = vGeant3New[2] - vGeant3[2]; // 1->2
-  Double_t dZ1i = Z - vGeant3[2]; // 1-i
-  Double_t dZi2 = vGeant3New[2] - Z; // i->2
-  Double_t xPrime = (vGeant3New[0] - vGeant3[0]) / dZ12;
-  Double_t xSecond =
-    ((vGeant3New[3] / vGeant3New[5]) - (vGeant3[3] / vGeant3[5])) / dZ12;
-  Double_t yPrime = (vGeant3New[1] - vGeant3[1]) / dZ12;
-  Double_t ySecond =
-    ((vGeant3New[4] / vGeant3New[5]) - (vGeant3[4] / vGeant3[5])) / dZ12;
-  vGeant3[0] = vGeant3[0] + xPrime * dZ1i - 0.5 * xSecond * dZ1i * dZi2; // X
-  vGeant3[1] = vGeant3[1] + yPrime * dZ1i - 0.5 * ySecond * dZ1i * dZi2; // Y
-  vGeant3[2] = Z; // Z
-  Double_t xPrimeI = xPrime - 0.5 * xSecond * (dZi2 - dZ1i);
-  Double_t yPrimeI = yPrime - 0.5 * ySecond * (dZi2 - dZ1i);
-  // (PX, PY, PZ)/PTOT assuming forward motion
-  vGeant3[5] =
-    1.0 / TMath::Sqrt(1.0 + xPrimeI * xPrimeI + yPrimeI * yPrimeI); // PZ/PTOT
-  vGeant3[3] = xPrimeI * vGeant3[5]; // PX/PTOT
-  vGeant3[4] = yPrimeI * vGeant3[5]; // PY/PTOT
-  // Track parameters from Geant3 parameters,
-  // with charge back for forward motion
-  GetFromGeant3Parameters(vGeant3, chargeExtrap * forwardBackward);
+  
+  // compute Jacobian to change the coordinate system
+  // from (X,slopeX,Y,slopeY,c/pYZ) to (X,thetaX,Y,thetaY,c/pYZ)
+  Double_t cosThetaX = TMath::Cos(TMath::ATan(fParameters(1,0)));
+  Double_t cosThetaY = TMath::Cos(TMath::ATan(fParameters(3,0)));
+  TMatrixD jacob(5,5);
+  jacob.Zero();
+  jacob(0,0) = 1.;
+  jacob(1,1) = cosThetaX * cosThetaX;
+  jacob(2,2) = 1.;
+  jacob(3,3) = cosThetaY * cosThetaY;
+  jacob(4,4) = 1.;
+  
+  // compute covariance matrix in ESD coordinate system
+  TMatrixD tmp(*fCovariances,TMatrixD::kMultTranspose,jacob);
+  TMatrixD tmp2(jacob,TMatrixD::kMult,tmp);
+  esdMuonTrack.SetCovariances(tmp2);
+
 }
 
   //__________________________________________________________________________
-void AliMUONTrackParam::SetGeant3Parameters(Double_t *VGeant3, Double_t ForwardBackward)
-{
-  // Set vector of Geant3 parameters pointed to by "VGeant3"
-  // from track parameters in current AliMUONTrackParam.
-  // Since AliMUONTrackParam is only geometry, one uses "ForwardBackward"
-  // to know whether the particle is going forward (+1) or backward (-1).
-  VGeant3[0] = this->fNonBendingCoor; // X
-  VGeant3[1] = this->fBendingCoor; // Y
-  VGeant3[2] = this->fZ; // Z
-  Double_t pYZ = TMath::Abs(1.0 / this->fInverseBendingMomentum);
-  Double_t pZ =
-    pYZ / TMath::Sqrt(1.0 + this->fBendingSlope * this->fBendingSlope);
-  VGeant3[6] =
-    TMath::Sqrt(pYZ * pYZ +
-               pZ * pZ * this->fNonBendingSlope * this->fNonBendingSlope); // PTOT
-  VGeant3[5] = ForwardBackward * pZ / VGeant3[6]; // PZ/PTOT
-  VGeant3[3] = this->fNonBendingSlope * VGeant3[5]; // PX/PTOT
-  VGeant3[4] = this->fBendingSlope * VGeant3[5]; // PY/PTOT
+Double_t AliMUONTrackParam::Px() const
+{
+  /// return p_x from track parameters
+  Double_t pYZ, pZ, pX;
+  pYZ = 0;
+  if (  TMath::Abs(fParameters(4,0)) > 0 )
+    pYZ = TMath::Abs(1.0 / fParameters(4,0));
+  pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
+  pX = pZ * fParameters(1,0); 
+  return pX;
 }
 
   //__________________________________________________________________________
-void AliMUONTrackParam::GetFromGeant3Parameters(Double_t *VGeant3, Double_t Charge)
+Double_t AliMUONTrackParam::Py() const
 {
-  // Get track parameters in current AliMUONTrackParam
-  // from Geant3 parameters pointed to by "VGeant3",
-  // assumed to be calculated for forward motion in Z.
-  // "InverseBendingMomentum" is signed with "Charge".
-  this->fNonBendingCoor = VGeant3[0]; // X
-  this->fBendingCoor = VGeant3[1]; // Y
-  this->fZ = VGeant3[2]; // Z
-  Double_t pYZ = VGeant3[6] * TMath::Sqrt(1.0 - VGeant3[3] * VGeant3[3]);
-  this->fInverseBendingMomentum = Charge / pYZ;
-  this->fBendingSlope = VGeant3[4] / VGeant3[5];
-  this->fNonBendingSlope = VGeant3[3] / VGeant3[5];
+  /// return p_y from track parameters
+  Double_t pYZ, pZ, pY;
+  pYZ = 0;
+  if (  TMath::Abs(fParameters(4,0)) > 0 )
+    pYZ = TMath::Abs(1.0 / fParameters(4,0));
+  pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
+  pY = pZ * fParameters(3,0); 
+  return pY;
 }
 
   //__________________________________________________________________________
-void AliMUONTrackParam::ExtrapToStation(Int_t Station, AliMUONTrackParam *TrackParam)
-{
-  // Track parameters extrapolated from current track parameters ("this")
-  // to both chambers of the station(0..) "Station"
-  // are returned in the array (dimension 2) of track parameters
-  // pointed to by "TrackParam" (index 0 and 1 for first and second chambers).
-  Double_t extZ[2], z1, z2;
-  Int_t i1 = -1, i2 = -1; // = -1 to avoid compilation warnings
-  AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
-  // range of Station to be checked ????
-  z1 = (&(pMUON->Chamber(2 * Station)))->Z(); // Z of first chamber
-  z2 = (&(pMUON->Chamber(2 * Station + 1)))->Z(); // Z of second chamber
-  // First and second Z to extrapolate at
-  if ((z1 > this->fZ) && (z2 > this->fZ)) {i1 = 0; i2 = 1;}
-  else if ((z1 < this->fZ) && (z2 < this->fZ)) {i1 = 1; i2 = 0;}
-  else {
-    cout << "ERROR in AliMUONTrackParam::CreateExtrapSegmentInStation" << endl;
-    cout << "Starting Z (" << this->fZ << ") in between z1 (" << z1 <<
-      ") and z2 (" << z2 << ") of station(0..) " << Station << endl;
-  }
-  extZ[i1] = z1;
-  extZ[i2] = z2;
-  // copy of track parameters
-  TrackParam[i1] = *this;
-  // first extrapolation
-  (&(TrackParam[i1]))->ExtrapToZ(extZ[0]);
-  TrackParam[i2] = TrackParam[i1];
-  // second extrapolation
-  (&(TrackParam[i2]))->ExtrapToZ(extZ[1]);
-  return;
+Double_t AliMUONTrackParam::Pz() const
+{
+  /// return p_z from track parameters
+  Double_t pYZ, pZ;
+  pYZ = 0;
+  if (  TMath::Abs(fParameters(4,0)) > 0 )
+    pYZ = TMath::Abs(1.0 / fParameters(4,0));
+  pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
+  return pZ;
 }
 
   //__________________________________________________________________________
-void AliMUONTrackParam::ExtrapToVertex()
+Double_t AliMUONTrackParam::P() const
 {
-  // Extrapolation to the vertex.
-  // Returns the track parameters resulting from the extrapolation,
-  // in the current TrackParam.
-  // Changes parameters according to Branson correction through the absorber 
+  /// return p from track parameters
+  Double_t  pYZ, pZ, p;
+  pYZ = 0;
+  if (  TMath::Abs(fParameters(4,0)) > 0 )
+    pYZ = TMath::Abs(1.0 / fParameters(4,0));
+  pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
+  p = TMath::Abs(pZ) * 
+    TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
+  return p;
   
-  Double_t zAbsorber = 503.0; // to be coherent with the Geant absorber geometry !!!!
-  // Extrapolates track parameters upstream to the "Z" end of the front absorber
-  ExtrapToZ(zAbsorber);
-    // Makes Branson correction (multiple scattering + energy loss)
-  BransonCorrection();
 }
 
   //__________________________________________________________________________
-void AliMUONTrackParam::BransonCorrection()
-{
-  // Branson correction of track parameters
-  // the entry parameters have to be calculated at the end of the absorber
-  Double_t zEndAbsorber, zBP, xBP, yBP;
-  Double_t  pYZ, pX, pY, pZ, pTotal, xEndAbsorber, yEndAbsorber, radiusEndAbsorber2, pT, theta;
-  Int_t sign;
-  // Would it be possible to calculate all that from Geant configuration ????
-  // and to get the Branson parameters from a function in ABSO module ????
-  // with an eventual contribution from other detectors like START ????
-  // Radiation lengths outer part theta > 3 degres
-  static Double_t x01[9] = { 18.8,    // C (cm)
-                            10.397,   // Concrete (cm)
-                            0.56,    // Plomb (cm)
-                            47.26,   // Polyethylene (cm)
-                            0.56,   // Plomb (cm)
-                            47.26,   // Polyethylene (cm)
-                            0.56,   // Plomb (cm)
-                            47.26,   // Polyethylene (cm)
-                            0.56 };   // Plomb (cm)
-  // inner part theta < 3 degres
-  static Double_t x02[3] = { 18.8,    // C (cm)
-                            10.397,   // Concrete (cm)
-                            0.35 };    // W (cm) 
-  // z positions of the materials inside the absober outer part theta > 3 degres
-  static Double_t z1[10] = { 90, 315, 467, 472, 477, 482, 487, 492, 497, 502 };
-  // inner part theta < 3 degres
-  static Double_t z2[4] = { 90, 315, 467, 503 };
-  static Bool_t first = kTRUE;
-  static Double_t zBP1, zBP2, rLimit;
-  // Calculates z positions of the Branson's planes: zBP1 for outer part and zBP2 for inner part (only at the first call)
-  if (first) {
-    first = kFALSE;
-    Double_t aNBP = 0.0;
-    Double_t aDBP = 0.0;
-    Int_t iBound;
-    
-    for (iBound = 0; iBound < 9; iBound++) {
-      aNBP = aNBP +
-       (z1[iBound+1] * z1[iBound+1] * z1[iBound+1] -
-        z1[iBound]   * z1[iBound]   * z1[iBound]    ) / x01[iBound];
-      aDBP = aDBP +
-       (z1[iBound+1] * z1[iBound+1] - z1[iBound]   * z1[iBound]    ) / x01[iBound];
-    }
-    zBP1 = (2.0 * aNBP) / (3.0 * aDBP);
-    aNBP = 0.0;
-    aDBP = 0.0;
-    for (iBound = 0; iBound < 3; iBound++) {
-      aNBP = aNBP +
-       (z2[iBound+1] * z2[iBound+1] * z2[iBound+1] -
-        z2[iBound]   * z2[iBound ]  * z2[iBound]    ) / x02[iBound];
-      aDBP = aDBP +
-       (z2[iBound+1] * z2[iBound+1] - z2[iBound] * z2[iBound]) / x02[iBound];
-    }
-    zBP2 = (2.0 * aNBP) / (3.0 * aDBP);
-    rLimit = z2[3] * TMath::Tan(3.0 * (TMath::Pi()) / 180.);
+const TMatrixD& AliMUONTrackParam::GetCovariances() const
+{
+  /// Return the covariance matrix (create it before if needed)
+  if (!fCovariances) {
+    fCovariances = new TMatrixD(5,5);
+    fCovariances->Zero();
   }
+  return *fCovariances;
+}
 
-  pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
-  sign = 1;      
-  if (fInverseBendingMomentum < 0) sign = -1;     
-  pZ = pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope)); 
-  pX = pZ * fNonBendingSlope; 
-  pY = pZ * fBendingSlope; 
-  pTotal = TMath::Sqrt(pYZ *pYZ + pX * pX);
-  xEndAbsorber = fNonBendingCoor; 
-  yEndAbsorber = fBendingCoor; 
-  radiusEndAbsorber2 = xEndAbsorber * xEndAbsorber + yEndAbsorber * yEndAbsorber;
-
-  if (radiusEndAbsorber2 > rLimit*rLimit) {
-    zEndAbsorber = z1[9];
-    zBP = zBP1;
-  } else {
-    zEndAbsorber = z2[3];
-    zBP = zBP2;
+  //__________________________________________________________________________
+void AliMUONTrackParam::SetCovariances(const TMatrixD& covariances)
+{
+  /// Set the covariance matrix
+  if (fCovariances) *fCovariances = covariances;
+  else fCovariances = new TMatrixD(covariances);
+}
+
+  //__________________________________________________________________________
+void AliMUONTrackParam::SetCovariances(const Double_t matrix[5][5])
+{
+  /// Set the covariance matrix
+  if (fCovariances) fCovariances->SetMatrixArray(&(matrix[0][0]));
+  else fCovariances = new TMatrixD(5,5,&(matrix[0][0]));
+}
+
+  //__________________________________________________________________________
+void AliMUONTrackParam::SetVariances(const Double_t matrix[5][5])
+{
+  /// Set the diagonal terms of the covariance matrix (variances)
+  if (!fCovariances) fCovariances = new TMatrixD(5,5);
+  fCovariances->Zero();
+  for (Int_t i=0; i<5; i++) (*fCovariances)(i,i) = matrix[i][i];
+}
+
+  //__________________________________________________________________________
+void AliMUONTrackParam::DeleteCovariances()
+{
+  /// Delete the covariance matrix
+  delete fCovariances;
+  fCovariances = 0x0;
+}
+
+  //__________________________________________________________________________
+const TMatrixD& AliMUONTrackParam::GetPropagator() const
+{
+  /// Return the propagator (create it before if needed)
+  if (!fPropagator) {
+    fPropagator = new TMatrixD(5,5);
+    fPropagator->UnitMatrix();
   }
+  return *fPropagator;
+}
 
-  xBP = xEndAbsorber - (pX / pZ) * (zEndAbsorber - zBP);
-  yBP = yEndAbsorber - (pY / pZ) * (zEndAbsorber - zBP);
+  //__________________________________________________________________________
+void AliMUONTrackParam::ResetPropagator()
+{
+  /// Reset the propagator
+  if (fPropagator) fPropagator->UnitMatrix();
+}
 
-  // new parameters after Branson and energy loss corrections
-  pZ = pTotal * zBP / TMath::Sqrt(xBP * xBP + yBP * yBP + zBP * zBP);
-  pX = pZ * xBP / zBP;
-  pY = pZ * yBP / zBP;
-  fBendingSlope = pY / pZ;
-  fNonBendingSlope = pX / pZ;
-  
-  pT = TMath::Sqrt(pX * pX + pY * pY);      
-  theta = TMath::ATan2(pT, pZ); 
-  pTotal =
-    TotalMomentumEnergyLoss(rLimit, pTotal, theta, xEndAbsorber, yEndAbsorber);
+  //__________________________________________________________________________
+void AliMUONTrackParam::UpdatePropagator(const TMatrixD& propagator)
+{
+  /// Update the propagator
+  if (fPropagator) *fPropagator = TMatrixD(propagator,TMatrixD::kMult,*fPropagator);
+  else fPropagator = new TMatrixD(propagator);
+}
 
-  fInverseBendingMomentum = (sign / pTotal) *
-    TMath::Sqrt(1.0 +
-               fBendingSlope * fBendingSlope +
-               fNonBendingSlope * fNonBendingSlope) /
-    TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope);
+  //__________________________________________________________________________
+const TMatrixD& AliMUONTrackParam::GetExtrapParameters() const
+{
+  /// Return extrapolated parameters (create it before if needed)
+  if (!fExtrapParameters) {
+    fExtrapParameters = new TMatrixD(5,1);
+    fExtrapParameters->Zero();
+  }
+  return *fExtrapParameters;
+  }
 
-  // vertex position at (0,0,0)
-  // should be taken from vertex measurement ???
-  fBendingCoor = 0.0;
-  fNonBendingCoor = 0;
-  fZ= 0;
+  //__________________________________________________________________________
+void AliMUONTrackParam::SetExtrapParameters(const TMatrixD& extrapParameters)
+{
+  /// Set extrapolated parameters
+  if (fExtrapParameters) *fExtrapParameters = extrapParameters;
+  else fExtrapParameters = new TMatrixD(extrapParameters);
 }
 
   //__________________________________________________________________________
-Double_t AliMUONTrackParam::TotalMomentumEnergyLoss(Double_t rLimit, Double_t pTotal, Double_t theta, Double_t xEndAbsorber, Double_t yEndAbsorber)
-{
-  // Returns the total momentum corrected from energy loss in the front absorber
-  Double_t deltaP, pTotalCorrected;
-
-  Double_t radiusEndAbsorber2 =
-    xEndAbsorber *xEndAbsorber + yEndAbsorber * yEndAbsorber;
-  // Parametrization to be redone according to change of absorber material ????
-  // See remark in function BransonCorrection !!!!
-  // The name is not so good, and there are many arguments !!!!
-  if (radiusEndAbsorber2 < rLimit * rLimit) {
-    if (pTotal < 15) {
-      deltaP = 2.737 + 0.0494 * pTotal - 0.001123 * pTotal * pTotal;
-    } else {
-      deltaP = 3.0643 + 0.01346 *pTotal;
-    }
-  } else {
-    if (pTotal < 15) {
-      deltaP  = 2.1380 + 0.0351 * pTotal - 0.000853 * pTotal * pTotal;
-    } else { 
-      deltaP = 2.407 + 0.00702 * pTotal;
-    }
+const TMatrixD& AliMUONTrackParam::GetExtrapCovariances() const
+{
+  /// Return the extrapolated covariance matrix (create it before if needed)
+  if (!fExtrapCovariances) {
+    fExtrapCovariances = new TMatrixD(5,5);
+    fExtrapCovariances->Zero();
+  }
+  return *fExtrapCovariances;
+  }
+
+  //__________________________________________________________________________
+void AliMUONTrackParam::SetExtrapCovariances(const TMatrixD& extrapCovariances)
+{
+  /// Set the extrapolated covariance matrix
+  if (fExtrapCovariances) *fExtrapCovariances = extrapCovariances;
+  else fExtrapCovariances = new TMatrixD(extrapCovariances);
+}
+
+  //__________________________________________________________________________
+const TMatrixD& AliMUONTrackParam::GetSmoothParameters() const
+{
+  /// Return the smoothed parameters (create it before if needed)
+  if (!fSmoothParameters) {
+    fSmoothParameters = new TMatrixD(5,1);
+    fSmoothParameters->Zero();
+  }
+  return *fSmoothParameters;
+  }
+
+  //__________________________________________________________________________
+void AliMUONTrackParam::SetSmoothParameters(const TMatrixD& smoothParameters)
+{
+  /// Set the smoothed parameters
+  if (fSmoothParameters) *fSmoothParameters = smoothParameters;
+  else fSmoothParameters = new TMatrixD(smoothParameters);
+}
+
+  //__________________________________________________________________________
+const TMatrixD& AliMUONTrackParam::GetSmoothCovariances() const
+{
+  /// Return the smoothed covariance matrix (create it before if needed)
+  if (!fSmoothCovariances) {
+    fSmoothCovariances = new TMatrixD(5,5);
+    fSmoothCovariances->Zero();
+  }
+  return *fSmoothCovariances;
+  }
+
+  //__________________________________________________________________________
+void AliMUONTrackParam::SetSmoothCovariances(const TMatrixD& smoothCovariances)
+{
+  /// Set the smoothed covariance matrix
+  if (fSmoothCovariances) *fSmoothCovariances = smoothCovariances;
+  else fSmoothCovariances = new TMatrixD(smoothCovariances);
+}
+
+//__________________________________________________________________________
+void AliMUONTrackParam::SetClusterPtr(AliMUONVCluster* cluster, Bool_t owner)
+{
+  /// set pointeur to associated cluster
+  if (fOwnCluster) delete fClusterPtr;
+  fClusterPtr = cluster;
+  fOwnCluster = owner;
+}
+
+  //__________________________________________________________________________
+Int_t AliMUONTrackParam::Compare(const TObject* trackParam) const
+{
+  /// "Compare" function to sort with decreasing Z (spectro. muon Z <0).
+  /// Returns 1 (0, -1) if the current Z
+  /// is smaller than (equal to, larger than) Z of trackParam
+  if (fZ < ((AliMUONTrackParam*)trackParam)->GetZ()) return(1);
+  else if (fZ == ((AliMUONTrackParam*)trackParam)->GetZ()) return(0);
+  else return(-1);
+}
+
+  //__________________________________________________________________________
+Bool_t AliMUONTrackParam::CompatibleTrackParam(const AliMUONTrackParam &trackParam, Double_t sigma2Cut, Double_t &chi2) const
+{
+  /// Return kTRUE if the two set of track parameters are compatible within sigma2Cut
+  /// Set chi2 to the compatible chi2 value
+  /// Note that parameter covariances must exist for at least one set of parameters
+  /// Note also that if parameters are not given at the same Z, results will be meaningless
+  
+  // reset chi2 value
+  chi2 = 0.;
+  
+  // ckeck covariance matrices
+  if (!fCovariances && !trackParam.fCovariances) {
+    AliError("Covariance matrix must exist for at least one set of parameters");
+    return kFALSE;
   }
-  deltaP = 0.88 * deltaP; // !!!! changes in the absorber composition ????
-  pTotalCorrected = pTotal + deltaP / TMath::Cos(theta);
-  return pTotalCorrected;
+  
+  Double_t maxChi2 = 5. * sigma2Cut * sigma2Cut; // 5 degrees of freedom
+  
+  // check Z parameters
+  if (fZ != trackParam.fZ)
+    AliWarning(Form("Parameters are given at different Z position (%le : %le): results are meaningless", fZ, trackParam.fZ));
+  
+  // compute the parameter residuals
+  TMatrixD deltaParam(fParameters, TMatrixD::kMinus, trackParam.fParameters);
+  
+  // build the error matrix
+  TMatrixD weight(5,5);
+  if (fCovariances) weight += *fCovariances;
+  if (trackParam.fCovariances) weight += *(trackParam.fCovariances);
+  
+  // invert the error matrix to get the parameter weights if possible
+  if (weight.Determinant() == 0) {
+    AliError("Cannot compute the compatibility chi2");
+    return kFALSE;
+  }
+  weight.Invert();
+  
+  // compute the compatibility chi2
+  TMatrixD tmp(deltaParam, TMatrixD::kTransposeMult, weight);
+  TMatrixD mChi2(tmp, TMatrixD::kMult, deltaParam);
+  
+  // set chi2 value
+  chi2 = mChi2(0,0);
+  
+  // check compatibility
+  if (chi2 > maxChi2) return kFALSE;
+  
+  return kTRUE;
 }
 
+  //__________________________________________________________________________
+void AliMUONTrackParam::Print(Option_t* opt) const
+{
+  /// Printing TrackParam information 
+  /// "full" option for printing all the information about the TrackParam
+  TString sopt(opt);
+  sopt.ToUpper();
+  if ( sopt.Contains("FULL") ) { 
+    cout << "<AliMUONTrackParam> Bending P=" << setw(5) << setprecision(3)  << 1./fParameters(4,0) << 
+      ", NonBendSlope=" << setw(5) << setprecision(3)  << fParameters(1,0)*180./TMath::Pi() <<
+      ", BendSlope=" << setw(5) << setprecision(3)     << fParameters(3,0)*180./TMath::Pi()  << 
+      ", (x,y,z)_IP=(" <<  setw(5) << setprecision(3) << fParameters(0,0) <<
+      "," <<  setw(5) << setprecision(3) << fParameters(2,0) <<
+      "," <<  setw(5) << setprecision(3) << fZ <<
+      ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << Px() <<
+      "," << setw(5) << setprecision(3) << Py() <<
+      "," << setw(5) << setprecision(3) << Pz() << ") GeV/c" << endl;
+  }
+  else {
+    cout << "<AliMUONTrackParam>"  << endl;
+  }
+    
+}