fix for disabled hough tracking code
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCTrackArray.cxx
CommitLineData
a6c02c85 1// @(#) $Id$
4aa41877 2// Original: AliHLTTrackArray.cxx,v 1.21 2005/06/14 10:55:21 cvetan
a6c02c85 3
4fdaad1e 4/**************************************************************************
d53596be 5 * This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
4fdaad1e 7 * *
d53596be 8 * Primary Authors: Uli Frankenfeld, maintained by *
9 * Matthias Richter <Matthias.Richter@ift.uib.no> *
10 * for The ALICE HLT Project. *
4fdaad1e 11 * *
12 * Permission to use, copy, modify and distribute this software and its *
13 * documentation strictly for non-commercial purposes is hereby granted *
14 * without fee, provided that the above copyright notice appears in all *
15 * copies and that both the copyright notice and this permission notice *
16 * appear in the supporting documentation. The authors make no claims *
17 * about the suitability of this software for any purpose. It is *
18 * provided "as is" without express or implied warranty. *
19 **************************************************************************/
20
21/** @file AliHLTTPCTrackArray.cxx
22 @author Uli Frankenfeld, maintained by Matthias Richter
23 @date
24 @brief Array of AliHLTTPCTracks */
a6c02c85 25
312160d3 26#include "AliLog.h"
27#include "TClass.h"
a6c02c85 28#include "AliHLTTPCLogging.h"
29#include "AliHLTTPCTrackArray.h"
5b538a2c 30// Matthias 17.10.2007 the hough code has been disabled for the moment
31//#define INCLUDE_TPC_HOUGH
a6c02c85 32#ifdef INCLUDE_TPC_HOUGH
33#include "AliHLTTPCHoughTrack.h"
34#endif
35#include "AliHLTTPCModelTrack.h"
36#include "AliHLTTPCConfMapTrack.h"
37#include "AliHLTTPCTrackSegmentData.h"
38#include "AliHLTTPCTransform.h"
39#include "AliHLTTPCConfMapPoint.h"
40
a6c02c85 41#if __GNUC__ >= 3
42using namespace std;
43#endif
44
45ClassImp(AliHLTTPCTrackArray)
46
47AliHLTTPCTrackArray::AliHLTTPCTrackArray()
4fdaad1e 48 :
2a083ac4 49 fTrackType('t'),
4fdaad1e 50 fSize(0),
2a083ac4 51 fIsPresent(NULL),
4fdaad1e 52 fNAbsent(0),
2a083ac4 53 fTrack(NULL),
54 fNTracks(0)
a6c02c85 55{
56 //Default constructor
4fdaad1e 57 SetSize();
58}
59
60
61AliHLTTPCTrackArray::AliHLTTPCTrackArray(const AliHLTTPCTrackArray&)
62 :
2a083ac4 63 fTrackType('t'),
4fdaad1e 64 fSize(0),
2a083ac4 65 fIsPresent(NULL),
4fdaad1e 66 fNAbsent(0),
2a083ac4 67 fTrack(NULL),
68 fNTracks(0)
4fdaad1e 69{
70 //constructor
71 SetSize();
72}
73
74AliHLTTPCTrackArray& AliHLTTPCTrackArray::operator=(const AliHLTTPCTrackArray&)
75{
76 //assignment
77 fSize=0;
a6c02c85 78 fNTracks=0;
79 fNAbsent=0;
80 fTrackType='t';
81 SetSize();
4fdaad1e 82 return *this;
a6c02c85 83}
84
a6c02c85 85AliHLTTPCTrackArray::AliHLTTPCTrackArray(Int_t ntrack)
4fdaad1e 86 :
2a083ac4 87 fTrackType('t'),
4fdaad1e 88 fSize(0),
2a083ac4 89 fIsPresent(NULL),
4fdaad1e 90 fNAbsent(0),
2a083ac4 91 fTrack(NULL),
92 fNTracks(0)
a6c02c85 93{
94 //Constructor.
a6c02c85 95 SetSize(ntrack);
96}
97
98AliHLTTPCTrackArray::AliHLTTPCTrackArray(char* tracktype,Int_t ntrack)
4fdaad1e 99 :
2a083ac4 100 fTrackType('t'),
4fdaad1e 101 fSize(0),
2a083ac4 102 fIsPresent(NULL),
103 fNAbsent(0),
104 fTrack(NULL),
105 fNTracks(0)
a6c02c85 106{
107 //Constructor.
a6c02c85 108 if(strcmp(tracktype,"AliHLTTPCTrack")==0) fTrackType='t';
109 if(strcmp(tracktype,"AliHLTTPCConfMapTrack")==0) fTrackType='c';
110#ifdef INCLUDE_TPC_HOUGH
111 if(strcmp(tracktype,"AliHLTTPCHoughTrack")==0) fTrackType='h';
112#endif
113 if(strcmp(tracktype,"AliHLTTPCModelTrack")==0) fTrackType='m';
114 SetSize(ntrack);
115}
116
117AliHLTTPCTrackArray::AliHLTTPCTrackArray(char* tracktype)
4fdaad1e 118 :
2a083ac4 119 fTrackType('t'),
4fdaad1e 120 fSize(0),
2a083ac4 121 fIsPresent(NULL),
122 fNAbsent(0),
123 fTrack(NULL),
124 fNTracks(0)
a6c02c85 125{
126 //Constructor.
a6c02c85 127 if(strcmp(tracktype,"AliHLTTPCTrack")==0) fTrackType='t';
128 if(strcmp(tracktype,"AliHLTTPCConfMapTrack")==0) fTrackType='c';
129#ifdef INCLUDE_TPC_HOUGH
130 if(strcmp(tracktype,"AliHLTTPCHoughTrack")==0) fTrackType='h';
131#endif
132 if(strcmp(tracktype,"AliHLTTPCModelTrack")==0) fTrackType='m';
133 SetSize();
134}
135
136AliHLTTPCTrackArray::~AliHLTTPCTrackArray()
137{
138 //Destructor
139 DeleteArray();
140}
141
142
143AliHLTTPCTrack *AliHLTTPCTrackArray::NextTrack()
144{
145 //next track in array
146 if(fNTracks<fSize) return fTrack[fNTracks++];
147 SetSize(fSize+100);
148 return fTrack[fNTracks++];
149}
150
151void AliHLTTPCTrackArray::DeleteArray()
152{
153 //delete array
154 for(Int_t i=0; i<fSize;i++)
155 delete fTrack[i];
156 delete[] fIsPresent;
157 delete[] fTrack;
158}
159
160Bool_t AliHLTTPCTrackArray::SetSize(Int_t newsize)
161{
162 //set size
163 if(newsize<=fSize) return kFALSE; //shrink comes later!!
164 if(!fSize){
165 fSize = newsize;
166 fTrack = new AliHLTTPCTrack*[fSize];
167 fIsPresent = new Bool_t[fSize];
168 switch(fTrackType){
169 case 't':
170 for(Int_t i=0;i<fSize;i++){
171 fTrack[i] = new AliHLTTPCTrack();
172 fIsPresent[i] = kTRUE;
173 }
174 break;
175 case 'c':
176 for(Int_t i=0;i<fSize;i++){
177 fTrack[i] = new AliHLTTPCConfMapTrack();
178 fIsPresent[i] = kTRUE;
179 }
180 break;
181#ifdef INCLUDE_TPC_HOUGH
182 case 'h':
183 for(Int_t i=0;i<fSize;i++){
184 fTrack[i] = new AliHLTTPCHoughTrack();
185 fIsPresent[i] = kTRUE;
186 }
187 break;
188#endif
189 case 'm':
190 for(Int_t i=0;i<fSize;i++){
191 fTrack[i] = new AliHLTTPCModelTrack();
192 fIsPresent[i] = kTRUE;
193 }
194 break;
195 default:
196 return kFALSE;
197 }
198 return kTRUE;
199 }
200 AliHLTTPCTrack **tmp = new AliHLTTPCTrack*[fSize];
201 Bool_t *pre = new Bool_t[fSize];
202 for(Int_t i=0; i<fSize;i++){
203 tmp[i] = fTrack[i];
204 pre[i] = fIsPresent[i];
205 }
206 delete[] fTrack;
207 delete[] fIsPresent;
208 fTrack = new AliHLTTPCTrack*[newsize];
209 fIsPresent = new Bool_t[newsize];
210 for(Int_t i=0; i<fSize;i++){
211 fTrack[i] = tmp[i];
212 fIsPresent[i] = pre[i];
213 }
214 delete[] tmp;
215 delete[] pre;
216 switch(fTrackType){
217 case 't':
218 for(Int_t i=fSize;i<newsize;i++){
219 fTrack[i] = new AliHLTTPCTrack();
220 fIsPresent[i] = kTRUE;
221 }
222 break;
223 case 'c':
224 for(Int_t i=fSize;i<newsize;i++){
225 fTrack[i] = new AliHLTTPCConfMapTrack();
226 fIsPresent[i] = kTRUE;
227 }
228 break;
229#ifdef INCLUDE_TPC_HOUGH
230 case 'h':
231 for(Int_t i=fSize;i<newsize;i++){
232 fTrack[i] = new AliHLTTPCHoughTrack();
233 fIsPresent[i] = kTRUE;
234 }
235 break;
236#endif
237 case 'm':
238 for(Int_t i=fSize;i<newsize;i++){
239 fTrack[i] = new AliHLTTPCModelTrack();
240 fIsPresent[i] = kTRUE;
241 }
242 break;
243 default:
244 return kFALSE;
245 }
246 fSize = newsize;
247 return kTRUE;
248}
249
250void AliHLTTPCTrackArray::Reset()
251{
252 //reset
253 fNTracks=0;
254 fNAbsent=0;
255 for(Int_t i=0; i<fSize;i++)
256 fIsPresent[i] = kTRUE;
257}
258
259void AliHLTTPCTrackArray::Remove(Int_t track)
260{
261 //remove track
262 if(fIsPresent[track]){
263 fIsPresent[track]=kFALSE;
264 fNAbsent++;
265 }
266}
267
4fdaad1e 268void AliHLTTPCTrackArray::FillTracks(Int_t ntracks, AliHLTTPCTrackSegmentData* tr,Int_t slice, Int_t bTransform)
a6c02c85 269{
270 //Read tracks from shared memory (or memory)
271 AliHLTTPCTrackSegmentData *trs = tr;
272 for(Int_t i=0; i<ntracks; i++){
273 AliHLTTPCTrack *track = NextTrack();
274 track->SetPt(trs->fPt);
275 track->SetPterr(trs->fPterr);
276 Float_t psi[1];
277 psi[0]=trs->fPsi;
4fdaad1e 278 if (slice>=0 && bTransform!=0) {
279 AliHLTTPCTransform::Local2GlobalAngle(psi,slice);
280 }
281 //cout << "psi " << psi[0] << endl;
a6c02c85 282 track->SetPsi(psi[0]);
283 track->SetTgl(trs->fTgl);
284 track->SetPsierr(trs->fPsierr);
285 track->SetTglerr(trs->fTglerr);
286 track->SetNHits(trs->fNPoints);
287 track->SetCharge(trs->fCharge);
288 Float_t first[3];
289 first[0]=trs->fX;first[1]=trs->fY;first[2]=trs->fZ;
4fdaad1e 290 if (slice>=0 && bTransform!=0) {
291 AliHLTTPCTransform::Local2Global(first,slice);
292 }
293 //cout << "first point: " << first[0] << " " << first[1] << " " << first[3] << endl;
a6c02c85 294 track->SetFirstPoint(first[0],first[1],first[2]);
295 Float_t last[3];
296 last[0]=trs->fLastX;last[1]=trs->fLastY;last[2]=trs->fLastZ;
4fdaad1e 297 if (slice>=0 && bTransform!=0) {
298 AliHLTTPCTransform::Local2Global(last,slice);
299 }
300 //cout << "last point: " << last[0] << " " << last[1] << " " << last[3] << endl;
a6c02c85 301 track->SetLastPoint(last[0],last[1],last[2]);
302 track->SetHits( trs->fNPoints, trs->fPointIDs );
4fdaad1e 303
d53596be 304 //if (slice>=0 && bTransform!=0) {
4e57c862 305 // Matthias Feb07: as everything is now in global coordinates, sector should
306 // be set to 0. But as the display does a check on the sector, we have to set
307 // it to the slice no. I suspect, that the transformation is done twice.
308 //track->SetSector(0);
309 track->SetSector(slice);
d53596be 310 //} else {
4fdaad1e 311 // the parameters are in local coordinates, set the sector no
312160d3 312 //#ifndef INCLUDE_TPC_HOUGH
d53596be 313 //if (slice<0) track->SetSector(0);
314 //else track->SetSector(slice);
312160d3 315 //#else
4fdaad1e 316 // Matthias Feb 2007: this is some kind of legacy ...
317 // the INCLUDE_TPC_HOUGH has never been switched on in the new TPCLib
318 // and this line was below in the corresponding block. As the slice
319 // parameter is very useful but not available if the define is off
320 // we distinguish the two cases here. Should be cleaned up.
312160d3 321 // Matthias April 2007: update, try to integrate Cvetans Hough tracker
322 // so we need the support for the AliHLTTPCHoughTrack. I dont have the
323 // full control of this code (should we use slice or trs->fSector?)
324 // But the FillTracks method is never called from the hough code, so we
325 // take 'slice'
326 if (GetTrackType()=='h') {
327 AliErrorClassStream() << "FillTracks was never used with AliHLTTPCHoughTrack:"
328 << " CHECK THIS CODE!!!" << endl;
329 }
330 //track->SetSector(trs->fSector);
331 //#endif // INCLUDE_TPC_HOUGH
d53596be 332 //}
21b6a334 333
334 // this is currently a quick hack for straight lines of the first version
335 // of the CA tracker.
336 // we have to think about a more general way of treating straight and curved
337 // tracks
338 if ( trs->fPt == -9876.0 || trs->fPt == -1.0) {
339 track->SetPhi0(atan2(first[1],first[0]));
340 track->SetKappa(1.0);
341 track->SetRadius(999999.0);
342 } else {
4e57c862 343 // Matthias Feb07: just tried to take this away, but this causes the tracks
344 // in the display not to be drawn. But we still have to tink about this.
345 track->CalculateHelix();
21b6a334 346 }
347
a6c02c85 348#ifdef INCLUDE_TPC_HOUGH
349#ifdef ROWHOUGHPARAMS
350 if(GetTrackType()=='h') {
351 ((AliHLTTPCHoughTrack *)track)->SetWeight(trs->fWeight);
352 ((AliHLTTPCHoughTrack *)track)->SetBinXY(trs->fBinX,trs->fBinY,trs->fBinXSize,trs->fBinYSize);
353 }
354 track->SetMCid(trs->fTrackID);
355 track->SetRowRange(trs->fRowRange1,trs->fRowRange2);
a6c02c85 356 track->SetPID(trs->fPID);
357#endif
358#endif // INCLUDE_TPC_HOUGH
359 UChar_t *tmpP = (UChar_t*)trs;
360 tmpP += sizeof(AliHLTTPCTrackSegmentData)+trs->fNPoints*sizeof(UInt_t);
361 trs = (AliHLTTPCTrackSegmentData*)tmpP;
362 }
363}
364
365UInt_t AliHLTTPCTrackArray::GetOutSize()
366{
367 //get size for IO
368 UInt_t count = GetOutCount(); //use only present tracks
369 UInt_t tHits = 0;
370 for(Int_t i=0;i<fNTracks;i++){ //loop over all tracks
371 AliHLTTPCTrack *track = GetCheckedTrack(i); //use only present tracks
372 if(track) //use only present tracks
373 tHits += track->GetNHits();
374 }
375
376 //calculate size of track
377 return count*sizeof(AliHLTTPCTrackSegmentData)+sizeof(UInt_t)*tHits;
378}
379
380UInt_t AliHLTTPCTrackArray::WriteTracks(UInt_t & ntracks,AliHLTTPCTrackSegmentData* tr)
381{
382 //write tracks
383 ntracks = GetOutCount();
384 return WriteTracks(tr);
385}
386
387UInt_t AliHLTTPCTrackArray::WriteTracks(AliHLTTPCTrackSegmentData* tr)
388{
389 //if(GetTrackType()=='c') return WriteConfMapTracks(tr);
390 AliHLTTPCTrackSegmentData *tP = tr;
391 UInt_t *pP;
392 UInt_t size = 0;
393 for(Int_t i=0; i<fNTracks; i++){ //loop over all tracks
394 AliHLTTPCTrack *track = GetCheckedTrack(i); //use only present tracks
395 if(!track) continue; //use only present tracks
396 tP->fX = track->GetFirstPointX();
397 tP->fY = track->GetFirstPointY();
398 tP->fZ = track->GetFirstPointZ();
399 tP->fPt = track->GetPt();
400 tP->fPterr = track->GetPterr();
401 tP->fLastX = track->GetLastPointX();
402 tP->fLastY = track->GetLastPointY();
403 tP->fLastZ = track->GetLastPointZ();
404 tP->fPsi = track->GetPsi();
405 tP->fTgl = track->GetTgl();
406 tP->fPsierr = track->GetPsierr();
407 tP->fTglerr = track->GetTglerr();
408 tP->fCharge = track->GetCharge();
409 tP->fNPoints = track->GetNHits();
410#ifdef INCLUDE_TPC_HOUGH
411#ifdef ROWHOUGHPARAMS
412 if(GetTrackType()=='h') {
413 tP->fWeight = ((AliHLTTPCHoughTrack *)track)->GetWeight();
414 tP->fBinX = ((AliHLTTPCHoughTrack *)track)->GetBinX();
415 tP->fBinY = ((AliHLTTPCHoughTrack *)track)->GetBinY();
416 tP->fBinXSize = ((AliHLTTPCHoughTrack *)track)->GetSizeX();
417 tP->fBinYSize = ((AliHLTTPCHoughTrack *)track)->GetSizeY();
418 }
419 tP->fTrackID = track->GetMCid();
420 tP->fRowRange1 = track->GetFirstRow();
421 tP->fRowRange2 = track->GetLastRow();
422 tP->fSector = track->GetSector();
423 tP->fPID = track->GetPID();
424#endif
425#endif // INCLUDE_TPC_HOUGH
426 pP = (UInt_t*)track->GetHitNumbers();
427 for (UInt_t j=0;j<tP->fNPoints;j++){
428 tP->fPointIDs[j] = pP[j];
429 }
430 Byte_t *tmpP = (Byte_t *)tP;
431 tmpP += sizeof(AliHLTTPCTrackSegmentData)+tP->fNPoints*sizeof(UInt_t);
432 size += sizeof(AliHLTTPCTrackSegmentData)+tP->fNPoints*sizeof(UInt_t);
433 tP = (AliHLTTPCTrackSegmentData*)tmpP;
738c049f 434
db16520a 435// LOG(AliHLTTPCLog::kError,"AliHLTTPCTrackArray::WriteTracks","TRACKPARAMETER") <<ENDLOG;
436// track->Rotate(0,kFALSE);
437// track->Print();
738c049f 438
a6c02c85 439 }
440 return size;
441}
442
443UInt_t AliHLTTPCTrackArray::WriteConfMapTracks(AliHLTTPCTrackSegmentData* tr)
444{
445 // use first and last point objects
446 AliHLTTPCTrackSegmentData *tP = tr;
447 UInt_t *pP;
448 UInt_t size = 0;
449 for(Int_t i=0; i<fNTracks; i++){ //loop over all tracks
450 AliHLTTPCConfMapTrack *track =(AliHLTTPCConfMapTrack *) GetCheckedTrack(i); //use only present tracks
451 if(!track) continue; //use only present tracks
452 AliHLTTPCConfMapPoint *hit = (AliHLTTPCConfMapPoint*)track->GetLastHit();
453 AliHLTTPCConfMapPoint *lastHit = (AliHLTTPCConfMapPoint*)track->GetFirstHit();
454 tP->fX = hit->GetX();
455 tP->fY = hit->GetY();
456 tP->fZ = hit->GetZ();
457 tP->fLastX = lastHit->GetX();
458 tP->fLastY = lastHit->GetY();
459 tP->fLastZ = lastHit->GetZ();
460
461// tP->fX = track->GetFirstPointX();
462// tP->fY = track->GetFirstPointY();
463// tP->fZ = track->GetFirstPointZ();
464 tP->fPt = track->GetPt();
465 tP->fPterr = track->GetPterr();
466// tP->fLastX = track->GetLastPointX();
467// tP->fLastY = track->GetLastPointY();
468// tP->fLastZ = track->GetLastPointZ();
469 tP->fPsi = track->GetPsi();
470 tP->fTgl = track->GetTgl();
471 tP->fPsierr = track->GetPsierr();
472 tP->fTglerr = track->GetTglerr();
473 tP->fCharge = track->GetCharge();
474#ifdef INCLUDE_TPC_HOUGH
475#ifdef ROWHOUGHPARAMS
476 tP->fTrackID = track->GetMCid();
477 tP->fRowRange1 = track->GetFirstRow();
478 tP->fRowRange2 = track->GetLastRow();
479 tP->fSector = track->GetSector();
480 tP->fPID = track->GetPID();
481#endif
482#endif // INCLUDE_TPC_HOUGH
483 tP->fNPoints = track->GetNHits();
484 pP = (UInt_t*)track->GetHitNumbers();
485 for (UInt_t j=0;j<tP->fNPoints;j++){
486 tP->fPointIDs[j] = pP[j];
487 }
488 Byte_t *tmpP = (Byte_t *)tP;
489 tmpP += sizeof(AliHLTTPCTrackSegmentData)+tP->fNPoints*sizeof(UInt_t);
490 size +=sizeof(AliHLTTPCTrackSegmentData)+tP->fNPoints*sizeof(UInt_t);
491 tP = (AliHLTTPCTrackSegmentData*)tmpP;
492 }
493 return size;
494}
495
496void AliHLTTPCTrackArray::AddLast(AliHLTTPCTrack *track)
497{
498 //add track to last position
499 AliHLTTPCTrack *tpt = NextTrack();
3cde846d 500 tpt->Copy(track);
a6c02c85 501
502}
503
504void AliHLTTPCTrackArray::AddTracks(AliHLTTPCTrackArray *newtrack,Bool_t remove_old,Int_t slice)
505{
506 //add tracks
507 if(GetTrackType() != newtrack->GetTrackType() && GetTrackType()!='t')
508 {
509 LOG(AliHLTTPCLog::kError,"AliHLTTPCTrackArray::AddTracks","Track types")
510 <<"Bad idea to add tracks of different types"<<ENDLOG;
511 return;
512 }
513 if(fSize < fNTracks+newtrack->GetNPresent())
514 SetSize(fSize+newtrack->GetSize());
515 for(Int_t i =0;i<newtrack->GetNTracks();i++){
516 AliHLTTPCTrack *tpt = newtrack->GetCheckedTrack(i);
517 if(!tpt) continue;
518 if(remove_old)
519 newtrack->Remove(i);
520 AliHLTTPCTrack *track = NextTrack();
3cde846d 521 track->Copy(tpt);
a6c02c85 522 if(slice>=0)
523 track->Rotate(slice); //Rotate track to global coordinates
524 /*
525 AliHLTTPCTrack *track;
526#ifdef INCLUDE_TPC_HOUGH
527 if(GetTrackType()=='h')
528 track = (AliHLTTPCHoughTrack*)NextTrack();
529 else
530#endif
531 track = NextTrack();
3cde846d 532 track->Copy(tpt);
a6c02c85 533 */
534 }
535}
536
537void AliHLTTPCTrackArray::Compress()
538{
539 //compress array
540 if(GetNPresent()==GetNTracks()) return;
541 AliHLTTPCTrack **tmp = new AliHLTTPCTrack *[fNTracks];
542 Int_t present=0;
543 Int_t absent=GetNPresent();
544 for(Int_t i=0;i<GetNTracks();i++){
545 if(fIsPresent[i]) tmp[present++] = fTrack[i];
546 else tmp[absent++] = fTrack[i];
547 }
548 for(Int_t i=0;i<GetNTracks();i++)
549 fIsPresent[i]=kTRUE;
550
551 //Copy pointers back
552 for(Int_t i=0; i<GetNTracks();i++){
553 fTrack[i]=tmp[i];
554 }
555
556 delete[] tmp;
557
558 fNTracks = GetNPresent();
559 fNAbsent = 0;
560}
561
562void AliHLTTPCTrackArray::QSort()
563{
564 // compress and sort
565 Compress();
566 QSort(fTrack,0,fNTracks);
567}
568
569void AliHLTTPCTrackArray::QSort( AliHLTTPCTrack **a, Int_t first, Int_t last)
570{
571 // Sort array of AliHLTTPCTrack pointers using a quicksort algorithm.
572 // Uses TrackCompare() to compare objects.
573 // Thanks to Root!
574
575 static AliHLTTPCTrack *tmp;
576 static int i; // "static" to save stack space
577 int j;
578
579 while (last - first > 1) {
580 i = first;
581 j = last;
582 for (;;) {
583 while (++i < last && TrackCompare(a[i], a[first]) < 0)
584 ;
585 while (--j > first && TrackCompare(a[j], a[first]) > 0)
586 ;
587 if (i >= j)
588 break;
589
590 tmp = a[i];
591 a[i] = a[j];
592 a[j] = tmp;
593 }
594 if (j == first) {
595 ++first;
596 continue;
597 }
598 tmp = a[first];
599 a[first] = a[j];
600 a[j] = tmp;
601 if (j - first < last - (j + 1)) {
602 QSort(a, first, j);
603 first = j + 1; // QSort(j + 1, last);
604 } else {
605 QSort(a, j + 1, last);
606 last = j; // QSort(first, j);
607 }
608 }
609}
610
611Int_t AliHLTTPCTrackArray::TrackCompare(AliHLTTPCTrack *a, AliHLTTPCTrack *b) const
612{
613 // Compare the two tracks.
614
615 return b->Compare(a);
616
617 /*
618#ifdef INCLUDE_TPC_HOUGH
619 if(fTrackType=='h')
620 {
621 AliHLTTPCHoughTrack *tra = (AliHLTTPCHoughTrack*)a;
622 AliHLTTPCHoughTrack *trb = (AliHLTTPCHoughTrack*)b;
623 if(tra->GetWeight() < trb->GetWeight()) return 1;
624 if(tra->GetWeight() > trb->GetWeight()) return -1;
625 }
626 else
627#endif
628 {
629 if(a->GetNHits() < b->GetNHits()) return 1;
630 if(a->GetNHits() > b->GetNHits()) return -1;
631 }
632
633 return 0;
634 */
635}
636
3cde846d 637AliHLTTPCTrack* AliHLTTPCTrackArray::operator[](int index)
638{
4fdaad1e 639 // access operator
3cde846d 640 if (index<fNTracks) return fTrack[index];
641 return NULL;
642}