- Added track parameters at DCA in AliESDMuonTrack
[u/mrichter/AliRoot.git] / MUON / AliMUONTrack.cxx
index 76eb487..718e2ea 100644 (file)
 #include "AliMUONTrack.h"
 
 #include "AliMUONTrackParam.h" 
-#include "AliMUONVCluster.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 <TMatrixD.h>
@@ -191,7 +193,111 @@ AliMUONTrack::AliMUONTrack(AliMUONObjectPair *segment)
   
 }
 
-  //__________________________________________________________________________
+//__________________________________________________________________________
+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)
+{
+  /// 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();
+      
+    }
+    
+  }
+  
+  // 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& track)
   : TObject(track),
     fTrackParamAtCluster(new TClonesArray("AliMUONTrackParam",10)),
@@ -343,7 +449,7 @@ void AliMUONTrack::AddTrackParamAtCluster(const AliMUONTrackParam &trackParam, A
   
   // link parameters with the associated cluster or its copy
   if (copy) {
-    AliMUONVCluster *clusterCopy = cluster.CreateCopy();
+    AliMUONVCluster *clusterCopy = static_cast<AliMUONVCluster*>(cluster.Clone());
     trackParamAtCluster->SetClusterPtr(clusterCopy, kTRUE);
   } else trackParamAtCluster->SetClusterPtr(&cluster);
 }
@@ -464,8 +570,8 @@ Bool_t AliMUONTrack::ComputeLocalChi2(Bool_t accountForMCS)
     AliMUONTrackParam* trackParamAtCluster1;
     AliMUONVCluster *cluster, *discardedCluster;
     Int_t iCluster1, iCluster2, iCurrentCluster1, iCurrentCluster2;
-    TMatrixD ClusterWeightsNB(nClusters-1,nClusters-1);
-    TMatrixD ClusterWeightsB(nClusters-1,nClusters-1);
+    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;
@@ -475,7 +581,7 @@ Bool_t AliMUONTrack::ComputeLocalChi2(Bool_t accountForMCS)
       discardedCluster = trackParamAtCluster->GetClusterPtr();
       
       // Recompute cluster weights without the current cluster
-      if (!ComputeClusterWeights(ClusterWeightsNB, ClusterWeightsB, &mcsCovariances, discardedCluster)) {
+      if (!ComputeClusterWeights(clusterWeightsNB, clusterWeightsB, &mcsCovariances, discardedCluster)) {
        AliWarning("cannot take into account the multiple scattering effects");
        delete [] dX;
        delete [] dY;
@@ -502,17 +608,17 @@ Bool_t AliMUONTrack::ComputeLocalChi2(Bool_t accountForMCS)
           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];
+          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];
+       globalChi2b += clusterWeightsNB(iCurrentCluster1, iCurrentCluster1) * dX[iCurrentCluster1] * dX[iCurrentCluster1] +
+                      clusterWeightsB(iCurrentCluster1, iCurrentCluster1) * dY[iCurrentCluster1] * dY[iCurrentCluster1];
        
         iCurrentCluster1++;
       }
@@ -636,7 +742,7 @@ Bool_t AliMUONTrack::ComputeClusterWeights(TMatrixD* mcsCovariances)
 }
 
   //__________________________________________________________________________
