]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONVTrackReconstructor.cxx
Filling residuals (GlobalQA) only for tracks with kTPCin
[u/mrichter/AliRoot.git] / MUON / AliMUONVTrackReconstructor.cxx
index 6eedfe7bb1ce7f5a868a59e41c5d82025dd8a260..6c0d15da0bee72f38b3d9e5e1d09433626d0bc9c 100644 (file)
 /// * ValidateTracksWithTrigger to match tracker/trigger tracks
 ///
 /// Several options and adjustable parameters are available for both KALMAN and ORIGINAL
-/// tracking algorithms. They can be changed by using:
-/// AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLow(High)FluxParam();
-/// muonRecoParam->Set...(); // see methods in AliMUONRecoParam.h for details
-/// AliMUONReconstructor::SetRecoParam(muonRecoParam);
+/// tracking algorithms. They can be changed through the AliMUONRecoParam object
+/// set in the reconstruction macro or read from the CDB
+/// (see methods in AliMUONRecoParam.h file for details)
 ///
 /// Main parameters and options are:
 /// - *fgkSigmaToCutForTracking* : quality cut used to select new clusters to be
@@ -74,6 +73,8 @@
 #include "AliMUONVClusterServer.h"
 #include "AliMUONVTriggerStore.h"
 #include "AliMUONVTriggerTrackStore.h"
+#include "AliMUONRecoParam.h"
+
 #include "AliMpDEManager.h"
 #include "AliMpArea.h"
 
@@ -93,21 +94,22 @@ ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
 /// \endcond
 
   //__________________________________________________________________________
-AliMUONVTrackReconstructor::AliMUONVTrackReconstructor(AliMUONVClusterServer& clusterServer)
-  : TObject(),
-    fRecTracksPtr(0x0),
-    fNRecTracks(0),
-  fClusterServer(clusterServer)
+AliMUONVTrackReconstructor::AliMUONVTrackReconstructor(const AliMUONRecoParam* recoParam,
+                                                       AliMUONVClusterServer* clusterServer)
+: TObject(),
+fRecTracksPtr(0x0),
+fNRecTracks(0),
+fClusterServer(clusterServer),
+fkRecoParam(recoParam)
 {
   /// Constructor for class AliMUONVTrackReconstructor
+  /// WARNING: if clusterServer=0x0, no clusterization will be possible at this level
   
   // Memory allocation for the TClonesArray of reconstructed tracks
   fRecTracksPtr = new TClonesArray("AliMUONTrack", 100);
   
   // set the magnetic field for track extrapolations
-  const AliMagF* kField = AliTracker::GetFieldMap();
-  if (!kField) AliFatal("No field available");
-  AliMUONTrackExtrap::SetField(kField);
+  AliMUONTrackExtrap::SetField();
 }
 
   //__________________________________________________________________________
