A tracker update: significant clean up, reorganise of the data structures, p-p track...
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCATrackletSelector.cxx
1 // @(#) $Id: AliHLTTPCCATrackletSelector.cxx 27042 2008-07-02 12:06:02Z richterm $
2 //***************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project          * 
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.                    *
17 //***************************************************************************
18
19 #include "AliHLTTPCCATrackletSelector.h"
20 #include "AliHLTTPCCATrack.h"
21 #include "AliHLTTPCCATracker.h"
22 #include "AliHLTTPCCATrackParam.h"
23 #include "AliHLTTPCCAMath.h"
24
25 GPUd() void AliHLTTPCCATrackletSelector::Thread
26 ( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
27   AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
28 {
29   // select best tracklets and kill clones
30
31   if( iSync==0 )
32     {
33       if( iThread==0 ){
34         if(iBlock==0){
35           CAMath::atomicExch(tracker.NTracks(),0);
36           CAMath::atomicExch(tracker.NTrackHits(),0);
37         }
38         s.fNTracklets = *tracker.NTracklets();
39         s.fNThreadsTotal = nThreads*nBlocks;
40         s.fItr0 = nThreads*iBlock;      
41       }
42     }
43   else if( iSync==1 )
44     {
45       AliHLTTPCCATrack tout;
46       Int_t trackHits[160];
47         
48       for( Int_t itr= s.fItr0 + iThread; itr<s.fNTracklets; itr+=s.fNThreadsTotal ){                    
49         Int_t *t = ((Int_t*)tracker.Tracklets()) + itr*(5+ sizeof(AliHLTTPCCATrackParam)/4 + 160 );     
50         Int_t tNHits = *t;
51         if( tNHits<=0 ) continue;
52         
53         tout.NHits() = 0;
54         Int_t *hitstore = t + 5+ sizeof(AliHLTTPCCATrackParam)/4 ;    
55         Int_t w = (tNHits<<16)+itr;     
56         Int_t nRows = tracker.Param().NRows();
57         Int_t gap = 0;
58         for( Int_t irow=0; irow<nRows; irow++ ){
59           Int_t ih = hitstore[irow];
60           if( ih<0 ) continue;
61           AliHLTTPCCARow &row = tracker.Rows()[irow];
62           Int_t ihTot = row.FirstHit()+ih;      
63           if( tracker.HitWeights()[ihTot] > w ){
64             if( ++gap>6){ tout.NHits()=0; break; }
65             continue;
66           } else gap = 0;
67           Int_t th = AliHLTTPCCATracker::IRowIHit2ID(irow,ih);
68           trackHits[tout.NHits()] = th;
69           tout.NHits()++;
70         }       
71         if( tout.NHits()<10 ) continue;//SG!!!
72         Int_t itrout = CAMath::atomicAdd(tracker.NTracks(),1);
73         tout.FirstHitID() = CAMath::atomicAdd( tracker.NTrackHits(), tout.NHits() );
74         tout.Param() = *( (AliHLTTPCCATrackParam*)( t+5) );
75         tout.Alive() = 1;
76         tracker.Tracks()[itrout] = tout;
77         for( Int_t ih=0; ih<tout.NHits(); ih++ ){//SG
78           tracker.TrackHits()[tout.FirstHitID() + ih] = trackHits[ih];
79         }
80       }
81     }
82 }