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