27 #include "Stl3Util/ftf/FtfFinder.h"
33 FtfFinder::FtfFinder ( )
47 FtfFinder::~FtfFinder ( )
50 if ( mcTrack )
delete[] mcTrack ;
51 if ( volumeC )
delete[] volumeC ;
52 if ( rowC )
delete[] rowC ;
53 if ( trackC )
delete[] trackC ;
58 double FtfFinder::process ( ) {
63 if ( para.infoLevel > 2 )
64 ftfLog (
"fft: Hit structure is empty \n " ) ;
68 initialCpuTime = CpuTime ( );
69 initialRealTime = RealTime ( );
72 if ( para.init == 0 ) {
73 if ( reset ( ) )
return 1 ;
77 if ( para.eventReset && setPointers ( ) )
return 1 ;
82 for ( i = 0 ; i < para.nPrimaryPasses ; i++ )
83 if ( getTracks ( ) ) break ;
87 for ( i = 0 ; i < para.nSecondaryPasses ; i++ )
88 if ( getTracks ( ) ) break ;
92 cpuTime = CpuTime ( ) - initialCpuTime ;
93 realTime = RealTime ( ) - initialRealTime ;
95 if ( para.infoLevel > 0 )
96 ftfLog (
"FtfFinder::process: cpu %7.3f real %f7.2 \n", cpuTime, realTime ) ;
105 void FtfFinder::dEdx ( ) {
106 for (
int i = 0 ; i<nTracks ; i++ ){
114 int FtfFinder::getTracks ( ) {
118 int nHitsSegment = (short)para.nHitsForSegment;
119 if ( para.primaries ) {
120 setConformalCoordinates ( ) ;
121 para.minHitsForFit = 1 ;
122 para.nHitsForSegment = max(2,nHitsSegment);
125 para.minHitsForFit = 2 ;
126 para.nHitsForSegment = max(3,nHitsSegment);
131 for (
int ir = para.nRowsPlusOne - 1 ; ir>=para.minHitsPerTrack ; ir--) {
135 if ( rowC[ir].first && (((
FtfHit *)rowC[ir].first)->row) < para.rowEnd ) break ;
139 firstHit = (
FtfHit *)(firstHit->nextRowHit) ) {
143 if ( firstHit->track != 0 ) continue ;
150 if ( nTracks > maxTracks ){
151 ftfLog(
"\n FtfFinder::getTracks: Max nr tracks reached !") ;
152 nTracks = maxTracks ;
159 thisTrack->para = ¶ ;
160 thisTrack->id = nTracks ;
161 thisTrack->firstHit = thisTrack->lastHit = firstHit ;
162 thisTrack->innerMostRow = thisTrack->outerMostRow = firstHit->row ;
163 thisTrack->xRefHit = firstHit->x ;
164 thisTrack->yRefHit = firstHit->y ;
165 thisTrack->xLastHit = firstHit->x ;
166 thisTrack->yLastHit = firstHit->y ;
168 thisTrack->debugNew ( ) ;
173 thisTrack->reset ( ) ;
177 if ( thisTrack->buildTrack ( firstHit, volumeC ) ) {
181 if ( para.primaries &&
182 para.mergePrimaries == 1 &&
184 thisTrack->mergePrimary( trackC ) ) {
186 thisTrack->deleteCandidate ( ) ;
193 thisTrack->deleteCandidate ( ) ;
204 if ( CpuTime() - initialCpuTime > para.maxTime ) {
205 ftfLog (
"FtfFinder::getTracks: tracker time out after %f\n",
206 CpuTime() - initialCpuTime ) ;
211 para.nHitsForSegment = nHitsSegment ;
217 void FtfFinder::mergePrimaryTracks ( ) {
221 memset ( trackC, 0, para.nPhiTrackPlusOne*para.nEtaTrackPlusOne*
sizeof(
FtfContainer) ) ;
226 for (
int i = 0 ; i < nTracks ; i++ ) {
227 currentTrack = &(
track[i]);
228 if ( currentTrack->flag < 0 ) continue ;
232 currentTrack->nxatrk = 0 ;
238 if ( currentTrack->mergePrimary ( trackC ) ) {
239 currentTrack->flag = -1 ;
246 int FtfFinder::reset (
void) {
256 para.nRowsPlusOne = (para.rowOuterMost-para.rowInnerMost) / para.modRow + 2;
257 if ( para.nRowsPlusOne < 1 ) {
258 ftfLog (
" =====> Error <===== \n" ) ;
259 ftfLog (
" Rows: Outer Most Inner Most %d % d \n",
260 para.rowOuterMost, para.rowInnerMost ) ;
263 para.nPhiPlusOne = para.nPhi + 1 ;
264 para.nEtaPlusOne = para.nEta + 1 ;
265 para.nPhiEtaPlusOne = para.nPhiPlusOne * para.nEtaPlusOne ;
266 if ( para.mergePrimaries ) {
267 para.nPhiTrackPlusOne = para.nPhiTrack + 1 ;
268 para.nEtaTrackPlusOne = para.nEtaTrack + 1 ;
272 if (volumeC != NULL)
delete []volumeC;
274 ftfLog (
"Allocating %d bytes of memory for volume\n",
277 para.nEtaPlusOne*
sizeof(VOLUME));
279 int nVolumes = para.nRowsPlusOne*para.nPhiPlusOne *
284 if ( rowC != NULL )
delete[] rowC ;
286 ftfLog (
"Allocating %d bytes of memory for rowC\n",
287 para.nRowsPlusOne*
sizeof(ROW));
292 if ( para.mergePrimaries ) {
293 if (trackC != NULL)
delete []trackC ;
295 ftfLog (stderr,
"Allocating %d bytes of memory for track_area\n",
296 para.nPhiTrackPlusOne*
297 para.nEtaTrackPlusOne*
sizeof(AREA));
299 int nTrackVolumes = para.nPhiTrackPlusOne*
300 para.nEtaTrackPlusOne ;
if(nTrackVolumes){}
301 trackC =
new FtfContainer[para.nPhiTrackPlusOne*para.nEtaTrackPlusOne];
306 phiDiff = para.phiMax - para.phiMin ;
307 if ( phiDiff > 2. * pi + 0.1 ) {
308 ftfLog (
"FtfFinder::reset: Wrong phi range %f, %f ",
309 para.phiMin*toDeg, para.phiMax*toDeg ) ;
312 if ( fabs(phiDiff-twoPi ) < pi / 36. ) para.phiClosed = 1 ;
318 para.phiSlice = (para.phiMax - para.phiMin)/para.nPhi ;
319 para.etaSlice = (para.etaMax - para.etaMin)/para.nEta ;
323 para.phiSliceTrack = (para.phiMaxTrack - para.phiMinTrack)/para.nPhiTrack;
324 para.etaSliceTrack = (para.etaMaxTrack - para.etaMinTrack)/para.nEtaTrack;
328 if ( para.xVertex != 0 || para.yVertex != 0 ) {
329 para.rVertex = (double)sqrt (para.xVertex*para.xVertex +
330 para.yVertex*para.yVertex) ;
331 para.phiVertex = (double)atan2(para.yVertex,para.xVertex);
335 para.phiVertex = 0.F ;
338 if ( para.dxVertex != 0 || para.dyVertex != 0 )
339 para.xyWeightVertex = 1. / ::sqrt(para.dxVertex*para.dxVertex+
340 para.dyVertex*para.dyVertex) ;
341 else para.xyWeightVertex = 1.0F ;
357 int FtfFinder::setConformalCoordinates ( )
363 double x, y, r2, invR2 ;
364 for (
int ihit = 0 ; ihit<nHits ; ihit++ )
369 thisHit = &(
hit[ihit]) ;
371 x = thisHit->x - para.xVertex ;
372 y = thisHit->y - para.yVertex ;
376 thisHit->xp = x * invR2 ;
377 thisHit->yp = - y * invR2 ;
378 thisHit->wxy = r2 * r2 / ( square(para.xyErrorScale)
379 * ( square(thisHit->dx) + square(thisHit->dy) ) ) ;
387 int FtfFinder::setPointers ( )
390 register int volumeIndex;
391 double r, r2, phi, eta ;
394 nHitsOutOfRange = 0 ;
397 memset ( rowC, 0, para.nRowsPlusOne*
sizeof(
FtfContainer) ) ;
398 int n = para.nRowsPlusOne*para.nEtaPlusOne*para.nPhiPlusOne ;
400 if ( para.mergePrimaries ){
401 memset ( trackC, 0, para.nPhiTrackPlusOne*
411 for ( ihit = 0 ; ihit<nHits ; ihit++ )
416 thisHit = &(
hit[ihit]) ;
417 localRow = thisHit->row - para.rowInnerMost ;
418 if ( fmod((
double)localRow,(
double)para.modRow) != 0 )
continue ;
420 if ( thisHit->row < para.rowInnerMost ) continue ;
421 if ( thisHit->row > para.rowOuterMost ) continue ;
425 localRow = localRow / para.modRow + 1 ;
432 cout <<
"SECTOR" <<
"," << thisHit->row <<
","
433 << (thisHit->buffer1>>6) <<
"," << (thisHit->buffer2>>6) <<
" --> "
434 <<
"( " << thisHit->x <<
"/ " << thisHit->y <<
"/ "
435 << thisHit->z <<
" )" << endl;
439 r2 = thisHit->x * thisHit->x + thisHit->y * thisHit->y ;
440 r = (double)sqrt ( r2 ) ;
441 phi = (double)atan2(thisHit->y,thisHit->x) + para.phiShift ;
442 if ( phi < 0 ) phi = phi + twoPi ;
444 eta = (double)seta(r,thisHit->z) ;
446 if ( para.szFitFlag ) {
448 thisHit->wz = (double)(1./ square ( para.szErrorScale * thisHit->dz ));
457 thisHit->nextVolumeHit =
458 thisHit->nextRowHit = 0 ;
463 thisHit->phiIndex = (int)( (thisHit->phi-para.phiMin)/para.phiSlice + 1.);
464 if ( thisHit->phiIndex < 1 || thisHit->phiIndex > para.nPhi ) {
465 if ( para.infoLevel > 2 ) {
466 ftfLog (
" === > Hit %d has Phi = %f \n", (
int)thisHit->id,
467 thisHit->phi*toDeg ) ;
468 ftfLog (
" Phi index %d out of range \n", thisHit->phiIndex ) ;
478 thisHit->etaIndex = (int)((thisHit->eta - para.etaMin)/para.etaSlice + 1.);
479 if ( thisHit->etaIndex < 1 || thisHit->etaIndex > para.nEta ) {
480 if ( para.infoLevel > 2 ) {
481 ftfLog(
" \n === > Hit %d has Eta = %f z %f ",
482 (
int)thisHit->id, thisHit->eta, thisHit->z ) ;
483 ftfLog (
" \n Eta min/max %f %f ", para.etaMin, para.etaMax ) ;
484 ftfLog (
" \n Eta slice %f ", para.etaSlice ) ;
485 ftfLog (
" \n Eta index %d out of range ", thisHit->etaIndex ) ;
493 thisHit->nextTrackHit = 0 ;
500 volumeIndex = localRow * para.nPhiEtaPlusOne +
501 thisHit->phiIndex * para.nEtaPlusOne + thisHit->etaIndex ;
504 if (volumeC[volumeIndex].first == 0 )
505 volumeC[volumeIndex].first = (
void *)thisHit ;
507 ((
FtfHit *)(volumeC[volumeIndex].last))->nextVolumeHit = thisHit ;
508 volumeC[volumeIndex].last = (
void *)thisHit ;
514 if ( rowC[localRow].first == NULL ){
515 rowC [localRow].first = (
void *)thisHit ;
518 ((
FtfHit *)(rowC[localRow].last))->nextRowHit = thisHit ;
519 rowC[localRow].last = (
void *)thisHit ;
530 double FtfFinder::CpuTime(
void ) {
531 return (
double)(clock()) / CLOCKS_PER_SEC;
536 double FtfFinder::RealTime (
void) {
537 const long nClicks = 400000000 ;
538 unsigned long eax, edx;
539 asm volatile(
"rdtsc":
"=a" (eax),
"=d" (edx));
540 double realTime = (double)(eax)/ nClicks;
544 double FtfFinder::RealTime (
void) {