StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AliHLTTPCCATrackletSelector.cxx
1 // @(#) $Id: AliHLTTPCCATrackletSelector.cxx,v 1.2 2016/07/15 14:43:33 fisyak Exp $
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 // Developed by: Igor Kulakov <I.Kulakov@gsi.de> *
11 // Maksym Zyzak <M.Zyzak@gsi.de> *
12 // *
13 // Permission to use, copy, modify and distribute this software and its *
14 // documentation strictly for non-commercial purposes is hereby granted *
15 // without fee, provided that the above copyright notice appears in all *
16 // copies and that both the copyright notice and this permission notice *
17 // appear in the supporting documentation. The authors make no claims *
18 // about the suitability of this software for any purpose. It is *
19 // provided "as is" without express or implied warranty. *
20 // *
21 //***************************************************************************
22 
23 
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"
31 #include <stack>
32 #undef USE_TBB
33 #ifdef USE_TBB
34 #include <tbb/atomic.h>
35 #endif //USE_TBB
36 
37 #include "debug.h"
38 
39 #ifdef MAIN_DRAW
40 #include "AliHLTTPCCADisplay.h"
41 #endif // DRAW
42 
43 using std::endl;
44 
45 void AliHLTTPCCATrackletSelector::run()
46 {
47  fTracks.resize( fTrackletVectors.Size() * ushort_v::Size * AliHLTTPCCAParameters::MaxNumberOfRows8 / AliHLTTPCCAParameters::MinimumHitsForTrack ); // should be less, the factor is for safety, since the tracks can be broken into pieces
48 #ifdef USE_TBB
49  tbb::atomic<int> numberOfTracks;
50  tbb::atomic<int> numberOfHits;
51 #else //USE_TBB
52  int numberOfTracks;
53  int numberOfHits;
54 #endif //USE_TBB
55 
56  numberOfTracks = -1;
57  std::stack<AliHLTTPCCATrack *> recycleBin;
58 
59  numberOfHits = 0;
60 
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;
65  // Tracklets that will be examined
66  const TrackletVector &tracklet = fTrackletVectors[itr];
67  debugTS() << "process " << trackIndexes << "\n" << tracklet.Param() << endl;;
68 
69  // the Tracklet says it contains so many hits
70  const ushort_v &tNHits = tracklet.NHits();
71 
72  // useless Tracklet...
73  const ushort_m &valid = trackIndexes < fNTracklets && tNHits > 0;
74 
75  const sfloat_v kMaximumSharedPerHits = 1.f / AliHLTTPCCAParameters::MinimumHitsPerShared;
76 
77  const ushort_v &firstRow = tracklet.FirstRow();
78  const ushort_v &lastRow = tracklet.LastRow();
79 
80  ushort_v tNHitsNew( Vc::Zero );
81 
82  const ushort_v &weight = SliceData::CalculateHitWeight( tNHits, trackIndexes );
83 
84  debugTS() << "tNHits: " << tNHits << ", valid: " << valid << ", firstRow: " << firstRow << ", lastRow: " << lastRow << ", weight: " << weight << endl;
85 
86  Track *tracks[short_v::Size];
87  {
88  int i = 0;
89  // XXX lock
90  for ( ; !recycleBin.empty() && i < short_v::Size; ++i ) {
91  tracks[i] = recycleBin.top();
92  recycleBin.pop();
93  tracks[i]->fParam = TrackParam( tracklet.Param(), i );
94  }
95  // XXX unlock
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 );
100  }
101  }
102 
103  //const int nRows = fTracker.Param().NRows(); // number of rows (Tracker global)
104  ushort_v gap( Vc::Zero ); // count how many rows are missing a hit
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 ) {
108  ++gap;
109  const ushort_v &hitIndexes = tracklet.HitIndexAtRow( rowIndex ); // hit index for the current row
110  debugTS() << hitIndexes << invalidMarker << validHitIndexes( hitIndexes ) << endl;
111  const ushort_m &validHits = valid && validHitIndexes( hitIndexes );
112  //cerr << rowIndex << hitIndexes << weight << fData.HitWeight( fData.Row( rowIndex ), hitIndexes, validHits ) << endl;
113  const ushort_m own = fData.TakeOwnHits( fData.Row( rowIndex ), hitIndexes, validHits, weight );
114  //cerr << own << fData.HitWeight( fData.Row( rowIndex ), hitIndexes, validHits ) << endl;
115  //const ushort_m &own = fData.HitWeight( 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 );
118 #ifndef NODEBUG
119  const ushort_m &invalidTrack = !( own || sharedOK );
120 // std::cout << invalidTrack << " "<< outHit <<" "<<firstRow.min()<<" "<<lastRow.max()<<" "<< firstRow<<" "<<lastRow<<std::endl;
121  if ( !invalidTrack.isEmpty() ) {
122  debugTS() << "invalidTrack at row " << rowIndex << ": " << invalidTrack
123  << ", own: " << own
124  << ", sharedOK: " << sharedOK
125  << endl;
126  debugTS() << "weight reference: " << fData.HitWeight( fData.Row( rowIndex ), hitIndexes, validHits ) << validHits << endl;
127  }
128 #endif
129  for ( int i = 0; i < short_v::Size; ++i ) {
130  if ( outHit[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];
138  } else {
139  tracks[i]->fNumberOfHits = 0;
140  }
141  }
142  }
143  gap.setZero( outHit );
144  ++tNHitsNew( outHit );
145  tNHitsNew.setZero( gap > ushort_v(AliHLTTPCCAParameters::MaximumRowGap) );
146  ++nShared( !own && outHit );
147  }
148 
149  for ( int i = 0; i < short_v::Size; ++i ) {
150  if ( tracks[i]->fNumberOfHits < ushort_v(AliHLTTPCCAParameters::MinimumHitsForTrack) ) {
151  tracks[i]->fNumberOfHits = 0;
152  // XXX lock
153  recycleBin.push( tracks[i] );
154  // XXX unlock
155  } else {
156  numberOfHits += tracks[i]->fNumberOfHits;
157  }
158  }
159 
160  //debugTS() << "NTracks: " << fTracker.NTracks() << ", NTrackHits: " << fTracker.NTrackHits() << endl;
161  }
162  fNumberOfHits = numberOfHits;
163  fTracks.resize( numberOfTracks + 1, 0 );
164  fNumberOfTracks = numberOfTracks + 1 - recycleBin.size();
165 }
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)
C++ STL includes.
Definition: AgUStep.h:47