24 #include "AliHLTTPCCATracker.h"
25 #include "AliHLTTPCCATrackParamVector.h"
26 #include "AliHLTTPCCAParameters.h"
27 #include "AliHLTTPCCAGrid.h"
28 #include "AliHLTTPCCAMath.h"
29 #include "AliHLTTPCCADef.h"
30 #include "AliHLTTPCCATracklet.h"
31 #include "AliHLTTPCCATrackletConstructor.h"
37 #include "AliHLTTPCCADisplay.h"
56 WaitingForFitLinkedHits = 0,
59 WaitingForExtrapolateDown,
70 short_v fCurrentHitIndex;
73 short_v fRemainingGap;
81 : fStartRow( Vc::Zero ),
82 fCurrentHitIndex( -1 ),
85 fRemainingGap( AliHLTTPCCAParameters::MaximumExtrapolationRowGap ),
88 fIsFragile( Vc::Zero )
94 static_cast<short_m
>( CAMath::Abs( fParam.SinPhi() ) > .999f ||
95 fParam.Chi2() >= sfloat_v(15.f)*
static_cast<sfloat_v
>(fParam.NDF()) );
98 std::ostream &operator<<( std::ostream &out ) {
101 out <<
"SR " << fStartRow << SEP;
102 out <<
"ER " << fEndRow << SEP;
103 out <<
"FR " << fFirstRow << SEP;
104 out <<
"LR " << fLastRow << SEP;
105 out <<
"CI " << fCurrentHitIndex << SEP;
106 out <<
"St " << fStage << SEP;
107 out <<
"NH " << fNHits << SEP;
108 out <<
"RG " << fRemainingGap << SEP;
109 out <<
"LY " << fLastY << SEP;
110 out <<
"LZ " << fLastZ << SEP;
111 out <<
"IF " << fIsFragile << SEP;
124 : r( _r ), fData( data ), fTracker( tracker ),
125 fTrackletVector( trackletVector ), trackIndex( _trackIndex ) {}
134 const ushort_v &trackIndex;
140 void AliHLTTPCCATrackletConstructor::FitTracklet( TrackMemory &r,
const int rowIndex,
145 const short_m active = r.fStage == FitLinkedHits;
147 assert( AliHLTTPCCAParameters::RowStep == 1 );
152 debugF() <<
"FitTracklet(" << rowIndex <<
") stage: " << r.fStage <<
" r.fStartRow: " << r.fStartRow <<
" active: " << active << endl;
154 assert( active == ( active && r.fStage == FitLinkedHits ) );
155 assert( active == ( active && r.fCurrentHitIndex >= 0 ) );
156 assert( active == ( active && rowIndex > r.fStartRow ) );
158 ASSERT( active == ( active && r.fCurrentHitIndex < row.NHits() ),
159 active << r.fCurrentHitIndex << row.NHits() );
161 const ushort_v oldHitIndex =
static_cast<ushort_v
>( r.fCurrentHitIndex );
166 const short_v isUsed(fData.HitDataIsUsed( row ),
static_cast<ushort_v
>(oldHitIndex), active);
167 const short_m fitMask = active && ( (isUsed != short_v(2)) && (isUsed != short_v(3)) );
169 const sfloat_v x = fData.RowX( rowIndex );
170 const sfloat_v y( fData.HitDataY( row ), oldHitIndex, fitMask);
171 const sfloat_v z( fData.HitDataZ( row ), oldHitIndex, fitMask);
173 debugF() <<
"x, y, z: " << x << y << z << endl;
175 sfloat_m activeF( static_cast<sfloat_m>( fitMask ) );
178 const sfloat_v dx = x - r.fParam.X();
179 const sfloat_v dy = y - r.fLastY;
180 const sfloat_v dz = z - r.fLastZ;
181 debugF() <<
"dx, dy, dz: " << dx << dy << dz << endl;
182 r.fLastY( activeF ) = y;
183 r.fLastZ( activeF ) = z;
185 sfloat_v err2Y, err2Z;
186 sfloat_v sinPhi = r.fParam.GetSinPhi();
189 const sfloat_m fragile =
190 static_cast<sfloat_m
>( r.fNHits < ushort_v(AliHLTTPCCAParameters::MinimumHitsForFragileTracklet) ) || CAMath::Abs( r.fParam.SinPhi() ) >= .99f;
191 sinPhi( fragile ) = dy * CAMath::RSqrt( dx * dx + dy * dy );
194 assert( ( x == 0 && activeF ).isEmpty() );
196 activeF = r.fParam.TransportToX( x, sinPhi, fTracker.Param().cBz(), -1.f, activeF );
198 if ( !activeF.isEmpty() )
200 fTracker.GetErrors2( rowIndex, r.fParam, &err2Y, &err2Z );
201 const short_m hitAdded =
static_cast<short_m
>( r.fParam.Filter( activeF, y, z, err2Y, err2Z, .99f ) );
202 trackletVector.SetRowHits( rowIndex, trackIndex, static_cast<ushort_v>(r.fCurrentHitIndex), hitAdded );
203 ++r.fNHits( static_cast<ushort_m>(hitAdded) );
204 r.fEndRow( hitAdded ) = rowIndex;
206 ASSERT( ( (row.NHits() >
static_cast<ushort_v
>(oldHitIndex) ) && hitAdded ) == hitAdded,
207 row.NHits() <<
static_cast<ushort_v
>(oldHitIndex) << hitAdded );
208 fData.SetHitAsUsedInTrackFit( row, static_cast<ushort_v>( oldHitIndex ), hitAdded );
211 r.fCurrentHitIndex.gather( fData.HitLinkUpData( row ),
static_cast<ushort_v
>( oldHitIndex ), active );
213 const short_m fittingDone = r.fCurrentHitIndex < 0 && active;
214 debugF() <<
"fittingDone = " << fittingDone << endl;
216 ++r.fStage( fittingDone );
217 r.fLastRow( fittingDone ) = rowIndex;
218 debugF() <<
"hits: " << r.fNHits <<
", sinphi: " << r.fParam.SinPhi() << endl;
221 const short_m invalidTracklet = r.IsInvalid() && fittingDone;
223 r.fNHits.setZero( invalidTracklet );
224 r.fStage( invalidTracklet || (fittingDone && !r.fIsFragile) ) = DoneStage;
226 debugF() <<
"r.fStage: " << r.fStage << endl;
230 void AliHLTTPCCATrackletConstructor::FindNextHit( TrackMemory &r,
const AliHLTTPCCARow &row,
231 sfloat_v::Memory &dy_best, sfloat_v::Memory &dz_best, short_m &active)
233 const sfloat_v fY = r.fParam.Y();
234 const sfloat_v fZ = r.fParam.Z();
235 const ushort_v fIndYmin = row.Grid().
GetBinBounded( fY - AliHLTTPCCAParameters::MinCellSize*.5f, fZ - AliHLTTPCCAParameters::MinCellSize*.5f );
237 short_v::Memory fHitIndexes;
238 for(
int iv=0; iv<short_v::Size; iv++)
239 fHitIndexes[iv] = -1;
241 foreach_bit(
int trackletIndex, active ) {
242 float minRadius2 = std::numeric_limits<float>::max();
244 const float y = fY[trackletIndex];
245 const float z = fZ[trackletIndex];
246 const int indYmin = fIndYmin[trackletIndex];
250 for (
int hitIndex = fData.
FirstHitInBin( row, indYmin ); hitIndex < end; hitIndex += float_v::Size ) {
252 yz.load( fData.HitDataY( row ) + hitIndex, Vc::Unaligned);
253 const float_v dy = yz - y;
254 yz.load( fData.HitDataZ( row ) + hitIndex, Vc::Unaligned);
256 const float_v dz = yz - z;
257 float_v radius2 = std::numeric_limits<float_v>::max();
258 radius2( uint_v( Vc::IndexesFromZero ) + hitIndex < end ) = dy * dy + dz * dz;
262 const float min = radius2.min();
263 if ( min < minRadius2 ) {
265 int i = ( radius2 == min ).firstOne();
266 assert( minRadius2 == radius2[i] );
267 dy_best[trackletIndex] = dy[i];
268 dz_best[trackletIndex] = dz[i];
269 fHitIndexes[trackletIndex] = hitIndex + i;
274 const int nY = row.Grid().Ny();
275 const int end = fData.
FirstHitInBin( row, indYmin + nY + 2 );
276 for (
int hitIndex = fData.
FirstHitInBin( row, indYmin + nY ); hitIndex < end; hitIndex += float_v::Size ) {
278 yz.load( fData.HitDataY( row ) + hitIndex, Vc::Unaligned );
279 const float_v dy = yz - y;
280 yz.load( fData.HitDataZ( row ) + hitIndex, Vc::Unaligned );
281 const float_v dz = yz - z;
284 float_v radius2 = std::numeric_limits<float_v>::max();
285 radius2( uint_v( Vc::IndexesFromZero ) + hitIndex < end ) = dy * dy + dz * dz;
286 const float min = radius2.min();
287 if ( min < minRadius2 ) {
289 int i = ( radius2 == min ).firstOne();
290 assert( minRadius2 == radius2[i] );
291 dy_best[trackletIndex] = dy[i];
292 dz_best[trackletIndex] = dz[i];
293 fHitIndexes[trackletIndex] = hitIndex + i;
299 r.fCurrentHitIndex( active ) =
static_cast<short_v
>( fHitIndexes );
301 active &= (r.fCurrentHitIndex != short_v(-1));
307 short_m AliHLTTPCCATrackletConstructor::ExtrapolateTracklet( TrackMemory &r,
const int rowIndex,
const ushort_v trackIndex,
308 TrackletVector &trackletVector,
const bool dir,
const short_m &mask )
315 short_m active = mask;
316 --r.fRemainingGap( active );
317 assert( r.fRemainingGap >= 0 || !active );
318 debugF() <<
"ExtrapolateTracklet(" << rowIndex <<
") fRemainingGap: " << r.fRemainingGap << endl;
321 const sfloat_v x = fData.RowX( rowIndex );
341 sfloat_m activeF( active );
342 assert( ( x == 0 && activeF ).isEmpty() );
346 sfloat_m transport = r.fParam.TransportToX( x, r.fParam.SinPhi(), fTracker.Param().cBz(), .99f, activeF );
347 activeF &= transport;
349 active =
static_cast<short_m
>( activeF );
351 if ( row.NHits() < 1 || active.isEmpty() ) {
352 ++r.fStage( r.fRemainingGap == 0 && mask );
354 debugF() <<
"r.fStage: " << r.fStage <<
" after ExtrapolateTracklet found empty row and fRemainingGap == " << r.fRemainingGap << endl;
357 ASSERT( r.fRemainingGap >= 0,
359 return short_m( Vc::Zero );
367 short_m linkMask = active; linkMask &= short_m(Vc::Zero);
398 sfloat_v::Memory dy_tmp; dy_tmp = sfloat_v(Vc::Zero);
399 sfloat_v::Memory dz_tmp; dz_tmp = sfloat_v(Vc::Zero);
400 short_m findMask = active && !linkMask;
402 FindNextHit(r, row, dy_tmp, dz_tmp, findMask);
404 const sfloat_v dy( dy_tmp );
405 const sfloat_v dz( dz_tmp );
406 active = linkMask || findMask;
419 sfloat_v err2Y, err2Z;
420 fTracker.GetErrors2( rowIndex, r.fParam, &err2Y, &err2Z );
422 const sfloat_v kFactor = AliHLTTPCCAParameters::HitPickUpFactor * AliHLTTPCCAParameters::HitPickUpFactor * 3.5f * 3.5f;
423 const sfloat_v two( 2.f );
425 const sfloat_v sy2 = CAMath::Min( two, kFactor * ( r.fParam.GetErr2Y() + err2Y ) );
426 const sfloat_v sz2 = CAMath::Min( two, kFactor * ( r.fParam.GetErr2Z() + err2Z ) );
428 activeF =
static_cast<sfloat_m
>( active );
429 debugF() <<
"activeF: " << activeF;
430 activeF &= dy * dy <= sy2 && dz * dz <= sz2;
431 debugF() <<
" -> " << activeF;
434 sfloat_m filtred = r.fParam.FilterDelta( activeF, dy, dz, err2Y, err2Z, .99f );
437 debugF() <<
" -> " << activeF;
438 active =
static_cast<short_m
>( activeF );
439 debugF() <<
" -> " << active << endl;
441 debugF() <<
"SetRowHits( " << rowIndex <<
", " << r.fCurrentHitIndex <<
", " << active <<
")" << endl;
443 ASSERT( ( (row.NHits() > r.fCurrentHitIndex) && active) == active,
444 row.NHits() << r.fCurrentHitIndex << active );
445 fData.SetHitAsUsedInTrackExtend( row, static_cast<ushort_v>(r.fCurrentHitIndex), active );
447 trackletVector.SetRowHits( rowIndex, trackIndex, static_cast<ushort_v>(r.fCurrentHitIndex), active );
448 ++r.fNHits( static_cast<ushort_m>(active) );
449 r.fRemainingGap( active ) = AliHLTTPCCAParameters::MaximumExtrapolationRowGap;
450 ++r.fStage( r.fRemainingGap == 0 && mask );
453 r.fLastRow( active && short_m( dir) ) = rowIndex;
454 r.fFirstRow( active && short_m(!dir) ) = rowIndex;
458 short_m AliHLTTPCCATrackletConstructor::ExtendTracklet( TrackMemory &r,
const int rowIndex,
const ushort_v trackIndex,
459 TrackletVector &trackletVector,
const bool dir,
const short_m &mask )
464 assert( AliHLTTPCCAParameters::RowStep == 1 );
467 short_m activeExtraMask = mask;
468 const short_m activeFitMask = (r.fStage == FitLinkedHits);
472 assert( activeFitMask == ( activeFitMask && r.fStage == FitLinkedHits ) );
473 assert( activeFitMask == ( activeFitMask && r.fCurrentHitIndex >= 0 ) );
474 assert( activeFitMask == ( activeFitMask && rowIndex > r.fStartRow ) );
475 ASSERT( activeFitMask == ( activeFitMask && r.fCurrentHitIndex < row.NHits() ),
476 activeFitMask << r.fCurrentHitIndex << row.NHits() );
477 assert( (activeFitMask && activeExtraMask).isEmpty() );
480 const ushort_v oldHitIndex =
static_cast<ushort_v
>( r.fCurrentHitIndex );
484 --r.fRemainingGap( activeExtraMask );
485 debugF() <<
"ExtrapolateTracklet(" << rowIndex <<
") fRemainingGap: " << r.fRemainingGap << endl;
490 const sfloat_v x = fData.RowX( rowIndex );
493 const short_v isUsed(fData.HitDataIsUsed( row ),
static_cast<ushort_v
>(oldHitIndex), activeFitMask);
494 const short_m fitMask = activeFitMask && (isUsed != short_v(2)) && (isUsed != short_v(3));
496 sfloat_m activeFitMaskF( static_cast<sfloat_m>( fitMask ) );
497 sfloat_m activeExtraMaskF( static_cast<sfloat_m>(activeExtraMask) );
499 assert( row.NHits() > oldHitIndex || !fitMask );
500 sfloat_v y( fData.HitDataY( row ), oldHitIndex, activeFitMaskF);
501 sfloat_v z( fData.HitDataZ( row ), oldHitIndex, activeFitMaskF);
504 const sfloat_v dx = x - r.fParam.X();
506 sfloat_v dy = y - r.fLastY;
507 sfloat_v dz = z - r.fLastZ;
508 r.fLastY( activeFitMaskF ) = y;
509 r.fLastZ( activeFitMaskF ) = z;
511 sfloat_v sinPhi = r.fParam.GetSinPhi();
513 const sfloat_m fragile = activeFitMaskF &&
514 (
static_cast<sfloat_m
>( r.fNHits < ushort_v(AliHLTTPCCAParameters::MinimumHitsForFragileTracklet) ) || CAMath::Abs( r.fParam.SinPhi() ) >= .99f );
515 sinPhi( fragile ) = dy * CAMath::RSqrt( dx * dx + dy * dy );
517 sfloat_v maxSinPhi = .99f;
518 maxSinPhi( activeFitMaskF ) = -1.f;
524 assert( ( (x == 0) && (activeExtraMaskF || activeFitMaskF) ).isEmpty() );
526 sfloat_m transport = r.fParam.TransportToX( x, sinPhi, fTracker.Param().cBz(), maxSinPhi, activeExtraMaskF || activeFitMaskF );
527 activeExtraMaskF &= transport;
528 activeFitMaskF &= transport;
531 if ( row.NHits() < 1 || ( activeExtraMaskF || activeFitMaskF ).isEmpty() ) {
534 ++r.fStage( r.fRemainingGap == 0 && mask );
536 debugF() <<
"r.fStage: " << r.fStage <<
" after ExtrapolateTracklet found empty row and fRemainingGap == " << r.fRemainingGap << endl;
540 r.fCurrentHitIndex.gather( fData.HitLinkUpData( row ),
static_cast<ushort_v
>( oldHitIndex ), activeFitMask );
542 const short_m fittingDone = r.fCurrentHitIndex < 0 && activeFitMask;
543 ++r.fStage( fittingDone );
544 r.fLastRow( fittingDone ) = rowIndex;
546 const short_m invalidTracklet = r.IsInvalid() && fittingDone;
547 r.fNHits.setZero( invalidTracklet );
548 r.fStage( invalidTracklet || (fittingDone && !r.fIsFragile) ) = DoneStage;
550 return short_m( Vc::Zero );
556 activeExtraMask =
static_cast<short_m
>( activeExtraMaskF );
559 short_m linkMask = short_m(Vc::Zero);
585 dy = y - r.fParam.Y();
586 dz = z - r.fParam.Z();
589 sfloat_v::Memory dy_tmp, dz_tmp;
590 short_m findMask = activeExtraMask && !linkMask;
591 if ( !findMask.isEmpty() ) {
594 FindNextHit(r, row, dy_tmp, dz_tmp, findMask);
605 activeExtraMask = linkMask || findMask;
606 activeExtraMaskF =
static_cast<sfloat_m
>( activeExtraMask );
608 dy( static_cast<sfloat_m>( findMask ) ) = sfloat_v( dy_tmp );
609 dz( static_cast<sfloat_m>( findMask ) ) = sfloat_v( dz_tmp );
622 sfloat_v err2Y, err2Z;
623 fTracker.GetErrors2( rowIndex, r.fParam, &err2Y, &err2Z );
625 const sfloat_v kFactor = AliHLTTPCCAParameters::HitPickUpFactor * AliHLTTPCCAParameters::HitPickUpFactor * 3.5f * 3.5f;
626 const sfloat_v two( 2.f );
628 const sfloat_v sy2 = CAMath::Min( two, kFactor * ( r.fParam.GetErr2Y() + err2Y ) );
629 const sfloat_v sz2 = CAMath::Min( two, kFactor * ( r.fParam.GetErr2Z() + err2Z ) );
632 activeExtraMaskF &= dy * dy <= sy2 && dz * dz <= sz2;
634 activeFitMaskF &= (dy * dy <= sy2 && dz * dz <= sz2) || (r.fNHits < 3);
639 const sfloat_m filtred = r.fParam.FilterDelta( activeExtraMaskF || activeFitMaskF, dy, dz, err2Y, err2Z, .99f );
640 activeExtraMaskF &= filtred;
641 activeExtraMask =
static_cast<short_m
>( activeExtraMaskF );
642 activeFitMaskF &= filtred;
643 const short_m hitAdded =
static_cast<short_m
>( activeFitMaskF );
649 trackletVector.SetRowHits( rowIndex, trackIndex, static_cast<ushort_v>(r.fCurrentHitIndex), activeExtraMask || hitAdded );
651 r.fCurrentHitIndex.gather( fData.HitLinkUpData( row ),
static_cast<ushort_v
>( oldHitIndex ), activeFitMask );
654 ASSERT( ( (row.NHits() > r.fCurrentHitIndex) && activeExtraMask) == activeExtraMask,
655 row.NHits() << r.fCurrentHitIndex << activeExtraMask );
656 fData.SetHitAsUsedInTrackExtend( row, static_cast<ushort_v>( r.fCurrentHitIndex ), activeExtraMask );
657 fData.SetHitAsUsedInTrackFit( row, static_cast<ushort_v>( oldHitIndex ), hitAdded );
659 ++r.fNHits( static_cast<ushort_m>( activeExtraMask || hitAdded ) );
660 r.fRemainingGap( activeExtraMask ) = AliHLTTPCCAParameters::MaximumExtrapolationRowGap;
664 ++r.fStage( (r.fRemainingGap == 0) && mask );
665 ASSERT( r.fRemainingGap >= 0,
666 r.fRemainingGap << mask << activeExtraMask );
669 const short_m fittingDone = r.fCurrentHitIndex < 0 && activeFitMask;
670 ++r.fStage( fittingDone );
671 r.fLastRow( fittingDone ) = rowIndex;
673 const short_m invalidTracklet = r.IsInvalid() && fittingDone;
674 r.fNHits.setZero( invalidTracklet );
675 r.fStage( invalidTracklet || (fittingDone && !r.fIsFragile) ) = DoneStage;
677 r.fEndRow( hitAdded ) = rowIndex;
679 r.fLastRow( activeExtraMask && short_m( dir) ) = rowIndex;
680 r.fFirstRow( activeExtraMask && short_m(!dir) ) = rowIndex;
681 return activeExtraMask;
688 assert( *fTracker.NTracklets() < 32768 );
689 const short nTracks = *fTracker.NTracklets();
691 for (
int trackIteration = 0; trackIteration * ushort_v::Size < nTracks; ++trackIteration ) {
692 const ushort_v trackIndex( ushort_v( Vc::IndexesFromZero ) + trackIteration * ushort_v::Size );
693 const ushort_m active = trackIndex < nTracks;
697 r.fStage( !active ) = NullStage;
700 r.fStartRow.gather( fTracker.TrackletStartHits(),
reinterpret_cast<short AliHLTTPCCAStartHitId::*
>( &AliHLTTPCCAStartHitId::fRow ), trackIndex, active );
701 r.fCurrentHitIndex.gather( fTracker.TrackletStartHits(),
reinterpret_cast<short int AliHLTTPCCAStartHitId::*
>( &AliHLTTPCCAStartHitId::fHit ), trackIndex, active );
702 r.fEndRow =
static_cast<ushort_v
>( r.fStartRow );
703 r.fLastRow =
static_cast<ushort_v
>( r.fStartRow );
704 r.fStartRow( !active ) = std::numeric_limits<short_v>::max();
705 r.fFirstRow = r.fStartRow;
706 ushort_v length( fTracker.TrackletStartHits(),
reinterpret_cast<unsigned short AliHLTTPCCAStartHitId::*
>( &AliHLTTPCCAStartHitId::fLength ), trackIndex, active );
707 const ushort_v MaxNHitsForFragileTracklet(6);
708 r.fIsFragile = (length < MaxNHitsForFragileTracklet);
710 const sfloat_v zero( Vc::Zero );
711 const sfloat_v one( Vc::One );
712 r.fParam.SetSinPhi( zero );
713 r.fParam.SetDzDs( zero );
714 r.fParam.SetQPt( zero );
715 r.fParam.SetSignCosPhi( one );
716 r.fParam.SetChi2( zero );
717 r.fParam.SetNDF( -3 );
718 r.fParam.SetCov( 0, one );
719 r.fParam.SetCov( 1, zero );
720 r.fParam.SetCov( 2, one );
721 r.fParam.SetCov( 3, zero );
722 r.fParam.SetCov( 4, zero );
723 r.fParam.SetCov( 5, one );
724 r.fParam.SetCov( 6, zero );
725 r.fParam.SetCov( 7, zero );
726 r.fParam.SetCov( 8, zero );
727 r.fParam.SetCov( 9, one );
728 r.fParam.SetCov( 10, zero );
729 r.fParam.SetCov( 11, zero );
730 r.fParam.SetCov( 12, zero );
731 r.fParam.SetCov( 13, zero );
732 r.fParam.SetCov( 14, 10.f );
742 InitTracklets init( r, fData, fTracker, fTrackletVectors[trackIteration], trackIndex );
743 r.fStartRow.callWithValuesSorted( init );
748 static unsigned int counters[6] = { 0, 0, 0, 0, 0, 0 };
750 #endif // USE_COUNTERS
752 const int rowStep = AliHLTTPCCAParameters::RowStep;
754 int rowIndex = r.fStartRow.min() + rowStep*2;
755 const short_v activationRow = r.fStartRow + rowStep*2;
756 debugF() <<
"============================================= Start Fitting Upwards =============================================" << endl;
759 #ifdef DISABLE_HIT_SEARCH
760 while ( rowIndex < fTracker.Param().NRows() && !( r.fStage <= FitLinkedHits ).isEmpty() ) {
763 #endif // USE_COUNTERS
765 ++r.fStage( rowIndex == activationRow );
766 FitTracklet( r, rowIndex, trackIndex, fTrackletVectors[trackIteration] );
771 const short_m ready = r.fStage <= DoneStage;
772 const sfloat_v x( fData.RowX(), sfloat_v::IndexType( r.fEndRow ) );
774 debugF() << x << sfloat_v::IndexType( r.fEndRow ) << sfloat_v( fData.RowX(), sfloat_v::IndexType( Vc::IndexesFromZero ) ) << endl;
775 assert( ( x == 0 && static_cast<sfloat_m>( ready ) ).isEmpty() );
778 const short_m transported =
static_cast<short_m
>( r.fParam.TransportToX(
779 x, fTracker.Param().cBz(), .999f,
static_cast<sfloat_m
>( ready ) ) );
781 debugF() <<
"============================================= Stop Fitting Upwards ==============================================" << endl;
783 if ( AliHLTTPCCADisplay::Instance().DrawType() == 1 ) {
784 foreach_bit(
int ii, r.fStage < DoneStage ) {
786 AliHLTTPCCADisplay::Instance().ClearView();
787 AliHLTTPCCADisplay::Instance().DrawSlice( &fTracker, 0 );
788 AliHLTTPCCADisplay::Instance().DrawSliceHits();
789 AliHLTTPCCADisplay::Instance().DrawTrackParam( t );
790 AliHLTTPCCADisplay::Instance().Ask();
794 #else // DISABLE_HIT_SEARCH
796 while ( rowIndex < fTracker.Param().NRows() && ( r.fStage == ExtrapolateUp ).isEmpty() ) {
799 #endif // USE_COUNTERS
801 r.fStage( rowIndex == activationRow ) = FitLinkedHits;
803 ExtendTracklet( r, rowIndex, trackIndex, fTrackletVectors[trackIteration], 1, short_m(Vc::Zero) );
808 debugF() <<
"========================================== Start Extrapolating Upwards ==========================================" << endl;
811 assert( r.fRemainingGap >= 0 );
813 while ( rowIndex < fTracker.Param().NRows() && !( r.fStage <= ExtrapolateUp ).isEmpty() ) {
816 #endif // USE_COUNTERS
818 r.fStage( rowIndex == activationRow ) = FitLinkedHits;
819 const short_m toExtrapolate = (r.fStage == ExtrapolateUp);
820 ExtendTracklet( r, rowIndex, trackIndex, fTrackletVectors[trackIteration], 1, toExtrapolate );
824 debugF() <<
"============================================= Stop Fitting Upwards ==============================================" << endl;
828 assert( r.fRemainingGap >= 0 );
829 while ( rowIndex < fTracker.Param().NRows() && !( mask = r.fStage == ExtrapolateUp ).isEmpty() ) {
832 #endif // USE_COUNTERS
834 assert ( r.fStage != FitLinkedHits );
835 ExtrapolateTracklet( r, rowIndex, trackIndex, fTrackletVectors[trackIteration], 1, mask );
838 debugF() <<
"=========================================== Stop Extrapolating Upwards ==========================================" << endl;
843 r.fRemainingGap = AliHLTTPCCAParameters::MaximumExtrapolationRowGap;
844 ++r.fStage( r.fStage == ExtrapolateUp );
845 const short_m ready = r.fStage == WaitingForExtrapolateDown;
846 debugF() <<
"ready to extrapolate downwards: " << ready << endl;
851 const sfloat_v x( fData.RowX(), sfloat_v::IndexType( r.fStartRow ),
static_cast<sfloat_m
>(ready));
852 debugF() << x << sfloat_v::IndexType( r.fEndRow ) << sfloat_v( fData.RowX(), sfloat_v::IndexType( Vc::IndexesFromZero ) ) << endl;
853 assert( ( x == 0 && static_cast<sfloat_m>( ready ) ).isEmpty() );
854 const short_m transported =
static_cast<short_m
>( r.fParam.TransportToX(
855 x, fTracker.Param().cBz(), .999f,
static_cast<sfloat_m
>( ready ) ) );
856 ++r.fStage( !transported );
859 if ( AliHLTTPCCADisplay::Instance().DrawType() == 1 ) {
860 foreach_bit(
int ii, r.fStage < DoneStage ) {
862 AliHLTTPCCADisplay::Instance().ClearView();
863 AliHLTTPCCADisplay::Instance().DrawSlice( &fTracker, 0 );
864 AliHLTTPCCADisplay::Instance().DrawSliceHits();
865 AliHLTTPCCADisplay::Instance().DrawTrackParam( t, 2 );
866 AliHLTTPCCADisplay::Instance().Ask();
870 debugF() <<
"========================================= Start Extrapolating Downwards =========================================" << endl;
872 short_v tmpRow(r.fStartRow);
873 tmpRow(!active) = fTracker.Param().NRows()-1;
874 int rowIndex = tmpRow.max();
878 const int minMaskedExtrRow = r.fStartRow.min();
879 while ( rowIndex >= minMaskedExtrRow && !( mask = r.fStage == ExtrapolateDown ).isEmpty() ) {
882 #endif // USE_COUNTERS
884 mask &= rowIndex < r.fStartRow + 1;
885 mask &= ( ( rowIndex - r.fStartRow ) & short_v( std::numeric_limits<short_v::EntryType>::min() + 1 ) ) != short_v( Vc::Zero );
886 ExtrapolateTracklet( r, rowIndex, trackIndex, fTrackletVectors[trackIteration], 0, mask );
890 while ( rowIndex >= 0 && !( mask = r.fStage == ExtrapolateDown ).isEmpty() ) {
893 #endif // USE_COUNTERS
894 ExtrapolateTracklet( r, rowIndex, trackIndex, fTrackletVectors[trackIteration], 0, mask );
897 r.fFirstRow = CAMath::Min( r.fFirstRow, r.fStartRow );
899 if ( AliHLTTPCCADisplay::Instance().DrawType() == 1 ) {
900 foreach_bit(
int ii, r.fStage < NullStage ) {
902 AliHLTTPCCADisplay::Instance().ClearView();
903 AliHLTTPCCADisplay::Instance().DrawSlice( &fTracker, 0 );
904 AliHLTTPCCADisplay::Instance().DrawSliceHits();
905 AliHLTTPCCADisplay::Instance().DrawTrackParam( t, 4 );
906 AliHLTTPCCADisplay::Instance().Ask();
916 #endif // DISABLE_HIT_SEARCH
920 std::cout <<
"Counters= " << counters[0] <<
" " << counters[1] <<
" " << counters[2] <<
" " << counters[3] <<
" " << counters[4] <<
" " << counters[5] << std::endl;
921 #endif // USE_COUNTERS
923 sfloat_m trackletOkF( r.fNHits >= ushort_v(AliHLTTPCCAParameters::MinimumHitsForTracklet) );
924 for (
int i = 0; i < 15; ++i ) {
925 trackletOkF &= CAMath::Finite( r.fParam.Cov()[i] );
927 for (
int i = 0; i < 5; ++i ) {
928 trackletOkF &= CAMath::Finite( r.fParam.Par()[i] );
933 assert( ( r.fParam.X() > 50.f && trackletOkF ) == trackletOkF );
934 trackletOkF &= r.fParam.X() > 50.f
938 && r.fParam.Err2QPt() > Vc::Zero;
939 trackletOkF &= r.fParam.Err2Y() > Vc::Zero && r.fParam.Err2Z() > Vc::Zero;
940 trackletOkF &= r.fParam.Err2SinPhi() > Vc::Zero && r.fParam.Err2DzDs() > Vc::Zero;
942 debugF() << r.fParam <<
"-> trackletOk: " << trackletOkF << endl;
944 const short_m trackletOk( trackletOkF );
945 r.fNHits.setZero( !trackletOk );
952 tracklet.SetNHits( r.fNHits );
954 if ( !( r.fNHits > 0 ).isEmpty() ) {
956 if ( AliHLTTPCCADisplay::Instance().DrawType() == 1 ) {
957 foreach_bit(
int ii, r.fStage < DoneStage ) {
959 AliHLTTPCCADisplay::Instance().ClearView();
960 AliHLTTPCCADisplay::Instance().DrawSlice( &fTracker, 0 );
961 AliHLTTPCCADisplay::Instance().DrawSliceHits();
962 AliHLTTPCCADisplay::Instance().DrawTrackParam( t, 2 );
963 AliHLTTPCCADisplay::Instance().Ask();
968 tracklet.SetFirstRow( static_cast<ushort_v>( r.fFirstRow ) );
969 tracklet.SetLastRow( r.fLastRow );
972 const sfloat_m MinQPt = CAMath::Abs(r.fParam.QPt()) < AliHLTTPCCAParameters::MinimumQPt;
973 sfloat_v NewQPt = r.fParam.QPt();
974 NewQPt(MinQPt) = AliHLTTPCCAParameters::MinimumQPt;
975 r.fParam.SetQPt(NewQPt);
978 tracklet.SetParam( r.fParam );
980 debugTS() << r.fFirstRow << r.fLastRow << endl;
981 debugTS() <<
"set hit weigths from row " << r.fFirstRow.min() <<
" until row " << r.fLastRow.max() << endl;
984 for (
int rowIndex = r.fFirstRow.min(); rowIndex <= r.fLastRow.max(); ++rowIndex ) {
985 const ushort_v &hitIndex = tracklet.HitIndexAtRow( rowIndex );
986 debugTS() <<
"MaximizeHitWeight at " << rowIndex << hitIndex <<
" with " << weight << endl;
995 if ( ISUNLIKELY( rowIndex >= fTracker.Param().NRows() ) ) {
998 debugF() <<
"InitTracklets(" << rowIndex <<
")" << endl;
1000 const int rowStep = AliHLTTPCCAParameters::RowStep;
1001 assert( rowIndex < fTracker.Param().NRows() - rowStep );
1003 const ushort_m &mask = rowIndex == r.fStartRow;
1004 const sfloat_m maskF( mask );
1007 const sfloat_v x = fData.RowX( rowIndex );
1008 const ushort_v &hitIndex =
static_cast<ushort_v
>( r.fCurrentHitIndex );
1009 const sfloat_v y( fData.HitDataY( row ), hitIndex, mask );
1010 const sfloat_v z( fData.HitDataZ( row ), hitIndex, mask );
1011 r.fParam.SetX( x, maskF );
1012 r.fParam.SetY( y, maskF );
1013 r.fParam.SetZ( z, maskF );
1014 fTrackletVector.SetRowHits( rowIndex, trackIndex, hitIndex, mask );
1017 const short_v isUsed(fData.HitDataIsUsed( row ),
static_cast<ushort_v
>( r.fCurrentHitIndex ), mask);
1018 fData.SetHitAsUsedInTrackFit( row, static_cast<ushort_v>( r.fCurrentHitIndex ), static_cast<short_m>(mask) && ( isUsed == short_v(1) ) );
1020 r.fCurrentHitIndex.gather( fData.HitLinkUpData( row ), hitIndex, mask );
1023 assert( ( r.fCurrentHitIndex >= 0 && mask ) == mask );
1026 rowIndex += rowStep;
1029 const sfloat_v x = fData.RowX( rowIndex );
1030 const ushort_v &hitIndex =
static_cast<ushort_v
>( r.fCurrentHitIndex );
1031 const sfloat_v y( fData.HitDataY( row ), hitIndex, mask);
1032 const sfloat_v z( fData.HitDataZ( row ), hitIndex, mask);
1033 const sfloat_v &dx = x - r.fParam.X();
1034 const sfloat_v &dy = y - r.fParam.Y();
1035 const sfloat_v &dz = z - r.fParam.Z();
1036 const sfloat_v &ri = sfloat_v( Vc::One ) * CAMath::RSqrt( dx * dx + dy * dy );
1037 const sfloat_v &sinPhi = dy * ri;
1038 r.fParam.SetSinPhi( sinPhi, maskF );
1039 r.fParam.SetDzDs ( dz * ri, maskF );
1040 sfloat_v err2Y, err2Z;
1043 fTracker.GetErrors2( rowIndex, r.fParam, &err2Y, &err2Z );
1045 r.fParam.SetCov( 0, err2Y, maskF );
1046 r.fParam.SetCov( 2, err2Z, maskF );
1048 const sfloat_m transported = r.fParam.TransportToX( x, sinPhi, fTracker.Param().cBz(), -1.f, maskF );
1052 fTracker.GetErrors2( rowIndex, r.fParam, &err2Y, &err2Z );
1054 const short_m hitAdded( r.fParam.Filter( maskF, y, z, err2Y, err2Z, .99f ) );
1056 UNUSED_PARAM2( transported, hitAdded );
1057 fTrackletVector.SetRowHits( rowIndex, trackIndex, hitIndex, mask );
1059 r.fLastY( maskF ) = y;
1060 r.fLastZ( maskF ) = z;
1063 const short_v isUsed(fData.HitDataIsUsed( row ),
static_cast<ushort_v
>( r.fCurrentHitIndex ), mask);
1064 fData.SetHitAsUsedInTrackFit( row, static_cast<ushort_v>( r.fCurrentHitIndex ), static_cast<short_m>(mask) && ( isUsed == short_v(1) ) );
1066 r.fCurrentHitIndex.gather( fData.HitLinkUpData( row ), hitIndex, mask );
1070 assert( ( r.fCurrentHitIndex >= 0 && mask ) == mask );
ushort_v FirstHitInBin(const AliHLTTPCCARow &row, ushort_v binIndexes) const
const AliHLTTPCCARow & Row(int rowIndex) const
ushort_v GetBinBounded(const sfloat_v &Y, const sfloat_v &Z) const
void operator()(int rowIndex)
static ushort_v CalculateHitWeight(ushort_v numberOfHits, ushort_v unique)
void MaximizeHitWeight(const AliHLTTPCCARow &row, const ushort_v &hitIndex, const ushort_v &weight)