]>
Commit | Line | Data |
---|---|---|
108615fc | 1 | //Author: Uli Frankenfeld |
2 | //Last Modified: 06.12.2000 | |
3 | ||
4 | #include <math.h> | |
5 | #include <string.h> | |
6 | #include <iostream.h> | |
7 | #include "AliL3Logging.h" | |
8 | #include "AliL3TrackArray.h" | |
9 | #include "AliL3HoughTrack.h" | |
10 | #include "AliL3ConfMapTrack.h" | |
11 | #include "AliL3TrackSegmentData.h" | |
12 | #include "AliL3Transform.h" | |
13 | #include "AliL3ConfMapPoint.h" | |
14 | //_____________________________________________________________ | |
15 | // | |
16 | // The L3 TrackArray | |
17 | // | |
18 | ||
19 | ClassImp(AliL3TrackArray) | |
20 | ||
21 | AliL3TrackArray::AliL3TrackArray(){ | |
22 | //Default constructor | |
23 | fSize = 0; | |
24 | fNTracks=0; | |
25 | fNAbsent=0; | |
26 | fTrackType='t'; | |
27 | SetSize(); | |
28 | } | |
29 | ||
30 | ||
31 | AliL3TrackArray::AliL3TrackArray(Int_t ntrack){ | |
32 | //Constructor. | |
33 | fSize = 0; | |
34 | fNTracks=0; | |
35 | fNAbsent=0; | |
36 | fTrackType='t'; | |
37 | SetSize(ntrack); | |
38 | } | |
39 | ||
40 | AliL3TrackArray::AliL3TrackArray(char* tracktype,Int_t ntrack){ | |
41 | //Constructor. | |
42 | fSize = 0; | |
43 | fNTracks=0; | |
44 | fNAbsent=0; | |
45 | if(strcmp(tracktype,"AliL3Track")==0) fTrackType='t'; | |
46 | if(strcmp(tracktype,"AliL3ConfMapTrack")==0) fTrackType='c'; | |
47 | if(strcmp(tracktype,"AliL3HoughTrack")==0) fTrackType='h'; | |
48 | SetSize(ntrack); | |
49 | } | |
50 | ||
51 | AliL3TrackArray::AliL3TrackArray(char* tracktype){ | |
52 | //Constructor. | |
53 | fSize = 0; | |
54 | fNTracks=0; | |
55 | fNAbsent=0; | |
56 | if(strcmp(tracktype,"AliL3Track")==0) fTrackType='t'; | |
57 | if(strcmp(tracktype,"AliL3ConfMapTrack")==0) fTrackType='c'; | |
58 | if(strcmp(tracktype,"AliL3HoughTrack")==0) fTrackType='h'; | |
59 | SetSize(); | |
60 | } | |
61 | ||
62 | ||
63 | AliL3TrackArray::~AliL3TrackArray(){ | |
64 | //Destructor | |
65 | DeleteArray(); | |
66 | } | |
67 | ||
68 | ||
69 | AliL3Track *AliL3TrackArray::NextTrack(){ | |
70 | if(fNTracks<fSize) return fTrack[fNTracks++]; | |
71 | SetSize(fSize+100); | |
72 | return fTrack[fNTracks++]; | |
73 | } | |
74 | ||
75 | void AliL3TrackArray::DeleteArray(){ | |
76 | for(Int_t i=0; i<fSize;i++) | |
77 | delete fTrack[i]; | |
78 | delete[] fIsPresent; | |
79 | delete[] fTrack; | |
80 | } | |
81 | ||
82 | Bool_t AliL3TrackArray::SetSize(Int_t newsize){ | |
83 | if(newsize<=fSize) return kFALSE; //shrink comes later!! | |
84 | if(!fSize){ | |
85 | fSize = newsize; | |
86 | fTrack = new AliL3Track*[fSize]; | |
87 | fIsPresent = new Bool_t[fSize]; | |
88 | switch(fTrackType){ | |
89 | case 't': | |
90 | for(Int_t i=0;i<fSize;i++){ | |
91 | fTrack[i] = new AliL3Track(); | |
92 | fIsPresent[i] = kTRUE; | |
93 | } | |
94 | break; | |
95 | case 'c': | |
96 | for(Int_t i=0;i<fSize;i++){ | |
97 | fTrack[i] = new AliL3ConfMapTrack(); | |
98 | fIsPresent[i] = kTRUE; | |
99 | } | |
100 | break; | |
101 | case 'h': | |
102 | for(Int_t i=0;i<fSize;i++){ | |
103 | fTrack[i] = new AliL3HoughTrack(); | |
104 | fIsPresent[i] = kTRUE; | |
105 | } | |
106 | break; | |
107 | default: | |
108 | return kFALSE; | |
109 | } | |
110 | return kTRUE; | |
111 | } | |
112 | AliL3Track **tmp = new AliL3Track*[fSize]; | |
113 | Bool_t *pre = new Bool_t[fSize]; | |
114 | for(Int_t i=0; i<fSize;i++){ | |
115 | tmp[i] = fTrack[i]; | |
116 | pre[i] = fIsPresent[i]; | |
117 | } | |
118 | delete[] fTrack; | |
119 | delete[] fIsPresent; | |
120 | fTrack = new AliL3Track*[fSize]; | |
121 | fIsPresent = new Bool_t[newsize]; | |
122 | for(Int_t i=0; i<fSize;i++){ | |
123 | fTrack[i] = tmp[i]; | |
124 | fIsPresent[i] = pre[i]; | |
125 | } | |
126 | delete[] tmp; | |
127 | delete[] pre; | |
128 | switch(fTrackType){ | |
129 | case 't': | |
130 | for(Int_t i=fSize;i<newsize;i++){ | |
131 | fTrack[i] = new AliL3Track(); | |
132 | fIsPresent[i] = kTRUE; | |
133 | } | |
134 | break; | |
135 | case 'c': | |
136 | for(Int_t i=fSize;i<newsize;i++){ | |
137 | fTrack[i] = new AliL3ConfMapTrack(); | |
138 | fIsPresent[i] = kTRUE; | |
139 | } | |
140 | break; | |
141 | case 'h': | |
142 | for(Int_t i=fSize;i<newsize;i++){ | |
143 | fTrack[i] = new AliL3HoughTrack(); | |
144 | fIsPresent[i] = kTRUE; | |
145 | } | |
146 | break; | |
147 | default: | |
148 | return kFALSE; | |
149 | } | |
150 | fSize = newsize; | |
151 | return kTRUE; | |
152 | } | |
153 | ||
154 | void AliL3TrackArray::Reset(){ | |
155 | fNTracks=0; | |
156 | fNAbsent=0; | |
157 | for(Int_t i=0; i<fSize;i++) | |
158 | fIsPresent[i] = kTRUE; | |
159 | } | |
160 | ||
161 | void AliL3TrackArray::Remove(Int_t track){ | |
162 | if(fIsPresent[track]){ | |
163 | fIsPresent[track]=kFALSE; | |
164 | fNAbsent++; | |
165 | } | |
166 | } | |
167 | ||
168 | void AliL3TrackArray::FillTracks(Int_t ntracks, AliL3TrackSegmentData* tr){ | |
169 | //Read tracks from shared memory (or memory) | |
170 | AliL3TrackSegmentData *trs = tr; | |
171 | for(Int_t i=0; i<ntracks; i++){ | |
172 | AliL3Track *track = NextTrack(); | |
173 | track->SetPt(trs->fPt); | |
174 | track->SetPsi(trs->fPsi); | |
175 | track->SetTgl(trs->fTgl); | |
176 | track->SetNHits(trs->fNPoints); | |
177 | track->SetCharge(trs->fCharge); | |
178 | track->SetFirstPoint(trs->fX,trs->fY,trs->fZ); | |
179 | track->SetLastPoint(trs->fLastX,trs->fLastY,trs->fLastZ); | |
180 | track->SetHits( trs->fNPoints, trs->fPointIDs ); | |
181 | UChar_t *tmpP = (UChar_t*)trs; | |
182 | tmpP += sizeof(AliL3TrackSegmentData)+trs->fNPoints*sizeof(UInt_t); | |
183 | trs = (AliL3TrackSegmentData*)tmpP; | |
184 | } | |
185 | } | |
186 | ||
187 | void AliL3TrackArray::FillTracks(Int_t ntracks, AliL3TrackSegmentData* tr,Int_t slice, AliL3Transform* trans){ | |
188 | //Read tracks from shared memory (or memory) | |
189 | AliL3TrackSegmentData *trs = tr; | |
190 | for(Int_t i=0; i<ntracks; i++){ | |
191 | AliL3Track *track = NextTrack(); | |
192 | track->SetPt(trs->fPt); | |
193 | Float_t psi[1]; | |
194 | psi[0]=trs->fPsi; | |
195 | trans->Local2GlobalAngle(psi,slice); | |
196 | track->SetPsi(psi[0]); | |
197 | track->SetTgl(trs->fTgl); | |
198 | track->SetNHits(trs->fNPoints); | |
199 | track->SetCharge(trs->fCharge); | |
200 | Float_t first[3]; | |
201 | first[0]=trs->fX;first[1]=trs->fY;first[2]=trs->fZ; | |
202 | trans->Local2Global(first,slice); | |
203 | track->SetFirstPoint(first[0],first[1],first[2]); | |
204 | Float_t last[3]; | |
205 | last[0]=trs->fLastX;last[1]=trs->fLastY;last[2]=trs->fLastZ; | |
206 | trans->Local2Global(last,slice); | |
207 | track->SetLastPoint(last[0],last[1],last[2]); | |
208 | track->SetHits( trs->fNPoints, trs->fPointIDs ); | |
209 | UChar_t *tmpP = (UChar_t*)trs; | |
210 | tmpP += sizeof(AliL3TrackSegmentData)+trs->fNPoints*sizeof(UInt_t); | |
211 | trs = (AliL3TrackSegmentData*)tmpP; | |
212 | } | |
213 | } | |
214 | ||
215 | UInt_t AliL3TrackArray::GetOutSize(){ | |
216 | UInt_t count = GetOutCount(); //use only present tracks | |
217 | UInt_t tHits = 0; | |
218 | for(Int_t i=0;i<fNTracks;i++){ //loop over all tracks | |
219 | AliL3Track *track = GetCheckedTrack(i); //use only present tracks | |
220 | if(track) //use only present tracks | |
221 | tHits += track->GetNHits(); | |
222 | } | |
223 | ||
224 | //calculate size of track | |
225 | return count*sizeof(AliL3TrackSegmentData)+sizeof(UInt_t)*tHits; | |
226 | } | |
227 | ||
228 | UInt_t AliL3TrackArray::WriteTracks(UInt_t & ntracks,AliL3TrackSegmentData* tr){ | |
229 | ntracks = GetOutCount(); | |
230 | return WriteTracks(tr); | |
231 | } | |
232 | ||
233 | UInt_t AliL3TrackArray::WriteTracks(AliL3TrackSegmentData* tr){ | |
234 | if(GetTrackType()=='c') return WriteConfMapTracks(tr); | |
235 | AliL3TrackSegmentData *tP = tr; | |
236 | UInt_t *pP; | |
237 | UInt_t size = 0; | |
238 | for(Int_t i=0; i<fNTracks; i++){ //loop over all tracks | |
239 | AliL3Track *track = GetCheckedTrack(i); //use only present tracks | |
240 | if(!track) continue; //use only present tracks | |
241 | tP->fX = track->GetFirstPointX(); | |
242 | tP->fY = track->GetFirstPointY(); | |
243 | tP->fZ = track->GetFirstPointZ(); | |
244 | tP->fPt = track->GetPt(); | |
245 | tP->fLastX = track->GetLastPointX(); | |
246 | tP->fLastY = track->GetLastPointY(); | |
247 | tP->fLastZ = track->GetLastPointZ(); | |
248 | tP->fPsi = track->GetPsi(); | |
249 | tP->fTgl = track->GetTgl(); | |
250 | tP->fCharge = track->GetCharge(); | |
251 | tP->fNPoints = track->GetNHits(); | |
252 | pP = (UInt_t*)track->GetHitNumbers(); | |
253 | for (UInt_t j=0;j<tP->fNPoints;j++){ | |
254 | tP->fPointIDs[j] = pP[j]; | |
255 | } | |
256 | Byte_t *tmpP = (Byte_t *)tP; | |
257 | tmpP += sizeof(AliL3TrackSegmentData)+tP->fNPoints*sizeof(UInt_t); | |
258 | size += sizeof(AliL3TrackSegmentData)+tP->fNPoints*sizeof(UInt_t); | |
259 | tP = (AliL3TrackSegmentData*)tmpP; | |
260 | } | |
261 | return size; | |
262 | } | |
263 | ||
264 | UInt_t AliL3TrackArray::WriteConfMapTracks(AliL3TrackSegmentData* tr){ | |
265 | // use first and last point objects | |
266 | AliL3TrackSegmentData *tP = tr; | |
267 | UInt_t *pP; | |
268 | UInt_t size = 0; | |
269 | for(Int_t i=0; i<fNTracks; i++){ //loop over all tracks | |
270 | AliL3ConfMapTrack *track =(AliL3ConfMapTrack *) GetCheckedTrack(i); //use only present tracks | |
271 | if(!track) continue; //use only present tracks | |
272 | AliL3ConfMapPoint *hit = (AliL3ConfMapPoint*)track->lastHit; | |
273 | AliL3ConfMapPoint *lastHit = (AliL3ConfMapPoint*)track->firstHit; | |
274 | tP->fX = hit->GetX(); | |
275 | tP->fY = hit->GetY(); | |
276 | tP->fZ = hit->GetZ(); | |
277 | tP->fLastX = lastHit->GetX(); | |
278 | tP->fLastY = lastHit->GetY(); | |
279 | tP->fLastZ = lastHit->GetZ(); | |
280 | ||
281 | // tP->fX = track->GetFirstPointX(); | |
282 | // tP->fY = track->GetFirstPointY(); | |
283 | // tP->fZ = track->GetFirstPointZ(); | |
284 | tP->fPt = track->GetPt(); | |
285 | // tP->fLastX = track->GetLastPointX(); | |
286 | // tP->fLastY = track->GetLastPointY(); | |
287 | // tP->fLastZ = track->GetLastPointZ(); | |
288 | tP->fPsi = track->GetPsi(); | |
289 | tP->fTgl = track->GetTgl(); | |
290 | tP->fCharge = track->GetCharge(); | |
291 | tP->fNPoints = track->GetNHits(); | |
292 | pP = (UInt_t*)track->GetHitNumbers(); | |
293 | for (UInt_t j=0;j<tP->fNPoints;j++){ | |
294 | tP->fPointIDs[j] = pP[j]; | |
295 | } | |
296 | Byte_t *tmpP = (Byte_t *)tP; | |
297 | tmpP += sizeof(AliL3TrackSegmentData)+tP->fNPoints*sizeof(UInt_t); | |
298 | size +=sizeof(AliL3TrackSegmentData)+tP->fNPoints*sizeof(UInt_t); | |
299 | tP = (AliL3TrackSegmentData*)tmpP; | |
300 | } | |
301 | return size; | |
302 | } | |
303 | ||
304 | void AliL3TrackArray::AddTracks(AliL3TrackArray *newtrack){ | |
305 | if(GetTrackType() != newtrack->GetTrackType()) | |
306 | return; | |
307 | if(fSize < fNTracks+newtrack->GetNPresent()) | |
308 | SetSize(fSize+newtrack->GetSize()); | |
309 | for(Int_t i =0;i<newtrack->GetNTracks();i++){ | |
310 | AliL3Track *tpt = newtrack->GetCheckedTrack(i); | |
311 | if(!tpt) continue; | |
312 | newtrack->Remove(i); | |
313 | AliL3Track *track = NextTrack(); | |
314 | track->SetNHits(tpt->GetNHits()); | |
315 | track->SetHits(tpt->GetNHits(),(UInt_t *)tpt->GetHitNumbers()); | |
316 | track->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ()); | |
317 | track->SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ()); | |
318 | track->SetPt(tpt->GetPt()); | |
319 | track->SetPsi(tpt->GetPsi()); | |
320 | track->SetTgl(tpt->GetTgl()); | |
321 | track->SetCharge(tpt->GetCharge()); | |
322 | } | |
323 | } | |
324 | ||
325 | ||
326 | void AliL3TrackArray::Compress(){ | |
327 | if(GetNPresent()==GetNTracks()) return; | |
328 | AliL3Track **tmp = new AliL3Track *[fNTracks]; | |
329 | Int_t present=0; | |
330 | Int_t absent=GetNPresent(); | |
331 | for(Int_t i=0;i<GetNTracks();i++){ | |
332 | if(fIsPresent[i]) tmp[present++] = fTrack[i]; | |
333 | else tmp[absent++] = fTrack[i]; | |
334 | } | |
335 | for(Int_t i=0;i<GetNTracks();i++) | |
336 | fIsPresent[i]=kTRUE; | |
337 | ||
338 | //Copy pointers back | |
339 | for(Int_t i=0; i<GetNTracks();i++){ | |
340 | fTrack[i]=tmp[i]; | |
341 | } | |
342 | ||
343 | delete[] tmp; | |
344 | ||
345 | fNTracks = GetNPresent(); | |
346 | fNAbsent = 0; | |
347 | } | |
348 | ||
349 | void AliL3TrackArray::QSort(){ | |
350 | // compress an sort | |
351 | Compress(); | |
352 | QSort(fTrack,0,fNTracks); | |
353 | } | |
354 | ||
355 | void AliL3TrackArray::QSort( AliL3Track **a, Int_t first, Int_t last){ | |
356 | ||
357 | // Sort array of AliL3Track pointers using a quicksort algorithm. | |
358 | // Uses TrackCompare() to compare objects. | |
359 | // Thanks to Root! | |
360 | ||
361 | static AliL3Track *tmp; | |
362 | static int i; // "static" to save stack space | |
363 | int j; | |
364 | ||
365 | while (last - first > 1) { | |
366 | i = first; | |
367 | j = last; | |
368 | for (;;) { | |
369 | while (++i < last && TrackCompare(a[i], a[first]) < 0) | |
370 | ; | |
371 | while (--j > first && TrackCompare(a[j], a[first]) > 0) | |
372 | ; | |
373 | if (i >= j) | |
374 | break; | |
375 | ||
376 | tmp = a[i]; | |
377 | a[i] = a[j]; | |
378 | a[j] = tmp; | |
379 | } | |
380 | if (j == first) { | |
381 | ++first; | |
382 | continue; | |
383 | } | |
384 | tmp = a[first]; | |
385 | a[first] = a[j]; | |
386 | a[j] = tmp; | |
387 | if (j - first < last - (j + 1)) { | |
388 | QSort(a, first, j); | |
389 | first = j + 1; // QSort(j + 1, last); | |
390 | } else { | |
391 | QSort(a, j + 1, last); | |
392 | last = j; // QSort(first, j); | |
393 | } | |
394 | } | |
395 | } | |
396 | ||
397 | Int_t AliL3TrackArray::TrackCompare(AliL3Track *a, AliL3Track *b){ | |
398 | // Compare the two tracks. | |
399 | ||
400 | if(a->GetNHits() < b->GetNHits()) return 1; | |
401 | if(a->GetNHits() > b->GetNHits()) return -1; | |
402 | return 0; | |
403 | } | |
404 | ||
405 |