]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder.cxx
changes from Matthias
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCANeighboursFinder.cxx
CommitLineData
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"
24
ce565086 25//#define DRAW
26
27#ifdef DRAW
28#include "AliHLTTPCCADisplay.h"
29#endif
30
00d07bcd 31GPUd() void AliHLTTPCCANeighboursFinder::Thread
fbb9b71b 32( int /*nBlocks*/, int nThreads, int iBlock, int iThread, int iSync,
00d07bcd 33 AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
34{
35 //* find neighbours
fbb9b71b 36
37 if ( iSync == 0 ) {
38 if ( iThread == 0 ) {
39 s.fNRows = tracker.Param().NRows();
40 s.fIRow = iBlock;
41 if ( s.fIRow < s.fNRows ) {
42 const AliHLTTPCCARow &row = tracker.Row( s.fIRow );
fbb9b71b 43 s.fNHits = row.NHits();
44
fbb9b71b 45 if ( ( s.fIRow >= 2 ) && ( s.fIRow <= s.fNRows - 3 ) ) {
46 s.fIRowUp = s.fIRow + 2;
47 s.fIRowDn = s.fIRow - 2;
4acc2401 48
49 // references to the rows above and below
50 const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp );
51 const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn );
52
53 // the axis perpendicular to the rows
54 const float xDn = rowDn.X();
55 const float x = row.X();
56 const float xUp = rowUp.X();
57
58 // number of hits in rows above and below
fbb9b71b 59 s.fUpNHits = tracker.Row( s.fIRowUp ).NHits();
4acc2401 60 s.fDnNHits = tracker.Row( s.fIRowDn ).NHits();
61
62 // distance of the rows (absolute and relative)
fbb9b71b 63 s.fUpDx = xUp - x;
64 s.fDnDx = xDn - x;
65 s.fUpTx = xUp / x;
66 s.fDnTx = xDn / x;
4acc2401 67 // UpTx/DnTx is used to move the HitArea such that central events are preferred (i.e. vertices
68 // coming from y = 0, z = 0).
69
fbb9b71b 70 s.fGridUp = tracker.Row( s.fIRowUp ).Grid();
71 s.fGridDn = tracker.Row( s.fIRowDn ).Grid();
72 }
00d07bcd 73 }
fbb9b71b 74 }
75 } else if ( iSync == 1 ) {
76 if ( s.fIRow < s.fNRows ) {
77 if ( ( s.fIRow == 0 ) || ( s.fIRow == s.fNRows - 1 ) || ( s.fIRow == 1 ) || ( s.fIRow == s.fNRows - 2 ) ) {
4acc2401 78 const AliHLTTPCCARow &row = tracker.Row( s.fIRow );
fbb9b71b 79 for ( int ih = iThread; ih < s.fNHits; ih += nThreads ) {
4acc2401 80 tracker.SetHitLinkUpData( row, ih, -1 );
81 tracker.SetHitLinkDownData( row, ih, -1 );
fbb9b71b 82 }
83 } else {
84 const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp );
85 const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn );
fbb9b71b 86
87 for ( unsigned int ih = iThread; ih < s.fGridUp.N() + s.fGridUp.Ny() + 2; ih += nThreads ) {
4acc2401 88 s.fGridContentUp[ih] = tracker.FirstHitInBin( rowUp, ih );
fbb9b71b 89 }
90 for ( unsigned int ih = iThread; ih < s.fGridDn.N() + s.fGridDn.Ny() + 2; ih += nThreads ) {
4acc2401 91 s.fGridContentDn[ih] = tracker.FirstHitInBin( rowDn, ih );
fbb9b71b 92 }
00d07bcd 93 }
94 }
fbb9b71b 95 } else if ( iSync == 2 ) {
96 if ( ( s.fIRow <= 1 ) || ( s.fIRow >= s.fNRows - 2 ) ) return;
97
98 //const float kAreaSize = 3;
99 float chi2Cut = 3.*3.*4 * ( s.fUpDx * s.fUpDx + s.fDnDx * s.fDnDx );
100 const float kAreaSize = 3;
101 //float chi2Cut = 3.*3.*(s.fUpDx*s.fUpDx + s.fDnDx*s.fDnDx ); //SG
102 const int kMaxN = 20;
103
104 const AliHLTTPCCARow &row = tracker.Row( s.fIRow );
105 const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp );
106 const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn );
4acc2401 107 const float y0 = row.Grid().YMin();
108 const float z0 = row.Grid().ZMin();
109 const float stepY = row.HstepY();
110 const float stepZ = row.HstepZ();
fbb9b71b 111
112 for ( int ih = iThread; ih < s.fNHits; ih += nThreads ) {
113
114 unsigned short *neighUp = s.fB[iThread];
115 float2 *yzUp = s.fA[iThread];
116 //unsigned short neighUp[5];
117 //float2 yzUp[5];
118
119 int linkUp = -1;
120 int linkDn = -1;
121
122 if ( s.fDnNHits > 0 && s.fUpNHits > 0 ) {
123
124 int nNeighUp = 0;
fbb9b71b 125
4acc2401 126 // coordinates of the hit in the current row
127 const float y = y0 + tracker.HitDataY( row, ih ) * stepY;
128 const float z = z0 + tracker.HitDataZ( row, ih ) * stepZ;
fbb9b71b 129
130 AliHLTTPCCAHitArea areaDn, areaUp;
4acc2401 131 // TODO: for NVIDIA GPUs it should use the GridContentUp/-Dn that got copied into shared mem
132 areaUp.Init( rowUp, tracker.Data(), y*s.fUpTx, z*s.fUpTx, kAreaSize, kAreaSize );
133 areaDn.Init( rowDn, tracker.Data(), y*s.fDnTx, z*s.fDnTx, kAreaSize, kAreaSize );
fbb9b71b 134
135 do {
136 AliHLTTPCCAHit h;
4acc2401 137 int i = areaUp.GetNext( tracker, rowUp, tracker.Data(), &h );
fbb9b71b 138 if ( i < 0 ) break;
139 neighUp[nNeighUp] = ( unsigned short ) i;
140 yzUp[nNeighUp] = CAMath::MakeFloat2( s.fDnDx * ( h.Y() - y ), s.fDnDx * ( h.Z() - z ) );
141 if ( ++nNeighUp >= kMaxN ) break;
142 } while ( 1 );
143
144 int nNeighDn = 0;
145
146 if ( nNeighUp > 0 ) {
147
148 int bestDn = -1, bestUp = -1;
149 float bestD = 1.e10;
150
151 do {
152 AliHLTTPCCAHit h;
4acc2401 153 int i = areaDn.GetNext( tracker, rowDn, tracker.Data(), &h );
fbb9b71b 154 if ( i < 0 ) break;
155
156 nNeighDn++;
157 float2 yzdn = CAMath::MakeFloat2( s.fUpDx * ( h.Y() - y ), s.fUpDx * ( h.Z() - z ) );
158
159 for ( int iUp = 0; iUp < nNeighUp; iUp++ ) {
160 float2 yzup = yzUp[iUp];
161 float dy = yzdn.x - yzup.x;
162 float dz = yzdn.y - yzup.y;
163 float d = dy * dy + dz * dz;
164 if ( d < bestD ) {
165 bestD = d;
166 bestDn = i;
167 bestUp = iUp;
168 }
169 }
170 } while ( 1 );
171
172 if ( bestD <= chi2Cut ) {
173 linkUp = neighUp[bestUp];
174 linkDn = bestDn;
175 }
176 }
ce565086 177#ifdef DRAW
fbb9b71b 178 std::cout << "n NeighUp = " << nNeighUp << ", n NeighDn = " << nNeighDn << std::endl;
179#endif
ce565086 180
fbb9b71b 181 }
182
4acc2401 183 tracker.SetHitLinkUpData( row, ih, linkUp );
184 tracker.SetHitLinkDownData( row, ih, linkDn );
ce565086 185#ifdef DRAW
fbb9b71b 186 std::cout << "Links for row " << s.fIRow << ", hit " << ih << ": " << linkUp << " " << linkDn << std::endl;
187 if ( s.fIRow == 22 && ih == 5 ) {
188 AliHLTTPCCADisplay::Instance().DrawSliceLink( s.fIRow, ih, -1, -1, 1 );
189 AliHLTTPCCADisplay::Instance().DrawSliceHit( s.fIRow, ih, kBlue, 1. );
190 AliHLTTPCCADisplay::Instance().Ask();
00d07bcd 191 }
fbb9b71b 192#endif
00d07bcd 193 }
fbb9b71b 194 }
00d07bcd 195}
196