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