@@ -136,26 +138,31 @@ void AliMUONVTrackReconstructor::EventReconstruct(AliMUONVClusterStore& clusterS
   // Reset array of tracks
   ResetTracks();
   
-  // Look for candidates from clusters in stations(1..) 4 and 5
-  MakeTrackCandidates(clusterStore);
+  // Look for candidates from clusters in stations(1..) 4 and 5 (abort in case of failure)
+  if (!MakeTrackCandidates(clusterStore)) return;
   
-  // Look for extra candidates from clusters in stations(1..) 4 and 5
-  if (AliMUONReconstructor::GetRecoParam()->MakeMoreTrackCandidates()) MakeMoreTrackCandidates(clusterStore);
+  // Look for extra candidates from clusters in stations(1..) 4 and 5 (abort in case of failure)
+  if (GetRecoParam()->MakeMoreTrackCandidates()) {
+    if (!MakeMoreTrackCandidates(clusterStore)) return;
+  }
   
   // Stop tracking if no candidate found
   if (fRecTracksPtr->GetEntriesFast() == 0) return;
   
-  // Follow tracks in stations(1..) 3, 2 and 1
-  FollowTracks(clusterStore);
+  // Follow tracks in stations(1..) 3, 2 and 1 (abort in case of failure)
+  if (!FollowTracks(clusterStore)) return;
   
   // Complement the reconstructed tracks
-  if (AliMUONReconstructor::GetRecoParam()->ComplementTracks()) ComplementTracks(clusterStore);
+  if (GetRecoParam()->ComplementTracks()) {
+    if (ComplementTracks(clusterStore)) RemoveIdenticalTracks();
+  }
   
   // Improve the reconstructed tracks
-  if (AliMUONReconstructor::GetRecoParam()->ImproveTracks()) ImproveTracks();
+  if (GetRecoParam()->ImproveTracks()) ImproveTracks();
   
-  // Remove double tracks
-  RemoveDoubleTracks();
+  // Remove connected tracks
+  if (GetRecoParam()->RemoveConnectedTracksInSt12()) RemoveConnectedTracks(kFALSE);
+  else RemoveConnectedTracks(kTRUE);
   
   // Fill AliMUONTrack data members
   Finalize();
@@ -200,33 +207,42 @@ TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsBetweenChambers(const AliM
       // non bending slope
       nonBendingSlope = (cluster1->GetX() - cluster2->GetX()) / (cluster1->GetZ() - cluster2->GetZ());
       
+      // check if non bending slope is within tolerances
+      if (TMath::Abs(nonBendingSlope) > GetRecoParam()->GetMaxNonBendingSlope()) continue;
+      
       // bending slope
       bendingSlope = (cluster1->GetY() - cluster2->GetY()) / (cluster1->GetZ() - cluster2->GetZ());
       
-      // impact parameter
-      impactParam = cluster1->GetY() - cluster1->GetZ() * bendingSlope;
-     
-      // absolute value of bending momentum
-      bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
-      
-      // check for non bending slope and bending momentum within tolerances
-      if (TMath::Abs(nonBendingSlope) < AliMUONReconstructor::GetRecoParam()->GetMaxNonBendingSlope() &&
-         bendingMomentum < AliMUONReconstructor::GetRecoParam()->GetMaxBendingMomentum() &&
-         bendingMomentum > AliMUONReconstructor::GetRecoParam()->GetMinBendingMomentum()) {
-        
-       // make new segment
-        segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(cluster1, cluster2, kFALSE, kFALSE);
-        
-       // Printout for debug
-       if (AliLog::GetGlobalDebugLevel() > 1) {
-          cout << "segmentIndex(0...): " << segments->GetLast() << endl;
-          segment->Dump();
-          cout << "Cluster in first chamber" << endl;
-          cluster1->Print();
-          cout << "Cluster in second chamber" << endl;
-          cluster2->Print();
-        }
+      // check the bending momentum of the bending slope depending if the field is ON or OFF
+      if (AliMUONTrackExtrap::IsFieldON()) {
+       
+       // impact parameter
+       impactParam = cluster1->GetY() - cluster1->GetZ() * bendingSlope;
+       
+       // absolute value of bending momentum
+       bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
+       
+       // check if bending momentum is within tolerances
+       if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() ||
+           bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) continue;
+       
+      } else {
        
+       // check if non bending slope is within tolerances
+       if (TMath::Abs(bendingSlope) > GetRecoParam()->GetMaxBendingSlope()) continue;
+      
+      }
+      // make new segment
+      segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(cluster1, cluster2, kFALSE, kFALSE);
+      
+      // Printout for debug
+      if (AliLog::GetGlobalDebugLevel() > 1) {
+       cout << "segmentIndex(0...): " << segments->GetLast() << endl;
+       segment->Dump();
+       cout << "Cluster in first chamber" << endl;
+       cluster1->Print();
+       cout << "Cluster in second chamber" << endl;
+       cluster2->Print();
       }
       
     }
@@ -239,23 +255,86 @@ TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsBetweenChambers(const AliM
   return segments;
 }
 
+  //__________________________________________________________________________
+void AliMUONVTrackReconstructor::RemoveUsedSegments(TClonesArray& segments)
+{
+  /// To remove pairs of clusters already attached to a track
+  AliDebug(1,"Enter RemoveUsedSegments");
+  Int_t nSegments = segments.GetEntriesFast();
+  Int_t nTracks = fRecTracksPtr->GetEntriesFast();
+  AliMUONObjectPair *segment;
+  AliMUONTrack *track;
+  AliMUONVCluster *cluster, *cluster1, *cluster2;
+  Bool_t foundCluster1, foundCluster2, removeSegment;
+  
+  // Loop over segments
+  for (Int_t iSegment=0; iSegment<nSegments; iSegment++) {
+    segment = (AliMUONObjectPair*) segments.UncheckedAt(iSegment);
+    
+    cluster1 = (AliMUONVCluster*) segment->First();
+    cluster2 = (AliMUONVCluster*) segment->Second();
+    removeSegment = kFALSE;
+    
+    // Loop over tracks
+    for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
+      track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack);
+      
+      // skip empty slot
+      if (!track) continue;
+      
+      foundCluster1 = kFALSE;
+      foundCluster2 = kFALSE;
+      
+      // Loop over clusters
+      Int_t nClusters = track->GetNClusters();
+      for (Int_t iCluster = 0; iCluster < nClusters; iCluster++) {
+        cluster = ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iCluster))->GetClusterPtr();
+       
+       // check if both clusters are in that track
+       if (cluster == cluster1) foundCluster1 = kTRUE;
+       else if (cluster == cluster2) foundCluster2 = kTRUE;
+       
+       if (foundCluster1 && foundCluster2) {
+         removeSegment = kTRUE;
+         break;
+       }
+       
+      }
+      
+      if (removeSegment) break;
+      
+    }
+    
+    if (removeSegment) segments.RemoveAt(iSegment);
+      
+  }
+  
+  segments.Compress();
+  
+  // Printout for debug
+  AliDebug(1,Form("NSegments =  %d ", segments.GetEntriesFast()));
+}
+
   //__________________________________________________________________________
 void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
 {
   /// To remove identical tracks:
   /// Tracks are considered identical if they have all their clusters in common.
   /// One keeps the track with the larger number of clusters if need be
-  AliMUONTrack *track1, *track2, *trackToRemove;
+  AliMUONTrack *track1, *track2;
+  Int_t nTracks = fRecTracksPtr->GetEntriesFast();
   Int_t clustersInCommon, nClusters1, nClusters2;
-  Bool_t removedTrack1;
   // Loop over first track of the pair
-  track1 = (AliMUONTrack*) fRecTracksPtr->First();
-  while (track1) {
-    removedTrack1 = kFALSE;
+  for (Int_t iTrack1 = 0; iTrack1 < nTracks; iTrack1++) {
+    track1 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack1);
+    // skip empty slot
+    if (!track1) continue;
     nClusters1 = track1->GetNClusters();
     // Loop over second track of the pair
-    track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
-    while (track2) {
+    for (Int_t iTrack2 = iTrack1+1; iTrack2 < nTracks; iTrack2++) {
+      track2 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack2);
+      // skip empty slot
+      if (!track2) continue;
       nClusters2 = track2->GetNClusters();
       // number of clusters in common between two tracks
       clustersInCommon = track1->ClustersInCommon(track2);
@@ -264,27 +343,18 @@ void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
         // decide which track to remove
         if (nClusters2 > nClusters1) {
          // remove track1 and continue the first loop with the track next to track1
-         trackToRemove = track1;
-         track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
-          fRecTracksPtr->Remove(trackToRemove);
-         fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
+          fRecTracksPtr->RemoveAt(iTrack1);
          fNRecTracks--;
-         removedTrack1 = kTRUE;
          break;
        } else {
          // remove track2 and continue the second loop with the track next to track2
-         trackToRemove = track2;
-         track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
-         fRecTracksPtr->Remove(trackToRemove);
-         fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
+         fRecTracksPtr->RemoveAt(iTrack2);
          fNRecTracks--;
         }
-      } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
+      }
     } // track2
