]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.cxx
Obsolete tracker output removed
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCATracker.cxx
CommitLineData
326c2d4b 1// @(#) $Id$
ce565086 2// **************************************************************************
fbb9b71b 3// This file is property of and copyright by the ALICE HLT Project *
d54804bf 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// Permission to use, copy, modify and distribute this software and its *
11// documentation strictly for non-commercial purposes is hereby granted *
12// without fee, provided that the above copyright notice appears in all *
13// copies and that both the copyright notice and this permission notice *
14// appear in the supporting documentation. The authors make no claims *
15// about the suitability of this software for any purpose. It is *
16// provided "as is" without express or implied warranty. *
ce565086 17// *
d54804bf 18//***************************************************************************
326c2d4b 19
20#include "AliHLTTPCCATracker.h"
d54804bf 21#include "AliHLTTPCCARow.h"
22#include "AliHLTTPCCATrack.h"
4687b8fc 23#include "AliHLTTPCCATracklet.h"
00d07bcd 24#include "AliHLTTPCCAMath.h"
4acc2401 25#include "MemoryAssignmentHelpers.h"
326c2d4b 26
dc4788ec 27#include "TStopwatch.h"
00d07bcd 28#include "AliHLTTPCCAHitArea.h"
29#include "AliHLTTPCCANeighboursFinder.h"
30#include "AliHLTTPCCANeighboursCleaner.h"
31#include "AliHLTTPCCAStartHitsFinder.h"
32#include "AliHLTTPCCATrackletConstructor.h"
33#include "AliHLTTPCCATrackletSelector.h"
34#include "AliHLTTPCCAProcess.h"
63d8b79d 35#include "AliHLTTPCCASliceTrack.h"
36#include "AliHLTTPCCASliceOutput.h"
4acc2401 37#include "AliHLTTPCCAClusterData.h"
70e4a065 38#include "AliHLTTPCCADataCompressor.h"
00d07bcd 39
40#include "AliHLTTPCCATrackParam.h"
00d07bcd 41
b22af1bf 42#include "AliHLTTPCCAGPUConfig.h"
b22af1bf 43
00d07bcd 44#if !defined(HLTCA_GPUCODE)
4687b8fc 45#include <iostream>
a59a784e 46#include <iomanip>
b22af1bf 47#include <string.h>
00d07bcd 48#endif
d54804bf 49
6de2bc40 50//#define DRAW1
326c2d4b 51
6de2bc40 52#ifdef DRAW1
fbb9b71b 53#include "AliHLTTPCCADisplay.h"
31649d4b 54#endif //DRAW1
326c2d4b 55
ce565086 56#ifdef HLTCA_INTERNAL_PERFORMANCE
a59a784e 57//#include "AliHLTTPCCAPerformance.h"
ce565086 58#endif
59
b22af1bf 60#ifdef HLTCA_STANDALONE
61#include "AliHLTTPCCAStandaloneFramework.h"
62#endif
ce565086 63
fbb9b71b 64ClassImp( AliHLTTPCCATracker )
326c2d4b 65
b22af1bf 66
67#if !defined(HLTCA_GPUCODE)
68
69AliHLTTPCCATracker::~AliHLTTPCCATracker()
326c2d4b 70{
71 // destructor
7be9b0d7 72 if (!fIsGPUTracker)
73 {
b22af1bf 74 if (fCommonMem) delete fCommonMem;
75 if (fHitMemory) delete[] fHitMemory;
76 if (fTrackletMemory) delete[] fTrackletMemory;
77 if (fTrackMemory) delete[] fTrackMemory;
78 fCommonMem = NULL;
79 fHitMemory = fTrackMemory = NULL;
7be9b0d7 80 }
326c2d4b 81}
00d07bcd 82
326c2d4b 83// ----------------------------------------------------------------------------------
7be9b0d7 84void AliHLTTPCCATracker::Initialize( const AliHLTTPCCAParam &param )
326c2d4b 85{
75192f26 86 // initialisation
00d07bcd 87 fParam = param;
4687b8fc 88 fParam.Update();
4acc2401 89 fData.InitializeRows( fParam );
90
326c2d4b 91 StartEvent();
92}
93
7be9b0d7 94void AliHLTTPCCATracker::StartEvent()
326c2d4b 95{
fbb9b71b 96 // start new event and fresh the memory
d54804bf 97
4acc2401 98 SetupCommonMemory();
4acc2401 99}
100
7be9b0d7 101void AliHLTTPCCATracker::SetGPUTracker()
102{
8566066c 103 //Make this a GPU Tracker
7be9b0d7 104 fIsGPUTracker = true;
b22af1bf 105 fData.SetGpuSliceData();
7be9b0d7 106}
107
8566066c 108char* AliHLTTPCCATracker::SetGPUTrackerCommonMemory(char* const pGPUMemory)
7be9b0d7 109{
8566066c 110 //Set up common Memory Pointer for GPU Tracker
a59a784e 111 fCommonMem = (commonMemoryStruct*) pGPUMemory;
112 return(pGPUMemory + sizeof(commonMemoryStruct));
7be9b0d7 113}
114
115
b22af1bf 116char* AliHLTTPCCATracker::SetGPUTrackerHitsMemory(char* pGPUMemory, int MaxNHits)
7be9b0d7 117{
8566066c 118 //Set up Hits Memory Pointers for GPU Tracker
7be9b0d7 119 fHitMemory = (char*) pGPUMemory;
120 SetPointersHits(MaxNHits);
b22af1bf 121 pGPUMemory += fHitMemorySize;
122 AssignMemory(fTrackletTmpStartHits, pGPUMemory, NHitsTotal());
123 AssignMemory(fRowStartHitCountOffset, pGPUMemory, Param().NRows());
124
125 return(pGPUMemory);
7be9b0d7 126}
127
b22af1bf 128char* AliHLTTPCCATracker::SetGPUTrackerTrackletsMemory(char* pGPUMemory, int MaxNTracks)
129{
8566066c 130 //Set up Tracklet Memory Pointers for GPU Tracker
b22af1bf 131 fTrackletMemory = (char*) pGPUMemory;
132 SetPointersTracklets(MaxNTracks);
133 pGPUMemory += fTrackletMemorySize;
134 AssignMemory(fGPUTrackletTemp, pGPUMemory, MaxNTracks);
135 AssignMemory(fRowBlockTracklets, pGPUMemory, MaxNTracks * 2 * (Param().NRows() / HLTCA_GPU_SCHED_ROW_STEP + 1));
136 AssignMemory(fRowBlockPos, pGPUMemory, 2 * (Param().NRows() / HLTCA_GPU_SCHED_ROW_STEP + 1));
137 AssignMemory(fBlockStartingTracklet, pGPUMemory, HLTCA_GPU_BLOCK_COUNT);
138
139 return(pGPUMemory);
140}
7be9b0d7 141
142char* AliHLTTPCCATracker::SetGPUTrackerTracksMemory(char* pGPUMemory, int MaxNTracks, int MaxNHits )
143{
8566066c 144 //Set up Tracks Memory Pointer for GPU Tracker
7be9b0d7 145 fTrackMemory = (char*) pGPUMemory;
146 SetPointersTracks(MaxNTracks, MaxNHits);
b22af1bf 147 pGPUMemory += fTrackMemorySize;
148
149 return(pGPUMemory);
7be9b0d7 150}
151
b22af1bf 152void AliHLTTPCCATracker::DumpSliceData(std::ostream &out)
7be9b0d7 153{
8566066c 154 //Dump Slice Input Data to File
155 out << "Slice Data:" << std::endl;
7be9b0d7 156 for (int i = 0;i < Param().NRows();i++)
157 {
8566066c 158 out << "Row: " << i << std::endl;
7be9b0d7 159 for (int j = 0;j < Row(i).NHits();j++)
160 {
b22af1bf 161 if (j && j % 16 == 0) out << std::endl;
162 out << j << '-' << Data().HitDataY(Row(i), j) << '-' << Data().HitDataZ(Row(i), j) << ", ";
7be9b0d7 163 }
8566066c 164 out << std::endl;
7be9b0d7 165 }
166}
167
b22af1bf 168void AliHLTTPCCATracker::DumpLinks(std::ostream &out)
7be9b0d7 169{
8566066c 170 //Dump Links (after Neighbours Finder / Cleaner) to file
171 out << "Hit Links:" << std::endl;
b22af1bf 172 for (int i = 0;i < Param().NRows();i++)
7be9b0d7 173 {
8566066c 174 out << "Row: " << i << std::endl;
b22af1bf 175 for (int j = 0;j < Row(i).NHits();j++)
7be9b0d7 176 {
8566066c 177 if (j && j % 32 == 0) out << std::endl;
b22af1bf 178 out << HitLinkUpData(Row(i), j) << "/" << HitLinkDownData(Row(i), j) << ", ";
7be9b0d7 179 }
8566066c 180 out << std::endl;
7be9b0d7 181 }
7be9b0d7 182}
183
b22af1bf 184void AliHLTTPCCATracker::DumpHitWeights(std::ostream &out)
7be9b0d7 185{
8566066c 186 //dump hit weights to file
187 out << "Hit Weights:" << std::endl;
b22af1bf 188 for (int i = 0;i < Param().NRows();i++)
189 {
8566066c 190 out << "Row: " << i << ":" << std::endl;
b22af1bf 191 for (int j = 0;j < Row(i).NHits();j++)
7be9b0d7 192 {
8566066c 193 if (j && j % 32 == 0) out << std::endl;
b22af1bf 194 out << HitWeight(Row(i), j) << ", ";
7be9b0d7 195 }
8566066c 196 out << std::endl;
b22af1bf 197 }
198}
199
a59a784e 200int AliHLTTPCCATracker::StarthitSortComparison(const void*a, const void* b)
b22af1bf 201{
8566066c 202 //qsort helper function to sort start hits
b22af1bf 203 AliHLTTPCCAHitId* aa = (AliHLTTPCCAHitId*) a;
204 AliHLTTPCCAHitId* bb = (AliHLTTPCCAHitId*) b;
205
206 if (aa->RowIndex() != bb->RowIndex()) return(aa->RowIndex() - bb->RowIndex());
207 return(aa->HitIndex() - bb->HitIndex());
7be9b0d7 208}
209
b22af1bf 210void AliHLTTPCCATracker::DumpStartHits(std::ostream &out)
7be9b0d7 211{
8566066c 212 //sort start hits and dump to file
213 out << "Start Hits: (" << *NTracklets() << ")" << std::endl;
b22af1bf 214#ifdef HLTCA_GPU_SORT_DUMPDATA
a59a784e 215 qsort(TrackletStartHits(), *NTracklets(), sizeof(AliHLTTPCCAHitId), StarthitSortComparison);
b22af1bf 216#endif
217 for (int i = 0;i < *NTracklets();i++)
7be9b0d7 218 {
8566066c 219 out << TrackletStartHit(i).RowIndex() << "-" << TrackletStartHit(i).HitIndex() << std::endl;
7be9b0d7 220 }
8566066c 221 out << std::endl;
b22af1bf 222}
223
224void AliHLTTPCCATracker::DumpTrackHits(std::ostream &out)
225{
8566066c 226 //dump tracks to file
227 out << "Tracks: (" << *NTracks() << ")" << std::endl;
b22af1bf 228#ifdef HLTCA_GPU_SORT_DUMPDATA
229 for (int k = 0;k < Param().NRows();k++)
7be9b0d7 230 {
b22af1bf 231 for (int l = 0;l < Row(k).NHits();l++)
7be9b0d7 232 {
b22af1bf 233#endif
234 for (int j = 0;j < *NTracks();j++)
235 {
236 if (Tracks()[j].NHits() == 0 || !Tracks()[j].Alive()) continue;
237#ifdef HLTCA_GPU_SORT_DUMPDATA
238 if (TrackHits()[Tracks()[j].FirstHitID()].RowIndex() == k && TrackHits()[Tracks()[j].FirstHitID()].HitIndex() == l)
239 {
240#endif
241 for (int i = 0;i < Tracks()[j].NHits();i++)
242 {
243 out << TrackHits()[Tracks()[j].FirstHitID() + i].RowIndex() << "-" << TrackHits()[Tracks()[j].FirstHitID() + i].HitIndex() << ", ";
244 }
8566066c 245 out << "(Track: " << j << ")" << std::endl;
b22af1bf 246#ifdef HLTCA_GPU_SORT_DUMPDATA
247 }
248 }
249#endif
250 }
251#ifdef HLTCA_GPU_SORT_DUMPDATA
7be9b0d7 252 }
b22af1bf 253#endif
7be9b0d7 254}
255
256void AliHLTTPCCATracker::DumpTrackletHits(std::ostream &out)
257{
8566066c 258 //dump tracklets to file
259 out << "Tracklets: (" << *NTracklets() << ")" << std::endl;
b22af1bf 260#ifdef HLTCA_GPU_SORT_DUMPDATA
261 AliHLTTPCCAHitId* tmpIds = new AliHLTTPCCAHitId[*NTracklets()];
262 AliHLTTPCCATracklet* tmpTracklets = new AliHLTTPCCATracklet[*NTracklets()];
263 memcpy(tmpIds, TrackletStartHits(), *NTracklets() * sizeof(AliHLTTPCCAHitId));
264 memcpy(tmpTracklets, Tracklets(), *NTracklets() * sizeof(AliHLTTPCCATracklet));
265#ifdef EXTERN_ROW_HITS
266 int* tmpHits = new int[*NTracklets() * Param().NRows()];
267 memcpy(tmpHits, TrackletRowHits(), *NTracklets() * Param().NRows() * sizeof(int));
268#endif
a59a784e 269 qsort(TrackletStartHits(), *NTracklets(), sizeof(AliHLTTPCCAHitId), StarthitSortComparison);
b22af1bf 270 for (int i = 0;i < *NTracklets();i++)
7be9b0d7 271 {
272 for (int j = 0;j < *NTracklets();j++)
273 {
b22af1bf 274 if (tmpIds[i].RowIndex() == TrackletStartHit(j).RowIndex() && tmpIds[i].HitIndex() == TrackletStartHit(j).HitIndex())
7be9b0d7 275 {
b22af1bf 276 memcpy(&Tracklets()[j], &tmpTracklets[i], sizeof(AliHLTTPCCATracklet));
277#ifdef EXTERN_ROW_HITS
278 if (tmpTracklets[i].NHits())
7be9b0d7 279 {
b22af1bf 280 for (int k = tmpTracklets[i].FirstRow();k <= tmpTracklets[i].LastRow();k++)
281 {
282 fTrackletRowHits[k * *NTracklets() + j] = tmpHits[k * *NTracklets() + i];
283 }
7be9b0d7 284 }
b22af1bf 285#endif
286 break;
287 }
288 }
289 }
290 delete[] tmpIds;
291 delete[] tmpTracklets;
292#ifdef EXTERN_ROW_HITS
293 delete[] tmpHits;
294#endif
295#endif
296 for (int j = 0;j < *NTracklets();j++)
297 {
8566066c 298 out << "Tracklet " << j << " (Hits: " << std::setw(3) << Tracklets()[j].NHits() << ", Start: " << std::setw(3) << TrackletStartHit(j).RowIndex() << "-" << std::setw(3) << TrackletStartHit(j).HitIndex() << ") ";
b22af1bf 299 if (Tracklets()[j].NHits() == 0);
300 else if (Tracklets()[j].LastRow() > Tracklets()[j].FirstRow() && (Tracklets()[j].FirstRow() >= Param().NRows() || Tracklets()[j].LastRow() >= Param().NRows()))
301 {
302#ifdef HLTCA_STANDALONE
303 printf("\nError: First %d Last %d Num %d", Tracklets()[j].FirstRow(), Tracklets()[j].LastRow(), Tracklets()[j].NHits());
304#endif
305 }
306 else if (Tracklets()[j].NHits() && Tracklets()[j].LastRow() > Tracklets()[j].FirstRow())
307 {
308 for (int i = Tracklets()[j].FirstRow();i <= Tracklets()[j].LastRow();i++)
309 {
310 //if (Tracklets()[j].RowHit(i) != -1)
311#ifdef EXTERN_ROW_HITS
312 out << i << "-" << fTrackletRowHits[i * fCommonMem->fNTracklets + j] << ", ";
313#else
314 out << i << "-" << Tracklets()[j].RowHit(i) << ", ";
315#endif
7be9b0d7 316 }
317 }
8566066c 318 out << std::endl;
7be9b0d7 319 }
320}
321
322
b22af1bf 323void AliHLTTPCCATracker::SetupCommonMemory()
4acc2401 324{
6de2bc40 325 // set up common memory
326
7be9b0d7 327 if (!fIsGPUTracker)
328 {
b22af1bf 329 if ( !fCommonMem ) {
7be9b0d7 330 // the 1600 extra bytes are not used unless fCommonMemorySize increases with a later event
b22af1bf 331 //fCommonMemory = reinterpret_cast<char*> ( new uint4 [ fCommonMemorySize/sizeof( uint4 ) + 100] );
332 fCommonMem = new commonMemoryStruct;
7be9b0d7 333 }
fbb9b71b 334
b22af1bf 335 if (fHitMemory) delete[] fHitMemory;
336 if (fTrackletMemory) delete[] fTrackletMemory;
337 if (fTrackMemory) delete[] fTrackMemory;
7be9b0d7 338 }
c259f7e4 339
b22af1bf 340 fHitMemory = fTrackletMemory = fTrackMemory = 0;
341
4acc2401 342 fData.Clear();
b22af1bf 343 fCommonMem->fNTracklets = 0;
344 fCommonMem->fNTracks = 0 ;
345 fCommonMem->fNTrackHits = 0;
326c2d4b 346}
347
7be9b0d7 348void AliHLTTPCCATracker::ReadEvent( AliHLTTPCCAClusterData *clusterData )
349{
350 // read event
351
352 fClusterData = clusterData;
353
354 StartEvent();
355
356 //* Convert input hits, create grids, etc.
357 fData.InitFromClusterData( *clusterData );
7be9b0d7 358 {
b22af1bf 359 if (!fIsGPUTracker)
360 {
361 SetPointersHits( fData.NumberOfHits() ); // to calculate the size
362 fHitMemory = reinterpret_cast<char*> ( new uint4 [ fHitMemorySize/sizeof( uint4 ) + 100] );
363 }
7be9b0d7 364 SetPointersHits( fData.NumberOfHits() ); // set pointers for hits
7be9b0d7 365 }
366}
367
fbb9b71b 368GPUhd() void AliHLTTPCCATracker::SetPointersHits( int MaxNHits )
c259f7e4 369{
370 // set all pointers to the event memory
371
4acc2401 372 char *mem = fHitMemory;
c259f7e4 373
374 // extra arrays for tpc clusters
c259f7e4 375
b22af1bf 376#ifdef HLTCA_GPU_SORT_STARTHITS_2
377 AssignMemory( fTrackletStartHits, mem, MaxNHits + 32);
378#else
379 AssignMemory( fTrackletStartHits, mem, MaxNHits);
380#endif
381
382 // calculate the size
c259f7e4 383
b22af1bf 384 fHitMemorySize = mem - fHitMemory;
385}
c259f7e4 386
b22af1bf 387GPUhd() void AliHLTTPCCATracker::SetPointersTracklets( int MaxNTracklets )
388{
389 // set all pointers to the tracklets memory
390 char *mem = fTrackletMemory;
fbb9b71b 391
b22af1bf 392 // memory for tracklets
c259f7e4 393
b22af1bf 394 AssignMemory( fTracklets, mem, MaxNTracklets );
395#ifdef EXTERN_ROW_HITS
396 AssignMemory( fTrackletRowHits, mem, MaxNTracklets * Param().NRows());
397#endif
c259f7e4 398
b22af1bf 399 fTrackletMemorySize = mem - fTrackletMemory;
c259f7e4 400}
401
402
fbb9b71b 403GPUhd() void AliHLTTPCCATracker::SetPointersTracks( int MaxNTracks, int MaxNHits )
c259f7e4 404{
405 // set all pointers to the tracks memory
4acc2401 406 char *mem = fTrackMemory;
fbb9b71b 407
c259f7e4 408 // memory for selected tracks
fbb9b71b 409
4acc2401 410 AssignMemory( fTracks, mem, MaxNTracks );
b22af1bf 411 AssignMemory( fTrackHits, mem, 2 * MaxNHits );
c259f7e4 412
413 // calculate the size
414
4acc2401 415 fTrackMemorySize = mem - fTrackMemory;
c259f7e4 416}
417
a59a784e 418GPUh() int AliHLTTPCCATracker::CheckEmptySlice() const
7be9b0d7 419{
8566066c 420 //Check if the Slice is empty, if so set the output apropriate and tell the reconstuct procesdure to terminate
7be9b0d7 421 if ( NHitsTotal() < 1 ) {
422 {
a59a784e 423 AliHLTTPCCASliceOutput::Allocate(*fOutput, 0, 0, fOutputControl);
424 AliHLTTPCCASliceOutput* useOutput = *fOutput;
90da1ad5 425 if (useOutput == NULL) return(1);
98512261 426 useOutput->SetNTracks( 0 );
427 useOutput->SetNTrackClusters( 0 );
7be9b0d7 428 }
326c2d4b 429
7be9b0d7 430 return 1;
431 }
432 return 0;
433}
434
435void AliHLTTPCCATracker::RunNeighboursFinder()
326c2d4b 436{
8566066c 437 //Run the CPU Neighbours Finder
7be9b0d7 438 AliHLTTPCCAProcess<AliHLTTPCCANeighboursFinder>( Param().NRows(), 1, *this );
439}
6de2bc40 440
7be9b0d7 441void AliHLTTPCCATracker::RunNeighboursCleaner()
442{
8566066c 443 //Run the CPU Neighbours Cleaner
7be9b0d7 444 AliHLTTPCCAProcess<AliHLTTPCCANeighboursCleaner>( Param().NRows() - 2, 1, *this );
445}
d54804bf 446
7be9b0d7 447void AliHLTTPCCATracker::RunStartHitsFinder()
448{
8566066c 449 //Run the CPU Start Hits Finder
7be9b0d7 450 AliHLTTPCCAProcess<AliHLTTPCCAStartHitsFinder>( Param().NRows() - 4, 1, *this );
451}
fbb9b71b 452
7be9b0d7 453void AliHLTTPCCATracker::RunTrackletConstructor()
454{
8566066c 455 //Run CPU Tracklet Constructor
a59a784e 456 AliHLTTPCCATrackletConstructor::AliHLTTPCCATrackletConstructorNewCPU(*this);
7be9b0d7 457}
fbb9b71b 458
7be9b0d7 459void AliHLTTPCCATracker::RunTrackletSelector()
460{
8566066c 461 //Run CPU Tracklet Selector
b22af1bf 462 AliHLTTPCCAProcess<AliHLTTPCCATrackletSelector>( 1, fCommonMem->fNTracklets, *this );
d54804bf 463}
464
b22af1bf 465#ifdef HLTCA_STANDALONE
466void AliHLTTPCCATracker::StandalonePerfTime(int i)
467{
8566066c 468 //Query Performance Timer for Standalone Version of Tracker
b22af1bf 469 if (fGPUDebugLevel >= 1)
470 {
a59a784e 471 AliHLTTPCCAStandaloneFramework::StandaloneQueryTime(&fPerfTimers[i]);
b22af1bf 472 }
473}
474#else
475void AliHLTTPCCATracker::StandalonePerfTime(int /*i*/) {}
476#endif
477
00d07bcd 478GPUh() void AliHLTTPCCATracker::Reconstruct()
479{
480 //* reconstruction of event
4acc2401 481 //std::cout<<"Reconstruct slice "<<fParam.ISlice()<<", nHits="<<NHitsTotal()<<std::endl;
326c2d4b 482
00d07bcd 483 fTimers[0] = 0; // find neighbours
484 fTimers[1] = 0; // construct tracklets
485 fTimers[2] = 0; // fit tracklets
486 fTimers[3] = 0; // prolongation of tracklets
487 fTimers[4] = 0; // selection
488 fTimers[5] = 0; // write output
489 fTimers[6] = 0;
490 fTimers[7] = 0;
fbb9b71b 491
693d2443 492 //if( fParam.ISlice()<1 ) return; //SG!!!
00d07bcd 493
00d07bcd 494 TStopwatch timer0;
b22af1bf 495
496 StandalonePerfTime(0);
497
7be9b0d7 498 if (CheckEmptySlice()) return;
4687b8fc 499
6de2bc40 500#ifdef DRAW1
f0fb467d 501 //if( fParam.ISlice()==2 || fParam.ISlice()==3)
502 {
fbb9b71b 503 AliHLTTPCCADisplay::Instance().ClearView();
693d2443 504 AliHLTTPCCADisplay::Instance().SetSliceView();
505 AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
fbb9b71b 506 AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
4acc2401 507 if ( NHitsTotal() > 0 ) {
fbb9b71b 508 AliHLTTPCCADisplay::Instance().DrawSliceHits( kRed, .5 );
693d2443 509 AliHLTTPCCADisplay::Instance().Ask();
510 }
f0fb467d 511 }
31649d4b 512#endif //DRAW1
693d2443 513
b22af1bf 514 fCommonMem->fNTracklets = fCommonMem->fNTracks = fCommonMem->fNTrackHits = 0;
4687b8fc 515
fbb9b71b 516#if !defined(HLTCA_GPUCODE)
517
31649d4b 518 if (fGPUDebugLevel >= 6)
7be9b0d7 519 {
31649d4b 520 *fGPUDebugOut << std::endl << std::endl << "Slice: " << Param().ISlice() << std::endl;
521 *fGPUDebugOut << "Slice Data:" << std::endl;
b22af1bf 522 DumpSliceData(*fGPUDebugOut);
31649d4b 523 }
b22af1bf 524
525 StandalonePerfTime(1);
693d2443 526
7be9b0d7 527 RunNeighboursFinder();
528
b22af1bf 529 StandalonePerfTime(2);
530
531 if (fGPUDebugLevel >= 6) DumpLinks(*fGPUDebugOut);
532
fbb9b71b 533#ifdef HLTCA_INTERNAL_PERFORMANCE
534 //if( Param().ISlice()<=2 )
ce565086 535 //AliHLTTPCCAPerformance::Instance().LinkPerformance( Param().ISlice() );
536#endif
537
538
f0fb467d 539#ifdef DRAW1
4acc2401 540 if ( NHitsTotal() > 0 ) {
fbb9b71b 541 AliHLTTPCCADisplay::Instance().DrawSliceLinks( -1, -1, 1 );
ce565086 542 AliHLTTPCCADisplay::Instance().Ask();
543 }
31649d4b 544#endif //DRAW1
ce565086 545
7be9b0d7 546 RunNeighboursCleaner();
ce565086 547
b22af1bf 548 StandalonePerfTime(3);
549
550 if (fGPUDebugLevel >= 6) DumpLinks(*fGPUDebugOut);
fbb9b71b 551
7be9b0d7 552 RunStartHitsFinder();
c259f7e4 553
b22af1bf 554 StandalonePerfTime(4);
555 StandalonePerfTime(5);
d54804bf 556
b22af1bf 557 if (fGPUDebugLevel >= 6) DumpStartHits(*fGPUDebugOut);
558
7be9b0d7 559 fData.ClearHitWeights();
d54804bf 560
b22af1bf 561 SetPointersTracklets( fCommonMem->fNTracklets * 2 ); // to calculate the size
562 fTrackletMemory = reinterpret_cast<char*> ( new uint4 [ fTrackletMemorySize/sizeof( uint4 ) + 100] );
563 SetPointersTracklets( fCommonMem->fNTracklets * 2 ); // set pointers for hits
564
565 SetPointersTracks( fCommonMem->fNTracklets * 2, NHitsTotal() ); // to calculate the size
7be9b0d7 566 fTrackMemory = reinterpret_cast<char*> ( new uint4 [ fTrackMemorySize/sizeof( uint4 ) + 100] );
b22af1bf 567 SetPointersTracks( fCommonMem->fNTracklets * 2, NHitsTotal() ); // set pointers for hits
568
569 StandalonePerfTime(6);
570 StandalonePerfTime(7);
d54804bf 571
7be9b0d7 572 RunTrackletConstructor();
ce565086 573
b22af1bf 574 StandalonePerfTime(8);
575
576 if (fGPUDebugLevel >= 6) DumpTrackletHits(*fGPUDebugOut);
577 if (fGPUDebugLevel >= 6) DumpHitWeights(*fGPUDebugOut);
d54804bf 578
7be9b0d7 579 //std::cout<<"Slice "<<Param().ISlice()<<": NHits="<<NHitsTotal()<<", NTracklets="<<*NTracklets()<<std::endl;
d54804bf 580
7be9b0d7 581 RunTrackletSelector();
d54804bf 582
b22af1bf 583 StandalonePerfTime(9);
584
7be9b0d7 585 //std::cout<<"Slice "<<Param().ISlice()<<": N start hits/tracklets/tracks = "<<nStartHits<<" "<<nStartHits<<" "<<*fNTracks<<std::endl;
d54804bf 586
b22af1bf 587 if (fGPUDebugLevel >= 6) DumpTrackHits(*fGPUDebugOut);
c259f7e4 588
589 //std::cout<<"Memory used for slice "<<fParam.ISlice()<<" : "<<fCommonMemorySize/1024./1024.<<" + "<<fHitMemorySize/1024./1024.<<" + "<<fTrackMemorySize/1024./1024.<<" = "<<( fCommonMemorySize+fHitMemorySize+fTrackMemorySize )/1024./1024.<<" Mb "<<std::endl;
590
fbb9b71b 591 WriteOutput();
592
b22af1bf 593 StandalonePerfTime(10);
594
693d2443 595#endif
596
f0fb467d 597#ifdef DRAW1
fbb9b71b 598 {
599 AliHLTTPCCADisplay &disp = AliHLTTPCCADisplay::Instance();
600 AliHLTTPCCATracker &slice = *this;
b22af1bf 601 std::cout << "N out tracks = " << slice.NOutTracks() << std::endl;
f0fb467d 602 AliHLTTPCCADisplay::Instance().SetSliceView();
fbb9b71b 603 AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
604 AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
f0fb467d 605 disp.DrawSliceHits( kRed, .5 );
606 disp.Ask();
b22af1bf 607 for ( int itr = 0; itr < slice.NOutTracks(); itr++ ) {
fbb9b71b 608 std::cout << "track N " << itr << ", nhits=" << slice.OutTracks()[itr].NHits() << std::endl;
f0fb467d 609 disp.DrawSliceOutTrack( itr, kBlue );
fbb9b71b 610 //disp.Ask();
611 //int id = slice.OutTracks()[itr].OrigTrackID();
612 //AliHLTTPCCATrack &tr = Tracks()[id];
613 //for( int ih=0; ih<tr.NHits(); ih++ ){
614 //int ic = (fTrackHits[tr.FirstHitID()+ih]);
615 //std::cout<<ih<<" "<<ID2IRow(ic)<<" "<<ID2IHit(ic)<<std::endl;
616 //}
617 //disp.DrawSliceTrack( id, kBlue );
618 //disp.Ask();
619 }
620 disp.Ask();
621 }
31649d4b 622#endif //DRAW1
dc4788ec 623
fbb9b71b 624 timer0.Stop();
625 fTimers[0] = timer0.CpuTime() / 100.;
326c2d4b 626
fbb9b71b 627}
326c2d4b 628
00d07bcd 629GPUh() void AliHLTTPCCATracker::WriteOutput()
630{
d54804bf 631 // write output
eb30eb49 632
00d07bcd 633 TStopwatch timer;
63d8b79d 634
4acc2401 635 //cout<<"output: nTracks = "<<*fNTracks<<", nHitsTotal="<<NHitsTotal()<<std::endl;
5cb6ddd4 636
d4594e7d 637 if (fOutputControl == NULL) fOutputControl = new AliHLTTPCCASliceOutput::outputControlStruct;
638 AliHLTTPCCASliceOutput::Allocate(*fOutput, fCommonMem->fNTracks, fCommonMem->fNTrackHits, fOutputControl);
98512261 639 AliHLTTPCCASliceOutput* useOutput = *fOutput;
d4594e7d 640 if (useOutput == NULL) return;
98512261 641
5cb6ddd4 642 useOutput->SetNTracks( fCommonMem->fNTracks );
643 useOutput->SetNTrackClusters( fCommonMem->fNTrackHits );
644
645 int nStoredHits = 0;
646
647 for ( int iTr = 0; iTr < fCommonMem->fNTracks; iTr++ ) {
648 AliHLTTPCCATrack &iTrack = fTracks[iTr];
649 AliHLTTPCCASliceTrack out;
650 out.SetFirstClusterRef( nStoredHits );
651 out.SetNClusters( iTrack.NHits() );
652 out.SetParam( iTrack.Param() );
653
654 useOutput->SetTrack( iTr, out );
655
656 int iID = iTrack.FirstHitID();
657 for ( int ith = 0; ith < iTrack.NHits(); ith++ ) {
658 const AliHLTTPCCAHitId &ic = fTrackHits[iID + ith];
659 int iRow = ic.RowIndex();
660 int ih = ic.HitIndex();
661
662 const AliHLTTPCCARow &row = fData.Row( iRow );
663
664 //float y0 = row.Grid().YMin();
665 //float z0 = row.Grid().ZMin();
666 //float stepY = row.HstepY();
667 //float stepZ = row.HstepZ();
668 //float x = row.X();
669
670 //const uint4 *tmpint4 = RowData() + row.FullOffset();
671 //const ushort2 *hits = reinterpret_cast<const ushort2*>(tmpint4);
672 //ushort2 hh = hits[ih];
673 //float y = y0 + hh.x*stepY;
674 //float z = z0 + hh.y*stepZ;
675
676 int clusterIndex = fData.ClusterDataIndex( row, ih );
677 int clusterRowIndex = clusterIndex - fClusterData->RowOffset( iRow );
678
679 if ( clusterIndex < 0 || clusterIndex >= fClusterData->NumberOfClusters() ) {
680 //std::cout << inpIDtot << ", " << fClusterData->NumberOfClusters()
681 //<< "; " << inpID << ", " << fClusterData->NumberOfClusters( iRow ) << std::endl;
682 //abort();
683 continue;
684 }
685 if ( clusterRowIndex < 0 || clusterRowIndex >= fClusterData->NumberOfClusters( iRow ) ) {
686 //std::cout << inpIDtot << ", " << fClusterData->NumberOfClusters()
687 //<< "; " << inpID << ", " << fClusterData->NumberOfClusters( iRow ) << std::endl;
688 //abort();
689 continue;
690 }
691
692 float origX = fClusterData->X( clusterIndex );
693 float origY = fClusterData->Y( clusterIndex );
694 float origZ = fClusterData->Z( clusterIndex );
695
696 int id = fClusterData->Id( clusterIndex );
697 AliHLTTPCCACompressedCluster cXYZ = AliHLTTPCCADataCompressor::PackXYZ( iRow, origX, origY, origZ );
698
699 //float2 hUnpackedYZ;
700 //hUnpackedYZ.x = origY;
701 //hUnpackedYZ.y = origZ;
702 //float hUnpackedX = origX;
703
704 useOutput->SetClusterId( nStoredHits, id );
705 useOutput->SetClusterRow( nStoredHits, ( unsigned char ) iRow );
706 useOutput->SetClusterPackedXYZ( nStoredHits, cXYZ );
707 nStoredHits++;
708 }
d54804bf 709 }
63d8b79d 710
00d07bcd 711 timer.Stop();
fbb9b71b 712 fTimers[5] += timer.CpuTime();
326c2d4b 713}
714
7be9b0d7 715#endif
716
4acc2401 717GPUh() void AliHLTTPCCATracker::FitTrackFull( const AliHLTTPCCATrack &/**/, float * /**/ ) const
fbb9b71b 718{
00d07bcd 719 // fit track with material
fbb9b71b 720#ifdef XXX
721 //* Fit the track
00d07bcd 722 FitTrack( iTrack, tt0 );
fbb9b71b 723 if ( iTrack.NHits() <= 3 ) return;
724
00d07bcd 725 AliHLTTPCCATrackParam &t = iTrack.Param();
726 AliHLTTPCCATrackParam t0 = t;
727
728 t.Chi2() = 0;
fbb9b71b 729 t.NDF() = -5;
730 bool first = 1;
731
732 int iID = iTrack.FirstHitID();
733 for ( int ih = 0; ih < iTrack.NHits(); ih++, iID++ ) {
4acc2401 734 const AliHLTTPCCAHitId &ic = fTrackHits[iID];
735 int iRow = ic.rowIndex();
736 const AliHLTTPCCARow &row = fData.Row( iRow );
fbb9b71b 737 if ( !t0.TransportToX( row.X() ) ) continue;
738 float dy, dz;
4acc2401 739 const AliHLTTPCCAHit &h = ic.hitIndex();
fbb9b71b 740
741 // check for wrong hits
742 if ( 0 ) {
00d07bcd 743 dy = t0.GetY() - h.Y();
744 dz = t0.GetZ() - h.Z();
fbb9b71b 745
00d07bcd 746 //if( dy*dy > 3.5*3.5*(/*t0.GetErr2Y() + */h.ErrY()*h.ErrY() ) ) continue;//SG!!!
fbb9b71b 747 //if( dz*dz > 3.5*3.5*(/*t0.GetErr2Z() + */h.ErrZ()*h.ErrZ() ) ) continue;
00d07bcd 748 }
326c2d4b 749
fbb9b71b 750 if ( !t.TransportToX( row.X() ) ) continue;
dc4788ec 751
00d07bcd 752 //* Update the track
fbb9b71b 753
754 if ( first ) {
755 t.Cov()[ 0] = .5 * .5;
00d07bcd 756 t.Cov()[ 1] = 0;
fbb9b71b 757 t.Cov()[ 2] = .5 * .5;
00d07bcd 758 t.Cov()[ 3] = 0;
759 t.Cov()[ 4] = 0;
fbb9b71b 760 t.Cov()[ 5] = .2 * .2;
00d07bcd 761 t.Cov()[ 6] = 0;
762 t.Cov()[ 7] = 0;
763 t.Cov()[ 8] = 0;
fbb9b71b 764 t.Cov()[ 9] = .2 * .2;
00d07bcd 765 t.Cov()[10] = 0;
766 t.Cov()[11] = 0;
767 t.Cov()[12] = 0;
768 t.Cov()[13] = 0;
fbb9b71b 769 t.Cov()[14] = .2 * .2;
00d07bcd 770 t.Chi2() = 0;
771 t.NDF() = -5;
772 }
fbb9b71b 773 float err2Y, err2Z;
00d07bcd 774 GetErrors2( iRow, t, err2Y, err2Z );
775
fbb9b71b 776 if ( !t.Filter2( h.Y(), h.Z(), err2Y, err2Z ) ) continue;
00d07bcd 777
fbb9b71b 778 first = 0;
779 }
00d07bcd 780 /*
fbb9b71b 781 float cosPhi = iTrack.Param().GetCosPhi();
00d07bcd 782 p0.Param().TransportToX(ID2Row( iTrack.PointID()[0] ).X());
fbb9b71b 783 p2.Param().TransportToX(ID2Row( iTrack.PointID()[1] ).X());
00d07bcd 784 if( p0.Param().GetCosPhi()*cosPhi<0 ){ // change direction
fbb9b71b 785 float *par = p0.Param().Par();
786 float *cov = p0.Param().Cov();
00d07bcd 787 par[2] = -par[2]; // sin phi
788 par[3] = -par[3]; // DzDs
789 par[4] = -par[4]; // kappa
790 cov[3] = -cov[3];
791 cov[4] = -cov[4];
792 cov[6] = -cov[6];
793 cov[7] = -cov[7];
794 cov[10] = -cov[10];
795 cov[11] = -cov[11];
796 p0.Param().CosPhi() = -p0.Param().GetCosPhi();
797 }
798 */
799#endif
800}
dc4788ec 801
4acc2401 802GPUh() void AliHLTTPCCATracker::FitTrack( const AliHLTTPCCATrack &/*track*/, float * /*t0[]*/ ) const
fbb9b71b 803{
804 //* Fit the track
00d07bcd 805#ifdef XXX
fbb9b71b 806 AliHLTTPCCAEndPoint &p2 = ID2Point( track.PointID()[1] );
4acc2401 807 const AliHLTTPCCAHit &c0 = ID2Hit( fTrackHits[p0.TrackHitID()].HitID() );
808 const AliHLTTPCCAHit &c1 = ID2Hit( fTrackHits[track.HitID()[1]].HitID() );
809 const AliHLTTPCCAHit &c2 = ID2Hit( fTrackHits[p2.TrackHitID()].HitID() );
810 const AliHLTTPCCARow &row0 = ID2Row( fTrackHits[p0.TrackHitID()].HitID() );
811 const AliHLTTPCCARow &row1 = ID2Row( fTrackHits[track.HitID()[1]].HitID() );
812 const AliHLTTPCCARow &row2 = ID2Row( fTrackHits[p2.TrackHitID()].HitID() );
fbb9b71b 813 float sp0[5] = {row0.X(), c0.Y(), c0.Z(), c0.ErrY(), c0.ErrZ() };
814 float sp1[5] = {row1.X(), c1.Y(), c1.Z(), c1.ErrY(), c1.ErrZ() };
815 float sp2[5] = {row2.X(), c2.Y(), c2.Z(), c2.ErrY(), c2.ErrZ() };
4acc2401 816 //std::cout<<"Fit track, points ="<<sp0[0]<<" "<<sp0[1]<<" / "<<sp1[0]<<" "<<sp1[1]<<" / "<<sp2[0]<<" "<<sp2[1]<<std::endl;
fbb9b71b 817 if ( track.NHits() >= 3 ) {
818 p0.Param().ConstructXYZ3( sp0, sp1, sp2, p0.Param().CosPhi(), t0 );
819 p2.Param().ConstructXYZ3( sp2, sp1, sp0, p2.Param().CosPhi(), t0 );
d54804bf 820 //p2.Param() = p0.Param();
821 //p2.Param().TransportToX(row2.X());
822 //p2.Param().Par()[1] = -p2.Param().Par()[1];
823 //p2.Param().Par()[4] = -p2.Param().Par()[4];
824 } else {
825 p0.Param().X() = row0.X();
826 p0.Param().Y() = c0.Y();
827 p0.Param().Z() = c0.Z();
fbb9b71b 828 p0.Param().Err2Y() = c0.ErrY() * c0.ErrY();
829 p0.Param().Err2Z() = c0.ErrZ() * c0.ErrZ();
d54804bf 830 p2.Param().X() = row2.X();
831 p2.Param().Y() = c2.Y();
832 p2.Param().Z() = c2.Z();
fbb9b71b 833 p2.Param().Err2Y() = c2.ErrY() * c2.ErrY();
834 p2.Param().Err2Z() = c2.ErrZ() * c2.ErrZ();
326c2d4b 835 }
00d07bcd 836#endif
837}
838
839
fbb9b71b 840GPUd() void AliHLTTPCCATracker::GetErrors2( int iRow, float z, float sinPhi, float cosPhi, float DzDs, float &Err2Y, float &Err2Z ) const
693d2443 841{
842 //
843 // Use calibrated cluster error from OCDB
844 //
845
63d8b79d 846 fParam.GetClusterErrors2( iRow, z, sinPhi, cosPhi, DzDs, Err2Y, Err2Z );
f0fb467d 847 Err2Y*=fParam.ClusterError2CorrectionY();
848 Err2Z*=fParam.ClusterError2CorrectionZ();
693d2443 849}
850
fbb9b71b 851GPUd() void AliHLTTPCCATracker::GetErrors2( int iRow, const AliHLTTPCCATrackParam &t, float &Err2Y, float &Err2Z ) const
00d07bcd 852{
853 //
854 // Use calibrated cluster error from OCDB
855 //
856
15d2e9cf 857 fParam.GetClusterErrors2( iRow, t.GetZ(), t.SinPhi(), t.GetCosPhi(), t.DzDs(), Err2Y, Err2Z );
00d07bcd 858}
859
4687b8fc 860
fbb9b71b 861#if !defined(HLTCA_GPUCODE)
4687b8fc 862
fbb9b71b 863GPUh() void AliHLTTPCCATracker::WriteEvent( std::ostream &out )
00d07bcd 864{
4687b8fc 865 // write event to the file
fbb9b71b 866 for ( int iRow = 0; iRow < fParam.NRows(); iRow++ ) {
4acc2401 867 out << fData.Row( iRow ).HitNumberOffset() << " " << fData.Row( iRow ).NHits() << std::endl;
fbb9b71b 868 }
4acc2401 869 out << NHitsTotal() << std::endl;
fbb9b71b 870
4acc2401 871 AliHLTResizableArray<float> y( NHitsTotal() ), z( NHitsTotal() );
fbb9b71b 872
873 for ( int iRow = 0; iRow < fParam.NRows(); iRow++ ) {
4acc2401 874 const AliHLTTPCCARow &row = Row( iRow );
fbb9b71b 875 float y0 = row.Grid().YMin();
876 float z0 = row.Grid().ZMin();
877 float stepY = row.HstepY();
878 float stepZ = row.HstepZ();
4acc2401 879 for ( int ih = 0; ih < fData.Row( iRow ).NHits(); ih++ ) {
880 int id = HitInputID( row, ih );
881 y[id] = y0 + HitDataY( row, ih ) * stepY;
882 z[id] = z0 + HitDataZ( row, ih ) * stepZ;
4687b8fc 883 }
884 }
4acc2401 885 for ( int ih = 0; ih < NHitsTotal(); ih++ ) {
fbb9b71b 886 out << y[ih] << " " << z[ih] << std::endl;
4687b8fc 887 }
fbb9b71b 888}
4687b8fc 889
5cb6ddd4 890GPUh() void AliHLTTPCCATracker::WriteTracks( std::ostream &/*out*/ )
4687b8fc 891{
5cb6ddd4 892 //* Write tracks to file --- dummy
4687b8fc 893}
894
5cb6ddd4 895GPUh() void AliHLTTPCCATracker::ReadTracks( std::istream &/*in*/ )
4687b8fc 896{
5cb6ddd4 897 //* Read tracks from file -- dummy
326c2d4b 898}
4687b8fc 899#endif