Fit mathematics improved, obsollete GBTracker cleaned up
[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
20
21 #include "AliHLTTPCCATrackletSelector.h"
22 #include "AliHLTTPCCATrack.h"
23 #include "AliHLTTPCCATracker.h"
24 #include "AliHLTTPCCATrackParam.h"
25 #include "AliHLTTPCCATracklet.h"
26 #include "AliHLTTPCCAMath.h"
27
28 GPUd() void AliHLTTPCCATrackletSelector::Thread
29 ( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
30   AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
31 {
32   // select best tracklets and kill clones
33
34   if( iSync==0 )
35     {
36       if( iThread==0 ){
37         if(iBlock==0){
38           CAMath::AtomicExch(tracker.NTracks(),0);
39           CAMath::AtomicExch(tracker.NTrackHits(),0);
40         }
41         s.fNTracklets = *tracker.NTracklets();
42         s.fNThreadsTotal = nThreads*nBlocks;
43         s.fItr0 = nThreads*iBlock;      
44       }
45     }
46   else if( iSync==1 )
47     {
48       AliHLTTPCCATrack tout;
49       Int_t trackHits[160];
50         
51       for( Int_t itr= s.fItr0 + iThread; itr<s.fNTracklets; itr+=s.fNThreadsTotal ){                    
52
53         AliHLTTPCCATracklet &tracklet = tracker.Tracklets()[itr];
54
55         Int_t tNHits = tracklet.NHits();
56         if( tNHits<=0 ) continue;
57
58         const Int_t kMaxRowGap = 4;
59         const Float_t kMaxShared = .1;
60
61         Int_t firstRow = tracklet.FirstRow();
62         Int_t lastRow = tracklet.LastRow();
63
64         tout.SetNHits( 0 );
65         Int_t kind = 0;
66         if(0){ 
67           if( tNHits>=10 && 1./.5 >= CAMath::Abs(tracklet.Param().QPt()) ){ //SG!!!
68             kind = 1;
69           }    
70         }
71
72         Int_t w = (kind<<29) + (tNHits<<16)+itr;
73
74         //Int_t w = (tNHits<<16)+itr;   
75         //Int_t nRows = tracker.Param().NRows();
76         Int_t gap = 0;
77         Int_t nShared = 0;
78         //std::cout<<" store tracklet: "<<firstRow<<" "<<lastRow<<std::endl;
79         for( Int_t irow=firstRow; irow<=lastRow; irow++ ){
80           gap++;
81           Int_t ih = tracklet.RowHit(irow);
82           if( ih>=0 ){
83             Int_t ihTot = tracker.Row(irow).FirstHit()+ih;
84             Bool_t own = ( tracker.HitWeights()[ihTot] <= w );
85             Bool_t sharedOK = ( (tout.NHits()<0) || (nShared<tout.NHits()*kMaxShared) );
86             if( own || sharedOK ){//SG!!!
87               gap = 0;
88               Int_t th = AliHLTTPCCATracker::IRowIHit2ID(irow,ih);
89               trackHits[tout.NHits()] = th;
90               tout.SetNHits( tout.NHits() + 1 );
91               if( !own ) nShared++;
92             }
93           }
94           
95           if( gap>kMaxRowGap || irow==lastRow ){ // store 
96             if( tout.NHits()>=10 ){ //SG!!!
97               Int_t itrout = CAMath::AtomicAdd(tracker.NTracks(),1);
98               tout.SetFirstHitID( CAMath::AtomicAdd( tracker.NTrackHits(), tout.NHits() ));
99               tout.SetParam( tracklet.Param() );
100               tout.SetAlive( 1 );
101               tracker.Tracks()[itrout] = tout;
102               for( Int_t jh=0; jh<tout.NHits(); jh++ ){
103                 tracker.TrackHits()[tout.FirstHitID() + jh] = trackHits[jh];
104               }
105             }
106             tout.SetNHits( 0 ); 
107             gap = 0;
108             nShared = 0;
109           }
110         }
111       }
112     }
113 }