297 {
298
299
300
301
302
303
304
305
306
309 cout << "Before pickHits";
310 if (is2d) cout<<" 2d:";
311 else cout<<" 3d:";
312 cout<< endl;
313 }
314
315 int nFound = 0;
316 int nCand = 0;
317 double rMin, rMax;
318 double rEnter, rExit;
320 int wireLow, wireHigh;
321 double phiLow, phiHigh;
322 int nCell;
325
326 double cellWidth;
327 double goodDriftCut;
328 double aresid = 0.;
329 int firstInputHit = -1;
330 int lCurl = 0;
331
332
335
338 assert (tkFit != 0);
340 assert (tkStatus != 0);
342 assert (hitList != 0);
344 double d0 = par.
d0();
345 double curv = 0.5 * par.
omega();
346 double sinPhi0 =
sin(par.
phi0());
347 double cosPhi0 =
cos(par.
phi0());
348
349
351 double absd0 = fabs(d0);
353
354 bool willCurl = false;
355 double rCurl = fabs(d0 + 1./curv);
357
358 if (rCurl < rMax) {
359 willCurl = true;
361 }
362
363 bool reachedLastInput = false;
364 bool hasCurled = false;
365
366
367 bool isHotOnLayer[43];
369 for(int ii=0; ii<43; ii++) isHotOnLayer[ii]=false;
371 isHotOnLayer[ihit->layerNumber()]=true;
372 }
373 }
374
375
376
378 layer = ((!lCurl) ? ( (hasCurled) ? gm->
prevLayer(layer) :
380
381
382 if (lCurl) {
383 lCurl = 0;
384 hasCurled = true;
385 }
386 if (tkStatus->
is2d() && layer->view() != 0)
continue;
387
389
390
391
392 bool lContinue = true;
394 if (layer == lastInputLayer) reachedLastInput = true;
395 }
396
397
398 if (hasCurled) {
399 rEnter = layer->rOut();
400 if (rEnter < rMin) {
401
402
403 break;
404 }
405 rExit = layer->rIn();
406 if (rExit < rMin) rExit = rMin;
407 if (rEnter > rMax) rEnter = rMax;
408
409
410
411 } else {
412 rEnter = layer->rIn();
413 rExit = layer->rOut();
414
415
416 if (rExit < rMin) continue;
417
418 if (willCurl) {
419 if (rEnter > rMax) {
420
421
422 hasCurled = 1;
423 continue;
424 }
425 if (rExit > rMax) {
426 lCurl = 1;
427 rExit = rMax;
428 }
429 } else {
430
431 if (rEnter > rMax) {
432
433 break;
434 }
435 if (rExit > rMax) rExit = rMax;
436 }
437 }
438
439 nCell = layer->nWires();
441
443
444 double deltaPhiCellWidth = 0.5 * (cellWidth * M_SQRT2)/layer->rMid();
445
446
448 int ierror = trk->
projectToR(rEnter, phiTemp, hasCurled);
449 phiEnter = phiTemp.
posRad();
450 if (ierror != 0) {
452 << "Error in MdcTrackList::pickHits projection, ierror " <<ierror<< std::endl;
453 continue;
454 }
455 ierror = trk->
projectToR(rExit, phiTemp, hasCurled);
456 phiExit = phiTemp.
posRad();
457 if (ierror != 0) {
459 << "Error in MdcTrackList::pickHits projection, ierror "<<ierror << std::endl;
460 continue;
461 }
462
463
465 std::cout<< endl<<"--pickHit of layer "<<layer->layNum()<<"--"<<std::endl;
466 std::cout<<
" track phiEnter "<< phiEnter.
deg()<<
" phiExit "<<phiExit.
deg()<<
" degree"<< std::endl;
469 std::cout<<
" goodDriftCut "<< goodDriftCut <<
"=sqrt(2)*0.5*"<<cellWidth<<
"+"<<
tkParam.
pickHitMargin<< std::endl;
470 }
471
473
474
475 double t_phiHit = -999.;
476 if (curv*Bz <= 0.0) {
477
478 phiLow = phiEnter;
479 phiHigh = phiExit;
480
483 } else {
484 phiLow = phiExit;
485 phiHigh = phiEnter;
488 }
489
490 if((phiHigh>0 && phiLow<0)){
492 }else if((phiHigh<0 && phiLow>0)){
494 }
495
496 double lowFloat = nCell /
Constants::twoPi * (phiLow - layer->phiOffset()) + 0.5;
497 double highFloat = nCell /
Constants::twoPi * (phiHigh - layer->phiOffset()) + 0.5;
498 wireLow = (lowFloat >= 0.0) ? int(lowFloat) : int(floor(lowFloat));
499 wireHigh = (highFloat >= 0.0) ? int(highFloat) : int(floor(highFloat));
500
502 std::cout <<
" wireLow "<<wireLow <<
" wireHigh "<<wireHigh <<
" phiLow "<<phiLow*180./
Constants::pi <<
" phiHigh "<<phiHigh*180./
Constants::pi << std::endl;
503 }
504
505 int tempDiff = 0;
508 if(wireLow>tempN/2. && wireHigh<tempN/2.){
510 tempDiff = wireHigh+tempN - wireLow +1;
511 }else{
513 tempDiff = wireHigh - wireLow +1;
514 }
515 }
516
517 if(wireLow>wireHigh) wireLow -= nCell;
518 long t_iHit = 0;
519 for (int thisWire = wireLow; thisWire <= wireHigh; thisWire++) {
521 thisHit = map->
hitWire(layer->layNum(), corrWire);
522
524 if(thisHit != 0) {cout<<endl<<
"test hit "; thisHit->
print(std::cout);}
525 else std::cout << endl<<"test hit ("<<layer->layNum()<<","<<corrWire<<")"<< std::endl;
526 }
527
528 double tof = 0.;
529 double z = 0.;
530 double driftDist = 0.;
531
532 double delx, dely;
533 double resid = 0., predDrift = 0.;
534 int ambig = 0;
536 double mcTkId = -9999;
537 if (thisHit == 0 ) {
538 delx = -d0 * sinPhi0 - layer->xWire(corrWire);
539 dely = d0 * cosPhi0 - layer->yWire(corrWire);
540 predDrift = cosPhi0 * dely - sinPhi0 * delx +
541 curv * (delx * delx + dely * dely);
542 if(6==
tkParam.
lPrint) cout<<
"No hit. predDrift="<<predDrift<<endl;
543 continue;
544 } else {
546
548 alink = 0;
549 }else{
552 }
553
554 if (alink == 0 || pickAm) {
555 if ((!tkStatus->
is2d()) && layer->view() != 0){
556 double rc = 9999.;
558 double rw = layer->rMid();
559 double alpha = acos(1 - rw*rw/(2*rc*rc));
560 double fltLen = rw;
561 if(fabs(1 - rw*rw/(2*rc*rc))<1) fltLen = rc *
alpha;
562 z = par.
z0() + fltLen* par.
tanDip();
564 double x = layer->getWire(corrWire)->xWireDC(z);
565 double y = layer->getWire(corrWire)->yWireDC(z);
566 delx = -d0 * sinPhi0 -
x;
567 dely = d0 * cosPhi0 -
y;
569 }else{
570 delx = -d0 * sinPhi0 - thisHit->
x();
571 dely = d0 * cosPhi0 - thisHit->
y();
573 }
574 predDrift = cosPhi0 * dely - sinPhi0 * delx +
575 curv * (delx * delx + dely * dely);
576
577
578 ambig = (predDrift >= 0) ? 1 : -1;
579 if (hasCurled) ambig = -ambig;
580 double entranceAngle=0.;
581 driftDist = thisHit->
driftDist(tof+bunchTime,ambig,entranceAngle,0.,z);
582 if (alink == 0) {
583
584 resid = ambig * fabs(driftDist) - predDrift;
585 aresid = fabs(resid);
586
587 }
588 } else {
589 ambig = alink->
ambig();
592 }
593 }
594
595
596 double zGuess = par.
z0() + layer->rMid() * par.
tanDip();
597 double phiDCz = layer->getWire(corrWire)->phiDC(zGuess);
598 BesAngle phiDCzMax(phiDCz + deltaPhiCellWidth);
599 BesAngle phiDCzMin(phiDCz - deltaPhiCellWidth);
600
603 if (thisHit != 0 &&alink==0) {
604 double entranceAngle = 0.;
605 sigma = thisHit->
sigma(driftDist, ambig, entranceAngle, atan(par.
tanDip()), z);
606 }
610 if(curv*Bz<=0.){
611
612 if((phiDCzMin-phiExit>0) || (phiDCzMax-phiEnter<0))
m_pickPhizOk[t_iHit] = 0;
614 }else{
615 if((phiDCzMin-phiEnter>0) || (phiDCzMax-phiExit<0))
m_pickPhizOk[t_iHit] = 0;
617 }
623 double t_phiLowCut=-999.;
624 double t_phiHighCut= -999.;
625 if(t_phiHit > -998.){
626 t_phiLowCut = (phiEnter-t_phiHit)*rEnter;
627 t_phiHighCut = (phiExit-t_phiHit)*rExit;
628 }
635 t_iHit++;
636 }
637
638 if(curv*Bz<=0.){
639
640 if((phiDCzMin-phiExit>0) || (phiDCzMax-phiEnter<0)) {
641 if(6==
tkParam.
lPrint){ std::cout<<
" CUT by phiDCz not in phi En Ex range, curv>=0"<<std::endl; }
642 continue;
643 }
644 }else{
645
646 if((phiDCzMin-phiEnter>0) || (phiDCzMax-phiExit<0)) {
647 if(6==
tkParam.
lPrint){ std::cout<<
" CUT by phiDCz not in phi En Ex range, curv<0"<<std::endl; }
648 continue;
649 }
650 }
651
652
653
654 if (ambig != 0 && fabs(predDrift) > goodDriftCut){
655 if(6==
tkParam.
lPrint){cout<<
" predDrift "<<predDrift<<
">goodDriftCut "<<goodDriftCut<<endl;}
656 continue;
657 }
658
659
660 if (ambig == 0 && fabs(predDrift) > goodDriftCut){
662 cout<<" ambig==0 && |predDirft| "<<fabs(predDrift) <<"> goodDriftCut "<< goodDriftCut<<endl;
663 cout<<" No good hit, but track near cell-edge " << endl;
664 }
665 continue;
666 }
667
668
669
670 if (ambig != 0) {
671
672
673 double entranceAngle = 0.;
674 double sigma = thisHit->
sigma(driftDist, ambig, entranceAngle, atan(par.
tanDip()), z);
676
677
679
680
681
682
683 if (alink == 0 && (aresid <= residCut) ) {
685 cout << " (2) New hit found " << endl;
686 }
687
688 int isActive = 1;
689
690
691
692
693
695 tempHot.setActivity(isActive);
696
698 tempHot.setUsability(false);
699 if(6==
tkParam.
lPrint) std::cout<<
" thisHit used, setUsability false " << std::endl;
700 }
701
702 double flt = layer->rMid();
704 flt += 0.000001 * (thisHit->
x() + thisHit->
y());
705 tempHot.setFltLen(flt);
708 std::cout<< " Append Hot " << std::endl;
709 }
711 }else{
713 if(alink!=0){
714 std::cout<< "Exist hot found"<<std::endl;
715 }else if(aresid > residCut){
716 thisHit->
print(std::cout);
718 }
719 }
720 }
721 if (!localHistory.member(
const_cast<MdcHitOnTrack*
>(alink))) {
724 nFound++;
725 if(6==
tkParam.
lPrint) std::cout<<
" nFound="<<nFound<<
" nCand "<<nCand<<std::endl;
726 if (layer == firstInputLayer && firstInputHit < 0) {
727 firstInputHit = nCand;
728 }
729 } else {
730 if(6==
tkParam.
lPrint) std::cout <<
"ErrMsg(warning) "<<
"would have inserted identical HOT "
731 "twice in history buffer" << std::endl;
732 }
733 }
734
735
736 else if (ambig == 0 && reachedLastInput) {
738 lContinue = false;
739 int nSuccess = 0;
740 int last = 8;
741 if (nCand < 8) last = nCand;
742 for (int i = 0; i < last; i++) {
743 int j = nCand - 1 - i;
744 if (localHistory[j] != 0) {
745
746 nSuccess++;
747 }
748 if (i == 2 && nSuccess >= 2) lContinue = true;
749 if (i == 4 && nSuccess >= 3) lContinue = true;
750 if (i == 7 && nSuccess >= 5) lContinue = true;
751 if(6==
tkParam.
lPrint) cout <<i<<
" (3) No hit found; if beyond known good region " << endl;
752 if (lContinue) {
753 if(6==
tkParam.
lPrint) std::cout<<
" pickHits break by lContinue. i="<<i<<
" nSuccess="<<nSuccess<< std::endl;
754 break;
755 }
756 }
757
758 if(6==
tkParam.
lPrint) cout <<
" (3) No hit found; if beyond known good region " << endl;
759
760 if (!lContinue) {
761
762 break;
763 }
764 localHistory.append(0);
765 }
766
767 nCand++;
768
769 if (ambig != 0 && reachedLastInput) {
773 }
774 }
775 else {
778 }
779 }
780 }
781
782 }
789 }
790 if (!lContinue && reachedLastInput) {
791
792 break;
793 }
794 }
795
796
797 bool lContinue = true;
798 for (int ihit = firstInputHit; ihit >= 0; ihit--) {
799 if (localHistory[ihit] != 0) {
800 if (lContinue) {
801
802 const MdcHitOnTrack *mdcHit = localHistory[ihit]->mdcHitOnTrack();
803 if (mdcHit != 0) {
806 }
807 }
808 continue;
809 } else {
810
812 std::cout << " gap found; delete hits. ";
813 }
814 if (!localHistory[ihit]->isUsable()) {
816 cout << "about to delete hit for unusable HOT:" << endl;
817 localHistory[ihit]->print(std::cout);
818 }
819 hitList->
removeHit(localHistory[ihit]->hit());
820 }
822 cout << " current contents of localHistory: "
823 <<localHistory.length()<<"hot" << endl;
824
825
826
827 }
828 nFound--;
829 }
830 }
831 else if (localHistory[ihit] == 0) {
832 if(6==
tkParam.
lPrint){ cout <<
" localHistory= 0 " << endl; }
833 int nSuccess = 0;
834 lContinue = false;
835 int last = 8;
836 if (nCand < 8) last = nCand;
837 for (int i = 0; i < last; i++) {
838 int j = ihit + 1 + i;
839 if (localHistory[j] != 0) nSuccess++;
840 if (i == 2 && nSuccess >= 2) lContinue = true;
841 if (i == 4 && nSuccess >= 3) lContinue = true;
842
843 if (lContinue) break;
844 }
845 }
846 }
849 }
851 if(6==
tkParam.
lPrint){ cout <<
" localHistory= 0 " << endl; }
852
854 cout << "After pickHits found " << nFound <<" hit(s)"<< endl;
856 std::cout<< std::endl;
857 }
858
859 return nFound;
860}
double sin(const BesAngle a)
double cos(const BesAngle a)
NTuple::Array< long > m_pickIs2D
NTuple::Array< double > m_pickPt
NTuple::Item< long > m_pickLayer
NTuple::Array< long > m_pickMcTk
AIDA::IHistogram1D * g_pickHitWire
NTuple::Item< long > m_pickNCellWithDigi
NTuple::Array< double > m_pickPhiLowCut
double haveDigiDrift[43][288]
NTuple::Array< double > m_pickDriftCut
NTuple::Array< double > m_pickCurv
NTuple::Array< double > m_pickDrift
NTuple::Array< double > m_pickResid
NTuple::Array< int > m_pickPhizOk
NTuple::Array< double > m_pickSigma
NTuple::Array< long > m_pickWire
NTuple::Tuple * m_tuplePick
NTuple::Array< double > m_pickDriftTruth
NTuple::Array< double > m_pickZ
NTuple::Array< double > m_pickPredDrift
NTuple::Item< long > m_pickNCell
NTuple::Array< double > m_pickPhiHighCut
static const double twoPi
static const int maxCell[43]
static const double radToDegrees
const MdcLayer * prevLayer(int lay) const
const MdcLayer * lastLayer() const
const MdcLayer * firstLayer() const
const MdcLayer * nextLayer(int lay) const
MdcHit * hitWire(int lay, int wire) const
const MdcLayer * layer() const
const MdcDigi * digi() const
void print(std::ostream &o) const
double sigma(double, int, double, double, double) const
double driftDist(double, int, double, double, double) const
const MdcLayer * layer() const
void setFirstLayer(const MdcLayer *l)
int projectToR(double radius, BesAngle &phiIntersect, int lCurl=0) const
void setHasCurled(bool c=true)
const MdcLayer * firstLayer() const
const MdcLayer * lastLayer() const
void setLastLayer(const MdcLayer *l)
int getTrackIndex() const
const TrkHitOnTrk * getHitOnTrack(const TrkRecoTrk *trk) const
hot_iterator begin() const
TrkHitOnTrk * appendHot(const TrkHitOnTrk *theHot)
bool removeHit(const TrkFundHit *theHit)
void print(std::ostream &o) const
const BField & bField() const
int mdcWrapWire(int wireIn, int nCell)