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"
28 #include "AliHLTTPCCADisplay.h"
31 GPUd() void AliHLTTPCCANeighboursFinder::Thread
32 ( int /*nBlocks*/, int nThreads, int iBlock, int iThread, int iSync,
33 AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
39 s.fNRows = tracker.Param().NRows();
41 if ( s.fIRow < s.fNRows ) {
42 const AliHLTTPCCARow &row = tracker.Row( s.fIRow );
43 s.fNHits = row.NHits();
45 if ( ( s.fIRow >= 2 ) && ( s.fIRow <= s.fNRows - 3 ) ) {
46 s.fIRowUp = s.fIRow + 2;
47 s.fIRowDn = s.fIRow - 2;
49 // references to the rows above and below
50 const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp );
51 const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn );
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();
58 // number of hits in rows above and below
59 s.fUpNHits = tracker.Row( s.fIRowUp ).NHits();
60 s.fDnNHits = tracker.Row( s.fIRowDn ).NHits();
62 // distance of the rows (absolute and relative)
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).
70 s.fGridUp = tracker.Row( s.fIRowUp ).Grid();
71 s.fGridDn = tracker.Row( s.fIRowDn ).Grid();
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 ) ) {
78 const AliHLTTPCCARow &row = tracker.Row( s.fIRow );
79 for ( int ih = iThread; ih < s.fNHits; ih += nThreads ) {
80 tracker.SetHitLinkUpData( row, ih, -1 );
81 tracker.SetHitLinkDownData( row, ih, -1 );
84 const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp );
85 const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn );
87 for ( unsigned int ih = iThread; ih < s.fGridUp.N() + s.fGridUp.Ny() + 2; ih += nThreads ) {
88 s.fGridContentUp[ih] = tracker.FirstHitInBin( rowUp, ih );
90 for ( unsigned int ih = iThread; ih < s.fGridDn.N() + s.fGridDn.Ny() + 2; ih += nThreads ) {
91 s.fGridContentDn[ih] = tracker.FirstHitInBin( rowDn, ih );
95 } else if ( iSync == 2 ) {
96 if ( ( s.fIRow <= 1 ) || ( s.fIRow >= s.fNRows - 2 ) ) return;
98 float chi2Cut = 3.*3.*4 * ( s.fUpDx * s.fUpDx + s.fDnDx * s.fDnDx );
99 const float kAreaSize = tracker.Param().NeighboursSearchArea();
100 //float chi2Cut = 3.*3.*(s.fUpDx*s.fUpDx + s.fDnDx*s.fDnDx ); //SG
101 const int kMaxN = 20;
103 const AliHLTTPCCARow &row = tracker.Row( s.fIRow );
104 const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp );
105 const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn );
106 const float y0 = row.Grid().YMin();
107 const float z0 = row.Grid().ZMin();
108 const float stepY = row.HstepY();
109 const float stepZ = row.HstepZ();
111 for ( int ih = iThread; ih < s.fNHits; ih += nThreads ) {
113 unsigned short *neighUp = s.fB[iThread];
114 float2 *yzUp = s.fA[iThread];
115 //unsigned short neighUp[5];
121 if ( s.fDnNHits > 0 && s.fUpNHits > 0 ) {
125 // coordinates of the hit in the current row
126 const float y = y0 + tracker.HitDataY( row, ih ) * stepY;
127 const float z = z0 + tracker.HitDataZ( row, ih ) * stepZ;
129 AliHLTTPCCAHitArea areaDn, areaUp;
130 // TODO: for NVIDIA GPUs it should use the GridContentUp/-Dn that got copied into shared mem
131 areaUp.Init( rowUp, tracker.Data(), y*s.fUpTx, z*s.fUpTx, kAreaSize, kAreaSize );
132 areaDn.Init( rowDn, tracker.Data(), y*s.fDnTx, z*s.fDnTx, kAreaSize, kAreaSize );
136 int i = areaUp.GetNext( tracker, rowUp, tracker.Data(), &h );
138 neighUp[nNeighUp] = ( unsigned short ) i;
139 yzUp[nNeighUp] = CAMath::MakeFloat2( s.fDnDx * ( h.Y() - y ), s.fDnDx * ( h.Z() - z ) );
140 if ( ++nNeighUp >= kMaxN ) break;
145 if ( nNeighUp > 0 ) {
147 int bestDn = -1, bestUp = -1;
152 int i = areaDn.GetNext( tracker, rowDn, tracker.Data(), &h );
156 float2 yzdn = CAMath::MakeFloat2( s.fUpDx * ( h.Y() - y ), s.fUpDx * ( h.Z() - z ) );
158 for ( int iUp = 0; iUp < nNeighUp; iUp++ ) {
159 float2 yzup = yzUp[iUp];
160 float dy = yzdn.x - yzup.x;
161 float dz = yzdn.y - yzup.y;
162 float d = dy * dy + dz * dz;
171 if ( bestD <= chi2Cut ) {
172 linkUp = neighUp[bestUp];
177 std::cout << "n NeighUp = " << nNeighUp << ", n NeighDn = " << nNeighDn << std::endl;
182 tracker.SetHitLinkUpData( row, ih, linkUp );
183 tracker.SetHitLinkDownData( row, ih, linkDn );
185 std::cout << "Links for row " << s.fIRow << ", hit " << ih << ": " << linkUp << " " << linkDn << std::endl;
186 if ( s.fIRow == 22 && ih == 5 ) {
187 AliHLTTPCCADisplay::Instance().DrawSliceLink( s.fIRow, ih, -1, -1, 1 );
188 AliHLTTPCCADisplay::Instance().DrawSliceHit( s.fIRow, ih, kBlue, 1. );
189 AliHLTTPCCADisplay::Instance().Ask();