- Added track parameters at DCA in AliESDMuonTrack
[u/mrichter/AliRoot.git] / MUON / AliMUONTrack.cxx
index 8c539e9..718e2ea 100644 (file)
 
 /* $Id$ */
 
-///////////////////////////////////////////////////
-//
-// Reconstructed track
-// in
-// ALICE
-// dimuon
-// spectrometer
-//
-///////////////////////////////////////////////////
+//-----------------------------------------------------------------------------
+// Class AliMUONTrack
+//-------------------
+// Reconstructed track in ALICE dimuon spectrometer
+//-----------------------------------------------------------------------------
 
 #include "AliMUONTrack.h"
 
 #include "AliMUONTrackParam.h" 
-#include "AliMUONHitForRec.h" 
+#include "AliMUONRawClusterV2.h" 
+#include "AliMUONObjectPair.h" 
 #include "AliMUONConstants.h"
 #include "AliMUONTrackExtrap.h" 
 
 #include "AliLog.h"
+#include "AliESDMuonTrack.h"
+#include "AliESDMuonCluster.h"
 
 #include <TMath.h>
-#include <Riostream.h>
 #include <TMatrixD.h>
 
+#include <Riostream.h>
+
 /// \cond CLASSIMP
 ClassImp(AliMUONTrack) // Class implementation in ROOT context
 /// \endcond
 
-const Double_t AliMUONTrack::fgkMaxTrackingDistanceBending    = 2.;
-const Double_t AliMUONTrack::fgkMaxTrackingDistanceNonBending = 2.;
-
 //__________________________________________________________________________
 AliMUONTrack::AliMUONTrack()
   : TObject(),
-    fTrackParamAtVertex(),
-    fTrackParamAtHit(0x0),
-    fHitForRecAtHit(0x0),
-    fNTrackHits(0),
-    fExtrapTrackParam(),
+    fTrackParamAtCluster(new TClonesArray("AliMUONTrackParam",10)),
     fFitWithVertex(kFALSE),
-    fVertex(0x0),
-    fFitFMin(-1.),
-    fMatchTrigger(kFALSE),
+    fVertexErrXY2(),
+    fFitWithMCS(kFALSE),
+    fClusterWeightsNonBending(0x0),
+    fClusterWeightsBending(0x0),
+    fGlobalChi2(-1.),
+    fImproved(kFALSE),
+    fMatchTrigger(-1),
     floTrgNum(-1),
     fChi2MatchTrigger(0.),
-    fTrackID(0)
+    fTrackID(0),
+    fTrackParamAtVertex(0x0),
+    fHitsPatternInTrigCh(0),
+    fLocalTrigger(0)
 {
   /// Default constructor
+  fTrackParamAtCluster->SetOwner(kTRUE);
+  fVertexErrXY2[0] = 0.;
+  fVertexErrXY2[1] = 0.;
 }
 
   //__________________________________________________________________________
-AliMUONTrack::AliMUONTrack(AliMUONHitForRec* hitForRec1, AliMUONHitForRec* hitForRec2)
+AliMUONTrack::AliMUONTrack(AliMUONObjectPair *segment)
   : TObject(),
-    fTrackParamAtVertex(),
-    fTrackParamAtHit(0x0),
-    fHitForRecAtHit(0x0),
-    fNTrackHits(0),
-    fExtrapTrackParam(),
+    fTrackParamAtCluster(new TClonesArray("AliMUONTrackParam",10)),
     fFitWithVertex(kFALSE),
-    fVertex(0x0),
-    fFitFMin(-1.),
-    fMatchTrigger(kFALSE),
+    fVertexErrXY2(),
+    fFitWithMCS(kFALSE),
+    fClusterWeightsNonBending(0x0),
+    fClusterWeightsBending(0x0),
+    fGlobalChi2(0.),
+    fImproved(kFALSE),
+    fMatchTrigger(-1),
     floTrgNum(-1),    
     fChi2MatchTrigger(0.),
-    fTrackID(0)
+    fTrackID(0),
+    fTrackParamAtVertex(0x0),
+    fHitsPatternInTrigCh(0),
+    fLocalTrigger(0)
 {
-  /// Constructor from thw hitForRec's
-
-  fTrackParamAtHit = new TClonesArray("AliMUONTrackParam",10);
-  fHitForRecAtHit = new TClonesArray("AliMUONHitForRec",10);
+  /// Constructor from two clusters
+  fTrackParamAtCluster->SetOwner(kTRUE);
+  
+  fVertexErrXY2[0] = 0.;
+  fVertexErrXY2[1] = 0.;
   
-  if (!hitForRec1) return; //AZ
+  // Pointers to clusters from the segment
+  AliMUONVCluster* cluster1 = (AliMUONVCluster*) segment->First();
+  AliMUONVCluster* cluster2 = (AliMUONVCluster*) segment->Second();
   
-  // Add hits to the track
-  AddTrackParamAtHit(0,hitForRec1);
-  AddTrackParamAtHit(0,hitForRec2);
+  // check sorting in -Z (spectro z<0)
+  if (cluster1->GetZ() < cluster2->GetZ()) {
+    cluster1 = cluster2;
+    cluster2 = (AliMUONVCluster*) segment->First();
+  }
   
-  // sort TrackParamAtHit according to increasing -Z
-  fTrackParamAtHit->Sort();
+  // order the clusters into the track according to the station the segment belong to
+  //(the cluster first attached is the one from which we will start the tracking procedure)
+  AliMUONVCluster *firstCluster, *lastCluster;
+  if (cluster1->GetChamberId() == 8) {
+    firstCluster = cluster1;
+    lastCluster = cluster2;
+  } else {
+    firstCluster = cluster2;
+    lastCluster = cluster1;
+  }
   
-  // Set track parameters at first track hit
-  AliMUONTrackParam* trackParamAtFirstHit = (AliMUONTrackParam*) fTrackParamAtHit->First();
-  AliMUONHitForRec* firstHit = trackParamAtFirstHit->GetHitForRecPtr();
-  AliMUONHitForRec* lastHit = ((AliMUONTrackParam*) fTrackParamAtHit->Last())->GetHitForRecPtr();
-  Double_t dZ = firstHit->GetZ() - lastHit->GetZ();
+  // Compute track parameters
+  Double_t z1 = firstCluster->GetZ();
+  Double_t z2 = lastCluster->GetZ();
+  Double_t dZ = z1 - z2;
   // Non bending plane
-  Double_t nonBendingCoor = firstHit->GetNonBendingCoor();
-  trackParamAtFirstHit->SetNonBendingCoor(nonBendingCoor);
-  trackParamAtFirstHit->SetNonBendingSlope((nonBendingCoor - lastHit->GetNonBendingCoor()) / dZ);
+  Double_t nonBendingCoor1 = firstCluster->GetX();
+  Double_t nonBendingCoor2 = lastCluster->GetX();
+  Double_t nonBendingSlope = (nonBendingCoor1 - nonBendingCoor2) / dZ;
   // Bending plane
-  Double_t bendingCoor = firstHit->GetBendingCoor();
-  trackParamAtFirstHit->SetBendingCoor(bendingCoor);
-  Double_t bendingSlope = (bendingCoor - lastHit->GetBendingCoor()) / dZ;
-  trackParamAtFirstHit->SetBendingSlope(bendingSlope);
+  Double_t bendingCoor1 = firstCluster->GetY();
+  Double_t bendingCoor2 = lastCluster->GetY();
+  Double_t bendingSlope = (bendingCoor1 - bendingCoor2) / dZ;
   // Inverse bending momentum
-  Double_t bendingImpact = bendingCoor - firstHit->GetZ() * bendingSlope;
+  Double_t bendingImpact = bendingCoor1 - z1 * bendingSlope;
   Double_t inverseBendingMomentum = 1. / AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(bendingImpact);
-  trackParamAtFirstHit->SetInverseBendingMomentum(inverseBendingMomentum);
   
-  // Evaluate covariances
-  TMatrixD *paramCov = trackParamAtFirstHit->GetCovariances();
-  (*paramCov) = 0;
+  
+  // Set track parameters at first cluster
+  AliMUONTrackParam trackParamAtFirstCluster;
+  trackParamAtFirstCluster.SetZ(z1);
+  trackParamAtFirstCluster.SetNonBendingCoor(nonBendingCoor1);
+  trackParamAtFirstCluster.SetNonBendingSlope(nonBendingSlope);
+  trackParamAtFirstCluster.SetBendingCoor(bendingCoor1);
+  trackParamAtFirstCluster.SetBendingSlope(bendingSlope);
+  trackParamAtFirstCluster.SetInverseBendingMomentum(inverseBendingMomentum);
+  
+  
+  // Set track parameters at last cluster
+  AliMUONTrackParam trackParamAtLastCluster;
+  trackParamAtLastCluster.SetZ(z2);
+  trackParamAtLastCluster.SetNonBendingCoor(nonBendingCoor2);
+  trackParamAtLastCluster.SetNonBendingSlope(nonBendingSlope);
+  trackParamAtLastCluster.SetBendingCoor(bendingCoor2);
+  trackParamAtLastCluster.SetBendingSlope(bendingSlope);
+  trackParamAtLastCluster.SetInverseBendingMomentum(inverseBendingMomentum);
+  
+  
+  // Compute and set track parameters covariances at first cluster
+  TMatrixD paramCov1(5,5);
+  paramCov1.Zero();
   // Non bending plane
-  (*paramCov)(0,0) = firstHit->GetNonBendingReso2();
-  (*paramCov)(0,1) = firstHit->GetNonBendingReso2() / dZ;
-  (*paramCov)(1,0) = (*paramCov)(0,1);
-  (*paramCov)(1,1) = ( firstHit->GetNonBendingReso2() + lastHit->GetNonBendingReso2() ) / dZ / dZ;
+  paramCov1(0,0) = firstCluster->GetErrX2();
+  paramCov1(0,1) = firstCluster->GetErrX2() / dZ;
+  paramCov1(1,0) = paramCov1(0,1);
+  paramCov1(1,1) = ( firstCluster->GetErrX2() + lastCluster->GetErrX2() ) / dZ / dZ;
   // Bending plane
-  (*paramCov)(2,2) = firstHit->GetBendingReso2();
-  (*paramCov)(2,3) = firstHit->GetBendingReso2() / dZ;
-  (*paramCov)(3,2) = (*paramCov)(2,3);
-  (*paramCov)(3,3) = ( firstHit->GetBendingReso2() + lastHit->GetBendingReso2() ) / dZ / dZ;
+  paramCov1(2,2) = firstCluster->GetErrY2();
+  paramCov1(2,3) = firstCluster->GetErrY2() / dZ;
+  paramCov1(3,2) = paramCov1(2,3);
+  paramCov1(3,3) = ( firstCluster->GetErrY2() + lastCluster->GetErrY2() ) / dZ / dZ;
   // Inverse bending momentum (50% error)
-  (*paramCov)(4,4) = 0.5*inverseBendingMomentum * 0.5*inverseBendingMomentum;
+  paramCov1(4,4) = 0.5*inverseBendingMomentum * 0.5*inverseBendingMomentum;
+  // Set covariances
+  trackParamAtFirstCluster.SetCovariances(paramCov1);
+  
+  
+  // Compute and set track parameters covariances at last cluster (as if the first cluster did not exist)
+  TMatrixD paramCov2(5,5);
+  paramCov2.Zero();
+  // Non bending plane
+  paramCov2(0,0) = paramCov1(0,0);
+  paramCov2(1,1) = 100.*paramCov1(1,1);
+  // Bending plane
+  paramCov2(2,2) = paramCov1(2,2);
+  paramCov2(3,3) = 100.*paramCov1(3,3);
+  // Inverse bending momentum
+  paramCov2(4,4) = paramCov1(4,4);
+  // Set covariances
+  trackParamAtLastCluster.SetCovariances(paramCov2);
+  
+  // Flag clusters as being removable
+  trackParamAtFirstCluster.SetRemovable(kTRUE);
+  trackParamAtLastCluster.SetRemovable(kTRUE);
+  
+  // Add track parameters at clusters
+  AddTrackParamAtCluster(trackParamAtFirstCluster,*firstCluster);
+  AddTrackParamAtCluster(trackParamAtLastCluster,*lastCluster);
   
 }
 
