coverity warning 16816 fixed
[u/mrichter/AliRoot.git] / HLT / TPCLib / merger-ca / AliHLTTPCGMMerger.cxx
CommitLineData
6d869045 1// $Id: AliHLTTPCGMMerger.cxx 30732 2009-01-22 23:02:02Z sgorbuno $
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: Sergey Gorbunov <sergey.gorbunov@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
20#include <stdio.h>
21#include "AliHLTTPCCASliceOutTrack.h"
22#include "AliHLTTPCCATracker.h"
23#include "AliHLTTPCCATrackParam.h"
24#include "AliHLTTPCGMCluster.h"
25
26#include "AliHLTTPCGMMerger.h"
27
28#include "AliHLTTPCCAMath.h"
29#include "TStopwatch.h"
30
31#include "AliHLTTPCCATrackParam.h"
32#include "AliHLTTPCCASliceOutput.h"
33#include "AliHLTTPCGMMergedTrack.h"
34#include "AliHLTTPCCADataCompressor.h"
35#include "AliHLTTPCCAParam.h"
36#include "AliHLTTPCCATrackLinearisation.h"
37#include "AliHLTTPCCADataCompressor.h"
38
39#include "AliHLTTPCGMTrackParam.h"
40#include "AliHLTTPCGMTrackLinearisation.h"
41#include "AliHLTTPCGMSliceTrack.h"
42#include "AliHLTTPCGMBorderTrack.h"
b0a6cd38 43#include <cmath>
6d869045 44
2fba026d 45#include <algorithm>
6d869045 46
2fba026d 47#include "AliHLTTPCCAGPUConfig.h"
48#include "MemoryAssignmentHelpers.h"
6d869045 49
50AliHLTTPCGMMerger::AliHLTTPCGMMerger()
51 :
52 fSliceParam(),
53 fNOutputTracks( 0 ),
2fba026d 54 fNOutputTrackClusters( 0 ),
6d869045 55 fOutputTracks( 0 ),
56 fOutputClusterIds(0),
57 fSliceTrackInfos( 0 ),
58 fMaxSliceTracks(0),
59 fClusterX(0),
60 fClusterY(0),
61 fClusterZ(0),
62 fClusterRowType(0),
63 fClusterAngle(0),
64 fBorderMemory(0),
2fba026d 65 fBorderRangeMemory(0),
66 fGPUTracker(NULL),
67 fDebugLevel(0),
68 fNClusters(0)
6d869045 69{
70 //* constructor
71
72 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
73 fNextSliceInd[iSlice] = iSlice + 1;
74 fPrevSliceInd[iSlice] = iSlice - 1;
75 }
76 int mid = fgkNSlices / 2 - 1 ;
2fba026d 77 int last = fgkNSlices - 1 ;
6d869045 78 fNextSliceInd[ mid ] = 0;
79 fPrevSliceInd[ 0 ] = mid; fNextSliceInd[ last ] = fgkNSlices / 2;
80 fPrevSliceInd[ fgkNSlices/2 ] = last;
65bd3f88 81 {
82 const double kCLight = 0.000299792458;
83 double constBz = fSliceParam.BzkG() * kCLight;
84
85 fPolinomialFieldBz[0] = constBz * ( 0.999286 );
86 fPolinomialFieldBz[1] = constBz * ( -4.54386e-7 );
87 fPolinomialFieldBz[2] = constBz * ( 2.32950e-5 );
88 fPolinomialFieldBz[3] = constBz * ( -2.99912e-7 );
89 fPolinomialFieldBz[4] = constBz * ( -2.03442e-8 );
90 fPolinomialFieldBz[5] = constBz * ( 9.71402e-8 );
91 }
6d869045 92
93 Clear();
94}
95
96
97AliHLTTPCGMMerger::AliHLTTPCGMMerger(const AliHLTTPCGMMerger&)
98 :
99 fSliceParam(),
100 fNOutputTracks( 0 ),
2fba026d 101 fNOutputTrackClusters( 0 ),
6d869045 102 fOutputTracks( 0 ),
103 fOutputClusterIds(0),
104 fSliceTrackInfos( 0 ),
105 fMaxSliceTracks(0),
106 fClusterX(0),
107 fClusterY(0),
108 fClusterZ(0),
109 fClusterRowType(0),
110 fClusterAngle(0),
111 fBorderMemory(0),
2fba026d 112 fBorderRangeMemory(0),
113 fGPUTracker(NULL),
114 fDebugLevel(0),
115 fNClusters(0)
6d869045 116{
117 //* dummy
34e46627 118 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
119 fNextSliceInd[iSlice] = 0;
120 fPrevSliceInd[iSlice] = 0;
121 }
65bd3f88 122 {
123 const double kCLight = 0.000299792458;
124 double constBz = fSliceParam.BzkG() * kCLight;
125
126 fPolinomialFieldBz[0] = constBz * ( 0.999286 );
127 fPolinomialFieldBz[1] = constBz * ( -4.54386e-7 );
128 fPolinomialFieldBz[2] = constBz * ( 2.32950e-5 );
129 fPolinomialFieldBz[3] = constBz * ( -2.99912e-7 );
130 fPolinomialFieldBz[4] = constBz * ( -2.03442e-8 );
131 fPolinomialFieldBz[5] = constBz * ( 9.71402e-8 );
132 }
34e46627 133 Clear();
6d869045 134}
135
136const AliHLTTPCGMMerger &AliHLTTPCGMMerger::operator=(const AliHLTTPCGMMerger&) const
137{
138 //* dummy
139 return *this;
140}
141
142
143AliHLTTPCGMMerger::~AliHLTTPCGMMerger()
144{
145 //* destructor
146 ClearMemory();
147}
148
149void AliHLTTPCGMMerger::Clear()
150{
151 for ( int i = 0; i < fgkNSlices; ++i ) {
152 fkSlices[i] = 0;
153 fSliceNTrackInfos[ i ] = 0;
154 fSliceTrackInfoStart[ i ] = 0;
155 }
156 ClearMemory();
157}
158
159
160void AliHLTTPCGMMerger::ClearMemory()
161{
6d869045 162 delete[] fOutputClusterIds;
163 delete[] fSliceTrackInfos;
2fba026d 164 if (!fGPUTracker)
165 {
166 delete[] fOutputTracks;
167 delete[] fClusterX;
168 delete[] fClusterY;
169 delete[] fClusterZ;
170 delete[] fClusterRowType;
171 delete[] fClusterAngle;
172 }
6d869045 173 delete[] fBorderMemory;
174 delete[] fBorderRangeMemory;
175
176 fNOutputTracks = 0;
177 fOutputTracks = 0;
178 fOutputClusterIds = 0;
179 fSliceTrackInfos = 0;
180 fMaxSliceTracks = 0;
181 fClusterX = 0;
182 fClusterY = 0;
183 fClusterZ = 0;
184 fClusterRowType = 0;
185 fClusterAngle = 0;
186 fBorderMemory = 0;
187 fBorderRangeMemory = 0;
188}
189
190
191void AliHLTTPCGMMerger::SetSliceData( int index, const AliHLTTPCCASliceOutput *sliceData )
192{
193 fkSlices[index] = sliceData;
194}
195
196
197bool AliHLTTPCGMMerger::Reconstruct()
198{
199 //* main merging routine
200
201 {
202 const double kCLight = 0.000299792458;
203 double constBz = fSliceParam.BzkG() * kCLight;
204
2fba026d 205 fPolinomialFieldBz[0] = constBz * ( 0.999286 );
206 fPolinomialFieldBz[1] = constBz * ( -4.54386e-7 );
207 fPolinomialFieldBz[2] = constBz * ( 2.32950e-5 );
208 fPolinomialFieldBz[3] = constBz * ( -2.99912e-7 );
209 fPolinomialFieldBz[4] = constBz * ( -2.03442e-8 );
210 fPolinomialFieldBz[5] = constBz * ( 9.71402e-8 );
6d869045 211 }
212
2d15d6ff 213 int nIter = 1;
6d869045 214 TStopwatch timer;
2fba026d 215#ifdef HLTCA_STANDALONE
216 unsigned long long int a, b, c, d, e, f, g;
217 AliHLTTPCCATracker::StandaloneQueryFreq(&g);
218#endif
2d15d6ff 219 //cout<<"Merger..."<<endl;
6d869045 220 for( int iter=0; iter<nIter; iter++ ){
221 if( !AllocateMemory() ) return 0;
2fba026d 222#ifdef HLTCA_STANDALONE
223 AliHLTTPCCATracker::StandaloneQueryTime(&a);
224#endif
6d869045 225 UnpackSlices();
2fba026d 226#ifdef HLTCA_STANDALONE
227 AliHLTTPCCATracker::StandaloneQueryTime(&b);
228#endif
6d869045 229 MergeWithingSlices();
2fba026d 230#ifdef HLTCA_STANDALONE
231 AliHLTTPCCATracker::StandaloneQueryTime(&c);
232#endif
6d869045 233 MergeSlices();
2fba026d 234#ifdef HLTCA_STANDALONE
235 AliHLTTPCCATracker::StandaloneQueryTime(&d);
236#endif
6d869045 237 CollectMergedTracks();
2fba026d 238#ifdef HLTCA_STANDALONE
239 AliHLTTPCCATracker::StandaloneQueryTime(&e);
240#endif
6d869045 241 Refit();
2fba026d 242#ifdef HLTCA_STANDALONE
243 AliHLTTPCCATracker::StandaloneQueryTime(&f);
244 if (fDebugLevel > 0)
245 {
246 printf("Merge Time:\tUnpack Slices:\t%lld us\n", (b - a) * 1000000 / g);
247 printf("\t\tMerge Within:\t%lld us\n", (c - b) * 1000000 / g);
248 printf("\t\tMerge Slices:\t%lld us\n", (d - c) * 1000000 / g);
249 printf("\t\tCollect:\t%lld us\n", (e - d) * 1000000 / g);
250 printf("\t\tRefit:\t\t%lld us\n", (f - e) * 1000000 / g);
251 }
252 int newTracks = 0;
253 for (int i = 0;i < fNOutputTracks;i++) if (fOutputTracks[i].OK()) newTracks++;
254 printf("Output Tracks: %d\n", newTracks);
255#endif
6d869045 256 }
257 timer.Stop();
2d15d6ff 258 //cout<<"\nMerger time = "<<timer.CpuTime()*1.e3/nIter<<" ms\n"<<endl;
6d869045 259
260 return 1;
261}
262
263
264
265bool AliHLTTPCGMMerger::AllocateMemory()
266{
267 //* memory allocation
268
269 ClearMemory();
270
271 int nTracks = 0;
2fba026d 272 fNClusters = 0;
6d869045 273 fMaxSliceTracks = 0;
274
275 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
276 if ( !fkSlices[iSlice] ) continue;
277 nTracks += fkSlices[iSlice]->NTracks();
2fba026d 278 fNClusters += fkSlices[iSlice]->NTrackClusters();
6d869045 279 if( fMaxSliceTracks < fkSlices[iSlice]->NTracks() ) fMaxSliceTracks = fkSlices[iSlice]->NTracks();
280 }
281
282 //cout<<"\nMerger: input "<<nTracks<<" tracks, "<<nClusters<<" clusters"<<endl;
2fba026d 283
284 fOutputClusterIds = new UInt_t[fNClusters];
285 fSliceTrackInfos = new AliHLTTPCGMSliceTrack[nTracks];
286 if (fGPUTracker)
287 {
288 char* basemem = fGPUTracker->MergerBaseMemory();
289 AssignMemory(fClusterX, basemem, fNClusters);
290 AssignMemory(fClusterY, basemem, fNClusters);
291 AssignMemory(fClusterZ, basemem, fNClusters);
292 AssignMemory(fClusterAngle, basemem, fNClusters);
293 AssignMemory(fClusterRowType, basemem, fNClusters);
294 AssignMemory(fOutputTracks, basemem, nTracks);
295 }
296 else
297 {
298 fOutputTracks = new AliHLTTPCGMMergedTrack[nTracks];
299 fClusterX = new float[fNClusters];
300 fClusterY = new float[fNClusters];
301 fClusterZ = new float[fNClusters];
302 fClusterRowType = new UInt_t[fNClusters];
303 fClusterAngle = new float[fNClusters];
304 }
6d869045 305 fBorderMemory = new AliHLTTPCGMBorderTrack[fMaxSliceTracks*2];
306 fBorderRangeMemory = new AliHLTTPCGMBorderTrack::Range[fMaxSliceTracks*2];
307
308 return ( ( fOutputTracks!=NULL )
309 && ( fOutputClusterIds!=NULL )
310 && ( fSliceTrackInfos!=NULL )
311 && ( fClusterX!=NULL )
312 && ( fClusterY!=NULL )
313 && ( fClusterZ!=NULL )
314 && ( fClusterRowType!=NULL )
315 && ( fClusterAngle!=NULL )
316 && ( fBorderMemory!=NULL )
317 && ( fBorderRangeMemory!=NULL )
318 );
319}
320
321
322
323void AliHLTTPCGMMerger::UnpackSlices()
324{
325 //* unpack the cluster information from the slice tracks and initialize track info array
326
327 int nTracksCurrent = 0;
328 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
329
330 fSliceTrackInfoStart[ iSlice ] = nTracksCurrent;
331
332 fSliceNTrackInfos[ iSlice ] = 0;
333
334 if ( !fkSlices[iSlice] ) continue;
335
336 float alpha = fSliceParam.Alpha( iSlice );
337
338 const AliHLTTPCCASliceOutput &slice = *( fkSlices[iSlice] );
339 const AliHLTTPCCASliceOutTrack *sliceTr = slice.GetFirstTrack();
340
341 for ( int itr = 0; itr < slice.NTracks(); itr++, sliceTr = sliceTr->GetNextTrack() ) {
342 AliHLTTPCGMSliceTrack &track = fSliceTrackInfos[nTracksCurrent];
343 track.Set( sliceTr, alpha );
344 if( !track.FilterErrors( fSliceParam, .999 ) ) continue;
345 track.SetPrevNeighbour( -1 );
346 track.SetNextNeighbour( -1 );
347 track.SetSliceNeighbour( -1 );
348 track.SetUsed( 0 );
349 nTracksCurrent++;
350 fSliceNTrackInfos[ iSlice ]++;
351 }
352
353 //std::cout<<"Unpack slice "<<iSlice<<": ntracks "<<slice.NTracks()<<"/"<<fSliceNTrackInfos[iSlice]<<std::endl;
354 }
355}
356
357
358
359
360
361void AliHLTTPCGMMerger::MakeBorderTracks( int iSlice, int iBorder, AliHLTTPCGMBorderTrack B[], int &nB )
362{
363 //* prepare slice tracks for merging with next/previous/same sector
364 //* each track transported to the border line
365
366 float fieldBz = fSliceParam.ConstBz();
367
368 nB = 0;
369
370 float dAlpha = fSliceParam.DAlpha() / 2;
371 float x0 = 0;
372
373 if ( iBorder == 0 ) { // transport to the left age of the sector and rotate horisontally
374 dAlpha = dAlpha - CAMath::Pi() / 2 ;
375 } else if ( iBorder == 1 ) { // transport to the right age of the sector and rotate horisontally
376 dAlpha = -dAlpha - CAMath::Pi() / 2 ;
377 } else if ( iBorder == 2 ) { // transport to the left age of the sector and rotate vertically
378 dAlpha = dAlpha;
379 x0 = fSliceParam.RowX( 63 );
380 } else if ( iBorder == 3 ) { // transport to the right age of the sector and rotate vertically
381 dAlpha = -dAlpha;
382 x0 = fSliceParam.RowX( 63 );
383 } else if ( iBorder == 4 ) { // transport to the middle of the sector, w/o rotation
384 dAlpha = 0;
385 x0 = fSliceParam.RowX( 63 );
386 }
387
388 const float maxSin = CAMath::Sin( 60. / 180.*CAMath::Pi() );
2fba026d 389 float cosAlpha = AliHLTTPCCAMath::Cos( dAlpha );
390 float sinAlpha = AliHLTTPCCAMath::Sin( dAlpha );
6d869045 391
392 for ( int itr = 0; itr < fSliceNTrackInfos[iSlice]; itr++ ) {
393
394 AliHLTTPCGMSliceTrack &track = fSliceTrackInfos[ fSliceTrackInfoStart[iSlice] + itr ];
395
396 if( track.Used() ) continue;
397 AliHLTTPCGMBorderTrack &b = B[nB];
398
399 if( track.TransportToXAlpha( x0, sinAlpha, cosAlpha, fieldBz, b, maxSin)){
400 b.SetTrackID( itr );
401 b.SetNClusters( track.NClusters() );
402 nB++;
403 }
404 }
405}
406
407
408void AliHLTTPCGMMerger::MergeBorderTracks ( int iSlice1, AliHLTTPCGMBorderTrack B1[], int N1,
409 int iSlice2, AliHLTTPCGMBorderTrack B2[], int N2 )
410{
411 //* merge two sets of tracks
412
413 //std::cout<<" Merge slices "<<iSlice1<<"+"<<iSlice2<<": tracks "<<N1<<"+"<<N2<<std::endl;
414 int statAll=0, statMerged=0;
415 float factor2ys = 1.5;//1.5;//SG!!!
416 float factor2zt = 1.5;//1.5;//SG!!!
417 float factor2k = 2.0;//2.2;
418
419 factor2k = 3.5 * 3.5 * factor2k * factor2k;
420 factor2ys = 3.5 * 3.5 * factor2ys * factor2ys;
421 factor2zt = 3.5 * 3.5 * factor2zt * factor2zt;
422
423 int minNPartHits = 10;//SG!!!
424 int minNTotalHits = 20;
425
426 AliHLTTPCGMBorderTrack::Range *range1 = fBorderRangeMemory;
427 AliHLTTPCGMBorderTrack::Range *range2 = fBorderRangeMemory + N1;
428
429 bool sameSlice = (iSlice1 == iSlice2);
430 {
431 for ( int itr = 0; itr < N1; itr++ ){
432 AliHLTTPCGMBorderTrack &b = B1[itr];
433 // if( iSlice1==7 && iSlice2==8 ){
434 //cout<<b.TrackID()<<": "<<b.Cov()[0]<<" "<<b.Cov()[1]<<endl;
435 //}
436 float d = 3.5*sqrt(b.Cov()[1]);
437 range1[itr].fId = itr;
438 range1[itr].fMin = b.Par()[1] - d;
439 range1[itr].fMax = b.Par()[1] + d;
440 }
441 std::sort(range1,range1+N1,AliHLTTPCGMBorderTrack::Range::CompMin);
442 if( sameSlice ){
443 for(int i=0; i<N1; i++) range2[i]= range1[i];
444 std::sort(range2,range2+N1,AliHLTTPCGMBorderTrack::Range::CompMax);
445 N2 = N1;
446 B2 = B1;
447 }else{
448 for ( int itr = 0; itr < N2; itr++ ){
449 AliHLTTPCGMBorderTrack &b = B2[itr];
450 float d = 3.5*sqrt(b.Cov()[1]);
451 range2[itr].fId = itr;
452 range2[itr].fMin = b.Par()[1] - d;
453 range2[itr].fMax = b.Par()[1] + d;
454 }
455 std::sort(range2,range2+N2,AliHLTTPCGMBorderTrack::Range::CompMax);
456 }
457 }
458
459 int i2 = 0;
460 for ( int i1 = 0; i1 < N1; i1++ ) {
461
462 AliHLTTPCGMBorderTrack::Range r1 = range1[i1];
463 while( i2<N2 && range2[i2].fMax< r1.fMin ) i2++;
464
465 AliHLTTPCGMBorderTrack &b1 = B1[r1.fId];
466 if ( b1.NClusters() < minNPartHits ) continue;
467 int iBest2 = -1;
468 int lBest2 = 0;
469 statAll++;
470 for( int k2 = i2; k2<N2; k2++){
471
472 AliHLTTPCGMBorderTrack::Range r2 = range2[k2];
473 if( r2.fMin > r1.fMax ) break;
474 if( sameSlice && (r1.fId >= r2.fId) ) continue;
475 // do check
476 AliHLTTPCGMBorderTrack &b2 = B2[r2.fId];
477 if ( b2.NClusters() < lBest2 ) continue;
478
479 if( !b1.CheckChi2Y(b2, factor2ys ) ) continue;
480 //if( !b1.CheckChi2Z(b2, factor2zt ) ) continue;
481 if( !b1.CheckChi2QPt(b2, factor2k ) ) continue;
482 if( !b1.CheckChi2YS(b2, factor2ys ) ) continue;
483 if( !b1.CheckChi2ZT(b2, factor2zt ) ) continue;
484 if ( b2.NClusters() < minNPartHits ) continue;
485 if ( b1.NClusters() + b2.NClusters() < minNTotalHits ) continue;
486
487 lBest2 = b2.NClusters();
488 iBest2 = b2.TrackID();
489 }
490
491 if ( iBest2 < 0 ) continue;
492 statMerged++;
493 AliHLTTPCGMSliceTrack &newTrack1 = fSliceTrackInfos[fSliceTrackInfoStart[iSlice1] + b1.TrackID() ];
494 AliHLTTPCGMSliceTrack &newTrack2 = fSliceTrackInfos[fSliceTrackInfoStart[iSlice2] + iBest2 ];
495
496 int old1 = newTrack2.PrevNeighbour();
497
498 if ( old1 >= 0 ) {
499 AliHLTTPCGMSliceTrack &oldTrack1 = fSliceTrackInfos[fSliceTrackInfoStart[iSlice1] + old1];
500 if ( oldTrack1.NClusters() < newTrack1.NClusters() ) {
501 newTrack2.SetPrevNeighbour( -1 );
502 oldTrack1.SetNextNeighbour( -1 );
503 } else continue;
504 }
505 int old2 = newTrack1.NextNeighbour();
506 if ( old2 >= 0 ) {
507 AliHLTTPCGMSliceTrack &oldTrack2 = fSliceTrackInfos[fSliceTrackInfoStart[iSlice2] + old2];
508 if ( oldTrack2.NClusters() < newTrack2.NClusters() ) {
509 oldTrack2.SetPrevNeighbour( -1 );
510 } else continue;
511 }
512 newTrack1.SetNextNeighbour( iBest2 );
513 newTrack2.SetPrevNeighbour( b1.TrackID() );
514 }
515 //cout<<"slices "<<iSlice1<<","<<iSlice2<<": all "<<statAll<<" merged "<<statMerged<<endl;
516}
517
518
519void AliHLTTPCGMMerger::MergeWithingSlices()
520{
521 //* merge track segments withing one slice
522
523 float x0 = fSliceParam.RowX( 63 );
524 const float maxSin = CAMath::Sin( 60. / 180.*CAMath::Pi() );
525
526 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
527
528 int nBord = 0;
529 for ( int itr = 0; itr < fSliceNTrackInfos[iSlice]; itr++ ) {
530 AliHLTTPCGMSliceTrack &track = fSliceTrackInfos[ fSliceTrackInfoStart[iSlice] + itr ];
531 //track.SetPrevNeighbour( -1 );
532 //track.SetNextNeighbour( -1 );
533 //track.SetSliceNeighbour( -1 );
534 //track.SetUsed(0);
535
536 AliHLTTPCGMBorderTrack &b = fBorderMemory[nBord];
537 if( track.TransportToX( x0, fSliceParam.ConstBz(), b, maxSin) ){
538 b.SetTrackID( itr );
539 b.SetNClusters( track.NClusters() );
540 nBord++;
541 }
542 }
543
544 MergeBorderTracks( iSlice, fBorderMemory, nBord, iSlice, fBorderMemory, nBord );
545
546 for ( int itr = 0; itr < fSliceNTrackInfos[iSlice]; itr++ ) {
547 AliHLTTPCGMSliceTrack &track = fSliceTrackInfos[ fSliceTrackInfoStart[iSlice] + itr];
548 if( track.PrevNeighbour()>=0 || track.Used() ) continue;
549 int jtr = track.NextNeighbour();
550 track.SetSliceNeighbour( jtr );
551 track.SetNextNeighbour(-1);
552 while( jtr>=0 ){
553 AliHLTTPCGMSliceTrack &trackN = fSliceTrackInfos[ fSliceTrackInfoStart[iSlice] + jtr];
554 if( trackN.NClusters()>track.NClusters() ) track.CopyParamFrom(trackN);
555 trackN.SetUsed(2);
556 jtr = trackN.NextNeighbour();
557 trackN.SetSliceNeighbour( jtr );
558 trackN.SetNextNeighbour(-1);
559 trackN.SetPrevNeighbour(-1);
560 }
561 }
562 }
563}
564
565
566
567
568void AliHLTTPCGMMerger::MergeSlices()
569{
570 //* track merging between slices
571
572 //for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
573 //for ( int itr = 0; itr < fSliceNTrackInfos[iSlice]; itr++ ) {
574 //AliHLTTPCGMSliceTrack &track = fSliceTrackInfos[ fSliceTrackInfoStart[iSlice] + itr ];
575 //track.SetPrevNeighbour( -1 );
576 //track.SetNextNeighbour( -1 );
577 //}
578 //}
579
580 AliHLTTPCGMBorderTrack
581 *bCurr = fBorderMemory,
582 *bNext = fBorderMemory + fMaxSliceTracks;
583
584 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
585 int jSlice = fNextSliceInd[iSlice];
586 int nCurr = 0, nNext = 0;
587 MakeBorderTracks( iSlice, 2, bCurr, nCurr );
588 MakeBorderTracks( jSlice, 3, bNext, nNext );
589 MergeBorderTracks( iSlice, bCurr, nCurr, jSlice, bNext, nNext );
590 MakeBorderTracks( iSlice, 0, bCurr, nCurr );
591 MakeBorderTracks( jSlice, 1, bNext, nNext );
592 MergeBorderTracks( iSlice, bCurr, nCurr, jSlice, bNext, nNext );
593 }
594}
595
596
597
598
599
600void AliHLTTPCGMMerger::CollectMergedTracks()
601{
602 //*
603
604 //for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
605 //for ( int itr = 0; itr < fSliceNTrackInfos[iSlice]; itr++ ) {
606 //AliHLTTPCGMSliceTrack &track = fSliceTrackInfos[ fSliceTrackInfoStart[iSlice] + itr ];
607 //if( track.Used()!=2 ) track.SetUsed(0);
608 //}
609 //}
610
611 fNOutputTracks = 0;
612 int nOutTrackClusters = 0;
6f0cdd46 613 const int kMaxParts = 400;
614 const int kMaxClusters = 1000;
6d869045 615
6f0cdd46 616 const AliHLTTPCGMSliceTrack *trackParts[kMaxParts];
6d869045 617
618 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
619
620 for ( int itr = 0; itr < fSliceNTrackInfos[iSlice]; itr++ ) {
621
622 AliHLTTPCGMSliceTrack &track = fSliceTrackInfos[fSliceTrackInfoStart[iSlice] + itr];
623
624 if ( track.Used() ) continue;
625 if ( track.PrevNeighbour() >= 0 ) continue;
626 int nParts = 0;
627 int jSlice = iSlice;
628 AliHLTTPCGMSliceTrack *trbase = &track, *tr = &track;
629 tr->SetUsed( 1 );
630 do{
6f0cdd46 631 if( nParts >= kMaxParts ) break;
6d869045 632 trackParts[nParts++] = tr;
633 int jtr = tr->SliceNeighbour();
634 if( jtr >= 0 ) {
635 tr = &(fSliceTrackInfos[fSliceTrackInfoStart[jSlice] + jtr]);
636 tr->SetUsed( 2 );
637 continue;
638 }
639 jtr = trbase->NextNeighbour();
640 if( jtr>=0 ){
641 jSlice = fNextSliceInd[jSlice];
642 trbase = &(fSliceTrackInfos[fSliceTrackInfoStart[jSlice] + jtr]);
643 tr = trbase;
644 if( tr->Used() ) break;
645 tr->SetUsed( 1 );
646 continue;
647 }
648 break;
649 }while(1);
650
651 // unpack and sort clusters
652
2fba026d 653 std::sort(trackParts, trackParts+nParts, CompareTrackParts );
6d869045 654
6f0cdd46 655 AliHLTTPCCASliceOutCluster tmp[kMaxClusters];
6d869045 656 int currCluster = nOutTrackClusters;
657 int nHits = 0;
658 for( int ipart=0; ipart<nParts; ipart++ ){
659 const AliHLTTPCGMSliceTrack *t = trackParts[ipart];
660 int nTrackHits = t->NClusters();
6f0cdd46 661 if( nHits + nTrackHits >= kMaxClusters ) break;
6d869045 662 const AliHLTTPCCASliceOutCluster *c= t->OrigTrack()->Clusters();
663 AliHLTTPCCASliceOutCluster *c2 = tmp+nHits + nTrackHits-1;
664 for( int i=0; i<nTrackHits; i++, c++, c2-- ) *c2 = *c;
665 float alpha = t->Alpha();
666 for( int i=0; i<nTrackHits; i++) fClusterAngle[currCluster++] = alpha;
667 nHits+=nTrackHits;
668 }
669
670 UInt_t *clId = fOutputClusterIds + nOutTrackClusters;
671 for( int i=0; i<nHits; i++ ) clId[i] = tmp[i].GetId();
672
673 UInt_t *clT = fClusterRowType + nOutTrackClusters;
674 for( int i=0; i<nHits; i++ ) clT[i] = tmp[i].GetRowType();
675
676 float *clX = fClusterX + nOutTrackClusters;
677 for( int i=0; i<nHits; i++ ) clX[i] = tmp[i].GetX();
678
679 float *clY = fClusterY + nOutTrackClusters;
680 for( int i=0; i<nHits; i++ ) clY[i] = tmp[i].GetY();
681
682 float *clZ = fClusterZ + nOutTrackClusters;
683 for( int i=0; i<nHits; i++ ) clZ[i] = tmp[i].GetZ();
684
685 if ( nHits < 30 ) continue;
686
687 AliHLTTPCGMMergedTrack &mergedTrack = fOutputTracks[fNOutputTracks];
688 mergedTrack.SetOK(1);
689 mergedTrack.SetNClusters( nHits );
690 mergedTrack.SetFirstClusterRef( nOutTrackClusters );
691 AliHLTTPCGMTrackParam &p1 = mergedTrack.Param();
692 const AliHLTTPCGMSliceTrack &p2 = *(trackParts[0]);
693
694 p1.X() = p2.X();
695 p1.Y() = p2.Y();
696 p1.Z() = p2.Z();
697 p1.SinPhi() = p2.SinPhi();
698 p1.DzDs() = p2.DzDs();
699 p1.QPt() = p2.QPt();
700 mergedTrack.SetAlpha( p2.Alpha() );
701
702 fNOutputTracks++;
703 nOutTrackClusters += nHits;
704 }
705 }
2fba026d 706 fNOutputTrackClusters = nOutTrackClusters;
6d869045 707}
708
6d869045 709void AliHLTTPCGMMerger::Refit()
710{
711 //* final refit
2fba026d 712#ifdef HLTCA_GPU_MERGER
713 if (fGPUTracker)
714 {
715 fGPUTracker->RefitMergedTracks(this);
716 }
717 else
718#endif
719 {
720#ifdef HLTCA_STANDALONE
721#pragma omp parallel for
722#endif
723 for ( int itr = 0; itr < fNOutputTracks; itr++ ) {
724 AliHLTTPCGMMergedTrack &track = fOutputTracks[itr];
725 if( !track.OK() ) continue;
726
727 int nTrackHits = track.NClusters();
728
729 AliHLTTPCGMTrackParam t = track.Param();
730 float Alpha = track.Alpha();
731
732 t.Fit( fPolinomialFieldBz,
733 fClusterX+track.FirstClusterRef(),
734 fClusterY+track.FirstClusterRef(),
735 fClusterZ+track.FirstClusterRef(),
736 fClusterRowType+track.FirstClusterRef(),
737 fClusterAngle+track.FirstClusterRef(),
738 fSliceParam, nTrackHits, Alpha, 0 );
739
740 if ( fabs( t.QPt() ) < 1.e-4 ) t.QPt() = 1.e-4 ;
741
742 bool ok = nTrackHits >= 30 && t.CheckNumericalQuality() && fabs( t.SinPhi() ) <= .999;
743 track.SetOK(ok);
744 if( !ok ) continue;
745
746 if( 1 ){//SG!!!
747 track.SetNClusters( nTrackHits );
748 track.Param() = t;
749 track.Alpha() = Alpha;
750 }
751
752 {
753 int ind = track.FirstClusterRef();
754 float alpha = fClusterAngle[ind];
755 float x = fClusterX[ind];
756 float y = fClusterY[ind];
757 float z = fClusterZ[ind];
758 float sinA = AliHLTTPCCAMath::Sin( alpha - track.Alpha());
759 float cosA = AliHLTTPCCAMath::Cos( alpha - track.Alpha());
760 track.SetLastX( x*cosA - y*sinA );
761 track.SetLastY( x*sinA + y*cosA );
762 track.SetLastZ( z );
763 }
764 }
765 }
6d869045 766}
767