]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCTrackMerger.cxx
- configure adapted to the new directory structure of the HOMER module in PubSub
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCTrackMerger.cxx
1 // @(#) $Id$
2 // Original: AliL3TrackMerger.cxx,v 1.12 2005/06/14 10:55:21 cvetan 
3
4 // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
5 //*-- Copyright &copy ALICE HLT Group
6
7 /** \class AliHLTTPCTrackMerger
8 <pre>
9 //_____________________________________________________________
10 // AliHLTTPCTrackMerger
11 //
12 // The HLTTPC track segment merger
13 //
14 </pre
15 */
16
17 #include "AliHLTTPCLogging.h"
18 #include "AliHLTTPCTrackMerger.h"
19 #include "AliHLTTPCTrack.h"
20 #include "AliHLTTPCTrackSegmentData.h"
21 #include "AliHLTTPCTransform.h"
22 #include "AliHLTTPCTrackArray.h"
23
24 #if __GNUC__ >= 3
25 using namespace std;
26 #endif
27
28 ClassImp(AliHLTTPCTrackMerger)
29
30 AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(){
31   //Default constructor
32   Is2Global(kFALSE);
33   fSlow = kFALSE;
34   SetParameter();
35   fRowMin = 0;
36   fRowMax = 0;
37 }
38
39
40 AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(Int_t nsubsectors) : AliHLTTPCMerger()
41 {
42   //Constructor.
43   InitMerger(nsubsectors);
44   fNSubSector = nsubsectors;
45   Is2Global(kFALSE);
46   fSlow = kFALSE;
47   SetParameter();
48   fRowMin = new Int_t[nsubsectors];
49   fRowMax = new Int_t[nsubsectors];
50   
51 }
52
53 AliHLTTPCTrackMerger::~AliHLTTPCTrackMerger(){
54   //Destructor
55 }
56
57 void AliHLTTPCTrackMerger::SetRows(Int_t *row){
58   //Set the indeces of the first and last
59   //TPC padrows
60   //
61   for(Int_t i=0;i<fNSubSector;i++){
62     fRowMin[i]=*(row+(2*i));
63     fRowMax[i]=*(row+(2*i+1));
64   }
65 }
66
67 void AliHLTTPCTrackMerger::InitSector(Int_t slice,Int_t subsector){
68   // 
69   // Select Sector and subsector. The following FillTracks call will 
70   // fill this subsector
71   //
72   fSlice = slice;
73   fSubSector = subsector;
74   fCurrentTracks = fSubSector;
75 }
76
77 void AliHLTTPCTrackMerger::SlowMerge(AliHLTTPCTrackArray *mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout,Double_t xval){
78   // 
79   // Slow merging of two AliHLTTPCTrackArrays
80   // at reference plane x=xval
81   //
82   void *ntuple=GetNtuple();
83   const Int_t  kNOut=tracksout->GetNTracks();
84   const Int_t  kNIn =tracksin->GetNTracks();
85   const Int_t  kNMerged =mergedtrack->GetNTracks();
86   AliHLTTPCTrack *tracks[2];
87   Bool_t merge = kTRUE;
88   while(merge){
89     Int_t inmin=-1,outmin=-1;
90     Double_t min=10;
91     for(Int_t out=0;out<kNOut;out++){
92     AliHLTTPCTrack *outertrack=tracksout->GetCheckedTrack(out);
93     if(!outertrack) continue;
94       for(Int_t in=0;in<kNIn;in++){
95         AliHLTTPCTrack *innertrack=tracksin->GetCheckedTrack(in);
96         if(!innertrack) continue;
97         Double_t diff = TrackDiff(innertrack,outertrack);
98         if(diff>=0&&diff<min){
99           min=diff;
100           inmin=in;
101           outmin=out; 
102         }
103       } 
104     }
105     if(inmin>=0&&outmin>=0){
106       AliHLTTPCTrack *outertrack=tracksout->GetTrack(outmin);
107       AliHLTTPCTrack *innertrack=tracksin->GetTrack(inmin);
108       tracks[0]=innertrack;
109       tracks[1]=outertrack;
110       SortTracks(tracks,2);
111       MultiMerge(mergedtrack,tracks,2);
112       outertrack->CalculatePoint(xval);
113       innertrack->CalculatePoint(xval);
114       PrintDiff(innertrack,outertrack);
115       //FillNtuple(ntuple,innertrack,outertrack);
116       tracksout->Remove(outmin);
117       tracksin->Remove(inmin);
118 //      tracksout->Compress();
119 //      tracksin->Compress(); 
120     }
121     else merge = kFALSE;
122   }
123   LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::SlowMerge","Result")
124   <<AliHLTTPCLog::kDec<<"Merged Tracks: "
125   <<mergedtrack->GetNTracks()-kNMerged<<ENDLOG;
126   char name[256] = "ntuple_t.root";
127   for(Int_t i=0;i<4;i++)
128     if(tracksin==GetInTracks(i))
129       sprintf(name,"ntuple_t_%d.root",i);
130   WriteNtuple(name,ntuple);
131 }
132
133 void AliHLTTPCTrackMerger::SlowMerge(){
134   fSlow = kTRUE;
135   Merge();
136 }
137
138 void AliHLTTPCTrackMerger::InterMerge(){
139   // 
140   // Merging of the tracks
141   // between readout patches
142   //
143   for(Int_t patch=0;patch< GetNIn();patch++){
144     AliHLTTPCTrackArray * tracks = GetInTracks(patch);
145     Double_t xval = AliHLTTPCTransform::Row2X((fRowMax[patch]+fRowMin[patch])/2);
146     Int_t nrow= fRowMax[patch]-fRowMin[patch]+1;
147     const Int_t  kNIn =tracks->GetNTracks();
148     AliHLTTPCTrack *tr[2];
149     for(Int_t in=0;in<kNIn;in++){
150       AliHLTTPCTrack *t = tracks->GetCheckedTrack(in);
151       if(t){
152         t->CalculateHelix();
153         t->CalculatePoint(xval);
154       }
155     }
156     for(Int_t out=0;out<kNIn;out++){
157     AliHLTTPCTrack *outertrack=tracks->GetCheckedTrack(out);
158     if(!outertrack) continue;
159       for(Int_t in=0;in<kNIn;in++){
160         if(in==out) continue;
161         AliHLTTPCTrack *innertrack=tracks->GetCheckedTrack(in);
162         if(!innertrack) continue;
163         if(outertrack->GetNHits()+innertrack->GetNHits()>nrow) continue;
164
165         if(IsTrack(innertrack,outertrack)){
166           tr[0]=innertrack;
167           tr[1]=outertrack;
168           SortTracks(tr,2);
169           if(tr[0]->GetLastPointX()<tr[1]->GetFirstPointX()){
170             MultiMerge(tracks,tr,2);
171             tracks->Remove(out);
172             tracks->Remove(in);
173             break;
174           }
175         }
176       }
177     }
178     Int_t nmerged = tracks->GetNTracks()-kNIn;
179     LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::InterMerge","Result")
180     <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
181   }
182 }
183
184 void AliHLTTPCTrackMerger::Merge(){
185   //Loop over tracks and pass them to the track merger.
186   Double_t edge0 = AliHLTTPCTransform::Pi()/18;
187   Double_t edge1 = AliHLTTPCTransform::TwoPi() - edge0;
188   AliHLTTPCTrackArray *ttt = GetOutTracks();
189   if(fNSubSector==1) {
190     GetOutTracks()->AddTracks(GetInTracks(0)); 
191     LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
192     <<AliHLTTPCLog::kDec<<"Total Copied Tracks: "<<GetOutTracks()->GetNPresent()
193     <<ENDLOG;
194     return;
195   }
196   Int_t subsec = fNSubSector -2; 
197   for(Int_t i=subsec;i>=0;i--){
198     AliHLTTPCTrackArray *tout = GetOutTracks();
199     if(i==subsec) tout = GetInTracks(subsec+1);
200     AliHLTTPCTrackArray *tin = GetInTracks(i);
201     Double_t xval = AliHLTTPCTransform::Row2X(fRowMax[i]);
202     Double_t xmax = AliHLTTPCTransform::Row2X(fRowMax[i+1]);
203     Double_t ymax = xval*tan(edge0);
204     for(Int_t out=0;out<tout->GetNTracks();out++){
205       AliHLTTPCTrack *outtrack=tout->GetCheckedTrack(out);
206       if(!outtrack) continue;
207       outtrack->CalculateHelix();
208       outtrack->CalculatePoint(xval);
209       if(outtrack->IsPoint()&&fabs(outtrack->GetPointY())>ymax){
210         if(outtrack->GetNHits()<10)
211           tout->Remove(out);
212       }
213     }
214 //    tout->Compress();
215     for(Int_t in=0;in<tin->GetNTracks();in++){
216       AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetTrack(in);
217       intrack->CalculateHelix();
218       intrack->CalculatePoint(xval);
219     }
220     tin->QSort();
221     tout->QSort();
222
223     if(fSlow) SlowMerge(ttt,tin,tout,xval);
224     else Merge(ttt,tin,tout);
225     for(Int_t in=0;in<tin->GetNTracks();in++){
226       AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in);
227       if(!intrack) continue;
228       if(intrack->CalculateEdgePoint(edge0)){
229         if(intrack->GetPointX()<xmax ){
230           AddTrack(ttt,intrack);
231           tin->Remove(in);
232         }
233       } 
234       else if(intrack->CalculateEdgePoint(edge1)){
235         if(intrack->GetPointX()<xmax ){
236           AddTrack(ttt,intrack);
237           tin->Remove(in);
238         }
239       }
240     }
241 /*
242     for(Int_t in=0;in<tin->GetNTracks();in++){
243       AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in);
244       if(!intrack) continue;
245       if(intrack->GetNHits()<10) continue;
246       AddTrack(ttt,intrack);
247       tin->Remove(in);
248     }
249 */
250   } // end subsector loop
251   LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
252   <<AliHLTTPCLog::kDec<<"Total Merged Tracks: "<<GetOutTracks()->GetNPresent()
253   <<ENDLOG;
254 }
255
256 Int_t AliHLTTPCTrackMerger::Merge(AliHLTTPCTrackArray* mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout){
257   //Loop over tracks and pass them to the track merger.
258   AliHLTTPCTrack *tracks[2];
259
260   const Int_t  kNOut=tracksout->GetNTracks();
261   const Int_t  kNIn =tracksin->GetNTracks();
262   const Int_t  kNMerged =mergedtrack->GetNTracks();
263
264   Bool_t *ismatchedin  = new Bool_t[kNIn];
265   for(Int_t in =0;in<kNIn;in++)
266     ismatchedin[in]=kFALSE;
267   Bool_t *ismatchedout = new Bool_t[kNOut];
268   for(Int_t out =0;out<kNOut;out++)
269     ismatchedout[out] = kFALSE;
270   for(Int_t out =0;out<kNOut;out++){
271     AliHLTTPCTrack *outertrack=(AliHLTTPCTrack*)tracksout->GetCheckedTrack(out);
272     if(!outertrack) continue;
273     for(Int_t in =0;in<kNIn;in++){
274       if(ismatchedin[in]) continue;
275       AliHLTTPCTrack *innertrack=(AliHLTTPCTrack*)tracksin->GetCheckedTrack(in);
276       if(!innertrack) continue;
277       if(outertrack==innertrack) continue;
278       if(outertrack->GetCharge()!=innertrack->GetCharge()) continue;
279       if(IsTrack(innertrack,outertrack)){
280         tracks[0]=innertrack; tracks[1]=outertrack; 
281         SortTracks(tracks,2);  
282         if(tracks[0]->GetLastPointX()<tracks[1]->GetFirstPointX()){
283           MultiMerge(mergedtrack,tracks,2);
284           tracksout->Remove(out);
285           tracksin->Remove(in);
286           ismatchedin[in]=kTRUE;
287           ismatchedout[out]=kTRUE;
288           break;
289         }
290       }
291     }
292   }
293
294   Int_t nmerged = mergedtrack->GetNTracks()-kNMerged;
295   LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
296   <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
297   delete[] ismatchedin;
298   delete[] ismatchedout;
299   return nmerged;
300 }
301
302