]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 1 | // @(#) $Id$ |
99cd2dbf | 2 | |
b661165c | 3 | // Author: Uli Frankenfeld <mailto:franken@fi.uib.no> |
3e87ef69 | 4 | //*-- Copyright © ALICE HLT Group |
108615fc | 5 | |
118c26c3 | 6 | #include "AliL3StandardIncludes.h" |
7 | ||
108615fc | 8 | #include "AliL3Logging.h" |
9 | #include "AliL3GlobalMerger.h" | |
10 | #include "AliL3Track.h" | |
11 | #include "AliL3Transform.h" | |
12 | #include "AliL3TrackArray.h" | |
b661165c | 13 | |
3e87ef69 | 14 | /** \class AliL3GlobalMerger |
15 | <pre> | |
108615fc | 16 | //_____________________________________________________________ |
b661165c | 17 | // AliL3GlobalMerger |
108615fc | 18 | // |
19 | // The L3 Slice merger | |
20 | // | |
3e87ef69 | 21 | </pre> |
22 | */ | |
108615fc | 23 | |
24 | ClassImp(AliL3GlobalMerger) | |
25 | ||
0a86fbb7 | 26 | AliL3GlobalMerger::AliL3GlobalMerger() |
27 | { | |
28 | //Default constructor. Use Setup to specify and setup the necessary parameters and arrays. | |
108615fc | 29 | Is2Global(kTRUE); |
0a86fbb7 | 30 | SetParameter(0,0,0,0,0); |
31 | fNSlices=0; | |
32 | fFirst=0; | |
33 | fLast=0; | |
108615fc | 34 | } |
35 | ||
36 | ||
0a86fbb7 | 37 | AliL3GlobalMerger::~AliL3GlobalMerger() |
38 | { | |
39 | //Destructor | |
40 | } | |
41 | ||
42 | void AliL3GlobalMerger::Setup(Int_t first,Int_t last) | |
43 | { | |
44 | //Used to setup the arrays and everything | |
45 | ||
108615fc | 46 | fNSlices = last-first+1; |
47 | fFirst = first; | |
48 | fLast = last; | |
0a86fbb7 | 49 | InitMerger(last-first+1); |
108615fc | 50 | } |
51 | ||
0a86fbb7 | 52 | void AliL3GlobalMerger::InitSlice(Int_t slice) |
53 | { | |
108615fc | 54 | // |
55 | // Select Sector The following FillTracks call will | |
56 | // fill this Sector | |
57 | // | |
58 | fSlice = slice; | |
59 | fCurrentTracks = fSlice - fFirst; | |
60 | } | |
61 | ||
99cd2dbf | 62 | Double_t AliL3GlobalMerger::CheckTracks(AliL3Track *innertrack,AliL3Track *outertrack,Int_t slice) |
63 | { | |
64 | //Compare the tracks by propagating the outermost track to the last and first point plane | |
65 | //of the innermost track. This plane is defined by the padrow plane where these points | |
66 | //are. | |
67 | ||
0a86fbb7 | 68 | if(innertrack->GetCharge()!=outertrack->GetCharge()) return -1; |
99cd2dbf | 69 | |
0a86fbb7 | 70 | Float_t angle = 0;//perpendicular to the padrowplane (in local system) |
494fad94 | 71 | AliL3Transform::Local2GlobalAngle(&angle,slice); |
99cd2dbf | 72 | Double_t dx[2],dy[2],dz[2]; |
73 | Double_t diff =-1; | |
74 | AliL3Track *tracks[2]; | |
75 | tracks[0] = innertrack; | |
76 | tracks[1] = outertrack; | |
77 | SortGlobalTracks(tracks,2); | |
78 | innertrack = tracks[0]; | |
79 | outertrack = tracks[1]; | |
80 | ||
81 | Float_t point[3]; | |
82 | ||
83 | point[0]=innertrack->GetLastPointX(); | |
84 | point[1]=innertrack->GetLastPointY(); | |
85 | point[2]=innertrack->GetLastPointZ(); | |
5a31e9df | 86 | AliL3Transform::Global2LocHLT(point,slice); |
99cd2dbf | 87 | |
88 | outertrack->CalculateReferencePoint(angle,point[0]);//local x = global distance to padrowplane | |
89 | if(!outertrack->IsPoint()) return diff; | |
90 | dx[0] = fabs(outertrack->GetPointX()-innertrack->GetLastPointX()); | |
91 | dy[0] = fabs(outertrack->GetPointY()-innertrack->GetLastPointY()); | |
92 | dz[0] = fabs(outertrack->GetPointZ()-innertrack->GetLastPointZ()); | |
93 | ||
94 | point[0]=innertrack->GetFirstPointX(); | |
95 | point[1]=innertrack->GetFirstPointY(); | |
96 | point[2]=innertrack->GetFirstPointZ(); | |
5a31e9df | 97 | AliL3Transform::Global2LocHLT(point,slice); |
99cd2dbf | 98 | |
99 | outertrack->CalculateReferencePoint(angle,point[0]);//local x = global distance to padrowplane | |
100 | if(!outertrack->IsPoint()) return diff; | |
101 | dx[1] = fabs(outertrack->GetPointX()-innertrack->GetFirstPointX()); | |
102 | dy[1] = fabs(outertrack->GetPointY()-innertrack->GetFirstPointY()); | |
103 | dz[1] = fabs(outertrack->GetPointZ()-innertrack->GetFirstPointZ()); | |
104 | ||
0a86fbb7 | 105 | diff=0;//This was a tough bug to find.... |
99cd2dbf | 106 | for(Int_t i=0; i<2; i++) |
107 | diff += sqrt(dx[i]*dx[i] + dy[i]*dy[i] + dz[i]*dz[i]); | |
108 | return diff; | |
109 | } | |
110 | ||
0a86fbb7 | 111 | void AliL3GlobalMerger::SlowMerge(Char_t *path) |
112 | { | |
113 | //Tuning of parameters. This matches _all_ tracks between two neighbouring | |
114 | //slices, and merges the ones which are closest in space. The difference | |
115 | //is written to a ntuppel, which can be used as a input for the SetParameters | |
116 | //when using normal Merge function. | |
117 | ||
118 | ||
108615fc | 119 | void* ntuple=GetNtuple(); |
120 | AliL3Track *track[2]; | |
121 | AliL3TrackArray *tout = GetOutTracks(); | |
0a86fbb7 | 122 | if(fNSlices<2) |
123 | { | |
124 | LOG(AliL3Log::kWarning,"AliL3GlobalMerger::SlowMerge","Slice Number") | |
125 | <<"Need more than one Slice!"<<ENDLOG; | |
126 | return; | |
108615fc | 127 | } |
0a86fbb7 | 128 | |
129 | for(Int_t i=0; i<fNSlices; i++) | |
130 | { | |
131 | //if(fNSlices!=18 && i+1 == fNSlices) continue; | |
132 | Int_t slice = fFirst + i; | |
133 | AliL3TrackArray *ttt0=GetInTracks(i); | |
134 | Int_t slice2 = i+1; | |
135 | //if(slice2==fNSlices) slice2 =0; | |
136 | ||
137 | //Make sure slices are on the same side of the TPC | |
138 | if(slice2 == 18) slice2=0; | |
139 | else if(slice2 == 36) slice2=18; | |
140 | AliL3TrackArray *ttt1=GetInTracks(slice2); | |
5a31e9df | 141 | //10 degrees -> the border of the slices in local coordinates |
142 | Float_t angle = AliL3Transform::Pi()/18; | |
0a86fbb7 | 143 | AliL3Transform::Local2GlobalAngle(&angle,slice); |
144 | ||
145 | //In the two following cases, the angle is 2*pi, so set it back to 0 in order for | |
146 | //the calculation of crossing points to be correct. | |
147 | if(slice==17 || slice==35) | |
148 | angle=0; | |
149 | if(i==0) | |
150 | ttt0->QSort(); | |
151 | ttt1->QSort(); | |
152 | for(Int_t s0=0;s0<ttt0->GetNTracks();s0++) | |
153 | { | |
154 | AliL3Track *track0=ttt0->GetCheckedTrack(s0); | |
155 | if(!track0) continue; | |
156 | track0->CalculateHelix(); | |
157 | track0->CalculateEdgePoint(angle); | |
158 | // if(track0->IsPoint()) AddTrack(tout,track0); | |
159 | } | |
160 | for(Int_t s1=0;s1<ttt1->GetNTracks();s1++) | |
161 | { | |
162 | AliL3Track *track1=ttt1->GetCheckedTrack(s1); | |
163 | if(!track1) continue; | |
164 | track1->CalculateHelix(); | |
165 | track1->CalculateEdgePoint(angle); | |
166 | // if(track1->IsPoint()) AddTrack(tout,track1); | |
167 | } | |
168 | Bool_t merge = kTRUE; | |
169 | while(merge) | |
170 | { | |
171 | Int_t min0=-1,min1=-1; | |
172 | Double_t min=5; | |
173 | Int_t n0=ttt0->GetNTracks(),n1=ttt1->GetNTracks(); | |
174 | for(Int_t s0=0;s0<n0;s0++) | |
175 | { | |
176 | AliL3Track *track0=ttt0->GetCheckedTrack(s0); | |
177 | if(!track0) continue; | |
178 | if(!track0->IsPoint()) continue; | |
179 | for(Int_t s1=0;s1<n1;s1++) | |
180 | { | |
181 | AliL3Track *track1=ttt1->GetCheckedTrack(s1); | |
182 | if(!track1) continue; | |
183 | if(!track1->IsPoint()) continue; | |
184 | ||
185 | //Double_t diff = TrackDiff(track0,track1,angle); | |
186 | Double_t diff = CheckTracks(track0,track1,slice); | |
187 | //PrintDiff(track0,track1); | |
188 | if(diff>=0&&diff<min) | |
189 | { | |
190 | min=diff; | |
191 | min0=s0; | |
192 | min1=s1; | |
193 | } | |
194 | } | |
195 | } | |
196 | if(min0>=0&&min1>=0) | |
197 | { | |
198 | AliL3Track *track0=ttt0->GetTrack(min0); | |
199 | AliL3Track *track1=ttt1->GetTrack(min1); | |
200 | track[0] = track0; | |
201 | track[1] = track1; | |
202 | SortGlobalTracks(track,2); | |
5a31e9df | 203 | track1->CalculateEdgePoint((angle+AliL3Transform::Pi()/9)); |
0a86fbb7 | 204 | if(track1->IsPoint())//Check if the track will cross the boundary of yet another slice. |
205 | MultiMerge(ttt1,track,2); | |
206 | else | |
207 | MultiMerge(tout,track,2); | |
208 | track0->CalculateReferencePoint(angle); | |
209 | track1->CalculateReferencePoint(angle); | |
210 | //PrintDiff(track0,track1); | |
211 | FillNtuple(ntuple,track0,track1); | |
212 | ttt0->Remove(min0); | |
213 | ttt1->Remove(min1); | |
214 | ||
215 | } | |
216 | else merge = kFALSE; | |
217 | } | |
218 | ttt0->Compress(); | |
219 | ttt1->Compress(); | |
220 | LOG(AliL3Log::kInformational,"AliL3GlobalMerger::SlowMerge","Result") | |
221 | <<AliL3Log::kDec<<"Merged Tracks: "<<tout->GetNTracks()<<" at:" | |
222 | <<angle<<ENDLOG; | |
108615fc | 223 | } |
0a86fbb7 | 224 | Char_t fname[1024]; |
225 | sprintf(fname,"%s/merge_parameters.root",path); | |
226 | WriteNtuple(fname,ntuple); | |
108615fc | 227 | } |
228 | ||
0a86fbb7 | 229 | void AliL3GlobalMerger::Merge() |
230 | { | |
231 | //Normal merging procedure. Matches tracks which are within limits | |
232 | //set by SetParameters. Parameters can be tuned by SlowMerge. | |
233 | ||
108615fc | 234 | AliL3Track *track[2]; |
235 | AliL3TrackArray *tout = GetOutTracks(); | |
0a86fbb7 | 236 | if(fNSlices<2) |
237 | { | |
238 | LOG(AliL3Log::kWarning,"AliL3GlobalMerger::Merge","Slice Number") | |
239 | <<"Need more than one Slice!"<<ENDLOG; | |
240 | return; | |
108615fc | 241 | } |
0a86fbb7 | 242 | for(Int_t i=0; i<fNSlices; i++) |
243 | { | |
244 | //if(fNSlices!=18 && i+1 == fNSlices) continue; | |
245 | Int_t slice = fFirst + i; | |
246 | AliL3TrackArray *ttt0=GetInTracks(i); | |
247 | Int_t slice2 = i+1; | |
248 | //if(slice2==fNSlices) slice2 =0; | |
249 | ||
250 | //Make sure slices are on the same side of the TPC | |
251 | if(slice2 == 18) slice2=0; | |
252 | else if(slice2 == 36) slice2=18; | |
253 | AliL3TrackArray *ttt1=GetInTracks(slice2); | |
5a31e9df | 254 | //10 degrees -> the border of the slices in local coordinates |
255 | Float_t angle = AliL3Transform::Pi()/18; | |
0a86fbb7 | 256 | AliL3Transform::Local2GlobalAngle(&angle,slice); |
257 | ||
258 | //In the two following cases, the angle is 2*pi, so set it back to 0 in order for | |
259 | //the calculation of crossing points to be correct. | |
260 | if(slice==17 || slice==35) | |
261 | angle=0; | |
262 | if(i==0) | |
263 | ttt0->QSort(); | |
264 | ttt1->QSort(); | |
265 | Bool_t *ismatched0 = new Bool_t[ttt0->GetNTracks()]; | |
266 | Bool_t *ismatched1 = new Bool_t[ttt1->GetNTracks()]; | |
267 | Int_t n0=0,n1=0; | |
268 | for(Int_t s0=0;s0<ttt0->GetNTracks();s0++) | |
269 | { | |
270 | ismatched0[s0]=kFALSE; | |
271 | AliL3Track *track0=ttt0->GetCheckedTrack(s0); | |
272 | if(!track0) continue; | |
273 | track0->CalculateHelix(); | |
274 | track0->CalculateEdgePoint(angle); | |
275 | if(track0->IsPoint()) | |
276 | { | |
277 | n0++; | |
278 | track0->CalculateReferencePoint(angle); | |
279 | } | |
280 | } | |
281 | for(Int_t s1=0;s1<ttt1->GetNTracks();s1++) | |
282 | { | |
283 | ismatched1[s1]=kFALSE; | |
284 | AliL3Track *track1=ttt1->GetCheckedTrack(s1); | |
285 | if(!track1) continue; | |
286 | track1->CalculateHelix(); | |
287 | track1->CalculateEdgePoint(angle); | |
288 | if(track1->IsPoint()) | |
289 | { | |
290 | n1++; | |
291 | track1->CalculateReferencePoint(angle); | |
292 | } | |
293 | } | |
294 | for(Int_t s0=0;s0<ttt0->GetNTracks();s0++) | |
295 | { | |
296 | if(ismatched0[s0]) continue; | |
297 | AliL3Track *track0=ttt0->GetCheckedTrack(s0); | |
298 | if(!track0) continue; | |
299 | if(!track0->IsPoint()) continue; | |
300 | for(Int_t s1=0;s1<ttt1->GetNTracks();s1++) | |
301 | { | |
302 | if(ismatched1[s1]) continue; | |
303 | AliL3Track *track1=ttt1->GetCheckedTrack(s1); | |
304 | if(!track1) continue; | |
305 | if(!track1->IsPoint()) continue; | |
306 | if(IsRTrack(track0,track1)) | |
307 | { | |
308 | track[0] = track0; | |
309 | track[1] = track1; | |
310 | SortGlobalTracks(track,2); | |
311 | Double_t r0 = pow(track[0]->GetLastPointX(),2)+ | |
312 | pow(track[0]->GetLastPointY(),2); | |
313 | Double_t r1 = pow(track[1]->GetFirstPointX(),2)+ | |
314 | pow(track[1]->GetFirstPointY(),2); | |
315 | if(r0<r1) | |
316 | { | |
317 | MultiMerge(tout,track,2); | |
318 | ismatched0[s0]=kTRUE; | |
319 | ismatched1[s1]=kTRUE; | |
320 | ttt0->Remove(s0); | |
321 | ttt1->Remove(s1); | |
322 | break; | |
323 | /* | |
324 | The track is merged, so we will _not_ look for more matches. | |
325 | Because there could easily be more matches, if a track is being | |
326 | split within the sector.... | |
327 | */ | |
328 | } | |
329 | } | |
330 | } | |
331 | } | |
332 | LOG(AliL3Log::kInformational,"AliL3GlobalMerger::Merge","Result") | |
333 | <<AliL3Log::kDec<<"slice0: "<<n0<<" slice1: "<<n1 | |
334 | <<" Merged Tracks: "<<tout->GetNTracks()<<ENDLOG; | |
335 | delete [] ismatched0; | |
336 | delete [] ismatched1; | |
108615fc | 337 | } |
108615fc | 338 | } |