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