L3 becomes HLT
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCInterMerger.cxx
1 // @(#) $Id$
2 // Original: AliHLTInterMerger.cxx,v 1.8 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 #include "AliHLTTPCLogging.h"
8 #include "AliHLTTPCInterMerger.h"
9 #include "AliHLTTPCTrack.h"
10 #include "AliHLTTPCTrackSegmentData.h"
11 #include "AliHLTTPCTransform.h"
12 #include "AliHLTTPCTrackArray.h"
13
14 /** \class AliHLTTPCInterMerger
15 <pre>
16 //_____________________________________________________________
17 // AliHLTTPCInterMerger
18 //
19 // The HLTTPC track segment merger
20 //
21 </pre>
22 */
23
24 #if __GNUC__ >= 3
25 using namespace std;
26 #endif
27
28 ClassImp(AliHLTTPCInterMerger)
29
30 AliHLTTPCInterMerger::AliHLTTPCInterMerger()
31 {
32   //Default constructor
33   InitMerger(1);
34   Is2Global(kFALSE);
35 //  SetParameter(2,2,.3,.3,.3);
36   SetParameter(1,0.5,0.0005,0.05,0.1);
37   fRowMax = fRowMin = 0;
38 }
39
40
41 AliHLTTPCInterMerger::~AliHLTTPCInterMerger(){
42   //Destructor
43   
44 }
45
46 void AliHLTTPCInterMerger::SlowMerge(){
47   Int_t nrow= fRowMax-fRowMin+1;
48   void *ntuple=GetNtuple();
49   AliHLTTPCTrackArray * tracks = GetInTracks(0);
50   const Int_t  kNIn =tracks->GetNTracks();
51   AliHLTTPCTrack *tr[2];
52   Bool_t merge = kTRUE;
53   for(Int_t in=0;in<kNIn;in++)
54     tracks->GetCheckedTrack(in)->CalculateHelix();
55   while(merge){
56     Int_t inmin=-1,outmin=-1;
57     Double_t min=10;
58     for(Int_t out=0;out<kNIn;out++){
59     AliHLTTPCTrack *outertrack=tracks->GetCheckedTrack(out);
60     if(!outertrack) continue;
61       for(Int_t in=0;in<kNIn;in++){
62         if(in==out) continue;
63         AliHLTTPCTrack *innertrack=tracks->GetCheckedTrack(in);
64         if(!innertrack) continue;
65         if(outertrack->GetNHits()+innertrack->GetNHits()>nrow) continue;
66
67         Double_t diff = TrackDiff(innertrack,outertrack);
68
69         if(diff>=0&&diff<min){
70           min=diff;
71           inmin=in;
72           outmin=out; 
73         }
74       } 
75     }
76     if(inmin>=0&&outmin>=0){
77       AliHLTTPCTrack *outertrack=tracks->GetTrack(outmin);
78       AliHLTTPCTrack *innertrack=tracks->GetTrack(inmin);
79       tr[0]=innertrack;
80       tr[1]=outertrack;
81       SortTracks(tr,2);
82       MultiMerge(tracks,tr,2);
83       outertrack->CalculatePoint(tr[0]->GetLastPointX());
84       innertrack->CalculatePoint(tr[0]->GetLastPointX());
85       PrintDiff(innertrack,outertrack);
86       FillNtuple(ntuple,innertrack,outertrack);
87       tracks->Remove(outmin);
88       tracks->Remove(inmin);
89     }
90     else merge = kFALSE;
91   }
92   LOG(AliHLTTPCLog::kInformational,"AliHLTTPCInterMerger::SlowMerge","Result")
93   <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<tracks->GetNTracks()-kNIn<<ENDLOG;
94
95   char name[256];
96   sprintf(name,"ntuple_i_%d.root",fPatch);
97   WriteNtuple(name,ntuple);
98 }
99
100 void AliHLTTPCInterMerger::MMerge(){
101   while(Merge());
102   GetOutTracks()->AddTracks(GetInTracks(0));
103 }
104
105 Int_t AliHLTTPCInterMerger::Merge(){
106   Int_t nrow= fRowMax-fRowMin+1;
107   Double_t xval =AliHLTTPCTransform::Row2X((fRowMax+fRowMin)/2);
108   AliHLTTPCTrackArray * tracks = GetInTracks(0);
109   const Int_t  kNIn =tracks->GetNTracks();
110   AliHLTTPCTrack *tr[2];
111   for(Int_t in=0;in<kNIn;in++){
112     AliHLTTPCTrack *t = tracks->GetCheckedTrack(in);
113     if(t){
114       t->CalculateHelix();
115       t->CalculatePoint(xval);
116     }
117   }
118   for(Int_t out=0;out<kNIn;out++){
119   AliHLTTPCTrack *outertrack=tracks->GetCheckedTrack(out);
120   if(!outertrack) continue;
121     for(Int_t in=0;in<kNIn;in++){
122       if(in==out) continue;
123       AliHLTTPCTrack *innertrack=tracks->GetCheckedTrack(in);
124       if(!innertrack) continue;
125       if(outertrack->GetNHits()+innertrack->GetNHits()>nrow) continue;
126
127       if(IsTrack(innertrack,outertrack)){
128         tr[0]=innertrack;
129         tr[1]=outertrack;
130         SortGlobalTracks(tr,2);
131
132         Double_t r0 = pow(tr[0]->GetLastPointX(),2)+
133                       pow(tr[0]->GetLastPointY(),2);
134         Double_t r1 = pow(tr[1]->GetFirstPointX(),2)+
135                       pow(tr[1]->GetFirstPointY(),2);
136         if(r0<r1){
137           MultiMerge(tracks,tr,2);
138           tracks->Remove(out);
139           tracks->Remove(in);
140           break;
141         }
142       }
143     } 
144   }
145   Int_t nmerged = tracks->GetNTracks()-kNIn; 
146   LOG(AliHLTTPCLog::kInformational,"AliHLTTPCInterMerger::Merge","Result")
147   <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
148   //add in tracks
149 //  GetOutTracks()->AddTracks(GetInTracks(0)); 
150
151   return nmerged;
152 }
153
154