Avoid to create the link inside a module pointing to the module itself
[u/mrichter/AliRoot.git] / HLT / src / AliL3TrackMerger.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
2
b661165c 3// Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
3e87ef69 4//*-- Copyright &copy ALICE HLT Group
108615fc 5
118c26c3 6#include "AliL3StandardIncludes.h"
7
108615fc 8#include "AliL3Logging.h"
9#include "AliL3TrackMerger.h"
10#include "AliL3Track.h"
11#include "AliL3TrackSegmentData.h"
12#include "AliL3Transform.h"
13#include "AliL3TrackArray.h"
14
3e87ef69 15/** \class AliL3TrackMerger
16<pre>
108615fc 17//_____________________________________________________________
b661165c 18// AliL3TrackMerger
108615fc 19//
20// The L3 track segment merger
21//
3e87ef69 22</pre
23*/
108615fc 24
25ClassImp(AliL3TrackMerger)
26
27AliL3TrackMerger::AliL3TrackMerger(){
28 //Default constructor
29 Is2Global(kFALSE);
30 fSlow = kFALSE;
31 SetParameter();
cd081a54 32 fRowMin = 0;
33 fRowMax = 0;
108615fc 34}
35
36
0a86fbb7 37AliL3TrackMerger::AliL3TrackMerger(Int_t nsubsectors) : AliL3Merger()
38{
108615fc 39 //Constructor.
0a86fbb7 40 InitMerger(nsubsectors);
108615fc 41 fNSubSector = nsubsectors;
42 Is2Global(kFALSE);
43 fSlow = kFALSE;
44 SetParameter();
cd081a54 45 fRowMin = new Int_t[nsubsectors];
46 fRowMax = new Int_t[nsubsectors];
0a86fbb7 47
108615fc 48}
49
50AliL3TrackMerger::~AliL3TrackMerger(){
51 //Destructor
52}
53
54void AliL3TrackMerger::SetRows(Int_t *row){
eeddc64d 55 for(Int_t i=0;i<fNSubSector;i++){
108615fc 56 fRowMin[i]=*(row+(2*i));
57 fRowMax[i]=*(row+(2*i+1));
58 }
59}
60
61void AliL3TrackMerger::InitSector(Int_t slice,Int_t subsector){
62 //
63 // Select Sector and subsector. The following FillTracks call will
64 // fill this subsector
65 //
66 fSlice = slice;
67 fSubSector = subsector;
68 fCurrentTracks = fSubSector;
69}
70
71void AliL3TrackMerger::SlowMerge(AliL3TrackArray *mergedtrack,AliL3TrackArray *tracksin,AliL3TrackArray *tracksout,Double_t xval){
72 void *ntuple=GetNtuple();
73 const Int_t kNOut=tracksout->GetNTracks();
74 const Int_t kNIn =tracksin->GetNTracks();
75 const Int_t kNMerged =mergedtrack->GetNTracks();
76 AliL3Track *tracks[2];
77 Bool_t merge = kTRUE;
78 while(merge){
79 Int_t inmin=-1,outmin=-1;
80 Double_t min=10;
81 for(Int_t out=0;out<kNOut;out++){
82 AliL3Track *outertrack=tracksout->GetCheckedTrack(out);
83 if(!outertrack) continue;
84 for(Int_t in=0;in<kNIn;in++){
85 AliL3Track *innertrack=tracksin->GetCheckedTrack(in);
86 if(!innertrack) continue;
87 Double_t diff = TrackDiff(innertrack,outertrack);
88 if(diff>=0&&diff<min){
89 min=diff;
90 inmin=in;
91 outmin=out;
92 }
93 }
94 }
95 if(inmin>=0&&outmin>=0){
96 AliL3Track *outertrack=tracksout->GetTrack(outmin);
97 AliL3Track *innertrack=tracksin->GetTrack(inmin);
98 tracks[0]=innertrack;
99 tracks[1]=outertrack;
100 SortTracks(tracks,2);
101 MultiMerge(mergedtrack,tracks,2);
102 outertrack->CalculatePoint(xval);
103 innertrack->CalculatePoint(xval);
104 PrintDiff(innertrack,outertrack);
68a27388 105 //FillNtuple(ntuple,innertrack,outertrack);
108615fc 106 tracksout->Remove(outmin);
107 tracksin->Remove(inmin);
108// tracksout->Compress();
109// tracksin->Compress();
110 }
111 else merge = kFALSE;
112 }
113 LOG(AliL3Log::kInformational,"AliL3TrackMerger::SlowMerge","Result")
114 <<AliL3Log::kDec<<"Merged Tracks: "
115 <<mergedtrack->GetNTracks()-kNMerged<<ENDLOG;
116 char name[256] = "ntuple_t.root";
117 for(Int_t i=0;i<4;i++)
118 if(tracksin==GetInTracks(i))
119 sprintf(name,"ntuple_t_%d.root",i);
120 WriteNtuple(name,ntuple);
121}
122
123void AliL3TrackMerger::SlowMerge(){
124 fSlow = kTRUE;
125 Merge();
126}
127
128void AliL3TrackMerger::InterMerge(){
129
130 for(Int_t patch=0;patch< GetNIn();patch++){
131 AliL3TrackArray * tracks = GetInTracks(patch);
494fad94 132 Double_t xval = AliL3Transform::Row2X((fRowMax[patch]+fRowMin[patch])/2);
108615fc 133 Int_t nrow= fRowMax[patch]-fRowMin[patch]+1;
134 const Int_t kNIn =tracks->GetNTracks();
135 AliL3Track *tr[2];
136 for(Int_t in=0;in<kNIn;in++){
137 AliL3Track *t = tracks->GetCheckedTrack(in);
138 if(t){
139 t->CalculateHelix();
140 t->CalculatePoint(xval);
141 }
142 }
143 for(Int_t out=0;out<kNIn;out++){
144 AliL3Track *outertrack=tracks->GetCheckedTrack(out);
145 if(!outertrack) continue;
146 for(Int_t in=0;in<kNIn;in++){
147 if(in==out) continue;
148 AliL3Track *innertrack=tracks->GetCheckedTrack(in);
149 if(!innertrack) continue;
150 if(outertrack->GetNHits()+innertrack->GetNHits()>nrow) continue;
151
152 if(IsTrack(innertrack,outertrack)){
153 tr[0]=innertrack;
154 tr[1]=outertrack;
155 SortTracks(tr,2);
156 if(tr[0]->GetLastPointX()<tr[1]->GetFirstPointX()){
157 MultiMerge(tracks,tr,2);
158 tracks->Remove(out);
159 tracks->Remove(in);
160 break;
161 }
162 }
163 }
164 }
165 Int_t nmerged = tracks->GetNTracks()-kNIn;
166 LOG(AliL3Log::kInformational,"AliL3TrackMerger::InterMerge","Result")
167 <<AliL3Log::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
168 }
169}
170
171void AliL3TrackMerger::Merge(){
172 //Loop over tracks and pass them to the track merger.
5a31e9df 173 Double_t edge0 = AliL3Transform::Pi()/18;
174 Double_t edge1 = AliL3Transform::TwoPi() - edge0;
108615fc 175 AliL3TrackArray *ttt = GetOutTracks();
176 if(fNSubSector==1) {
177 GetOutTracks()->AddTracks(GetInTracks(0));
178 LOG(AliL3Log::kInformational,"AliL3TrackMerger::Merge","Result")
179 <<AliL3Log::kDec<<"Total Copied Tracks: "<<GetOutTracks()->GetNPresent()
180 <<ENDLOG;
181 return;
182 }
183 Int_t subsec = fNSubSector -2;
184 for(Int_t i=subsec;i>=0;i--){
185 AliL3TrackArray *tout = GetOutTracks();
186 if(i==subsec) tout = GetInTracks(subsec+1);
187 AliL3TrackArray *tin = GetInTracks(i);
494fad94 188 Double_t xval = AliL3Transform::Row2X(fRowMax[i]);
189 Double_t xmax = AliL3Transform::Row2X(fRowMax[i+1]);
108615fc 190 Double_t ymax = xval*tan(edge0);
191 for(Int_t out=0;out<tout->GetNTracks();out++){
192 AliL3Track *outtrack=tout->GetCheckedTrack(out);
193 if(!outtrack) continue;
194 outtrack->CalculateHelix();
195 outtrack->CalculatePoint(xval);
196 if(outtrack->IsPoint()&&fabs(outtrack->GetPointY())>ymax){
197 if(outtrack->GetNHits()<10)
198 tout->Remove(out);
199 }
200 }
201// tout->Compress();
202 for(Int_t in=0;in<tin->GetNTracks();in++){
203 AliL3Track *intrack=(AliL3Track*)tin->GetTrack(in);
204 intrack->CalculateHelix();
205 intrack->CalculatePoint(xval);
206 }
207 tin->QSort();
208 tout->QSort();
209
210 if(fSlow) SlowMerge(ttt,tin,tout,xval);
211 else Merge(ttt,tin,tout);
212 for(Int_t in=0;in<tin->GetNTracks();in++){
213 AliL3Track *intrack=(AliL3Track*)tin->GetCheckedTrack(in);
214 if(!intrack) continue;
215 if(intrack->CalculateEdgePoint(edge0)){
216 if(intrack->GetPointX()<xmax ){
217 AddTrack(ttt,intrack);
218 tin->Remove(in);
219 }
220 }
221 else if(intrack->CalculateEdgePoint(edge1)){
222 if(intrack->GetPointX()<xmax ){
223 AddTrack(ttt,intrack);
224 tin->Remove(in);
225 }
226 }
227 }
228/*
229 for(Int_t in=0;in<tin->GetNTracks();in++){
230 AliL3Track *intrack=(AliL3Track*)tin->GetCheckedTrack(in);
231 if(!intrack) continue;
232 if(intrack->GetNHits()<10) continue;
233 AddTrack(ttt,intrack);
234 tin->Remove(in);
235 }
236*/
237 } // end subsector loop
238 LOG(AliL3Log::kInformational,"AliL3TrackMerger::Merge","Result")
239 <<AliL3Log::kDec<<"Total Merged Tracks: "<<GetOutTracks()->GetNPresent()
240 <<ENDLOG;
241}
242
243Int_t AliL3TrackMerger::Merge(AliL3TrackArray* mergedtrack,AliL3TrackArray *tracksin,AliL3TrackArray *tracksout){
244 //Loop over tracks and pass them to the track merger.
245 AliL3Track *tracks[2];
246
247 const Int_t kNOut=tracksout->GetNTracks();
248 const Int_t kNIn =tracksin->GetNTracks();
249 const Int_t kNMerged =mergedtrack->GetNTracks();
250
251 Bool_t *ismatchedin = new Bool_t[kNIn];
252 for(Int_t in =0;in<kNIn;in++)
253 ismatchedin[in]=kFALSE;
254 Bool_t *ismatchedout = new Bool_t[kNOut];
255 for(Int_t out =0;out<kNOut;out++)
256 ismatchedout[out] = kFALSE;
257 for(Int_t out =0;out<kNOut;out++){
258 AliL3Track *outertrack=(AliL3Track*)tracksout->GetCheckedTrack(out);
259 if(!outertrack) continue;
260 for(Int_t in =0;in<kNIn;in++){
261 if(ismatchedin[in]) continue;
262 AliL3Track *innertrack=(AliL3Track*)tracksin->GetCheckedTrack(in);
263 if(!innertrack) continue;
264 if(outertrack==innertrack) continue;
265 if(outertrack->GetCharge()!=innertrack->GetCharge()) continue;
266 if(IsTrack(innertrack,outertrack)){
267 tracks[0]=innertrack; tracks[1]=outertrack;
268 SortTracks(tracks,2);
269 if(tracks[0]->GetLastPointX()<tracks[1]->GetFirstPointX()){
270 MultiMerge(mergedtrack,tracks,2);
271 tracksout->Remove(out);
272 tracksin->Remove(in);
273 ismatchedin[in]=kTRUE;
274 ismatchedout[out]=kTRUE;
275 break;
276 }
277 }
278 }
279 }
280
281 Int_t nmerged = mergedtrack->GetNTracks()-kNMerged;
282 LOG(AliL3Log::kInformational,"AliL3TrackMerger::Merge","Result")
283 <<AliL3Log::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
284 delete[] ismatchedin;
285 delete[] ismatchedout;
286 return nmerged;
287}
288
289