]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder.cxx
1. bug fix: skip the final transport of tracks to the inner TPC X, when the tracks...
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCANeighboursFinder.cxx
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.                           *
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.                    *
17 //                                                                          *
18 //***************************************************************************
19
20 #include "AliHLTTPCCANeighboursFinder.h"
21 #include "AliHLTTPCCAMath.h"
22 #include "AliHLTTPCCAHitArea.h"
23 #include "AliHLTTPCCATracker.h"
24
25 //#define DRAW
26
27 #ifdef DRAW
28 #include "AliHLTTPCCADisplay.h"
29 #endif
30
31 GPUd() void AliHLTTPCCANeighboursFinder::Thread
32 ( int /*nBlocks*/, int nThreads, int iBlock, int iThread, int iSync,
33   AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
34 {
35   //* find neighbours
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 );
43         s.fNHits = row.NHits();
44
45         if ( ( s.fIRow >= 2 ) && ( s.fIRow <= s.fNRows - 3 ) ) {
46           s.fIRowUp = s.fIRow + 2;
47           s.fIRowDn = s.fIRow - 2;
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
59           s.fUpNHits = tracker.Row( s.fIRowUp ).NHits();
60           s.fDnNHits = tracker.Row( s.fIRowDn ).NHits();
61
62           // distance of the rows (absolute and relative)
63           s.fUpDx = xUp - x;
64           s.fDnDx = xDn - x;
65           s.fUpTx = xUp / x;
66           s.fDnTx = xDn / x;
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
70           s.fGridUp = tracker.Row( s.fIRowUp ).Grid();
71           s.fGridDn = tracker.Row( s.fIRowDn ).Grid();
72         }
73       }
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 ) ) {
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 );
82         }
83       } else {
84         const AliHLTTPCCARow &rowUp = tracker.Row( s.fIRowUp );
85         const AliHLTTPCCARow &rowDn = tracker.Row( s.fIRowDn );
86
87         for ( unsigned int ih = iThread; ih < s.fGridUp.N() + s.fGridUp.Ny() + 2; ih += nThreads ) {
88           s.fGridContentUp[ih] = tracker.FirstHitInBin( rowUp, ih );
89         }
90         for ( unsigned int ih = iThread; ih < s.fGridDn.N() + s.fGridDn.Ny() + 2; ih += nThreads ) {
91           s.fGridContentDn[ih] = tracker.FirstHitInBin( rowDn, ih );
92         }
93       }
94     }
95   } else if ( iSync == 2 ) {
96     if ( ( s.fIRow <= 1 ) || ( s.fIRow >= s.fNRows - 2 ) ) return;
97
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;
102
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();
110
111     for ( int ih = iThread; ih < s.fNHits; ih += nThreads ) {
112
113       unsigned short *neighUp = s.fB[iThread];
114       float2 *yzUp = s.fA[iThread];
115       //unsigned short neighUp[5];
116       //float2 yzUp[5];
117
118       int linkUp = -1;
119       int linkDn = -1;
120
121       if ( s.fDnNHits > 0 && s.fUpNHits > 0 ) {
122
123         int nNeighUp = 0;
124
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;
128
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 );
133
134         do {
135           AliHLTTPCCAHit h;
136           int i = areaUp.GetNext( tracker, rowUp, tracker.Data(), &h );
137           if ( i < 0 ) break;
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;
141         } while ( 1 );
142
143         int nNeighDn = 0;
144
145         if ( nNeighUp > 0 ) {
146
147           int bestDn = -1, bestUp = -1;
148           float bestD = 1.e10;
149
150           do {
151             AliHLTTPCCAHit h;
152             int i = areaDn.GetNext( tracker, rowDn, tracker.Data(), &h );
153             if ( i < 0 ) break;
154
155             nNeighDn++;
156             float2 yzdn = CAMath::MakeFloat2( s.fUpDx * ( h.Y() - y ), s.fUpDx * ( h.Z() - z ) );
157
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;
163               if ( d < bestD ) {
164                 bestD = d;
165                 bestDn = i;
166                 bestUp = iUp;
167               }
168             }
169           } while ( 1 );
170
171           if ( bestD <= chi2Cut ) {
172             linkUp = neighUp[bestUp];
173             linkDn = bestDn;
174           }
175         }
176 #ifdef DRAW
177         std::cout << "n NeighUp = " << nNeighUp << ", n NeighDn = " << nNeighDn << std::endl;
178 #endif
179
180       }
181
182       tracker.SetHitLinkUpData( row, ih, linkUp );
183       tracker.SetHitLinkDownData( row, ih, linkDn );
184 #ifdef DRAW
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();
190       }
191 #endif
192     }
193   }
194 }
195