]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalTrackMatcher.h
Updated track-matcher component to deal with EMCAL
[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 #include "AliHLTLogging.h"
19 #include "AliESDtrack.h"
20 #include "TObjArray.h"
21 #include "TArrayI.h"
22
23 class AliHLTGlobalTrackMatcher : public AliHLTLogging {
24
25 public:
26
27   ///Constructor
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*>  &clustersVector, Double_t bz ); 
36
37
38   ///Set the maximum Z to be within distance of detector volume
39   void SetMaxZ(Float_t z) { fMaxZ = z; }
40   ///Set the maximum X to be within distance of detector volume
41   void SetMaxX(Float_t x) { fMaxX = x; }
42   ///Set whether the detector is in positive y direction
43   void SetYSign(Bool_t y) { fYSign = y; }
44   ///Set the max distance to be considered a match
45   void SetMatchDistance(Float_t d)  { fMatchDistance = d*d; }
46   ///Set the radius of detector volume
47   void SetRadius(Float_t r) { fRadius = r; }
48
49 private:  
50
51   void DoInit();
52
53   //Loops over clusters and decides if track is a good match to any of these
54   template <class T>
55   Int_t MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz); 
56
57   //Add track Id to cluster's list of matching tracks
58   Int_t AddTrackToCluster(Int_t tId, Int_t* clustersArray, Bool_t bestMatch, Int_t nMatches);
59   Int_t AddTrackToCluster(Int_t tId, TArrayI* clustersArray, Bool_t bestMatch, Int_t nMatches);
60
61   //Projects track to detector volume and decides if it's anywhere near calorimeter volume
62   Bool_t IsTrackCloseToDetector(AliExternalTrackParam * track, Double_t bz, Double_t fMaxX, Bool_t ySign, Double_t fMaxZ, Double_t dRadius);
63
64   // Geometrical cut off values used to decide whether track is anywhere near calorimeter volumes
65   Float_t fMaxZ;              // max Z track    (cm)
66   Float_t fMaxX;              // max X track    (cm)
67
68   Float_t fMatchDistance;     // Square of maximum distance where track is considered a match to cluster (cm^2)
69   Double_t fRadius;           // Radial position of detector volume
70   Bool_t fYSign;               // Positive or negative y
71
72   AliHLTGlobalTrackMatcher(const AliHLTGlobalTrackMatcher & );
73   AliHLTGlobalTrackMatcher & operator = (const AliHLTGlobalTrackMatcher &);
74
75   ClassDef(AliHLTGlobalTrackMatcher,1) 
76 };
77
78
79
80 template <class T>
81 Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*>  &clustersVector, Double_t bz ) {
82   //See above for documentation
83
84
85   Int_t nTracks = trackArray->GetEntriesFast();
86   Int_t nClusters = clustersVector.size();
87
88   if ( nTracks <= 0 ) {
89     return 0;
90   } else if  ( nClusters <= 0 )  {
91     return 0;
92   }
93
94   Float_t bestMatch[nClusters];   
95   for(int ic = 0; ic < nClusters; ic++) {
96     bestMatch[ic] = 999999;
97   }
98     
99   for (int it = 0; it < nTracks; it++ ) {
100     AliExternalTrackParam * track = static_cast<AliExternalTrackParam*>(trackArray->At(it));
101     if ( IsTrackCloseToDetector(track, bz, fMaxX, fYSign, fMaxZ, fRadius ) ) {
102       MatchTrackToClusters( track, clustersVector, nClusters, bestMatch, bz);
103     } 
104   } 
105   return 0;
106 }
107
108
109
110 template <class T>
111 Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz) {
112   //See header file for documentation
113   Int_t iResult = 0;
114  
115   Float_t clusterPosition[3];
116   Double_t trackPosition[3];
117  
118     for(int ic = 0; ic < nClusters; ic++) {
119     
120     T * cluster = clustersVector.at(ic);
121     
122     cluster->GetPosition(clusterPosition);
123    
124     //Get track postion at radius of cluster
125     Double_t rCluster = TMath::Sqrt(clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1]);      
126     if (! (track->GetXYZAt(rCluster, bz, trackPosition)) ) {
127       HLTInfo("Track reached detector but not cluster!!!!!!");
128       continue;
129     }
130
131     //Calculate track - cluster residual
132     Double_t dxy = 0;
133     for(int i = 0; i < 2; i++) {
134       Double_t dd = trackPosition[i] - clusterPosition[i];
135       dxy += dd*dd;
136     }
137
138     Double_t dd = trackPosition[2] - clusterPosition[2];
139     Double_t dz = dd*dd;
140   
141     Double_t match = dz + dxy;
142     
143     if( match > fMatchDistance  )  {     
144       continue;
145     }
146
147     if (match < bestMatch[ic]) {
148       bestMatch[ic] = match;
149       cluster->SetEmcCpvDistance(TMath::Sqrt(match));
150       cluster->SetTrackDistance(TMath::Sqrt(dxy), TMath::Sqrt(dz));
151     }
152     
153     Int_t nTracksMatched = cluster->GetNTracksMatched();
154     iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched);
155   }
156   
157   return iResult;
158 }
159
160 #endif