-    if (removedTrack1) continue;
-    track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
   } // track1
-  return;
+  fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
 }
 
   //__________________________________________________________________________
@@ -295,6 +365,50 @@ void AliMUONVTrackReconstructor::RemoveDoubleTracks()
   /// which has the smaller number of clusters are in common with the other track.
   /// Among two identical tracks, one keeps the track with the larger number of clusters
   /// or, if these numbers are equal, the track with the minimum chi2.
+  AliMUONTrack *track1, *track2;
+  Int_t nTracks = fRecTracksPtr->GetEntriesFast();
+  Int_t clustersInCommon2, nClusters1, nClusters2;
+  // Loop over first track of the pair
+  for (Int_t iTrack1 = 0; iTrack1 < nTracks; iTrack1++) {
+    track1 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack1);
+    // skip empty slot
+    if (!track1) continue;
+    nClusters1 = track1->GetNClusters();
+    // Loop over second track of the pair
+    for (Int_t iTrack2 = iTrack1+1; iTrack2 < nTracks; iTrack2++) {
+      track2 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack2);
+      // skip empty slot
+      if (!track2) continue;
+      nClusters2 = track2->GetNClusters();
+      // number of clusters in common between two tracks
+      clustersInCommon2 = 2 * track1->ClustersInCommon(track2);
+      // check for identical tracks
+      if (clustersInCommon2 > nClusters1 || clustersInCommon2 > nClusters2) {
+        // decide which track to remove
+        if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
+         // remove track2 and continue the second loop with the track next to track2
+         fRecTracksPtr->RemoveAt(iTrack2);
+         fNRecTracks--;
+        } else {
+         // else remove track1 and continue the first loop with the track next to track1
+          fRecTracksPtr->RemoveAt(iTrack1);
+         fNRecTracks--;
+         break;
+        }
+      }
+    } // track2
+  } // track1
+  fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
+}
+
+  //__________________________________________________________________________
+void AliMUONVTrackReconstructor::RemoveConnectedTracks(Bool_t inSt345)
+{
+  /// To remove double tracks:
+  /// Tracks are considered identical if they share 1 cluster or more.
+  /// If inSt345=kTRUE only stations 3, 4 and 5 are considered.
+  /// Among two identical tracks, one keeps the track with the larger number of clusters
+  /// or, if these numbers are equal, the track with the minimum chi2.
   AliMUONTrack *track1, *track2, *trackToRemove;
   Int_t clustersInCommon, nClusters1, nClusters2;
   Bool_t removedTrack1;
@@ -308,9 +422,10 @@ void AliMUONVTrackReconstructor::RemoveDoubleTracks()
     while (track2) {
       nClusters2 = track2->GetNClusters();
       // number of clusters in common between two tracks
-      clustersInCommon = track1->ClustersInCommon(track2);
+      if (inSt345) clustersInCommon = track1->ClustersInCommonInSt345(track2);
+      else clustersInCommon = track1->ClustersInCommon(track2);
       // check for identical tracks
-      if (((nClusters1 < nClusters2) && (2 * clustersInCommon > nClusters1)) || (2 * clustersInCommon > nClusters2)) {
+      if (clustersInCommon > 0) {
         // decide which track to remove
         if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
          // remove track2 and continue the second loop with the track next to track2
@@ -344,11 +459,11 @@ void AliMUONVTrackReconstructor::AskForNewClustersInChamber(const AliMUONTrackPa
   /// Ask the clustering to reconstruct new clusters around the track candidate position
   
   // check if the current chamber is useable
-  if (!AliMUONReconstructor::GetRecoParam()->UseChamber(chamber)) return;
+  if (!fClusterServer || !GetRecoParam()->UseChamber(chamber)) return;
   
   // maximum distance between the center of the chamber and a detection element
   // (accounting for the inclination of the chamber)
-  static const Double_t gkMaxDZ = 15.; // 15 cm
+  static const Double_t kMaxDZ = 15.; // 15 cm
   
   // extrapolate track parameters to the chamber
   AliMUONTrackParam extrapTrackParam(trackParam);
@@ -356,20 +471,20 @@ void AliMUONVTrackReconstructor::AskForNewClustersInChamber(const AliMUONTrackPa
   
   // build the searching area using the track resolution and the maximum-distance-to-track value
   const TMatrixD& kParamCov = extrapTrackParam.GetCovariances();
-  Double_t errX2 = kParamCov(0,0) + gkMaxDZ * gkMaxDZ * kParamCov(1,1) + 2. * gkMaxDZ * TMath::Abs(kParamCov(0,1));
-  Double_t errY2 = kParamCov(2,2) + gkMaxDZ * gkMaxDZ * kParamCov(3,3) + 2. * gkMaxDZ * TMath::Abs(kParamCov(2,3));
-  Double_t dX = TMath::Abs(trackParam.GetNonBendingSlope()) * gkMaxDZ +
-               AliMUONReconstructor::GetRecoParam()->GetMaxNonBendingDistanceToTrack() +
-               AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2);
-  Double_t dY = TMath::Abs(trackParam.GetBendingSlope()) * gkMaxDZ +
-               AliMUONReconstructor::GetRecoParam()->GetMaxBendingDistanceToTrack() +
-               AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2);
-  TVector2 dimensions(dX, dY);
-  TVector2 position(extrapTrackParam.GetNonBendingCoor(), extrapTrackParam.GetBendingCoor());
-  AliMpArea area(position, dimensions);
+  Double_t errX2 = kParamCov(0,0) + kMaxDZ * kMaxDZ * kParamCov(1,1) + 2. * kMaxDZ * TMath::Abs(kParamCov(0,1));
+  Double_t errY2 = kParamCov(2,2) + kMaxDZ * kMaxDZ * kParamCov(3,3) + 2. * kMaxDZ * TMath::Abs(kParamCov(2,3));
+  Double_t dX = TMath::Abs(trackParam.GetNonBendingSlope()) * kMaxDZ +
+               GetRecoParam()->GetMaxNonBendingDistanceToTrack() +
+               GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2);
+  Double_t dY = TMath::Abs(trackParam.GetBendingSlope()) * kMaxDZ +
+               GetRecoParam()->GetMaxBendingDistanceToTrack() +
+               GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2);
+  AliMpArea area(extrapTrackParam.GetNonBendingCoor(), 
+                 extrapTrackParam.GetBendingCoor(),
+                 dX, dY);
   
   // ask to cluterize in the given area of the given chamber
-  fClusterServer.Clusterize(chamber, clusterStore, area);
+  fClusterServer->Clusterize(chamber, clusterStore, area, GetRecoParam());
   
 }
 
@@ -413,7 +528,7 @@ Double_t AliMUONVTrackReconstructor::TryOneCluster(const AliMUONTrackParam &trac
 }
 
   //__________________________________________________________________________
-Bool_t AliMUONVTrackReconstructor::TryOneClusterFast(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster)
+Bool_t AliMUONVTrackReconstructor::TryOneClusterFast(const AliMUONTrackParam &trackParam, const AliMUONVCluster* cluster)
 {
 /// Test the compatibility between the track and the cluster
 /// given the track resolution + the maximum-distance-to-track value
@@ -427,10 +542,10 @@ Bool_t AliMUONVTrackReconstructor::TryOneClusterFast(const AliMUONTrackParam &tr
   Double_t errX2 = kParamCov(0,0) + dZ * dZ * kParamCov(1,1) + 2. * dZ * kParamCov(0,1);
   Double_t errY2 = kParamCov(2,2) + dZ * dZ * kParamCov(3,3) + 2. * dZ * kParamCov(2,3);
 
-  Double_t dXmax = AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2) +
-                   AliMUONReconstructor::GetRecoParam()->GetMaxNonBendingDistanceToTrack();
-  Double_t dYmax = AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2) +
-                  AliMUONReconstructor::GetRecoParam()->GetMaxBendingDistanceToTrack();
+  Double_t dXmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2) +
+                   GetRecoParam()->GetMaxNonBendingDistanceToTrack();
+  Double_t dYmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2) +
+                  GetRecoParam()->GetMaxBendingDistanceToTrack();
   
   if (TMath::Abs(dX) > dXmax || TMath::Abs(dY) > dYmax) return kFALSE;
   
