]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalTrackMatcher.h
initializing variables that were declare without a value
[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 #include "AliTrackerBase.h" // Marcel: for EMCal track-matching
25
26 class AliHLTGlobalTrackMatcher : public AliHLTLogging{
27
28 public:
29   AliHLTGlobalTrackMatcher();
30
31   /** destructor */
32   virtual ~AliHLTGlobalTrackMatcher();
33
34   //Main function, loops over tracks and calls appropriate functions to establish matches
35   template <class T>
36   Int_t Match( TObjArray * trackArray, vector<T*>  &phosClustersVector, vector<T*>  &emcalClustersVector,  Double_t bz, Int_t Method ); 
37
38 private:
39   
40   void DoInit();
41
42  
43   //Loops over clusters and decides if track is a good match to any of these
44   template <class T>
45   Int_t MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz); 
46
47   template <class T>
48   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
49
50   //Add track Id to cluster's list of matching tracks
51   Int_t AddTrackToCluster(Int_t tId, Int_t* clustersArray, Bool_t bestMatch, Int_t nMatches);
52   Int_t AddTrackToCluster(Int_t tId, TArrayI* clustersArray, Bool_t bestMatch, Int_t nMatches);
53
54   //Projects track to detector volume and decides if it's anywhere near calorimeter volume
55   Bool_t IsTrackCloseToDetector(AliExternalTrackParam * track, Double_t bz, Double_t fMaxX, Bool_t ySign, Double_t fMaxZ, Double_t dRadius);
56
57   // Geometrical cut off values used to decide whether track is anywhere near calorimeter volumes
58   Float_t fPhosMaxZ;              // max Z track    (cm)
59   Float_t fPhosMaxX;              // max X track    (cm)
60   Float_t fEmcalMaxZ;             // max Z track    (cm)
61   Float_t fEmcalMaxX;             // max X track    (cm)
62
63   Float_t fMatchDistance;        // Square of maximum distance where track is considered a match to cluster (cm^2)
64   Float_t fMatchDistanceEMCal; // Square of maximum distance where track is considered a match to cluster (EtaxPhi space) 
65
66   const Double_t fPhosRadius;          // Radial position of PHOS 
67   const Double_t fEmcalRadius;         // Radial position of EMCAL
68
69   Float_t fStep; // Step for EMCal Extrapolation Calculation
70   Float_t fMass; // Mass for EMCal Extrapolation hipothesis
71
72   AliHLTGlobalTrackMatcher(const AliHLTGlobalTrackMatcher & );
73   AliHLTGlobalTrackMatcher & operator = (const AliHLTGlobalTrackMatcher &);
74
75   ClassDef(AliHLTGlobalTrackMatcher,1) 
76 };
77
78
79 template <class T>
80 Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*>  &phosClustersVector, vector<T*> &emcalClustersVector,  Double_t bz, Int_t Method ) {
81   //Method for extrapolation EMcal
82   //See above for documentation
83
84   Int_t nTracks = trackArray->GetEntriesFast();
85   Int_t nPhosClusters = phosClustersVector.size();
86   Int_t nEmcalClusters = emcalClustersVector.size(); 
87   
88
89   //HLTError("tracks phos emcal %d %d %d", nTracks, nPhosClusters, nEmcalClusters);
90
91   //See if there are tracks and clusters to match
92   if ( nTracks <= 0 ) {
93     return 0;
94   } else if ( (nEmcalClusters <= 0) && (nPhosClusters <= 0))  {
95     return 0;
96   }
97
98
99   Float_t bestMatchPhos[nPhosClusters];   
100   for(int ic = 0; ic < nPhosClusters; ic++) {
101     bestMatchPhos[ic] = 999999;
102   }
103
104   Float_t bestMatchEmcal[nEmcalClusters];   
105   for(int ic = 0; ic < nEmcalClusters; ic++) {
106     bestMatchEmcal[ic] = 999999;
107   }
108
109   //Loop over tracks
110   for (int it = 0; it < nTracks; it++ ) {
111     AliExternalTrackParam * track = static_cast<AliExternalTrackParam*>(trackArray->At(it));
112
113     if ( IsTrackCloseToDetector(track, bz, fEmcalMaxX, kTRUE, fEmcalMaxZ, fEmcalRadius ) ) {
114         if(Method!=1&&Method!=2){
115           HLTError("\n Method %d is not valid",Method);
116           return 0; // No method defined
117           }
118         MatchTrackToEMCalClusters( track, emcalClustersVector, nEmcalClusters, bestMatchEmcal, bz,Method); //With Method
119         
120     } else if  ( IsTrackCloseToDetector(track, bz, fPhosMaxX, kFALSE, fPhosMaxZ, fPhosRadius ) ) {
121       MatchTrackToClusters( track, phosClustersVector, nPhosClusters, bestMatchPhos, bz);
122     } 
123   }   
124     
125   return 0;
126
127
128 //MARCEL 
129 template <class T>
130 Int_t AliHLTGlobalTrackMatcher::MatchTrackToEMCalClusters( AliExternalTrackParam * track,  vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz, Int_t Method ) {
131
132   //See header file for documentation
133   Int_t iResult = 0;
134   Float_t clusterPosition[3];
135   
136   for(int ic = 0; ic < nClusters; ic++) {
137     
138     T * cluster = clustersVector.at(ic);
139  
140     if(cluster->E()<1.)continue;  
141 /* The lines below correspond to the method for Track-matching from RecoUtils:ExtrapolatetoCluster
142    In principle, the method ExtrapolateToCluster should be called directly from RecoUtils. The problems is that This method requires AliVCluster
143    which would have to be created inside the GlobalMatcher, since the information this class obtains from the Cluster comes from the
144    data struct with the cluster information. In order to avoid the whole creation of a AliVCluster object, the code from RecoUtils
145    was brought here in the same way it is written there.
146 */ 
147     cluster->GetPosition(clusterPosition);
148     TVector3 vec(clusterPosition[0],clusterPosition[1],clusterPosition[2]);
149     if(clusterPosition[1]<0.)   continue;  
150     if(TMath::Abs(track->Eta()-vec.Eta())>0.3)  continue; 
151     
152     AliExternalTrackParam *trkParam = new AliExternalTrackParam(*track);//Retrieve the starting point every time before the extrapolation
153     Double_t trkPos[3] = {0, 0, 0};
154     Double_t alpha =  ((int)(vec.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad();
155     vec.RotateZ(-alpha); //Rotate the cluster to the local extrapolation coordinate system
156     trkParam->Rotate(alpha); //Rotate the track to the same local extrapolation system
157     if(1==Method&&!trkParam->GetXYZAt(vec.X(), bz, trkPos))             continue; // Simpler extrapolation  
158     if(2==Method){
159       if(!AliTrackerBase::PropagateTrackToBxByBz(trkParam, vec.X(), fMass, fStep,kFALSE, 0.8, -1))      continue;  
160       trkParam->GetXYZ(trkPos); //Get the extrapolated global position
161       }
162
163     TVector3 clsPosVec(clusterPosition[0],clusterPosition[1],clusterPosition[2]);
164     TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
165
166     // track cluster matching
167     Double_t tmpPhi = clsPosVec.DeltaPhi(trkPosVec); // tmpPhi is between -pi and pi
168     Double_t tmpEta = clsPosVec.Eta()-trkPosVec.Eta();  // track cluster matching
169     Double_t match=TMath::Sqrt(tmpEta*tmpEta + tmpPhi*tmpPhi);//MARCEL
170  
171     if( match > fMatchDistanceEMCal )continue;
172     
173     if (match < bestMatch[ic]) {
174       bestMatch[ic] = match;
175       cluster->SetEmcCpvDistance(TMath::Sqrt(match));
176       Double_t dx=tmpPhi;
177       Double_t dz=tmpEta;  
178       cluster->SetTrackDistance(dx,dz);
179     }
180     //Add track to cluster's array of matching tracks
181     Int_t nTracksMatched = cluster->GetNTracksMatched();
182     iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched);
183   }
184   
185   return iResult;
186 }
187
188 template <class T>
189 Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * track, vector<T*>  &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz) {
190   
191   //See header file for documentation
192   Int_t iResult = 0;
193  
194   Float_t clusterPosition[3];
195   Double_t trackPosition[3];
196   
197   for(int ic = 0; ic < nClusters; ic++) {
198     
199     T * cluster = clustersVector.at(ic);
200     
201     //Get cluster global coordinates
202     cluster->GetPosition(clusterPosition);
203
204     Double_t rCluster = TMath::Sqrt(clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1]);      
205
206     //Rotate tracking system to the angle of the cluster
207     TVector3 cVec(clusterPosition);
208     if (! (track->Rotate(cVec.Phi())) ) {
209       continue;
210     }
211    
212     if(! (track->GetXYZAt(rCluster, bz, trackPosition)) ) {
213       continue;
214     }
215
216     //Calculate track - cluster residuals
217     Double_t match = 0;
218     for(int i = 0; i < 3; i++) {
219       Double_t dd = trackPosition[i] - clusterPosition[i];
220       match += dd*dd;
221     }
222  
223
224     if( match > fMatchDistance  )  {     
225       continue;
226     }
227
228     if (match < bestMatch[ic]) {
229       
230       bestMatch[ic] = match;
231       cluster->SetEmcCpvDistance(TMath::Sqrt(match));
232       
233       Double_t dx = trackPosition[0] - clusterPosition[0];
234       Double_t dy = trackPosition[1] - clusterPosition[1];
235       Double_t dz = trackPosition[2] - clusterPosition[2];
236       cluster->SetTrackDistance( ((dx > 0) ? 1 : -1 )*TMath::Sqrt(dx*dx + dy*dy), dz);
237     }
238     
239     //Add track to cluster's array of matching tracks
240     Int_t nTracksMatched = cluster->GetNTracksMatched();
241     iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched);
242   }
243   
244   return iResult;
245 }
246
247 #endif