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