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
50 #ifdef HLTCA_STANDALONE
52 fLinkTmpMemory( NULL ),
58 fIsGPUTracker( false ),
61 fRowStartHitCountOffset( NULL ),
62 fTrackletTmpStartHits( NULL ),
63 fGPUTrackletTemp( NULL ),
64 fRowBlockTracklets( NULL ),
66 fBlockStartingTracklet( NULL ),
67 fGPUParametersConst(),
72 fTrackletMemorySize( 0 ),
74 fTrackMemorySize( 0 ),
75 fTrackletStartHits( 0 ),
77 fTrackletRowHits( NULL ),
84 ~AliHLTTPCCATracker();
86 struct StructGPUParameters
88 StructGPUParameters() : fScheduleFirstDynamicTracklet( 0 ), fGPUError( 0 ) {}
89 int fScheduleFirstDynamicTracklet; //Last Tracklet with fixed position in sheduling
90 int fGPUError; //Signalizes error on GPU during GPU Reconstruction, kind of return value
93 struct StructGPUParametersConst
95 StructGPUParametersConst() : fGPUFixedBlockCount( 0 ), fGPUiSlice( 0 ), fGPUnSlices( 0 ) {}
96 int fGPUFixedBlockCount; //Count of blocks that is used for this tracker in fixed schedule situations
97 int fGPUiSlice; // slice number processed by running GPU MP
98 int fGPUnSlices; // n of slices to be processed in parallel
101 struct commonMemoryStruct
103 commonMemoryStruct() : fNTracklets( 0 ), fNTracks( 0 ), fNTrackHits( 0 ), fGPUParameters() {}
104 int fNTracklets; // number of tracklets
105 int fNTracks; // number of reconstructed tracks
106 int fNTrackHits; // number of track hits
107 StructGPUParameters fGPUParameters; // GPU parameters
110 void Initialize( const AliHLTTPCCAParam ¶m );
114 int CheckEmptySlice() const;
117 #if !defined(HLTCA_GPUCODE)
119 #endif //!HLTCA_GPUCODE
121 //Make Reconstruction steps directly callable (Used for GPU debugging)
122 void RunNeighboursFinder();
123 void RunNeighboursCleaner();
124 void RunStartHitsFinder();
125 void RunTrackletConstructor();
126 void RunTrackletSelector();
128 //GPU Tracker Interface
129 void SetGPUTracker();
130 void SetGPUDebugLevel(int Level, std::ostream *NewDebugOut = NULL) {fGPUDebugLevel = Level;if (NewDebugOut) fGPUDebugOut = NewDebugOut;}
132 char* SetGPUTrackerCommonMemory(char* const pGPUMemory);
133 char* SetGPUTrackerHitsMemory(char* pGPUMemory, int MaxNHits);
134 char* SetGPUTrackerTrackletsMemory(char* pGPUMemory, int MaxNTracklets);
135 char* SetGPUTrackerTracksMemory(char* pGPUMemory, int MaxNTracks, int MaxNHits );
138 void DumpSliceData(std::ostream &out); //Dump Input Slice Data
139 void DumpLinks(std::ostream &out); //Dump all links to file (for comparison after NeighboursFinder/Cleaner)
140 void DumpStartHits(std::ostream &out); //Same for Start Hits
141 void DumpHitWeights(std::ostream &out); //....
142 void DumpTrackHits(std::ostream &out); //Same for Track Hits
143 void DumpTrackletHits(std::ostream &out); //Same for Track Hits
145 GPUd() void GetErrors2( int iRow, const AliHLTTPCCATrackParam &t, float &Err2Y, float &Err2Z ) const;
146 GPUd() void GetErrors2( int iRow, float z, float sinPhi, float cosPhi, float DzDs, float &Err2Y, float &Err2Z ) const;
148 void FitTrack( const AliHLTTPCCATrack &track, float *t0 = 0 ) const;
149 void FitTrackFull( const AliHLTTPCCATrack &track, float *t0 = 0 ) const;
151 void SetupCommonMemory();
152 void SetPointersHits( int MaxNHits );
153 void SetPointersTracklets ( int MaxNTracklets );
154 void SetPointersTracks( int MaxNTracks, int MaxNHits );
155 size_t SetPointersSliceData(const AliHLTTPCCAClusterData *data, bool allocate = false) { return(fData.SetPointers(data, allocate)); }
157 void SetOutput( AliHLTTPCCASliceOutput** out ) { fOutput = out; }
159 void ReadEvent( AliHLTTPCCAClusterData *clusterData );
161 #if !defined(HLTCA_GPUCODE)
162 GPUh() void WriteEvent( std::ostream &out );
163 GPUh() void WriteTracks( std::ostream &out ) ;
164 GPUh() void ReadTracks( std::istream &in );
165 #endif //!HLTCA_GPUCODE
167 GPUhd() const AliHLTTPCCAParam &Param() const { return fParam; }
168 GPUhd() void SetParam( const AliHLTTPCCAParam &v ) { fParam = v; }
170 GPUhd() const AliHLTTPCCASliceOutput::outputControlStruct* OutputControl() const { return fOutputControl; }
171 GPUh() void SetOutputControl( AliHLTTPCCASliceOutput::outputControlStruct* const val) { fOutputControl = val; }
173 GPUhd() AliHLTTPCCAClusterData *ClusterData() const { return fClusterData; }
174 GPUhd() const AliHLTTPCCASliceData &Data() const { return fData; }
176 GPUh() void ClearSliceDataHitWeights() {fData.ClearHitWeights();}
178 GPUhd() const AliHLTTPCCARow &Row( int rowIndex ) const { return fData.Row( rowIndex ); }
179 GPUh() const AliHLTTPCCARow &Row( const AliHLTTPCCAHitId &HitId ) const { return fData.Row( HitId.RowIndex() ); }
181 GPUhd() double Timer( int i ) const { return fTimers[i]; }
182 GPUhd() void SetTimer( int i, double v ) { fTimers[i] = v; }
184 GPUhd() int NHitsTotal() const { return fData.NumberOfHits(); }
186 GPUd() void SetHitLinkUpData( const AliHLTTPCCARow &row, int hitIndex, short v ) { fData.SetHitLinkUpData( row, hitIndex, v ); }
187 GPUd() void SetHitLinkDownData( const AliHLTTPCCARow &row, int hitIndex, short v ) { fData.SetHitLinkDownData( row, hitIndex, v ); }
188 GPUd() short HitLinkUpData( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.HitLinkUpData( row, hitIndex ); }
189 GPUd() short HitLinkDownData( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.HitLinkDownData( row, hitIndex ); }
191 GPUd() const ushort2 *HitData( const AliHLTTPCCARow &row ) const { return fData.HitData(row); }
192 GPUd() const short_v *HitLinkUpData ( const AliHLTTPCCARow &row ) const { return fData.HitLinkUpData(row); }
193 GPUd() const short_v *HitLinkDownData( const AliHLTTPCCARow &row ) const { return fData.HitLinkDownData(row); }
194 GPUd() const ushort_v *FirstHitInBin( const AliHLTTPCCARow &row ) const { return fData.FirstHitInBin(row); }
196 GPUd() int FirstHitInBin( const AliHLTTPCCARow &row, int binIndex ) const { return fData.FirstHitInBin( row, binIndex ); }
198 GPUd() unsigned short HitDataY( const AliHLTTPCCARow &row, int hitIndex ) const {
199 return fData.HitDataY( row, hitIndex );
201 GPUd() unsigned short HitDataZ( const AliHLTTPCCARow &row, int hitIndex ) const {
202 return fData.HitDataZ( row, hitIndex );
204 GPUd() ushort2 HitData( const AliHLTTPCCARow &row, int hitIndex ) const {
205 return fData.HitData( row, hitIndex );
208 GPUhd() int HitInputID( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.ClusterDataIndex( row, hitIndex ); }
211 * The hit weight is used to determine whether a hit belongs to a certain tracklet or another one
212 * competing for the same hit. The tracklet that has a higher weight wins. Comparison is done
213 * using the the number of hits in the tracklet (the more hits it has the more it keeps). If
214 * tracklets have the same number of hits then it doesn't matter who gets it, but it should be
215 * only one. So a unique number (row index is good) is added in the least significant part of
218 static int CalculateHitWeight( int NHits, int unique ) {
219 return ( NHits << 16 ) + unique;
221 GPUd() void MaximizeHitWeight( const AliHLTTPCCARow &row, int hitIndex, int weight ) {
222 fData.MaximizeHitWeight( row, hitIndex, weight );
224 GPUd() int HitWeight( const AliHLTTPCCARow &row, int hitIndex ) const {
225 return fData.HitWeight( row, hitIndex );
228 GPUhd() int *NTracklets() const { return &fCommonMem->fNTracklets; }
230 GPUhd() const AliHLTTPCCAHitId &TrackletStartHit( int i ) const { return fTrackletStartHits[i]; }
231 GPUhd() AliHLTTPCCAHitId *TrackletStartHits() const { return fTrackletStartHits; }
232 GPUhd() AliHLTTPCCAHitId *TrackletTmpStartHits() const { return fTrackletTmpStartHits; }
233 GPUhd() const AliHLTTPCCATracklet &Tracklet( int i ) const { return fTracklets[i]; }
234 GPUhd() AliHLTTPCCATracklet *Tracklets() const { return fTracklets;}
235 GPUhd() int* TrackletRowHits() const { return fTrackletRowHits; }
237 GPUhd() int *NTracks() const { return &fCommonMem->fNTracks; }
238 GPUhd() AliHLTTPCCATrack *Tracks() const { return fTracks; }
239 GPUhd() int *NTrackHits() const { return &fCommonMem->fNTrackHits; }
240 GPUhd() AliHLTTPCCAHitId *TrackHits() const { return fTrackHits; }
242 GPUhd() AliHLTTPCCASliceOutput** Output() const { return fOutput; }
244 GPUh() commonMemoryStruct *CommonMemory() const {return(fCommonMem); }
245 GPUh() static size_t CommonMemorySize() { return(sizeof(AliHLTTPCCATracker::commonMemoryStruct)); }
246 GPUh() char* HitMemory() const {return(fHitMemory); }
247 GPUh() size_t HitMemorySize() const {return(fHitMemorySize); }
248 GPUh() char* TrackletMemory() {return(fTrackletMemory); }
249 GPUh() size_t TrackletMemorySize() const {return(fTrackletMemorySize); }
250 GPUh() char* TrackMemory() {return(fTrackMemory); }
251 GPUh() size_t TrackMemorySize() const {return(fTrackMemorySize); }
252 GPUhd() AliHLTTPCCARow* SliceDataRows() const {return(fData.Rows()); }
254 GPUhd() uint3* RowStartHitCountOffset() const {return(fRowStartHitCountOffset);}
255 GPUhd() AliHLTTPCCATrackletConstructor::AliHLTTPCCAGPUTempMemory* GPUTrackletTemp() const {return(fGPUTrackletTemp);}
256 GPUhd() int* RowBlockTracklets(int reverse, int iRowBlock) const {return(&fRowBlockTracklets[(reverse * ((fParam.NRows() / HLTCA_GPU_SCHED_ROW_STEP) + 1) + iRowBlock) * fCommonMem->fNTracklets]);}
257 GPUhd() int* RowBlockTracklets() const {return(fRowBlockTracklets);}
258 GPUhd() int4* RowBlockPos(int reverse, int iRowBlock) const {return(&fRowBlockPos[reverse * ((fParam.NRows() / HLTCA_GPU_SCHED_ROW_STEP) + 1) + iRowBlock]);}
259 GPUhd() int4* RowBlockPos() const {return(fRowBlockPos);}
260 GPUhd() uint2* BlockStartingTracklet() const {return(fBlockStartingTracklet);}
261 GPUhd() StructGPUParameters* GPUParameters() const {return(&fCommonMem->fGPUParameters);}
262 GPUhd() StructGPUParametersConst* GPUParametersConst() {return(&fGPUParametersConst);}
263 GPUhd() void SetGPUTextureBase(char* val) { fData.SetGPUTextureBase(val); }
264 GPUh() void SetGPUSliceDataMemory(void* const pSliceMemory, void* const pRowMemory) { fData.SetGPUSliceDataMemory(pSliceMemory, pRowMemory); }
266 GPUh() unsigned long long int* PerfTimer(unsigned int i) {return &fPerfTimers[i]; }
268 #ifdef HLTCA_STANDALONE
269 GPUhd() char* StageAtSync() {return(fStageAtSync);}
270 GPUh() const char* LinkTmpMemory() const {return(fLinkTmpMemory);}
274 //Temporary Variables for Standalone measurements
275 #ifdef HLTCA_STANDALONE
276 char* fStageAtSync; //Pointer to array storing current stage for every thread at every sync point
277 char *fLinkTmpMemory; //tmp memory for hits after neighbours finder
280 AliHLTTPCCAParam fParam; // parameters
281 double fTimers[10]; // timers
282 unsigned long long int fPerfTimers[16]; // running CPU time for different parts of the algorithm
283 void StandalonePerfTime(int i);
285 AliHLTTPCCASliceOutput::outputControlStruct* fOutputControl; // output control
287 /** A pointer to the ClusterData object that the SliceData was created from. This can be used to
288 * merge clusters from inside the SliceTracker code and recreate the SliceData. */
289 AliHLTTPCCAClusterData *fClusterData; // ^
290 AliHLTTPCCASliceData fData; // The SliceData object. It is used to encapsulate the storage in memory from the access
292 bool fIsGPUTracker; // is it GPU tracker object
293 int fGPUDebugLevel; // debug level
294 std::ostream *fGPUDebugOut; // debug stream
297 uint3* fRowStartHitCountOffset; //Offset, length and new offset of start hits in row
298 AliHLTTPCCAHitId *fTrackletTmpStartHits; //Unsorted start hits
299 AliHLTTPCCATrackletConstructor::AliHLTTPCCAGPUTempMemory *fGPUTrackletTemp; //Temp Memory for GPU Tracklet Constructor
300 int* fRowBlockTracklets; //Reference which tracklet is processed in which rowblock next
301 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
302 uint2* fBlockStartingTracklet; // First Tracklet that is to be processed by current GPU MP
304 StructGPUParametersConst fGPUParametersConst; // Parameters for GPU if this is a GPU tracker
308 commonMemoryStruct *fCommonMem; // common event memory
310 char *fHitMemory; // event memory for hits
311 size_t fHitMemorySize; // size of the event memory for hits [bytes]
313 char *fTrackletMemory; //event memory for tracklets
314 size_t fTrackletMemorySize; //size of the event memory for tracklets
316 char *fTrackMemory; // event memory for tracks
317 size_t fTrackMemorySize; // size of the event memory for tracks [bytes]
319 AliHLTTPCCAHitId *fTrackletStartHits; // start hits for the tracklets
320 AliHLTTPCCATracklet *fTracklets; // tracklets
321 int *fTrackletRowHits; //Hits for each Tracklet in each row
324 AliHLTTPCCATrack *fTracks; // reconstructed tracks
325 AliHLTTPCCAHitId *fTrackHits; // array of track hit numbers
329 AliHLTTPCCASliceOutput **fOutput; //address of pointer pointing to SliceOutput Object
332 AliHLTTPCCATracker( const AliHLTTPCCATracker& );
333 AliHLTTPCCATracker &operator=( const AliHLTTPCCATracker& );
335 static int StarthitSortComparison(const void*a, const void* b);
339 #endif //ALIHLTTPCCATRACKER_H