]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/global/AliHLTGlobalTrackMatcher.h
HLTpendolino
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalTrackMatcher.h
index 958636c43f1782c20e0ed589c893be2f3211e89a..74de6f1e3edc156af01ef7e979f72b63f219d69d 100644 (file)
 */
 
 
+
 #include "AliHLTLogging.h"
 #include "AliESDtrack.h"
 #include "TObjArray.h"
 #include "TArrayI.h"
 #include "TVector3.h"
+#include "AliTrackerBase.h" // Marcel: for EMCal track-matching
 
 class AliHLTGlobalTrackMatcher : public AliHLTLogging{
 
@@ -31,16 +33,20 @@ public:
 
   //Main function, loops over tracks and calls appropriate functions to establish matches
   template <class T>
-  Int_t Match( TObjArray * trackArray, vector<T*>  &phosClustersVector, vector<T*>  &emcalClustersVector,  Double_t bz ); 
-  
+  Int_t Match( TObjArray * trackArray, vector<T*>  &phosClustersVector, vector<T*>  &emcalClustersVector,  Double_t bz, Int_t Method ); 
+
 private:
   
   void DoInit();
 
   //Loops over clusters and decides if track is a good match to any of these
   template <class T>
   Int_t MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz); 
 
+  template <class T>
+  Int_t MatchTrackToEMCalClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz, Int_t Method); // EMCal Track-Matching from recoUtils::ExtrapolateTracktoCluster
+
   //Add track Id to cluster's list of matching tracks
   Int_t AddTrackToCluster(Int_t tId, Int_t* clustersArray, Bool_t bestMatch, Int_t nMatches);
   Int_t AddTrackToCluster(Int_t tId, TArrayI* clustersArray, Bool_t bestMatch, Int_t nMatches);
@@ -55,10 +61,14 @@ private:
   Float_t fEmcalMaxX;             // max X track    (cm)
 
   Float_t fMatchDistance;        // Square of maximum distance where track is considered a match to cluster (cm^2)
+  Float_t fMatchDistanceEMCal; // Square of maximum distance where track is considered a match to cluster (EtaxPhi space) 
 
   const Double_t fPhosRadius;          // Radial position of PHOS 
   const Double_t fEmcalRadius;         // Radial position of EMCAL
 
+  Float_t fStep; // Step for EMCal Extrapolation Calculation
+  Float_t fMass; // Mass for EMCal Extrapolation hipothesis
+
   AliHLTGlobalTrackMatcher(const AliHLTGlobalTrackMatcher & );
   AliHLTGlobalTrackMatcher & operator = (const AliHLTGlobalTrackMatcher &);
 
@@ -67,10 +77,10 @@ private:
 
 
 template <class T>
-Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*>  &phosClustersVector, vector<T*> &emcalClustersVector,  Double_t bz ) {
+Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*>  &phosClustersVector, vector<T*> &emcalClustersVector,  Double_t bz, Int_t Method ) {
+  //Method for extrapolation EMcal
   //See above for documentation
 
-
   Int_t nTracks = trackArray->GetEntriesFast();
   Int_t nPhosClusters = phosClustersVector.size();
   Int_t nEmcalClusters = emcalClustersVector.size(); 
@@ -100,19 +110,80 @@ Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*>  &phos
   for (int it = 0; it < nTracks; it++ ) {
     AliExternalTrackParam * track = static_cast<AliExternalTrackParam*>(trackArray->At(it));
 
-    if ( IsTrackCloseToDetector(track, bz, fPhosMaxX, kFALSE, fPhosMaxZ, fPhosRadius ) ) {
+    if ( IsTrackCloseToDetector(track, bz, fEmcalMaxX, kTRUE, fEmcalMaxZ, fEmcalRadius ) ) {
+        if(Method!=1&&Method!=2){
+         HLTError("\n Method %d is not valid",Method);
+         return 0; // No method defined
+         }
+       MatchTrackToEMCalClusters( track, emcalClustersVector, nEmcalClusters, bestMatchEmcal, bz,Method); //With Method
+       
+    } else if  ( IsTrackCloseToDetector(track, bz, fPhosMaxX, kFALSE, fPhosMaxZ, fPhosRadius ) ) {
       MatchTrackToClusters( track, phosClustersVector, nPhosClusters, bestMatchPhos, bz);
-
-    } else if ( IsTrackCloseToDetector(track, bz, fEmcalMaxX, kTRUE, fEmcalMaxZ, fEmcalRadius ) ) {
-      MatchTrackToClusters( track, emcalClustersVector, nEmcalClusters, bestMatchEmcal, bz);
     } 
-
   }   
     
   return 0;
 } 
 
+//MARCEL 
+template <class T>
+Int_t AliHLTGlobalTrackMatcher::MatchTrackToEMCalClusters( AliExternalTrackParam * track,  vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz, Int_t Method ) {
 
+  //See header file for documentation
+  Int_t iResult = 0;
+  Float_t clusterPosition[3];
+  
+  for(int ic = 0; ic < nClusters; ic++) {
+    
+    T * cluster = clustersVector.at(ic);
+    if(cluster->E()<1.)continue;  
+/* The lines below correspond to the method for Track-matching from RecoUtils:ExtrapolatetoCluster
+   In principle, the method ExtrapolateToCluster should be called directly from RecoUtils. The problems is that This method requires AliVCluster
+   which would have to be created inside the GlobalMatcher, since the information this class obtains from the Cluster comes from the
+   data struct with the cluster information. In order to avoid the whole creation of a AliVCluster object, the code from RecoUtils
+   was brought here in the same way it is written there.
+*/ 
+    cluster->GetPosition(clusterPosition);
+    TVector3 vec(clusterPosition[0],clusterPosition[1],clusterPosition[2]);
+    if(clusterPosition[1]<0.)  continue;  
+    if(TMath::Abs(track->Eta()-vec.Eta())>0.3) continue; 
+    
+    AliExternalTrackParam *trkParam = new AliExternalTrackParam(*track);//Retrieve the starting point every time before the extrapolation
+    Double_t trkPos[3] = {0, 0, 0};
+    Double_t alpha =  ((int)(vec.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad();
+    vec.RotateZ(-alpha); //Rotate the cluster to the local extrapolation coordinate system
+    trkParam->Rotate(alpha); //Rotate the track to the same local extrapolation system
+    if(1==Method&&!trkParam->GetXYZAt(vec.X(), bz, trkPos))            continue; // Simpler extrapolation  
+    if(2==Method){
+      if(!AliTrackerBase::PropagateTrackToBxByBz(trkParam, vec.X(), fMass, fStep,kFALSE, 0.8, -1))     continue;  
+      trkParam->GetXYZ(trkPos); //Get the extrapolated global position
+      }
+
+    TVector3 clsPosVec(clusterPosition[0],clusterPosition[1],clusterPosition[2]);
+    TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
+
+    // track cluster matching
+    Double_t tmpPhi = clsPosVec.DeltaPhi(trkPosVec); // tmpPhi is between -pi and pi
+    Double_t tmpEta = clsPosVec.Eta()-trkPosVec.Eta();  // track cluster matching
+    Double_t match=TMath::Sqrt(tmpEta*tmpEta + tmpPhi*tmpPhi);//MARCEL
+    if( match > fMatchDistanceEMCal )continue;
+    
+    if (match < bestMatch[ic]) {
+      bestMatch[ic] = match;
+      cluster->SetEmcCpvDistance(TMath::Sqrt(match));
+      Double_t dx=tmpPhi;
+      Double_t dz=tmpEta;  
+      cluster->SetTrackDistance(dx,dz);
+    }
+    //Add track to cluster's array of matching tracks
+    Int_t nTracksMatched = cluster->GetNTracksMatched();
+    iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched);
+  }
+  
+  return iResult;
+}
 
 template <class T>
 Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz) {
@@ -122,7 +193,6 @@ Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * tr
  
   Float_t clusterPosition[3];
   Double_t trackPosition[3];
   
   for(int ic = 0; ic < nClusters; ic++) {
     
@@ -142,28 +212,28 @@ Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * tr
     if(! (track->GetXYZAt(rCluster, bz, trackPosition)) ) {
       continue;
     }
-    
-    //Get residual in z= 0 plane (squared)
-    Double_t dxy = 0;
-    for(int i = 0; i < 2; i++) {
+
+    //Calculate track - cluster residuals
+    Double_t match = 0;
+    for(int i = 0; i < 3; i++) {
       Double_t dd = trackPosition[i] - clusterPosition[i];
-      dxy += dd*dd;
+      match += dd*dd;
     }
 
-    //Get z residual (squared)
-    Double_t dd = trackPosition[2] - clusterPosition[2];
-    Double_t dz = dd*dd;
-  
-    Double_t match = dz + dxy;
-    
     if( match > fMatchDistance  )  {     
       continue;
     }
 
     if (match < bestMatch[ic]) {
+      
       bestMatch[ic] = match;
       cluster->SetEmcCpvDistance(TMath::Sqrt(match));
-      cluster->SetTrackDistance(TMath::Sqrt(dxy), TMath::Sqrt(dz));
+      
+      Double_t dx = trackPosition[0] - clusterPosition[0];
+      Double_t dy = trackPosition[1] - clusterPosition[1];
+      Double_t dz = trackPosition[2] - clusterPosition[2];
+      cluster->SetTrackDistance( ((dx > 0) ? 1 : -1 )*TMath::Sqrt(dx*dx + dy*dy), dz);
     }
     
     //Add track to cluster's array of matching tracks