117#ifdef MDCPATREC_TIMETEST
118 TAU_PROFILE_TIMER( timer8,
"fill ax seg",
"int ()", TAU_DEFAULT );
119 TAU_PROFILE_START( timer8 );
125#ifdef MDCPATREC_TIMETEST
126 TAU_PROFILE_STOP( timer8 );
129 bool goodOnly =
true;
130 bool useBad = ( segs->
count() < 400 );
137 seed = segs->
getSeed( 0, goodOnly );
138 if ( seed == 0 && goodOnly && useBad )
144 else if ( seed == 0 && ( !goodOnly || !useBad ) ) {
break; }
146 if ( 3 == m_debug )
dumpSeed( seed, goodOnly );
155#ifdef MDCPATREC_TIMETEST
156 TAU_PROFILE_TIMER( timer3,
"combine ax seg",
"int ()", TAU_DEFAULT );
157 TAU_PROFILE_START( timer3 );
161#ifdef MDCPATREC_TIMETEST
162 TAU_PROFILE_STOP( timer3 );
167 cout <<
" ***** Ax.combineSegs success? " << success <<
"\n";
170 if ( !success )
continue;
173#ifdef MDCPATREC_TIMETEST
174 TAU_PROFILE_TIMER( timer4,
"circle fitting",
"int ()", TAU_DEFAULT );
175 TAU_PROFILE_START( timer4 );
178#ifdef MDCPATREC_TIMETEST
179 TAU_PROFILE_STOP( timer4 );
184 cout <<
"finishCircle success? " << success <<
"\n";
188 if ( !success )
continue;
191 assert( tkFit != 0 );
203 cout << __FILE__ <<
" Killing track by d0:" << par.
d0() <<
">" <<
m_d0Cut << endl;
211 cout << __FILE__ <<
" Killing track by pt:" << tkFit->
pt( 0. ) <<
"<" <<
m_ptCut
217 if ( 3 <= m_debug ) std::cout <<
" *** End r-phi track-finding " << std::endl;
220#ifdef MDCPATREC_TIMETEST
221 TAU_PROFILE_TIMER( timer5,
"fill st seg",
"int ()", TAU_DEFAULT );
222 TAU_PROFILE_START( timer5 );
225#ifdef MDCPATREC_TIMETEST
226 TAU_PROFILE_STOP( timer5 );
231 std::cout << std::endl <<
"----------------------------------------" << std::endl;
232 std::cout <<
" Segment list after St.fillWithSegs " << std::endl;
236#ifdef MDCPATREC_TIMETEST
237 TAU_PROFILE_TIMER( timer6,
"combine st seg",
"int ()", TAU_DEFAULT );
238 TAU_PROFILE_START( timer6 );
240 success = stereoSegs.
combineSegs( trialTrack, 0, context, bunchTime,
tkParam.maxSegChisqO,
242#ifdef MDCPATREC_TIMETEST
243 TAU_PROFILE_STOP( timer6 );
248 cout <<
" ***** St.combineSegs success? " << success <<
"\n";
255#ifdef MDCPATREC_TIMETEST
256 TAU_PROFILE_TIMER( timer7,
"helix fitting",
"int ()", TAU_DEFAULT );
257 TAU_PROFILE_START( timer7 );
260#ifdef MDCPATREC_TIMETEST
261 TAU_PROFILE_STOP( timer7 );
265 if ( 3 == m_debug ) {
dumpHelix( trialTrack ); }
266 if ( !success )
continue;
275 cout << __FILE__ <<
" Killing track by d0 after 3d fit:" << d0par <<
">" <<
m_d0Cut
285 { cout << __FILE__ <<
" Killing track by z0:" << z0par <<
">" <<
m_z0Cut << endl; }
290 append( trialTrack );
294 if ( 3 == m_debug ) std::cout <<
" ***** End one track-finding *****" << std::endl;
316 cout <<
"Before pickHits";
317 if ( is2d ) cout <<
" 2d:";
325 double rEnter, rExit;
327 int wireLow, wireHigh;
328 double phiLow, phiHigh;
337 int firstInputHit = -1;
346 assert( tkFit != 0 );
348 assert( tkStatus != 0 );
350 assert( hitList != 0 );
352 double d0 = par.
d0();
353 double curv = 0.5 * par.
omega();
354 double sinPhi0 =
sin( par.
phi0() );
355 double cosPhi0 =
cos( par.
phi0() );
359 double absd0 = fabs( d0 );
362 bool willCurl =
false;
363 double rCurl = fabs( d0 + 1. / curv );
372 bool reachedLastInput =
false;
373 bool hasCurled =
false;
376 bool isHotOnLayer[43];
377 if (
tkParam.pickSkipExistLayer )
379 for (
int ii = 0; ii < 43; ii++ ) isHotOnLayer[ii] =
false;
381 { isHotOnLayer[ihit->layerNumber()] =
true; }
397 if ( tkStatus->
is2d() && layer->view() != 0 )
continue;
399 if (
tkParam.pickSkipExistLayer && isHotOnLayer[layer->layNum()] )
404 bool lContinue =
true;
405 if (
tkParam.pickUitlLastLayer )
407 if ( layer == lastInputLayer ) reachedLastInput =
true;
413 rEnter = layer->rOut();
420 rExit = layer->rIn();
421 if ( rExit < rMin ) rExit = rMin;
422 if ( rEnter > rMax ) rEnter = rMax;
429 rEnter = layer->rIn();
430 rExit = layer->rOut();
433 if ( rExit < rMin )
continue;
458 if ( rExit > rMax ) rExit = rMax;
462 nCell = layer->nWires();
465 goodDriftCut = 0.5 * cellWidth * M_SQRT2 +
tkParam.pickHitMargin;
467 double deltaPhiCellWidth = 0.5 * ( cellWidth * M_SQRT2 ) / layer->rMid();
471 int ierror = trk->
projectToR( rEnter, phiTemp, hasCurled );
472 phiEnter = phiTemp.
posRad();
476 std::cout <<
" ErrMsg(warning) "
477 <<
"Error in MdcTrackList::pickHits projection, ierror " << ierror
481 ierror = trk->
projectToR( rExit, phiTemp, hasCurled );
482 phiExit = phiTemp.
posRad();
486 std::cout <<
" ErrMsg(warning) "
487 <<
"Error in MdcTrackList::pickHits projection, ierror " << ierror
494 std::cout << endl <<
"--pickHit of layer " << layer->layNum() <<
"--" << std::endl;
495 std::cout <<
" track phiEnter " << phiEnter.
deg() <<
" phiExit " << phiExit.
deg()
496 <<
" degree" << std::endl;
497 std::cout <<
" cell width " << 360. / layer->nWires() <<
" dPhiz "
501 std::cout <<
" maxInactiveResid " <<
tkParam.maxInactiveResid <<
" pickHitPhiFactor "
502 <<
tkParam.pickHitPhiFactor << std::endl;
503 std::cout <<
" goodDriftCut " << goodDriftCut <<
"=sqrt(2)*0.5*" << cellWidth <<
"+"
504 <<
tkParam.pickHitMargin << std::endl;
510 double t_phiHit = -999.;
511 if ( curv * Bz <= 0.0 )
517 phiLow -=
tkParam.maxInactiveResid / rEnter;
518 phiHigh +=
tkParam.maxInactiveResid / rExit;
524 phiLow -=
tkParam.maxInactiveResid / rExit;
525 phiHigh +=
tkParam.maxInactiveResid / rEnter;
531 double lowFloat = nCell /
Constants::twoPi * ( phiLow - layer->phiOffset() ) + 0.5;
532 double highFloat = nCell /
Constants::twoPi * ( phiHigh - layer->phiOffset() ) + 0.5;
533 wireLow = ( lowFloat >= 0.0 ) ?
int( lowFloat ) : int( floor( lowFloat ) );
534 wireHigh = ( highFloat >= 0.0 ) ?
int( highFloat ) : int( floor( highFloat ) );
538 std::cout <<
" wireLow " << wireLow <<
" wireHigh " << wireHigh <<
" phiLow "
547 if ( wireLow > tempN / 2. && wireHigh < tempN / 2. )
550 tempDiff = wireHigh + tempN - wireLow + 1;
555 tempDiff = wireHigh - wireLow + 1;
559 if ( wireLow > wireHigh ) wireLow -= nCell;
561 for (
int thisWire = wireLow; thisWire <= wireHigh; thisWire++ )
564 thisHit =
map->hitWire( layer->layNum(), corrWire );
570 cout << endl <<
"test hit ";
571 thisHit->
print( std::cout );
575 <<
"test hit (" << layer->layNum() <<
"," << corrWire <<
")" << std::endl;
580 double driftDist = 0.;
583 double resid = 0., predDrift = 0.;
586 double mcTkId = -9999;
589 delx = -d0 * sinPhi0 - layer->xWire( corrWire );
590 dely = d0 * cosPhi0 - layer->yWire( corrWire );
591 predDrift = cosPhi0 * dely - sinPhi0 * delx + curv * ( delx * delx + dely * dely );
592 if ( 6 ==
tkParam.lPrint ) cout <<
"No hit. predDrift=" << predDrift << endl;
606 if ( 6 ==
tkParam.lPrint ) { cout <<
" existing hot; "; }
609 if ( alink == 0 || pickAm )
611 if ( ( !tkStatus->
is2d() ) && layer->view() != 0 )
615 double rw = layer->rMid();
616 double alpha = acos( 1 - rw * rw / ( 2 * rc * rc ) );
618 if ( fabs( 1 - rw * rw / ( 2 * rc * rc ) ) < 1 ) fltLen = rc *
alpha;
619 z = par.
z0() + fltLen * par.
tanDip();
621 double x = layer->getWire( corrWire )->xWireDC( z );
622 double y = layer->getWire( corrWire )->yWireDC( z );
623 delx = -d0 * sinPhi0 - x;
624 dely = d0 * cosPhi0 - y;
629 delx = -d0 * sinPhi0 - thisHit->
x();
630 dely = d0 * cosPhi0 - thisHit->
y();
633 predDrift = cosPhi0 * dely - sinPhi0 * delx + curv * ( delx * delx + dely * dely );
636 ambig = ( predDrift >= 0 ) ? 1 : -1;
637 if ( hasCurled ) ambig = -ambig;
638 double entranceAngle = 0.;
639 driftDist = thisHit->
driftDist( tof + bunchTime, ambig, entranceAngle, 0., z );
643 resid = ambig * fabs( driftDist ) - predDrift;
644 aresid = fabs( resid );
650 ambig = alink->
ambig();
651 if ( 6 ==
tkParam.lPrint ) cout <<
" pick ambig for hot" << endl;
657 double zGuess = par.
z0() + layer->rMid() * par.
tanDip();
658 double phiDCz = layer->getWire( corrWire )->phiDC( zGuess );
659 BesAngle phiDCzMax( phiDCz + deltaPhiCellWidth );
660 BesAngle phiDCzMin( phiDCz - deltaPhiCellWidth );
665 if ( thisHit != 0 && alink == 0 )
667 double entranceAngle = 0.;
668 sigma = thisHit->
sigma( driftDist, ambig, entranceAngle, atan( par.
tanDip() ), z );
674 if ( curv * Bz <= 0. )
677 if ( ( phiDCzMin - phiExit > 0 ) || ( phiDCzMax - phiEnter < 0 ) )
683 if ( ( phiDCzMin - phiEnter > 0 ) || ( phiDCzMax - phiExit < 0 ) )
692 double t_phiLowCut = -999.;
693 double t_phiHighCut = -999.;
694 if ( t_phiHit > -998. )
696 t_phiLowCut = ( phiEnter - t_phiHit ) * rEnter;
697 t_phiHighCut = ( phiExit - t_phiHit ) * rExit;
708 if ( curv * Bz <= 0. )
711 if ( ( phiDCzMin - phiExit > 0 ) || ( phiDCzMax - phiEnter < 0 ) )
714 { std::cout <<
" CUT by phiDCz not in phi En Ex range, curv>=0" << std::endl; }
721 if ( ( phiDCzMin - phiEnter > 0 ) || ( phiDCzMax - phiExit < 0 ) )
724 { std::cout <<
" CUT by phiDCz not in phi En Ex range, curv<0" << std::endl; }
731 if ( ambig != 0 && fabs( predDrift ) > goodDriftCut )
734 { cout <<
" predDrift " << predDrift <<
">goodDriftCut " << goodDriftCut << endl; }
739 if ( ambig == 0 && fabs( predDrift ) > goodDriftCut )
743 cout <<
" ambig==0 && |predDirft| " << fabs( predDrift ) <<
"> goodDriftCut "
744 << goodDriftCut << endl;
745 cout <<
" No good hit, but track near cell-edge " << endl;
755 double entranceAngle = 0.;
757 thisHit->
sigma( driftDist, ambig, entranceAngle, atan( par.
tanDip() ), z );
758 double factor =
tkParam.pickHitFactor;
761 double residCut =
tkParam.maxActiveSigma * factor * sigma;
768 if ( alink == 0 && ( aresid <= residCut ) )
772 cout <<
" (2) New hit found " << endl;
788 std::cout <<
" thisHit used, setUsability false " << std::endl;
791 double flt = layer->rMid();
793 flt += 0.000001 * ( thisHit->
x() + thisHit->
y() );
797 std::cout <<
" aresid " << aresid <<
"<=residCut " << residCut <<
" nSig "
798 << aresid / sigma <<
" nSigCut " << (
tkParam.maxActiveSigma * factor )
799 <<
" factor " << factor <<
" maxActiveSigma " <<
tkParam.maxActiveSigma
800 <<
" tanDip " << par.
tanDip() << std::endl;
801 std::cout <<
" Append Hot " << std::endl;
809 if ( alink != 0 ) { std::cout <<
"Exist hot found" << std::endl; }
810 else if ( aresid > residCut )
812 thisHit->
print( std::cout );
813 std::cout <<
" Drop hit. aresid " << aresid <<
">residCut " << residCut
814 <<
" nSig " << aresid / sigma <<
" nSigCut "
815 << (
tkParam.maxActiveSigma * factor ) <<
" factor " << factor
816 <<
" maxActiveSigma " <<
tkParam.maxActiveSigma <<
" tanDip "
817 << par.
tanDip() << std::endl;
821 if ( !localHistory.member(
const_cast<MdcHitOnTrack*
>( alink ) ) )
827 std::cout <<
" nFound=" << nFound <<
" nCand " << nCand << std::endl;
828 if ( layer == firstInputLayer && firstInputHit < 0 ) { firstInputHit = nCand; }
833 std::cout <<
"ErrMsg(warning) "
834 <<
"would have inserted identical HOT "
835 "twice in history buffer"
841 else if ( ambig == 0 && reachedLastInput )
843 if ( 6 ==
tkParam.lPrint ) std::cout <<
"ambig==0 " << std::endl;
847 if ( nCand < 8 ) last = nCand;
848 for (
int i = 0; i < last; i++ )
850 int j = nCand - 1 - i;
851 if ( localHistory[j] != 0 )
856 if ( i == 2 && nSuccess >= 2 ) lContinue =
true;
857 if ( i == 4 && nSuccess >= 3 ) lContinue =
true;
858 if ( i == 7 && nSuccess >= 5 ) lContinue =
true;
860 cout << i <<
" (3) No hit found; if beyond known good region "
865 std::cout <<
" pickHits break by lContinue. i=" << i <<
" nSuccess=" << nSuccess
872 cout <<
" (3) No hit found; if beyond known good region " << endl;
879 localHistory.append( 0 );
884 if ( ambig != 0 && reachedLastInput )
907 if ( !lContinue && reachedLastInput )
915 bool lContinue =
true;
916 for (
int ihit = firstInputHit; ihit >= 0; ihit-- )
918 if ( localHistory[ihit] != 0 )
923 const MdcHitOnTrack* mdcHit = localHistory[ihit]->mdcHitOnTrack();
934 if ( 6 ==
tkParam.lPrint ) { std::cout <<
" gap found; delete hits. "; }
935 if ( !localHistory[ihit]->isUsable() )
939 cout <<
"about to delete hit for unusable HOT:" << endl;
940 localHistory[ihit]->print( std::cout );
942 hitList->
removeHit( localHistory[ihit]->hit() );
946 cout <<
" current contents of localHistory: " << localHistory.length() <<
"hot"
956 else if ( localHistory[ihit] == 0 )
958 if ( 6 ==
tkParam.lPrint ) { cout <<
" localHistory= 0 " << endl; }
962 if ( nCand < 8 ) last = nCand;
963 for (
int i = 0; i < last; i++ )
965 int j = ihit + 1 + i;
966 if ( localHistory[j] != 0 ) nSuccess++;
967 if ( i == 2 && nSuccess >= 2 ) lContinue =
true;
968 if ( i == 4 && nSuccess >= 3 ) lContinue =
true;
970 if ( lContinue )
break;
976 std::cout <<
"nFound=" << nFound <<
" < " <<
tkParam.pickHitFract * nCand
977 <<
" pickHitFract? " <<
tkParam.pickHitFract <<
"*" << nCand << std::endl;
979 if ( nFound <
tkParam.pickHitFract * nCand )
981 if ( 6 ==
tkParam.lPrint ) { cout <<
" localHistory= 0 " << endl; }
985 cout <<
"After pickHits found " << nFound <<
" hit(s)" << endl;
987 std::cout << std::endl;