-  //__________________________________________________________________________
-AliMUONTrack::~AliMUONTrack()
+//__________________________________________________________________________
+AliMUONTrack::AliMUONTrack(AliESDMuonTrack &esdTrack)
+  : TObject(),
+    fTrackParamAtCluster(new TClonesArray("AliMUONTrackParam",10)),
+    fFitWithVertex(kFALSE),
+    fVertexErrXY2(),
+    fFitWithMCS(kFALSE),
+    fClusterWeightsNonBending(0x0),
+    fClusterWeightsBending(0x0),
+    fGlobalChi2(esdTrack.GetChi2()),
+    fImproved(kFALSE),
+    fMatchTrigger(esdTrack.GetMatchTrigger()),
+    floTrgNum(-1),
+    fChi2MatchTrigger(esdTrack.GetChi2MatchTrigger()),
+    fTrackID(0),
+    fTrackParamAtVertex(new AliMUONTrackParam()),
+    fHitsPatternInTrigCh(esdTrack.GetHitsPatternInTrigCh()),
+    fLocalTrigger(0)
 {
-  /// Destructor
-  if (fTrackParamAtHit) {
-    // delete the TClonesArray of pointers to TrackParam
-    delete fTrackParamAtHit;
-    fTrackParamAtHit = 0x0;
-  }
-
-  if (fHitForRecAtHit) {
-    // delete the TClonesArray of pointers to HitForRec
-    delete fHitForRecAtHit;
-    fHitForRecAtHit = 0x0;
+  /// Constructor from ESD muon track
+  /// Compute track parameters and covariances at each cluster if available
+  /// or store parameters and covariances at first (fake) cluster only if not
+  
+  fTrackParamAtCluster->SetOwner(kTRUE);
+  
+  fVertexErrXY2[0] = 0.;
+  fVertexErrXY2[1] = 0.;
+  
+  // global info
+  SetLocalTrigger(esdTrack.LoCircuit(), esdTrack.LoStripX(), esdTrack.LoStripY(),
+                 esdTrack.LoDev(), esdTrack.LoLpt(), esdTrack.LoHpt());
+  
+  // track parameters at vertex
+  fTrackParamAtVertex->GetParamFrom(esdTrack);
+  
+  // track parameters at first cluster
+  AliMUONTrackParam param;
+  param.GetParamFromUncorrected(esdTrack);
+  param.GetCovFrom(esdTrack);
+  
+  // fill fTrackParamAtCluster with track parameters at each cluster if available
+  if(esdTrack.ClustersStored()) {
+    
+    AliMUONRawClusterV2 cluster;
+    
+    // loop over ESD clusters
+    AliESDMuonCluster *esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().First();
+    while (esdCluster) {
+      
+      // copy cluster information
+      cluster.SetUniqueID(esdCluster->GetUniqueID());
+      cluster.SetXYZ(esdCluster->GetX(), esdCluster->GetY(), esdCluster->GetZ());
+      cluster.SetErrXY(esdCluster->GetErrX(), esdCluster->GetErrY());
+      
+      // only set the Z parameter to avoid error in the AddTrackParamAtCluster(...) method
+      param.SetZ(cluster.GetZ());
+      
+      // add common track parameters at current cluster
+      AddTrackParamAtCluster(param, cluster, kTRUE);
+      
+      esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().After(esdCluster);
+    }
+    
+    // sort array of track parameters at clusters
+    fTrackParamAtCluster->Sort();
+    
+    // check that parameters stored in ESD are parameters at the most upstream cluster
+    // (convert Z position values to Float_t because of Double32_t in ESD track)
+    AliMUONTrackParam *firstTrackParam = (AliMUONTrackParam*) fTrackParamAtCluster->First();
+    if (((Float_t)firstTrackParam->GetZ()) != ((Float_t)esdTrack.GetZUncorrected())) {
+      
+      AliError("track parameters are not given at the most upstream stored cluster");
+      fTrackParamAtCluster->Clear("C");
+      
+    } else {
+      
+      // Compute track parameters and covariances at each cluster from info at the first one
+      UpdateCovTrackParamAtCluster();
+      
+    }
+    
   }
   
-  if (fVertex) {
-    // delete the vertex used during the tracking procedure
-    delete fVertex;
-    fVertex = 0x0;
+  // fill fTrackParamAtCluster with track parameters at first (fake) cluster
+  // if first cluster not found or clusters not available
+  if (GetNClusters() == 0) {
+    
+    // get number of the first hit chamber (according to the MUONClusterMap if not empty)
+    Int_t firstCh = 0;
+    if (esdTrack.GetMuonClusterMap() != 0) while (!esdTrack.IsInMuonClusterMap(firstCh)) firstCh++;
+    else firstCh = AliMUONConstants::ChamberNumber(param.GetZ());
+    
+    // produce fake cluster at this chamber
+    AliMUONRawClusterV2 fakeCluster(firstCh, 0, 0);
+    fakeCluster.SetXYZ(param.GetNonBendingCoor(), param.GetBendingCoor(), param.GetZ());
+    fakeCluster.SetErrXY(0., 0.);
+    
+    // add track parameters at first (fake) cluster
+    AddTrackParamAtCluster(param, fakeCluster, kTRUE);
+    
   }
+  
 }
 
-  //__________________________________________________________________________
-AliMUONTrack::AliMUONTrack (const AliMUONTrack& theMUONTrack)
-  : TObject(theMUONTrack),
-    fTrackParamAtVertex(theMUONTrack.fTrackParamAtVertex),
-    fTrackParamAtHit(0x0),
-    fHitForRecAtHit(0x0),
-    fNTrackHits(theMUONTrack.fNTrackHits),
-    fExtrapTrackParam(theMUONTrack.fExtrapTrackParam),
-    fFitWithVertex(theMUONTrack.fFitWithVertex),
-    fVertex(0x0),
-    fFitFMin(theMUONTrack.fFitFMin),
-    fMatchTrigger(theMUONTrack.fMatchTrigger),
-    floTrgNum(theMUONTrack.floTrgNum),    
-    fChi2MatchTrigger(theMUONTrack.fChi2MatchTrigger),
-    fTrackID(theMUONTrack.fTrackID)
+//__________________________________________________________________________
+AliMUONTrack::AliMUONTrack(const AliMUONTrack& track)
+  : TObject(track),
+    fTrackParamAtCluster(new TClonesArray("AliMUONTrackParam",10)),
+    fFitWithVertex(track.fFitWithVertex),
+    fVertexErrXY2(),
+    fFitWithMCS(track.fFitWithMCS),
+    fClusterWeightsNonBending(0x0),
+    fClusterWeightsBending(0x0),
+    fGlobalChi2(track.fGlobalChi2),
+    fImproved(track.fImproved),
+    fMatchTrigger(track.fMatchTrigger),
+    floTrgNum(track.floTrgNum),    
+    fChi2MatchTrigger(track.fChi2MatchTrigger),
+    fTrackID(track.fTrackID),
+    fTrackParamAtVertex(0x0),
+    fHitsPatternInTrigCh(track.fHitsPatternInTrigCh),
+    fLocalTrigger(track.fLocalTrigger)
 {
   ///copy constructor
-  Int_t maxIndex = 0;
   
   // necessary to make a copy of the objects and not only the pointers in TClonesArray.
-  if (theMUONTrack.fTrackParamAtHit) {
-    maxIndex = (theMUONTrack.fTrackParamAtHit)->GetEntriesFast();
-    fTrackParamAtHit = new TClonesArray("AliMUONTrackParam",maxIndex);
-    for (Int_t index = 0; index < maxIndex; index++) {
-      new ((*fTrackParamAtHit)[index]) AliMUONTrackParam(*(AliMUONTrackParam*)theMUONTrack.fTrackParamAtHit->At(index));
-    }
+  AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*) track.fTrackParamAtCluster->First();
+  while (trackParamAtCluster) {
+    new ((*fTrackParamAtCluster)[GetNClusters()]) AliMUONTrackParam(*trackParamAtCluster);
+    trackParamAtCluster = (AliMUONTrackParam*) track.fTrackParamAtCluster->After(trackParamAtCluster);
   }
   
-  // necessary to make a copy of the objects and not only the pointers in TClonesArray.
-  if (theMUONTrack.fHitForRecAtHit) {
-    maxIndex = (theMUONTrack.fHitForRecAtHit)->GetEntriesFast();
-    fHitForRecAtHit = new TClonesArray("AliMUONHitForRec",maxIndex);
-    for (Int_t index = 0; index < maxIndex; index++) {
-      new ((*fHitForRecAtHit)[index]) AliMUONHitForRec(*(AliMUONHitForRec*)theMUONTrack.fHitForRecAtHit->At(index));
-    }
-  }
+  // copy vertex resolution square used during the tracking procedure
+  fVertexErrXY2[0] = track.fVertexErrXY2[0];
+  fVertexErrXY2[1] = track.fVertexErrXY2[1];
+  
+  // copy cluster weights matrices if any
+  if (track.fClusterWeightsNonBending) fClusterWeightsNonBending = new TMatrixD(*(track.fClusterWeightsNonBending));
+  if (track.fClusterWeightsBending) fClusterWeightsBending = new TMatrixD(*(track.fClusterWeightsBending));
   
-  // copy vertex used during the tracking procedure if any
-  if (theMUONTrack.fVertex) fVertex = new AliMUONHitForRec(*(theMUONTrack.fVertex));
+  // copy track parameters at vertex if any
+  if (track.fTrackParamAtVertex) fTrackParamAtVertex = new AliMUONTrackParam(*(track.fTrackParamAtVertex));
   
 }
 
   //__________________________________________________________________________
-AliMUONTrack & AliMUONTrack::operator=(const AliMUONTrack& theMUONTrack)
+AliMUONTrack & AliMUONTrack::operator=(const AliMUONTrack& track)
 {
   /// Asignment operator
   // check assignement to self
-  if (this == &theMUONTrack)
+  if (this == &track)
     return *this;
 
   // base class assignement
-  TObject::operator=(theMUONTrack);
+  TObject::operator=(track);
 
-  fTrackParamAtVertex = theMUONTrack.fTrackParamAtVertex;
-
-  Int_t maxIndex = 0;
-  
   // necessary to make a copy of the objects and not only the pointers in TClonesArray.
-  if (theMUONTrack.fTrackParamAtHit) {
-    if (fTrackParamAtHit) fTrackParamAtHit->Clear();
-    else fTrackParamAtHit = new TClonesArray("AliMUONTrackParam",10);
-    maxIndex = (theMUONTrack.fTrackParamAtHit)->GetEntriesFast();
-    for (Int_t index = 0; index < maxIndex; index++) {
-      new ((*fTrackParamAtHit)[fTrackParamAtHit->GetEntriesFast()])
-       AliMUONTrackParam(*(AliMUONTrackParam*)(theMUONTrack.fTrackParamAtHit)->At(index));
-    }
-  } else if (fTrackParamAtHit) {
-    delete fTrackParamAtHit;
-    fTrackParamAtHit = 0x0;
+  fTrackParamAtCluster = new TClonesArray("AliMUONTrackParam",10);
+  AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*) track.fTrackParamAtCluster->First();
+  while (trackParamAtCluster) {
+    new ((*fTrackParamAtCluster)[GetNClusters()]) AliMUONTrackParam(*trackParamAtCluster);
+    trackParamAtCluster = (AliMUONTrackParam*) track.fTrackParamAtCluster->After(trackParamAtCluster);
   }
-
-  // necessary to make a copy of the objects and not only the pointers in TClonesArray.
-  if (theMUONTrack.fHitForRecAtHit) {
-    if (fHitForRecAtHit) fHitForRecAtHit->Clear();
-    else fHitForRecAtHit = new TClonesArray("AliMUONHitForRec",10);
-    maxIndex = (theMUONTrack.fHitForRecAtHit)->GetEntriesFast();
-    for (Int_t index = 0; index < maxIndex; index++) {
-      new ((*fHitForRecAtHit)[fHitForRecAtHit->GetEntriesFast()])
-       AliMUONHitForRec(*(AliMUONHitForRec*)(theMUONTrack.fHitForRecAtHit)->At(index));
-    }
-  } else if (fHitForRecAtHit) {
-    delete fHitForRecAtHit;
-    fHitForRecAtHit = 0x0;
+  
+  // copy cluster weights matrix if any
+  if (track.fClusterWeightsNonBending) {
+    if (fClusterWeightsNonBending) {
+      fClusterWeightsNonBending->ResizeTo(*(track.fClusterWeightsNonBending));
+      *fClusterWeightsNonBending = *(track.fClusterWeightsNonBending);
+    } else fClusterWeightsNonBending = new TMatrixD(*(track.fClusterWeightsNonBending));
+  } else if (fClusterWeightsNonBending) {
+    delete fClusterWeightsNonBending;
+    fClusterWeightsNonBending = 0x0;
   }
   
-  // copy vertex used during the tracking procedure if any.
-  if (theMUONTrack.fVertex) {
-    if (fVertex) *fVertex = *(theMUONTrack.fVertex);
-    else fVertex = new AliMUONHitForRec(*(theMUONTrack.fVertex));
-  } else if (fVertex) {
-    delete fVertex;
-    fVertex = 0x0;
+  // copy cluster weights matrix if any
+  if (track.fClusterWeightsBending) {
+    if (fClusterWeightsBending) {
+      fClusterWeightsBending->ResizeTo(*(track.fClusterWeightsBending));
+      *fClusterWeightsBending = *(track.fClusterWeightsBending);
+    } else fClusterWeightsBending = new TMatrixD(*(track.fClusterWeightsBending));
+  } else if (fClusterWeightsBending) {
+    delete fClusterWeightsBending;
+    fClusterWeightsBending = 0x0;
   }
   
-  fExtrapTrackParam = theMUONTrack.fExtrapTrackParam;
+  // copy track parameters at vertex if any
+  if (track.fTrackParamAtVertex) {
+    if (fTrackParamAtVertex) *fTrackParamAtVertex = *(track.fTrackParamAtVertex);
+    else fTrackParamAtVertex = new AliMUONTrackParam(*(track.fTrackParamAtVertex));
+  } else if (fTrackParamAtVertex) {
+    delete fTrackParamAtVertex;
+    fTrackParamAtVertex = 0x0;
+  }
   
-  fNTrackHits         =  theMUONTrack.fNTrackHits;
-  fFitWithVertex      =  theMUONTrack.fFitWithVertex;
-  fFitFMin            =  theMUONTrack.fFitFMin;
-  fMatchTrigger       =  theMUONTrack.fMatchTrigger;
-  floTrgNum           =  theMUONTrack.floTrgNum;
-  fChi2MatchTrigger   =  theMUONTrack.fChi2MatchTrigger;
-  fTrackID            =  theMUONTrack.fTrackID;
+  fFitWithVertex      =  track.fFitWithVertex;
+  fVertexErrXY2[0]    =  track.fVertexErrXY2[0];
+  fVertexErrXY2[1]    =  track.fVertexErrXY2[1];
+  fFitWithMCS         =  track.fFitWithMCS;
+  fGlobalChi2         =  track.fGlobalChi2;
+  fImproved           =  track.fImproved;
+  fMatchTrigger       =  track.fMatchTrigger;
+  floTrgNum           =  track.floTrgNum;
+  fChi2MatchTrigger   =  track.fChi2MatchTrigger;
+  fTrackID            =  track.fTrackID; 
+  fHitsPatternInTrigCh = track.fHitsPatternInTrigCh;
+  fLocalTrigger        = track.fLocalTrigger;
 
   return *this;
 }
 
   //__________________________________________________________________________
-void AliMUONTrack::AddTrackParamAtHit(AliMUONTrackParam *trackParam, AliMUONHitForRec *hitForRec) 
+AliMUONTrack::~AliMUONTrack()
 {
-  /// Add TrackParamAtHit if "trackParam" != NULL
-  /// else create empty TrackParamAtHit and set the z position to the one of "hitForRec" if any
-  /// Update link to HitForRec if "hitForRec" != NULL
-  if (!fTrackParamAtHit) {
-    fTrackParamAtHit = new TClonesArray("AliMUONTrackParam",10);  
-    fNTrackHits = 0;
-  }
-  AliMUONTrackParam* trackParamAtHit;
-  if (trackParam) {
-    trackParamAtHit = new ((*fTrackParamAtHit)[fNTrackHits]) AliMUONTrackParam(*trackParam);
-    if (hitForRec) {
-      if (hitForRec->GetZ() != trackParam->GetZ())
-        AliWarning("Added track parameters at a different z position than the one of the attached hit");
-    }
-  } else {
-    trackParamAtHit = new ((*fTrackParamAtHit)[fNTrackHits]) AliMUONTrackParam();
-    if (hitForRec) ((AliMUONTrackParam*) fTrackParamAtHit->UncheckedAt(fNTrackHits))->SetZ(hitForRec->GetZ());
-  }
-  if (hitForRec) trackParamAtHit->SetHitForRecPtr(hitForRec);
-  fNTrackHits++;
+  /// Destructor
+  delete fTrackParamAtCluster;
+  delete fClusterWeightsNonBending;
+  delete fClusterWeightsBending;
+  delete fTrackParamAtVertex;
+}
+
+  //__________________________________________________________________________
+void AliMUONTrack::Clear(Option_t* opt)
+{
+  /// Clear arrays
+  fTrackParamAtCluster->Clear(opt);
+  delete fClusterWeightsNonBending; fClusterWeightsNonBending = 0x0;
+  delete fClusterWeightsBending; fClusterWeightsBending = 0x0;
+  delete fTrackParamAtVertex; fTrackParamAtVertex = 0x0;
 }
 
   //__________________________________________________________________________
-void AliMUONTrack::AddHitForRecAtHit(const AliMUONHitForRec *hitForRec) 
+void AliMUONTrack::AddTrackParamAtCluster(const AliMUONTrackParam &trackParam, AliMUONVCluster &cluster, Bool_t copy)
 {
-  /// Add hitForRec to the array of hitForRec at hit
-  if (!fHitForRecAtHit)
-    fHitForRecAtHit = new TClonesArray("AliMUONHitForRec",10); 
+  /// Copy given track parameters into a new TrackParamAtCluster
+  /// Link parameters with the associated cluster
+  /// If copy=kTRUE: the cluster is copied then passed the trackParam which become its owner 
+  ///     otherwise: make sure to do not delete the cluster until it is used by the track
   
-  if (!hitForRec)
-    AliFatal("AliMUONTrack::AddHitForRecAtHit: hitForRec == NULL");
+  // check chamber ID of the associated cluster
+  if (cluster.GetChamberId() < 0 || cluster.GetChamberId() > AliMUONConstants::NTrackingCh()) {
+    AliError(Form("Chamber ID of the associated cluster is not valid (ChamberId=%d)",cluster.GetChamberId()));
+    return;
+  }
+  
+  // check whether track parameters are given at the correct cluster z position
+  if (cluster.GetZ() != trackParam.GetZ()) {
+    AliError("track parameters are given at a different z position than the one of the associated cluster");
+    return;
+  }
   
-  new ((*fHitForRecAtHit)[fHitForRecAtHit->GetEntriesFast()]) AliMUONHitForRec(*hitForRec);
+  // add parameters to the array of track parameters
+  AliMUONTrackParam* trackParamAtCluster = new ((*fTrackParamAtCluster)[GetNClusters()]) AliMUONTrackParam(trackParam);
+  
+  // link parameters with the associated cluster or its copy
+  if (copy) {
+    AliMUONVCluster *clusterCopy = static_cast<AliMUONVCluster*>(cluster.Clone());
+    trackParamAtCluster->SetClusterPtr(clusterCopy, kTRUE);
+  } else trackParamAtCluster->SetClusterPtr(&cluster);
 }
 
   //__________________________________________________________________________
-void AliMUONTrack::SetVertex(AliMUONHitForRec* vertex)
+void AliMUONTrack::RemoveTrackParamAtCluster(AliMUONTrackParam *trackParam)
 {
-  /// Set the vertex used during the tracking procedure
-  if (!fVertex) fVertex = new AliMUONHitForRec(*vertex);
-  else *fVertex = *vertex;
+  /// Remove trackParam from the array of TrackParamAtCluster
+  if (!fTrackParamAtCluster->Remove(trackParam)) {
+    AliWarning("object to remove does not exist in array fTrackParamAtCluster");
+    return;
+  }
+  
+  fTrackParamAtCluster->Compress();
 }
 
   //__________________________________________________________________________
-Int_t AliMUONTrack::HitsInCommon(AliMUONTrack* track) const
+void AliMUONTrack::UpdateTrackParamAtCluster()
 {
-  /// Returns the number of hits in common between the current track ("this")
-  /// and the track pointed to by "track".
-  Int_t hitsInCommon = 0;
-  AliMUONTrackParam *trackParamAtHit1, *trackParamAtHit2;
-  // Loop over hits of first track
-  trackParamAtHit1 = (AliMUONTrackParam*) this->fTrackParamAtHit->First();
-  while (trackParamAtHit1) {
-    // Loop over hits of second track
-    trackParamAtHit2 = (AliMUONTrackParam*) track->fTrackParamAtHit->First();
-    while (trackParamAtHit2) {
-      // Increment "hitsInCommon" if both TrackParamAtHits point to the same HitForRec
-      if ((trackParamAtHit1->GetHitForRecPtr()) == (trackParamAtHit2->GetHitForRecPtr())) {
-        hitsInCommon++;
-       break;
-      }
-      trackParamAtHit2 = (AliMUONTrackParam*) track->fTrackParamAtHit->After(trackParamAtHit2);
-    } // trackParamAtHit2
-    trackParamAtHit1 = (AliMUONTrackParam*) this->fTrackParamAtHit->After(trackParamAtHit1);
-  } // trackParamAtHit1
-  return hitsInCommon;
+  /// Update track parameters at each attached cluster
+  
+  if (GetNClusters() == 0) {
+    AliWarning("no cluster attached to the track");
+    return;
+  }
+  
+  AliMUONTrackParam* startingTrackParam = (AliMUONTrackParam*) fTrackParamAtCluster->First();
+  AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) fTrackParamAtCluster->After(startingTrackParam);
+  while (trackParamAtCluster) {
+    
+    // reset track parameters and their covariances
+    trackParamAtCluster->SetParameters(startingTrackParam->GetParameters());
+    trackParamAtCluster->SetZ(startingTrackParam->GetZ());
+    
+    // extrapolation to the given z
+    AliMUONTrackExtrap::ExtrapToZ(trackParamAtCluster, trackParamAtCluster->GetClusterPtr()->GetZ());
+    
+    // prepare next step
+    startingTrackParam = trackParamAtCluster;
+    trackParamAtCluster = (AliMUONTrackParam*) (fTrackParamAtCluster->After(trackParamAtCluster));
+  }
+
 }
 
   //__________________________________________________________________________
-Bool_t* AliMUONTrack::CompatibleTrack(AliMUONTrack * track, Double_t sigma2Cut) const
+void AliMUONTrack::UpdateCovTrackParamAtCluster()
 {
-  /// Return kTRUE/kFALSE for each chamber if hit is compatible or not 
-  TClonesArray *hitArray, *thisHitArray;
-  AliMUONHitForRec *hit, *thisHit;
-  Int_t chamberNumber;
-  Float_t deltaZ;
-  Float_t deltaZMax = 1.; // 1 cm
-  Float_t chi2 = 0;
-  Bool_t *nCompHit = new Bool_t[AliMUONConstants::NTrackingCh()]; 
-
-  for ( Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
-    nCompHit[ch] = kFALSE;
+  /// Update track parameters and their covariances at each attached cluster
+  /// Include effects of multiple scattering in chambers
+  
+  if (GetNClusters() == 0) {
+    AliWarning("no cluster attached to the track");
+    return;
+  }
+  
+  AliMUONTrackParam* startingTrackParam = (AliMUONTrackParam*) fTrackParamAtCluster->First();
+  AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) fTrackParamAtCluster->After(startingTrackParam);
+  Int_t expectedChamber = startingTrackParam->GetClusterPtr()->GetChamberId() + 1;
+  Int_t currentChamber;
+  while (trackParamAtCluster) {
+    
+    // reset track parameters and their covariances
+    trackParamAtCluster->SetParameters(startingTrackParam->GetParameters());
+    trackParamAtCluster->SetZ(startingTrackParam->GetZ());
+    trackParamAtCluster->SetCovariances(startingTrackParam->GetCovariances());
+    
+    // add MCS effect
+    AliMUONTrackExtrap::AddMCSEffect(trackParamAtCluster,AliMUONConstants::ChamberThicknessInX0(),1.);
+    
+    // add MCS in missing chambers if any
+    currentChamber = trackParamAtCluster->GetClusterPtr()->GetChamberId();
+    while (currentChamber > expectedChamber) {
+      // extrapolation to the missing chamber
+      AliMUONTrackExtrap::ExtrapToZCov(trackParamAtCluster, AliMUONConstants::DefaultChamberZ(expectedChamber));
+      // add MCS effect
+      AliMUONTrackExtrap::AddMCSEffect(trackParamAtCluster,AliMUONConstants::ChamberThicknessInX0(),1.);
+      expectedChamber++;
+    }
+    
+    // extrapolation to the z of the current cluster
+    AliMUONTrackExtrap::ExtrapToZCov(trackParamAtCluster, trackParamAtCluster->GetClusterPtr()->GetZ());
+    
+    // prepare next step
+    expectedChamber = currentChamber + 1;
+    startingTrackParam = trackParamAtCluster;
+    trackParamAtCluster = (AliMUONTrackParam*) (fTrackParamAtCluster->After(trackParamAtCluster));
   }
+  
+}
 
-  thisHitArray = this->GetHitForRecAtHit();
-
-  hitArray =  track->GetHitForRecAtHit();
-
-  for (Int_t iHthis = 0; iHthis < thisHitArray->GetEntriesFast(); iHthis++) {
-    thisHit = (AliMUONHitForRec*) thisHitArray->At(iHthis);
-    chamberNumber = thisHit->GetChamberNumber();
-    if (chamberNumber < 0 || chamberNumber > AliMUONConstants::NTrackingCh()) continue; 
-    nCompHit[chamberNumber] = kFALSE;
-    for (Int_t iH = 0; iH < hitArray->GetEntriesFast(); iH++) {
-      hit = (AliMUONHitForRec*) hitArray->At(iH);
-      deltaZ = TMath::Abs(thisHit->GetZ() - hit->GetZ());
-      chi2 = thisHit->NormalizedChi2WithHitForRec(hit,sigma2Cut); // set cut to 4 sigmas
-      if (chi2 < 3. && deltaZ < deltaZMax) {
-       nCompHit[chamberNumber] = kTRUE;
-       break;
+  //__________________________________________________________________________
+Bool_t AliMUONTrack::ComputeLocalChi2(Bool_t accountForMCS)
+{
+  /// Compute each cluster contribution to the chi2 of the track
+  /// accounting for multiple scattering or not according to the flag
+  /// - Also recompute the weight matrices of the attached clusters if accountForMCS=kTRUE
+  /// - Assume that track parameters at each cluster are corrects
+  /// - Return kFALSE if computation failed
+  
+  if (accountForMCS) { // Compute local chi2 taking into account multiple scattering effects
+      
+    // Compute MCS covariance matrix only once
+    Int_t nClusters = GetNClusters();
+    TMatrixD mcsCovariances(nClusters,nClusters);
+    ComputeMCSCovariances(mcsCovariances);
+    
+    // Make sure cluster weights are consistent with following calculations
+    if (!ComputeClusterWeights(&mcsCovariances)) {
+      AliWarning("cannot take into account the multiple scattering effects");
+      return ComputeLocalChi2(kFALSE);
+    }
+    
+    // Compute chi2 of the track
+    Double_t globalChi2 = ComputeGlobalChi2(kTRUE);
+    if (globalChi2 < 0.) return kFALSE;
+    
+    // Loop over removable clusters and compute their local chi2
+    AliMUONTrackParam* trackParamAtCluster1;
+    AliMUONVCluster *cluster, *discardedCluster;
+    Int_t iCluster1, iCluster2, iCurrentCluster1, iCurrentCluster2;
+    TMatrixD clusterWeightsNB(nClusters-1,nClusters-1);
+    TMatrixD clusterWeightsB(nClusters-1,nClusters-1);
+    Double_t *dX = new Double_t[nClusters-1];
+    Double_t *dY = new Double_t[nClusters-1];
+    Double_t globalChi2b;
+    AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) fTrackParamAtCluster->First();
+    while (trackParamAtCluster) {
+      
+      discardedCluster = trackParamAtCluster->GetClusterPtr();
+      
+      // Recompute cluster weights without the current cluster
+      if (!ComputeClusterWeights(clusterWeightsNB, clusterWeightsB, &mcsCovariances, discardedCluster)) {
+       AliWarning("cannot take into account the multiple scattering effects");
+       delete [] dX;
+       delete [] dY;
+       return ComputeLocalChi2(kFALSE);
       }
-    }  
+      
+      // Compute track chi2 without the current cluster
+      globalChi2b = 0.;
+      iCurrentCluster1 = 0;
+      for (iCluster1 = 0; iCluster1 < nClusters ; iCluster1++) { 
+       trackParamAtCluster1 = (AliMUONTrackParam*) fTrackParamAtCluster->UncheckedAt(iCluster1);
+       cluster = trackParamAtCluster1->GetClusterPtr();
+        
+        if (cluster == discardedCluster) continue;
+        
+        // Compute and save residuals
+       dX[iCurrentCluster1] = cluster->GetX() - trackParamAtCluster1->GetNonBendingCoor();
+       dY[iCurrentCluster1] = cluster->GetY() - trackParamAtCluster1->GetBendingCoor();
+        
+        iCurrentCluster2 = 0;
+       for (iCluster2 = 0; iCluster2 < iCluster1; iCluster2++) {
+         cluster = ((AliMUONTrackParam*) fTrackParamAtCluster->UncheckedAt(iCluster2))->GetClusterPtr();
+          
+          if (cluster == discardedCluster) continue;
+          
+          // Add contribution from covariances
+          globalChi2b += (clusterWeightsNB(iCurrentCluster1, iCurrentCluster2) +
+                         clusterWeightsNB(iCurrentCluster2, iCurrentCluster1)) * dX[iCurrentCluster1] * dX[iCurrentCluster2] +
+                        (clusterWeightsB(iCurrentCluster1, iCurrentCluster2) +
+                         clusterWeightsB(iCurrentCluster2, iCurrentCluster1)) * dY[iCurrentCluster1] * dY[iCurrentCluster2];
+          
+          iCurrentCluster2++;
+       }
+        
+        // Add contribution from variances
+       globalChi2b += clusterWeightsNB(iCurrentCluster1, iCurrentCluster1) * dX[iCurrentCluster1] * dX[iCurrentCluster1] +
+                      clusterWeightsB(iCurrentCluster1, iCurrentCluster1) * dY[iCurrentCluster1] * dY[iCurrentCluster1];
+       
+        iCurrentCluster1++;
+      }
+
+      // Set local chi2
+      trackParamAtCluster->SetLocalChi2(globalChi2 - globalChi2b);
+      
+      trackParamAtCluster = (AliMUONTrackParam*) fTrackParamAtCluster->After(trackParamAtCluster);
+    }
+    
+    delete [] dX;
+    delete [] dY;
+    
+  } else { // without multiple scattering effects
+    
+    AliMUONVCluster *discardedCluster;
+    Double_t dX, dY;
+    AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) fTrackParamAtCluster->First();
+    while (trackParamAtCluster) {
+      
+      discardedCluster = trackParamAtCluster->GetClusterPtr();
+      
+      // Compute residuals
+      dX = discardedCluster->GetX() - trackParamAtCluster->GetNonBendingCoor();
+      dY = discardedCluster->GetY() - trackParamAtCluster->GetBendingCoor();
+      
+      // Set local chi2
+      trackParamAtCluster->SetLocalChi2(dX * dX / discardedCluster->GetErrX2() + dY * dY / discardedCluster->GetErrY2());
+    
+      trackParamAtCluster = (AliMUONTrackParam*) fTrackParamAtCluster->After(trackParamAtCluster);
+    }
+  
   }
   
-  return nCompHit;
+  return kTRUE;
+  
 }
 
   //__________________________________________________________________________
-Double_t AliMUONTrack::TryOneHitForRec(AliMUONHitForRec* hitForRec)
+Double_t AliMUONTrack::ComputeGlobalChi2(Bool_t accountForMCS)
 {
-/// Test the compatibility between the track and the hitForRec:
-/// return the corresponding Chi2
-  
-  // Get track parameters and their covariances at the z position of hitForRec
-  AliMUONTrackParam extrapTrackParam(fExtrapTrackParam);
-  AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam, hitForRec->GetZ());
-  
-  // Set differences between trackParam and hitForRec in the bending and non bending directions
-  TMatrixD dPos(2,1);
-  dPos(0,0) = hitForRec->GetNonBendingCoor() - extrapTrackParam.GetNonBendingCoor();
-  dPos(1,0) = hitForRec->GetBendingCoor() - extrapTrackParam.GetBendingCoor();
-  
-  // quick test of hitForRec compatibility within a wide road of x*y = 10*1 cm2 to save computing time
-  if (TMath::Abs(dPos(0,0)) > fgkMaxTrackingDistanceNonBending ||
-      TMath::Abs(dPos(1,0)) > fgkMaxTrackingDistanceBending) return 1.e10;
-  
-  // Set the error matrix from trackParam covariances and hitForRec resolution
-  TMatrixD* paramCov = extrapTrackParam.GetCovariances();
-  TMatrixD error(2,2);
-  error(0,0) = (*paramCov)(0,0) + hitForRec->GetNonBendingReso2();
-  error(0,1) = (*paramCov)(0,2);
-  error(1,0) = (*paramCov)(2,0);
-  error(1,1) = (*paramCov)(2,2) + hitForRec->GetBendingReso2();
-  
-  // Invert the error matrix for Chi2 calculation
-  if (error.Determinant() != 0) {
-    error.Invert();
+  /// Compute the chi2 of the track accounting for multiple scattering or not according to the flag
+  /// - Assume that track parameters at each cluster are corrects
+  /// - Assume the cluster weights matrices are corrects
+  /// - Return negative value if chi2 computation failed
+  
+  Double_t chi2 = 0.;
+  
+  if (accountForMCS) {
+    
+    // Check the weight matrices. If weight matrices are not available compute chi2 without MCS
+    if (!fClusterWeightsNonBending || !fClusterWeightsBending) {
+      AliWarning("cluster weights including multiple scattering effects are not available\n\t\t --> compute chi2 WITHOUT multiple scattering");
+      return ComputeGlobalChi2(kFALSE);
+    }
+    Int_t nClusters = GetNClusters();
+    if (fClusterWeightsNonBending->GetNrows() != nClusters || fClusterWeightsBending->GetNcols() != nClusters) {
+      AliWarning("cluster weights including multiple scattering effects are not available\n\t\t --> compute chi2 WITHOUT multiple scattering");
+      return ComputeGlobalChi2(kFALSE);
+    }
+    
+    // Compute chi2
+    AliMUONVCluster *cluster;
+    Double_t *dX = new Double_t[nClusters];
+    Double_t *dY = new Double_t[nClusters];
+    AliMUONTrackParam* trackParamAtCluster;
+    for (Int_t iCluster1 = 0; iCluster1 < nClusters; iCluster1++) { 
+      trackParamAtCluster = (AliMUONTrackParam*) fTrackParamAtCluster->UncheckedAt(iCluster1);
+      cluster = trackParamAtCluster->GetClusterPtr();
+      dX[iCluster1] = cluster->GetX() - trackParamAtCluster->GetNonBendingCoor();
+      dY[iCluster1] = cluster->GetY() - trackParamAtCluster->GetBendingCoor();
+      for (Int_t iCluster2 = 0; iCluster2 < iCluster1; iCluster2++) {
+        chi2 += ((*fClusterWeightsNonBending)(iCluster1, iCluster2) + (*fClusterWeightsNonBending)(iCluster2, iCluster1)) * dX[iCluster1] * dX[iCluster2] +
+               ((*fClusterWeightsBending)(iCluster1, iCluster2) + (*fClusterWeightsBending)(iCluster2, iCluster1)) * dY[iCluster1] * dY[iCluster2];
+      }
+      chi2 += ((*fClusterWeightsNonBending)(iCluster1, iCluster1) * dX[iCluster1] * dX[iCluster1]) +
+             ((*fClusterWeightsBending)(iCluster1, iCluster1) * dY[iCluster1] * dY[iCluster1]);
+    }
+    delete [] dX;
+    delete [] dY;
+    
   } else {
-    AliWarning(" Determinant error=0");
-    return 1.e10;
+    
+    AliMUONVCluster *cluster;
+    Double_t dX, dY;
+    AliMUONTrackParam* trackParamAtCluster;
+    Int_t nClusters = GetNClusters();
+    for (Int_t iCluster = 0; iCluster < nClusters ; iCluster++) { 
+      trackParamAtCluster = (AliMUONTrackParam*) fTrackParamAtCluster->UncheckedAt(iCluster);
+      cluster = trackParamAtCluster->GetClusterPtr();
+      dX = cluster->GetX() - trackParamAtCluster->GetNonBendingCoor();
+      dY = cluster->GetY() - trackParamAtCluster->GetBendingCoor();
+      chi2 += dX * dX / cluster->GetErrX2() + dY * dY / cluster->GetErrY2();
+    }
+    
   }
   
-  // Compute the Chi2 value
-  TMatrixD tmp(error,TMatrixD::kMult,dPos);
-  TMatrixD result(dPos,TMatrixD::kTransposeMult,tmp);
+  return chi2;
   
-  return result(0,0);
+}
+
+  //__________________________________________________________________________
+Bool_t AliMUONTrack::ComputeClusterWeights(TMatrixD* mcsCovariances)
+{
+  /// Compute the weight matrices of the attached clusters, in non bending and bending direction,
+  /// accounting for multiple scattering correlations and cluster resolution
+  /// - Use the provided MCS covariance matrix if any (otherwise build it temporarily)
+  /// - Assume that track parameters at each cluster are corrects
+  /// - Return kFALSE if computation failed
+  
+  // Alocate memory
+  Int_t nClusters = GetNClusters();
+  if (!fClusterWeightsNonBending) fClusterWeightsNonBending = new TMatrixD(nClusters,nClusters);
+  if (!fClusterWeightsBending) fClusterWeightsBending = new TMatrixD(nClusters,nClusters);
+  
+  // Compute weights matrices
+  if (!ComputeClusterWeights(*fClusterWeightsNonBending, *fClusterWeightsBending, mcsCovariances)) return kFALSE;
+  
+  return kTRUE;
   
 }
 
   //__________________________________________________________________________
-Double_t AliMUONTrack::TryTwoHitForRec(AliMUONHitForRec* hitForRec1, AliMUONHitForRec* hitForRec2)
+Bool_t AliMUONTrack::ComputeClusterWeights(TMatrixD& clusterWeightsNB, TMatrixD& clusterWeightsB,
+                                          TMatrixD* mcsCovariances, AliMUONVCluster* discardedCluster) const
 {
-/// Test the compatibility between the track and the 2 hitForRec together:
-/// return the corresponding Chi2 accounting for covariances between the 2 hitForRec
-  
-  // Get track parameters and their covariances at the z position of the first hitForRec
-  AliMUONTrackParam extrapTrackParam1(fExtrapTrackParam);
-  AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam1, hitForRec1->GetZ());
-  
-  // Get track parameters at second hitForRec
-  AliMUONTrackParam extrapTrackParam2(extrapTrackParam1);
-  AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam2, hitForRec2->GetZ());
-  
-  // Set differences between track and the 2 hitForRec in the bending and non bending directions
-  TMatrixD dPos(4,1);
-  dPos(0,0) = hitForRec1->GetNonBendingCoor() - extrapTrackParam1.GetNonBendingCoor();
-  dPos(1,0) = hitForRec1->GetBendingCoor() - extrapTrackParam1.GetBendingCoor();
-  dPos(2,0) = hitForRec2->GetNonBendingCoor() - extrapTrackParam2.GetNonBendingCoor();
-  dPos(3,0) = hitForRec2->GetBendingCoor() - extrapTrackParam2.GetBendingCoor();
-  
-  // quick tests of hitForRec compatibility within a wide road of x*y = 1*1 cm2 to save computing time
-  if (TMath::Abs(dPos(0,0)) > fgkMaxTrackingDistanceNonBending ||
-      TMath::Abs(dPos(1,0)) > fgkMaxTrackingDistanceBending    ||
-      TMath::Abs(dPos(2,0)) > fgkMaxTrackingDistanceNonBending ||
-      TMath::Abs(dPos(3,0)) > fgkMaxTrackingDistanceBending) return 1.e10;
-  
-  // Calculate the error matrix from the track parameter covariances at first hitForRec
-  TMatrixD error(4,4);
-  error = 0.;
-  if (extrapTrackParam1.CovariancesExist()) {
-    // Get the pointer to the parameter covariance matrix at first hitForRec
-    TMatrixD* paramCov = extrapTrackParam1.GetCovariances();
-    
-    // Save track parameters at first hitForRec
-    AliMUONTrackParam extrapTrackParam1Save(extrapTrackParam1);
-    Double_t nonBendingCoor1        = extrapTrackParam1Save.GetNonBendingCoor();
-    Double_t nonBendingSlope1       = extrapTrackParam1Save.GetNonBendingSlope();
-    Double_t bendingCoor1           = extrapTrackParam1Save.GetBendingCoor();
-    Double_t bendingSlope1          = extrapTrackParam1Save.GetBendingSlope();
-    Double_t inverseBendingMomentum1 = extrapTrackParam1Save.GetInverseBendingMomentum();
-    Double_t z1                             = extrapTrackParam1Save.GetZ();
-    
-    // Save track coordinates at second hitForRec
-    Double_t nonBendingCoor2        = extrapTrackParam2.GetNonBendingCoor();
-    Double_t bendingCoor2           = extrapTrackParam2.GetBendingCoor();
-    
-    // Calculate the jacobian related to the transformation between track parameters
-    // at first hitForRec and track coordinates at the 2 hitForRec z-position
-    TMatrixD jacob(4,5);
-    jacob = 0.;
-    // first derivative at the first hitForRec:
-    jacob(0,0) = 1.; // dx1/dx
-    jacob(1,2) = 1.; // dy1/dy
-    // first derivative at the second hitForRec:
-    Double_t dParam[5];
-    for (Int_t i=0; i<5; i++) {
-      // Skip jacobian calculation for parameters with no associated error
-      if ((*paramCov)(i,i) == 0.) continue;
-      // Small variation of parameter i only
-      for (Int_t j=0; j<5; j++) {
-        if (j==i) {
-          dParam[j] = TMath::Sqrt((*paramCov)(i,i));
-         if (j == 4) dParam[j] *= TMath::Sign(1.,-inverseBendingMomentum1); // variation always in the same direction
-        } else dParam[j] = 0.;
+  /// Compute the weight matrices, in non bending and bending direction,
+  /// of the other attached clusters assuming the discarded one does not exist
+  /// accounting for multiple scattering correlations and cluster resolution
+  /// - Use the provided MCS covariance matrix if any (otherwise build it temporarily)
+  /// - Return kFALSE if computation failed
+  
+  // Check MCS covariance matrix and recompute it if need
+  Int_t nClusters = GetNClusters();
+  Bool_t deleteMCSCov = kFALSE;
+  if (!mcsCovariances) {
+    mcsCovariances = new TMatrixD(nClusters,nClusters);
+    deleteMCSCov = kTRUE;
+    ComputeMCSCovariances(*mcsCovariances);
+  }
+  
+  // Resize the weights matrices; alocate memory
+  if (discardedCluster) {
+    clusterWeightsNB.ResizeTo(nClusters-1,nClusters-1);
+    clusterWeightsB.ResizeTo(nClusters-1,nClusters-1);
+  } else {
+    clusterWeightsNB.ResizeTo(nClusters,nClusters);
+    clusterWeightsB.ResizeTo(nClusters,nClusters);
+  }
+  
+  // Define variables
+  AliMUONVCluster *cluster1, *cluster2;
+  Int_t iCurrentCluster1, iCurrentCluster2;
+  
+  // Compute the covariance matrices
+  iCurrentCluster1 = 0;
+  for (Int_t iCluster1 = 0; iCluster1 < nClusters; iCluster1++) { 
+    cluster1 = ((AliMUONTrackParam*) fTrackParamAtCluster->UncheckedAt(iCluster1))->GetClusterPtr();
+    
+    if (cluster1 == discardedCluster) continue;
+    
+    // Loop over next clusters
+    iCurrentCluster2 = iCurrentCluster1;
+    for (Int_t iCluster2 = iCluster1; iCluster2 < nClusters; iCluster2++) {
+      cluster2 = ((AliMUONTrackParam*) fTrackParamAtCluster->UncheckedAt(iCluster2))->GetClusterPtr();
+      
+      if (cluster2 == discardedCluster) continue;
+      
+      // Fill with MCS covariances
+      clusterWeightsNB(iCurrentCluster1, iCurrentCluster2) = (*mcsCovariances)(iCluster1,iCluster2);
+      
+      // Equal contribution from multiple scattering in non bending and bending directions
+      clusterWeightsB(iCurrentCluster1, iCurrentCluster2) = clusterWeightsNB(iCurrentCluster1, iCurrentCluster2);
+      
+      // Add contribution from cluster resolution to diagonal element and symmetrize the matrix
+      if (iCurrentCluster1 == iCurrentCluster2) {
+       
+       // In non bending plane
+        clusterWeightsNB(iCurrentCluster1, iCurrentCluster1) += cluster1->GetErrX2();
+       // In bending plane
+       clusterWeightsB(iCurrentCluster1, iCurrentCluster1) += cluster1->GetErrY2();
+       
+      } else {
+       
+       // In non bending plane
+       clusterWeightsNB(iCurrentCluster2, iCurrentCluster1) = clusterWeightsNB(iCurrentCluster1, iCurrentCluster2);
+       // In bending plane
+       clusterWeightsB(iCurrentCluster2, iCurrentCluster1) = clusterWeightsB(iCurrentCluster1, iCurrentCluster2);
+       
       }
-      // Set new track parameters at first hitForRec
-      extrapTrackParam1Save.SetNonBendingCoor       (nonBendingCoor1         + dParam[0]);
-      extrapTrackParam1Save.SetNonBendingSlope      (nonBendingSlope1        + dParam[1]);
-      extrapTrackParam1Save.SetBendingCoor          (bendingCoor1            + dParam[2]);
-      extrapTrackParam1Save.SetBendingSlope         (bendingSlope1           + dParam[3]);
-      extrapTrackParam1Save.SetInverseBendingMomentum(inverseBendingMomentum1 + dParam[4]);
-      extrapTrackParam1Save.SetZ                    (z1);
-      // Extrapolate new track parameters to the z position of the second hitForRec
-      AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam1Save,hitForRec2->GetZ());
-      // Calculate the jacobian
-      jacob(2,i) = (extrapTrackParam1Save.GetNonBendingCoor()  - nonBendingCoor2) / dParam[i]; // dx2/dParami
-      jacob(3,i) = (extrapTrackParam1Save.GetBendingCoor()     - bendingCoor2   ) / dParam[i]; // dy2/dParami
+      
+      iCurrentCluster2++;
     }
     
-    // Calculate the error matrix
-    TMatrixD tmp((*paramCov),TMatrixD::kMultTranspose,jacob);
-    error = TMatrixD(jacob,TMatrixD::kMult,tmp);
+    iCurrentCluster1++;
+  }
+    
+  // Inversion of covariance matrices to get the weights
+  if (clusterWeightsNB.Determinant() != 0 && clusterWeightsB.Determinant() != 0) {
+    clusterWeightsNB.Invert();
+    clusterWeightsB.Invert();
+  } else {
+    AliWarning(" Determinant = 0");
+    clusterWeightsNB.ResizeTo(0,0);
+    clusterWeightsB.ResizeTo(0,0);
+    if(deleteMCSCov) delete mcsCovariances;
+    return kFALSE;
   }
   
-  // Add hitForRec resolution to the error matrix
-  error(0,0) += hitForRec1->GetNonBendingReso2();
-  error(1,1) += hitForRec1->GetBendingReso2();
-  error(2,2) += hitForRec2->GetNonBendingReso2();
-  error(3,3) += hitForRec2->GetBendingReso2();
+  if(deleteMCSCov) delete mcsCovariances;
   
-  // invert the error matrix for Chi2 calculation
-  if (error.Determinant() != 0) {
-    error.Invert();
-  } else {
-    AliWarning(" Determinant error=0");
-    return 1.e10;
+  return kTRUE;
+  
+}
+
+  //__________________________________________________________________________
+void AliMUONTrack::ComputeMCSCovariances(TMatrixD& mcsCovariances) const
+{
+  /// Compute the multiple scattering covariance matrix
+  /// (assume that track parameters at each cluster are corrects)
+  
+  // Reset the size of the covariance matrix if needed
+  Int_t nClusters = GetNClusters();
+  if (mcsCovariances.GetNrows() != nClusters) mcsCovariances.ResizeTo(nClusters,nClusters);
+  
+  // Define variables
+  Int_t nChambers = AliMUONConstants::NTrackingCh();
+  AliMUONTrackParam* trackParamAtCluster;
+  AliMUONTrackParam extrapTrackParam;
+  Int_t currentChamber = 0, expectedChamber = 0, size = 0;
+  Double_t *mcsAngle2 = new Double_t[2*nChambers];
+  Double_t *zMCS = new Double_t[2*nChambers];
+  Int_t *indices = new Int_t[2*nClusters];
+  
+  // Compute multiple scattering dispersion angle at each chamber
+  // and save the z position where it is calculated
+  for (Int_t iCluster = 0; iCluster < nClusters; iCluster++) {
+    trackParamAtCluster = (AliMUONTrackParam*) fTrackParamAtCluster->UncheckedAt(iCluster);
+    
+    // look for missing chambers if any
+    currentChamber = trackParamAtCluster->GetClusterPtr()->GetChamberId();
+    while (currentChamber > expectedChamber) {
+      
+      // Save the z position where MCS dispersion is calculated
+      zMCS[size] = AliMUONConstants::DefaultChamberZ(expectedChamber);
+      
+      // Do not take into account MCS in chambers prior the first cluster
+      if (iCluster > 0) {
+        
+        // Get track parameters at missing chamber z
+        extrapTrackParam = *trackParamAtCluster;
+        AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, zMCS[size]);
+        
+        // Save multiple scattering dispersion angle in missing chamber
+        mcsAngle2[size] = AliMUONTrackExtrap::GetMCSAngle2(extrapTrackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
+        
+      } else mcsAngle2[size] = 0.;
+      
+      expectedChamber++;
+      size++;
+    }
+    
+    // Save z position where MCS dispersion is calculated
+    zMCS[size] = trackParamAtCluster->GetZ();
+    
+    // Save multiple scattering dispersion angle in current chamber
+    mcsAngle2[size] = AliMUONTrackExtrap::GetMCSAngle2(*trackParamAtCluster,AliMUONConstants::ChamberThicknessInX0(),1.);
+    
+    // Save indice in zMCS array corresponding to the current cluster
+    indices[iCluster] = size;
+    
+    expectedChamber = currentChamber + 1;
+    size++;
   }
   
-  // Compute the Chi2 value
-  TMatrixD tmp2(error,TMatrixD::kMult,dPos);
-  TMatrixD result(dPos,TMatrixD::kTransposeMult,tmp2);
+  // complete array of z if last cluster is on the last but one chamber
+  if (currentChamber != nChambers-1) zMCS[size++] = AliMUONConstants::DefaultChamberZ(nChambers-1);
+  
+  // Compute the covariance matrix
+  for (Int_t iCluster1 = 0; iCluster1 < nClusters; iCluster1++) { 
+    
+    for (Int_t iCluster2 = iCluster1; iCluster2 < nClusters; iCluster2++) {
+      
+      // Initialization to 0 (diagonal plus upper triangular part)
+      mcsCovariances(iCluster1,iCluster2) = 0.;
+      
+      // Compute contribution from multiple scattering in upstream chambers
+      for (Int_t k = 0; k < indices[iCluster1]; k++) {         
+       mcsCovariances(iCluster1,iCluster2) += (zMCS[indices[iCluster1]] - zMCS[k]) * (zMCS[indices[iCluster2]] - zMCS[k]) * mcsAngle2[k];
+      }
+      
+      // Symetrize the matrix
+      mcsCovariances(iCluster2,iCluster1) = mcsCovariances(iCluster1,iCluster2);
+    }
+    
+  }
+    
+  delete [] mcsAngle2;
+  delete [] zMCS;
+  delete [] indices;
   
-  return result(0,0);
+}
+
+  //__________________________________________________________________________
+Int_t AliMUONTrack::ClustersInCommon(AliMUONTrack* track) const
+{
+  /// Returns the number of clusters in common between the current track ("this")
+  /// and the track pointed to by "track".
+  Int_t clustersInCommon = 0;
+  AliMUONTrackParam *trackParamAtCluster1, *trackParamAtCluster2;
+  // Loop over clusters of first track
+  trackParamAtCluster1 = (AliMUONTrackParam*) this->fTrackParamAtCluster->First();
+  while (trackParamAtCluster1) {
+    // Loop over clusters of second track
+    trackParamAtCluster2 = (AliMUONTrackParam*) track->fTrackParamAtCluster->First();
+    while (trackParamAtCluster2) {
+      // Increment "clustersInCommon" if both trackParamAtCluster1 & 2 point to the same cluster
+      if ((trackParamAtCluster1->GetClusterPtr()) == (trackParamAtCluster2->GetClusterPtr())) {
+        clustersInCommon++;
+       break;
+      }
+      trackParamAtCluster2 = (AliMUONTrackParam*) track->fTrackParamAtCluster->After(trackParamAtCluster2);
+    } // trackParamAtCluster2
+    trackParamAtCluster1 = (AliMUONTrackParam*) this->fTrackParamAtCluster->After(trackParamAtCluster1);
+  } // trackParamAtCluster1
+  return clustersInCommon;
+}
+
+  //__________________________________________________________________________
+Double_t AliMUONTrack::GetNormalizedChi2() const
+{
+  /// return the chi2 value divided by the number of degrees of freedom (or 1.e10 if ndf < 0)
   
+  Double_t numberOfDegFree = (2. * GetNClusters() - 5.);
+  if (numberOfDegFree > 0.) return fGlobalChi2 / numberOfDegFree;
+  else return 1.e10;
 }
 
   //__________________________________________________________________________
-void AliMUONTrack::RecursiveDump(void) const
+Bool_t* AliMUONTrack::CompatibleTrack(AliMUONTrack *track, Double_t sigmaCut) const
+{
+  /// for each chamber: return kTRUE (kFALSE) if clusters are compatible (not compatible)
+  AliMUONTrackParam *trackParamAtCluster1, *trackParamAtCluster2;
+  AliMUONVCluster *cluster1, *cluster2;
+  Double_t chi2, dX, dY, dZ;
+  Double_t chi2Max = sigmaCut * sigmaCut;
+  Double_t dZMax = 1.; // 1 cm
+  
+  Bool_t *compatibleCluster = new Bool_t[AliMUONConstants::NTrackingCh()]; 
+  for ( Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) compatibleCluster[ch] = kFALSE;
+
+  // Loop over clusters of first track
+  trackParamAtCluster1 = (AliMUONTrackParam*) this->fTrackParamAtCluster->First();
+  while (trackParamAtCluster1) {
+    
+    cluster1 = trackParamAtCluster1->GetClusterPtr();
+    
+    // Loop over clusters of second track
+    trackParamAtCluster2 = (AliMUONTrackParam*) track->fTrackParamAtCluster->First();
+    while (trackParamAtCluster2) {
+      
+      cluster2 = trackParamAtCluster2->GetClusterPtr();
+      
+      //prepare next step
+      trackParamAtCluster2 = (AliMUONTrackParam*) track->fTrackParamAtCluster->After(trackParamAtCluster2);
+      
+      // z direction
+      dZ = cluster1->GetZ() - cluster2->GetZ();
+      if (dZ > dZMax) continue;
+      
+      // non bending direction
+      dX = cluster1->GetX() - cluster2->GetX();
+      chi2 = dX * dX / (cluster1->GetErrX2() + cluster2->GetErrX2());
+      if (chi2 > chi2Max) continue;
+      
+      // bending direction
+      dY = cluster1->GetY() - cluster2->GetY();
+      chi2 = dY * dY / (cluster1->GetErrY2() + cluster2->GetErrY2());
+      if (chi2 > chi2Max) continue;
+      
+      compatibleCluster[cluster1->GetChamberId()] = kTRUE;
+      break;
+    }
+    
+    trackParamAtCluster1 = (AliMUONTrackParam*) this->fTrackParamAtCluster->After(trackParamAtCluster1);
+  }
+  
+  return compatibleCluster;
+}
+
+//__________________________________________________________________________
+void AliMUONTrack::SetTrackParamAtVertex(const AliMUONTrackParam* trackParam)
+{
+  /// set track parameters at vertex
+  if (trackParam == 0x0) return;
+  if (fTrackParamAtVertex) *fTrackParamAtVertex = *trackParam;
+  else fTrackParamAtVertex = new AliMUONTrackParam(*trackParam);
+}
+
+//__________________________________________________________________________
+void AliMUONTrack::RecursiveDump() const
 {
-  /// Recursive dump of AliMUONTrack, i.e. with dump of TrackParamAtHit's and attached HitForRec's
-  AliMUONTrackParam *trackParamAtHit;
-  AliMUONHitForRec *hitForRec;
+  /// Recursive dump of AliMUONTrack, i.e. with dump of trackParamAtCluster and attached clusters
+  AliMUONTrackParam *trackParamAtCluster;
+  AliMUONVCluster *cluster;
   cout << "Recursive dump of Track: " << this << endl;
   // Track
   this->Dump();
-  for (Int_t trackHitIndex = 0; trackHitIndex < fNTrackHits; trackHitIndex++) {
-    trackParamAtHit = (AliMUONTrackParam*) ((*fTrackParamAtHit)[trackHitIndex]);
-    // TrackHit
-    cout << "TrackParamAtHit: " << trackParamAtHit << " (index: " << trackHitIndex << ")" << endl;
-    trackParamAtHit->Dump();
-    hitForRec = trackParamAtHit->GetHitForRecPtr();
-    // HitForRec
-    cout << "HitForRec: " << hitForRec << endl;
-    hitForRec->Dump();
+  for (Int_t iCluster = 0; iCluster < GetNClusters(); iCluster++) {
+    trackParamAtCluster = (AliMUONTrackParam*) ((*fTrackParamAtCluster)[iCluster]);
+    // trackParamAtCluster
+    cout << "trackParamAtCluster: " << trackParamAtCluster << " (index: " << iCluster << ")" << endl;
+    trackParamAtCluster->Dump();
+    cluster = trackParamAtCluster->GetClusterPtr();
+    // cluster
+    cout << "cluster: " << cluster << endl;
+    cluster->Print();
   }
   return;
 }
   
 //_____________________________________________-
-void AliMUONTrack::Print(Option_t* opt) const
+void AliMUONTrack::Print(Option_t*) const
 {
   /// Printing Track information 
-  /// "full" option for printing all the information about the track
-  TString sopt(opt);
-  sopt.ToUpper();
-  if ( sopt.Contains("FULL") ) { 
-    cout << "<AliMUONTrack> No.Clusters=" << setw(2)   << GetNTrackHits() << 
-      //      ", Bending P="<< setw(8) << setprecision(5)      << 1./GetInverseBendingMomentum() << 
-      //", NonBendSlope=" << setw(8) << setprecision(5)  << GetNonBendingSlope()*180./TMath::Pi() <<
-      //", BendSlope=" << setw(8) << setprecision(5)     << GetBendingSlope()*180./TMath::Pi() <<
+
+  cout << "<AliMUONTrack> No.Clusters=" << setw(2)   << GetNClusters() << 
       ", Match2Trig=" << setw(1) << GetMatchTrigger()  << 
       ", LoTrgNum=" << setw(3) << GetLoTrgNum()  << 
-      ", Chi2-tracking-trigger=" << setw(8) << setprecision(5) <<  GetChi2MatchTrigger() << endl ;
-    GetTrackParamAtHit()->First()->Print("full");
-  }
-  else {
-    cout << "<AliMUONTrack>";
-    GetTrackParamAtHit()->First()->Print("");
+    ", Chi2-tracking-trigger=" << setw(8) << setprecision(5) <<  GetChi2MatchTrigger();
+  cout << Form(" HitTriggerPattern %x",fHitsPatternInTrigCh) << endl;
+  fTrackParamAtCluster->First()->Print("FULL");
+}
+
+//__________________________________________________________________________
+void AliMUONTrack::SetLocalTrigger(Int_t loCirc, Int_t loStripX, Int_t loStripY, Int_t loDev, Int_t loLpt, Int_t loHpt)
+{
+  /// pack the local trigger information and store
+
+  if (loCirc < 0) return;
+
+  fLocalTrigger = 0;
+  fLocalTrigger += loCirc;
+  fLocalTrigger += loStripX << 8;
+  fLocalTrigger += loStripY << 13;
+  fLocalTrigger += loDev    << 17;
+  fLocalTrigger += loLpt    << 22;
+  fLocalTrigger += loHpt    << 24;
 
-  }
-    
 }
+