-Bool_t AliMUONTrack::ComputeClusterWeights(TMatrixD& ClusterWeightsNB, TMatrixD& ClusterWeightsB,
+Bool_t AliMUONTrack::ComputeClusterWeights(TMatrixD& clusterWeightsNB, TMatrixD& clusterWeightsB,
                                           TMatrixD* mcsCovariances, AliMUONVCluster* discardedCluster) const
 {
   /// Compute the weight matrices, in non bending and bending direction,
@@ -656,11 +762,11 @@ Bool_t AliMUONTrack::ComputeClusterWeights(TMatrixD& ClusterWeightsNB, TMatrixD&
   
   // Resize the weights matrices; alocate memory
   if (discardedCluster) {
-    ClusterWeightsNB.ResizeTo(nClusters-1,nClusters-1);
-    ClusterWeightsB.ResizeTo(nClusters-1,nClusters-1);
+    clusterWeightsNB.ResizeTo(nClusters-1,nClusters-1);
+    clusterWeightsB.ResizeTo(nClusters-1,nClusters-1);
   } else {
-    ClusterWeightsNB.ResizeTo(nClusters,nClusters);
-    ClusterWeightsB.ResizeTo(nClusters,nClusters);
+    clusterWeightsNB.ResizeTo(nClusters,nClusters);
+    clusterWeightsB.ResizeTo(nClusters,nClusters);
   }
   
   // Define variables
@@ -682,25 +788,25 @@ Bool_t AliMUONTrack::ComputeClusterWeights(TMatrixD& ClusterWeightsNB, TMatrixD&
       if (cluster2 == discardedCluster) continue;
       
       // Fill with MCS covariances
-      ClusterWeightsNB(iCurrentCluster1, iCurrentCluster2) = (*mcsCovariances)(iCluster1,iCluster2);
+      clusterWeightsNB(iCurrentCluster1, iCurrentCluster2) = (*mcsCovariances)(iCluster1,iCluster2);
       
       // Equal contribution from multiple scattering in non bending and bending directions
-      ClusterWeightsB(iCurrentCluster1, iCurrentCluster2) = ClusterWeightsNB(iCurrentCluster1, iCurrentCluster2);
+      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();
+        clusterWeightsNB(iCurrentCluster1, iCurrentCluster1) += cluster1->GetErrX2();
        // In bending plane
-       ClusterWeightsB(iCurrentCluster1, iCurrentCluster1) += cluster1->GetErrY2();
+       clusterWeightsB(iCurrentCluster1, iCurrentCluster1) += cluster1->GetErrY2();
        
       } else {
        
        // In non bending plane
-       ClusterWeightsNB(iCurrentCluster2, iCurrentCluster1) = ClusterWeightsNB(iCurrentCluster1, iCurrentCluster2);
+       clusterWeightsNB(iCurrentCluster2, iCurrentCluster1) = clusterWeightsNB(iCurrentCluster1, iCurrentCluster2);
        // In bending plane
-       ClusterWeightsB(iCurrentCluster2, iCurrentCluster1) = ClusterWeightsB(iCurrentCluster1, iCurrentCluster2);
+       clusterWeightsB(iCurrentCluster2, iCurrentCluster1) = clusterWeightsB(iCurrentCluster1, iCurrentCluster2);
        
       }
       
@@ -711,13 +817,13 @@ Bool_t AliMUONTrack::ComputeClusterWeights(TMatrixD& ClusterWeightsNB, TMatrixD&
   }
     
   // Inversion of covariance matrices to get the weights
-  if (ClusterWeightsNB.Determinant() != 0 && ClusterWeightsB.Determinant() != 0) {
-    ClusterWeightsNB.Invert();
-    ClusterWeightsB.Invert();
+  if (clusterWeightsNB.Determinant() != 0 && clusterWeightsB.Determinant() != 0) {
+    clusterWeightsNB.Invert();
+    clusterWeightsB.Invert();
   } else {
     AliWarning(" Determinant = 0");
-    ClusterWeightsNB.ResizeTo(0,0);
-    ClusterWeightsB.ResizeTo(0,0);
+    clusterWeightsNB.ResizeTo(0,0);
+    clusterWeightsB.ResizeTo(0,0);
     if(deleteMCSCov) delete mcsCovariances;
     return kFALSE;
   }
@@ -852,13 +958,13 @@ Double_t AliMUONTrack::GetNormalizedChi2() const
 }
 
   //__________________________________________________________________________
-Bool_t* AliMUONTrack::CompatibleTrack(AliMUONTrack *track, Double_t sigma2Cut) 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 = sigma2Cut * sigma2Cut;
+  Double_t chi2Max = sigmaCut * sigmaCut;
   Double_t dZMax = 1.; // 1 cm
   
   Bool_t *compatibleCluster = new Bool_t[AliMUONConstants::NTrackingCh()]; 
@@ -904,14 +1010,6 @@ Bool_t* AliMUONTrack::CompatibleTrack(AliMUONTrack *track, Double_t sigma2Cut) c
 }
 
 //__________________________________________________________________________
-AliMUONTrackParam* AliMUONTrack::GetTrackParamAtVertex()
-{
-  /// return reference to track parameters at vertex (create it before if needed)
-  if (!fTrackParamAtVertex) fTrackParamAtVertex = new AliMUONTrackParam();
-  return fTrackParamAtVertex;
-}
-
-//__________________________________________________________________________
 void AliMUONTrack::SetTrackParamAtVertex(const AliMUONTrackParam* trackParam)
 {
   /// set track parameters at vertex