17 #ifndef SLICEDATAVECTOR_H
18 #define SLICEDATAVECTOR_H
20 #include "AliHLTTPCCARow.h"
21 #include "AliHLTTPCCAMath.h"
22 #include "AliHLTTPCCAParam.h"
23 #include "AliHLTTPCCADef.h"
24 #include "AliHLTTPCCAClusterData.h"
36 typedef short short_i;
37 typedef unsigned int uint_i;
48 AliHLTTPCCASliceData() : fRows(), fNumberOfHits(0), fMemorySize( 0 ), fMemory( 0 ), fParam( 0 ) {}
75 short HitLinkDownDataS(
const AliHLTTPCCARow &row,
short hitIndex )
const;
78 short_v HitLinkUpData (
const AliHLTTPCCARow &row,
const short_i &hitIndex )
const;
79 short_v HitLinkDownData(
const AliHLTTPCCARow &row,
const short_i &hitIndex )
const;
80 short_v HitLinkUpData (
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes )
const;
81 short_v HitLinkDownData(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes )
const;
82 void SetHitLinkUpData (
const AliHLTTPCCARow &row,
const short_i &hitIndex,
const short_v &value );
83 void SetHitLinkDownData(
const AliHLTTPCCARow &row,
const short_i &hitIndex,
const short_v &value );
84 void SetHitLinkUpData (
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_v &value,
const short_m &mask );
85 void SetHitLinkDownData(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_v &value,
const short_m &mask );
86 void SetHitLinkUpData (
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_v &value );
87 void SetHitLinkDownData(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_v &value);
98 float HitDataYS(
const AliHLTTPCCARow &row,
short hitIndex )
const;
99 float HitDataZS(
const AliHLTTPCCARow &row,
short hitIndex )
const;
103 sfloat_v HitDataY(
const AliHLTTPCCARow &row,
const uint_i &hitIndex )
const;
104 sfloat_v HitDataZ(
const AliHLTTPCCARow &row,
const uint_i &hitIndex )
const;
105 sfloat_v HitDataY(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const sfloat_m &mask )
const;
106 sfloat_v HitDataZ(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const sfloat_m &mask )
const;
108 void SetHitAsUsed(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_m &mask );
109 void SetHitAsUsedInTrackFit(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_m &mask );
110 void SetHitAsUsedInTrackExtend(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_m &mask );
132 ushort_m TakeOwnHits(
const AliHLTTPCCARow &row,
const ushort_v &hitIndex,
const ushort_m &mask,
133 const ushort_v &weights )
const;
139 const ushort_v &weight );
162 void StoreToFile( FILE * )
const;
163 void RestoreFromFile( FILE * );
165 const float *RowX()
const {
return fParam->RowX(); }
166 float RowX(
int i )
const {
return fParam->RowX( i ); }
170 VectorSizeFactor = ushort_v::Size / float_v::Size
185 return row.fLinkUpData[hitIndex];
188 inline short AliHLTTPCCASliceData::HitLinkDownDataS(
const AliHLTTPCCARow &row,
short hitIndex )
const
190 return row.fLinkDownData[hitIndex];
193 inline const short *AliHLTTPCCASliceData::HitLinkUpData (
const AliHLTTPCCARow &row )
const
195 return row.fLinkUpData;
198 inline const short *AliHLTTPCCASliceData::HitLinkDownData(
const AliHLTTPCCARow &row )
const
200 return row.fLinkDownData;
203 inline short_v AliHLTTPCCASliceData::HitLinkUpData (
const AliHLTTPCCARow &row,
const short_i &hitIndex )
const
206 return short_v( &row.fLinkUpData[hitIndex] );
209 inline short_v AliHLTTPCCASliceData::HitLinkDownData(
const AliHLTTPCCARow &row,
const short_i &hitIndex )
const
212 return short_v( &row.fLinkDownData[hitIndex] );
215 inline short_v AliHLTTPCCASliceData::HitLinkUpData (
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes )
const
217 return short_v( row.fLinkUpData, hitIndexes );
220 inline short_v AliHLTTPCCASliceData::HitLinkDownData(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes )
const
230 return short_v( row.fLinkDownData, hitIndexes );
233 inline void AliHLTTPCCASliceData::SetHitLinkUpData (
const AliHLTTPCCARow &row,
const short_i &hitIndex,
const short_v &value )
236 value.store( &row.fLinkUpData[hitIndex] );
239 inline void AliHLTTPCCASliceData::SetHitLinkDownData(
const AliHLTTPCCARow &row,
const short_i &hitIndex,
const short_v &value )
242 value.store( &row.fLinkDownData[hitIndex] );
245 inline void AliHLTTPCCASliceData::SetHitLinkUpData (
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_v &value,
const short_m &mask )
248 short *array = row.fLinkUpData;
249 foreach_bit(
int i, mask){
250 array[hitIndexes[i]] = value[i];
254 inline void AliHLTTPCCASliceData::SetHitLinkDownData(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_v &value,
const short_m &mask )
257 short *array = row.fLinkDownData;
258 foreach_bit(
int i, mask){
259 array[hitIndexes[i]] = value[i];
263 inline void AliHLTTPCCASliceData::SetHitLinkUpData (
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_v &value)
266 short *array = row.fLinkUpData;
267 for (
int i = 0; i < short_v::Size; i++){
268 array[hitIndexes[i]] = value[i];
273 inline void AliHLTTPCCASliceData::SetHitLinkDownData(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_v &value)
276 short *array = row.fLinkDownData;
277 for (
int i = 0; i < short_v::Size; i++){
278 array[hitIndexes[i]] = value[i];
286 for( ; i < fRows.
Size(); i++ ) {
287 if (fRows[i].fHitDataZ == row.fHitDataZ)
break;
292 inline float AliHLTTPCCASliceData::HitDataYS(
const AliHLTTPCCARow &row,
short hitIndex )
const
294 return row.fHitDataY[hitIndex];
297 inline float AliHLTTPCCASliceData::HitDataZS(
const AliHLTTPCCARow &row,
short hitIndex )
const
299 return row.fHitDataZ[hitIndex];
302 inline const float *AliHLTTPCCASliceData::HitDataY(
const AliHLTTPCCARow &row )
const
304 return row.fHitDataY;
307 inline const float *AliHLTTPCCASliceData::HitDataZ(
const AliHLTTPCCARow &row )
const
309 return row.fHitDataZ;
312 inline const short *AliHLTTPCCASliceData::HitDataIsUsed(
const AliHLTTPCCARow &row )
const
314 return row.fHitDataIsUsed;
317 inline void AliHLTTPCCASliceData::SetHitAsUsed(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_m &mask )
320 short *array = row.fHitDataIsUsed;
321 foreach_bit(
int i, mask){
322 array[hitIndexes[i]] = 1;
326 inline void AliHLTTPCCASliceData::SetHitAsUsedInTrackFit(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_m &mask )
329 short *array = row.fHitDataIsUsed;
330 foreach_bit(
int i, mask){
331 array[hitIndexes[i]] = 2;
335 inline void AliHLTTPCCASliceData::SetHitAsUsedInTrackExtend(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const short_m &mask )
338 short *array = row.fHitDataIsUsed;
339 foreach_bit(
int i, mask){
340 array[hitIndexes[i]] = 3;
344 inline sfloat_v AliHLTTPCCASliceData::HitDataY(
const AliHLTTPCCARow &row,
const uint_i &hitIndex )
const
347 return sfloat_v( &row.fHitDataY[hitIndex] );
350 inline sfloat_v AliHLTTPCCASliceData::HitDataZ(
const AliHLTTPCCARow &row,
const uint_i &hitIndex )
const
353 return sfloat_v( &row.fHitDataZ[hitIndex] );
356 inline sfloat_v AliHLTTPCCASliceData::HitDataY(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const sfloat_m &mask )
const
358 return sfloat_v( row.fHitDataY, hitIndexes, mask );
361 inline sfloat_v AliHLTTPCCASliceData::HitDataZ(
const AliHLTTPCCARow &row,
const ushort_v &hitIndexes,
const sfloat_m &mask )
const
363 return sfloat_v( row.fHitDataZ, hitIndexes, mask );
373 const ushort_v tmp( row.fFirstHitInBin, binIndexes );
374 assert( tmp <= row.NHits() );
380 return row.fFirstHitInBin;
385 return row.fFirstHitInBin[binIndex];
390 return row.fClusterDataIndex[hitIndex];
395 return fRows[rowIndex];
401 return ( numberOfHits << 8 ) | ( unique & 0 );
404 inline ushort_m AliHLTTPCCASliceData::TakeOwnHits(
const AliHLTTPCCARow &row,
405 const ushort_v &hitIndex,
const ushort_m &mask,
const ushort_v &weights )
const
407 const ushort_v storedWeights( row.fHitWeights, hitIndex, mask );
408 const ushort_m own = storedWeights == weights && mask;
409 const ushort_v takenMarker = std::numeric_limits<ushort_v>::max();
410 takenMarker.scatter( row.fHitWeights, hitIndex, own );
415 const ushort_v &hitIndex,
const ushort_v &weight )
417 const short_m mask = validHitIndexes( hitIndex );
419 const ushort_v oldWeight( row.fHitWeights, hitIndex, mask );
420 debugF() <<
"scatter HitWeigths " << weight <<
" to " << hitIndex << ( weight > oldWeight && mask ) <<
" old: " << oldWeight << std::endl;
421 weight.scatter( row.fHitWeights, hitIndex, weight > oldWeight && mask );
426 return ushort_v( row.fHitWeights, hitIndex, mask );
432 static inline float fastInvSqrt(
float _x )
434 union {
float f;
int i; } x = { _x };
435 const float xhalf = 0.5f * x.f;
436 x.i = 0x5f3759df - ( x.i >> 1 );
437 x.f = x.f * ( 1.5f - xhalf * x.f * x.f );
443 const float minCellSize = AliHLTTPCCAParameters::MinCellSize;
444 if ( row->NHits() <= 0 ) {
446 row->fGrid.CreateEmpty();
448 }
else if ( row->NHits() == 1 ) {
449 const float y = data.
Y( clusterDataOffset );
450 const float z = data.
Z( clusterDataOffset );
451 row->fGrid.Create1( y, z, minCellSize, minCellSize );
455 const float norm = fastInvSqrt( AliHLTTPCCAParameters::GridCreationCoeff*row->fNHits );
463 if ( float_v::Size > 1 ) {
466 for (
int i = clusterDataOffset; i < clusterDataOffset + row->fNHits; ++i ) {
467 float tmp[4] = { data.
Y( i ), data.
Z( i ), 0.f, 0.f };
469 r.load( tmp, Vc::Unaligned);
472 min = CAMath::Min( min, r );
473 max = CAMath::Max( max, r );
484 const float_v s = CAMath::Max( ( max - min ) * norm, float_v( minCellSize ) );
488 for (
int i = clusterDataOffset; i < clusterDataOffset + row->fNHits; ++i ) {
489 const float y = data.
Y( i );
490 const float z = data.
Z( i );
491 if ( yMax < y ) yMax = y;
492 if ( yMin > y ) yMin = y;
493 if ( zMax < z ) zMax = z;
494 if ( zMin > z ) zMin = z;
496 sy = CAMath::Max( ( yMax - yMin ) * norm, minCellSize );
497 sz = CAMath::Max( ( zMax - zMin ) * norm, minCellSize );
507 row->fGrid.Create( yMin, yMax, zMin, zMax, sy, sz );
513 #endif // SLICEDATAVECTOR_H
ushort_v FirstHitInBin(const AliHLTTPCCARow &row, ushort_v binIndexes) const
short HitLinkUpDataS(const AliHLTTPCCARow &row, short hitIndex) const
void InitFromClusterData(const AliHLTTPCCAClusterData &data)
ushort_v HitWeight(const AliHLTTPCCARow &row, const ushort_v &hitIndex, const ushort_m &mask) const
const AliHLTTPCCARow & Row(int rowIndex) const
float HitDataXS(const AliHLTTPCCARow &row, short hitIndex) const
int ClusterDataIndex(const AliHLTTPCCARow &row, int hitIndex) const
static ushort_v CalculateHitWeight(ushort_v numberOfHits, ushort_v unique)
void MaximizeHitWeight(const AliHLTTPCCARow &row, const ushort_v &hitIndex, const ushort_v &weight)