317 {
318
319 cout.precision(6);
320 MsgStream log(
msgSvc(), name());
321 log << MSG::INFO << "in execute()" << endreq;
322
323
324 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
325 if (!evTimeCol) {
326 log << MSG::WARNING<< "Could not retrieve RecEsTimeCol , use t0=0" << endreq;
327 m_bunchT0=0.;
328 }else{
329 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
330 if (iter_evt != evTimeCol->end()){
331 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;
332 }
333 }
334
335
336 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
337 if (!eventHeader) {
338 log << MSG::FATAL << "Could not find Event Header" << endreq;
339 return( StatusCode::FAILURE);
340 }
341
342 DataObject *aTrackCol;
343 DataObject *aRecHitCol;
344 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
345 if(!m_combineTracking){
346 eventSvc()->findObject("/Event/Recon/RecMdcTrackCol",aTrackCol);
347 if(aTrackCol != NULL) {
348 dataManSvc->clearSubTree("/Event/Recon/RecMdcTrackCol");
349 eventSvc()->unregisterObject("/Event/Recon/RecMdcTrackCol");
350 }
351 eventSvc()->findObject("/Event/Recon/RecMdcHitCol",aRecHitCol);
352 if(aRecHitCol != NULL) {
353 dataManSvc->clearSubTree("/Event/Recon/RecMdcHitCol");
354 eventSvc()->unregisterObject("/Event/Recon/RecMdcHitCol");
355 }
356 }
357
359 eventSvc()->findObject("/Event/Recon/RecMdcTrackCol",aTrackCol);
360 if (aTrackCol) {
362 }else{
365 if(!sc.isSuccess()) {
366 log << MSG::FATAL << " Could not register RecMdcTrack collection" <<endreq;
367 return StatusCode::FAILURE;
368 }
369 }
370
372 eventSvc()->findObject("/Event/Recon/RecMdcHitCol",aRecHitCol);
373 if (aRecHitCol) {
375 }else{
378 if(!sc.isSuccess()) {
379 log << MSG::FATAL << " Could not register RecMdcHit collection" <<endreq;
380 return StatusCode::FAILURE;
381 }
382 }
383
384
385 if(m_removeBadTrack) {
386 vector<RecMdcTrack*> vec_trackList;
387 if( m_debug>0 ) cout<<"PATTSF collect "<<trackList->size()<<" track. "<<endl;
388 if(trackList->size()!=0){
389 RecMdcTrackCol::iterator iter_pat = trackList->begin();
390 for(;iter_pat!=trackList->end();iter_pat++){
391 double d0=(*iter_pat)->helix(0);
392 double kap = (*iter_pat)->helix(2);
393 double pt = 0.00001;
394 if(fabs(kap)>0.00001) pt = fabs(1./kap);
395 double dz=(*iter_pat)->helix(4);
396 double chi2=(*iter_pat)->chi2();
397 if( m_debug>0) cout<<"d0: "<<d0<<" z0: "<<dz<<" pt "<<pt<<" chi2 "<<chi2<<endl;
398 if(fabs(d0)>m_dropTrkDrCut || fabs(dz)>m_dropTrkDzCut || chi2>m_dropTrkChi2Cut || pt>m_dropTrkPtCut) {
399 vec_trackList.push_back(*iter_pat);
400
401 HitRefVec rechits = (*iter_pat)->getVecHits();
402 HitRefVec::iterator hotIter = rechits.begin();
403 while (hotIter!=rechits.end()) {
404 if(m_debug>0) cout <<"remove hit " << (*hotIter)->getId() <<endl;
405 hitList->remove(*hotIter);
406 hotIter++;
407 }
408 trackList->remove(*iter_pat);
409 iter_pat--;
410 }
411
412 }
413 } else {
414 if(m_debug>0) cout<<" PATTSF find 0 track. "<<endl;
415 }
416 }
417
418 int nTdsTk=trackList->size();
419
420
421 t_eventNum=eventHeader->eventNumber();
422 t_runNum=eventHeader->runNumber();
423 if( m_drawTuple ){
424 m_eventNum=t_eventNum;
425 m_runNum=t_runNum;
426 }
427 if(m_debug>0) cout<<" begin event :"<<t_eventNum<<endl;
428 if(t_eventNum<=m_eventcut) {
429 cout<<" eventNum cut "<<t_eventNum<<endl;
430 return StatusCode::SUCCESS;
431 }
432 log << MSG::INFO << "HoughValidUpdate: retrieved event: " << eventHeader->eventNumber() << " run: " << eventHeader->runNumber() << endreq;
433
434 vector<double> vec_u;
435 vector<double> vec_v;
436 vector<double> vec_p;
437 vector<double> vec_x_east;
438 vector<double> vec_y_east;
439 vector<double> vec_z_east;
440 vector<double> vec_x_west;
441 vector<double> vec_y_west;
442 vector<double> vec_z_west;
443 vector<double> vec_z_Mc;
444 vector<double> vec_x;
445 vector<double> vec_y;
446 vector<double> vec_z;
447 vector<int> vec_layer;
448 vector<int> vec_wire;
449 vector<int> vec_slant;
450 vector<double> vec_zStereo;
451 vector<double> l;
452
453 vector<int> vec_layer_Mc;
454 vector<int> vec_wire_Mc;
455 vector<int> vec_hit_Mc;
456 vector<double> vec_ztruth_Mc;
457 vector<double> vec_flt_truth_mc;
458 vector<double> vec_pos_flag;
459 vector<double> vec_phit_MC;
460
461
462 int mc_particle=GetMcInfo();
463 if(m_debug>2) cout<<"MC particle : "<<mc_particle<<endl;
464
465
466 if(m_fillTruth ==1 && m_useMcInfo) {
467 int digiId_Mc=0;
468 int nHitAxial_Mc=0;
469 SmartDataPtr<Event::MdcMcHitCol> mcMdcMcHitCol(eventSvc(),"/Event/MC/MdcMcHitCol");
470 if (!mcMdcMcHitCol) {
471 log << MSG::INFO << "Could not find MdcMcHit" << endreq;
472 }else{
473 Event::MdcMcHitCol::iterator iterMcHit = mcMdcMcHitCol->begin();
474
475 for(; iterMcHit != mcMdcMcHitCol->end(); ++iterMcHit,digiId_Mc++) {
479 double hittemp=layerId_Mc*1000+wireId_Mc;
480 double mc_hit_distance =(*iterMcHit)->getDriftDistance();
481 double z_mc = (*iterMcHit)->getPositionZ()/10.;
482 double flt_truth=(z_mc-dz_mc)/tanl_mc;
483 double pos_flag=(*iterMcHit)->getPositionFlag();
484
485
486 if( (*iterMcHit)->getPositionFlag()==-999 ){
487
488 double px= (*iterMcHit)->getPositionX();
489 double py= (*iterMcHit)->getPositionY();
490 double pz= (*iterMcHit)->getPositionZ();
491 double pxyz = sqrt(px*px+py*py+pz*pz);
492 vec_phit_MC.push_back(pxyz);
493
494
495
496
497
498
499 }
500
501
502 vec_layer_Mc.push_back(layerId_Mc);
503 vec_wire_Mc.push_back(wireId_Mc);
504 vec_hit_Mc.push_back(hittemp);
505 vec_ztruth_Mc.push_back(z_mc);
506 vec_flt_truth_mc.push_back(flt_truth);
507 vec_pos_flag.push_back(pos_flag);
508
509 if(m_debug>5) {
510 cout<<"(" <<layerId_Mc<<","<<wireId_Mc<<"):"<<endl;
511 cout<<" hit_distance : "<<mc_hit_distance<<endl;
512 cout<<" position flag : "<<pos_flag<<endl;
513 cout<<" hit_z_mc : "<<z_mc<<endl;
514 cout<<" flt_truth : "<<flt_truth<<endl;
515 }
516
517 if(m_data==0){
518 if ((layerId_Mc>=8&&layerId_Mc<=19)||(layerId_Mc>=36)) {
519 nHitAxial_Mc++;}
520 const MdcGeoWire *geowir =m_mdcGeomSvc->
Wire(layerId_Mc,wireId_Mc);
523
524 double x = (*iterMcHit)->getPositionX()/10.;
525 double y = (*iterMcHit)->getPositionY()/10.;
526 double z = (*iterMcHit)->getPositionZ()/10.;
527 double u=CFtrans(x,y);
528 double v=CFtrans(y,x);
529 double p=sqrt(u*u+
v*
v);
530
531 vec_x_east.push_back(eastP.x());
532 vec_y_east.push_back(eastP.y());
533 vec_z_east.push_back(eastP.z());
534 vec_x_west.push_back(westP.x());
535 vec_y_west.push_back(westP.y());
536 vec_z_west.push_back(westP.z());
537 vec_x.push_back(x);
538 vec_y.push_back(y);
539 vec_z.push_back(z);
540 vec_u.push_back(u);
542 vec_p.push_back(p);
543 vec_slant.push_back( SlantId(layerId_Mc) );
544
545 m_x_east[digiId_Mc]=eastP.x();
546 m_y_east[digiId_Mc]=eastP.y();
547 m_z_east[digiId_Mc]=eastP.z();
548 m_x_west[digiId_Mc]=westP.x();
549 m_y_west[digiId_Mc]=westP.y();
550 m_z_west[digiId_Mc]=westP.z();
551 m_layer[digiId_Mc]=layerId_Mc;
552 m_cell[digiId_Mc]=wireId_Mc;
554 m_y[digiId_Mc]=y;
555 m_z[digiId_Mc]=z;
556 m_u[digiId_Mc]=u;
558 m_p[digiId_Mc]=p;
559 m_slant[digiId_Mc]=SlantId(layerId_Mc);
560 }
561 }
562 }
563 m_nHit_Mc=digiId_Mc;
564 m_nHitAxial_Mc=nHitAxial_Mc;
565 if(0==m_data) {m_nHit=digiId_Mc; m_nHitAxial=nHitAxial_Mc;}
566 }
567
568
569 vector<int> vec_hit;
570 vector<int> vec_track_index;
571 set<int> hit_noise;
572 uint32_t getDigiFlag = 0;
576
578 if(m_debug>0) cout<<"MdcDigiVec: "<<mdcDigiVec.size()<<endl;
579 MdcDigiVec::iterator iter1 = mdcDigiVec.begin();
580 int digiId = 0;
581 int nHitAxial = 0;
582 for (;iter1 != mdcDigiVec.end(); iter1++, digiId++) {
586 double hittemp=layerId*1000+wireId;
590 if ((layerId>=8&&layerId<=19)||(layerId>=36)) nHitAxial++;
591
592 int track_index=(*iter1)->getTrackIndex();
593 if( track_index>=1000 ) track_index-=1000;
594 if( track_index<0 ) hit_noise.insert(hittemp);
595 int tchannal=(*iter1)->getTimeChannel();
596 int qchannal=(*iter1)->getChargeChannel();
597 if( tchannal!=qchannal && m_debug>0 ) cout<<"("<<layerId<<","<<wireId<<")"<< 0<<endl;
598 if( m_debug>3 ) cout<<"track_index in digi: "<<"("<<layerId<<","<<wireId<<" "<< track_index<<endl;
599 if( m_debug>3 ) cout<<"event: "<<t_eventNum<<" "<<"layer: "<<layerId<<" "<<"wireId: "<<wireId<<" "<<"zeast: "<<eastP.z()<<" "<<"zwest: "<<westP.z()<<" "<<endl;
600
601
602 double x =(eastP.x()+westP.x())/2.;
603 double y =(eastP.y()+westP.y())/2.;
604 double u=CFtrans(x,y);
605 double v=CFtrans(y,x);
606 if(m_debug>3) cout<<
"digiId: "<<digiId<<
" layer: "<<layerId<<
" "<<
"wireId: "<<wireId<<
" "<<
"x: "<<
x<<
" "<<
"y: "<<y<<
" "<<
"u: "<<u<<
"v: "<<
v<<endl;
607
608 vec_track_index.push_back(track_index);
609 vec_layer.push_back(layerId);
610 vec_wire.push_back(wireId);
611 vec_hit.push_back(hittemp);
612 vec_x_east.push_back(eastP.x());
613 vec_y_east.push_back(eastP.y());
614 vec_z_east.push_back(eastP.z());
615 vec_x_west.push_back(westP.x());
616 vec_y_west.push_back(westP.y());
617 vec_z_west.push_back(westP.z());
618 vec_x.push_back(x);
619 vec_y.push_back(y);
620 vec_p.push_back(sqrt(u*u+
v*
v));
621 vec_u.push_back(u);
623 vec_slant.push_back( SlantId(layerId) );
624
625 if(m_drawTuple){
626 m_x_east[digiId]=eastP.x();
627 m_y_east[digiId]=eastP.y();
628 m_z_east[digiId]=eastP.z();
629 m_x_west[digiId]=westP.x();
630 m_y_west[digiId]=westP.y();
631 m_z_west[digiId]=westP.z();
632 m_layer[digiId]=layerId;
633 m_cell[digiId]=wireId;
634 m_x[digiId]=(vec_x_east[digiId]+vec_x_west[digiId])/2;
635 m_y[digiId]=(vec_y_east[digiId]+vec_y_west[digiId])/2;
636 m_u[digiId]=u;
638 m_p[digiId]=sqrt(u*u+
v*
v);
639 m_slant[digiId]=SlantId( layerId );
640 m_layerNhit[layerId]++;
641 }
642 }
643 if(m_drawTuple){
644 m_nHit=digiId;
645 m_nHitAxial=nHitAxial;
646 m_nHitStereo=m_nHit-m_nHitAxial;
647 }
648 if(m_debug>0) cout<<"Hit digi number: "<<digiId<<endl;
649 if(digiId<5||nHitAxial<3) {
650 if(m_drawTuple) m_trackFailure=1;
651 if(m_drawTuple) ntuplehit->write();
652 if(m_debug>0) cout<<"not enough hit "<<endl;
653 return StatusCode::SUCCESS;
654 }
655
656
657 vector<int> vec_digitruth(digiId,0);
658 vector<double> vec_flt_truth(digiId,999.);
659 vector<double> vec_ztruth(digiId,999.);
660 vector<double> vec_posflag_truth(digiId,999.);
661 if(m_useMcInfo){
662 int if_exit_delta_e=0;
663 int nhit_digi=0;
664 for(int iHit=0;iHit<digiId;iHit++){
665 vector<int>::iterator iter_ihit = find( vec_hit_Mc.begin(),vec_hit_Mc.end(),vec_hit[iHit] );
666 if( iter_ihit==vec_hit_Mc.end() ) {
667 vec_digitruth[iHit]=0;
668 if(m_drawTuple) m_digi_truth[iHit]=0;
669 if_exit_delta_e=1;
670 }
671 else {
672 vec_digitruth[iHit]=1;
673 m_digi_truth[iHit]=1;
674 nhit_digi++;
675 }
676 for(int iHit_Mc=0;iHit_Mc<vec_flt_truth_mc.size();iHit_Mc++){
677 if(vec_hit[iHit]==vec_hit_Mc[iHit_Mc]) {
678 vec_flt_truth[iHit]=vec_flt_truth_mc[iHit_Mc];
679 vec_ztruth[iHit]=vec_ztruth_Mc[iHit_Mc];
680 vec_posflag_truth[iHit]=vec_pos_flag[iHit_Mc];
681 if(m_drawTuple){
682 m_ztruth[iHit]=vec_ztruth_Mc[iHit_Mc];
683 m_ltruth[iHit]=vec_flt_truth_mc[iHit_Mc];
684 m_postruth[iHit]=vec_pos_flag[iHit_Mc];
685 }
686 }
687 }
688 if(m_debug>3) cout<<" hitPos: "<<"("<<vec_layer[iHit]<<","<<vec_wire[iHit]<<")"<<" flt_truth: "<<vec_flt_truth[iHit]<<" z_truth: "<<vec_ztruth[iHit]<<" pos_flag: "<<vec_posflag_truth[iHit]<<" digi_truth: "<<vec_digitruth[iHit]<<endl;
689 }
690 if( m_drawTuple ){
691 m_e_delta=if_exit_delta_e;
692 m_nHitDigi=nhit_digi;
693 }
694 }
695
696
697 vector<int>::iterator laymax=max_element( vec_layer.begin(),vec_layer.end() );
698 if(m_drawTuple) m_layer_max=*laymax;
699
700
701 int nhit;
702 int nhitaxial;
703 if(m_data==0 && m_useMcInfo && m_fillTruth) {
704 nhit=m_nHit_Mc;
705 nhitaxial=m_nHitAxial_Mc;
706 }
707 else{
708 nhit=digiId;
709 nhitaxial=nHitAxial;
710 }
711
712 binX=m_binx;
713 binY=m_biny;
714 TH2D *h1 =
new TH2D(
"h1",
"h1",binX,0,
M_PI,binY,-m_maxrho,m_maxrho);
715 TH2D *h2 =
new TH2D(
"h2",
"h2",binX,0,
M_PI,binY,-m_maxrho,m_maxrho);
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786 vector< vector< vector<int> > > vec_selectNum(binX,vector< vector<int> >(binY,vector<int>() ) );
789 int peak_track;
790 if(m_method==1){
791 FillHist(h1,vec_u,vec_v,nhit,vec_selectNum);
792 int max_count=0;
793 int max_binx=0;
794 int max_biny=0;
795 for(int i=0;i<binX;i++){
796 for(int j=0;j<binY;j++){
797 int count=h1->GetBinContent(i+1,j+1);
798 if(max_count<
count) {
800 max_binx=i+1;
801 max_biny=j+1;
802 }
803 }
804 }
805
806 if(vec_selectNum[max_binx-1][max_biny-1].size() != max_count ) cout<< "ERROR IN VEC!!! "<<endl;
807 if(m_debug>4) {
808 cout<<"maxBin: ["<<max_binx-1<<","<<max_biny-1<<"]: "<<vec_selectNum[max_binx-1][max_biny-1].size()<<endl;
809 for(int i =0;i<vec_selectNum[max_binx-1][max_biny-1].size();i++) cout<<" maxBin select hit: "<<vec_selectNum[max_binx-1][max_biny-1][i]<<endl;
810 }
811
812 if(m_debug>4) {
813 for(int ibinx=0;ibinx<binX;ibinx++){
814 for(int ibiny=0;ibiny<binY;ibiny++){
815 int bincount=h1->GetBinContent(ibinx+1,ibiny+1);
816 if(vec_selectNum[ibinx][ibiny].size() != bincount ) cout<< "ERROR IN VECTORSELECT filling "<<endl;
817 if(vec_selectNum[ibinx][ibiny].size() == 0 ) continue;
818 cout<<"bin:"<<"["<<ibinx<<","<<ibiny<<"]"<<" select:"<<vec_selectNum[ibinx][ibiny].size()<<endl;
819 for(int i=0;i<vec_selectNum[ibinx][ibiny].size();i++){
820 int ihit=vec_selectNum[ibinx][ibiny][i];
821 cout<<" hit: "<<ihit<<" ("<<vec_layer[ihit]<<","<<vec_wire[ihit]<<")"<<endl;
822 }
823 }
824 }
825 }
826
827
828
829 int count_use=0;
830 double sum=0;
831 double sum2=0;
832 for(int i=0;i<binX;i++){
833 for(int j=0;j<binY;j++){
834 int count=h1->GetBinContent(i+1,j+1);
836 count_use++;
839 }
840 }
841 }
842 double f_n=m_ndev1;
843 double aver=sum/count_use;
844 double dev=sqrt(sum2/count_use-aver*aver);
845 int min_counts=(int)(aver+f_n*dev);
846 if (min_counts<m_ndev2) min_counts=m_ndev2;
847 if(m_debug>2) cout<<"aver: "<<aver<<" "<<"dev: "<<dev<<" min: "<<min_counts<<endl;
848
849 vector< vector <int> > hough_trans_CS(binX,vector <int> (binY,0) );
850 vector< vector <int> > hough_trans_CS_peak(binX,vector <int> (binY,0) );
851 for(int i=0;i<binX;i++){
852 for(int j=0;j<binY;j++){
853 hough_trans_CS[i][j]=h1->GetBinContent(i+1,j+1);
854 }
855 }
856
857 int npeak_1=0;
858 for (int r=0; r<binY; r++) {
859 double binHigh=2*m_maxrho/binY;
860 double rho_peak=r*binHigh-m_maxrho;
861 for (int a=0; a<binX; a++) {
862 long max_around=0;
863 for (int ar=a-1; ar<=a+1; ar++) {
864 for (int rx=r-1; rx<=r+1; rx++) {
865 int ax;
866 if (ar<0) { ax=ar+binX; }
867 else if (ar>=binX) { ax=ar-binX; }
868 else { ax=ar; }
869 if ( (ax!=a || rx!=r) && rx>=0 && rx<binY) {
870 if (hough_trans_CS[ax][rx]>max_around) { max_around=hough_trans_CS[ax][rx]; }
871 }
872 }
873 }
874
875 if (hough_trans_CS[a][r]<=min_counts||fabs(rho_peak)<m_rhocut) { hough_trans_CS_peak[a][r]=0; }
876 else if (hough_trans_CS[a][r]<max_around) { hough_trans_CS_peak[a][r]=0; }
877 else if (hough_trans_CS[a][r]==max_around) { hough_trans_CS_peak[a][r]=1; }
878 else if (hough_trans_CS[a][r]>max_around) { hough_trans_CS_peak[a][r]=2; }
879 if(hough_trans_CS_peak[a][r]!=0) {
880 if(m_debug>2) cout<<" possible peak1:"<<"["<<a<<","<<r<<"]"<<": "<<hough_trans_CS_peak[a][r]<<" "<<hough_trans_CS[a][r]<<endl;
881 npeak_1++;
882 }
883 }
884 }
885
886
887
888 int npeak_2=0;
889 for (int r=0; r<binY; r++) {
890 for (int a=0; a<binX; a++) {
891 if (hough_trans_CS_peak[a][r]==1) {
892 hough_trans_CS_peak[a][r]=2;
893 for (int ar=a-1; ar<=a+1; ar++) {
894 for (int rx=r-1; rx<=r+1; rx++) {
895 int ax;
896 if (ar<0) { ax=ar+binX; }
897 else if (ar>=binX) { ax=ar-binX; }
898 else { ax=ar; }
899 if ( (ax!=a || rx!=r) && rx>=0 && rx<binY) {
900 if (hough_trans_CS_peak[ax][rx]==1) { hough_trans_CS_peak[ax][rx]=0; }
901 }
902 }
903 }
904 }
905 if(hough_trans_CS_peak[a][r]==2) {
906 double binHigh=2*m_maxrho/binY;
907 double rho_peak=r*binHigh-m_maxrho;
908 npeak_2++;
909 if(m_debug>2){
910 cout<<" possible peak2: "<<"["<<a<<","<<r<<"]"<<": "<<hough_trans_CS_peak[a][r]<<" "<<hough_trans_CS[a][r]<<" rhopeak: "<<rho_peak<<endl;
911 for(int i=0;i<hough_trans_CS[a][r];i++){
912 int hitNum=vec_selectNum[a][r][i];
913 if(m_debug>2) cout<<" select hit: "<<hitNum<<"("<<vec_layer[hitNum]<<","<<vec_wire[hitNum]<<")"<<endl;
914 }
915 }
916 }
917 }
918 }
919
920
921 for(int i=0;i<binX;i++){
922 for(int j=0;j<binY;j++){
923 if(hough_trans_CS_peak[i][j]==2){
924 h2->SetBinContent(i+1,j+1,hough_trans_CS[i][j]);
925 }
926 }
927 }
928
929 vector<int> peakList[3];
930 for(
int n=0;
n<npeak_2;
n++){
931 for (int r=0; r<binY; r++) {
932 for (int a=0; a<binX; a++) {
933 if (hough_trans_CS_peak[a][r]==2) {
934 peakList[0].push_back(a);
935 peakList[1].push_back(r);
936 peakList[2].push_back(hough_trans_CS[a][r]);
937 }
938 }
939 }
940 }
941
942 if(m_drawTuple){
943 m_npeak_1=npeak_1;
944 m_npeak_2=npeak_2;
945 }
946 if(m_debug>0) {
947 cout<<"npeak_1: "<<npeak_1<<endl;
948 cout<<"npeak_2: "<<npeak_2<<endl;
949 }
950
951
952 int n_max;
953 for (int na=0; na<npeak_2-1; na++) {
954 n_max=na;
955 for (int nb=na+1; nb<npeak_2; nb++) {
956 if (peakList[2][n_max]<peakList[2][nb]) { n_max=nb; }
957 }
958 if (n_max!=na) {
959 float swap[3];
960 for (int i=0; i<3; i++) {
961 swap[i]=peakList[i][na];
962 peakList[i][na]=peakList[i][n_max];
963 peakList[i][n_max]=swap[i];
964 }
965 }
966 }
967
968 if(npeak_2==0||npeak_2>100){
969 if(m_debug>0) cout<<" FAILURE IN NPEAK2 !!!!!! "<<endl;
970 delete h1;
971 delete h2;
972 if(m_drawTuple){
973 m_trackFailure=2;
974 m_npeak_2=-999;
975 }
976 if(m_drawTuple) ntuplehit->write();
977 return StatusCode::SUCCESS;
978 }
979
980 if(m_debug>2){
981 for(
int n=0;
n<npeak_2;
n++){
982 int bintheta=peakList[0][
n];
983 int binrho=peakList[1][
n];
985 cout<<
"possible peakList after SORT: "<<
n<<
": "<<
"["<<bintheta<<
","<<binrho<<
"]: "<<
count<<endl;
986 for(
int i=0;i<
count;i++){
987 int hitNum=vec_selectNum[bintheta][binrho][i];
988 if(m_debug>2) cout<<" "<<" select hit:"<<":"<<hitNum<<" ------ "<<"("<<vec_layer[hitNum]<<","<<vec_wire[hitNum]<<")"<<endl;
989 }
990 }
991 }
992
993
994 peak_track=npeak_2;
995 Combine(h1,m_peakCellNumX,m_peakCellNumY,vec_selectNum,peak_hit_list,peak_hit_num,peak_track,peakList);
996 if(m_drawTuple) m_npeak_after_tracking=peak_track;
997
998 if(m_debug>0) cout<<"event"<<t_eventNum<<": "<<"has found: "<<peak_track<<" track."<<endl;
999 for( int i=0;i<peak_track;i++){
1000 if(m_debug>0) cout<<"peak["<<i<<"] collect "<<peak_hit_num[i]<<" hits "<<endl;
1001 int nhitaxialselect=0;
1002 for(int j =0;j<peak_hit_num[i];j++){
1003 int hit_number=peak_hit_list[i][j];
1004 if(vec_slant[hit_number]==0) nhitaxialselect++ ;
1005 if(m_debug>0) cout<<" "<<" collect hits: ("<<vec_layer[hit_number]<<","<<vec_wire[hit_number]<<")"<<endl;
1006 }
1007 if(m_drawTuple){
1008 m_nHitSelect[i]=peak_hit_num[i];
1009 m_nHitAxialSelect[i]=nhitaxialselect;
1010 m_nHitStereoSelect[i]=peak_hit_num[i]-nhitaxialselect;
1011 m_axiallose[i]=m_nHitAxial-m_nHitAxialSelect[i];
1012 m_stereolose[i]=m_nHit-m_nHitSelect[i]-m_axiallose[i];
1013 }
1014 }
1015 }
1016
1017 vector<int> vec_hitbeforefit;
1018 vector<bool> vec_truthHit(nhit,false);
1019 int peak_fit=peak_track;
1020 if(m_setpeak_fit!=-1) {
1021 peak_fit=m_setpeak_fit;
1022 }
1023 if(m_drawTuple) m_trackNum=peak_fit;
1024
1025 vector<int> vec_hit_use;
1026
1027
1028
1029 vector<TrkRecoTrk*> vec_newTrack;
1030 vector<TrkRecoTrk*> vec_track_in_tds;
1031 vector<int> vec_hitOnTrack;
1032 vector<MdcHit*> vec_for_clean;
1033 vector<TrkRecoTrk*> vec_trk_for_clean;
1034 vector<Mytrack> vec_myTrack;
1035 int track_fit_success=0;
1036
1037 for(track_fit=0;track_fit<peak_fit;track_fit++){
1038 double d0_before_least=-999.;
1039 double phi0_before_least=-999.;
1040 double omega_before_least=-999.;
1041 map<int,double> hit_to_circle1;
1042 map<int,double> hit_to_circle2;
1043 map<int,double> hit_to_circle3;
1044 if(m_debug>0) cout<<"Do fitting track: "<<track_fit<<endl;
1045
1046 for(int i=0;i<nhit;i++) vec_truthHit[i]=false;
1047
1048
1049 if(m_debug>1) cout<<"candi track["<<track_fit<<"] collect "<<peak_hit_num[track_fit]<<" hits "<<endl;
1050
1051 for(int i=0;i<peak_hit_num[track_fit];i++){
1052 int hitNum=peak_hit_list[track_fit][i];
1053 int hittemp=vec_layer[hitNum]*1000+vec_wire[hitNum];
1054 vector<int>::iterator iter_ihit = find( vec_hit_use.begin(),vec_hit_use.end(),hittemp );
1055 if( iter_ihit==vec_hit_use.end() ) vec_truthHit[hitNum]=true;
1056 if( m_debug >1 && vec_truthHit[hitNum]==true) cout<<" "<<"collect hit :"<<"("<<vec_layer[hitNum]<<","<<vec_wire[hitNum]<<")"<<" "<<endl;;
1057 }
1058 if( m_debug >1){
1059 for(int i=0;i<nhit;i++){
1060 if(vec_truthHit[i]==false){
1061 cout<<"candi track "<<"uncollect hit: "<<endl;
1062 cout<<" "<<"uncollect hit :"<<"("<<vec_layer[i]<<","<<vec_wire[i]<<")"<<" " <<endl;
1063 }
1064 }
1065 }
1066
1067 int t_nHitAxialSelect=0;
1068 for(int i=0;i<nhit;i++){
1069 if(vec_truthHit[i]==true){
1070 if(vec_slant[i]==0) t_nHitAxialSelect++;
1071 }
1072 }
1073 if(m_debug>1) cout<<"track "<<track_fit<<" with axial select: "<<t_nHitAxialSelect<<endl;
1074 if(t_nHitAxialSelect<3 && m_drawTuple){
1075 m_x_circle[track_fit]=-999.;
1076 m_y_circle[track_fit]=-999.;
1077 m_r[track_fit]=-999.;
1078 m_chis_pt[track_fit] = -999.;
1079 m_pt[track_fit]=-999.;
1080 continue;
1081 }
1082 double circle_x=0;
1083 double circle_y=0;
1084 double circle_r=0;
1085 int leastSquare=LeastSquare(nhit,vec_x,vec_y,vec_slant,vec_layer,vec_truthHit,d0_before_least,phi0_before_least,omega_before_least,circle_x,circle_y,circle_r);
1086
1087 for(int i=0;i<nhit;i++){
1088 int hittemp=vec_layer[i]*1000+vec_wire[i];
1089 double dist_temp=sqrt(pow( (vec_y[i]-circle_y),2)+pow( (vec_x[i]-circle_x),2))-circle_r;
1090 if(dist_temp>10.) vec_truthHit[i]=false;
1091 if(m_debug>1&&vec_truthHit[i]==true) cout<<"IN LEAST1: "<<"("<<vec_layer[i]<<","<<vec_wire[i]<<"):"<<dist_temp<<endl;
1092 }
1093
1094 t_nHitAxialSelect=0;
1095 for(int i=0;i<nhit;i++){
1096 if(vec_truthHit[i]==true){
1097 if(vec_slant[i]==0) t_nHitAxialSelect++;
1098 }
1099 }
1100 if(m_debug>1) cout<<"track "<<track_fit<<"with axial2 select: "<<t_nHitAxialSelect<<endl;
1101 if(t_nHitAxialSelect<3) continue;
1102
1103 int leastSquare2=LeastSquare(nhit,vec_x,vec_y,vec_slant,vec_layer,vec_truthHit,d0_before_least,phi0_before_least,omega_before_least,circle_x,circle_y,circle_r);
1104 for(int i=0;i<nhit;i++){
1105 int hittemp=vec_layer[i]*1000+vec_wire[i];
1106 double dist_temp=sqrt(pow( (vec_y[i]-circle_y),2)+pow( (vec_x[i]-circle_x),2))-circle_r;
1107 hit_to_circle1[hittemp]=dist_temp;
1108 if(m_debug>1&&vec_truthHit[i]==true) cout<<" IN LEAST2: "<<"("<<vec_layer[i]<<","<<vec_wire[i]<<"):"<<dist_temp<<endl;
1109 }
1110
1111 if(m_drawTuple){
1112 m_x_circle[track_fit]=circle_x;
1113 m_y_circle[track_fit]=circle_y;
1114 m_r[track_fit]=circle_r;
1115 m_chis_pt[track_fit]=circle_r/333.567;
1116 }
1117
1118
1122 const TrkFit* newFit2[2];
1124
1125 int Q_iq[]={-1,1};
1126 double Q_Chis_2d[]={9999,9999};
1127 double Q_Chis_3d[]={9999,9999};
1128 double Q_z[]={999,999};
1129 double Q_pt2[]={999,999};
1130 double Q_tanl[]={999,999};
1131 int Q_ok[2][2]={0};
1132
1133 int q_start=0;
1134 int q_end=1;
1135 if(m_q==-1) {q_start=0;q_end=0;}
1136 if(m_q==1) {q_start=1;q_end=1;}
1137 for(int i_q=q_start;i_q<=q_end;i_q++){
1138 double d0=d0_before_least;
1139 double phi0=phi0_before_least;
1140 double omega=omega_before_least;
1141 double z0=0;
1142 double tanl=0;
1143 if(m_debug>0 ){
1144 cout<<"BY LEASTSQUARE: "<<endl;
1145 cout<<" d0: "<<d0<<" d0_mc "<<d0_mc<<endl;
1146 cout<<" phi0: "<<phi0<<" phi0_mc "<<phi0_mc<<endl;
1147 cout<<" omega0: "<<omega<<" omega_mc "<<omega_mc<<endl;
1148 }
1149
1150 vector<double> vec_flt_least;
1151 for(int i=0;i<nhit;i++){
1152 double theta_temp;
1153 if(circle_x==0||vec_x[i]-circle_x==0){
1154 theta_temp=0;
1155 }
1156 else{
1157 theta_temp=
M_PI-atan2(vec_y[i]-circle_y,vec_x[i]-circle_x)+atan2(circle_y,circle_x);
1158 if(theta_temp>2*
M_PI){
1159 theta_temp=theta_temp-2*
M_PI;
1160 }
1161 if(theta_temp<0){
1162 theta_temp=theta_temp+2*
M_PI;
1163 }
1164 }
1165 if(Q_iq[i_q]==-1) {
1166 double l_temp=circle_r*theta_temp;
1167 vec_flt_least.push_back(l_temp);
1168 }
1169 if(Q_iq[i_q]==1) {
1170 theta_temp=2*
M_PI-theta_temp;
1171 double l_temp=circle_r*(theta_temp);
1172 vec_flt_least.push_back(l_temp);
1173 }
1174 }
1175 if(m_debug>2) {
1176 for(int i=0;i<nhit;i++){
1177 cout<<"By least 2d: "<< "("<<vec_layer[i]<<","<<vec_wire[i]<<"):"<<vec_flt_least[i]<<endl;
1178 }
1179 }
1180
1181
1182 if(Q_iq[i_q]==-1){
1183 d0=-d0;
1184 omega=-1./circle_r;
1185 }
1186 if(Q_iq[i_q]==1){
1187 d0=d0;
1188 omega=1./circle_r;
1190 }
1191
1192
1193 double x_cirtemp;
1194 double y_cirtemp;
1195 double r_temp;
1198 float chisum =0.;
1200
1201 bool permitFlips = true;
1202 bool lPickHits = m_pickHits;
1204 int nDigi = digiToHots(mdcDigiVec,newTrack,vec_truthHit,getDigiFlag,vec_flt_least,hit_to_circle1,vec_for_clean);
1205 if(m_debug>2){
1207 }
1208
1209
1210 qhits[i_q] = newTrack->
hits();
1213
1214
1215 if (!newFit[i_q] || (newFit[i_q]->nActive()<3) || err.
failure()!=0) {
1216 if(m_debug>0){
1217 cout << "evt "<<t_eventNum<<" global 2d fit failed ";
1218 if(newFit[i_q]) cout <<
" nAct "<<newFit[i_q]->
nActive();
1219 cout<<
"ERR1 failure ="<<err.
failure()<<endl;
1220 }
1221
1222 Q_ok[i_q][0]=0;
1223 Q_ok[i_q][1]=0;
1224 Q_Chis_2d[i_q]=-999.;
1225 delete newTrack;
1226 continue;
1227 }else{
1228 Q_ok[i_q][0]=1;
1229 Q_ok[i_q][1]=0;
1230 if(m_debug>0) cout <<"evt "<<t_eventNum<< " global 2d fit success"<<endl;
1231 if(m_debug>2) {
1232 newTrack->
print(std::cout);
1233 }
1234 Q_Chis_2d[i_q]=newFit[i_q]->
chisq();
1235
1240 r_temp=Q_iq[i_q]/par.
omega();
1243
1244 if(m_debug>1) cout<<" circle after globle 2d: "<<"("<<x_cirtemp<<","<<y_cirtemp<<","<<r_temp<<")"<<endl;
1245 if(m_debug>0) cout<<"pt_rec: "<<-1*Q_iq[i_q]/omega/333.567<<endl;
1246
1247 if(m_drawTuple){
1248 m_x_circle[track_fit]=x_cirtemp;
1249 m_y_circle[track_fit]=y_cirtemp;
1250 m_r[track_fit]=r_temp;
1251 m_chis_pt[track_fit] = newFit[i_q]->
chisq();
1252 m_pt[track_fit]=r_temp/333.567;
1253 }
1254 }
1255
1256 int nfit2d=0;
1257 if(m_debug>1) cout<<" hot list:"<<endl;
1259 int lay=((
MdcHit*)(hotIter->hit()))->layernumber();
1260 int wir=((
MdcHit*)(hotIter->hit()))->wirenumber();
1261 int hittemp=lay*1000+wir;
1262 while (hotIter!=qhits[i_q]->hotList().end()) {
1263 if(m_debug>1){ cout <<
"(" <<((
MdcHit*)(hotIter->hit()))->layernumber()
1264 <<
","<<((
MdcHit*)(hotIter->hit()))->wirenumber()
1265 <<":"<<hotIter->isActive()<<") ";
1266 }
1267 if (hotIter->isActive()==1) nfit2d++;
1268 hotIter++;
1269 }
1270 if(m_debug>0) cout<<"charge "<<i_q<<" In 2Dfit Num Of Active Hits: "<<nfit2d<<endl;
1271
1272
1273 if(m_debug>0 && m_drawTuple){
1274 cout<<" By global 2d charge "<<i_q<<endl;
1275 cout<<" d0: " <<d0<<" "<<m_drTruth[0]<<endl;
1276 cout<<" phi0: " <<phi0<<" "<<m_phi0Truth[0]<<endl;
1277 cout<<" omega: "<<omega<<" "<<m_omegaTruth[0]<<endl;
1278 cout<<" z0: " <<z0<<" "<<m_dzTruth[0]<<endl;
1279 cout<<" tanl: "<<tanl<<" "<<m_tanl_mc[0]<<endl;
1280 }
1281
1282 if(m_debug>2) {
1283 cout<<"least:( "<<circle_x<<","<<circle_y<<","<<circle_r<<endl;
1284 cout<<"2d:( "<<x_cirtemp<<","<<y_cirtemp<<","<<r_temp<<endl;
1285 }
1286 delete newTrack;
1287
1288
1289 vector<double> vec_flt;
1290 vector<double> vec_theta_ontrack;
1291 for(int i=0;i<nhit;i++){
1292 double theta_temp;
1293 if(x_cirtemp==0||vec_x[i]-x_cirtemp==0){
1294 theta_temp=0;
1295 }
1296 else{
1297 theta_temp=
M_PI-atan2(vec_y[i]-y_cirtemp,vec_x[i]-x_cirtemp)+atan2(y_cirtemp,x_cirtemp);
1298 if(theta_temp>2*
M_PI){
1299 theta_temp=theta_temp-2*
M_PI;
1300 }
1301 if(theta_temp<0){
1302 theta_temp=theta_temp+2*
M_PI;
1303 }
1304 if(Q_iq[i_q]==-1) {
1305 double l_temp=r_temp*theta_temp;
1306 vec_flt.push_back(l_temp);
1307 vec_theta_ontrack.push_back(theta_temp);
1308
1309 }
1310 if(Q_iq[i_q]==1) {
1311 theta_temp=2*
M_PI-theta_temp;
1312 double l_temp=r_temp*(theta_temp);
1313 vec_flt.push_back(l_temp);
1314 vec_theta_ontrack.push_back(theta_temp);
1315
1316 }
1317 }
1318 }
1319
1320 if(m_debug>3){
1321 for(int i=0;i<nhit;i++){
1322 cout<<"i: "<<"theta: "<<vec_theta_ontrack[i]<<" l: "<<vec_flt[i]<<endl;
1323 }
1324 }
1325
1326 for(int i=0;i<nhit;i++){
1327 int hittemp=vec_layer[i]*1000+vec_wire[i];
1328 double dist_temp=sqrt(pow( (vec_y[i]-y_cirtemp),2)+pow( (vec_x[i]-x_cirtemp),2))-r_temp;
1329 hit_to_circle2[hittemp]=dist_temp;
1330 }
1331
1332 vector<double> vec_l_Calcu_Left;
1333 vector<double> vec_l_Calcu_Right;
1334 vector<double> vec_z_Calcu_Left;
1335 vector<double> vec_z_Calcu_Right;
1336 vector<double> vec_z_Calcu;
1337 vector<double> vec_l_Calcu;
1338 vector<double> vec_delta_z;
1339 vector<double> vec_delta_l;
1340
1341 double l_Calcu_Left=-999.;
1342 double l_Calcu_Right=-999.;
1343 double z_Calcu_Left=-999.;
1344 double z_Calcu_Right=-999.;
1345 double z_Calcu=-999.;
1346 double l_Calcu=-999.;
1347 double delta_z=-999.;
1348 double delta_l=-999.;
1349
1350 MdcDigiVec::iterator iter2 = mdcDigiVec.begin();
1351 int zPos;
1352 int digiId = 0;
1353 for (;iter2 != mdcDigiVec.end(); iter2++, digiId++) {
1354 if(vec_truthHit[digiId]==false) continue;
1355 if(vec_slant[digiId]==0) continue;
1356 if(vec_theta_ontrack[digiId]>
M_PI)
continue;
1357 const MdcDigi* aDigi = *iter2;
1361 zPos=zPosition(*hit,m_bunchT0,x_cirtemp,y_cirtemp,r_temp,digiId,delta_z,delta_l,l_Calcu_Left,l_Calcu_Right,z_Calcu_Left,z_Calcu_Right,z_Calcu,l_Calcu,Q_iq[i_q]);
1362 if(m_debug>2) cout<<"in ZS calcu hitPos: "<<"("<<vec_layer[digiId]<<","<<vec_wire[digiId]<<")"<<" l_truth: "<<vec_flt_truth[digiId]<<" z_truth: "<<vec_ztruth[digiId]<<" l_Cal: "<<l_Calcu<<" z_Cal: "<<z_Calcu<<endl;
1363 delete hit;
1364 if(zPos==-1||zPos==-2) continue;
1365 vec_l_Calcu_Left.push_back(l_Calcu_Left);
1366 vec_l_Calcu_Right.push_back(l_Calcu_Right);
1367 vec_z_Calcu_Left.push_back(z_Calcu_Left);
1368 vec_z_Calcu_Right.push_back(z_Calcu_Right);
1369 vec_z_Calcu.push_back(z_Calcu);
1370 vec_l_Calcu.push_back(l_Calcu_Right);
1371 vec_delta_z.push_back(delta_z);
1372 vec_delta_l.push_back(delta_l);
1373 }
1374 int nHitUseInZs=vec_delta_z.size();
1375
1376 if(m_drawTuple){
1377 for(int i=0;i<nHitUseInZs;i++){
1378 m_nHitStereo_use=vec_delta_z.size();
1379 m_lCalcuLeft[i]=vec_l_Calcu_Left[i];
1380 m_lCalcuRight[i]=vec_l_Calcu_Right[i];
1381 m_zCalcuLeft[i]=vec_z_Calcu_Left[i];
1382 m_zCalcuRight[i]=vec_z_Calcu_Right[i];
1383 m_lCalcu[i]=vec_l_Calcu[i];
1384 m_zCalcu[i]=vec_z_Calcu[i];
1385 m_delta_z[i]=vec_delta_z[i];
1386 m_delta_l[i]=vec_delta_l[i];
1387 }
1388 }
1389
1390
1391 vector< vector< vector <double> > > point(2, vector< vector<double> >(2,vector<double>() ));
1392 for(int iHit=0;iHit<nHitUseInZs;iHit++){
1393 point[0][0].push_back(vec_l_Calcu_Left[iHit]);
1394 point[0][1].push_back(vec_z_Calcu_Left[iHit]);
1395 point[1][0].push_back(vec_l_Calcu_Right[iHit]);
1396 point[1][1].push_back(vec_z_Calcu_Right[iHit]);
1397 }
1398 vector<int> ambigList;
1399 if(nHitUseInZs!=0){
1400 AmbigChoose(point,nHitUseInZs,ambigList,tanl,z0);
1401 if(m_drawTuple){
1402 m_tanl_Cal=tanl;
1403 m_z0_Cal=z0;
1404 }
1405
1406 if(m_useMcInfo && m_drawTuple){
1407 int ambig_no_match_num=0;
1408 for(int iHit=0;iHit<nHitUseInZs;iHit++){
1409 if(ambigList[iHit]==0) ambigList[iHit]=1;
1410 else ambigList[iHit]=0;
1411 if(ambigList[iHit]!=m_postruth[iHit]) { m_ambig_no_match=1; ambig_no_match_num++; }
1412 }
1413 m_ambig_no_match_propotion=(double)(ambig_no_match_num)/m_nHitStereo_use;
1414 for (int iHit=0;iHit<ambigList.size();iHit++){
1415 m_amb[iHit]=ambigList[iHit];
1416 }
1417 }
1418 }
1419
1420 if(m_debug>0 && m_drawTuple){
1421 cout<<"By 3d track zs fit:"<<endl;
1422 cout<<"d0: "<<d0<<" mc : "<<m_drTruth[0]<<endl;
1423 cout<<"phi0: "<<phi0<<" mc : "<<m_phi0Truth[0]<<endl;
1424 cout<<"omega: "<<omega<<" mc : "<<m_omegaTruth[0]<<endl;
1425 cout<<"z0: "<<z0<<" mc : "<<m_dzTruth[0]<<endl;
1426 cout<<"tanl: "<<tanl<<" mc : "<<m_tanl_mc[0]<<endl;
1427 }
1428
1429 if(m_mcpar==1){
1430 d0=m_drTruth[0];
1431 phi0=m_phi0Truth[0];
1432 if(Q_iq[i_q]==-1) {phi0=m_phi0Truth[0]-3./2.*
M_PI;omega=m_omegaTruth[0];}
1433 else {phi0=m_phi0Truth[0]-1./2.*
M_PI;omega=-1*m_omegaTruth[0];}
1434 z0=m_dzTruth[0];
1435 tanl=m_tanl_mc[0];
1436 }
1437
1438
1439
1440 if(m_debug>0) cout<< "become 3d fit "<<endl;
1443 chisum =0.;
1444 newTrack2[i_q] = helixfactory.
makeTrack(tt2, chisum, *m_context, m_bunchT0);
1445 vec_trk_for_clean.push_back(newTrack2[i_q]);
1446 permitFlips = true;
1447 lPickHits = m_pickHits;
1448 helixfactory.
setFlipAndDrop(*newTrack2[i_q], permitFlips, lPickHits);
1449 int nDigi2 = digiToHots2(mdcDigiVec,newTrack2[i_q],vec_truthHit,vec_flt_truth,getDigiFlag,vec_slant,vec_l_Calcu,vec_flt,vec_theta_ontrack,vec_hitbeforefit,hit_to_circle2,vec_for_clean,tanl);
1450 if(m_debug>2){
1451 cout<<__FILE__<<__LINE__<<"AFTER digiToHots 3d ---------BEFORE 3d fit"<<endl;
1452 newTrack2[i_q]->
printAll(std::cout);
1453 }
1454
1455 qhits2[i_q] = newTrack2[i_q]->
hits();
1457 newFit2[i_q] = newTrack2[i_q]->
fitResult();
1458 int nActiveHit = newTrack2[i_q]->
hots()->
nActive();
1459 int fitSuccess_3d = 0;
1460 if (!newFit2[i_q] || (newFit2[i_q]->nActive()<5) || err2.
failure()!=0) {
1461 fitSuccess_3d=0;
1462 Q_ok[i_q][1]=0;
1463 Q_Chis_3d[i_q]=-999.;
1464 if(m_debug>0){
1465 cout << "evt "<<t_eventNum<<" global 3d fit failed ";
1466 if(!newFit2[i_q]) cout<<" newfit2 point is NULL!!!" <<endl;
1467 if(newFit2[i_q]) cout <<
" nAct "<<newFit2[i_q]->
nActive();
1468 cout<<
"ERR2 failure ="<<err2.
failure()<<endl;
1469 }
1470 }else{
1471
1473 if(
abs( 1/(par2.
omega()) )>0.001){
1474 fitSuccess_3d=1;
1475 Q_Chis_3d[i_q]=newFit2[i_q]->
chisq();
1476 Q_ok[i_q][1]=1;
1477 if(m_debug>0) cout <<
"evt "<<t_eventNum<<
" global 3d fit success "<<err2.
failure()<<endl;
1478 if(m_debug>2){
1479 cout<<__FILE__<<__LINE__<<"AFTER fit 3d "<<endl;
1480 newTrack2[i_q]->
print(std::cout);
1481 }
1482 } else {
1483 fitSuccess_3d=0;
1484 Q_ok[i_q][1]=0;
1485 Q_Chis_3d[i_q]=-999.;
1486 if(m_debug>2) cout<<"3dfit failure of omega "<<endl;
1487 }
1488 bool badQuality = false;
1489
1490
1491 if(fabs(Q_Chis_3d[i_q])>m_qualityFactor*m_dropTrkChi2Cut ){
1492 if(m_debug>0){
1493 std::cout<<__FILE__<<" "<<__LINE__<<" drop track by chi2 "<<Q_Chis_3d[i_q]<<" > "<<m_qualityFactor<<" * "<<m_dropTrkChi2Cut <<std::endl;
1494 }
1495 badQuality=1;
1496 }
1497 if( fabs(par2.
d0())>m_qualityFactor*m_dropTrkDrCut) {
1498 if(m_debug>0){
1499 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by d0 "<<par2.
d0()<<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkDrCut <<std::endl;
1500 }
1501 badQuality=1;
1502 }
1503 if( fabs(par2.
z0())>m_qualityFactor*m_dropTrkDzCut) {
1504 if(m_debug>0){
1505 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by z0 "<<par2.
z0()<<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkDzCut <<std::endl;
1506 }
1507 badQuality=1;
1508 }
1509 if( (fabs(Q_Chis_3d[i_q])/qhits2[i_q]->nHit()) > m_qualityFactor*m_dropTrkChi2NdfCut) {
1510 if(m_debug>0){
1511 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by chi2/ndf"<<(fabs(Q_Chis_3d[i_q])/qhits2[i_q]->
nHit()) <<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkChi2NdfCut<<std::endl;
1512 }
1513 badQuality=1;
1514 }
1515 if( nActiveHit <= m_dropTrkNhitCut) {
1516 if(m_debug>0){
1517 std::cout<<__FILE__<<" "<<__LINE__<<" drop track by nhit"<<nActiveHit <<" <= "<<m_qualityFactor<<" * "<<m_dropTrkNhitCut<<std::endl;
1518 }
1519 badQuality=1;
1520 }
1521 if(badQuality) {
1522 fitSuccess_3d=0;
1523 Q_ok[i_q][1]=0;
1524 Q_Chis_3d[i_q]=-999.;
1525 if(m_debug>2) cout<<"3dfit failure of bad quality"<<endl;
1526 }
1527
1528 }
1529
1530
1531 if(fitSuccess_3d==1){
1533 if(m_debug>0){
1534 cout<<"BY 3d global fit charge "<<i_q<<endl;
1535 cout<<
"d0: "<<par2.
d0()<<endl;
1536 cout<<
"phi0: "<<par2.
phi0()<<endl;
1537 cout<<
"w: "<<par2.
omega()<<endl;
1538 cout<<
"z: "<<par2.
z0()<<endl;
1539 cout<<
"tanl: "<<par2.
tanDip()<<endl;
1540 }
1541 r_temp=Q_iq[i_q]/par2.
omega();
1543 y_cirtemp = -1.*
cos(par2.
phi0()) *(par2.
d0()+1/par2.
omega()) * -1;
1544 if(m_debug>0) cout<<" circle after globle 3d: "<<"("<<x_cirtemp<<","<<y_cirtemp<<","<<r_temp<<")"<<endl;
1545 double pxy=-1*r_temp/333.567;
1546 double pz=pxy*par2.
tanDip();
1547 double pxyz=sqrt(pxy*pxy+pz*pz);
1548
1549 Q_pt2[i_q]=fabs(pxy);
1551 Q_tanl[i_q]=par2.
tanDip();
1552 } else{
1553 continue;
1554 }
1555
1556
1557 for(int i=0;i<nhit;i++){
1558 int hittemp=vec_layer[i]*1000+vec_wire[i];
1559 double dist_temp=sqrt(pow( (vec_y[i]-y_cirtemp),2)+pow( (vec_x[i]-x_cirtemp),2))-r_temp;
1560 hit_to_circle3[hittemp]=dist_temp;
1561 }
1562 }
1563
1564 if(m_debug>3){
1565 cout<<"chis 2d: "<<Q_Chis_2d[0]<<" "<<Q_Chis_2d[1]<<endl;
1566 cout<<"chis 3d: "<<Q_Chis_3d[0]<<" "<<Q_Chis_3d[1]<<endl;
1567 cout<<"Z: "<<Q_z[0]<<" "<<Q_z[1]<<endl;
1568 cout<<"chis ok-: "<<Q_ok[0][0]<<" "<<Q_ok[0][1]<<endl;
1569 cout<<"chis ok+: "<<Q_ok[1][0]<<" "<<Q_ok[1][1]<<endl;
1570 }
1571
1572 int Q;
1573 int Q_judge[2]={0};
1574 if(Q_ok[0][1]==1) Q_judge[0]=1;
1575 if(Q_ok[1][1]==1) Q_judge[1]=1;
1576 if(Q_judge[0]==1&&Q_judge[1]==0) Q=-1;
1577 if(Q_judge[0]==0&&Q_judge[1]==1) Q=1;
1578 if(Q_judge[0]==1&&Q_judge[1]==1) {
1579 if(fabs(Q_z[0])>fabs(Q_z[1])) Q=1;
1580 else Q=-1;
1581 }
1582 if(Q_judge[0]==0&&Q_judge[1]==0) {Q=0; continue;}
1583 int q_choose=0;
1584 if(Q==-1) q_choose=0;
1585 if(Q== 1) q_choose=1;
1587 if(m_debug>0){
1588 cout<<"after q choose By 3d global fit: "<<Q<<endl;
1589 cout<<
"d0: "<<par_final.
d0()<<endl;
1590 cout<<
"phi0: "<<par_final.
phi0()<<endl;
1591 cout<<
"w: "<<par_final.
omega()<<endl;
1592 cout<<
"z: "<<par_final.
z0()<<endl;
1593 cout<<
"tanl: "<<par_final.
tanDip()<<endl;
1594 }
1595 double pxy=-1*Q_iq[q_choose]/par_final.
omega()/333.567;
1596 double pz=pxy*par_final.
tanDip();
1597 double pxyz=sqrt(pxy*pxy+pz*pz);
1598
1599 if(m_debug>0) cout<<"pt2_rec: "<<pxy<<endl;
1600 if(m_drawTuple){
1601 m_pt2_rec_final[track_fit_success]=pxy;
1602 m_p_rec_final[track_fit_success]=pxyz;
1603 m_d0_final[track_fit_success]=par_final.
d0();
1604 m_phi0_final[track_fit_success]=par_final.
phi0();
1605 m_omega_final[track_fit_success]=par_final.
omega();
1606 m_z0_final[track_fit_success]=par_final.
z0();
1607 m_tanl_final[track_fit_success]=par_final.
tanDip();
1608 m_Q[track_fit_success]=Q;
1609 }
1610
1611 int nfit3d=0;
1612 if(m_debug>1) cout<<" hot list:"<<endl;
1614 while (hotIter2!=qhits2[q_choose]->hotList().end()) {
1615 int lay=((
MdcHit*)(hotIter2->hit()))->layernumber();
1616 int wir=((
MdcHit*)(hotIter2->hit()))->wirenumber();
1617 int hittemp=lay*1000+wir;
1618 if(m_debug>1){ cout <<
"(" <<((
MdcHit*)(hotIter2->hit()))->layernumber()
1619 <<
","<<((
MdcHit*)(hotIter2->hit()))->wirenumber()
1620 <<":"<<hotIter2->isActive()<<") ";
1621 }
1622 if( hotIter2->isActive()==1) {
1623 nfit3d++;
1624 if(track_fit_success==0) vec_hitOnTrack.push_back(hittemp);
1625 }
1626 hotIter2++;
1627 }
1628 if(m_debug>0) cout<<"In 3D fit Num Of Active Hits: "<<nfit3d<<endl;
1629
1630 track_fit_success++;
1631 int choise_temp,choise_no;
1632 if(Q==-1) choise_temp=0,choise_no=1;
1633 if(Q==1) choise_temp=1,choise_no=0;
1634 vec_newTrack.push_back( newTrack2[choise_temp] );
1635 }
1636
1637 for(int iTrack=0;iTrack<vec_newTrack.size();iTrack++){
1638 const TrkFit* newFit_combine = vec_newTrack[iTrack]->fitResult();
1640 double cx_combine=(-333.567/par_combine.
omega()+par_combine.
d0())*
cos(par_combine.
phi0());
1641 double cy_combine=(-333.567/par_combine.
omega()+par_combine.
d0())*
sin(par_combine.
phi0());
1642 double phi_combine=par_combine.
phi0()-
M_PI/2;
1643 double pxy_combine=1./par_combine.
omega()/333.567;
1644 if(pxy_combine<0) phi_combine+=
M_PI;
1645 if(phi_combine<0) phi_combine+=2*
M_PI;
1646 if(phi_combine>2*
M_PI) phi_combine-=2*
M_PI;
1647
1648 Mytrack mytrack;
1649 mytrack.pt=pxy_combine;
1650 mytrack.charge=(int)(fabs(pxy_combine)/pxy_combine);
1651 mytrack.phi=phi_combine;
1652 mytrack.r=-333.567/par_combine.
omega();
1653 mytrack.x_cir=cx_combine;
1654 mytrack.y_cir=cy_combine;
1655 mytrack.newTrack=vec_newTrack[iTrack];
1656 mytrack.use_in_tds=true;
1657 mytrack.vec_hit_on_trk=vec_hitOnTrack;
1658
1659 vec_myTrack.push_back(mytrack);
1660
1661 }
1662
1663 std::sort(vec_myTrack.begin(),vec_myTrack.end(),
compare);
1664
1665 for(int i=0;i<vec_newTrack.size();i++){
1666 Mytrack *mytrack_i=&(vec_myTrack[i]);
1667 if(mytrack_i->use_in_tds==false) continue;
1668 for(int j=i+1;j<vec_newTrack.size();j++){
1669 Mytrack *mytrack_j=&(vec_myTrack[j]);
1670 if(mytrack_j->use_in_tds==false) continue;
1671 if( fabs(mytrack_j->phi-mytrack_i->phi)<0.1 ) mytrack_j->use_in_tds=false;
1672 if(fabs(mytrack_j->r)*(1.-0.25) <= fabs(mytrack_i->r) && fabs(mytrack_i->r) <= fabs(mytrack_j->r)*(1.+0.25)){
1673 if(fabs(mytrack_j->x_cir-mytrack_i->x_cir) <= fabs(mytrack_j->r)*(0.25)&& fabs(mytrack_j->y_cir-mytrack_i->y_cir) <= fabs(mytrack_j->r)*(0.25) ){
1674 if(mytrack_j->charge==mytrack_i->charge)
1675 mytrack_j->use_in_tds=false;
1676 }
1677 }
1678 }
1679 }
1680
1681 int nTrack_tds=0;
1682 vector<Mytrack> vec_mytrack_in_tds;
1683 for(int i=0;i<track_fit_success;i++){
1684 Mytrack mytrack=vec_myTrack[i];
1685 if(mytrack.use_in_tds==false) continue;
1686 vec_mytrack_in_tds.push_back(mytrack);
1687 nTrack_tds++;
1688 }
1689
1690 if(m_drawTuple){
1691 m_trackNum_tds=nTrack_tds;
1692 m_trackNum_fit=track_fit_success;
1693 }
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708 int outputTrk=0;
1709 int itrack=0;
1710 for(int i=0;i<nTrack_tds;i++){
1711 Mytrack mytrack=vec_mytrack_in_tds[i];
1712 const TrkFit* newFit_tds= mytrack.newTrack->fitResult();
1714
1715
1716
1717 double cr= 1./ par_tds.
omega();
1718 double cx=
sin(par_tds.
phi0()) *(par_tds.
d0()+1/par_tds.
omega()) * -1.;
1719 double cy= -1.*
cos(par_tds.
phi0()) *(par_tds.
d0()+1/par_tds.
omega()) * -1;
1720
1721 unsigned bestIndex = 0;
1722 double bestDiff = 1.0e+20;
1723 double cR, cX, cY;
1724 vector<double> a0,a1,a2,a3,a4;
1725 vector<double> zdelta;
1726 RecMdcTrackCol::iterator iteritrk = trackList->begin();
1727 int itrk=0;
1728 for(;iteritrk!=trackList->end();iteritrk++){
1729 double pt=(*iteritrk)->pxy();
1730 a0.push_back( (*iteritrk)->helix(0) );
1731 a1.push_back( (*iteritrk)->helix(1) );
1732 a2.push_back( (*iteritrk)->helix(2) );
1733 a3.push_back( (*iteritrk)->helix(3) );
1734 a4.push_back( (*iteritrk)->helix(4) );
1735 zdelta.push_back( par_tds.
z0()-(*iteritrk)->helix(3) );
1736
1737
1738
1739 cR=(-333.567)/a2[itrk];
1740 cX=(cR+a0[itrk])*
cos(a1[itrk]);
1741 cY=(cR+a0[itrk])*
sin(a1[itrk]);
1742
1743 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1744 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1745 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1746 if(diff < bestDiff){
1747 bestDiff = diff;
1748 bestIndex = itrk;
1749 }
1750 }
1751 }
1752 itrk++;
1753 }
1754
1755 if(bestDiff == 1.0e20) { if(m_debug>0) cout<<" no merge "<<endl; }
1756 else continue;
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1771 mdcTrack=
new MdcTrack(mytrack.newTrack);
1772 vec_track_in_tds.push_back(mytrack.newTrack);
1773 int tkStat = 4;
1774 int tkId = nTdsTk + itrack;
1775 mdcTrack->
storeTrack(tkId, trackList, hitList, tkStat);
1777 outputTrk++;
1778 delete mdcTrack;
1779
1780 double pxy=1/par_tds.
omega()/333.567;
1781 double pz=pxy*par_tds.
tanDip();
1782 double pxyz=sqrt(pxy*pxy+pz*pz);
1783 if(m_drawTuple){
1784 m_pt2_rec_tds[itrack]=pxy;
1785 m_p_rec_tds[itrack]=pxyz;
1786 m_d0_tds[itrack]=par_tds.
d0();
1787 m_phi0_tds[itrack]=par_tds.
phi0();
1788 m_omega_tds[itrack]=par_tds.
omega();
1789 m_z0_tds[itrack]=par_tds.
z0();
1790 m_tanl_tds[itrack]=par_tds.
tanDip();
1791 m_Q_tds[itrack]=pxy>0?1:-1;
1792 }
1793 itrack++;
1794 }
1795 if(m_drawTuple) m_outputTrk=outputTrk;
1796 int nTdsTk_temp=trackList->size();
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823 for(int i=0;i<vec_for_clean.size();i++){
1824 delete vec_for_clean[i];
1825 }
1826 for(int i=0;i<vec_trk_for_clean.size();i++){
1827
1828
1829 vector<TrkRecoTrk*>::iterator iterTrk =find(vec_track_in_tds.begin(),vec_track_in_tds.end(),vec_trk_for_clean[i]);
1830 if(iterTrk ==vec_track_in_tds.end() ) delete vec_trk_for_clean[i];
1831
1832 }
1833 delete h1;
1834 delete h2;
1835
1836 if(m_drawTuple) ntuplehit->write();
1837 if(m_debug>0) cout<<"end event" <<endl;
1838 return StatusCode::SUCCESS;
1839}
std::vector< MdcDigi * > MdcDigiVec
DOUBLE_PRECISION count[2]
double sin(const BesAngle a)
double cos(const BesAngle a)
ObjectVector< RecMdcHit > RecMdcHitCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
bool compare(const HoughValidUpdate::Mytrack &a, const HoughValidUpdate::Mytrack &b)
HepPoint3D Forward(void) const
HepPoint3D Backward(void) const
const MdcGeoWire *const Wire(unsigned id)
void setCalibSvc(const MdcCalibFunSvc *calibSvc)
void setCountPropTime(const bool count)
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
void printRecMdcTrackCol() const
void storeTrack(int trackId, RecMdcTrackCol *trackList, RecMdcHitCol *hitList, int tkStat)
MdcDigiVec & getMdcDigiVec(uint32_t control=0)
virtual double chisq() const =0
virtual int nActive() const =0
virtual TrkExchangePar helix(double fltL) const =0
const TrkHotList & hotList() const
hot_iterator begin() const
virtual int nActive(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
virtual void print(std::ostream &) const
const TrkFit * fitResult() const
virtual void printAll(std::ostream &) const
bool setFlipAndDrop(TrkRecoTrk &, bool allowFlips, bool allowDrops) const
TrkRecoTrk * makeTrack(const TrkExchangePar &helix, const double chi2, const TrkContext &, double trackT0) const
_EXTERN_ std::string RecMdcTrackCol
_EXTERN_ std::string RecMdcHitCol