3 // ************************************************************************
4 // This file is property of and copyright by the ALICE HLT Project *
5 // ALICE Experiment at CERN, All rights reserved. *
6 // See cxx source for full Copyright notice *
8 //*************************************************************************
10 #ifndef ALIHLTTPCCATRACKER_H
11 #define ALIHLTTPCCATRACKER_H
14 #include "AliHLTTPCCADef.h"
15 #include "AliHLTTPCCAGPUConfig.h"
16 #include "AliHLTTPCCAParam.h"
18 #include "AliHLTTPCCAHitId.h"
19 #include "AliHLTTPCCASliceData.h"
20 #include "AliHLTTPCCASliceOutput.h"
21 #include "AliHLTTPCCATrackletConstructor.h"
22 #include "AliHLTTPCCATracklet.h"
24 class AliHLTTPCCATrack;
25 class AliHLTTPCCATrackParam;
26 class AliHLTTPCCAClusterData;
30 * @class AliHLTTPCCATracker
32 * Slice tracker for ALICE HLT.
33 * The class reconstructs tracks in one slice of TPC.
34 * The reconstruction algorithm is based on the Cellular Automaton method
36 * The CA tracker is designed stand-alone.
37 * It is integrated to the HLT framework via AliHLTTPCCATrackerComponent interface.
38 * The class is under construction.
42 class AliHLTTPCCAClusterData;
44 class AliHLTTPCCATracker
53 fIsGPUTracker( false ),
56 fRowStartHitCountOffset( NULL ),
57 fTrackletTmpStartHits( NULL ),
58 fGPUTrackletTemp( NULL ),
59 fRowBlockTracklets( NULL ),
61 fBlockStartingTracklet( NULL ),
62 fGPUParametersConst(),
67 fTrackletMemorySize( 0 ),
69 fTrackMemorySize( 0 ),
70 fTrackletStartHits( 0 ),
72 fTrackletRowHits( NULL ),
79 ~AliHLTTPCCATracker();
81 struct StructGPUParameters
83 StructGPUParameters() : fScheduleFirstDynamicTracklet( 0 ), fGPUError( 0 ) {}
84 int fScheduleFirstDynamicTracklet; //Last Tracklet with fixed position in sheduling
85 int fGPUError; //Signalizes error on GPU during GPU Reconstruction, kind of return value
88 struct StructGPUParametersConst
90 StructGPUParametersConst() : fGPUFixedBlockCount( 0 ), fGPUiSlice( 0 ), fGPUnSlices( 0 ) {}
91 int fGPUFixedBlockCount; //Count of blocks that is used for this tracker in fixed schedule situations
92 int fGPUiSlice; // slice number processed by running GPU MP
93 int fGPUnSlices; // n of slices to be processed in parallel
96 struct commonMemoryStruct
98 commonMemoryStruct() : fNTracklets( 0 ), fNTracks( 0 ), fNTrackHits( 0 ), fGPUParameters() {}
99 int fNTracklets; // number of tracklets
100 int fNTracks; // number of reconstructed tracks
101 int fNTrackHits; // number of track hits
102 StructGPUParameters fGPUParameters; // GPU parameters
105 void Initialize( const AliHLTTPCCAParam ¶m );
109 int CheckEmptySlice() const;
112 #if !defined(HLTCA_GPUCODE)
114 #endif //!HLTCA_GPUCODE
116 //Make Reconstruction steps directly callable (Used for GPU debugging)
117 void RunNeighboursFinder();
118 void RunNeighboursCleaner();
119 void RunStartHitsFinder();
120 void RunTrackletConstructor();
121 void RunTrackletSelector();
123 //GPU Tracker Interface
124 void SetGPUTracker();
125 void SetGPUDebugLevel(int Level, std::ostream *NewDebugOut = NULL) {fGPUDebugLevel = Level;if (NewDebugOut) fGPUDebugOut = NewDebugOut;}
127 char* SetGPUTrackerCommonMemory(char* const pGPUMemory);
128 char* SetGPUTrackerHitsMemory(char* pGPUMemory, int MaxNHits);
129 char* SetGPUTrackerTrackletsMemory(char* pGPUMemory, int MaxNTracklets);
130 char* SetGPUTrackerTracksMemory(char* pGPUMemory, int MaxNTracks, int MaxNHits );
133 void DumpSliceData(std::ostream &out); //Dump Input Slice Data
134 void DumpLinks(std::ostream &out); //Dump all links to file (for comparison after NeighboursFinder/Cleaner)
135 void DumpStartHits(std::ostream &out); //Same for Start Hits
136 void DumpHitWeights(std::ostream &out); //....
137 void DumpTrackHits(std::ostream &out); //Same for Track Hits
138 void DumpTrackletHits(std::ostream &out); //Same for Track Hits
140 GPUd() void GetErrors2( int iRow, const AliHLTTPCCATrackParam &t, float &Err2Y, float &Err2Z ) const;
141 GPUd() void GetErrors2( int iRow, float z, float sinPhi, float cosPhi, float DzDs, float &Err2Y, float &Err2Z ) const;
143 void FitTrack( const AliHLTTPCCATrack &track, float *t0 = 0 ) const;
144 void FitTrackFull( const AliHLTTPCCATrack &track, float *t0 = 0 ) const;
146 void SetupCommonMemory();
147 void SetPointersHits( int MaxNHits );
148 void SetPointersTracklets ( int MaxNTracklets );
149 void SetPointersTracks( int MaxNTracks, int MaxNHits );
150 size_t SetPointersSliceData(const AliHLTTPCCAClusterData *data, bool allocate = false) { return(fData.SetPointers(data, allocate)); }
152 void SetOutput( AliHLTTPCCASliceOutput** out ) { fOutput = out; }
154 void ReadEvent( AliHLTTPCCAClusterData *clusterData );
156 #if !defined(HLTCA_GPUCODE)
157 GPUh() void WriteEvent( std::ostream &out );
158 GPUh() void WriteTracks( std::ostream &out ) ;
159 GPUh() void ReadTracks( std::istream &in );
160 #endif //!HLTCA_GPUCODE
162 GPUhd() const AliHLTTPCCAParam &Param() const { return fParam; }
163 GPUhd() void SetParam( const AliHLTTPCCAParam &v ) { fParam = v; }
165 GPUhd() const AliHLTTPCCASliceOutput::outputControlStruct* OutputControl() const { return fOutputControl; }
166 GPUh() void SetOutputControl( AliHLTTPCCASliceOutput::outputControlStruct* const val) { fOutputControl = val; }
168 GPUhd() AliHLTTPCCAClusterData *ClusterData() const { return fClusterData; }
169 GPUhd() const AliHLTTPCCASliceData &Data() const { return fData; }
171 GPUh() void ClearSliceDataHitWeights() {fData.ClearHitWeights();}
173 GPUhd() const AliHLTTPCCARow &Row( int rowIndex ) const { return fData.Row( rowIndex ); }
174 GPUh() const AliHLTTPCCARow &Row( const AliHLTTPCCAHitId &HitId ) const { return fData.Row( HitId.RowIndex() ); }
176 GPUhd() double Timer( int i ) const { return fTimers[i]; }
177 GPUhd() void SetTimer( int i, double v ) { fTimers[i] = v; }
179 GPUhd() int NHitsTotal() const { return fData.NumberOfHits(); }
181 GPUd() void SetHitLinkUpData( const AliHLTTPCCARow &row, int hitIndex, short v ) { fData.SetHitLinkUpData( row, hitIndex, v ); }
182 GPUd() void SetHitLinkDownData( const AliHLTTPCCARow &row, int hitIndex, short v ) { fData.SetHitLinkDownData( row, hitIndex, v ); }
183 GPUd() short HitLinkUpData( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.HitLinkUpData( row, hitIndex ); }
184 GPUd() short HitLinkDownData( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.HitLinkDownData( row, hitIndex ); }
186 GPUd() const ushort2 *HitData( const AliHLTTPCCARow &row ) const { return fData.HitData(row); }
187 GPUd() const short_v *HitLinkUpData ( const AliHLTTPCCARow &row ) const { return fData.HitLinkUpData(row); }
188 GPUd() const short_v *HitLinkDownData( const AliHLTTPCCARow &row ) const { return fData.HitLinkDownData(row); }
189 GPUd() const ushort_v *FirstHitInBin( const AliHLTTPCCARow &row ) const { return fData.FirstHitInBin(row); }
191 GPUd() int FirstHitInBin( const AliHLTTPCCARow &row, int binIndex ) const { return fData.FirstHitInBin( row, binIndex ); }
193 GPUd() unsigned short HitDataY( const AliHLTTPCCARow &row, int hitIndex ) const {
194 return fData.HitDataY( row, hitIndex );
196 GPUd() unsigned short HitDataZ( const AliHLTTPCCARow &row, int hitIndex ) const {
197 return fData.HitDataZ( row, hitIndex );
199 GPUd() ushort2 HitData( const AliHLTTPCCARow &row, int hitIndex ) const {
200 return fData.HitData( row, hitIndex );
203 GPUhd() int HitInputID( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.ClusterDataIndex( row, hitIndex ); }
206 * The hit weight is used to determine whether a hit belongs to a certain tracklet or another one
207 * competing for the same hit. The tracklet that has a higher weight wins. Comparison is done
208 * using the the number of hits in the tracklet (the more hits it has the more it keeps). If
209 * tracklets have the same number of hits then it doesn't matter who gets it, but it should be
210 * only one. So a unique number (row index is good) is added in the least significant part of
213 static int CalculateHitWeight( int NHits, int unique ) {
214 return ( NHits << 16 ) + unique;
216 GPUd() void MaximizeHitWeight( const AliHLTTPCCARow &row, int hitIndex, int weight ) {
217 fData.MaximizeHitWeight( row, hitIndex, weight );
219 GPUd() int HitWeight( const AliHLTTPCCARow &row, int hitIndex ) const {
220 return fData.HitWeight( row, hitIndex );
223 GPUhd() int *NTracklets() const { return &fCommonMem->fNTracklets; }
225 GPUhd() const AliHLTTPCCAHitId &TrackletStartHit( int i ) const { return fTrackletStartHits[i]; }
226 GPUhd() AliHLTTPCCAHitId *TrackletStartHits() const { return fTrackletStartHits; }
227 GPUhd() AliHLTTPCCAHitId *TrackletTmpStartHits() const { return fTrackletTmpStartHits; }
228 GPUhd() const AliHLTTPCCATracklet &Tracklet( int i ) const { return fTracklets[i]; }
229 GPUhd() AliHLTTPCCATracklet *Tracklets() const { return fTracklets;}
230 GPUhd() int* TrackletRowHits() const { return fTrackletRowHits; }
232 GPUhd() int *NTracks() const { return &fCommonMem->fNTracks; }
233 GPUhd() AliHLTTPCCATrack *Tracks() const { return fTracks; }
234 GPUhd() int *NTrackHits() const { return &fCommonMem->fNTrackHits; }
235 GPUhd() AliHLTTPCCAHitId *TrackHits() const { return fTrackHits; }
237 GPUhd() AliHLTTPCCASliceOutput** Output() const { return fOutput; }
239 GPUh() commonMemoryStruct *CommonMemory() const {return(fCommonMem); }
240 GPUh() static size_t CommonMemorySize() { return(sizeof(AliHLTTPCCATracker::commonMemoryStruct)); }
241 GPUh() char* HitMemory() const {return(fHitMemory); }
242 GPUh() size_t HitMemorySize() const {return(fHitMemorySize); }
243 GPUh() char* TrackletMemory() {return(fTrackletMemory); }
244 GPUh() size_t TrackletMemorySize() const {return(fTrackletMemorySize); }
245 GPUh() char* TrackMemory() {return(fTrackMemory); }
246 GPUh() size_t TrackMemorySize() const {return(fTrackMemorySize); }
247 GPUhd() AliHLTTPCCARow* SliceDataRows() const {return(fData.Rows()); }
249 GPUhd() uint3* RowStartHitCountOffset() const {return(fRowStartHitCountOffset);}
250 GPUhd() AliHLTTPCCATrackletConstructor::AliHLTTPCCAGPUTempMemory* GPUTrackletTemp() const {return(fGPUTrackletTemp);}
251 GPUhd() int* RowBlockTracklets(int reverse, int iRowBlock) const {return(&fRowBlockTracklets[(reverse * ((fParam.NRows() / HLTCA_GPU_SCHED_ROW_STEP) + 1) + iRowBlock) * fCommonMem->fNTracklets]);}
252 GPUhd() int* RowBlockTracklets() const {return(fRowBlockTracklets);}
253 GPUhd() int4* RowBlockPos(int reverse, int iRowBlock) const {return(&fRowBlockPos[reverse * ((fParam.NRows() / HLTCA_GPU_SCHED_ROW_STEP) + 1) + iRowBlock]);}
254 GPUhd() int4* RowBlockPos() const {return(fRowBlockPos);}
255 GPUhd() uint2* BlockStartingTracklet() const {return(fBlockStartingTracklet);}
256 GPUhd() StructGPUParameters* GPUParameters() const {return(&fCommonMem->fGPUParameters);}
257 GPUhd() StructGPUParametersConst* GPUParametersConst() {return(&fGPUParametersConst);}
258 GPUhd() void SetGPUTextureBase(char* val) { fData.SetGPUTextureBase(val); }
259 GPUh() void SetGPUSliceDataMemory(void* const pSliceMemory, void* const pRowMemory) { fData.SetGPUSliceDataMemory(pSliceMemory, pRowMemory); }
261 GPUh() unsigned long long int* PerfTimer(unsigned int i) {return &fPerfTimers[i]; }
265 #ifdef HLTCA_GPU_TRACKLET_CONSTRUCTOR_DO_PROFILE
266 char* fStageAtSync; //Pointer to array storing current stage for every thread at every sync point
267 #endif //HLTCA_GPU_TRACKLET_CONSTRUCTOR_DO_PROFILE
269 AliHLTTPCCAParam fParam; // parameters
270 double fTimers[10]; // timers
271 unsigned long long int fPerfTimers[16]; // running CPU time for different parts of the algorithm
272 void StandalonePerfTime(int i);
274 AliHLTTPCCASliceOutput::outputControlStruct* fOutputControl; // output control
276 /** A pointer to the ClusterData object that the SliceData was created from. This can be used to
277 * merge clusters from inside the SliceTracker code and recreate the SliceData. */
278 AliHLTTPCCAClusterData *fClusterData; // ^
279 AliHLTTPCCASliceData fData; // The SliceData object. It is used to encapsulate the storage in memory from the access
281 bool fIsGPUTracker; // is it GPU tracker object
282 int fGPUDebugLevel; // debug level
283 std::ostream *fGPUDebugOut; // debug stream
286 uint3* fRowStartHitCountOffset; //Offset, length and new offset of start hits in row
287 AliHLTTPCCAHitId *fTrackletTmpStartHits; //Unsorted start hits
288 AliHLTTPCCATrackletConstructor::AliHLTTPCCAGPUTempMemory *fGPUTrackletTemp; //Temp Memory for GPU Tracklet Constructor
289 int* fRowBlockTracklets; //Reference which tracklet is processed in which rowblock next
290 int4* fRowBlockPos; //x is last tracklet to be processed, y is last tracklet already processed, z is last tracklet to be processed in next iteration, w is initial x value to check if tracklet must be initialized
291 uint2* fBlockStartingTracklet; // First Tracklet that is to be processed by current GPU MP
293 StructGPUParametersConst fGPUParametersConst; // Parameters for GPU if this is a GPU tracker
297 commonMemoryStruct *fCommonMem; // common event memory
299 char *fHitMemory; // event memory for hits
300 size_t fHitMemorySize; // size of the event memory for hits [bytes]
302 char *fTrackletMemory; //event memory for tracklets
303 size_t fTrackletMemorySize; //size of the event memory for tracklets
305 char *fTrackMemory; // event memory for tracks
306 size_t fTrackMemorySize; // size of the event memory for tracks [bytes]
308 AliHLTTPCCAHitId *fTrackletStartHits; // start hits for the tracklets
309 AliHLTTPCCATracklet *fTracklets; // tracklets
310 int *fTrackletRowHits; //Hits for each Tracklet in each row
313 AliHLTTPCCATrack *fTracks; // reconstructed tracks
314 AliHLTTPCCAHitId *fTrackHits; // array of track hit numbers
318 AliHLTTPCCASliceOutput **fOutput; //address of pointer pointing to SliceOutput Object
321 AliHLTTPCCATracker( const AliHLTTPCCATracker& );
322 AliHLTTPCCATracker &operator=( const AliHLTTPCCATracker& );
324 static int StarthitSortComparison(const void*a, const void* b);
328 #endif //ALIHLTTPCCATRACKER_H