]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalTrackMatcher.h
- commented out the UPC and V0 branches
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalTrackMatcher.h
1 //$Id$
2
3 #ifndef ALIHLTGLOBALTRACKMATCHER_H
4 #define ALIHLTGLOBALTRACKMATCHER_H
5
6
7 //* This file is property of and copyright by the ALICE HLT Project        * 
8 //* ALICE Experiment at CERN, All rights reserved.                         *
9 //* See cxx source for full Copyright notice                               *
10
11 /** @file   AliHLTGlobalTrackMatcher.h
12     @author Svein Lindal (svein.lindal@fys.uio.no)
13     @date   
14     @brief  The HLT class matching TPC tracks to calorimeter clusters
15 */
16
17
18
19 #include "AliHLTLogging.h"
20 #include "AliESDtrack.h"
21 #include "TObjArray.h"
22 #include "TArrayI.h"
23 #include "TVector3.h"
24
25 class AliHLTGlobalTrackMatcher : public AliHLTLogging{
26
27 public:
28   AliHLTGlobalTrackMatcher();
29
30   /** destructor */
31   virtual ~AliHLTGlobalTrackMatcher();
32
33   //Main function, loops over tracks and calls appropriate functions to establish matches
34   template <class T>
35   Int_t Match( TObjArray * trackArray, vector<T*>  &phosClustersVector, vector<T*>  &emcalClustersVector,  Double_t bz ); 
36   
37 private:
38   
39   void DoInit();
40
41   //Loops over clusters and decides if track is a good match to any of these
42   template <class T>
43   Int_t MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz); 
44
45   //Add track Id to cluster's list of matching tracks
46   Int_t AddTrackToCluster(Int_t tId, Int_t* clustersArray, Bool_t bestMatch, Int_t nMatches);
47   Int_t AddTrackToCluster(Int_t tId, TArrayI* clustersArray, Bool_t bestMatch, Int_t nMatches);
48
49   //Projects track to detector volume and decides if it's anywhere near calorimeter volume
50   Bool_t IsTrackCloseToDetector(AliExternalTrackParam * track, Double_t bz, Double_t fMaxX, Bool_t ySign, Double_t fMaxZ, Double_t dRadius);
51
52   // Geometrical cut off values used to decide whether track is anywhere near calorimeter volumes
53   Float_t fPhosMaxZ;              // max Z track    (cm)
54   Float_t fPhosMaxX;              // max X track    (cm)
55   Float_t fEmcalMaxZ;             // max Z track    (cm)
56   Float_t fEmcalMaxX;             // max X track    (cm)
57
58   Float_t fMatchDistance;        // Square of maximum distance where track is considered a match to cluster (cm^2)
59
60   const Double_t fPhosRadius;          // Radial position of PHOS 
61   const Double_t fEmcalRadius;         // Radial position of EMCAL
62
63   AliHLTGlobalTrackMatcher(const AliHLTGlobalTrackMatcher & );
64   AliHLTGlobalTrackMatcher & operator = (const AliHLTGlobalTrackMatcher &);
65
66   ClassDef(AliHLTGlobalTrackMatcher,1) 
67 };
68
69
70 template <class T>
71 Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*>  &phosClustersVector, vector<T*> &emcalClustersVector,  Double_t bz ) {
72   //See above for documentation
73
74
75   Int_t nTracks = trackArray->GetEntriesFast();
76   Int_t nPhosClusters = phosClustersVector.size();
77   Int_t nEmcalClusters = emcalClustersVector.size(); 
78   
79
80   //HLTError("tracks phos emcal %d %d %d", nTracks, nPhosClusters, nEmcalClusters);
81
82   //See if there are tracks and clusters to match
83   if ( nTracks <= 0 ) {
84     return 0;
85   } else if ( (nEmcalClusters <= 0) && (nPhosClusters <= 0))  {
86     return 0;
87   }
88
89
90   Float_t bestMatchPhos[nPhosClusters];   
91   for(int ic = 0; ic < nPhosClusters; ic++) {
92     bestMatchPhos[ic] = 999999;
93   }
94
95   Float_t bestMatchEmcal[nEmcalClusters];   
96   for(int ic = 0; ic < nEmcalClusters; ic++) {
97     bestMatchEmcal[ic] = 999999;
98   }
99
100   //Loop over tracks
101   for (int it = 0; it < nTracks; it++ ) {
102     AliExternalTrackParam * track = static_cast<AliExternalTrackParam*>(trackArray->At(it));
103
104     if ( IsTrackCloseToDetector(track, bz, fPhosMaxX, kFALSE, fPhosMaxZ, fPhosRadius ) ) {
105       MatchTrackToClusters( track, phosClustersVector, nPhosClusters, bestMatchPhos, bz);
106
107     } else if ( IsTrackCloseToDetector(track, bz, fEmcalMaxX, kTRUE, fEmcalMaxZ, fEmcalRadius ) ) {
108       MatchTrackToClusters( track, emcalClustersVector, nEmcalClusters, bestMatchEmcal, bz);
109     } 
110
111   }   
112     
113   return 0;
114
115
116
117
118 template <class T>
119 Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz) {
120   
121   //See header file for documentation
122   Int_t iResult = 0;
123  
124   Float_t clusterPosition[3];
125   Double_t trackPosition[3];
126  
127   
128   for(int ic = 0; ic < nClusters; ic++) {
129     
130     T * cluster = clustersVector.at(ic);
131     
132     //Get cluster global coordinates
133     cluster->GetPosition(clusterPosition);
134
135     Double_t rCluster = TMath::Sqrt(clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1]);      
136
137     //Rotate tracking system to the angle of the cluster
138     TVector3 cVec(clusterPosition);
139     if (! (track->Rotate(cVec.Phi())) ) {
140       continue;
141     }
142    
143     if(! (track->GetXYZAt(rCluster, bz, trackPosition)) ) {
144       continue;
145     }
146
147     //Calculate track - cluster residuals
148     Double_t match = 0;
149     for(int i = 0; i < 3; i++) {
150       Double_t dd = trackPosition[i] - clusterPosition[i];
151       match += dd*dd;
152     }
153
154     if( match > fMatchDistance  )  {     
155       continue;
156     }
157
158     if (match < bestMatch[ic]) {
159       
160       bestMatch[ic] = match;
161       cluster->SetEmcCpvDistance(TMath::Sqrt(match));
162       
163       Double_t dx = trackPosition[0] - clusterPosition[0];
164       Double_t dy = trackPosition[1] - clusterPosition[1];
165       Double_t dz = trackPosition[2] - clusterPosition[2];
166       cluster->SetTrackDistance( ((dx > 0) ? 1 : -1 )*TMath::Sqrt(dx*dx + dy*dy), dz);
167     }
168     
169     //Add track to cluster's array of matching tracks
170     Int_t nTracksMatched = cluster->GetNTracksMatched();
171     iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched);
172   }
173   
174   return iResult;
175 }
176
177 #endif