6 #ifndef ALIHLTTPCCANEIGHBOURSFINDER_H
7 #define ALIHLTTPCCANEIGHBOURSFINDER_H
9 #include "AliHLTTPCCATracker.h"
10 #include "AliHLTTPCCAHitArea.h"
13 #include <tbb/blocked_range.h>
27 void operator()(
const tbb::blocked_range<int> &r )
const;
31 void executeOnRow(
int rowIndex )
const;
39 inline void AliHLTTPCCATracker::NeighboursFinder::operator()(
const tbb::blocked_range<int> &r )
const
41 for (
int i = r.begin(); i < r.end(); ++i ) {
47 inline void AliHLTTPCCATracker::NeighboursFinder::executeOnRow(
int rowIndex )
const
49 debugS() <<
"NeighboursFinder on row " << rowIndex << std::endl;
53 const int rowStep = AliHLTTPCCAParameters::RowStep;
59 const int numberOfHits = row.NHits();
60 const int numberOfHitsUp = rowUp.NHits();
61 const int numberOfHitsDown = rowDn.NHits();
62 if ( numberOfHits == 0 ) {
63 debugS() <<
"no hits in this row" << std::endl;
66 if ( numberOfHitsDown == 0 || numberOfHitsUp == 0 ) {
67 debugS() <<
"no hits in neighbouring rows" << std::endl;
72 const float xDn = fData.RowX( rowIndex - rowStep );
73 const float x = fData.RowX( rowIndex );
74 const float xUp = fData.RowX( rowIndex + rowStep );
77 const float UpDx = xUp - x;
78 const float DnDx = xDn - x;
79 const float UpTx = xUp / x;
80 const float DnTx = xDn / x;
107 static const float kAreaSizeY = AliHLTTPCCAParameters::NeighbourAreaSizeTgY[fIter];
108 static const float kAreaSizeZ = AliHLTTPCCAParameters::NeighbourAreaSizeTgZ[fIter];
109 static const int kMaxN = 20;
113 float curv2Cut = AliHLTTPCCAParameters::NeighbourCurvCut[fIter] * .5 * ( UpDx * DnDx * ( UpDx - DnDx ) );
114 curv2Cut *= curv2Cut;
115 const float UpErr2 = (rowIndex - rowStep < AliHLTTPCCAParameters::NumberOfInnerRows) ? 0.06*0.06 : 0.12*0.12,
116 DnErr2 = (rowIndex + rowStep < AliHLTTPCCAParameters::NumberOfInnerRows) ? 0.06*0.06 : 0.12*0.12;
120 #else // USE_CURV_CUT
121 const float chi2Cut = AliHLTTPCCAParameters::NeighbourChiCut[fIter]*AliHLTTPCCAParameters::NeighbourChiCut[fIter] * 4.f * ( UpDx * UpDx + DnDx * DnDx );
122 #endif // USE_CURV_CUT
128 STATIC_ASSERT( short_v::Size % float_v::Size == 0, Short_Vector_Size_is_not_a_multiple_of_Float_Vector_Size );
129 for (
int hitIndex = 0; hitIndex < numberOfHits; hitIndex += short_v::Size ) {
134 #ifdef DRAW_NEIGHBOURSFINDING
135 sfloat_v neighUpY[kMaxN];
136 sfloat_v neighUpZ[kMaxN];
139 ushort_v hitIndexes = ushort_v( Vc::IndexesFromZero ) + hitIndex;
140 const short_m &validHitsMask = hitIndexes < numberOfHits;
148 sfloat_v y(Vc::Zero), z(Vc::Zero), yUp(Vc::Zero), zUp(Vc::Zero), yDn(Vc::Zero), zDn(Vc::Zero);
151 y = fData.HitDataY( row, hitIndex );
152 z = fData.HitDataZ( row, hitIndex );
153 #ifdef DRAW_NEIGHBOURSFINDING
154 std::cout <<
" centr y = " << y <<
" centr z = " << z << std::endl;
162 const sfloat_v UpDy = yUp - y,
164 const sfloat_v UpR2 = UpDy*UpDy + UpDx*UpDx,
165 DnR2 = DnDy*DnDy + DnDx*DnDx;
166 sfloat_v chi2Cut = curv2Cut + (UpErr2/UpR2 + DnErr2/DnR2)*(UpDx*DnDx)*(UpDx*DnDx);
169 #endif // USE_CURV_CUT
172 HitArea areaUp( rowUp, fData, yUp, zUp, UpDx*kAreaSizeY, UpDx*kAreaSizeZ, validHitsMask );
174 ushort_v maxUpperNeighbourIndex = ushort_v(Vc::Zero);
175 int upperNeighbourIndex = 0;
176 NeighbourData neighUp[kMaxN];
177 while ( !( areaUp.GetNext( &neighUp[upperNeighbourIndex] ) ).isEmpty() ) {
178 assert( neighUp[upperNeighbourIndex].fLinks < rowUp.NHits() || !neighUp[upperNeighbourIndex].fValid );
179 debugS() << neighUp[upperNeighbourIndex];
181 #ifdef DRAW_NEIGHBOURSFINDING
182 neighUpY[upperNeighbourIndex] = neighUp[upperNeighbourIndex].fY;
183 neighUpZ[upperNeighbourIndex] = neighUp[upperNeighbourIndex].fZ;
185 neighUp[upperNeighbourIndex].fY = DnDx * ( neighUp[upperNeighbourIndex].fY - y );
186 neighUp[upperNeighbourIndex].fZ = DnDx * ( neighUp[upperNeighbourIndex].fZ - z );
188 maxUpperNeighbourIndex(neighUp[upperNeighbourIndex].fValid)++;
189 ++upperNeighbourIndex;
192 if ( ISUNLIKELY(upperNeighbourIndex >= kMaxN) ){
199 if ( upperNeighbourIndex <= 0 )
continue;
203 sfloat_v bestD = chi2Cut;
204 NeighbourData neighDn;
208 HitArea areaDn( rowDn, fData, yDn, zDn, -DnDx*kAreaSizeY, -DnDx*kAreaSizeZ, validHitsMask );
209 while ( !( nextMask = areaDn.GetNext( &neighDn ) ).isEmpty() ) {
213 if ( ISUNLIKELY( ((Vc::Zero < maxUpperNeighbourIndex) && neighDn.fValid).isEmpty() ) )
continue;
215 assert( neighDn.fLinks < rowDn.NHits() || !neighDn.fValid );
219 #ifdef DRAW_NEIGHBOURSFINDING
220 sfloat_v neighDnY = neighDn.fY;
221 sfloat_v neighDnZ = neighDn.fZ;
224 neighDn.fY = UpDx * ( neighDn.fY - y );
225 neighDn.fZ = UpDx * ( neighDn.fZ - z );
227 short_m dnMask( Vc::Zero );
233 for (
int i = 0; i < upperNeighbourIndex; ++i ) {
234 sfloat_m masksf( neighDn.fValid & neighUp[i].fValid );
235 const sfloat_v dy = neighDn.fY - neighUp[i].fY;
236 const sfloat_v dz = neighDn.fZ - neighUp[i].fZ;
237 #ifdef DRAW_NEIGHBOURSFINDING
238 AliHLTTPCCADisplay::Instance().ClearView();
239 AliHLTTPCCADisplay::Instance().SetSliceView();
240 AliHLTTPCCADisplay::Instance().SetCurrentSlice(fTracker);
241 AliHLTTPCCADisplay::Instance().DrawSlice( fTracker, 1 );
242 AliHLTTPCCADisplay::Instance().DrawPoint(xDn, neighDnY[0], neighDnZ[0], 2-2 );
243 AliHLTTPCCADisplay::Instance().DrawPoint(x, y[0], z[0], 8-2 );
244 AliHLTTPCCADisplay::Instance().DrawPoint(xUp, neighUpY[i][0], neighUpZ[i][0], 4-2 );
245 AliHLTTPCCADisplay::Instance().DrawSliceHits(-1, 0.5);
246 AliHLTTPCCADisplay::Instance().Ask();
248 const sfloat_v d = dy * dy + dz * dz;
251 const short_m masks( masksf );
253 bestUp( masks ) = neighUp[i].fLinks;
254 debugS() <<
"best up: " << masks <<
" " << bestUp << std::endl;
256 bestDn( dnMask ) = neighDn.fLinks;
257 debugS() <<
"best down: " << dnMask <<
" " << bestDn << std::endl;
263 assert( bestD < chi2Cut || ( bestUp == -1 && bestDn == -1 ) );
265 debugS() <<
"Set Link Data: Up = " << bestUp <<
", Down = " << bestDn << std::endl;
268 const short_m nonUsedMask = validHitsMask && ( short_v(fData.HitDataIsUsed( row ), hitIndexes) == short_v( Vc::Zero ) );
269 assert( ((bestUp >= -1) && (bestUp < rowUp.NHits()) && nonUsedMask) == nonUsedMask );
270 assert( ((bestDn >= -1) && (bestDn < rowDn.NHits()) && nonUsedMask) == nonUsedMask );
271 fData.SetHitLinkUpData( row, hitIndexes, bestUp, nonUsedMask);
272 fData.SetHitLinkDownData( row, hitIndexes, bestDn, nonUsedMask);
const AliHLTTPCCARow & Row(int rowIndex) const