]>
Commit | Line | Data |
---|---|---|
d64429af | 1 | //$Id$ |
2 | ||
3cfb9c56 | 3 | #ifndef ALIHLTGLOBALTRACKMATCHER_H |
4 | #define ALIHLTGLOBALTRACKMATCHER_H | |
434146d0 | 5 | |
6 | ||
3cfb9c56 | 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 | |
b3e7198f | 14 | @brief The HLT class matching TPC tracks to calorimeter clusters |
3cfb9c56 | 15 | */ |
16 | ||
17 | ||
e5b4e619 | 18 | |
3cfb9c56 | 19 | #include "AliHLTLogging.h" |
20 | #include "AliESDtrack.h" | |
2a24cbbe | 21 | #include "TObjArray.h" |
22 | #include "TArrayI.h" | |
52426eff | 23 | #include "TVector3.h" |
5d8d9319 | 24 | #include "AliTrackerBase.h" // Marcel: for EMCal track-matching |
3cfb9c56 | 25 | |
a46c7ba5 | 26 | class AliHLTGlobalTrackMatcher : public AliHLTLogging{ |
b3e7198f | 27 | |
3cfb9c56 | 28 | public: |
29 | AliHLTGlobalTrackMatcher(); | |
b3e7198f | 30 | |
a46c7ba5 | 31 | /** destructor */ |
3cfb9c56 | 32 | virtual ~AliHLTGlobalTrackMatcher(); |
33 | ||
a46c7ba5 | 34 | //Main function, loops over tracks and calls appropriate functions to establish matches |
2a24cbbe | 35 | template <class T> |
ec54c698 | 36 | Int_t Match( TObjArray * trackArray, vector<T*> &phosClustersVector, vector<T*> &emcalClustersVector, Double_t bz ); |
5d8d9319 | 37 | |
a46c7ba5 | 38 | private: |
39 | ||
434146d0 | 40 | void DoInit(); |
bad7877b | 41 | |
5d8d9319 | 42 | |
2a24cbbe | 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); | |
bad7877b | 46 | |
5d8d9319 | 47 | template <class T> |
48 | Int_t MatchTrackToEMCalClusters( AliExternalTrackParam * track, vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz); // EMCal Track-Matching from recoUtils::ExtrapolateTracktoCluster | |
49 | ||
2a24cbbe | 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 | |
a46c7ba5 | 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) | |
5d8d9319 | 64 | Float_t fMatchDistanceEMCal; // Square of maximum distance where track is considered a match to cluster (EtaxPhi space) |
3cfb9c56 | 65 | |
a46c7ba5 | 66 | const Double_t fPhosRadius; // Radial position of PHOS |
67 | const Double_t fEmcalRadius; // Radial position of EMCAL | |
bad7877b | 68 | |
bc72e5b9 | 69 | AliHLTGlobalTrackMatcher(const AliHLTGlobalTrackMatcher & ); |
70 | AliHLTGlobalTrackMatcher & operator = (const AliHLTGlobalTrackMatcher &); | |
71 | ||
2a24cbbe | 72 | ClassDef(AliHLTGlobalTrackMatcher,1) |
3cfb9c56 | 73 | }; |
74 | ||
2a24cbbe | 75 | |
76 | template <class T> | |
e5b4e619 | 77 | Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*> &phosClustersVector, vector<T*> &emcalClustersVector, Double_t bz ) { |
2a24cbbe | 78 | //See above for documentation |
79 | ||
80 | Int_t nTracks = trackArray->GetEntriesFast(); | |
ec54c698 | 81 | Int_t nPhosClusters = phosClustersVector.size(); |
82 | Int_t nEmcalClusters = emcalClustersVector.size(); | |
a46c7ba5 | 83 | |
ec54c698 | 84 | |
4502b5bb | 85 | //HLTError("tracks phos emcal %d %d %d", nTracks, nPhosClusters, nEmcalClusters); |
86 | ||
ec54c698 | 87 | //See if there are tracks and clusters to match |
2a24cbbe | 88 | if ( nTracks <= 0 ) { |
2a24cbbe | 89 | return 0; |
ec54c698 | 90 | } else if ( (nEmcalClusters <= 0) && (nPhosClusters <= 0)) { |
2a24cbbe | 91 | return 0; |
92 | } | |
93 | ||
e5b4e619 | 94 | |
a46c7ba5 | 95 | Float_t bestMatchPhos[nPhosClusters]; |
96 | for(int ic = 0; ic < nPhosClusters; ic++) { | |
97 | bestMatchPhos[ic] = 999999; | |
2a24cbbe | 98 | } |
ec54c698 | 99 | |
100 | Float_t bestMatchEmcal[nEmcalClusters]; | |
101 | for(int ic = 0; ic < nEmcalClusters; ic++) { | |
102 | bestMatchEmcal[ic] = 999999; | |
103 | } | |
104 | ||
a46c7ba5 | 105 | //Loop over tracks |
2a24cbbe | 106 | for (int it = 0; it < nTracks; it++ ) { |
107 | AliExternalTrackParam * track = static_cast<AliExternalTrackParam*>(trackArray->At(it)); | |
a46c7ba5 | 108 | |
e5b4e619 | 109 | if ( IsTrackCloseToDetector(track, bz, fPhosMaxX, kFALSE, fPhosMaxZ, fPhosRadius ) ) { |
110 | MatchTrackToClusters( track, phosClustersVector, nPhosClusters, bestMatchPhos, bz); | |
111 | ||
112 | } else if ( IsTrackCloseToDetector(track, bz, fEmcalMaxX, kTRUE, fEmcalMaxZ, fEmcalRadius ) ) { | |
5d8d9319 | 113 | MatchTrackToEMCalClusters( track, emcalClustersVector, nEmcalClusters, bestMatchEmcal, bz); |
e5b4e619 | 114 | } |
115 | ||
ec54c698 | 116 | } |
e5b4e619 | 117 | |
2a24cbbe | 118 | return 0; |
a46c7ba5 | 119 | } |
2a24cbbe | 120 | |
5d8d9319 | 121 | //MARCEL |
122 | template <class T> | |
123 | Int_t AliHLTGlobalTrackMatcher::MatchTrackToEMCalClusters( AliExternalTrackParam * track, vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t /* bz */) { | |
124 | ||
125 | //See header file for documentation | |
126 | Int_t iResult = 0; | |
127 | ||
128 | Float_t clusterPosition[3]; | |
129 | //Double_t trackPosition[3]; | |
130 | ||
131 | for(int ic = 0; ic < nClusters; ic++) { | |
132 | ||
133 | T * cluster = clustersVector.at(ic); | |
134 | ||
135 | /* The lines below correspond to the method for Track-matching from RecoUtils:ExtrapolatetoCluster | |
136 | In principle, the method ExtrapolateToCluster should be called directly from RecoUtils. The problems is that This method requires AliVCluster | |
137 | which would have to be created inside the GlobalMatcher, since the information this class obtains from the Cluster comes from the | |
138 | data struct with the cluster information. In order to avoid the whole creation of a AliVCluster object, the code from RecoUtils | |
139 | was brought here in the same way it is written there. | |
140 | */ | |
141 | cluster->GetPosition(clusterPosition); | |
142 | TVector3 VClsPos(clusterPosition[0], clusterPosition[1], clusterPosition[2]); //MARCEL | |
143 | //Double_t rCluster = TMath::Sqrt(clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1]); | |
144 | AliExternalTrackParam *trkParam = new AliExternalTrackParam(*track);//Retrieve the starting point every time before the extrapolation | |
145 | Double_t trkPos[3]; | |
146 | TVector3 vec(clusterPosition[0],clusterPosition[1],clusterPosition[2]); | |
147 | Double_t alpha = ((int)(vec.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad(); | |
148 | vec.RotateZ(-alpha); //Rotate the cluster to the local extrapolation coordinate system | |
149 | trkParam->Rotate(alpha); //Rotate the track to the same local extrapolation system | |
150 | Float_t fMass=0.139; | |
151 | Float_t fStep=50.; | |
152 | if(!AliTrackerBase::PropagateTrackToBxByBz(trkParam, vec.X(), fMass, fStep,kFALSE, 0.8, -1)) return kFALSE; | |
153 | trkParam->GetXYZ(trkPos); //Get the extrapolated global position | |
154 | TVector3 clsPosVec(clusterPosition[0],clusterPosition[1],clusterPosition[2]); | |
155 | TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]); | |
156 | Float_t clsPhi = (Float_t)clsPosVec.Phi(); | |
157 | if(clsPhi<0) clsPhi+=2*TMath::Pi(); | |
158 | Float_t trkPhi = (Float_t)trkPosVec.Phi(); | |
159 | if(trkPhi<0) trkPhi+=2*TMath::Pi(); | |
160 | Double_t tmpPhi = clsPhi-trkPhi; // track cluster matching | |
161 | Double_t tmpEta = clsPosVec.Eta()-trkPosVec.Eta(); // track cluster matching | |
162 | Double_t tmpR=TMath::Sqrt(tmpEta*tmpEta + tmpPhi*tmpPhi);//MARCEL | |
163 | Double_t match = tmpR; | |
164 | ||
165 | if( match > fMatchDistanceEMCal )continue; | |
166 | ||
167 | if (match < bestMatch[ic]) { | |
168 | bestMatch[ic] = match; | |
169 | cluster->SetEmcCpvDistance(TMath::Sqrt(match)); | |
170 | Double_t dx=tmpPhi; | |
171 | Double_t dz=tmpEta; | |
172 | cluster->SetTrackDistance(dx,dz); | |
173 | } | |
174 | //Add track to cluster's array of matching tracks | |
175 | Int_t nTracksMatched = cluster->GetNTracksMatched(); | |
176 | iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched); | |
177 | } | |
178 | ||
179 | return iResult; | |
180 | } | |
181 | //end of MARCEL TEST | |
2a24cbbe | 182 | |
e5b4e619 | 183 | |
2a24cbbe | 184 | template <class T> |
185 | Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * track, vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz) { | |
a46c7ba5 | 186 | |
2a24cbbe | 187 | //See header file for documentation |
188 | Int_t iResult = 0; | |
e5b4e619 | 189 | |
2a24cbbe | 190 | Float_t clusterPosition[3]; |
191 | Double_t trackPosition[3]; | |
a46c7ba5 | 192 | |
e5b4e619 | 193 | for(int ic = 0; ic < nClusters; ic++) { |
2a24cbbe | 194 | |
e5b4e619 | 195 | T * cluster = clustersVector.at(ic); |
196 | ||
197 | //Get cluster global coordinates | |
198 | cluster->GetPosition(clusterPosition); | |
199 | ||
200 | Double_t rCluster = TMath::Sqrt(clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1]); | |
201 | ||
202 | //Rotate tracking system to the angle of the cluster | |
203 | TVector3 cVec(clusterPosition); | |
204 | if (! (track->Rotate(cVec.Phi())) ) { | |
205 | continue; | |
206 | } | |
207 | ||
208 | if(! (track->GetXYZAt(rCluster, bz, trackPosition)) ) { | |
209 | continue; | |
210 | } | |
d64429af | 211 | |
212 | //Calculate track - cluster residuals | |
213 | Double_t match = 0; | |
214 | for(int i = 0; i < 3; i++) { | |
e5b4e619 | 215 | Double_t dd = trackPosition[i] - clusterPosition[i]; |
d64429af | 216 | match += dd*dd; |
e5b4e619 | 217 | } |
5d8d9319 | 218 | |
e5b4e619 | 219 | |
e5b4e619 | 220 | if( match > fMatchDistance ) { |
221 | continue; | |
222 | } | |
223 | ||
224 | if (match < bestMatch[ic]) { | |
d64429af | 225 | |
e5b4e619 | 226 | bestMatch[ic] = match; |
227 | cluster->SetEmcCpvDistance(TMath::Sqrt(match)); | |
d64429af | 228 | |
229 | Double_t dx = trackPosition[0] - clusterPosition[0]; | |
230 | Double_t dy = trackPosition[1] - clusterPosition[1]; | |
231 | Double_t dz = trackPosition[2] - clusterPosition[2]; | |
232 | cluster->SetTrackDistance( ((dx > 0) ? 1 : -1 )*TMath::Sqrt(dx*dx + dy*dy), dz); | |
2a24cbbe | 233 | } |
e5b4e619 | 234 | |
235 | //Add track to cluster's array of matching tracks | |
236 | Int_t nTracksMatched = cluster->GetNTracksMatched(); | |
237 | iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched); | |
238 | } | |
2a24cbbe | 239 | |
240 | return iResult; | |
241 | } | |
242 | ||
3cfb9c56 | 243 | #endif |