]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.cxx
style changes
[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"
326c2d4b 21#include "AliHLTTPCCAOutTrack.h"
d54804bf 22#include "AliHLTTPCCAGrid.h"
23#include "AliHLTTPCCARow.h"
24#include "AliHLTTPCCATrack.h"
4687b8fc 25#include "AliHLTTPCCATracklet.h"
00d07bcd 26#include "AliHLTTPCCAMath.h"
27#include "AliHLTTPCCAHit.h"
4acc2401 28#include "MemoryAssignmentHelpers.h"
326c2d4b 29
dc4788ec 30#include "TStopwatch.h"
00d07bcd 31#include "AliHLTTPCCAHitArea.h"
32#include "AliHLTTPCCANeighboursFinder.h"
33#include "AliHLTTPCCANeighboursCleaner.h"
34#include "AliHLTTPCCAStartHitsFinder.h"
35#include "AliHLTTPCCATrackletConstructor.h"
36#include "AliHLTTPCCATrackletSelector.h"
37#include "AliHLTTPCCAProcess.h"
63d8b79d 38#include "AliHLTTPCCASliceTrack.h"
39#include "AliHLTTPCCASliceOutput.h"
40#include "AliHLTTPCCADataCompressor.h"
4acc2401 41#include "AliHLTTPCCAClusterData.h"
00d07bcd 42
43#include "AliHLTTPCCATrackParam.h"
00d07bcd 44
45#if !defined(HLTCA_GPUCODE)
4687b8fc 46#include <iostream>
00d07bcd 47#endif
d54804bf 48
6de2bc40 49//#define DRAW1
326c2d4b 50
6de2bc40 51#ifdef DRAW1
fbb9b71b 52#include "AliHLTTPCCADisplay.h"
326c2d4b 53#endif //DRAW
54
ce565086 55#ifdef HLTCA_INTERNAL_PERFORMANCE
fbb9b71b 56#include "AliHLTTPCCAPerformance.h"
ce565086 57#endif
58
59
fbb9b71b 60ClassImp( AliHLTTPCCATracker )
326c2d4b 61
fbb9b71b 62#if !defined(HLTCA_GPUCODE)
326c2d4b 63
64AliHLTTPCCATracker::AliHLTTPCCATracker()
fbb9b71b 65 :
66 fParam(),
4acc2401 67 fClusterData( 0 ),
68 fData(),
fbb9b71b 69 fCommonMemory( 0 ),
70 fCommonMemorySize( 0 ),
71 fHitMemory( 0 ),
72 fHitMemorySize( 0 ),
73 fTrackMemory( 0 ),
74 fTrackMemorySize( 0 ),
fbb9b71b 75 fNTracklets( 0 ),
76 fTrackletStartHits( 0 ),
77 fTracklets( 0 ),
78 fNTracks( 0 ),
79 fTracks( 0 ),
80 fNTrackHits( 0 ),
81 fTrackHits( 0 ),
82 fOutput( 0 ),
83 fNOutTracks( 0 ),
84 fOutTracks( 0 ),
85 fNOutTrackHits( 0 ),
4acc2401 86 fOutTrackHits( 0 )
326c2d4b 87{
88 // constructor
326c2d4b 89}
90
00d07bcd 91GPUd() AliHLTTPCCATracker::~AliHLTTPCCATracker()
326c2d4b 92{
93 // destructor
4acc2401 94 delete[] fCommonMemory;
95 delete[] fHitMemory;
96 delete[] fTrackMemory;
326c2d4b 97}
00d07bcd 98#endif
99
100
326c2d4b 101
102// ----------------------------------------------------------------------------------
ce565086 103GPUd() void AliHLTTPCCATracker::Initialize( const AliHLTTPCCAParam &param )
326c2d4b 104{
75192f26 105 // initialisation
00d07bcd 106 fParam = param;
4687b8fc 107 fParam.Update();
4acc2401 108 fData.InitializeRows( fParam );
109
326c2d4b 110 StartEvent();
111}
112
00d07bcd 113GPUd() void AliHLTTPCCATracker::StartEvent()
326c2d4b 114{
fbb9b71b 115 // start new event and fresh the memory
d54804bf 116
4acc2401 117 SetupCommonMemory();
118 *fNTrackHits = 0;
119}
120
121void AliHLTTPCCATracker::SetupCommonMemory()
122{
6de2bc40 123 // set up common memory
124
fbb9b71b 125 if ( !fCommonMemory ) {
c259f7e4 126 SetPointersCommon(); // just to calculate the size
4acc2401 127 // the 1600 extra bytes are not used unless fCommonMemorySize increases with a later event
fbb9b71b 128 fCommonMemory = reinterpret_cast<char*> ( new uint4 [ fCommonMemorySize/sizeof( uint4 ) + 100] );
c259f7e4 129 SetPointersCommon();// set pointers
4687b8fc 130 }
fbb9b71b 131
4acc2401 132 delete[] fHitMemory;
c259f7e4 133 fHitMemory = 0;
4acc2401 134 delete[] fTrackMemory;
c259f7e4 135 fTrackMemory = 0;
136
4acc2401 137 fData.Clear();
4687b8fc 138 *fNTracklets = 0;
139 *fNTracks = 0 ;
140 *fNTrackHits = 0;
141 *fNOutTracks = 0;
142 *fNOutTrackHits = 0;
326c2d4b 143}
144
c259f7e4 145GPUhd() void AliHLTTPCCATracker::SetPointersCommon()
146{
147 // set all pointers to the event memory
148
4acc2401 149 char *mem = fCommonMemory;
150 AssignMemory( fNTracklets, mem, 1 );
151 AssignMemory( fNTracks, mem, 1 );
152 AssignMemory( fNTrackHits, mem, 1 );
153 AssignMemory( fNOutTracks, mem, 1 );
154 AssignMemory( fNOutTrackHits, mem, 1 );
c259f7e4 155
156 // calculate the size
157
4acc2401 158 fCommonMemorySize = mem - fCommonMemory;
c259f7e4 159}
160
161
fbb9b71b 162GPUhd() void AliHLTTPCCATracker::SetPointersHits( int MaxNHits )
c259f7e4 163{
164 // set all pointers to the event memory
165
4acc2401 166 char *mem = fHitMemory;
c259f7e4 167
168 // extra arrays for tpc clusters
c259f7e4 169
4acc2401 170 AssignMemory( fTrackletStartHits, mem, MaxNHits );
c259f7e4 171
172 // arrays for track hits
173
4acc2401 174 AssignMemory( fTrackHits, mem, 10 * MaxNHits );
fbb9b71b 175
4acc2401 176 AssignMemory( fOutTrackHits, mem, 10 * MaxNHits );
c259f7e4 177
178 // calculate the size
179
4acc2401 180 fHitMemorySize = mem - fHitMemory;
c259f7e4 181}
182
183
fbb9b71b 184GPUhd() void AliHLTTPCCATracker::SetPointersTracks( int MaxNTracks, int MaxNHits )
c259f7e4 185{
186 // set all pointers to the tracks memory
187
4acc2401 188 char *mem = fTrackMemory;
fbb9b71b 189
c259f7e4 190 // memory for tracklets
191
4acc2401 192 AssignMemory( fTracklets, mem, MaxNTracks );
fbb9b71b 193
c259f7e4 194 // memory for selected tracks
fbb9b71b 195
4acc2401 196 AssignMemory( fTracks, mem, MaxNTracks );
fbb9b71b 197
63d8b79d 198 // memory for output
199
4acc2401 200 AlignTo < sizeof( void * ) > ( mem );
201 fOutput = reinterpret_cast<AliHLTTPCCASliceOutput *>( mem );
fbb9b71b 202 mem += AliHLTTPCCASliceOutput::EstimateSize( MaxNTracks, MaxNHits );
203
c259f7e4 204 // memory for output tracks
205
4acc2401 206 AssignMemory( fOutTracks, mem, MaxNTracks );
c259f7e4 207
208 // calculate the size
209
4acc2401 210 fTrackMemorySize = mem - fTrackMemory;
c259f7e4 211}
212
326c2d4b 213
4acc2401 214void AliHLTTPCCATracker::ReadEvent( AliHLTTPCCAClusterData *clusterData )
326c2d4b 215{
6de2bc40 216 // read event
217
4acc2401 218 fClusterData = clusterData;
d54804bf 219
c259f7e4 220 StartEvent();
fbb9b71b 221
4acc2401 222 //* Convert input hits, create grids, etc.
223 fData.InitFromClusterData( *clusterData );
fbb9b71b 224
4687b8fc 225 {
4acc2401 226 SetPointersHits( fData.NumberOfHits() ); // to calculate the size
fbb9b71b 227 fHitMemory = reinterpret_cast<char*> ( new uint4 [ fHitMemorySize/sizeof( uint4 ) + 100] );
4acc2401 228 SetPointersHits( fData.NumberOfHits() ); // set pointers for hits
4687b8fc 229 *fNTracklets = 0;
230 *fNTracks = 0 ;
231 *fNOutTracks = 0;
232 *fNOutTrackHits = 0;
233 }
d54804bf 234}
235
00d07bcd 236GPUh() void AliHLTTPCCATracker::Reconstruct()
237{
238 //* reconstruction of event
4acc2401 239 //std::cout<<"Reconstruct slice "<<fParam.ISlice()<<", nHits="<<NHitsTotal()<<std::endl;
326c2d4b 240
00d07bcd 241 fTimers[0] = 0; // find neighbours
242 fTimers[1] = 0; // construct tracklets
243 fTimers[2] = 0; // fit tracklets
244 fTimers[3] = 0; // prolongation of tracklets
245 fTimers[4] = 0; // selection
246 fTimers[5] = 0; // write output
247 fTimers[6] = 0;
248 fTimers[7] = 0;
fbb9b71b 249
693d2443 250 //if( fParam.ISlice()<1 ) return; //SG!!!
00d07bcd 251
00d07bcd 252 TStopwatch timer0;
4687b8fc 253
4acc2401 254 if ( NHitsTotal() < 1 ) {
63d8b79d 255 {
fbb9b71b 256 SetPointersTracks( 1, 1 ); // to calculate the size
257 fTrackMemory = reinterpret_cast<char*> ( new uint4 [ fTrackMemorySize/sizeof( uint4 ) + 100] );
258 SetPointersTracks( 1, 1 ); // set pointers for tracks
259 fOutput->SetNTracks( 0 );
260 fOutput->SetNTrackClusters( 0 );
63d8b79d 261 }
693d2443 262
63d8b79d 263 return;
264 }
6de2bc40 265#ifdef DRAW1
266 //if( fParam.ISlice()==15){
fbb9b71b 267 AliHLTTPCCADisplay::Instance().ClearView();
693d2443 268 AliHLTTPCCADisplay::Instance().SetSliceView();
269 AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
fbb9b71b 270 AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
4acc2401 271 if ( NHitsTotal() > 0 ) {
fbb9b71b 272 AliHLTTPCCADisplay::Instance().DrawSliceHits( kRed, .5 );
693d2443 273 AliHLTTPCCADisplay::Instance().Ask();
274 }
6de2bc40 275 //}
693d2443 276#endif
277
00d07bcd 278 *fNTracks = 0;
4687b8fc 279 *fNTracklets = 0;
280
fbb9b71b 281#if !defined(HLTCA_GPUCODE)
282
00d07bcd 283 AliHLTTPCCAProcess<AliHLTTPCCANeighboursFinder>( Param().NRows(), 1, *this );
693d2443 284
fbb9b71b 285#ifdef HLTCA_INTERNAL_PERFORMANCE
286 //if( Param().ISlice()<=2 )
ce565086 287 //AliHLTTPCCAPerformance::Instance().LinkPerformance( Param().ISlice() );
288#endif
289
290
291#ifdef DRAW
4acc2401 292 if ( NHitsTotal() > 0 ) {
fbb9b71b 293 AliHLTTPCCADisplay::Instance().DrawSliceLinks( -1, -1, 1 );
ce565086 294 AliHLTTPCCADisplay::Instance().Ask();
295 }
296#endif
297
298
fbb9b71b 299 AliHLTTPCCAProcess<AliHLTTPCCANeighboursCleaner>( Param().NRows() - 2, 1, *this );
300 AliHLTTPCCAProcess<AliHLTTPCCAStartHitsFinder>( Param().NRows() - 4, 1, *this );
301
302 int nStartHits = *fNTracklets;
d54804bf 303
fbb9b71b 304 int nThreads = 128;
4acc2401 305 int nBlocks = NHitsTotal() / nThreads + 1;
fbb9b71b 306 if ( nBlocks < 12 ) {
307 nBlocks = 12;
4acc2401 308 nThreads = NHitsTotal() / 12 + 1;
fbb9b71b 309 if ( nThreads % 32 ) nThreads = ( nThreads / 32 + 1 ) * 32;
326c2d4b 310 }
fbb9b71b 311
4acc2401 312 nThreads = NHitsTotal();
00d07bcd 313 nBlocks = 1;
dc4788ec 314
4acc2401 315 fData.ClearHitWeights();
316 //AliHLTTPCCAProcess<AliHLTTPCCAUsedHitsInitialiser>( nBlocks, nThreads, *this );
dc4788ec 317
c259f7e4 318
319 {
4acc2401 320 SetPointersTracks( nStartHits, NHitsTotal() ); // to calculate the size
fbb9b71b 321 fTrackMemory = reinterpret_cast<char*> ( new uint4 [ fTrackMemorySize/sizeof( uint4 ) + 100] );
4acc2401 322 SetPointersTracks( nStartHits, NHitsTotal() ); // set pointers for hits
c259f7e4 323 }
324
fbb9b71b 325 int nMemThreads = AliHLTTPCCATrackletConstructor::NMemThreads();
00d07bcd 326 nThreads = 256;//96;
fbb9b71b 327 nBlocks = nStartHits / nThreads + 1;
328 if ( nBlocks < 30 ) {
00d07bcd 329 nBlocks = 30;
fbb9b71b 330 nThreads = ( nStartHits ) / 30 + 1;
331 if ( nThreads % 32 ) nThreads = ( nThreads / 32 + 1 ) * 32;
00d07bcd 332 }
d54804bf 333
00d07bcd 334 nThreads = nStartHits;
335 nBlocks = 1;
d54804bf 336
fbb9b71b 337 AliHLTTPCCAProcess1<AliHLTTPCCATrackletConstructor>( nBlocks, nMemThreads + nThreads, *this );
d54804bf 338
4acc2401 339 //std::cout<<"Slice "<<Param().ISlice()<<": NHits="<<NHitsTotal()<<", NTracklets="<<*NTracklets()<<std::endl;
ce565086 340
fbb9b71b 341 {
00d07bcd 342 nThreads = 128;
fbb9b71b 343 nBlocks = nStartHits / nThreads + 1;
344 if ( nBlocks < 12 ) {
345 nBlocks = 12;
346 nThreads = nStartHits / 12 + 1;
347 nThreads = ( nThreads / 32 + 1 ) * 32;
00d07bcd 348 }
fbb9b71b 349
4687b8fc 350 *fNTrackHits = 0;
d54804bf 351
00d07bcd 352 nThreads = nStartHits;
353 nBlocks = 1;
d54804bf 354
d54804bf 355
fbb9b71b 356 AliHLTTPCCAProcess<AliHLTTPCCATrackletSelector>( nBlocks, nThreads, *this );
d54804bf 357
693d2443 358 //std::cout<<"Slice "<<Param().ISlice()<<": N start hits/tracklets/tracks = "<<nStartHits<<" "<<nStartHits<<" "<<*fNTracks<<std::endl;
fbb9b71b 359 }
c259f7e4 360
361 //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;
362
fbb9b71b 363
364 WriteOutput();
365
d54804bf 366
693d2443 367#endif
368
369#ifdef DRAW
fbb9b71b 370 {
371 AliHLTTPCCADisplay &disp = AliHLTTPCCADisplay::Instance();
372 AliHLTTPCCATracker &slice = *this;
373 std::cout << "N out tracks = " << *slice.NOutTracks() << std::endl;
374 //disp.Ask();
375 AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
376 AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
377 disp.DrawSliceHits( -1, .5 );
378 for ( int itr = 0; itr < *slice.NOutTracks(); itr++ ) {
379 std::cout << "track N " << itr << ", nhits=" << slice.OutTracks()[itr].NHits() << std::endl;
380 disp.DrawSliceOutTrack( itr, kBlue );
381 //disp.Ask();
382 //int id = slice.OutTracks()[itr].OrigTrackID();
383 //AliHLTTPCCATrack &tr = Tracks()[id];
384 //for( int ih=0; ih<tr.NHits(); ih++ ){
385 //int ic = (fTrackHits[tr.FirstHitID()+ih]);
386 //std::cout<<ih<<" "<<ID2IRow(ic)<<" "<<ID2IHit(ic)<<std::endl;
387 //}
388 //disp.DrawSliceTrack( id, kBlue );
389 //disp.Ask();
390 }
391 disp.Ask();
392 }
d54804bf 393#endif
dc4788ec 394
fbb9b71b 395 timer0.Stop();
396 fTimers[0] = timer0.CpuTime() / 100.;
326c2d4b 397
fbb9b71b 398}
326c2d4b 399
d54804bf 400
401
d54804bf 402
00d07bcd 403GPUh() void AliHLTTPCCATracker::WriteOutput()
404{
d54804bf 405 // write output
eb30eb49 406
00d07bcd 407 TStopwatch timer;
63d8b79d 408
4acc2401 409 //cout<<"output: nTracks = "<<*fNTracks<<", nHitsTotal="<<NHitsTotal()<<std::endl;
63d8b79d 410
63d8b79d 411 fOutput->SetNTracks( *fNTracks );
412 fOutput->SetNTrackClusters( *fNTrackHits );
413 fOutput->SetPointers();
414
fbb9b71b 415 int nStoredHits = 0;
15d2e9cf 416
fbb9b71b 417 for ( int iTr = 0; iTr < *fNTracks; iTr++ ) {
418 AliHLTTPCCATrack &iTrack = fTracks[iTr];
63d8b79d 419
63d8b79d 420 AliHLTTPCCASliceTrack out;
421 out.SetFirstClusterRef( nStoredHits );
fbb9b71b 422 out.SetNClusters( iTrack.NHits() );
63d8b79d 423 out.SetParam( iTrack.Param() );
424
425 fOutput->SetTrack( iTr, out );
426
fbb9b71b 427 int iID = iTrack.FirstHitID();
428 for ( int ith = 0; ith < iTrack.NHits(); ith++ ) {
4acc2401 429 const AliHLTTPCCAHitId &ic = fTrackHits[iID + ith];
430 int iRow = ic.RowIndex();
431 int ih = ic.HitIndex();
fbb9b71b 432
4acc2401 433 const AliHLTTPCCARow &row = fData.Row( iRow );
15d2e9cf 434
fbb9b71b 435 //float y0 = row.Grid().YMin();
436 //float z0 = row.Grid().ZMin();
437 //float stepY = row.HstepY();
438 //float stepZ = row.HstepZ();
439 //float x = row.X();
63d8b79d 440
15d2e9cf 441 //const uint4 *tmpint4 = RowData() + row.FullOffset();
442 //const ushort2 *hits = reinterpret_cast<const ushort2*>(tmpint4);
443 //ushort2 hh = hits[ih];
fbb9b71b 444 //float y = y0 + hh.x*stepY;
445 //float z = z0 + hh.y*stepZ;
63d8b79d 446
16b802c5 447 int clusterIndex = fData.ClusterDataIndex( row, ih );
448 int clusterRowIndex = clusterIndex - fClusterData->RowOffset( iRow );
4acc2401 449
16b802c5 450 if ( clusterIndex < 0 || clusterIndex >= fClusterData->NumberOfClusters() ) {
4acc2401 451 //std::cout << inpIDtot << ", " << fClusterData->NumberOfClusters()
452 //<< "; " << inpID << ", " << fClusterData->NumberOfClusters( iRow ) << std::endl;
453 //abort();
454 continue;
455 }
16b802c5 456 if ( clusterRowIndex < 0 || clusterRowIndex >= fClusterData->NumberOfClusters( iRow ) ) {
4acc2401 457 //std::cout << inpIDtot << ", " << fClusterData->NumberOfClusters()
458 //<< "; " << inpID << ", " << fClusterData->NumberOfClusters( iRow ) << std::endl;
459 //abort();
460 continue;
461 }
63d8b79d 462
16b802c5 463 float origX = fClusterData->X( clusterIndex );
464 float origY = fClusterData->Y( clusterIndex );
465 float origZ = fClusterData->Z( clusterIndex );
466
467
6de2bc40 468 int id = fClusterData->Id( clusterIndex );
15d2e9cf 469
fbb9b71b 470 unsigned short hPackedYZ = 0;
63d8b79d 471 UChar_t hPackedAmp = 0;
4acc2401 472 float2 hUnpackedYZ;
473 hUnpackedYZ.x = origY;
474 hUnpackedYZ.y = origZ;
15d2e9cf 475 float hUnpackedX = origX;
476
6de2bc40 477 fOutput->SetClusterId( nStoredHits, id );
b8139972 478 fOutput->SetClusterRow( nStoredHits, ( unsigned char ) iRow );
63d8b79d 479 fOutput->SetClusterPackedYZ( nStoredHits, hPackedYZ );
fbb9b71b 480 fOutput->SetClusterPackedAmp( nStoredHits, hPackedAmp );
63d8b79d 481 fOutput->SetClusterUnpackedYZ( nStoredHits, hUnpackedYZ );
15d2e9cf 482 fOutput->SetClusterUnpackedX( nStoredHits, hUnpackedX );
63d8b79d 483 nStoredHits++;
484 }
485 }
fbb9b71b 486
487
488 // old stuff
63d8b79d 489
4687b8fc 490 *fNOutTrackHits = 0;
491 *fNOutTracks = 0;
492
4687b8fc 493
fbb9b71b 494 for ( int iTr = 0; iTr < *fNTracks; iTr++ ) {
4687b8fc 495
4acc2401 496 const AliHLTTPCCATrack &iTrack = fTracks[iTr];
4687b8fc 497
4acc2401 498 //std::cout<<"iTr = "<<iTr<<", nHits="<<iTrack.NHits()<<std::endl;
693d2443 499
500 //if( !iTrack.Alive() ) continue;
fbb9b71b 501 if ( iTrack.NHits() < 3 ) continue;
4687b8fc 502 AliHLTTPCCAOutTrack &out = fOutTracks[*fNOutTracks];
693d2443 503 out.SetFirstHitRef( *fNOutTrackHits );
504 out.SetNHits( 0 );
fbb9b71b 505 out.SetOrigTrackID( iTr );
693d2443 506 out.SetStartPoint( iTrack.Param() );
fbb9b71b 507 out.SetEndPoint( iTrack.Param() );
508
509 int iID = iTrack.FirstHitID();
510 int nOutTrackHitsOld = *fNOutTrackHits;
511
512 for ( int ith = 0; ith < iTrack.NHits(); ith++ ) {
4acc2401 513 const AliHLTTPCCAHitId &ic = fTrackHits[iID + ith];
514 const AliHLTTPCCARow &row = Row( ic );
515 int ih = ic.HitIndex();
516 fOutTrackHits[*fNOutTrackHits] = HitInputID( row, ih );
fbb9b71b 517 ( *fNOutTrackHits )++;
4acc2401 518 //std::cout<<"write i,row,hit,id="<<ith<<", "<<ID2IRow(ic)<<", "<<ih<<", "<<HitInputID( row, ih )<<std::endl;
519 if ( *fNOutTrackHits >= 10*NHitsTotal() ) {
520 std::cout << "fNOutTrackHits>NHitsTotal()" << std::endl;
fbb9b71b 521 //exit(0);
522 return;//SG!!!
eb30eb49 523 }
fbb9b71b 524 out.SetNHits( out.NHits() + 1 );
525 }
526 if ( out.NHits() >= 2 ) {
527 ( *fNOutTracks )++;
528 } else {
529 ( *fNOutTrackHits ) = nOutTrackHitsOld;
d54804bf 530 }
531 }
63d8b79d 532
533
00d07bcd 534 timer.Stop();
fbb9b71b 535 fTimers[5] += timer.CpuTime();
326c2d4b 536}
537
4acc2401 538GPUh() void AliHLTTPCCATracker::FitTrackFull( const AliHLTTPCCATrack &/**/, float * /**/ ) const
fbb9b71b 539{
00d07bcd 540 // fit track with material
fbb9b71b 541#ifdef XXX
542 //* Fit the track
00d07bcd 543 FitTrack( iTrack, tt0 );
fbb9b71b 544 if ( iTrack.NHits() <= 3 ) return;
545
00d07bcd 546 AliHLTTPCCATrackParam &t = iTrack.Param();
547 AliHLTTPCCATrackParam t0 = t;
548
549 t.Chi2() = 0;
fbb9b71b 550 t.NDF() = -5;
551 bool first = 1;
552
553 int iID = iTrack.FirstHitID();
554 for ( int ih = 0; ih < iTrack.NHits(); ih++, iID++ ) {
4acc2401 555 const AliHLTTPCCAHitId &ic = fTrackHits[iID];
556 int iRow = ic.rowIndex();
557 const AliHLTTPCCARow &row = fData.Row( iRow );
fbb9b71b 558 if ( !t0.TransportToX( row.X() ) ) continue;
559 float dy, dz;
4acc2401 560 const AliHLTTPCCAHit &h = ic.hitIndex();
fbb9b71b 561
562 // check for wrong hits
563 if ( 0 ) {
00d07bcd 564 dy = t0.GetY() - h.Y();
565 dz = t0.GetZ() - h.Z();
fbb9b71b 566
00d07bcd 567 //if( dy*dy > 3.5*3.5*(/*t0.GetErr2Y() + */h.ErrY()*h.ErrY() ) ) continue;//SG!!!
fbb9b71b 568 //if( dz*dz > 3.5*3.5*(/*t0.GetErr2Z() + */h.ErrZ()*h.ErrZ() ) ) continue;
00d07bcd 569 }
326c2d4b 570
fbb9b71b 571 if ( !t.TransportToX( row.X() ) ) continue;
dc4788ec 572
00d07bcd 573 //* Update the track
fbb9b71b 574
575 if ( first ) {
576 t.Cov()[ 0] = .5 * .5;
00d07bcd 577 t.Cov()[ 1] = 0;
fbb9b71b 578 t.Cov()[ 2] = .5 * .5;
00d07bcd 579 t.Cov()[ 3] = 0;
580 t.Cov()[ 4] = 0;
fbb9b71b 581 t.Cov()[ 5] = .2 * .2;
00d07bcd 582 t.Cov()[ 6] = 0;
583 t.Cov()[ 7] = 0;
584 t.Cov()[ 8] = 0;
fbb9b71b 585 t.Cov()[ 9] = .2 * .2;
00d07bcd 586 t.Cov()[10] = 0;
587 t.Cov()[11] = 0;
588 t.Cov()[12] = 0;
589 t.Cov()[13] = 0;
fbb9b71b 590 t.Cov()[14] = .2 * .2;
00d07bcd 591 t.Chi2() = 0;
592 t.NDF() = -5;
593 }
fbb9b71b 594 float err2Y, err2Z;
00d07bcd 595 GetErrors2( iRow, t, err2Y, err2Z );
596
fbb9b71b 597 if ( !t.Filter2( h.Y(), h.Z(), err2Y, err2Z ) ) continue;
00d07bcd 598
fbb9b71b 599 first = 0;
600 }
00d07bcd 601 /*
fbb9b71b 602 float cosPhi = iTrack.Param().GetCosPhi();
00d07bcd 603 p0.Param().TransportToX(ID2Row( iTrack.PointID()[0] ).X());
fbb9b71b 604 p2.Param().TransportToX(ID2Row( iTrack.PointID()[1] ).X());
00d07bcd 605 if( p0.Param().GetCosPhi()*cosPhi<0 ){ // change direction
fbb9b71b 606 float *par = p0.Param().Par();
607 float *cov = p0.Param().Cov();
00d07bcd 608 par[2] = -par[2]; // sin phi
609 par[3] = -par[3]; // DzDs
610 par[4] = -par[4]; // kappa
611 cov[3] = -cov[3];
612 cov[4] = -cov[4];
613 cov[6] = -cov[6];
614 cov[7] = -cov[7];
615 cov[10] = -cov[10];
616 cov[11] = -cov[11];
617 p0.Param().CosPhi() = -p0.Param().GetCosPhi();
618 }
619 */
620#endif
621}
dc4788ec 622
4acc2401 623GPUh() void AliHLTTPCCATracker::FitTrack( const AliHLTTPCCATrack &/*track*/, float * /*t0[]*/ ) const
fbb9b71b 624{
625 //* Fit the track
00d07bcd 626#ifdef XXX
fbb9b71b 627 AliHLTTPCCAEndPoint &p2 = ID2Point( track.PointID()[1] );
4acc2401 628 const AliHLTTPCCAHit &c0 = ID2Hit( fTrackHits[p0.TrackHitID()].HitID() );
629 const AliHLTTPCCAHit &c1 = ID2Hit( fTrackHits[track.HitID()[1]].HitID() );
630 const AliHLTTPCCAHit &c2 = ID2Hit( fTrackHits[p2.TrackHitID()].HitID() );
631 const AliHLTTPCCARow &row0 = ID2Row( fTrackHits[p0.TrackHitID()].HitID() );
632 const AliHLTTPCCARow &row1 = ID2Row( fTrackHits[track.HitID()[1]].HitID() );
633 const AliHLTTPCCARow &row2 = ID2Row( fTrackHits[p2.TrackHitID()].HitID() );
fbb9b71b 634 float sp0[5] = {row0.X(), c0.Y(), c0.Z(), c0.ErrY(), c0.ErrZ() };
635 float sp1[5] = {row1.X(), c1.Y(), c1.Z(), c1.ErrY(), c1.ErrZ() };
636 float sp2[5] = {row2.X(), c2.Y(), c2.Z(), c2.ErrY(), c2.ErrZ() };
4acc2401 637 //std::cout<<"Fit track, points ="<<sp0[0]<<" "<<sp0[1]<<" / "<<sp1[0]<<" "<<sp1[1]<<" / "<<sp2[0]<<" "<<sp2[1]<<std::endl;
fbb9b71b 638 if ( track.NHits() >= 3 ) {
639 p0.Param().ConstructXYZ3( sp0, sp1, sp2, p0.Param().CosPhi(), t0 );
640 p2.Param().ConstructXYZ3( sp2, sp1, sp0, p2.Param().CosPhi(), t0 );
d54804bf 641 //p2.Param() = p0.Param();
642 //p2.Param().TransportToX(row2.X());
643 //p2.Param().Par()[1] = -p2.Param().Par()[1];
644 //p2.Param().Par()[4] = -p2.Param().Par()[4];
645 } else {
646 p0.Param().X() = row0.X();
647 p0.Param().Y() = c0.Y();
648 p0.Param().Z() = c0.Z();
fbb9b71b 649 p0.Param().Err2Y() = c0.ErrY() * c0.ErrY();
650 p0.Param().Err2Z() = c0.ErrZ() * c0.ErrZ();
d54804bf 651 p2.Param().X() = row2.X();
652 p2.Param().Y() = c2.Y();
653 p2.Param().Z() = c2.Z();
fbb9b71b 654 p2.Param().Err2Y() = c2.ErrY() * c2.ErrY();
655 p2.Param().Err2Z() = c2.ErrZ() * c2.ErrZ();
326c2d4b 656 }
00d07bcd 657#endif
658}
659
660
fbb9b71b 661GPUd() void AliHLTTPCCATracker::GetErrors2( int iRow, float z, float sinPhi, float cosPhi, float DzDs, float &Err2Y, float &Err2Z ) const
693d2443 662{
663 //
664 // Use calibrated cluster error from OCDB
665 //
666
63d8b79d 667 fParam.GetClusterErrors2( iRow, z, sinPhi, cosPhi, DzDs, Err2Y, Err2Z );
693d2443 668}
669
fbb9b71b 670GPUd() void AliHLTTPCCATracker::GetErrors2( int iRow, const AliHLTTPCCATrackParam &t, float &Err2Y, float &Err2Z ) const
00d07bcd 671{
672 //
673 // Use calibrated cluster error from OCDB
674 //
675
15d2e9cf 676 fParam.GetClusterErrors2( iRow, t.GetZ(), t.SinPhi(), t.GetCosPhi(), t.DzDs(), Err2Y, Err2Z );
00d07bcd 677}
678
4687b8fc 679
fbb9b71b 680#if !defined(HLTCA_GPUCODE)
4687b8fc 681
fbb9b71b 682GPUh() void AliHLTTPCCATracker::WriteEvent( std::ostream &out )
00d07bcd 683{
4687b8fc 684 // write event to the file
fbb9b71b 685 for ( int iRow = 0; iRow < fParam.NRows(); iRow++ ) {
4acc2401 686 out << fData.Row( iRow ).HitNumberOffset() << " " << fData.Row( iRow ).NHits() << std::endl;
fbb9b71b 687 }
4acc2401 688 out << NHitsTotal() << std::endl;
fbb9b71b 689
4acc2401 690 AliHLTResizableArray<float> y( NHitsTotal() ), z( NHitsTotal() );
fbb9b71b 691
692 for ( int iRow = 0; iRow < fParam.NRows(); iRow++ ) {
4acc2401 693 const AliHLTTPCCARow &row = Row( iRow );
fbb9b71b 694 float y0 = row.Grid().YMin();
695 float z0 = row.Grid().ZMin();
696 float stepY = row.HstepY();
697 float stepZ = row.HstepZ();
4acc2401 698 for ( int ih = 0; ih < fData.Row( iRow ).NHits(); ih++ ) {
699 int id = HitInputID( row, ih );
700 y[id] = y0 + HitDataY( row, ih ) * stepY;
701 z[id] = z0 + HitDataZ( row, ih ) * stepZ;
4687b8fc 702 }
703 }
4acc2401 704 for ( int ih = 0; ih < NHitsTotal(); ih++ ) {
fbb9b71b 705 out << y[ih] << " " << z[ih] << std::endl;
4687b8fc 706 }
fbb9b71b 707}
4687b8fc 708
fbb9b71b 709GPUh() void AliHLTTPCCATracker::WriteTracks( std::ostream &out )
4687b8fc 710{
fbb9b71b 711 //* Write tracks to file
712
713 out << fTimers[0] << std::endl;
714 out << *fNOutTrackHits << std::endl;
715 for ( int ih = 0; ih < *fNOutTrackHits; ih++ ) {
716 out << fOutTrackHits[ih] << " ";
4687b8fc 717 }
fbb9b71b 718 out << std::endl;
719
720 out << *fNOutTracks << std::endl;
721
722 for ( int itr = 0; itr < *fNOutTracks; itr++ ) {
723 AliHLTTPCCAOutTrack &t = fOutTracks[itr];
724 AliHLTTPCCATrackParam p1 = t.StartPoint();
725 AliHLTTPCCATrackParam p2 = t.EndPoint();
726 out << t.NHits() << " ";
727 out << t.FirstHitRef() << " ";
728 out << t.OrigTrackID() << " ";
729 out << std::endl;
730 out << p1.X() << " ";
731 out << p1.SignCosPhi() << " ";
732 out << p1.Chi2() << " ";
733 out << p1.NDF() << std::endl;
734 for ( int i = 0; i < 5; i++ ) out << p1.Par()[i] << " ";
735 out << std::endl;
736 for ( int i = 0; i < 15; i++ ) out << p1.Cov()[i] << " ";
737 out << std::endl;
738 out << p2.X() << " ";
739 out << p2.SignCosPhi() << " ";
740 out << p2.Chi2() << " ";
741 out << p2.NDF() << std::endl;
742 for ( int i = 0; i < 5; i++ ) out << p2.Par()[i] << " ";
743 out << std::endl;
744 for ( int i = 0; i < 15; i++ ) out << p2.Cov()[i] << " ";
745 out << std::endl;
4687b8fc 746 }
747}
748
749GPUh() void AliHLTTPCCATracker::ReadTracks( std::istream &in )
750{
fbb9b71b 751 //* Read tracks from file
752 in >> fTimers[0];
753 in >> *fNOutTrackHits;
4687b8fc 754
fbb9b71b 755 for ( int ih = 0; ih < *fNOutTrackHits; ih++ ) {
756 in >> fOutTrackHits[ih];
4687b8fc 757 }
fbb9b71b 758 in >> *fNOutTracks;
4687b8fc 759
fbb9b71b 760 for ( int itr = 0; itr < *fNOutTracks; itr++ ) {
761 AliHLTTPCCAOutTrack &t = fOutTracks[itr];
693d2443 762 AliHLTTPCCATrackParam p1, p2;
fbb9b71b 763 int i;
764 float f;
765 in >> i; t.SetNHits( i );
766 in >> i; t.SetFirstHitRef( i );
767 in >> i; t.SetOrigTrackID( i );
768 in >> f; p1.SetX( f );
769 in >> f; p1.SetSignCosPhi( f );
770 in >> f; p1.SetChi2( f );
771 in >> i; p1.SetNDF( i );
772 for ( int j = 0; j < 5; j++ ) { in >> f; p1.SetPar( j, f ); }
773 for ( int j = 0; j < 15; j++ ) { in >> f; p1.SetCov( j, f ); }
774 in >> f; p2.SetX( f );
775 in >> f; p2.SetSignCosPhi( f );
776 in >> f; p2.SetChi2( f );
777 in >> i; p2.SetNDF( i );
778 for ( int j = 0; j < 5; j++ ) { in >> f; p2.SetPar( j, f ); }
779 for ( int j = 0; j < 15; j++ ) { in >> f; p2.SetCov( j, f ); }
693d2443 780 t.SetStartPoint( p1 );
781 t.SetEndPoint( p2 );
4687b8fc 782 }
326c2d4b 783}
4687b8fc 784#endif