]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalTrackMatcher.h
- using AliVertexerTracks initialization provided by Andrea
[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   AliHLTGlobalTrackMatcher();
27
28   /** destructor */
29   virtual ~AliHLTGlobalTrackMatcher();
30
31   //Main function, loops over tracks and calls appropriate functions to establish matches
32   template <class T>
33   Int_t Match( TObjArray * trackArray, vector<T*>  &clustersVector, Double_t bz ); 
34   
35 private:
36   
37   void DoInit();
38
39   //Loops over clusters and decides if track is a good match to any of these
40   template <class T>
41   Int_t MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz); 
42
43   //Add track Id to cluster's list of matching tracks
44   Int_t AddTrackToCluster(Int_t tId, Int_t* clustersArray, Bool_t bestMatch, Int_t nMatches);
45   Int_t AddTrackToCluster(Int_t tId, TArrayI* clustersArray, Bool_t bestMatch, Int_t nMatches);
46
47   //Projects track to detector volume and decides if it's anywhere near calorimeter volume
48   Bool_t IsTrackCloseToDetector(AliExternalTrackParam * track, Double_t bz, Double_t fMaxX, Bool_t ySign, Double_t fMaxZ, Double_t dRadius);
49
50   // Geometrical cut off values used to decide whether track is anywhere near calorimeter volumes
51   Float_t fPhosMaxZ;              // max Z track    (cm)
52   Float_t fPhosMaxX;              // max X track    (cm)
53   Float_t fEmcalMaxZ;             // max Z track    (cm)
54   Float_t fEmcalMaxX;             // max X track    (cm)
55
56   Float_t fMatchDistance;        // Square of maximum distance where track is considered a match to cluster (cm^2)
57
58   const Double_t fPhosRadius;          // Radial position of PHOS 
59   const Double_t fEmcalRadius;         // Radial position of EMCAL
60
61   AliHLTGlobalTrackMatcher(const AliHLTGlobalTrackMatcher & );
62   AliHLTGlobalTrackMatcher & operator = (const AliHLTGlobalTrackMatcher &);
63
64   ClassDef(AliHLTGlobalTrackMatcher,1) 
65 };
66
67
68 template <class T>
69 Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*>  &clustersVector, Double_t bz ) {
70   //See above for documentation
71
72   Int_t nTracks = trackArray->GetEntriesFast();
73   Int_t nPhosClusters = clustersVector.size();
74  
75   //TODO emcal not yet implemented
76   Int_t nEmcalClusters = 0; //BALLE event->GetEMCALClusters(fEmcalClustersArray);
77   
78   if ( nTracks <= 0 ) {
79     //    HLTWarning("No tracks in event");
80     return 0;
81   } else if  ( (nEmcalClusters <= 0) && (nPhosClusters <= 0))  {
82     //HLTWarning("No calorimeter clusters in Event"); 
83     return 0;
84   }
85
86   Float_t bestMatchPhos[nPhosClusters];   
87   for(int ic = 0; ic < nPhosClusters; ic++) {
88     bestMatchPhos[ic] = 999999;
89   }
90     
91   //BALLE TODO EMCAL implement
92   // Float_t bestMatchEmcal[nEmcalClusters];    
93   //   for(int ic = 0; ic < nEmcalClusters; ic++) {
94   //     bestMatchEmcal[ic] = 999999;
95   //   }
96     
97     
98   //Loop over tracks
99   for (int it = 0; it < nTracks; it++ ) {
100     AliExternalTrackParam * track = static_cast<AliExternalTrackParam*>(trackArray->At(it));
101
102     if ( IsTrackCloseToDetector(track, bz, fPhosMaxX, kFALSE, fPhosMaxZ, fPhosRadius ) ) {
103       MatchTrackToClusters( track, clustersVector, nPhosClusters, bestMatchPhos, bz);
104       
105       //BALLE TODO EMCAL !!!!
106       //     } else if ( IsTrackCloseToDetector(track, bz, fEmcalMaxX, kTRUE, fEmcalMaxZ, fEmcalRadius ) ) {
107       //       MatchTrackToClusters( track, fEmcalClustersArray, nEmcalClusters, bestMatchEmcal, bz);
108     } 
109     
110
111   } // track loop 
112   
113     
114   return 0;
115
116
117
118
119 template <class T>
120 Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz) {
121   
122   //See header file for documentation
123   Int_t iResult = 0;
124  
125   Float_t clusterPosition[3];
126   Double_t trackPosition[3];
127  
128   
129   for(int ic = 0; ic < nClusters; ic++) {
130     
131     T * cluster = clustersVector.at(ic);
132     
133     //Get cluster global coordinates
134     cluster->GetPosition(clusterPosition);
135    
136     //Get track postion at radius of cluster
137     Double_t rCluster = TMath::Sqrt(clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1]);      
138     if (! (track->GetXYZAt(rCluster, bz, trackPosition)) ) {
139       HLTInfo("Track reached detector but not cluster!!!!!!");
140       continue;
141     }
142
143
144     //    HLTInfo("Cluster global position %f %f %f", clusterPosition[0],clusterPosition[1],clusterPosition[2]);
145
146     
147     //Calculate track - cluster residual
148   
149
150     //Get residual in z= 0 plane (squared)
151     Double_t dxy = 0;
152     for(int i = 0; i < 2; i++) {
153       Double_t dd = trackPosition[i] - clusterPosition[i];
154       dxy += dd*dd;
155     }
156
157     //Get z residual (squared)
158     Double_t dd = trackPosition[2] - clusterPosition[2];
159     Double_t dz = dd*dd;
160   
161     Double_t match = dz + dxy;
162     
163     //    HLTInfo("Track cluster residual %f, maxmatch %f", match, fMatchDistance);
164     
165     if( match > fMatchDistance  )  {     
166       continue;
167     }
168
169
170     if (match < bestMatch[ic]) {
171       bestMatch[ic] = match;
172       cluster->SetEmcCpvDistance(TMath::Sqrt(match));
173       cluster->SetTrackDistance(TMath::Sqrt(dxy), TMath::Sqrt(dz));
174     }
175     
176     //Add track to cluster's array of matching tracks
177     Int_t nTracksMatched = cluster->GetNTracksMatched();
178     iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched);
179     //HLTInfo("Added track %d to cluster %d, it now has %d matching tracks", track->GetID(), cluster->GetID(), cluster->GetNTracksMatched());
180   }
181   
182   return iResult;
183 }
184
185 #endif