]>
Commit | Line | Data |
---|---|---|
ce565086 | 1 | // @(#) $Id: AliHLTTPCCANeighboursFinder1.cxx 27042 2008-07-02 12:06:02Z richterm $ |
2 | // ************************************************************************** | |
fbb9b71b | 3 | // This file is property of and copyright by the ALICE HLT Project * |
00d07bcd | 4 | // ALICE Experiment at CERN, All rights reserved. * |
5 | // * | |
6 | // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> * | |
7 | // Ivan Kisel <kisel@kip.uni-heidelberg.de> * | |
8 | // for The ALICE HLT Project. * | |
9 | // * | |
10 | // Permission to use, copy, modify and distribute this software and its * | |
11 | // documentation strictly for non-commercial purposes is hereby granted * | |
12 | // without fee, provided that the above copyright notice appears in all * | |
13 | // copies and that both the copyright notice and this permission notice * | |
14 | // appear in the supporting documentation. The authors make no claims * | |
15 | // about the suitability of this software for any purpose. It is * | |
16 | // provided "as is" without express or implied warranty. * | |
ce565086 | 17 | // * |
00d07bcd | 18 | //*************************************************************************** |
19 | ||
20 | #include "AliHLTTPCCANeighboursFinder.h" | |
21 | #include "AliHLTTPCCAMath.h" | |
22 | #include "AliHLTTPCCAHitArea.h" | |
23 | #include "AliHLTTPCCATracker.h" | |
a59a784e | 24 | #include "AliHLTTPCCAHit.h" |
00d07bcd | 25 | |
ce565086 | 26 | //#define DRAW |
27 | ||
28 | #ifdef DRAW | |
29 | #include "AliHLTTPCCADisplay.h" | |
31649d4b | 30 | #endif //DRAW |
ce565086 | 31 | |
f0bada7f | 32 | GPUdi() void AliHLTTPCCANeighboursFinder::Thread |
fbb9b71b | 33 | ( int /*nBlocks*/, int nThreads, int iBlock, int iThread, int iSync, |
00d07bcd | 34 | AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker ) |
35 | { | |
36 | //* find neighbours | |
fbb9b71b | 37 | |
38 | if ( iSync == 0 ) { | |
b22af1bf | 39 | #ifdef HLTCA_GPUCODE |
40 | for (int i = iThread;i < sizeof(AliHLTTPCCARow) / sizeof(int);i += nThreads) | |
41 | { | |
42 | reinterpret_cast<int*>(&s.fRow)[i] = reinterpret_cast<int*>(&tracker.SliceDataRows()[iBlock])[i]; | |
43 | if (iBlock >= 2 && iBlock <= tracker.Param().NRows() - 3) | |
44 | { | |
45 | reinterpret_cast<int*>(&s.fRowUp)[i] = reinterpret_cast<int*>(&tracker.SliceDataRows()[iBlock + 2])[i]; | |
46 | reinterpret_cast<int*>(&s.fRowDown)[i] = reinterpret_cast<int*>(&tracker.SliceDataRows()[iBlock - 2])[i]; | |
47 | } | |
48 | } | |
49 | __syncthreads(); | |
50 | #endif | |
fbb9b71b | 51 | if ( iThread == 0 ) { |
52 | s.fNRows = tracker.Param().NRows(); | |
53 | s.fIRow = iBlock; | |
54 | if ( s.fIRow < s.fNRows ) { | |
b22af1bf | 55 | #ifdef HLTCA_GPUCODE |
56 | const AliHLTTPCCARow &row = s.fRow; | |
57 | #else | |
58 | const AliHLTTPCCARow &row = tracker.Row( s.fIRow ); | |
59 | #endif | |
fbb9b71b | 60 | s.fNHits = row.NHits(); |
61 | ||
fbb9b71b | 62 | if ( ( s.fIRow >= 2 ) && ( s.fIRow <= s.fNRows - 3 ) ) { |
63 | s.fIRowUp = s.fIRow + 2; | |
64 | s.fIRowDn = s.fIRow - 2; | |
4acc2401 | 65 | |
66 | // references to the rows above and below | |
b22af1bf | 67 | |
68 | #ifdef HLTCA_GPUCODE | |
69 | const AliHLTTPCCARow &rowUp = s.fRowUp; | |
70 | const AliHLTTPCCARow &rowDn = s.fRowDown; | |
71 | #else | |
4acc2401 | 72 | const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp ); |
73 | const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn ); | |
b22af1bf | 74 | #endif |
4acc2401 | 75 | // the axis perpendicular to the rows |
76 | const float xDn = rowDn.X(); | |
77 | const float x = row.X(); | |
78 | const float xUp = rowUp.X(); | |
79 | ||
80 | // number of hits in rows above and below | |
fbb9b71b | 81 | s.fUpNHits = tracker.Row( s.fIRowUp ).NHits(); |
4acc2401 | 82 | s.fDnNHits = tracker.Row( s.fIRowDn ).NHits(); |
83 | ||
84 | // distance of the rows (absolute and relative) | |
fbb9b71b | 85 | s.fUpDx = xUp - x; |
86 | s.fDnDx = xDn - x; | |
87 | s.fUpTx = xUp / x; | |
88 | s.fDnTx = xDn / x; | |
4acc2401 | 89 | // UpTx/DnTx is used to move the HitArea such that central events are preferred (i.e. vertices |
90 | // coming from y = 0, z = 0). | |
91 | ||
b22af1bf | 92 | //s.fGridUp = tracker.Row( s.fIRowUp ).Grid(); |
93 | //s.fGridDn = tracker.Row( s.fIRowDn ).Grid(); | |
fbb9b71b | 94 | } |
00d07bcd | 95 | } |
fbb9b71b | 96 | } |
97 | } else if ( iSync == 1 ) { | |
98 | if ( s.fIRow < s.fNRows ) { | |
b22af1bf | 99 | if ( ( s.fIRow <= 1 ) || ( s.fIRow >= s.fNRows - 2 ) ) { |
100 | #ifdef HLTCA_GPUCODE | |
101 | const AliHLTTPCCARow &row = s.fRow; | |
102 | #else | |
103 | const AliHLTTPCCARow &row = tracker.Row( s.fIRow ); | |
104 | #endif | |
fbb9b71b | 105 | for ( int ih = iThread; ih < s.fNHits; ih += nThreads ) { |
4acc2401 | 106 | tracker.SetHitLinkUpData( row, ih, -1 ); |
107 | tracker.SetHitLinkDownData( row, ih, -1 ); | |
fbb9b71b | 108 | } |
109 | } else { | |
b22af1bf | 110 | /*#ifdef HLTCA_GPUCODE |
111 | const AliHLTTPCCARow &rowUp = s.fRowUp; | |
112 | const AliHLTTPCCARow &rowDn = s.fRowDown; | |
113 | #else | |
114 | const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp ); | |
115 | const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn ); | |
116 | #endif | |
fbb9b71b | 117 | |
118 | for ( unsigned int ih = iThread; ih < s.fGridUp.N() + s.fGridUp.Ny() + 2; ih += nThreads ) { | |
4acc2401 | 119 | s.fGridContentUp[ih] = tracker.FirstHitInBin( rowUp, ih ); |
fbb9b71b | 120 | } |
121 | for ( unsigned int ih = iThread; ih < s.fGridDn.N() + s.fGridDn.Ny() + 2; ih += nThreads ) { | |
4acc2401 | 122 | s.fGridContentDn[ih] = tracker.FirstHitInBin( rowDn, ih ); |
b22af1bf | 123 | }*/ |
00d07bcd | 124 | } |
125 | } | |
fbb9b71b | 126 | } else if ( iSync == 2 ) { |
f0bada7f | 127 | |
128 | #ifdef HLTCA_GPUCODE | |
129 | if ( ( iBlock <= 1 ) || ( iBlock >= s.fNRows - 2 ) ) return; | |
130 | #else | |
fbb9b71b | 131 | if ( ( s.fIRow <= 1 ) || ( s.fIRow >= s.fNRows - 2 ) ) return; |
f0bada7f | 132 | #endif |
fbb9b71b | 133 | |
fbb9b71b | 134 | float chi2Cut = 3.*3.*4 * ( s.fUpDx * s.fUpDx + s.fDnDx * s.fDnDx ); |
f0fb467d | 135 | const float kAreaSize = tracker.Param().NeighboursSearchArea(); |
fbb9b71b | 136 | //float chi2Cut = 3.*3.*(s.fUpDx*s.fUpDx + s.fDnDx*s.fDnDx ); //SG |
b22af1bf | 137 | #define kMaxN 20 |
138 | ||
139 | #ifdef HLTCA_GPUCODE | |
140 | const AliHLTTPCCARow &row = s.fRow; | |
141 | const AliHLTTPCCARow &rowUp = s.fRowUp; | |
142 | const AliHLTTPCCARow &rowDn = s.fRowDown; | |
143 | #else | |
144 | const AliHLTTPCCARow &row = tracker.Row( s.fIRow ); | |
145 | const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp ); | |
146 | const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn ); | |
147 | #endif | |
4acc2401 | 148 | const float y0 = row.Grid().YMin(); |
149 | const float z0 = row.Grid().ZMin(); | |
150 | const float stepY = row.HstepY(); | |
151 | const float stepZ = row.HstepZ(); | |
fbb9b71b | 152 | |
b22af1bf | 153 | for ( int ih = iThread; ih < s.fNHits; ih += nThreads ) { |
fbb9b71b | 154 | |
fbb9b71b | 155 | int linkUp = -1; |
156 | int linkDn = -1; | |
157 | ||
158 | if ( s.fDnNHits > 0 && s.fUpNHits > 0 ) { | |
159 | ||
31649d4b | 160 | |
fbb9b71b | 161 | |
4acc2401 | 162 | // coordinates of the hit in the current row |
b22af1bf | 163 | #if defined(HLTCA_GPU_TEXTURE_FETCHa) |
f0bada7f | 164 | ushort2 tmpval = tex1Dfetch(gAliTexRefu2, ((char*) tracker.Data().HitData() - tracker.Data().GPUTextureBase()) / sizeof(ushort2) + row.HitNumberOffset() + ih); |
b22af1bf | 165 | const float y = y0 + tmpval.x * stepY; |
166 | const float z = z0 + tmpval.y * stepZ; | |
167 | #else | |
4acc2401 | 168 | const float y = y0 + tracker.HitDataY( row, ih ) * stepY; |
169 | const float z = z0 + tracker.HitDataZ( row, ih ) * stepZ; | |
b22af1bf | 170 | #endif |
fbb9b71b | 171 | |
f0bada7f | 172 | #if ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0 |
31649d4b | 173 | unsigned short *neighUp = s.fB[iThread]; |
174 | float2 *yzUp = s.fA[iThread]; | |
175 | #if defined(HLTCA_GPUCODE) & kMaxN > ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP | |
176 | unsigned short neighUp2[kMaxN - ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP]; | |
177 | float2 yzUp2[kMaxN - ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP]; | |
178 | #endif | |
f0bada7f | 179 | #else |
180 | unsigned short neighUp[kMaxN]; | |
181 | float2 yzUp[kMaxN]; | |
182 | #endif //ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0 | |
31649d4b | 183 | |
184 | int nNeighUp = 0; | |
fbb9b71b | 185 | AliHLTTPCCAHitArea areaDn, areaUp; |
4acc2401 | 186 | areaUp.Init( rowUp, tracker.Data(), y*s.fUpTx, z*s.fUpTx, kAreaSize, kAreaSize ); |
187 | areaDn.Init( rowDn, tracker.Data(), y*s.fDnTx, z*s.fDnTx, kAreaSize, kAreaSize ); | |
fbb9b71b | 188 | |
189 | do { | |
190 | AliHLTTPCCAHit h; | |
4acc2401 | 191 | int i = areaUp.GetNext( tracker, rowUp, tracker.Data(), &h ); |
fbb9b71b | 192 | if ( i < 0 ) break; |
f0bada7f | 193 | #if defined(HLTCA_GPUCODE) & kMaxN > ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP & ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0 |
b22af1bf | 194 | if (nNeighUp >= ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP) |
195 | { | |
196 | neighUp2[nNeighUp - ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP] = ( unsigned short ) i; | |
197 | yzUp2[nNeighUp - ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP] = CAMath::MakeFloat2( s.fDnDx * ( h.Y() - y ), s.fDnDx * ( h.Z() - z ) ); | |
198 | } | |
199 | else | |
200 | #endif | |
201 | { | |
202 | neighUp[nNeighUp] = ( unsigned short ) i; | |
203 | yzUp[nNeighUp] = CAMath::MakeFloat2( s.fDnDx * ( h.Y() - y ), s.fDnDx * ( h.Z() - z ) ); | |
204 | } | |
fbb9b71b | 205 | if ( ++nNeighUp >= kMaxN ) break; |
206 | } while ( 1 ); | |
207 | ||
208 | int nNeighDn = 0; | |
209 | ||
210 | if ( nNeighUp > 0 ) { | |
211 | ||
212 | int bestDn = -1, bestUp = -1; | |
213 | float bestD = 1.e10; | |
214 | ||
215 | do { | |
216 | AliHLTTPCCAHit h; | |
4acc2401 | 217 | int i = areaDn.GetNext( tracker, rowDn, tracker.Data(), &h ); |
fbb9b71b | 218 | if ( i < 0 ) break; |
219 | ||
220 | nNeighDn++; | |
221 | float2 yzdn = CAMath::MakeFloat2( s.fUpDx * ( h.Y() - y ), s.fUpDx * ( h.Z() - z ) ); | |
222 | ||
223 | for ( int iUp = 0; iUp < nNeighUp; iUp++ ) { | |
f0bada7f | 224 | #if defined(HLTCA_GPUCODE) & kMaxN > ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP & ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0 |
b22af1bf | 225 | float2 yzup = iUp >= ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP ? yzUp2[iUp - ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP] : yzUp[iUp]; |
226 | #else | |
fbb9b71b | 227 | float2 yzup = yzUp[iUp]; |
b22af1bf | 228 | #endif |
229 | ||
fbb9b71b | 230 | float dy = yzdn.x - yzup.x; |
231 | float dz = yzdn.y - yzup.y; | |
232 | float d = dy * dy + dz * dz; | |
233 | if ( d < bestD ) { | |
234 | bestD = d; | |
235 | bestDn = i; | |
236 | bestUp = iUp; | |
237 | } | |
238 | } | |
239 | } while ( 1 ); | |
240 | ||
241 | if ( bestD <= chi2Cut ) { | |
f0bada7f | 242 | #if defined(HLTCA_GPUCODE) & kMaxN > ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP & ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0 |
b22af1bf | 243 | linkUp = bestUp >= ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP ? neighUp2[bestUp - ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP] : neighUp[bestUp]; |
244 | #else | |
fbb9b71b | 245 | linkUp = neighUp[bestUp]; |
b22af1bf | 246 | #endif |
fbb9b71b | 247 | linkDn = bestDn; |
248 | } | |
249 | } | |
ce565086 | 250 | #ifdef DRAW |
fbb9b71b | 251 | std::cout << "n NeighUp = " << nNeighUp << ", n NeighDn = " << nNeighDn << std::endl; |
31649d4b | 252 | #endif //DRAW |
fbb9b71b | 253 | } |
254 | ||
4acc2401 | 255 | tracker.SetHitLinkUpData( row, ih, linkUp ); |
256 | tracker.SetHitLinkDownData( row, ih, linkDn ); | |
ce565086 | 257 | #ifdef DRAW |
fbb9b71b | 258 | std::cout << "Links for row " << s.fIRow << ", hit " << ih << ": " << linkUp << " " << linkDn << std::endl; |
259 | if ( s.fIRow == 22 && ih == 5 ) { | |
260 | AliHLTTPCCADisplay::Instance().DrawSliceLink( s.fIRow, ih, -1, -1, 1 ); | |
261 | AliHLTTPCCADisplay::Instance().DrawSliceHit( s.fIRow, ih, kBlue, 1. ); | |
262 | AliHLTTPCCADisplay::Instance().Ask(); | |
00d07bcd | 263 | } |
31649d4b | 264 | #endif //DRAW |
00d07bcd | 265 | } |
fbb9b71b | 266 | } |
00d07bcd | 267 | } |
268 |