Little changes to make g++ version 3.2 compile the hough library.
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughIntMerger.cxx
1 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
2 //*-- Copyright &copy ASV 
3
4 #include "AliL3StandardIncludes.h"
5
6 #include "AliL3Logging.h"
7 #include "AliL3HoughIntMerger.h"
8 #include "AliL3HoughTrack.h"
9 #include "AliL3TrackSegmentData.h"
10 #include "AliL3Transform.h"
11 #include "AliL3TrackArray.h"
12
13 #if GCCVERSION == 3
14 using namespace std;
15 #endif
16
17 //_____________________________________________________________
18 // Hough Inter merger
19 // Merging of multiple reconstructed tracks
20
21 ClassImp(AliL3HoughIntMerger)
22
23 AliL3HoughIntMerger::AliL3HoughIntMerger() : AliL3Merger(1,"AliL3HoughTrack")
24 {
25   //Default constructor
26   fRowMax = fRowMin = 0;
27   SetParameters(0.001,0.05,10);
28   Is2Global(kFALSE);
29 }
30
31
32 AliL3HoughIntMerger::~AliL3HoughIntMerger()
33 {
34   //Destructor
35   
36 }
37
38 void AliL3HoughIntMerger::SetParameters(Double_t maxkappa, Double_t maxphi0, Double_t maxtgl)
39 {
40   fMaxKappa = maxkappa;
41   fMaxPhi0 = maxphi0;
42   fMaxTgl = maxtgl;
43 }
44
45 void AliL3HoughIntMerger::FillTracks(AliL3TrackArray *tracks)
46 {
47   if(tracks->GetNTracks()==0)
48     LOG(AliL3Log::kWarning,"AliL3HoughIntMerger::FillTracks","Track Array")
49       <<"Adding empty track array"<<ENDLOG;
50   
51   GetInTracks(0)->AddTracks(tracks,kFALSE);//Copy tracks
52   printf("Filling %d tracks to intermerger\n",tracks->GetNTracks());
53 }
54
55 Bool_t AliL3HoughIntMerger::IsTrack(AliL3Track *innertrack,AliL3Track *outertrack)
56 {
57   //Check if the tracks can be merged, called by the track merger
58   
59   AliL3HoughTrack *tr1 = (AliL3HoughTrack*)innertrack;
60   AliL3HoughTrack *tr2 = (AliL3HoughTrack*)outertrack;
61   
62   if(abs(tr1->GetEtaIndex() - tr2->GetEtaIndex()) > 1) return kFALSE;
63   if(tr1->GetCharge()!=tr2->GetCharge()) return kFALSE;
64   if(fabs(tr1->GetKappa()-tr2->GetKappa())   >fMaxKappa) return kFALSE;
65   if(fabs(tr1->GetPhi0()-tr2->GetPhi0()) > fMaxPhi0) return kFALSE;
66
67   return kTRUE;//Tracks could be merged
68 }
69
70 AliL3Track *AliL3HoughIntMerger::MultiMerge(AliL3TrackArray *mergedtrack,AliL3Track **tracks, Int_t ntrack)
71 {
72   //Called by the track merger
73
74   AliL3HoughTrack *newtrack = (AliL3HoughTrack*)mergedtrack->NextTrack();
75   AliL3HoughTrack **trs = (AliL3HoughTrack**)tracks;
76       
77   AliL3HoughTrack *tpt=trs[0];//this is the "best" track
78   //AliL3HoughTrack *tpl=trs[ntrack-1];
79   newtrack->Set(tpt);
80   return (AliL3Track*)newtrack;
81 }
82
83
84
85 void AliL3HoughIntMerger::MMerge()
86 {
87   GetInTracks(0)->QSort();
88   while(Merge());
89   GetOutTracks()->AddTracks(GetInTracks(0));
90 }
91
92 Int_t AliL3HoughIntMerger::Merge()
93 {
94   
95   AliL3TrackArray * tracks = GetInTracks(0);
96   const Int_t  kNIn =tracks->GetNTracks();
97   AliL3Track *tr[2];
98
99   for(Int_t out=0;out<kNIn;out++)
100     {
101       AliL3HoughTrack *outertrack=(AliL3HoughTrack*)tracks->GetCheckedTrack(out);
102       if(!outertrack) continue;
103       for(Int_t in=0;in<kNIn;in++)
104         {
105           if(in==out) continue;
106           AliL3HoughTrack *innertrack=(AliL3HoughTrack*)tracks->GetCheckedTrack(in);
107           if(!innertrack) continue;
108           if(IsTrack(innertrack,outertrack))
109             {
110               tr[0]=innertrack;
111               tr[1]=outertrack;
112               SortTracks(tr,2);
113               Print(tr);
114               MultiMerge(tracks,tr,2);
115               tracks->Remove(out);
116               tracks->Remove(in);
117               break;
118             }
119         } 
120     }
121   Int_t nmerged = tracks->GetNTracks()-kNIn; 
122   LOG(AliL3Log::kInformational,"AliL3HoughIntMerger::Merge","Result")
123     <<AliL3Log::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
124   
125   //add in tracks
126   //GetOutTracks()->AddTracks(GetInTracks(0)); 
127   
128   return nmerged;
129 }
130
131 void AliL3HoughIntMerger::Print(AliL3Track **tracks)
132 {
133   AliL3HoughTrack *tr1 = (AliL3HoughTrack*)tracks[0];
134   AliL3HoughTrack *tr2 = (AliL3HoughTrack*)tracks[1];
135   Double_t kappadiff = fabs(tr1->GetKappa()-tr2->GetKappa());
136   Double_t phi0diff = fabs(tr1->GetPhi0()-tr2->GetPhi0());
137   cout << "---------Difference in intermerged tracks---------"<<endl;
138   cout << "Kappa: "<<kappadiff<<" Phi0 : "<<phi0diff<<endl;
139   
140 }
141
142 void AliL3HoughIntMerger::SortTracks(AliL3Track **trs, Int_t ntrack)
143 {
144   //Sort the tracks according to their weight
145
146   AliL3HoughTrack **tracks = (AliL3HoughTrack**)trs;
147   AliL3HoughTrack **tmp = new  AliL3HoughTrack*[ntrack];
148   for(Int_t i=0;i<ntrack;i++) tmp[i] = (AliL3HoughTrack*)tracks[i];
149   Int_t *t = new Int_t[ntrack];
150   for(Int_t i=0;i<ntrack;i++) t[i]=-1;
151   
152   for(Int_t j=0;j<ntrack;j++)
153     {
154       Double_t maxw=0;
155       Int_t    maxi=0;
156       for(Int_t i=0;i<ntrack;i++)
157         {
158           if(!tracks[i]) continue;
159           if(tracks[i]->GetWeight() > maxw)
160             {
161               maxw=tracks[i]->GetWeight();
162               maxi=i;
163             }     
164         }
165       t[j]=maxi;  
166       tracks[maxi]=0;
167     }
168   for(Int_t i=0;i<ntrack;i++) tracks[i] = tmp[t[i]];
169   delete[] t;
170   delete[] tmp;
171 }