@@ -495,8 +610,8 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInChamber(AliMUONTrack &trac
   AliDebug(1,Form("Enter FollowLinearTrackInChamber(1..) %d", nextChamber+1));
   
   Double_t chi2WithOneCluster = 1.e10;
-  Double_t maxChi2WithOneCluster = 2. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
-                                       AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
+  Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
+                                       GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
   Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
   Bool_t foundOneCluster = kFALSE;
   AliMUONTrack *newTrack = 0x0;
@@ -549,13 +664,14 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInChamber(AliMUONTrack &trac
        cluster->Print();
       }
       
-      if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
+      if (GetRecoParam()->TrackAllTracks()) {
        // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
        newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
-       if (AliMUONReconstructor::GetRecoParam()->RequestStation(nextChamber/2))
+       if (GetRecoParam()->RequestStation(nextChamber/2))
          extrapTrackParamAtCluster.SetRemovable(kFALSE);
        else extrapTrackParamAtCluster.SetRemovable(kTRUE);
        newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster,*cluster);
+       newTrack->SetGlobalChi2(trackCandidate.GetGlobalChi2()+chi2WithOneCluster);
        fNRecTracks++;
        
        // Printout for debuging
@@ -575,12 +691,13 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInChamber(AliMUONTrack &trac
   }
   
   // fill out the best track if required else clean up the fRecTracksPtr array
-  if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
+  if (!GetRecoParam()->TrackAllTracks()) {
     if (foundOneCluster) {
-      if (AliMUONReconstructor::GetRecoParam()->RequestStation(nextChamber/2))
+      if (GetRecoParam()->RequestStation(nextChamber/2))
        bestTrackParamAtCluster.SetRemovable(kFALSE);
       else bestTrackParamAtCluster.SetRemovable(kTRUE);
       trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
+      trackCandidate.SetGlobalChi2(trackCandidate.GetGlobalChi2()+bestChi2WithOneCluster);
       
       // Printout for debuging
       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
@@ -629,10 +746,10 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trac
   
   Double_t chi2WithOneCluster = 1.e10;
   Double_t chi2WithTwoClusters = 1.e10;
-  Double_t maxChi2WithOneCluster = 2. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
-                                       AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
-  Double_t maxChi2WithTwoClusters = 4. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
-                                        AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
+  Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
+                                       GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
+  Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
+                                        GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
   Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
   Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
   Bool_t foundOneCluster = kFALSE;
@@ -725,13 +842,14 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trac
            clusterCh1->Print();
          }
          
-         if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
+         if (GetRecoParam()->TrackAllTracks()) {
            // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
             newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
            extrapTrackParamAtCluster1.SetRemovable(kTRUE);
            newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
            extrapTrackParamAtCluster2.SetRemovable(kTRUE);
            newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
+           newTrack->SetGlobalChi2(newTrack->GetGlobalChi2()+chi2WithTwoClusters);
            fNRecTracks++;
            
            // Tag clusterCh1 as used
@@ -758,13 +876,14 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trac
       if (!foundSecondCluster) {
        foundOneCluster = kTRUE;
         
-       if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
+       if (GetRecoParam()->TrackAllTracks()) {
          // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
           newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
-         if (AliMUONReconstructor::GetRecoParam()->RequestStation(nextStation))
+         if (GetRecoParam()->RequestStation(nextStation))
            extrapTrackParamAtCluster2.SetRemovable(kFALSE);
          else extrapTrackParamAtCluster2.SetRemovable(kTRUE);
          newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
+         newTrack->SetGlobalChi2(newTrack->GetGlobalChi2()+chi2WithOneCluster);
          fNRecTracks++;
          
          // Printout for debuging
@@ -787,7 +906,7 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trac
   
   // look for candidates in chamber 1 not already attached to a track
   // if we want to keep all possible tracks or if no good couple of clusters has been found
-  if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
+  if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
     
     // Printout for debuging
     if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
@@ -830,13 +949,14 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trac
          clusterCh1->Print();
        }
        
-       if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
+       if (GetRecoParam()->TrackAllTracks()) {
          // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
          newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
-         if (AliMUONReconstructor::GetRecoParam()->RequestStation(nextStation))
+         if (GetRecoParam()->RequestStation(nextStation))
            extrapTrackParamAtCluster1.SetRemovable(kFALSE);
          else extrapTrackParamAtCluster1.SetRemovable(kTRUE);
          newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
+         newTrack->SetGlobalChi2(newTrack->GetGlobalChi2()+chi2WithOneCluster);
          fNRecTracks++;
          
          // Printout for debuging
@@ -858,12 +978,13 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trac
   }
   
   // fill out the best track if required else clean up the fRecTracksPtr array
-  if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
+  if (!GetRecoParam()->TrackAllTracks()) {
     if (foundTwoClusters) {
       bestTrackParamAtCluster1.SetRemovable(kTRUE);
       trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
       bestTrackParamAtCluster2.SetRemovable(kTRUE);
       trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster2,*(bestTrackParamAtCluster2.GetClusterPtr()));
+      trackCandidate.SetGlobalChi2(trackCandidate.GetGlobalChi2()+bestChi2WithTwoClusters);
       
       // Printout for debuging
       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
@@ -872,10 +993,11 @@ Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trac
       }
       
     } else if (foundOneCluster) {
-      if (AliMUONReconstructor::GetRecoParam()->RequestStation(nextStation))
+      if (GetRecoParam()->RequestStation(nextStation))
        bestTrackParamAtCluster1.SetRemovable(kFALSE);
       else bestTrackParamAtCluster1.SetRemovable(kTRUE);
       trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
+      trackCandidate.SetGlobalChi2(trackCandidate.GetGlobalChi2()+bestChi2WithOneCluster);
       
       // Printout for debuging
       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
@@ -913,9 +1035,6 @@ void AliMUONVTrackReconstructor::ImproveTracks()
   
   AliMUONTrack *track, *nextTrack;
   
-  // Remove double track to improve only "good" tracks
-  RemoveDoubleTracks();
-  
   track = (AliMUONTrack*) fRecTracksPtr->First();
   while (track) {
     
@@ -942,6 +1061,7 @@ void AliMUONVTrackReconstructor::ImproveTracks()
 void AliMUONVTrackReconstructor::Finalize()
 {
   /// Recompute track parameters and covariances at each attached cluster from those at the first one
+  /// Set the label pointing to the corresponding MC track
   
   AliMUONTrack *track;
   
@@ -950,6 +1070,8 @@ void AliMUONVTrackReconstructor::Finalize()
     
     FinalizeTrack(*track);
     
+    track->FindMCLabel();
+    
     track = (AliMUONTrack*) fRecTracksPtr->After(track);
     
   }
@@ -996,16 +1118,10 @@ void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCir
   
   while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
   {
-    Bool_t xTrig=kFALSE;
-    Bool_t yTrig=kFALSE;
+    Bool_t xTrig=locTrg->IsTrigX();
+    Bool_t yTrig=locTrg->IsTrigY();
     
     Int_t localBoardId = locTrg->LoCircuit();
-    if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 && 
-         locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
-    else xTrig=kTRUE;                         // trigger in X
-    if (locTrg->LoTrigY()==1 && 
-        locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
-    else yTrig = kTRUE;                          // trigger in Y
     
     if (xTrig && yTrig) 
     { // make Trigger Track if trigger in X and Y
@@ -1013,13 +1129,7 @@ void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCir
       Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX()); 
       // need first to convert deviation to [0-30] 
       // (see AliMUONLocalTriggerBoard::LocalTrigger)
-      Int_t deviation = locTrg->LoDev(); 
-      Int_t sign = 0;
-      if ( !locTrg->LoSdev() &&  deviation ) sign=-1;
-      if ( !locTrg->LoSdev() && !deviation ) sign= 0;
-      if (  locTrg->LoSdev() == 1 )          sign=+1;
-      deviation *= sign;
-      deviation += 15;
+      Int_t deviation = locTrg->GetDeviation(); 
       Int_t stripX21 = locTrg->LoStripX()+deviation+1;
       Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);       
       Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
@@ -1029,6 +1139,9 @@ void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCir
       
       Float_t thetax = TMath::ATan2( x11 , z11 );
       Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
+
+      CorrectThetaRange(thetax);
+      CorrectThetaRange(thetay);
       
       triggerTrack.SetX11(x11);
       triggerTrack.SetY11(y11);
@@ -1042,3 +1155,13 @@ void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCir
   } // end of loop on Local Trigger
 }
 
+//__________________________________________________________________________
+void AliMUONVTrackReconstructor::CorrectThetaRange(Float_t& theta)
+{
+  /// The angles of the trigger tracks, obtained with ATan2, 
+  /// have values around +pi and -pi. On the contrary, the angles 
+  /// used in the tracker tracks have values around 0.
+  /// This function sets the same range for the trigger tracks angles.
+  if (theta < -TMath::PiOver2()) theta += TMath::Pi();
+  else if(theta > TMath::PiOver2()) theta -= TMath::Pi();
+}