1 // @(#) $Id: AliHLTTPCCANeighboursFinder1.cxx 27042 2008-07-02 12:06:02Z richterm $
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
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. *
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. *
18 //***************************************************************************
20 #include "AliHLTTPCCANeighboursFinder.h"
21 #include "AliHLTTPCCAMath.h"
22 #include "AliHLTTPCCAHitArea.h"
23 #include "AliHLTTPCCATracker.h"
24 #include "AliHLTTPCCAHit.h"
29 #include "AliHLTTPCCADisplay.h"
32 GPUdi() void AliHLTTPCCANeighboursFinder::Thread
33 ( int /*nBlocks*/, int nThreads, int iBlock, int iThread, int iSync,
34 GPUsharedref() MEM_LOCAL(AliHLTTPCCASharedMemory) &s, GPUconstant() MEM_CONSTANT(AliHLTTPCCATracker) &tracker )
40 for (int i = iThread;i < sizeof(MEM_PLAIN(AliHLTTPCCARow)) / sizeof(int);i += nThreads)
42 reinterpret_cast<GPUsharedref() int*>(&s.fRow)[i] = reinterpret_cast<GPUglobalref() int*>(&tracker.SliceDataRows()[iBlock])[i];
43 if (iBlock >= 2 && iBlock <= tracker.Param().NRows() - 3)
45 reinterpret_cast<GPUsharedref() int*>(&s.fRowUp)[i] = reinterpret_cast<GPUglobalref() int*>(&tracker.SliceDataRows()[iBlock + 2])[i];
46 reinterpret_cast<GPUsharedref() int*>(&s.fRowDown)[i] = reinterpret_cast<GPUglobalref() int*>(&tracker.SliceDataRows()[iBlock - 2])[i];
52 s.fNRows = tracker.Param().NRows();
54 if ( s.fIRow < s.fNRows ) {
56 GPUsharedref() const MEM_LOCAL(AliHLTTPCCARow) &row = s.fRow;
58 GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow) &row = tracker.Row( s.fIRow );
60 s.fNHits = row.NHits();
62 if ( ( s.fIRow >= 2 ) && ( s.fIRow <= s.fNRows - 3 ) ) {
63 s.fIRowUp = s.fIRow + 2;
64 s.fIRowDn = s.fIRow - 2;
66 // references to the rows above and below
69 GPUsharedref() const MEM_LOCAL(AliHLTTPCCARow) &rowUp = s.fRowUp;
70 GPUsharedref() const MEM_LOCAL(AliHLTTPCCARow) &rowDn = s.fRowDown;
72 GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow) &rowUp = tracker.Row( s.fIRowUp );
73 GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow) &rowDn = tracker.Row( s.fIRowDn );
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();
80 // number of hits in rows above and below
81 s.fUpNHits = tracker.Row( s.fIRowUp ).NHits();
82 s.fDnNHits = tracker.Row( s.fIRowDn ).NHits();
84 // distance of the rows (absolute and relative)
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).
92 //s.fGridUp = tracker.Row( s.fIRowUp ).Grid();
93 //s.fGridDn = tracker.Row( s.fIRowDn ).Grid();
97 } else if ( iSync == 1 ) {
98 if ( s.fIRow < s.fNRows ) {
99 if ( ( s.fIRow <= 1 ) || ( s.fIRow >= s.fNRows - 2 ) ) {
101 GPUsharedref() const MEM_LOCAL(AliHLTTPCCARow) &row = s.fRow;
103 GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow) &row = tracker.Row( s.fIRow );
105 for ( int ih = iThread; ih < s.fNHits; ih += nThreads ) {
106 tracker.SetHitLinkUpData( row, ih, -1 );
107 tracker.SetHitLinkDownData( row, ih, -1 );
110 /*#ifdef HLTCA_GPUCODE
111 const AliHLTTPCCARow &rowUp = s.fRowUp;
112 const AliHLTTPCCARow &rowDn = s.fRowDown;
114 const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp );
115 const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn );
118 for ( unsigned int ih = iThread; ih < s.fGridUp.N() + s.fGridUp.Ny() + 2; ih += nThreads ) {
119 s.fGridContentUp[ih] = tracker.FirstHitInBin( rowUp, ih );
121 for ( unsigned int ih = iThread; ih < s.fGridDn.N() + s.fGridDn.Ny() + 2; ih += nThreads ) {
122 s.fGridContentDn[ih] = tracker.FirstHitInBin( rowDn, ih );
126 } else if ( iSync == 2 ) {
129 if ( ( iBlock <= 1 ) || ( iBlock >= s.fNRows - 2 ) ) return;
131 if ( ( s.fIRow <= 1 ) || ( s.fIRow >= s.fNRows - 2 ) ) return;
134 float chi2Cut = 3.*3.*4 * ( s.fUpDx * s.fUpDx + s.fDnDx * s.fDnDx );
135 const float kAreaSize = tracker.Param().NeighboursSearchArea();
136 //float chi2Cut = 3.*3.*(s.fUpDx*s.fUpDx + s.fDnDx*s.fDnDx ); //SG
140 GPUsharedref() const MEM_LOCAL(AliHLTTPCCARow) &row = s.fRow;
141 GPUsharedref() const MEM_LOCAL(AliHLTTPCCARow) &rowUp = s.fRowUp;
142 GPUsharedref() const MEM_LOCAL(AliHLTTPCCARow) &rowDn = s.fRowDown;
144 GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow) &row = tracker.Row( s.fIRow );
145 GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow) &rowUp = tracker.Row( s.fIRowUp );
146 GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow) &rowDn = tracker.Row( s.fIRowDn );
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();
153 for ( int ih = iThread; ih < s.fNHits; ih += nThreads ) {
158 if ( s.fDnNHits > 0 && s.fUpNHits > 0 ) {
162 // coordinates of the hit in the current row
163 #if defined(HLTCA_GPU_TEXTURE_FETCHa)
164 ushort2 tmpval = tex1Dfetch(gAliTexRefu2, ((char*) tracker.Data().HitData() - tracker.Data().GPUTextureBase()) / sizeof(ushort2) + row.HitNumberOffset() + ih);
165 const float y = y0 + tmpval.x * stepY;
166 const float z = z0 + tmpval.y * stepZ;
168 const float y = y0 + tracker.HitDataY( row, ih ) * stepY;
169 const float z = z0 + tracker.HitDataZ( row, ih ) * stepZ;
172 #if ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0
173 GPUsharedref() unsigned short *neighUp = s.fB[iThread];
174 GPUsharedref() 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];
180 unsigned short neighUp[kMaxN];
182 #endif //ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0
185 AliHLTTPCCAHitArea areaDn, areaUp;
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 );
191 int i = areaUp.GetNext( tracker, rowUp, tracker.Data(), &h );
193 #if defined(HLTCA_GPUCODE) & kMaxN > ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP & ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0
194 if (nNeighUp >= ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP)
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 ) );
202 neighUp[nNeighUp] = ( unsigned short ) i;
203 yzUp[nNeighUp] = CAMath::MakeFloat2( s.fDnDx * ( h.Y() - y ), s.fDnDx * ( h.Z() - z ) );
205 if ( ++nNeighUp >= kMaxN ) break;
210 if ( nNeighUp > 0 ) {
212 int bestDn = -1, bestUp = -1;
217 int i = areaDn.GetNext( tracker, rowDn, tracker.Data(), &h );
221 float2 yzdn = CAMath::MakeFloat2( s.fUpDx * ( h.Y() - y ), s.fUpDx * ( h.Z() - z ) );
223 for ( int iUp = 0; iUp < nNeighUp; iUp++ ) {
224 #if defined(HLTCA_GPUCODE) & kMaxN > ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP & ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0
225 float2 yzup = iUp >= ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP ? yzUp2[iUp - ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP] : yzUp[iUp];
227 float2 yzup = yzUp[iUp];
230 float dy = yzdn.x - yzup.x;
231 float dz = yzdn.y - yzup.y;
232 float d = dy * dy + dz * dz;
241 if ( bestD <= chi2Cut ) {
242 #if defined(HLTCA_GPUCODE) & kMaxN > ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP & ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP > 0
243 linkUp = bestUp >= ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP ? neighUp2[bestUp - ALIHLTTPCCANEIGHBOURS_FINDER_MAX_NNEIGHUP] : neighUp[bestUp];
245 linkUp = neighUp[bestUp];
251 std::cout << "n NeighUp = " << nNeighUp << ", n NeighDn = " << nNeighDn << std::endl;
255 tracker.SetHitLinkUpData( row, ih, linkUp );
256 tracker.SetHitLinkDownData( row, ih, linkDn );
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();