]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.cxx
coding violations and compilation warnings fixed (Sergey)
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCATracker.cxx
CommitLineData
326c2d4b 1// @(#) $Id$
2//*************************************************************************
3// This file is property of and copyright by the ALICE HLT Project *
4// ALICE Experiment at CERN, All rights reserved. *
5// *
6// Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
7// Ivan Kisel <kisel@kip.uni-heidelberg.de> *
8// for The ALICE HLT Project. *
9// *
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//*************************************************************************
18
19#include "AliHLTTPCCATracker.h"
20
21#include "AliHLTTPCCAHit.h"
22#include "AliHLTTPCCACell.h"
23#include "AliHLTTPCCAOutTrack.h"
24
25#include "TMath.h"
26//#include "Riostream.h"
27#include <vector>
28#include <algo.h>
dc4788ec 29#include "TStopwatch.h"
326c2d4b 30//#define DRAW
31
32#ifdef DRAW
33#include "AliHLTTPCCADisplay.h"
34#include "TApplication.h"
326c2d4b 35#endif //DRAW
36
dc4788ec 37ClassImp(AliHLTTPCCATracker)
326c2d4b 38
39
40AliHLTTPCCATracker::AliHLTTPCCATracker()
dc4788ec 41 :fParam(),fRows(0),fOutTrackHits(0),fNOutTrackHits(0),fOutTracks(0),fNOutTracks(0),fTrackCells(0),fNHitsTotal(0),fTracks(0),fNTracks(0),fCellHitPointers(0)
326c2d4b 42{
43 // constructor
44 fRows = new AliHLTTPCCARow[fParam.NRows()];
45 Initialize( fParam );
46}
47
48AliHLTTPCCATracker::AliHLTTPCCATracker( const AliHLTTPCCATracker& )
dc4788ec 49 :fParam(),fRows(0),fOutTrackHits(0),fNOutTrackHits(0),fOutTracks(0),fNOutTracks(0),fTrackCells(0),fNHitsTotal(0),fTracks(0),fNTracks(0),fCellHitPointers(0)
326c2d4b 50{
51 // dummy
52}
53
54AliHLTTPCCATracker &AliHLTTPCCATracker::operator=( const AliHLTTPCCATracker& )
55{
56 // dummy
dc4788ec 57 fRows=0;
58 fOutTrackHits=0;
59 fOutTracks=0;
60 fNOutTracks=0;
61 fTrackCells=0;
ce622827 62 return *this;
326c2d4b 63}
64
65AliHLTTPCCATracker::~AliHLTTPCCATracker()
66{
67 // destructor
68 StartEvent();
69 delete[] fRows;
70}
71
72// ----------------------------------------------------------------------------------
73void AliHLTTPCCATracker::Initialize( AliHLTTPCCAParam &param )
74{
75 // initialosation
76 StartEvent();
77 delete[] fRows;
78 fRows = 0;
79 fParam = param;
80 fParam.Update();
81 fRows = new AliHLTTPCCARow[fParam.NRows()];
82 for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
dc4788ec 83 fRows[irow].X() = fParam.RowX(irow);
326c2d4b 84 }
85 StartEvent();
86}
87
88void AliHLTTPCCATracker::StartEvent()
89{
90 // start new event and fresh the memory
91 delete[] fTracks;
92 delete[] fTrackCells;
93 delete[] fOutTrackHits;
94 delete[] fOutTracks;
dc4788ec 95 delete[] fCellHitPointers;
326c2d4b 96 fTracks = 0;
97 fTrackCells = 0;
98 fOutTrackHits = 0;
99 fOutTracks = 0;
100 fNTracks = 0;
101 fNOutTrackHits = 0;
102 fNOutTracks = 0;
103 fNHitsTotal = 0;
104 for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
105 fRows[irow].Clear();
106 }
107}
108
109
110void AliHLTTPCCATracker::ReadHitRow( Int_t iRow, AliHLTTPCCAHit *Row, Int_t NHits )
111{
112 // read row of hits
113 AliHLTTPCCARow &row = fRows[iRow];
114 row.Hits() = new AliHLTTPCCAHit[NHits];
115 for( Int_t i=0; i<NHits; i++ ){
116 row.Hits()[i]=Row[i];
117 row.Hits()[i].ErrY()*= fParam.YErrorCorrection();
118 row.Hits()[i].ErrZ()*= fParam.ZErrorCorrection();
119 }
120 row.NHits() = NHits;
121 fNHitsTotal += NHits;
122}
123
124void AliHLTTPCCATracker::Reconstruct()
125{
126 // reconstruction of event
dc4788ec 127 fTimers[0] = 0;
128 fTimers[1] = 0;
129 fTimers[2] = 0;
130 fTimers[3] = 0;
131 //cout<<"Find Cells..."<<endl;
326c2d4b 132 FindCells();
dc4788ec 133 //cout<<"Find Tracks..."<<endl;
134 FindTracks();
135 //cout<<"Find Tracks OK"<<endl;
136 }
326c2d4b 137
138
139void AliHLTTPCCATracker::FindCells()
140{
141 // cell finder - neighbouring hits are grouped to cells
142
dc4788ec 143 TStopwatch timer;
144 Bool_t *vUsed = new Bool_t [fNHitsTotal];
145 fCellHitPointers = new Int_t [fNHitsTotal];
146 AliHLTTPCCACell *vCells = new AliHLTTPCCACell[fNHitsTotal];
147
148 Int_t lastCellHitPointer = 0;
326c2d4b 149 for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
150 AliHLTTPCCARow &row=fRows[irow];
151 Int_t nHits = row.NHits();
152 if( nHits<1 ) continue;
dc4788ec 153 row.CellHitPointers() = fCellHitPointers + lastCellHitPointer;
326c2d4b 154 Int_t nPointers = 0;
dc4788ec 155 Int_t nCells = 0;
156
326c2d4b 157 for (Int_t ih = 0; ih<nHits; ih++) vUsed[ih] = 0;
dc4788ec 158
326c2d4b 159 for (Int_t ih = 0; ih<nHits; ih++){
160 if( vUsed[ih] ) continue;
161 // cell start
dc4788ec 162 AliHLTTPCCACell &cell = vCells[nCells++];
326c2d4b 163 cell.FirstHitRef() = nPointers;
164 cell.NHits() = 1;
165 cell.IDown() = -1;
166 cell.IUp() = -1;
167 cell.IUsed() = 0;
168 row.CellHitPointers()[nPointers++] = ih;
169 vUsed[ih] = 1;
170 Int_t jLast = ih;
171 while( jLast<nHits-1 ){
172 AliHLTTPCCAHit &h = row.Hits()[jLast];
173 Double_t d2min = 1.e10;
174 Int_t jBest = -1;
175 for (Int_t j = jLast+1; j<nHits; j++){
176 if( vUsed[j] ) continue;
177 AliHLTTPCCAHit &h1 = row.Hits()[j];
178 Double_t dy = TMath::Abs(h.Y() - h1.Y() );
dc4788ec 179 if( dy>(h.ErrY()+h1.ErrY())*3.5*2 ) break;
326c2d4b 180 Double_t dz = TMath::Abs(h.Z() - h1.Z() );
dc4788ec 181 if( dz>(h.ErrZ()+h1.ErrZ())*3.5*2 ) continue;
326c2d4b 182 Double_t d2 = dz*dz+dy*dy;
183 if( d2<d2min ){
184 d2min = d2;
185 jBest = j;
186 }
187 }
188 if( jBest<0 ) break;
189 row.CellHitPointers()[nPointers++] = jBest;
190 cell.NHits()++;
191 vUsed[jBest] = 1;
192 jLast = jBest;
193 }
194
195 AliHLTTPCCAHit &h = row.GetCellHit(cell,0);
196 AliHLTTPCCAHit &h1= row.GetCellHit(cell,cell.NHits()-1);
197
198 cell.Y() = .5*(h.Y() + h1.Y());
199 cell.Z() = .5*(h.Z() + h1.Z());
200 cell.ErrY() = .5*(TMath::Abs(h.Y() - h1.Y())/3 + h.ErrY() + h1.ErrY());
201 cell.ErrZ() = .5*(TMath::Abs(h.Z() - h1.Z())/3 + h.ErrZ() + h1.ErrZ());
326c2d4b 202 }
203
dc4788ec 204 row.Cells() = new AliHLTTPCCACell[nCells];
205 row.NCells() = nCells;
206 lastCellHitPointer += nPointers;
207 for( Int_t i=0; i<nCells; i++ ) row.Cells()[i]=vCells[i];
326c2d4b 208 }
dc4788ec 209 delete[] vUsed;
210 delete[] vCells;
211 timer.Stop();
212 fTimers[0] = timer.CpuTime();
326c2d4b 213}
214
215
216void AliHLTTPCCATracker::FindTracks()
217{
218 // the Cellular Automaton track finder
219
220 if( fNHitsTotal < 1 ) return;
221
222#ifdef DRAW
223 if( !gApplication ){
224 TApplication *myapp = new TApplication("myapp",0,0);
dc4788ec 225 }
226 //AliHLTTPCCADisplay::Instance().Init();
326c2d4b 227 AliHLTTPCCADisplay::Instance().SetCurrentSector( this );
228 AliHLTTPCCADisplay::Instance().DrawSector( this );
dc4788ec 229 for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
230 for (Int_t i = 0; i<fRows[iRow].NHits(); i++)
231 AliHLTTPCCADisplay::Instance().DrawHit( iRow, i );
232 cout<<"hits"<<endl;
233 AliHLTTPCCADisplay::Instance().Ask();
234 AliHLTTPCCADisplay::Instance().Clear();
235 AliHLTTPCCADisplay::Instance().DrawSector( this );
326c2d4b 236 for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
237 for (Int_t i = 0; i<fRows[iRow].NCells(); i++)
238 AliHLTTPCCADisplay::Instance().DrawCell( iRow, i );
dc4788ec 239 cout<<"cells"<<endl;
240 AliHLTTPCCADisplay::Instance().Ask();
326c2d4b 241 Int_t nConnectedCells = 0;
242#endif
243
244 std::vector<AliHLTTPCCATrack> vTracks;
245 std::vector<Int_t> vTrackCells;
246 fTrackCells = new Int_t[2*fNHitsTotal];
247
dc4788ec 248 TStopwatch timer1;
249 Double_t factor2 = 3.5*fParam.CellConnectionFactor()*3.5*fParam.CellConnectionFactor();
250
326c2d4b 251 for( Int_t iRow1=0; iRow1<fParam.NRows()-1; iRow1++ ){
252 AliHLTTPCCARow &row1 = fRows[iRow1];
253 Int_t lastRow2 = iRow1+3;
254 if( lastRow2>=fParam.NRows() ) lastRow2 = fParam.NRows()-1;
255 for( Int_t iRow2=iRow1+1; iRow2<=lastRow2; iRow2++ ){
256 AliHLTTPCCARow &row2 = fRows[iRow2];
257 for (Int_t i1 = 0; i1<row1.NCells(); i1++){
258 AliHLTTPCCACell *c1 = &(row1.Cells()[i1]);
259 if( c1->IUp()>=0 ) continue;
260 Double_t sy1 = c1->ErrY()*c1->ErrY();
261 Double_t sz1 = c1->ErrZ()*c1->ErrZ();
262 for (Int_t i2 = 0; i2<row2.NCells(); i2++){
263 AliHLTTPCCACell *c2 = &(row2.Cells()[i2]);
264 Double_t sy2 = c2->ErrY()*c2->ErrY();
dc4788ec 265 Double_t dy = c1->Y()-c2->Y();
266 if( dy*dy>factor2*(sy1+sy2) ){
267 if( dy>0 ) continue;
268 else break;
269 }
326c2d4b 270 Double_t sz2 = c2->ErrZ()*c2->ErrZ();
dc4788ec 271 Double_t dz = c1->Z()-c2->Z();
272 if( dz*dz>factor2*(sz1+sz2) ) continue;
326c2d4b 273 if( c1->IUp() ==-1 ) c1->IUp() = (i2<<8)+iRow2;
274 else c1->IUp() = -2;
275 if( c2->IDown() ==-1 ) c2->IDown() = (i1<<8)+iRow1;
276 else c2->IDown() = -2;
277 }
278 }
279 }
280 }
281
dc4788ec 282 timer1.Stop();
283 fTimers[1] = timer1.CpuTime();
284
285 TStopwatch timer2;
286
326c2d4b 287 Int_t nOutTrackHits = 0;
288 Int_t nTrackCells = 0;
289 for( Int_t iRow1=0; iRow1<fParam.NRows(); iRow1++ ){
dc4788ec 290 AliHLTTPCCARow &row1 = fRows[iRow1];
326c2d4b 291 for (Int_t i1 = 0; i1<row1.NCells(); i1++){
292 AliHLTTPCCACell *c1 = &(row1.Cells()[i1]);
dc4788ec 293 //if( c1->IDown()==-2 || c1->IUp()==-2 ) continue;
326c2d4b 294 if( c1->IUsed()>0 ) continue;
295 c1->IUsed() = 1;
296 AliHLTTPCCATrack track;
297 track.Used() = 0;
298 track.NCells() = 1;
299 track.IFirstCell() = nTrackCells;
300 fTrackCells[nTrackCells++] = (i1<<8)+iRow1;
301 AliHLTTPCCACell *last = c1;
302 Int_t lastRow = iRow1;
303 while( last->IUp() >=0 ){
304 Int_t iRow2 = last->IUp()%256;
305 AliHLTTPCCARow &row2 = fRows[iRow2];
306 AliHLTTPCCACell *next = &(row2.Cells()[last->IUp()>>8]);
307 if( next->IDown()==-2 || next->IUp()==-2 ) break;
308#ifdef DRAW
dc4788ec 309 AliHLTTPCCADisplay::Instance().ConnectCells( lastRow,*last,iRow2,*next );
326c2d4b 310 nConnectedCells++;
311#endif
312 next->IUsed() = 1;
313 fTrackCells[nTrackCells++] = last->IUp();
314 track.NCells()++;
315 last = next;
316 lastRow = iRow2;
317 }
318 vTracks.push_back(track);
319 }
320 }
dc4788ec 321
322 timer2.Stop();
323 fTimers[2] = timer2.CpuTime();
326c2d4b 324
325 Int_t nTracks = vTracks.size();
326 std::sort( vTracks.begin(), vTracks.end(), AliHLTTPCCATrack::CompareSize);
dc4788ec 327
328#ifdef DRAW
329 if( nConnectedCells>0 ) AliHLTTPCCADisplay::Instance().Ask();
330#endif
331
326c2d4b 332
333 fTracks = new AliHLTTPCCATrack[nTracks];
334 fNTracks = 0;
335 vTrackCells.clear();
336
dc4788ec 337 Int_t *vMatchedTracks = new Int_t[nTracks];
338
339 //cout<<"nTracks = "<<nTracks<<endl;
340 TStopwatch timer3;
341
326c2d4b 342 for( Int_t itr=0; itr<nTracks; itr++ ){
343 AliHLTTPCCATrack &iTrack = vTracks[itr];
dc4788ec 344 if( iTrack.NCells()<3 ) break;
345
346#ifdef DRAW
326c2d4b 347 FitTrack( iTrack );
dc4788ec 348 //AliHLTTPCCADisplay::Instance().Ask();
349 AliHLTTPCCADisplay::Instance().DrawTrack( iTrack );
350 //AliHLTTPCCADisplay::Instance().Ask();
351#endif
352 if( iTrack.Used() ) continue;
353
354
355 FitTrack( iTrack, 1 );
356 if( iTrack.Param().Chi2() > fParam.TrackChi2Cut()*iTrack.Param().NDF() ) continue;
326c2d4b 357
358 Int_t iFirstRow = GetTrackCellIRow( iTrack, 0);
359 Int_t iLastRow = GetTrackCellIRow( iTrack, iTrack.NCells()-1);
360 AliHLTTPCCACell *iFirstCell = &GetTrackCell( iTrack, 0);
dc4788ec 361 AliHLTTPCCACell *iLastCell = &GetTrackCell( iTrack, iTrack.NCells()-1);
326c2d4b 362 Bool_t updated = 1;
363 Int_t nMatched = 0;
dc4788ec 364 std::vector<Int_t> vMatchedCellsFront;
365 std::vector<Int_t> vMatchedCellsBack;
326c2d4b 366 while( updated ){
367 updated = 0;
dc4788ec 368 for( Int_t jtr=itr+1; jtr<nTracks; jtr++ ){
326c2d4b 369 AliHLTTPCCATrack &jTrack = vTracks[jtr];
370 if( jTrack.Used() ) continue;
371 Int_t jFirstRow = GetTrackCellIRow( jTrack, 0);
372 Int_t jLastRow = GetTrackCellIRow( jTrack, jTrack.NCells()-1);
373 AliHLTTPCCACell *jFirstCell = &GetTrackCell( jTrack, 0);
374 AliHLTTPCCACell *jLastCell = &GetTrackCell( jTrack, jTrack.NCells()-1);
375
376 Int_t dFirstRow1 = TMath::Abs(iFirstRow-jLastRow);
377 Int_t dFirstRow2 = TMath::Abs(iFirstRow-jFirstRow);
378 Int_t dLastRow1 = TMath::Abs(iLastRow-jLastRow);
379 Int_t dLastRow2 = TMath::Abs(iLastRow-jFirstRow);
380 if( dFirstRow1 > fParam.MaxTrackMatchDRow() &&
381 dFirstRow2 > fParam.MaxTrackMatchDRow() &&
382 dLastRow1 > fParam.MaxTrackMatchDRow() &&
383 dLastRow2 > fParam.MaxTrackMatchDRow() ) continue;
384 Int_t iCase=0;
385 AliHLTTPCCACell *iC, *jC;
386 if( dFirstRow1<dFirstRow2 && dFirstRow1<dLastRow1 && dFirstRow1<dLastRow2 ){
387 iCase = 0;
388 iC = iFirstCell;
389 jC = jLastCell;
390 }else if( dFirstRow2<dLastRow1 && dFirstRow2<dLastRow2 ){
391 iCase = 1;
392 iC = iFirstCell;
393 jC = jFirstCell;
394 }else if( dLastRow1<dLastRow2 ){
395 iCase = 2;
396 iC = iLastCell;
397 jC = jLastCell;
398 }else{
399 iCase = 3;
400 iC = iLastCell;
401 jC = jFirstCell;
402 }
403 {
404 Double_t dy = TMath::Abs(iC->Y() - jC->Y());
405 Double_t dz = TMath::Abs(iC->Z() - jC->Z());
406 Double_t sy1 = iC->ErrY()*iC->ErrY();
407 Double_t sz1 = iC->ErrZ()*iC->ErrZ();
408 Double_t sy2 = jC->ErrY()*jC->ErrY();
409 Double_t sz2 = jC->ErrZ()*jC->ErrZ();
dc4788ec 410 Double_t dist1 = sqrt( (dy*dy)/(sy1+sy2) );
411 Double_t dist2 = sqrt( (dz*dz)/(sz1+sz2) );
412 if( dist1>3.5*fParam.TrackConnectionFactor() ) continue;
413 if( dist2>3.5*fParam.TrackConnectionFactor() ) continue;
326c2d4b 414 }
415 AliHLTTPCCATrackPar t = iTrack.Param();
416 //t.Chi2() = 0;
417 //t.NDF() = 0;
418 for( Int_t i=0; i<jTrack.NCells() ; i++){
419 AliHLTTPCCACell &c = GetTrackCell(jTrack,i);
420 AliHLTTPCCARow &row = GetTrackCellRow(jTrack,i);
421 for( Int_t j=0; j<c.NHits(); j++){
422 AliHLTTPCCAHit &h = row.GetCellHit(c,j);
423 Double_t m[3] = {row.X(), h.Y(), h.Z() };
424 Double_t mV[6] = {fParam.ErrX()*fParam.ErrX(), 0, h.ErrY()*h.ErrY(), 0, 0, h.ErrZ()*h.ErrZ() };
425 Double_t mV1[6];
426 t.TransportBz(fParam.Bz(),m);
427 t.GetConnectionMatrix(fParam.Bz(),m, mV1);
428 t.Filter(m, mV, mV1);
429 }
430 }
431 if( t.Chi2() > fParam.TrackChi2Cut()*t.NDF() ) continue;
432 if( iCase==0 ){
433 iFirstRow = jFirstRow;
434 iFirstCell = jFirstCell;
dc4788ec 435 for( Int_t i=jTrack.NCells()-1; i>=0; i-- ){
436 vMatchedCellsBack.push_back(fTrackCells[jTrack.IFirstCell()+i]);
437 }
326c2d4b 438 }else if( iCase ==1 ){
439 iFirstRow = jLastRow;
440 iFirstCell = jLastCell;
dc4788ec 441 for( Int_t i=0; i<jTrack.NCells(); i++){
442 vMatchedCellsBack.push_back(fTrackCells[jTrack.IFirstCell()+i]);
443 }
326c2d4b 444 }else if( iCase == 2 ){
445 iLastRow = jFirstRow;
446 iLastCell = jFirstCell;
dc4788ec 447 for( Int_t i=jTrack.NCells()-1; i>=0; i-- ){
448 vMatchedCellsFront.push_back(fTrackCells[jTrack.IFirstCell()+i]);
449 }
326c2d4b 450 }else{
451 iLastRow = jLastRow;
452 iLastCell = jLastCell;
dc4788ec 453 for( Int_t i=0; i<jTrack.NCells(); i++){
454 vMatchedCellsFront.push_back(fTrackCells[jTrack.IFirstCell()+i]);
455 }
326c2d4b 456 }
457 t.Normalize();
458
326c2d4b 459 //t.NDF()+= iTrack.Param().NDF();
460 //t.Chi2()+= iTrack.Param().Chi2();
461 iTrack.Param() = t;
462 vMatchedTracks[nMatched++] = jtr;
463 jTrack.Used()=1;
464 updated = 1;
465 break;
466 }
dc4788ec 467 }// while updated
326c2d4b 468
469 if(0){
470 Double_t t0[7];
471 for( Int_t i=0; i<7; i++ ) t0[i] = iTrack.Param().Par()[i];
472 iTrack.Param().Init();
473 for( Int_t i=0; i<7; i++ ) iTrack.Param().Par()[i] = t0[i];
474 for( Int_t i=0; i<iTrack.NCells() ; i++){
475 AliHLTTPCCACell &c = GetTrackCell( iTrack, i);
476 AliHLTTPCCARow &row = GetTrackCellRow( iTrack, i);
477 for( Int_t j=0; j<c.NHits(); j++){
478 AliHLTTPCCAHit &h = row.GetCellHit(c,j);
479 Double_t m[3] = {row.X(), h.Y(), h.Z() };
480 Double_t mV[6] = {0, 0, h.ErrY()*h.ErrY(), 0, 0, h.ErrZ()*h.ErrZ() };
481 Double_t mV1[6];
482 iTrack.Param().TransportBz(fParam.Bz(), m, t0);
483 iTrack.Param().GetConnectionMatrix(fParam.Bz(), m, mV1, t0);
484 iTrack.Param().Filter(m, mV, mV1);
485 }
486 }
487 iTrack.Param().Normalize();
488 }
489 //FitTrack(iTrack,5);
490 Int_t nHits = 0;
491 for( Int_t iCell=0; iCell<iTrack.NCells(); iCell++){
492 Int_t ind = fTrackCells[iTrack.IFirstCell()+iCell];
493 AliHLTTPCCARow &row = fRows[ind%256];
494 AliHLTTPCCACell &c = row.Cells()[ind>>8];
495 nHits+=c.NHits();
496 }
dc4788ec 497 for( UInt_t i=0; i<vMatchedCellsBack.size(); i++){
498 Int_t ind = vMatchedCellsBack[i];
326c2d4b 499 AliHLTTPCCARow &row = fRows[ind%256];
500 AliHLTTPCCACell &c = row.Cells()[ind>>8];
501 nHits+=c.NHits();
502 }
dc4788ec 503 for( UInt_t i=0; i<vMatchedCellsFront.size(); i++){
504 Int_t ind = vMatchedCellsFront[i];
505 AliHLTTPCCARow &row = fRows[ind%256];
506 AliHLTTPCCACell &c = row.Cells()[ind>>8];
507 nHits+=c.NHits();
508 }
509 Int_t nCells = iTrack.NCells()+vMatchedCellsBack.size()+vMatchedCellsFront.size();
510 if( nHits<5 || nCells<3){
326c2d4b 511 for( Int_t i=0; i<nMatched; i++ ) vTracks[vMatchedTracks[i]].Used()=0;
512 continue;
513 }
514 iTrack.Used() = 1;
dc4788ec 515
516 AliHLTTPCCATrack &mTrack = fTracks[fNTracks++];
517 mTrack = iTrack;
518 mTrack.IFirstCell() = vTrackCells.size();
519 mTrack.NCells() = 0;
520
521 for( Int_t i=vMatchedCellsBack.size()-1; i>=0; i-- ){
522 vTrackCells.push_back(vMatchedCellsBack[i]);
523 mTrack.NCells()++;
524 }
326c2d4b 525 for( Int_t i=0; i<iTrack.NCells() ; i++){
526 vTrackCells.push_back(fTrackCells[iTrack.IFirstCell()+i]);
dc4788ec 527 mTrack.NCells()++;
528 }
529 for( UInt_t i=0; i<vMatchedCellsFront.size(); i++){
530 vTrackCells.push_back(vMatchedCellsFront[i]);
531 mTrack.NCells()++;
532 }
326c2d4b 533 nOutTrackHits+= nHits;
534 }
dc4788ec 535
536 timer3.Stop();
537 fTimers[3] = timer3.CpuTime();
538
539 delete[] vMatchedTracks;
326c2d4b 540
541 //fTrackCells = new Int_t[vTrackCells.size()];
542 for( UInt_t i=0; i<vTrackCells.size(); i++ ) fTrackCells[i] = vTrackCells[i];
543
544#ifdef DRAW
dc4788ec 545 if( nTracks>0 ) AliHLTTPCCADisplay::Instance().Ask();
326c2d4b 546#endif
547
dc4788ec 548 //cout<<"n out Tracks = "<<fNTracks<<endl;
326c2d4b 549
550 fOutTrackHits = new Int_t[nOutTrackHits];
551 fNOutTrackHits = 0;
552 fNOutTracks = fNTracks;
553 fOutTracks = new AliHLTTPCCAOutTrack[fNOutTracks];
554 for( Int_t itr=0; itr<fNOutTracks; itr++ ){
555 AliHLTTPCCATrack &t = fTracks[itr];
556#ifdef DRAW
dc4788ec 557 AliHLTTPCCADisplay::Instance().DrawTrack( t );
558 //AliHLTTPCCADisplay::Instance().Ask();
326c2d4b 559#endif
560 AliHLTTPCCAOutTrack &tmp = fOutTracks[itr];
561 tmp.FirstHitRef() = fNOutTrackHits;
562 tmp.NHits() = 0;
563 tmp.Param() = t.Param();
564 for( Int_t iCell=0; iCell<t.NCells(); iCell++){
565 AliHLTTPCCACell &cell = GetTrackCell(t,iCell);
566 AliHLTTPCCARow &row = GetTrackCellRow(t,iCell);
567 for( Int_t iHit=0; iHit<cell.NHits(); iHit++ ){
568 AliHLTTPCCAHit &hit = row.GetCellHit(cell,iHit);
569 fOutTrackHits[fNOutTrackHits] = hit.ID();
570 fNOutTrackHits++;
571 tmp.NHits()++;
572 }
573 }
574 }
575
576#ifdef DRAW
577 AliHLTTPCCADisplay::Instance().Ask();
578 //AliHLTTPCCADisplay::Instance().DrawMCTracks(fParam.fISec);
579 //AliHLTTPCCADisplay::Instance().Update();
580 //AliHLTTPCCADisplay::Instance().Ask();
581#endif
582}
583
584
585
586void AliHLTTPCCATracker::FitTrack( AliHLTTPCCATrack &track, Int_t nIter )
587{
588 // fit the track with nIter iterations
589
590 AliHLTTPCCATrackPar &t = track.Param();
591 t.Init();
592
593 AliHLTTPCCACell &c1 = GetTrackCell(track,0);
594 AliHLTTPCCACell &c2 = GetTrackCell(track,track.NCells()-1);
595 AliHLTTPCCARow &row1 = GetTrackCellRow(track,0);
596 AliHLTTPCCARow &row2 = GetTrackCellRow(track,track.NCells()-1);
597 Double_t t0[7];
598 t0[0]=row1.X();
599 t0[1]=c1.Y();
600 t0[2]=c1.Z();
601 t0[3]= row2.X() - row1.X();
602 t0[4]= c2.Y() - c1.Y();
603 t0[5]= c2.Z() - c1.Z();
604 Double_t tt = sqrt(t0[3]*t0[3]+t0[4]*t0[4]+t0[5]*t0[5]);
dd94bda2 605 if( TMath::Abs(tt)>1.e-4 ){
326c2d4b 606 t0[3]/=tt;
607 t0[4]/=tt;
608 t0[5]/=tt;
609 }else{
610 t0[4]=1;
611 }
612 t0[6] = 0;
613
dc4788ec 614 Int_t step = track.NCells()/3;
615
326c2d4b 616 for( Int_t iter=0; iter<nIter; iter++ ){
617 t.Init();
618 for( Int_t i=0; i<7; i++) t.Par()[i] = t0[i];
619 {
620 Double_t m[3] = {row1.X(), c1.Y(), c1.Z() };
621 t.TransportBz(fParam.Bz(),m,t0);
622 }
623 t.Init();
624 for( Int_t i=0; i<7; i++ ) t.Par()[i] = t0[i];
dc4788ec 625
626 //AliHLTTPCCATrackPar tt = t;
627
628 for( Int_t i=0; i<track.NCells() ; i+=step){
326c2d4b 629 AliHLTTPCCACell &c = GetTrackCell(track,i);
630 AliHLTTPCCARow &row = GetTrackCellRow(track,i);
631 for( Int_t j=0; j<c.NHits(); j++){
632 AliHLTTPCCAHit &h = row.GetCellHit(c,j);
633 Double_t m[3] = {row.X(), h.Y(), h.Z() };
634 Double_t mV[6] = {fParam.ErrX()*fParam.ErrX(), 0, h.ErrY()*h.ErrY(), 0, 0, h.ErrZ()*h.ErrZ() };
635 Double_t mV1[6];
636 t.TransportBz(fParam.Bz(),m, t0);
637 t.GetConnectionMatrix(fParam.Bz(),m, mV1, t0);
638 t.Filter(m, mV, mV1);
dc4788ec 639 //tt.TransportBz(fParam.Bz(),m, t0);
640 //tt.GetConnectionMatrix(fParam.Bz(),m, mV1, t0);
641 //tt.Filter(m, mV, mV1);
326c2d4b 642 }
643 }
644 t.Normalize();
645 for( Int_t i=0; i<7; i++ ) t0[i] = t.Par()[i];
646 }
647}