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"
17 #include "AliHLTTPCCARow.h"
18 #include "AliHLTTPCCAHit.h"
20 #include "AliHLTArray.h"
21 #include "AliHLTTPCCAHitId.h"
22 #include "AliHLTTPCCASliceData.h"
23 #include "AliHLTTPCCATracklet.h"
24 #include "AliHLTTPCCAOutTrack.h"
25 #include "AliHLTTPCCASliceOutput.h"
26 #include "AliHLTTPCCATrackletConstructor.h"
28 class AliHLTTPCCATrack;
29 class AliHLTTPCCATrackParam;
30 class AliHLTTPCCAClusterData;
33 * @class AliHLTTPCCATracker
35 * Slice tracker for ALICE HLT.
36 * The class reconstructs tracks in one slice of TPC.
37 * The reconstruction algorithm is based on the Cellular Automaton method
39 * The CA tracker is designed stand-alone.
40 * It is integrated to the HLT framework via AliHLTTPCCATrackerComponent interface.
41 * The class is under construction.
45 class AliHLTTPCCAClusterData;
47 class AliHLTTPCCATracker
55 fIsGPUTracker( false ),
58 fRowStartHitCountOffset( NULL ),
59 fTrackletTmpStartHits( NULL ),
60 fGPUTrackletTemp( NULL ),
61 fRowBlockTracklets( NULL ),
63 fBlockStartingTracklet( NULL ),
64 fGPUParametersConst(),
69 fTrackletMemorySize( 0 ),
71 fTrackMemorySize( 0 ),
72 fTrackletStartHits( 0 ),
74 fTrackletRowHits( NULL ),
81 ~AliHLTTPCCATracker();
83 struct StructGPUParameters
85 int fScheduleFirstDynamicTracklet; //Last Tracklet with fixed position in sheduling
86 int fGPUError; //Signalizes error on GPU during GPU Reconstruction, kind of return value
89 struct StructGPUParametersConst
91 int fGPUFixedBlockCount; //Count of blocks that is used for this tracker in fixed schedule situations
96 struct commonMemoryStruct
98 int fNTracklets; // number of tracklets
99 int fNTracks; // number of reconstructed tracks
100 int fNTrackHits; // number of track hits
101 StructGPUParameters fGPUParameters;
104 void Initialize( const AliHLTTPCCAParam ¶m );
108 int CheckEmptySlice();
111 #if !defined(HLTCA_GPUCODE)
115 //Make Reconstruction steps directly callable (Used for GPU debugging)
116 void RunNeighboursFinder();
117 void RunNeighboursCleaner();
118 void RunStartHitsFinder();
119 void RunTrackletConstructor();
120 void RunTrackletSelector();
122 //GPU Tracker Interface
123 void SetGPUTracker();
124 void SetGPUDebugLevel(int Level, std::ostream *NewDebugOut = NULL) {fGPUDebugLevel = Level;if (NewDebugOut) fGPUDebugOut = NewDebugOut;}
126 char* SetGPUTrackerCommonMemory(char* pGPUMemory);
127 char* SetGPUTrackerHitsMemory(char* pGPUMemory, int MaxNHits);
128 char* SetGPUTrackerTrackletsMemory(char* pGPUMemory, int MaxNTracklets);
129 char* SetGPUTrackerTracksMemory(char* pGPUMemory, int MaxNTracks, int MaxNHits );
132 void DumpSliceData(std::ostream &out); //Dump Input Slice Data
133 void DumpLinks(std::ostream &out); //Dump all links to file (for comparison after NeighboursFinder/Cleaner)
134 void DumpStartHits(std::ostream &out); //Same for Start Hits
135 void DumpHitWeights(std::ostream &out); //....
136 void DumpTrackHits(std::ostream &out); //Same for Track Hits
137 void DumpTrackletHits(std::ostream &out); //Same for Track Hits
139 GPUd() void GetErrors2( int iRow, const AliHLTTPCCATrackParam &t, float &Err2Y, float &Err2Z ) const;
140 GPUd() void GetErrors2( int iRow, float z, float sinPhi, float cosPhi, float DzDs, float &Err2Y, float &Err2Z ) const;
142 void FitTrack( const AliHLTTPCCATrack &track, float *t0 = 0 ) const;
143 void FitTrackFull( const AliHLTTPCCATrack &track, float *t0 = 0 ) const;
145 void SetupCommonMemory();
146 void SetPointersHits( int MaxNHits );
147 void SetPointersTracklets ( int MaxNTracklets );
148 void SetPointersTracks( int MaxNTracks, int MaxNHits );
150 void SetOutput( AliHLTTPCCASliceOutput* out ) { fOutput = out; }
152 void ReadEvent( AliHLTTPCCAClusterData *clusterData );
154 #if !defined(HLTCA_GPUCODE)
155 GPUh() void WriteEvent( std::ostream &out );
156 GPUh() void WriteTracks( std::ostream &out ) ;
157 GPUh() void ReadTracks( std::istream &in );
160 GPUhd() const AliHLTTPCCAParam &Param() const { return fParam; }
161 GPUhd() void SetParam( const AliHLTTPCCAParam &v ) { fParam = v; }
163 GPUhd() AliHLTTPCCAClusterData *ClusterData() const { return fClusterData; }
164 GPUhd() const AliHLTTPCCASliceData &Data() const { return fData; }
165 GPUhd() AliHLTTPCCASliceData *pData() {return &fData; }
167 GPUh() void ClearSliceDataHitWeights() {fData.ClearHitWeights();}
169 GPUhd() const AliHLTTPCCARow &Row( int rowIndex ) const { return fData.Row( rowIndex ); }
170 GPUh() const AliHLTTPCCARow &Row( const AliHLTTPCCAHitId &HitId ) const { return fData.Row( HitId.RowIndex() ); }
172 GPUhd() double Timer( int i ) const { return fTimers[i]; }
173 GPUhd() void SetTimer( int i, double v ) { fTimers[i] = v; }
175 GPUhd() int NHitsTotal() const { return fData.NumberOfHits(); }
177 GPUd() void SetHitLinkUpData( const AliHLTTPCCARow &row, int hitIndex, short v ) { fData.SetHitLinkUpData( row, hitIndex, v ); }
178 GPUd() void SetHitLinkDownData( const AliHLTTPCCARow &row, int hitIndex, short v ) { fData.SetHitLinkDownData( row, hitIndex, v ); }
179 GPUd() short HitLinkUpData( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.HitLinkUpData( row, hitIndex ); }
180 GPUd() short HitLinkDownData( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.HitLinkDownData( row, hitIndex ); }
182 GPUd() const ushort2 *HitData( const AliHLTTPCCARow &row ) const { return fData.HitData(row); }
183 GPUd() const short_v *HitLinkUpData ( const AliHLTTPCCARow &row ) const { return fData.HitLinkUpData(row); }
184 GPUd() const short_v *HitLinkDownData( const AliHLTTPCCARow &row ) const { return fData.HitLinkDownData(row); }
185 GPUd() const ushort_v *FirstHitInBin( const AliHLTTPCCARow &row ) const { return fData.FirstHitInBin(row); }
187 GPUd() int FirstHitInBin( const AliHLTTPCCARow &row, int binIndex ) const { return fData.FirstHitInBin( row, binIndex ); }
189 GPUd() unsigned short HitDataY( const AliHLTTPCCARow &row, int hitIndex ) const {
190 return fData.HitDataY( row, hitIndex );
192 GPUd() unsigned short HitDataZ( const AliHLTTPCCARow &row, int hitIndex ) const {
193 return fData.HitDataZ( row, hitIndex );
195 GPUd() ushort2 HitData( const AliHLTTPCCARow &row, int hitIndex ) const {
196 return fData.HitData( row, hitIndex );
199 GPUhd() int HitInputID( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.ClusterDataIndex( row, hitIndex ); }
202 * The hit weight is used to determine whether a hit belongs to a certain tracklet or another one
203 * competing for the same hit. The tracklet that has a higher weight wins. Comparison is done
204 * using the the number of hits in the tracklet (the more hits it has the more it keeps). If
205 * tracklets have the same number of hits then it doesn't matter who gets it, but it should be
206 * only one. So a unique number (row index is good) is added in the least significant part of
209 static int CalculateHitWeight( int NHits, int unique ) {
210 return ( NHits << 16 ) + unique;
212 GPUd() void MaximizeHitWeight( const AliHLTTPCCARow &row, int hitIndex, int weight ) {
213 fData.MaximizeHitWeight( row, hitIndex, weight );
215 GPUd() int HitWeight( const AliHLTTPCCARow &row, int hitIndex ) const {
216 return fData.HitWeight( row, hitIndex );
219 GPUhd() int NTracklets() const { return fCommonMem->fNTracklets; }
220 GPUhd() int *NTracklets() { return &fCommonMem->fNTracklets; }
222 GPUhd() const AliHLTTPCCAHitId &TrackletStartHit( int i ) const { return fTrackletStartHits[i]; }
223 GPUhd() AliHLTTPCCAHitId *TrackletStartHits() const { return fTrackletStartHits; }
224 GPUhd() AliHLTTPCCAHitId *TrackletTmpStartHits() const { return fTrackletTmpStartHits; }
225 GPUhd() const AliHLTTPCCATracklet &Tracklet( int i ) const { return fTracklets[i]; }
226 GPUhd() AliHLTTPCCATracklet *Tracklets() const { return fTracklets;}
227 GPUhd() int* TrackletRowHits() { return fTrackletRowHits; }
229 GPUhd() int *NTracks() const { return &fCommonMem->fNTracks; }
230 GPUhd() AliHLTTPCCATrack *Tracks() const { return fTracks; }
231 GPUhd() int *NTrackHits() const { return &fCommonMem->fNTrackHits; }
232 GPUhd() AliHLTTPCCAHitId *TrackHits() const { return fTrackHits; }
234 GPUhd() AliHLTTPCCASliceOutput * Output() const { return fOutput; }
236 GPUh() commonMemoryStruct *CommonMemory() {return(fCommonMem); }
237 static GPUh() size_t CommonMemorySize() { return(sizeof(AliHLTTPCCATracker::commonMemoryStruct)); }
238 GPUh() char* &HitMemory() {return(fHitMemory); }
239 GPUh() size_t HitMemorySize() const {return(fHitMemorySize); }
240 GPUh() char* &TrackletMemory() {return(fTrackletMemory); }
241 GPUh() size_t TrackletMemorySize() const {return(fTrackletMemorySize); }
242 GPUh() char* &TrackMemory() {return(fTrackMemory); }
243 GPUh() size_t TrackMemorySize() const {return(fTrackMemorySize); }
244 GPUh() char* OutputMemory() const {return(fOutput->Memory()); }
245 GPUh() size_t OutputMemorySize() const {return(fOutput->MemorySize()); }
246 GPUhd() AliHLTTPCCARow* SliceDataRows() {return(fData.Rows()); }
248 GPUhd() uint3* RowStartHitCountOffset() const {return(fRowStartHitCountOffset);}
249 GPUhd() AliHLTTPCCATrackletConstructor::AliHLTTPCCAGPUTempMemory* GPUTrackletTemp() const {return(fGPUTrackletTemp);}
250 GPUhd() int* RowBlockTracklets(int reverse, int iRowBlock) const {return(&fRowBlockTracklets[(reverse * ((fParam.NRows() / HLTCA_GPU_SCHED_ROW_STEP) + 1) + iRowBlock) * fCommonMem->fNTracklets]);}
251 GPUhd() int* RowBlockTracklets() const {return(fRowBlockTracklets);}
252 GPUhd() int4* RowBlockPos(int reverse, int iRowBlock) const {return(&fRowBlockPos[reverse * ((fParam.NRows() / HLTCA_GPU_SCHED_ROW_STEP) + 1) + iRowBlock]);}
253 GPUhd() int4* RowBlockPos() const {return(fRowBlockPos);}
254 GPUhd() uint2* BlockStartingTracklet() const {return(fBlockStartingTracklet);}
255 GPUhd() StructGPUParameters* GPUParameters() const {return(&fCommonMem->fGPUParameters);}
256 GPUhd() StructGPUParametersConst* GPUParametersConst() {return(&fGPUParametersConst);}
258 GPUh() unsigned long long int* PerfTimer(unsigned int i) {return &fPerfTimers[i]; }
260 #ifdef HLTCA_GPU_TRACKLET_CONSTRUCTOR_DO_PROFILE
261 char* fStageAtSync; //Pointer to array storing current stage for every thread at every sync point
266 AliHLTTPCCAParam fParam; // parameters
268 unsigned long long int fPerfTimers[16]; // running CPU time for different parts of the algorithm
269 void StandalonePerfTime(int i);
271 /** A pointer to the ClusterData object that the SliceData was created from. This can be used to
272 * merge clusters from inside the SliceTracker code and recreate the SliceData. */
273 AliHLTTPCCAClusterData *fClusterData; // ^
274 AliHLTTPCCASliceData fData; // The SliceData object. It is used to encapsulate the storage in memory from the access
276 bool fIsGPUTracker; // is it GPU tracker object
277 int fGPUDebugLevel; // debug level
278 std::ostream *fGPUDebugOut; // debug stream
281 uint3* fRowStartHitCountOffset; //Offset, length and new offset of start hits in row
282 AliHLTTPCCAHitId *fTrackletTmpStartHits; //Unsorted start hits
283 AliHLTTPCCATrackletConstructor::AliHLTTPCCAGPUTempMemory *fGPUTrackletTemp; //Temp Memory for GPU Tracklet Constructor
284 int* fRowBlockTracklets; //Reference which tracklet is processed in which rowblock next
285 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
286 uint2* fBlockStartingTracklet;
288 StructGPUParametersConst fGPUParametersConst;
292 commonMemoryStruct *fCommonMem; // common event memory
294 char *fHitMemory; // event memory for hits
295 size_t fHitMemorySize; // size of the event memory [bytes]
297 char *fTrackletMemory;
298 size_t fTrackletMemorySize;
300 char *fTrackMemory; // event memory for tracks
301 size_t fTrackMemorySize; // size of the event memory [bytes]
303 AliHLTTPCCAHitId *fTrackletStartHits; // start hits for the tracklets
304 AliHLTTPCCATracklet *fTracklets; // tracklets
305 int *fTrackletRowHits;
308 AliHLTTPCCATrack *fTracks; // reconstructed tracks
309 AliHLTTPCCAHitId *fTrackHits; // array of track hit numbers
313 AliHLTTPCCASliceOutput *fOutput;
316 AliHLTTPCCATracker( const AliHLTTPCCATracker& );
317 AliHLTTPCCATracker &operator=( const AliHLTTPCCATracker& );
319 static int starthitSortComparison(const void*a, const void* b);