2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
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. *
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. *
18 //***************************************************************************
20 #include "AliHLTTPCCATracker.h"
21 #include "AliHLTTPCCAOutTrack.h"
22 #include "AliHLTTPCCAGrid.h"
23 #include "AliHLTTPCCARow.h"
24 #include "AliHLTTPCCATrack.h"
25 #include "AliHLTTPCCATracklet.h"
26 #include "AliHLTTPCCAMath.h"
27 #include "AliHLTTPCCAHit.h"
29 #include "TStopwatch.h"
30 #include "AliHLTTPCCAHitArea.h"
31 #include "AliHLTTPCCANeighboursFinder.h"
32 #include "AliHLTTPCCANeighboursCleaner.h"
33 #include "AliHLTTPCCAStartHitsFinder.h"
34 #include "AliHLTTPCCATrackletConstructor.h"
35 #include "AliHLTTPCCATrackletSelector.h"
36 #include "AliHLTTPCCAProcess.h"
37 #include "AliHLTTPCCAUsedHitsInitialiser.h"
38 #include "AliHLTTPCCASliceTrack.h"
39 #include "AliHLTTPCCASliceOutput.h"
40 #include "AliHLTTPCCADataCompressor.h"
42 #include "AliHLTTPCCATrackParam.h"
44 #if !defined(HLTCA_GPUCODE)
51 #include "AliHLTTPCCADisplay.h"
54 #ifdef HLTCA_INTERNAL_PERFORMANCE
55 #include "AliHLTTPCCAPerformance.h"
59 ClassImp(AliHLTTPCCATracker)
61 #if !defined(HLTCA_GPUCODE)
63 AliHLTTPCCATracker::AliHLTTPCCATracker()
80 fTrackletStartHits(0),
96 AliHLTTPCCATracker::AliHLTTPCCATracker( const AliHLTTPCCATracker& )
101 fCommonMemorySize(0),
113 fTrackletStartHits(0),
129 AliHLTTPCCATracker &AliHLTTPCCATracker::operator=( const AliHLTTPCCATracker& )
138 GPUd() AliHLTTPCCATracker::~AliHLTTPCCATracker()
141 if( fCommonMemory ) delete[] fCommonMemory;
142 if( fHitMemory ) delete[] fHitMemory;
143 if( fTrackMemory ) delete[] fTrackMemory;
144 if( fTmpHitInputIDs ) delete[] fTmpHitInputIDs;
150 // ----------------------------------------------------------------------------------
151 GPUd() void AliHLTTPCCATracker::Initialize( const AliHLTTPCCAParam ¶m )
156 for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
157 fRows[irow].SetX( fParam.RowX(irow) );
158 fRows[irow].SetMaxY( CAMath::Tan( fParam.DAlpha()/2.)*fRows[irow].X() );
163 GPUd() void AliHLTTPCCATracker::StartEvent()
165 // start new event and fresh the memory
167 if( !fCommonMemory ){
168 SetPointersCommon(); // just to calculate the size
169 fCommonMemory = reinterpret_cast<Char_t*> ( new uint4 [ fCommonMemorySize/sizeof(uint4) + 100] );
170 SetPointersCommon();// set pointers
173 if( fHitMemory ) delete[] fHitMemory;
175 if( fTrackMemory ) delete[] fTrackMemory;
184 if( fTmpHitInputIDs ) delete[] fTmpHitInputIDs;
190 GPUhd() void AliHLTTPCCATracker::SetPointersCommon()
192 // set all pointers to the event memory
194 ULong_t mem = (ULong_t) fCommonMemory;
195 UInt_t sI = sizeof(Int_t);
199 fNTracklets = (Int_t*) mem;
201 fNTracks = (Int_t*) mem;
203 fNTrackHits = (Int_t*) mem;
205 fNOutTracks = (Int_t*) mem;
207 fNOutTrackHits = (Int_t*) mem;
210 // calculate the size
212 fCommonMemorySize = mem - (ULong_t) fCommonMemory;
216 GPUhd() void AliHLTTPCCATracker::SetPointersHits( Int_t MaxNHits )
218 // set all pointers to the event memory
220 Int_t gridSizeTotal = 2*(2*MaxNHits + 10*Param().NRows());
221 //gridSizeTotal *=100;//SG!!!
223 ULong_t mem = (ULong_t) fHitMemory;
224 UInt_t sI = sizeof(Int_t);
225 UInt_t sF = sizeof(Float_t);
226 UInt_t sS = sizeof(Short_t);
227 UInt_t s4 = sizeof(uint4);
231 mem = ( mem/s4 + 1 )*s4;
232 fInputEvent = (Char_t*) mem;
233 fInputEventSize = (1+fParam.NRows()*2 + 1)*sI + (MaxNHits*2)*sF;
234 mem+= fInputEventSize;
236 // set cluster data for TPC rows
238 mem = ( mem/s4 + 1 )*s4;
239 fRowData = (uint4*) mem;
240 fRowDataSize = ( 2*MaxNHits*sS + // yz
241 gridSizeTotal*sS + // grid
242 2*MaxNHits*sS + // link up,link down
243 fParam.NRows()*s4 // row alignment
247 // extra arrays for tpc clusters
249 mem = ( mem/sI + 1 )*sI;
251 fHitInputIDs = (Int_t*) mem;
254 fTrackletStartHits = (Int_t*) mem;
257 fHitWeights = (Int_t*) mem;
260 // arrays for track hits
262 fTrackHits = (Int_t*) mem;
263 mem+= 10*MaxNHits*sI;//SG!!!
265 fOutTrackHits = (Int_t*) mem;
266 mem+= 10*MaxNHits*sI; //SG!!!
268 // calculate the size
270 fHitMemorySize = mem - (ULong_t) fHitMemory;
274 GPUhd() void AliHLTTPCCATracker::SetPointersTracks( Int_t MaxNTracks, Int_t MaxNHits )
276 // set all pointers to the tracks memory
278 ULong_t mem = (ULong_t) fTrackMemory;
280 // memory for tracklets
282 mem = ( mem/sizeof(AliHLTTPCCATracklet) + 1 )*sizeof(AliHLTTPCCATracklet);
283 fTracklets = (AliHLTTPCCATracklet *) mem;
284 mem+= MaxNTracks*sizeof(AliHLTTPCCATracklet);
286 // memory for selected tracks
288 mem = ( mem/sizeof(AliHLTTPCCATrack) + 1 )*sizeof(AliHLTTPCCATrack);
289 fTracks = (AliHLTTPCCATrack*) mem;
290 mem+= MaxNTracks*sizeof(AliHLTTPCCATrack);
294 mem = ( mem/sizeof(AliHLTTPCCASliceOutput) + 1 )*sizeof(AliHLTTPCCASliceOutput);
295 fOutput = (AliHLTTPCCASliceOutput*) mem;
296 mem+= AliHLTTPCCASliceOutput::EstimateSize(MaxNTracks, MaxNHits);
298 // memory for output tracks
300 mem = ( mem/sizeof(AliHLTTPCCAOutTrack) + 1 )*sizeof(AliHLTTPCCAOutTrack);
302 fOutTracks = (AliHLTTPCCAOutTrack*) mem;
303 mem+= MaxNTracks*sizeof(AliHLTTPCCAOutTrack);
305 // calculate the size
307 fTrackMemorySize = mem - (ULong_t) fTrackMemory;
312 GPUd() void AliHLTTPCCATracker::ReadEvent( const Int_t *RowFirstHit, const Int_t *RowNHits, const Float_t *Y, const Float_t *Z, Int_t NHits )
321 SetPointersHits(NHits); // to calculate the size
322 fHitMemory = reinterpret_cast<Char_t*> ( new uint4 [ fHitMemorySize/sizeof(uint4) + 100] );
323 SetPointersHits(NHits); // set pointers for hits
330 reinterpret_cast<Int_t*>( fInputEvent )[0] = fParam.NRows();
331 reinterpret_cast<Int_t*>( fInputEvent )[1+fParam.NRows()*2] = NHits;
332 Int_t *rowHeaders = reinterpret_cast<Int_t*>( fInputEvent ) +1;
333 Float_t *hitsYZ = reinterpret_cast<Float_t*>( fInputEvent ) + 1+fParam.NRows()*2+1;
334 for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
335 rowHeaders[iRow*2 ] = RowFirstHit[iRow];
336 rowHeaders[iRow*2+1] = RowNHits[iRow];
338 for( Int_t iHit=0; iHit<NHits; iHit++ ){
339 hitsYZ[iHit*2 ] = Y[iHit];
340 hitsYZ[iHit*2+1] = Z[iHit];
343 //SG cell finder - test code
345 if( fTmpHitInputIDs ) delete[] fTmpHitInputIDs;
346 fTmpHitInputIDs = new Int_t [NHits];
347 const Float_t areaY = .5;
348 const Float_t areaZ = .5;
349 Int_t newRowNHitsTotal = 0;
350 Bool_t *usedHits = new Bool_t [NHits];
351 for( Int_t iHit=0; iHit<NHits; iHit++ ) usedHits[iHit] = 0;
352 for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
353 rowHeaders[iRow*2 ] = newRowNHitsTotal; // new first hit
354 rowHeaders[iRow*2+1] = 0; // new N hits
355 Int_t newRowNHits = 0;
356 Int_t oldRowFirstHit = RowFirstHit[iRow];
357 Int_t oldRowLastHit = oldRowFirstHit + RowNHits[iRow];
358 for( Int_t iHit=oldRowFirstHit; iHit<oldRowLastHit; iHit++ ){
359 if( usedHits[iHit] ) continue;
360 Float_t y0 = Y[iHit];
361 Float_t z0 = Z[iHit];
366 if(0) for( Int_t jHit=iHit+1; jHit<oldRowLastHit; jHit++ ){//SG!!!
367 //if( usedHits[jHit] ) continue;
368 Float_t dy = Y[jHit] - y0;
369 Float_t dz = Z[jHit] - z0;
370 if( CAMath::Abs(dy)<areaY && CAMath::Abs(dz)<areaZ ){
377 Int_t id = newRowNHitsTotal+newRowNHits;
378 hitsYZ[id*2 ] = cy/nclu;
379 hitsYZ[id*2+1] = cz/nclu;
380 fTmpHitInputIDs[id] = iHit;
383 rowHeaders[iRow*2+1] = newRowNHits;
384 newRowNHitsTotal+=newRowNHits;
386 fNHitsTotal = newRowNHitsTotal;
387 reinterpret_cast<Int_t*>( fInputEvent )[1+fParam.NRows()*2] = newRowNHitsTotal;
394 GPUd() void AliHLTTPCCATracker::SetupRowData()
396 //* Convert input hits, create grids, etc.
398 fNHitsTotal = reinterpret_cast<Int_t*>( fInputEvent )[1+fParam.NRows()*2];
399 Int_t *rowHeaders = reinterpret_cast<Int_t*>( fInputEvent ) +1;
400 Float_t *hitsYZ = reinterpret_cast<Float_t*>( fInputEvent ) + 1+fParam.NRows()*2+1;
402 for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
404 AliHLTTPCCARow &row = fRows[iRow];
405 row.SetFirstHit( rowHeaders[iRow*2] );
406 row.SetNHits( rowHeaders[iRow*2+1] );
407 Float_t yMin=1.e3, yMax=-1.e3, zMin=1.e3, zMax=-1.e3;
408 Int_t nGrid = row.NHits();
409 for( Int_t i=0; i<row.NHits(); i++ ){
410 Int_t j = row.FirstHit()+i;
411 Float_t y = hitsYZ[j*2];
412 Float_t z = hitsYZ[j*2+1];
413 if( yMax < y ) yMax = y;
414 if( yMin > y ) yMin = y;
415 if( zMax < z ) zMax = z;
416 if( zMin > z ) zMin = z;
419 yMin = yMax = zMin = zMax = 0;
423 AliHLTTPCCAGrid grid;
424 grid.Create( yMin, yMax, zMin, zMax, nGrid );
426 Float_t sy = ( CAMath::Abs( grid.StepYInv() ) >1.e-4 ) ?1./grid.StepYInv() :1;
427 Float_t sz = ( CAMath::Abs( grid.StepZInv() ) >1.e-4 ) ?1./grid.StepZInv() :1;
429 //cout<<"grid n = "<<row.Grid().N()<<" "<<sy<<" "<<sz<<" "<<yMin<<" "<<yMax<<" "<<zMin<<" "<<zMax<<endl;
432 if( sy < 2. ) { recreate = 1; sy = 2; }
433 if( sz < 2. ) { recreate = 1; sz = 2; }
434 //recreate = 1;//SG!!!
437 if( recreate ) grid.Create( yMin, yMax, zMin, zMax, sy, sz );
441 AliHLTTPCCAHit ffHits[fNHitsTotal];
443 Int_t rowDataOffset = 0;
445 for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
447 AliHLTTPCCARow &row = fRows[iRow];
448 const AliHLTTPCCAGrid &grid = row.Grid();
450 Int_t c[grid.N()+3+10];
451 Int_t bins[row.NHits()];
452 Int_t filled[ row.Grid().N() +3+10 ];
454 for( UInt_t bin=0; bin<row.Grid().N()+3; bin++ ) filled[bin] = 0;
456 for( Int_t i=0; i<row.NHits(); i++ ){
457 Int_t j = row.FirstHit()+i;
458 Int_t bin = row.Grid().GetBin( hitsYZ[2*j], hitsYZ[2*j+1] );
465 for( UInt_t bin=0; bin<row.Grid().N()+3; bin++ ){
471 for( Int_t i=0; i<row.NHits(); i++ ){
473 Int_t ind = c[bin] + filled[bin]-1;
475 AliHLTTPCCAHit &h = ffHits[row.FirstHit()+ind];
476 fHitInputIDs[row.FirstHit()+ind] = fTmpHitInputIDs[row.FirstHit()+i];
477 h.SetY( hitsYZ[2*(row.FirstHit()+i)] );
478 h.SetZ( hitsYZ[2*(row.FirstHit()+i)+1] );
483 Float_t y0 = row.Grid().YMin();
484 Float_t stepY = (row.Grid().YMax() - y0)*(1./65535.);
485 Float_t z0 = row.Grid().ZMin();
486 Float_t stepZ = (row.Grid().ZMax() - z0)*(1./65535.);
487 if( stepY<1.e-4 ) stepY = 1.e-4;
488 if( stepZ<1.e-4 ) stepZ = 1.e-4;
489 Float_t stepYi = 1./stepY;
490 Float_t stepZi = 1./stepZ;
494 row.SetHstepY( stepY );
495 row.SetHstepZ( stepZ );
496 row.SetHstepYi( stepYi );
497 row.SetHstepZi( stepZi );
499 row.SetFullOffset( rowDataOffset );
500 ushort2 *p= (ushort2*)( fRowData + row.FullOffset() );
501 for( Int_t ih=0; ih<row.NHits(); ih++ ){
502 Int_t ihTot = row.FirstHit()+ih;
503 AliHLTTPCCAHit &hh = ffHits[ihTot];
504 Float_t xx = ((hh.Y() - y0)*stepYi);
505 Float_t yy = ((hh.Z() - z0)*stepZi);
506 if( xx<0 || yy<0 || xx>=65536 || yy>= 65536 ){
507 std::cout<<"!!!! hit packing error!!! "<<xx<<" "<<yy<<" "<<std::endl;
509 p[ih].x = (UShort_t) xx;
510 p[ih].y = (UShort_t) yy;
512 Int_t size = row.NHits()*sizeof(ushort2);
514 row.SetFullGridOffset( row.NHits()*2 );
515 UShort_t *p1 = ((UShort_t *)p) + row.FullGridOffset();
518 for( Int_t i=0; i<n; i++ ){
522 Int_t nn = n+grid.Ny()+3;
523 for( Int_t i=n; i<nn; i++ ) p1[i] = a;
525 size+= (nn)*sizeof(UShort_t);
526 row.SetFullLinkOffset( row.NHits()*2 + nn );
527 size+= row.NHits()*2*sizeof(Short_t);
529 if( size%16 ) size = size/sizeof(uint4)+1;
530 else size = size/sizeof(uint4);
531 row.SetFullSize( size );
532 //cout<<iRow<<", "<<row.fNHits<<"= "<<size*16<<"b: "<<row.fFullOffset<<" "<<row.fFullSize<<" "<<row.fFullGridOffset<<" "<<row.fFullLinkOffset<<std::endl;
540 GPUh() void AliHLTTPCCATracker::Reconstruct()
542 //* reconstruction of event
543 //std::cout<<"Reconstruct slice "<<fParam.ISlice()<<", nHits="<<fNHitsTotal<<std::endl;
545 fTimers[0] = 0; // find neighbours
546 fTimers[1] = 0; // construct tracklets
547 fTimers[2] = 0; // fit tracklets
548 fTimers[3] = 0; // prolongation of tracklets
549 fTimers[4] = 0; // selection
550 fTimers[5] = 0; // write output
554 //if( fParam.ISlice()<1 ) return; //SG!!!
559 if( fNHitsTotal < 1 ){
561 SetPointersTracks(1, 1); // to calculate the size
562 fTrackMemory = reinterpret_cast<Char_t*> ( new uint4 [ fTrackMemorySize/sizeof(uint4) + 100] );
563 SetPointersTracks(1, 1); // set pointers for tracks
564 fOutput->SetNTracks(0);
565 fOutput->SetNTrackClusters(0);
572 AliHLTTPCCADisplay::Instance().ClearView();
573 AliHLTTPCCADisplay::Instance().SetSliceView();
574 AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
575 AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
577 AliHLTTPCCADisplay::Instance().DrawSliceHits( kRed, 1.);
578 AliHLTTPCCADisplay::Instance().Ask();
585 #if !defined(HLTCA_GPUCODE)
587 AliHLTTPCCAProcess<AliHLTTPCCANeighboursFinder>( Param().NRows(), 1, *this );
589 #ifdef HLTCA_INTERNAL_PERFORMANCE
590 //if( Param().ISlice()<=2 )
591 //AliHLTTPCCAPerformance::Instance().LinkPerformance( Param().ISlice() );
597 AliHLTTPCCADisplay::Instance().DrawSliceLinks( -1, -1, 1);
598 AliHLTTPCCADisplay::Instance().Ask();
603 AliHLTTPCCAProcess<AliHLTTPCCANeighboursCleaner>( Param().NRows()-2, 1, *this );
604 AliHLTTPCCAProcess<AliHLTTPCCAStartHitsFinder>( Param().NRows()-4, 1, *this );
606 Int_t nStartHits = *fNTracklets;
608 Int_t nThreads = 128;
609 Int_t nBlocks = fNHitsTotal/nThreads + 1;
612 nThreads = fNHitsTotal/12+1;
613 if( nThreads%32 ) nThreads = (nThreads/32+1)*32;
616 nThreads = fNHitsTotal;
619 AliHLTTPCCAProcess<AliHLTTPCCAUsedHitsInitialiser>(nBlocks, nThreads,*this);
623 SetPointersTracks(nStartHits, fNHitsTotal); // to calculate the size
624 fTrackMemory = reinterpret_cast<Char_t*> ( new uint4 [ fTrackMemorySize/sizeof(uint4) + 100] );
625 SetPointersTracks(nStartHits, fNHitsTotal); // set pointers for hits
628 Int_t nMemThreads = AliHLTTPCCATrackletConstructor::NMemThreads();
630 nBlocks = nStartHits/nThreads + 1;
633 nThreads = (nStartHits)/30+1;
634 if( nThreads%32 ) nThreads = (nThreads/32+1)*32;
637 nThreads = nStartHits;
640 AliHLTTPCCAProcess1<AliHLTTPCCATrackletConstructor>(nBlocks, nMemThreads+nThreads,*this);
642 //std::cout<<"Slice "<<Param().ISlice()<<": NHits="<<fNHitsTotal<<", NTracklets="<<*NTracklets()<<std::endl;
646 nBlocks = nStartHits/nThreads + 1;
649 nThreads = nStartHits/12+1;
650 nThreads = (nThreads/32+1)*32;
655 nThreads = nStartHits;
659 AliHLTTPCCAProcess<AliHLTTPCCATrackletSelector>(nBlocks, nThreads,*this);
661 //std::cout<<"Slice "<<Param().ISlice()<<": N start hits/tracklets/tracks = "<<nStartHits<<" "<<nStartHits<<" "<<*fNTracks<<std::endl;
664 //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;
674 AliHLTTPCCADisplay &disp = AliHLTTPCCADisplay::Instance();
675 AliHLTTPCCATracker &slice = *this;
676 std::cout<<"N out tracks = "<<*slice.NOutTracks()<<std::endl;
678 AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
679 AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
680 disp.DrawSliceHits(-1,.5);
681 for( Int_t itr=0; itr<*slice.NOutTracks(); itr++ ){
682 std::cout<<"track N "<<itr<<", nhits="<<slice.OutTracks()[itr].NHits()<<std::endl;
683 disp.DrawSliceOutTrack( itr, kBlue );
685 //int id = slice.OutTracks()[itr].OrigTrackID();
686 //AliHLTTPCCATrack &tr = Tracks()[id];
687 //for( Int_t ih=0; ih<tr.NHits(); ih++ ){
688 //Int_t ic = (fTrackHits[tr.FirstHitID()+ih]);
689 //std::cout<<ih<<" "<<ID2IRow(ic)<<" "<<ID2IHit(ic)<<std::endl;
691 //disp.DrawSliceTrack( id, kBlue );
699 fTimers[0] = timer0.CpuTime()/100.;
706 GPUh() void AliHLTTPCCATracker::WriteOutput()
712 //cout<<"output: nTracks = "<<*fNTracks<<", nHitsTotal="<<fNHitsTotal<<std::endl;
715 fOutput->SetNTracks( *fNTracks );
716 fOutput->SetNTrackClusters( *fNTrackHits );
717 fOutput->SetPointers();
719 Int_t nStoredHits = 0;
721 for( Int_t iTr=0; iTr<*fNTracks; iTr++){
722 AliHLTTPCCATrack &iTrack = fTracks[iTr];
724 AliHLTTPCCASliceTrack out;
725 out.SetFirstClusterRef( nStoredHits );
726 out.SetNClusters( iTrack.NHits() );
727 out.SetParam( iTrack.Param() );
729 fOutput->SetTrack( iTr, out );
731 Int_t iID = iTrack.FirstHitID();
732 for( Int_t ith=0; ith<iTrack.NHits(); ith++ ){
733 Int_t ic = (fTrackHits[iID+ith]);
734 Int_t iRow = ID2IRow(ic);
735 Int_t ih = ID2IHit(ic);
736 const AliHLTTPCCARow &row = fRows[iRow];
738 Float_t y0 = row.Grid().YMin();
739 Float_t z0 = row.Grid().ZMin();
740 Float_t stepY = row.HstepY();
741 Float_t stepZ = row.HstepZ();
742 //Float_t x = row.X();
744 const uint4 *tmpint4 = RowData() + row.FullOffset();
745 const ushort2 *hits = reinterpret_cast<const ushort2*>(tmpint4);
746 ushort2 hh = hits[ih];
748 Float_t y = y0 + hh.x*stepY;
749 Float_t z = z0 + hh.y*stepZ;
751 Int_t inpIDtot = fHitInputIDs[row.FirstHit()+ih];
752 Int_t inpID = inpIDtot - row.FirstHit();
754 UInt_t hIDrc = AliHLTTPCCADataCompressor::IRowIClu2IDrc(iRow,inpID);
755 UShort_t hPackedYZ = 0;
756 UChar_t hPackedAmp = 0;
757 float2 hUnpackedYZ = CAMath::MakeFloat2(y,z);
759 fOutput->SetClusterIDrc( nStoredHits, hIDrc );
760 fOutput->SetClusterPackedYZ( nStoredHits, hPackedYZ );
761 fOutput->SetClusterPackedAmp( nStoredHits, hPackedAmp);
762 fOutput->SetClusterUnpackedYZ( nStoredHits, hUnpackedYZ );
774 for( Int_t iTr=0; iTr<*fNTracks; iTr++){
776 AliHLTTPCCATrack &iTrack = fTracks[iTr];
778 //cout<<"iTr = "<<iTr<<", nHits="<<iTrack.NHits()<<std::endl;
780 //if( !iTrack.Alive() ) continue;
781 if( iTrack.NHits()<3 ) continue;
782 AliHLTTPCCAOutTrack &out = fOutTracks[*fNOutTracks];
783 out.SetFirstHitRef( *fNOutTrackHits );
785 out.SetOrigTrackID( iTr );
786 out.SetStartPoint( iTrack.Param() );
787 out.SetEndPoint( iTrack.Param() );
789 Int_t iID = iTrack.FirstHitID();
790 Int_t nOutTrackHitsOld = *fNOutTrackHits;
792 for( Int_t ith=0; ith<iTrack.NHits(); ith++ ){
793 Int_t ic = (fTrackHits[iID+ith]);
794 const AliHLTTPCCARow &row = ID2Row(ic);
795 Int_t ih = ID2IHit(ic);
796 fOutTrackHits[*fNOutTrackHits] = fHitInputIDs[row.FirstHit()+ih];
798 //cout<<"write i,row,hit,id="<<ith<<", "<<ID2IRow(ic)<<", "<<ih<<", "<<fHitInputIDs[row.FirstHit()+ih]<<std::endl;
799 if( *fNOutTrackHits>=10*fNHitsTotal ){
800 std::cout<<"fNOutTrackHits>fNHitsTotal"<<std::endl;
804 out.SetNHits( out.NHits() + 1 );
806 if( out.NHits() >= 2 ){
809 (*fNOutTrackHits) = nOutTrackHitsOld;
815 fTimers[5]+=timer.CpuTime();
818 GPUh() void AliHLTTPCCATracker::FitTrackFull( AliHLTTPCCATrack &/**/, Float_t * /**/ ) const
820 // fit track with material
823 FitTrack( iTrack, tt0 );
824 if( iTrack.NHits()<=3 ) return;
826 AliHLTTPCCATrackParam &t = iTrack.Param();
827 AliHLTTPCCATrackParam t0 = t;
833 Int_t iID = iTrack.FirstHitID();
834 for( Int_t ih=0; ih<iTrack.NHits(); ih++, iID++ ){
835 Int_t *ic = &(fTrackHits[iID]);
836 Int_t iRow = ID2IRow(*ic);
837 AliHLTTPCCARow &row = fRows[iRow];
838 if( !t0.TransportToX( row.X() ) ) continue;
840 AliHLTTPCCAHit &h = ID2Hit(*ic);
842 // check for wrong hits
844 dy = t0.GetY() - h.Y();
845 dz = t0.GetZ() - h.Z();
847 //if( dy*dy > 3.5*3.5*(/*t0.GetErr2Y() + */h.ErrY()*h.ErrY() ) ) continue;//SG!!!
848 //if( dz*dz > 3.5*3.5*(/*t0.GetErr2Z() + */h.ErrZ()*h.ErrZ() ) ) continue;
851 if( !t.TransportToX( row.X() ) ) continue;
874 Float_t err2Y, err2Z;
875 GetErrors2( iRow, t, err2Y, err2Z );
877 if( !t.Filter2( h.Y(), h.Z(), err2Y, err2Z ) ) continue;
882 Float_t cosPhi = iTrack.Param().GetCosPhi();
883 p0.Param().TransportToX(ID2Row( iTrack.PointID()[0] ).X());
884 p2.Param().TransportToX(ID2Row( iTrack.PointID()[1] ).X());
885 if( p0.Param().GetCosPhi()*cosPhi<0 ){ // change direction
886 Float_t *par = p0.Param().Par();
887 Float_t *cov = p0.Param().Cov();
888 par[2] = -par[2]; // sin phi
889 par[3] = -par[3]; // DzDs
890 par[4] = -par[4]; // kappa
897 p0.Param().CosPhi() = -p0.Param().GetCosPhi();
903 GPUh() void AliHLTTPCCATracker::FitTrack( AliHLTTPCCATrack &/*track*/, Float_t */*t0[]*/ ) const
907 AliHLTTPCCAEndPoint &p2 = ID2Point(track.PointID()[1]);
908 AliHLTTPCCAHit &c0 = ID2Hit(fTrackHits[p0.TrackHitID()].HitID());
909 AliHLTTPCCAHit &c1 = ID2Hit(fTrackHits[track.HitID()[1]].HitID());
910 AliHLTTPCCAHit &c2 = ID2Hit(fTrackHits[p2.TrackHitID()].HitID());
911 AliHLTTPCCARow &row0 = ID2Row(fTrackHits[p0.TrackHitID()].HitID());
912 AliHLTTPCCARow &row1 = ID2Row(fTrackHits[track.HitID()[1]].HitID());
913 AliHLTTPCCARow &row2 = ID2Row(fTrackHits[p2.TrackHitID()].HitID());
914 Float_t sp0[5] = {row0.X(), c0.Y(), c0.Z(), c0.ErrY(), c0.ErrZ() };
915 Float_t sp1[5] = {row1.X(), c1.Y(), c1.Z(), c1.ErrY(), c1.ErrZ() };
916 Float_t sp2[5] = {row2.X(), c2.Y(), c2.Z(), c2.ErrY(), c2.ErrZ() };
917 //cout<<"Fit track, points ="<<sp0[0]<<" "<<sp0[1]<<" / "<<sp1[0]<<" "<<sp1[1]<<" / "<<sp2[0]<<" "<<sp2[1]<<std::endl;
918 if( track.NHits()>=3 ){
919 p0.Param().ConstructXYZ3(sp0,sp1,sp2,p0.Param().CosPhi(), t0);
920 p2.Param().ConstructXYZ3(sp2,sp1,sp0,p2.Param().CosPhi(), t0);
921 //p2.Param() = p0.Param();
922 //p2.Param().TransportToX(row2.X());
923 //p2.Param().Par()[1] = -p2.Param().Par()[1];
924 //p2.Param().Par()[4] = -p2.Param().Par()[4];
926 p0.Param().X() = row0.X();
927 p0.Param().Y() = c0.Y();
928 p0.Param().Z() = c0.Z();
929 p0.Param().Err2Y() = c0.ErrY()*c0.ErrY();
930 p0.Param().Err2Z() = c0.ErrZ()*c0.ErrZ();
931 p2.Param().X() = row2.X();
932 p2.Param().Y() = c2.Y();
933 p2.Param().Z() = c2.Z();
934 p2.Param().Err2Y() = c2.ErrY()*c2.ErrY();
935 p2.Param().Err2Z() = c2.ErrZ()*c2.ErrZ();
942 GPUd() void AliHLTTPCCATracker::GetErrors2( Int_t iRow, Float_t z, Float_t sinPhi, Float_t cosPhi, Float_t DzDs, Float_t &Err2Y, Float_t &Err2Z ) const
945 // Use calibrated cluster error from OCDB
948 fParam.GetClusterErrors2( iRow, z, sinPhi, cosPhi, DzDs, Err2Y, Err2Z );
951 GPUd() void AliHLTTPCCATracker::GetErrors2( Int_t iRow, const AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z ) const
954 // Use calibrated cluster error from OCDB
957 fParam.GetClusterErrors2( iRow, t.GetZ(), t.SinPhi(), t.CosPhi(), t.DzDs(), Err2Y, Err2Z );
961 #if !defined(HLTCA_GPUCODE)
963 GPUh() void AliHLTTPCCATracker::WriteEvent( std::ostream &out )
965 // write event to the file
966 for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
967 out<<fRows[iRow].FirstHit()<<" "<<fRows[iRow].NHits()<<std::endl;
969 out<<fNHitsTotal<<std::endl;
971 Float_t y[fNHitsTotal], z[fNHitsTotal];
973 for( Int_t iRow=0; iRow<fParam.NRows(); iRow++){
974 AliHLTTPCCARow &row = fRows[iRow];
975 Float_t y0 = row.Grid().YMin();
976 Float_t z0 = row.Grid().ZMin();
977 Float_t stepY = row.HstepY();
978 Float_t stepZ = row.HstepZ();
979 const uint4* tmpint4 = RowData() + row.FullOffset();
980 const ushort2 *hits = reinterpret_cast<const ushort2*>(tmpint4);
981 for( Int_t ih=0; ih<fRows[iRow].NHits(); ih++ ){
982 Int_t ihTot = row.FirstHit() + ih;
983 Int_t id = fHitInputIDs[ihTot];
984 ushort2 hh = hits[ih];
985 y[id] = y0 + hh.x*stepY;
986 z[id] = z0 + hh.y*stepZ;
989 for( Int_t ih=0; ih<fNHitsTotal; ih++ ){
990 out<<y[ih]<<" "<<z[ih]<<std::endl;
994 GPUh() void AliHLTTPCCATracker::ReadEvent( std::istream &in )
996 //* Read event from file
998 Int_t rowFirstHit[Param().NRows()], rowNHits[Param().NRows()];
999 for( Int_t iRow=0; iRow<Param().NRows(); iRow++ ){
1000 in>>rowFirstHit[iRow]>>rowNHits[iRow];
1004 Float_t y[nHits], z[nHits];
1005 for( Int_t ih=0; ih<nHits; ih++ ){
1008 ReadEvent( rowFirstHit, rowNHits, y, z, nHits );
1011 GPUh() void AliHLTTPCCATracker::WriteTracks( std::ostream &out )
1013 //* Write tracks to file
1015 out<<fTimers[0]<<std::endl;
1016 out<<*fNOutTrackHits<<std::endl;
1017 for( Int_t ih=0; ih<*fNOutTrackHits; ih++ ){
1018 out<< fOutTrackHits[ih]<<" ";
1022 out<<*fNOutTracks<<std::endl;
1024 for( Int_t itr=0; itr<*fNOutTracks; itr++ ){
1025 AliHLTTPCCAOutTrack &t = fOutTracks[itr];
1026 AliHLTTPCCATrackParam p1 = t.StartPoint();
1027 AliHLTTPCCATrackParam p2 = t.EndPoint();
1028 out<< t.NHits()<<" ";
1029 out<< t.FirstHitRef()<<" ";
1030 out<< t.OrigTrackID()<<" ";
1033 out<< p1.CosPhi()<<" ";
1034 out<< p1.Chi2()<<" ";
1035 out<< p1.NDF()<<std::endl;
1036 for( Int_t i=0; i<5; i++ ) out<<p1.Par()[i]<<" ";
1038 for( Int_t i=0; i<15; i++ ) out<<p1.Cov()[i]<<" ";
1041 out<< p2.CosPhi()<<" ";
1042 out<< p2.Chi2()<<" ";
1043 out<< p2.NDF()<<std::endl;
1044 for( Int_t i=0; i<5; i++ ) out<<p2.Par()[i]<<" ";
1046 for( Int_t i=0; i<15; i++ ) out<<p2.Cov()[i]<<" ";
1051 GPUh() void AliHLTTPCCATracker::ReadTracks( std::istream &in )
1053 //* Read tracks from file
1055 in>>*fNOutTrackHits;
1057 for( Int_t ih=0; ih<*fNOutTrackHits; ih++ ){
1058 in>>fOutTrackHits[ih];
1062 for( Int_t itr=0; itr<*fNOutTracks; itr++ ){
1063 AliHLTTPCCAOutTrack &t = fOutTracks[itr];
1064 AliHLTTPCCATrackParam p1, p2;
1067 in>> i; t.SetNHits( i );
1068 in>> i; t.SetFirstHitRef( i );
1069 in>> i; t.SetOrigTrackID( i );
1070 in>> f; p1.SetX( f );
1071 in>> f; p1.SetCosPhi( f );
1072 in>> f; p1.SetChi2( f );
1073 in>> i; p1.SetNDF( i );
1074 for( Int_t j=0; j<5; j++ ){ in>>f; p1.SetPar(j,f); }
1075 for( Int_t j=0; j<15; j++ ){ in>>f; p1.SetCov(j,f); }
1076 in>> f; p2.SetX( f );
1077 in>> f; p2.SetCosPhi( f );
1078 in>> f; p2.SetChi2( f );
1079 in>> i; p2.SetNDF( i );
1080 for( Int_t j=0; j<5; j++ ){ in>>f; p2.SetPar(j,f); }
1081 for( Int_t j=0; j<15; j++ ){ in>>f; p2.SetCov(j,f); }
1082 t.SetStartPoint( p1 );
1083 t.SetEndPoint( p2 );