24 #include "AliHLTTPCCATrackletSelector.h"
25 #include "AliHLTTPCCATrack.h"
26 #include "AliHLTTPCCATracker.h"
27 #include "AliHLTTPCCATrackParamVector.h"
28 #include "AliHLTTPCCATracklet.h"
29 #include "AliHLTTPCCAMath.h"
30 #include "AliHLTTPCCAParameters.h"
34 #include <tbb/atomic.h>
40 #include "AliHLTTPCCADisplay.h"
45 void AliHLTTPCCATrackletSelector::run()
47 fTracks.resize( fTrackletVectors.Size() * ushort_v::Size * AliHLTTPCCAParameters::MaxNumberOfRows8 / AliHLTTPCCAParameters::MinimumHitsForTrack );
49 tbb::atomic<int> numberOfTracks;
50 tbb::atomic<int> numberOfHits;
57 std::stack<AliHLTTPCCATrack *> recycleBin;
61 const int fNTracklets = fTracker.NTracklets();
62 debugTS() <<
"run TrackletSelector on " << fNTracklets <<
" tracklets" << endl;
63 for (
int itr = 0; itr * short_v::Size < fNTracklets; ++itr ) {
64 const ushort_v trackIndexes = ushort_v( Vc::IndexesFromZero ) + itr * short_v::Size;
67 debugTS() <<
"process " << trackIndexes <<
"\n" << tracklet.Param() << endl;;
70 const ushort_v &tNHits = tracklet.NHits();
73 const ushort_m &valid = trackIndexes < fNTracklets && tNHits > 0;
75 const sfloat_v kMaximumSharedPerHits = 1.f / AliHLTTPCCAParameters::MinimumHitsPerShared;
77 const ushort_v &firstRow = tracklet.FirstRow();
78 const ushort_v &lastRow = tracklet.LastRow();
80 ushort_v tNHitsNew( Vc::Zero );
84 debugTS() <<
"tNHits: " << tNHits <<
", valid: " << valid <<
", firstRow: " << firstRow <<
", lastRow: " << lastRow <<
", weight: " << weight << endl;
86 Track *tracks[short_v::Size];
90 for ( ; !recycleBin.empty() && i < short_v::Size; ++i ) {
91 tracks[i] = recycleBin.top();
93 tracks[i]->fParam =
TrackParam( tracklet.Param(), i );
96 for ( ; i < short_v::Size; ++i ) {
97 tracks[i] =
new Track;
98 fTracks[++numberOfTracks] = tracks[i];
99 tracks[i]->fParam =
TrackParam( tracklet.Param(), i );
104 ushort_v gap( Vc::Zero );
105 ushort_v nShared( Vc::Zero );
106 const ushort_v &invalidMarker = std::numeric_limits<ushort_v>::max();
107 for (
int rowIndex = firstRow.min(); rowIndex <= lastRow.max(); ++rowIndex ) {
109 const ushort_v &hitIndexes = tracklet.HitIndexAtRow( rowIndex );
110 debugTS() << hitIndexes << invalidMarker << validHitIndexes( hitIndexes ) << endl;
111 const ushort_m &validHits = valid && validHitIndexes( hitIndexes );
113 const ushort_m own = fData.TakeOwnHits( fData.
Row( rowIndex ), hitIndexes, validHits, weight );
116 const ushort_m &sharedOK = nShared < static_cast<ushort_v>(
static_cast<sfloat_v
>( tNHitsNew ) * kMaximumSharedPerHits );
117 const ushort_m &outHit = validHits && ( own || sharedOK );
119 const ushort_m &invalidTrack = !( own || sharedOK );
121 if ( !invalidTrack.isEmpty() ) {
122 debugTS() <<
"invalidTrack at row " << rowIndex <<
": " << invalidTrack
124 <<
", sharedOK: " << sharedOK
126 debugTS() <<
"weight reference: " << fData.
HitWeight( fData.
Row( rowIndex ), hitIndexes, validHits ) << validHits << endl;
129 for (
int i = 0; i < short_v::Size; ++i ) {
131 assert( hitIndexes[i] < fData.
Row( rowIndex ).NHits() );
132 tracks[i]->fHitIdArray[tracks[i]->fNumberOfHits++].Set( rowIndex, hitIndexes[i] );
133 }
else if ( static_cast<int>(gap[i]) > static_cast<int>(AliHLTTPCCAParameters::MaximumRowGap) ) {
134 if ( tracks[i]->fNumberOfHits >= AliHLTTPCCAParameters::MinimumHitsForTrack ) {
135 numberOfHits += tracks[i]->fNumberOfHits;
136 tracks[i] =
new Track;
137 fTracks[++numberOfTracks] = tracks[i];
139 tracks[i]->fNumberOfHits = 0;
143 gap.setZero( outHit );
144 ++tNHitsNew( outHit );
145 tNHitsNew.setZero( gap > ushort_v(AliHLTTPCCAParameters::MaximumRowGap) );
146 ++nShared( !own && outHit );
149 for (
int i = 0; i < short_v::Size; ++i ) {
150 if ( tracks[i]->fNumberOfHits < ushort_v(AliHLTTPCCAParameters::MinimumHitsForTrack) ) {
151 tracks[i]->fNumberOfHits = 0;
153 recycleBin.push( tracks[i] );
156 numberOfHits += tracks[i]->fNumberOfHits;
162 fNumberOfHits = numberOfHits;
163 fTracks.resize( numberOfTracks + 1, 0 );
164 fNumberOfTracks = numberOfTracks + 1 - recycleBin.size();
ushort_v HitWeight(const AliHLTTPCCARow &row, const ushort_v &hitIndex, const ushort_m &mask) const
const AliHLTTPCCARow & Row(int rowIndex) const
static ushort_v CalculateHitWeight(ushort_v numberOfHits, ushort_v unique)