2 //***************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 // Ivan Kisel <kisel@kip.uni-heidelberg.de> *
8 // for The ALICE HLT Project. *
10 // Permission to use, copy, modify and distribute this software and its *
11 // documentation strictly for non-commercial purposes is hereby granted *
12 // without fee, provided that the above copyright notice appears in all *
13 // copies and that both the copyright notice and this permission notice *
14 // appear in the supporting documentation. The authors make no claims *
15 // about the suitability of this software for any purpose. It is *
16 // provided "as is" without express or implied warranty. *
17 //***************************************************************************
19 #include "AliHLTTPCCAGBTracker.h"
20 #include "AliHLTTPCCAGBHit.h"
21 #include "AliHLTTPCCAOutTrack.h"
22 #include "AliHLTTPCCATracker.h"
23 #include "AliHLTTPCCAGBTrack.h"
24 #include "AliHLTTPCCATrackParam.h"
25 //#include "AliHLTTPCCAEventHeader.h"
27 #include "AliHLTTPCCAMath.h"
28 #include "TStopwatch.h"
33 #include "AliHLTTPCCADisplay.h"
34 #include "TApplication.h"
38 AliHLTTPCCAGBTracker::AliHLTTPCCAGBTracker()
53 for( Int_t i=0; i<20; i++ ) fStatTime[i] = 0;
56 AliHLTTPCCAGBTracker::AliHLTTPCCAGBTracker(const AliHLTTPCCAGBTracker&)
73 AliHLTTPCCAGBTracker &AliHLTTPCCAGBTracker::operator=(const AliHLTTPCCAGBTracker&)
79 AliHLTTPCCAGBTracker::~AliHLTTPCCAGBTracker()
83 if( fSliceTrackInfos ) delete[] fSliceTrackInfos;
85 if( fSlices ) delete[] fSlices;
89 void AliHLTTPCCAGBTracker::SetNSlices( Int_t N )
94 if( fSliceTrackInfos ) delete[] fSliceTrackInfos;
96 if( fSlices ) delete[] fSlices;
98 fSlices = new AliHLTTPCCATracker[N];
99 fSliceTrackInfos = new AliHLTTPCCAGBSliceTrackInfo *[N];
100 for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
101 fSliceTrackInfos[iSlice] = 0;
105 void AliHLTTPCCAGBTracker::StartEvent()
107 //* clean up track and hit arrays
109 if( fSliceTrackInfos ){
110 for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
111 if( fSliceTrackInfos[iSlice] ) delete[] fSliceTrackInfos[iSlice];
112 fSliceTrackInfos[iSlice] = 0;
115 if( fTrackHits ) delete[] fTrackHits;
117 if( fTracks ) delete[] fTracks;
119 if( fHits ) delete[] fHits;
123 for( Int_t i=0; i<fNSlices; i++) fSlices[i].StartEvent();
127 void AliHLTTPCCAGBTracker::SetNHits( Int_t nHits )
129 //* set the number of hits
130 if( fHits ) delete[] fHits;
132 fHits = new AliHLTTPCCAGBHit[ nHits ];
136 void AliHLTTPCCAGBTracker::ReadHit( Float_t x, Float_t y, Float_t z,
137 Float_t errY, Float_t errZ, Float_t amp,
138 Int_t ID, Int_t iSlice, Int_t iRow )
140 //* read the hit to local array
141 AliHLTTPCCAGBHit &hit = fHits[fNHits];
145 hit.ErrX() = 1.e-4;//fSlices[iSlice].Param().ErrX();
156 void AliHLTTPCCAGBTracker::FindTracks()
158 //* main tracking routine
162 if( fStatNEvents<=1 ){
164 TApplication *myapp = new TApplication("myapp",0,0);
166 AliHLTTPCCADisplay::Instance().Init();
168 AliHLTTPCCADisplay::Instance().SetTPCView();
169 AliHLTTPCCADisplay::Instance().DrawTPC();
172 if( fNHits<=0 ) return;
174 std::sort(fHits,fHits+fNHits, AliHLTTPCCAGBHit::Compare );
176 // Read hits, row by row
178 Int_t nHitsTotal = fNHits;
179 Float_t *hitY = new Float_t [nHitsTotal];
180 Float_t *hitZ = new Float_t [nHitsTotal];
182 Int_t sliceNHits[fNSlices];
183 Int_t rowNHits[fNSlices][200];
185 for( Int_t is=0; is<fNSlices; is++ ){
187 for( Int_t ir=0; ir<200; ir++ ) rowNHits[is][ir] = 0;
190 for( Int_t ih=0; ih<nHitsTotal; ih++){
191 AliHLTTPCCAGBHit &h = fHits[ih];
192 sliceNHits[h.ISlice()]++;
193 rowNHits[h.ISlice()][h.IRow()]++;
196 Int_t firstSliceHit = 0;
197 for( Int_t is=0; is<fNSlices; is++ ){
198 fFirstSliceHit[is] = firstSliceHit;
199 Int_t rowFirstHits[200];
200 Int_t firstRowHit = 0;
201 for( Int_t ir=0; ir<200; ir++ ){
202 rowFirstHits[ir] = firstRowHit;
203 for( Int_t ih=0; ih<rowNHits[is][ir]; ih++){
204 AliHLTTPCCAGBHit &h = fHits[firstSliceHit + firstRowHit + ih];
205 hitY[firstRowHit + ih] = h.Y();
206 hitZ[firstRowHit + ih] = h.Z();
208 firstRowHit+=rowNHits[is][ir];
210 fSlices[is].ReadEvent( rowFirstHits, rowNHits[is], hitY, hitZ, sliceNHits[is] );
212 //Int_t data[ rowNHits[is]]
213 //AliHLTTPCCAEventHeader event;
215 firstSliceHit+=sliceNHits[is];
224 //std::cout<<"Start CA reconstruction"<<std::endl;
225 for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
227 AliHLTTPCCATracker &slice = fSlices[iSlice];
230 //fTime+= timer.CpuTime();
231 //blaTime+= timer.CpuTime();
232 fStatTime[0] += timer.CpuTime();
233 fStatTime[1]+=slice.Timers()[0];
234 fStatTime[2]+=slice.Timers()[1];
235 fStatTime[3]+=slice.Timers()[2];
236 fStatTime[4]+=slice.Timers()[3];
237 fStatTime[5]+=slice.Timers()[4];
238 fStatTime[6]+=slice.Timers()[5];
239 fStatTime[7]+=slice.Timers()[6];
240 fStatTime[8]+=slice.Timers()[7];
244 //std::cout<<"blaTime = "<<timer2.CpuTime()*1.e3<<std::endl;
245 fSliceTrackerTime = timer2.CpuTime();
247 for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
248 AliHLTTPCCATracker &iS = fSlices[iSlice];
249 if( fSliceTrackInfos[iSlice] ) delete[] fSliceTrackInfos[iSlice];
250 fSliceTrackInfos[iSlice]=0;
251 Int_t iNTracks = *iS.NOutTracks();
252 fSliceTrackInfos[iSlice] = new AliHLTTPCCAGBSliceTrackInfo[iNTracks];
253 for( Int_t itr=0; itr<iNTracks; itr++ ){
254 fSliceTrackInfos[iSlice][itr].fPrevNeighbour = -1;
255 fSliceTrackInfos[iSlice][itr].fNextNeighbour = -1;
256 fSliceTrackInfos[iSlice][itr].fUsed = 0;
260 //std::cout<<"Start CA merging"<<std::endl;
261 TStopwatch timerMerge;
264 fStatTime[9]+=timerMerge.CpuTime();
265 //fTime+=timerMerge.CpuTime();
266 //std::cout<<"End CA merging"<<std::endl;
268 fTime+= timer1.CpuTime();
271 AliHLTTPCCADisplay::Instance().Ask();
276 void AliHLTTPCCAGBTracker::FindTracks0()
278 //* main tracking routine
282 if( fStatNEvents<=1 ){
284 TApplication *myapp = new TApplication("myapp",0,0);
286 AliHLTTPCCADisplay::Instance().Init();
288 AliHLTTPCCADisplay::Instance().SetTPCView();
289 AliHLTTPCCADisplay::Instance().DrawTPC();
292 if( fNHits<=0 ) return;
294 std::sort(fHits,fHits+fNHits, AliHLTTPCCAGBHit::Compare );
296 // Read hits, row by row
298 Int_t nHitsTotal = fNHits;
299 Float_t *hitY = new Float_t [nHitsTotal];
300 Float_t *hitZ = new Float_t [nHitsTotal];
302 Int_t sliceNHits[fNSlices];
303 Int_t rowNHits[fNSlices][200];
305 for( Int_t is=0; is<fNSlices; is++ ){
307 for( Int_t ir=0; ir<200; ir++ ) rowNHits[is][ir] = 0;
310 for( Int_t ih=0; ih<nHitsTotal; ih++){
311 AliHLTTPCCAGBHit &h = fHits[ih];
312 sliceNHits[h.ISlice()]++;
313 rowNHits[h.ISlice()][h.IRow()]++;
316 Int_t firstSliceHit = 0;
317 for( Int_t is=0; is<fNSlices; is++ ){
318 fFirstSliceHit[is] = firstSliceHit;
319 Int_t rowFirstHits[200];
320 Int_t firstRowHit = 0;
321 for( Int_t ir=0; ir<200; ir++ ){
322 rowFirstHits[ir] = firstRowHit;
323 for( Int_t ih=0; ih<rowNHits[is][ir]; ih++){
324 AliHLTTPCCAGBHit &h = fHits[firstSliceHit + firstRowHit + ih];
325 hitY[firstRowHit + ih] = h.Y();
326 hitZ[firstRowHit + ih] = h.Z();
328 firstRowHit+=rowNHits[is][ir];
330 //if( is==24 ){//SG!!!
331 fSlices[is].ReadEvent( rowFirstHits, rowNHits[is], hitY, hitZ, sliceNHits[is] );
334 //Int_t data[ rowNHits[is]]
335 //AliHLTTPCCAEventHeader event;
337 firstSliceHit+=sliceNHits[is];
345 void AliHLTTPCCAGBTracker::FindTracks1()
347 //* main tracking routine
350 //std::cout<<"Start CA reconstruction"<<std::endl;
351 for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
353 AliHLTTPCCATracker &slice = fSlices[iSlice];
356 //fTime+= timer.CpuTime();
357 //blaTime+= timer.CpuTime();
358 fStatTime[0] += timer.CpuTime();
359 fStatTime[1]+=slice.Timers()[0];
360 fStatTime[2]+=slice.Timers()[1];
361 fStatTime[3]+=slice.Timers()[2];
362 fStatTime[4]+=slice.Timers()[3];
363 fStatTime[5]+=slice.Timers()[4];
364 fStatTime[6]+=slice.Timers()[5];
365 fStatTime[7]+=slice.Timers()[6];
366 fStatTime[8]+=slice.Timers()[7];
370 //std::cout<<"blaTime = "<<timer2.CpuTime()*1.e3<<std::endl;
371 fSliceTrackerTime = timer2.CpuTime();
375 void AliHLTTPCCAGBTracker::FindTracks2()
377 //* main tracking routine
381 for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
382 AliHLTTPCCATracker &iS = fSlices[iSlice];
383 if( fSliceTrackInfos[iSlice] ) delete[] fSliceTrackInfos[iSlice];
384 fSliceTrackInfos[iSlice]=0;
385 Int_t iNTracks = *iS.NOutTracks();
386 fSliceTrackInfos[iSlice] = new AliHLTTPCCAGBSliceTrackInfo[iNTracks];
387 for( Int_t itr=0; itr<iNTracks; itr++ ){
388 fSliceTrackInfos[iSlice][itr].fPrevNeighbour = -1;
389 fSliceTrackInfos[iSlice][itr].fNextNeighbour = -1;
390 fSliceTrackInfos[iSlice][itr].fUsed = 0;
394 //std::cout<<"Start CA merging"<<std::endl;
395 TStopwatch timerMerge;
398 fStatTime[9]+=timerMerge.CpuTime();
399 //fTime+=timerMerge.CpuTime();
400 //std::cout<<"End CA merging"<<std::endl;
402 fTime+= fSliceTrackerTime + timer1.CpuTime();
405 AliHLTTPCCADisplay::Instance().Ask();
409 void AliHLTTPCCAGBTracker::Merging()
411 //* track merging between slices
413 Float_t dalpha = fSlices[1].Param().Alpha() - fSlices[0].Param().Alpha();
414 Int_t nextSlice[100], prevSlice[100];
415 for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
416 nextSlice[iSlice] = iSlice + 1;
417 prevSlice[iSlice] = iSlice - 1;
419 nextSlice[ fNSlices/2 - 1 ] = 0;
420 prevSlice[ 0 ] = fNSlices/2 - 1;
421 nextSlice[ fNSlices - 1 ] = fNSlices/2;
422 prevSlice[ fNSlices/2 ] = fNSlices - 1;
424 TStopwatch timerMerge1;
426 Int_t maxNSliceTracks = 0;
427 for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
428 AliHLTTPCCATracker &iS = fSlices[iSlice];
429 if( maxNSliceTracks < *iS.NOutTracks() ) maxNSliceTracks = *iS.NOutTracks();
432 //* arrays for rotated track parameters
434 AliHLTTPCCATrackParam *iTrParams[2], *jTrParams[2];
435 Bool_t *iOK[2], *jOK[2];
436 for( Int_t i=0; i<2; i++ ){
437 iTrParams[i] = new AliHLTTPCCATrackParam[maxNSliceTracks];
438 jTrParams[i] = new AliHLTTPCCATrackParam[maxNSliceTracks];
439 iOK[i] = new Bool_t [maxNSliceTracks];
440 jOK[i] = new Bool_t [maxNSliceTracks];
443 for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
444 //std::cout<<"\nMerge slice "<<iSlice<<std::endl<<std::endl;
445 AliHLTTPCCATracker &iS = fSlices[iSlice];
446 Int_t jSlice = nextSlice[iSlice];
447 AliHLTTPCCATracker &jS = fSlices[jSlice];
448 Int_t iNTracks = *iS.NOutTracks();
449 Int_t jNTracks = *jS.NOutTracks();
450 if( iNTracks<=0 || jNTracks<=0 ) continue;
452 //* prepare slice tracks for merging
454 for (Int_t itr=0; itr<iNTracks; itr++) {
457 if( iS.OutTracks()[itr].NHits()<10 ) continue;
458 AliHLTTPCCATrackParam &iT1 = iTrParams[0][itr];
459 AliHLTTPCCATrackParam &iT2 = iTrParams[1][itr];
460 iT1 = iS.OutTracks()[itr].StartPoint();
461 iT2 = iS.OutTracks()[itr].EndPoint();
462 iOK[0][itr] = iT1.Rotate( dalpha/2 - CAMath::Pi()/2 );
463 iOK[1][itr] = iT2.Rotate( dalpha/2 - CAMath::Pi()/2 );
466 iOK[0][itr] = iT1.TransportToX( 0, .99 );
467 if( iS.Param().RMin() > iT1.Y() || iS.Param().RMax() < iT1.Y() ) iOK[0][itr]=0;
470 iOK[1][itr] = iT2.TransportToX( 0, .99 );
471 if( iS.Param().RMin() > iT2.Y() || iS.Param().RMax() < iT2.Y() ) iOK[1][itr]=0;
475 for (Int_t jtr=0; jtr<jNTracks; jtr++) {
478 if( jS.OutTracks()[jtr].NHits()<10 ) continue;
479 AliHLTTPCCATrackParam &jT1 = jTrParams[0][jtr];
480 AliHLTTPCCATrackParam &jT2 = jTrParams[1][jtr];
481 jT1 = jS.OutTracks()[jtr].StartPoint();
482 jT2 = jS.OutTracks()[jtr].EndPoint();
483 jOK[0][jtr] = jT1.Rotate( -dalpha/2 - CAMath::Pi()/2 );
484 jOK[1][jtr] = jT2.Rotate( -dalpha/2 - CAMath::Pi()/2 );
486 jOK[0][jtr] = jT1.TransportToX( 0, .99 );
487 if( jS.Param().RMin() > jT1.Y() || jS.Param().RMax() < jT1.Y() ) jOK[0][jtr]=0;
490 jOK[1][jtr] = jT2.TransportToX( 0, .99 );
491 if( jS.Param().RMin() > jT2.Y() || jS.Param().RMax() < jT2.Y() ) jOK[1][jtr]=0;
496 //std::cout<<"Start slice merging.."<<std::endl;
497 for (Int_t itr=0; itr<iNTracks; itr++) {
498 if( !iOK[0][itr] && !iOK[1][itr] ) continue;
501 for (Int_t jtr=0; jtr<jNTracks; jtr++) {
502 if( jS.OutTracks()[jtr].NHits() < lBest ) continue;
503 if( !jOK[0][jtr] && !jOK[1][jtr] ) continue;
504 for( Int_t ip=0; ip<2 && (jBest!=jtr) ; ip++ ){
505 if( !iOK[ip][itr] ) continue;
506 for( Int_t jp=0; jp<2 && (jBest!=jtr) ; jp++ ){
507 if( !jOK[jp][jtr] ) continue;
508 AliHLTTPCCATrackParam &iT = iTrParams[ip][itr];
509 AliHLTTPCCATrackParam &jT = jTrParams[jp][jtr];
510 // check for neighbouring
512 Float_t factor2 = 3.5*3.5;
513 Float_t d = jT.GetY() - iT.GetY();
514 Float_t s2 = jT.GetErr2Y() + iT.GetErr2Y();
515 if( d*d>factor2*s2 ){
518 d = jT.GetZ() - iT.GetZ();
519 s2 = jT.GetErr2Z() + iT.GetErr2Z();
520 if( d*d>factor2*s2 ){
524 { // phi, kappa, DsDz signs are the same
525 d = jT.GetSinPhi() - iT.GetSinPhi();
526 s2 = jT.GetErr2SinPhi() + iT.GetErr2SinPhi();
527 if( d*d>factor2*s2 ) ok = 0;
528 d = jT.GetKappa() - iT.GetKappa();
529 s2 = jT.GetErr2Kappa() + iT.GetErr2Kappa();
530 if( d*d>factor2*s2 ) ok = 0;
531 d = jT.GetDzDs() - iT.GetDzDs();
532 s2 = jT.GetErr2DzDs() + iT.GetErr2DzDs();
533 if( d*d>factor2*s2 ) ok = 0;
535 if( !ok ){ // phi, kappa, DsDz signs are the different
536 d = jT.GetSinPhi() + iT.GetSinPhi();
537 s2 = jT.GetErr2SinPhi() + iT.GetErr2SinPhi();
538 if( d*d>factor2*s2 ) continue;
539 d = jT.GetKappa() + iT.GetKappa();
540 s2 = jT.GetErr2Kappa() + iT.GetErr2Kappa();
541 if( d*d>factor2*s2 ) continue;
542 d = jT.GetDzDs() + iT.GetDzDs();
543 s2 = jT.GetErr2DzDs() + iT.GetErr2DzDs();
544 if( d*d>factor2*s2 ) continue;
546 // tracks can be matched
548 lBest = jS.OutTracks()[jtr].NHits();
555 Int_t oldi = fSliceTrackInfos[jSlice][jBest].fPrevNeighbour;
557 if( iS.OutTracks()[ oldi ].NHits() < iS.OutTracks()[ itr ].NHits() ){
558 fSliceTrackInfos[jSlice][jBest].fPrevNeighbour = -1;
559 fSliceTrackInfos[iSlice][oldi].fNextNeighbour = -1;
563 fSliceTrackInfos[iSlice][itr].fNextNeighbour = jBest;
564 fSliceTrackInfos[jSlice][jBest].fPrevNeighbour = itr;
569 for( Int_t i=0; i<2; i++){
570 if( iTrParams[i] ) delete[] iTrParams[i];
571 if( jTrParams[i] ) delete[] jTrParams[i];
572 if( iOK[i] ) delete[] iOK[i];
573 if( jOK[i] ) delete[] jOK[i];
577 fStatTime[10]+=timerMerge1.CpuTime();
579 TStopwatch timerMerge2;
581 Int_t nTracksTot = 0;
582 for( Int_t iSlice = 0; iSlice<fNSlices; iSlice++ ){
583 AliHLTTPCCATracker &slice = fSlices[iSlice];
584 nTracksTot+= *slice.NOutTracks();
587 if( fTrackHits ) delete[] fTrackHits;
589 if(fTracks ) delete[] fTracks;
591 fTrackHits = new Int_t [fNHits*10];
592 fTracks = new AliHLTTPCCAGBTrack[nTracksTot];
595 Int_t nTrackHits = 0;
597 //std::cout<<"\nStart global track creation...\n"<<std::endl;
599 static Int_t nRejected = 0;
601 Int_t maxNRows = fSlices[0].Param().NRows();
603 for( Int_t iSlice = 0; iSlice<fNSlices; iSlice++ ){
605 AliHLTTPCCATracker &slice = fSlices[iSlice];
606 for( Int_t itr=0; itr<*slice.NOutTracks(); itr++ ){
607 if( fSliceTrackInfos[iSlice][itr].fUsed ) continue;
608 //std::cout<<"\n slice "<<iSlice<<", track "<<itr<<"\n"<<std::endl;
609 //AliHLTTPCCAOutTrack &tCA = slice.OutTracks()[itr];
610 AliHLTTPCCAGBTrack &t = fTracks[fNTracks];
611 //t.Param() = tCA.StartPoint();
612 //t.Alpha() = slice.Param().Alpha();
614 t.FirstHitRef() = nTrackHits;
619 Float_t fX, fY, fZ, fErr2Y, fErr2Z, fAmp;
621 for( Int_t i=0; i<maxNRows; i++ ) fitPoints[i].fISlice = -1;
624 Int_t jSlice = iSlice;
627 if( fSliceTrackInfos[jSlice][jtr].fUsed ) break;
628 fSliceTrackInfos[jSlice][jtr].fUsed = 1;
629 AliHLTTPCCATracker &jslice = fSlices[jSlice];
630 AliHLTTPCCAOutTrack &jTr = jslice.OutTracks()[jtr];
631 for( Int_t jhit=0; jhit<jTr.NHits(); jhit++){
632 Int_t id = fFirstSliceHit[jSlice] + jslice.OutTrackHits()[jTr.FirstHitRef()+jhit];
633 AliHLTTPCCAGBHit &h = fHits[id];
634 FitPoint &p = fitPoints[h.IRow()];
635 if( p.fISlice >=0 ) continue;
636 p.fISlice = h.ISlice();
638 p.fX = jslice.Rows()[h.IRow()].X();
641 //p.fErr2Y = h.ErrY()*h.ErrY();
642 //p.fErr2Z = h.ErrZ()*h.ErrZ();
646 jtr = fSliceTrackInfos[jSlice][jtr].fNextNeighbour;
647 jSlice = nextSlice[jSlice];
650 if( nHits < 10 ) continue; //SG!!!
652 Int_t firstRow = 0, lastRow = maxNRows-1;
653 for( firstRow=0; firstRow<maxNRows; firstRow++ ){
654 if( fitPoints[firstRow].fISlice>=0 ) break;
656 for( lastRow=maxNRows-1; lastRow>=0; lastRow-- ){
657 if( fitPoints[lastRow].fISlice>=0 ) break;
659 Int_t mmidRow = (firstRow + lastRow )/2;
660 Int_t midRow = firstRow;
661 for( Int_t i=firstRow+1; i<=lastRow; i++ ){
662 if( fitPoints[i].fISlice<0 ) continue;
663 if( CAMath::Abs(i-mmidRow)>=CAMath::Abs(midRow-mmidRow) ) continue;
666 if( midRow==firstRow || midRow==lastRow ) continue;
668 Int_t searchRows[300];
669 Int_t nSearchRows = 0;
671 for( Int_t i=firstRow; i<=lastRow; i++ ) searchRows[nSearchRows++] = i;
672 for( Int_t i=lastRow+1; i<maxNRows; i++ ) searchRows[nSearchRows++] = i;
673 for( Int_t i=firstRow-1; i>=0; i-- ) searchRows[nSearchRows++] = i;
677 AliHLTTPCCATrackParam t0;
682 FitPoint &p0 = fitPoints[firstRow];
683 FitPoint &p1 = fitPoints[midRow];
684 FitPoint &p2 = fitPoints[lastRow];
685 Float_t x0=p0.fX, y0=p0.fY, z0=p0.fZ;
686 Float_t x1=p1.fX, y1=p1.fY, z1=p1.fZ;
687 Float_t x2=p2.fX, y2=p2.fY, z2=p2.fZ;
688 if( p1.fISlice!=p0.fISlice ){
689 Float_t dAlpha = fSlices[p0.fISlice].Param().Alpha() - fSlices[p1.fISlice].Param().Alpha();
690 Float_t c = CAMath::Cos(dAlpha);
691 Float_t s = CAMath::Sin(dAlpha);
692 x1 = p1.fX*c + p1.fY*s;
693 y1 = p1.fY*c - p1.fX*s;
695 if( p2.fISlice!=p0.fISlice ){
696 Float_t dAlpha = fSlices[p0.fISlice].Param().Alpha() - fSlices[p2.fISlice].Param().Alpha();
697 Float_t c = CAMath::Cos(dAlpha);
698 Float_t s = CAMath::Sin(dAlpha);
699 x2 = p2.fX*c + p2.fY*s;
700 y2 = p2.fY*c - p2.fX*s;
703 Float_t sp0[5] = {x0, y0, z0, .5, .5 };
704 Float_t sp1[5] = {x1, y1, z1, .5, .5 };
705 Float_t sp2[5] = {x2, y2, z2, .5, .5 };
706 t0.ConstructXYZ3(sp0,sp1,sp2,1., 0);
709 Int_t currslice = fitPoints[firstRow].fISlice;
711 for( Int_t rowID=0; rowID<nSearchRows; rowID++ ){
712 Int_t iRow = searchRows[rowID];
713 FitPoint &p = fitPoints[iRow];
719 //* Rotate to the new slice
721 if( p.fISlice!=currslice ){
722 if( !t0.Rotate( fSlices[p.fISlice].Param().Alpha() - fSlices[currslice].Param().Alpha() ) ) continue;
723 currslice = p.fISlice;
725 //* Transport to the new row
727 if( !t0.TransportToX( p.fX, .99 ) ) continue;
729 //* Calculate hit errors
731 GetErrors2( p.fISlice, iRow, t0, p.fErr2Y, p.fErr2Z );
735 //* Search for the missed hit
737 Float_t factor2 = 3.5*3.5;
739 AliHLTTPCCATracker *cslice = &(fSlices[currslice]);
740 AliHLTTPCCARow *row = &(cslice->Rows()[iRow]);
741 if( !t0.TransportToX( row->X(), .99 ) ) continue;
743 if( t0.GetY() > row->MaxY() ){ //next slice
745 Int_t j = nextSlice[currslice];
747 //* Rotate to the new slice
749 if( !t0.Rotate( -fSlices[currslice].Param().Alpha() +fSlices[j].Param().Alpha() ) ) continue;
751 cslice = &(fSlices[currslice]);
752 row = &(cslice->Rows()[iRow]);
753 if( !t0.TransportToX( row->X(), .99 ) ) continue;
754 if( CAMath::Abs(t0.GetY()) > row->MaxY() ) continue;
756 }else if( t0.GetY() < -row->MaxY() ){ //prev slice
757 Int_t j = prevSlice[currslice];
758 //* Rotate to the new slice
759 if( !t0.Rotate( -fSlices[currslice].Param().Alpha() +fSlices[j].Param().Alpha() ) ) break;
761 cslice = &(fSlices[currslice]);
762 row = &(cslice->Rows()[iRow]);
763 if( !t0.TransportToX( row->X(), .99 ) ) continue;
764 if( CAMath::Abs(t0.GetY()) > row->MaxY() ) continue;
769 Float_t y0 = row->Grid().YMin();
770 Float_t z0 = row->Grid().ZMin();
771 Float_t stepY = row->HstepY();
772 Float_t stepZ = row->HstepZ();
773 uint4* tmpint4 = cslice->RowData() + row->FullOffset();
774 ushort2 *hits = reinterpret_cast<ushort2*>(tmpint4);
776 for( Int_t ish=0; ish<row->NHits(); ish++ ){
777 AliHLTTPCCAHit sh;// = cslice->Hits()[row->FirstHit()+ish];
779 ushort2 hh = hits[ish];
780 sh.Y() = y0 + hh.x*stepY;
781 sh.Z() = z0 + hh.y*stepZ;
784 Float_t dy = sh.Y() - t0.GetY();
785 Float_t dz = sh.Z() - t0.GetZ();
786 Float_t dds = dy*dy+dz*dz;
792 if( bestsh<0 ) continue;
794 //* Calculate hit errors
796 GetErrors2( currslice, iRow, t0, p.fErr2Y, p.fErr2Z );
798 AliHLTTPCCAHit sh;// = cslice->Hits()[row->FirstHit()+bestsh];
800 ushort2 hh = hits[bestsh];
801 sh.Y() = y0 + hh.x*stepY;
802 sh.Z() = z0 + hh.y*stepZ;
805 Float_t dy = sh.Y() - t0.GetY();
806 Float_t dz = sh.Z() - t0.GetZ();
807 Float_t s2z = /*t0.GetErr2Z() + */ p.fErr2Z;
808 if( dz*dz>factor2*s2z ) continue;
809 Float_t s2y = /*t0.GetErr2Y() + */ p.fErr2Y;
810 if( dy*dy>factor2*s2y ) continue;
812 p.fISlice = currslice;
813 p.fHitID = fFirstSliceHit[p.fISlice] + cslice->HitInputIDs()[row->FirstHit() + bestsh];
817 p.fAmp = fHits[p.fHitID].Amp();
822 t0.Filter2( p.fY, p.fZ, p.fErr2Y, p.fErr2Z, .99 );
825 //* final refit, dE/dx calculation
826 //std::cout<<"\n\nstart refit..\n"<<std::endl;
828 AliHLTTPCCATrackParam::AliHLTTPCCATrackFitParam fitPar;
830 Double_t sumDeDx = 0;
834 t0.CalculateFitParameters( fitPar, fSlices[0].Param().Bz() );
854 for( Int_t iRow = maxNRows-1; iRow>=0; iRow-- ){
855 FitPoint &p = fitPoints[iRow];
856 if( p.fISlice<0 ) continue;
857 fTrackHits[nTrackHits+t.NHits()] = p.fHitID;
860 //* Rotate to the new slice
862 if( p.fISlice!=currslice ){
863 //std::cout<<"rotate..."<<std::endl;
864 //std::cout<<" before rotation:"<<std::endl;
866 if( !t0.Rotate( fSlices[p.fISlice].Param().Alpha() - fSlices[currslice].Param().Alpha() ) ) continue;
867 //std::cout<<" after rotation:"<<std::endl;
869 currslice = p.fISlice;
871 //* Transport to the new row
873 //std::cout<<" before transport:"<<std::endl;
876 //if( !t0.TransportToX( p.fX, .99 ) ) continue;
877 if( !t0.TransportToXWithMaterial( p.fX, fitPar ) ) continue;
878 //if( !t0.TransportToX( p.fX, .99 ) ) continue;
879 //std::cout<<" after transport:"<<std::endl;
885 t0.Cov()[ 0] = .5*.5;
887 t0.Cov()[ 2] = .5*.5;
890 t0.Cov()[ 5] = .2*.2;
894 t0.Cov()[ 9] = .2*.2;
899 t0.Cov()[14] = .5*.5;
904 //std::cout<<" before filtration:"<<std::endl;
907 if( !t0.Filter2( p.fY, p.fZ, p.fErr2Y, p.fErr2Z, .99 ) ) continue;
908 //std::cout<<" after filtration:"<<std::endl;
912 if( CAMath::Abs( t0.CosPhi() )>1.e-4 ){
913 Float_t dLdX = CAMath::Sqrt(1.+t0.DzDs()*t0.DzDs())/CAMath::Abs(t0.CosPhi());
914 sumDeDx+=p.fAmp/dLdX;
919 if( nDeDx >0 ) t.DeDx() = sumDeDx/nDeDx;
920 if( t0.GetErr2Y()<=0 ){
921 //std::cout<<"nhits = "<<t.NHits()<<", t0.GetErr2Y() = "<<t0.GetErr2Y()<<std::endl;
927 if( t.NHits()<30 ) continue;//SG!!
931 Double_t ddAlpha = 0.00609235;
933 if( t0.TransportToXWithMaterial( xTPC, fitPar ) ){
934 Double_t y=t0.GetY();
935 Double_t ymax=xTPC*CAMath::Tan(dAlpha/2.);
937 if( t0.Rotate( ddAlpha ) ){ dAlpha=ddAlpha; t0.TransportToXWithMaterial( xTPC, fitPar ); }
938 } else if (y <-ymax) {
939 if( t0.Rotate( -ddAlpha ) ){ dAlpha=-ddAlpha; t0.TransportToXWithMaterial( xTPC, fitPar );}
947 Float_t *c = t0.Cov();
948 for( Int_t i=0; i<15; i++ ) ok = ok && finite(c[i]);
949 for( Int_t i=0; i<5; i++ ) ok = ok && finite(t0.Par()[i]);
950 ok = ok && (t0.GetX()>50);
952 if( c[0]<=0 || c[2]<=0 || c[5]<=0 || c[9]<=0 || c[14]<=0 ) ok = 0;
953 //if( c[0]>5. || c[2]>5. || c[5]>2. || c[9]>2 || c[14]>2 ) ok = 0;
956 //std::cout<<"\n\nRejected: "<<nRejected<<"\n"<<std::endl;
961 if( CAMath::Abs(t0.Kappa())<1.e-8 ) t0.Kappa() = 1.e-8;
963 t.Alpha() = fSlices[currslice].Param().Alpha() + dAlpha;
964 nTrackHits+= t.NHits();
969 //std::cout<<"\n\nRejected: "<<nRejected<<"\n"<<std::endl;
971 fStatTime[11]+=timerMerge2.CpuTime();
973 TStopwatch timerMerge3;
976 //std::cout<<"Selection..."<<std::endl;
978 AliHLTTPCCAGBTrack *vtracks = new AliHLTTPCCAGBTrack [fNTracks];
979 Int_t *vhits = new Int_t [fNHits];
980 AliHLTTPCCAGBTrack **vptracks = new AliHLTTPCCAGBTrack* [fNTracks];
982 for( Int_t itr=0; itr<fNTracks; itr++ ){
983 vptracks[itr] = &(fTracks[itr]);
987 std::sort(vptracks, vptracks+fNTracks, AliHLTTPCCAGBTrack::ComparePNClusters );
988 for( Int_t itr=0; itr<fNTracks; itr++ ){
989 AliHLTTPCCAGBTrack &t = *(vptracks[itr]);
990 AliHLTTPCCAGBTrack &to = vtracks[nTracks];
992 to.FirstHitRef() = nHits;
994 for( Int_t ih=0; ih<t.NHits(); ih++ ){
995 Int_t jh = fTrackHits[t.FirstHitRef()+ih];
996 AliHLTTPCCAGBHit &h = fHits[jh];
997 if( h.IsUsed() ) continue;
998 vhits[to.FirstHitRef() + to.NHits()] = jh;
1002 if( to.NHits()<10 ) continue;//SG!!!
1005 //std::cout<<to.Param().GetErr2Y()<<" "<<to.Param().GetErr2Z()<<std::endl;
1008 if( fTrackHits ) delete[] fTrackHits;
1009 if( fTracks ) delete[] fTracks;
1015 fStatTime[12]+=timerMerge3.CpuTime();
1018 void AliHLTTPCCAGBTracker::GetErrors2( Int_t iSlice, Int_t iRow, AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z )
1021 // Use calibrated cluster error from OCDB
1024 Float_t z = CAMath::Abs((250.-0.275)-CAMath::Abs(t.GetZ()));
1025 Int_t type = (iRow<63) ? 0: (iRow>126) ? 1:2;
1026 Float_t cosPhiInv = CAMath::Abs(t.GetCosPhi())>1.e-2 ?1./t.GetCosPhi() :0;
1027 Float_t angleY = t.GetSinPhi()*cosPhiInv ;
1028 Float_t angleZ = t.GetDzDs()*cosPhiInv ;
1030 AliHLTTPCCATracker &slice = fSlices[iSlice];
1032 Err2Y = slice.Param().GetClusterError2(0,type, z,angleY);
1033 Err2Z = slice.Param().GetClusterError2(1,type, z,angleZ);
1037 void AliHLTTPCCAGBTracker::GetErrors2( AliHLTTPCCAGBHit &h, AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z )
1040 // Use calibrated cluster error from OCDB
1043 GetErrors2( h.ISlice(), h.IRow(), t, Err2Y, Err2Z );
1046 void AliHLTTPCCAGBTracker::WriteSettings( std::ostream &out ) const
1048 //* write settings to the file
1049 out<< NSlices()<<std::endl;
1050 for( Int_t iSlice=0; iSlice<NSlices(); iSlice++ ){
1051 fSlices[iSlice].Param().WriteSettings( out );
1055 void AliHLTTPCCAGBTracker::ReadSettings( std::istream &in )
1057 //* Read settings from the file
1060 SetNSlices( nSlices );
1061 for( Int_t iSlice=0; iSlice<NSlices(); iSlice++ ){
1062 AliHLTTPCCAParam param;
1063 param.ReadSettings ( in );
1064 fSlices[iSlice].Initialize( param );
1068 void AliHLTTPCCAGBTracker::WriteEvent( std::ostream &out ) const
1070 // write event to the file
1072 out<<NHits()<<std::endl;
1073 for (Int_t ih=0; ih<NHits(); ih++) {
1074 AliHLTTPCCAGBHit &h = fHits[ih];
1082 out<<h.ISlice()<<" ";
1083 out<<h.IRow()<<std::endl;
1087 void AliHLTTPCCAGBTracker::ReadEvent( std::istream &in )
1089 //* Read event from file
1095 for (Int_t i=0; i<nHits; i++) {
1096 Float_t x, y, z, errY, errZ;
1098 Int_t id, iSlice, iRow;
1099 in>>x>>y>>z>>errY>>errZ>>amp>>id>>iSlice>>iRow;
1100 ReadHit( x, y, z, errY, errZ, amp, id, iSlice, iRow );
1104 void AliHLTTPCCAGBTracker::WriteTracks( std::ostream &out ) const
1106 //* Write tracks to file
1108 out<<fSliceTrackerTime<<std::endl;
1109 Int_t nTrackHits = 0;
1110 for( Int_t itr=0; itr<fNTracks; itr++ ){
1111 nTrackHits+=fTracks[itr].NHits();
1113 out<<nTrackHits<<std::endl;
1114 for( Int_t ih=0; ih<nTrackHits; ih++ ){
1115 out<< fTrackHits[ih]<<" ";
1119 out<<NTracks()<<std::endl;
1120 for( Int_t itr=0; itr<fNTracks; itr++ ){
1121 AliHLTTPCCAGBTrack &t = fTracks[itr];
1122 AliHLTTPCCATrackParam &p = t.Param();
1123 out<< t.NHits()<<" ";
1124 out<< t.FirstHitRef()<<" ";
1125 out<< t.Alpha()<<" ";
1126 out<< t.DeDx()<<std::endl;
1128 out<< p.CosPhi()<<" ";
1129 out<< p.Chi2()<<" ";
1130 out<< p.NDF()<<std::endl;
1131 for( Int_t i=0; i<5; i++ ) out<<p.Par()[i]<<" ";
1133 for( Int_t i=0; i<15; i++ ) out<<p.Cov()[i]<<" ";
1138 void AliHLTTPCCAGBTracker::ReadTracks( std::istream &in )
1140 //* Read tracks from file
1143 fSliceTrackerTime = fTime;
1144 fStatTime[0]+=fTime;
1146 if( fTrackHits ) delete[] fTrackHits;
1148 Int_t nTrackHits = 0;
1150 fTrackHits = new Int_t [nTrackHits];
1151 for( Int_t ih=0; ih<nTrackHits; ih++ ){
1152 in >> TrackHits()[ih];
1154 if( fTracks ) delete[] fTracks;
1157 fTracks = new AliHLTTPCCAGBTrack[fNTracks];
1158 for( Int_t itr=0; itr<NTracks(); itr++ ){
1159 AliHLTTPCCAGBTrack &t = Tracks()[itr];
1160 AliHLTTPCCATrackParam &p = t.Param();
1162 in>> t.FirstHitRef();
1169 for( Int_t i=0; i<5; i++ ) in>>p.Par()[i];
1170 for( Int_t i=0; i<15; i++ ) in>>p.Cov()[i];