515 unsigned int i_layer_max = 0;
518 float Xor, Yor,
sigma, rm=0., phim=0;
519 float Ymid, Xmid, Amid;
521 const unsigned int MAX_STATION = 8;
522 const float SIGMA = 0.0080;
523 const float DRIFTSPACE_LIMIT = 16.;
524 const int MIN_MDT_FOR_FIT = 3;
526 const unsigned int MAX_LAYER = 12;
528 unsigned int MdtLayerHits[MAX_STATION][MAX_LAYER];
529 std:: vector<unsigned int> MdtLayerHits_index[MAX_STATION][MAX_LAYER];
531 for (
unsigned int i_st=0; i_st<MAX_STATION; i_st++) {
532 for (
unsigned int i_ly=0; i_ly<MAX_LAYER; i_ly++) {
533 MdtLayerHits[i_st][i_ly] = 0;
534 MdtLayerHits_index[i_st][i_ly].clear();
538 float Chbest = 1.e25;
543 unsigned int sumN[8];
546 for (
unsigned int i_st=0; i_st<8; i_st++) {
554 for (
unsigned int i_hit=0; i_hit<mdtSegment->size(); i_hit++){
557 if (mdtSegment->at(i_hit).isOutlier>1)
continue;
559 double Z = mdtSegment->at(i_hit).Z;
560 double R = mdtSegment->at(i_hit).R;
562 sumZ[i_station] = sumZ[i_station] +
Z;
563 sumR[i_station] = sumR[i_station] +
R;
566 if (sumN[i_station]!=0) {
567 avZ[i_station] = sumZ[i_station]/sumN[i_station];
568 avR[i_station] = sumR[i_station]/sumN[i_station];
572 if (sumN[i_station]==0)
return;
574 for (
unsigned int i_hit=0; i_hit<mdtSegment->size(); i_hit++) {
576 if (mdtSegment->at(i_hit).isOutlier>1)
continue;
578 double Z = mdtSegment->at(i_hit).Z;
579 double R = mdtSegment->at(i_hit).R;
585 double nbw = aw*
Z+(avR[i_station]-aw*avZ[i_station]);
587 if ( R>(nbw-nsWidth) &&
R<(nbw+nsWidth) ) {
588 mdtSegment->at(i_hit).isOutlier = 0;
590 mdtSegment->at(i_hit).isOutlier = 2;
595 for (
unsigned int i_hit=0; i_hit<mdtSegment->size(); i_hit++) {
597 unsigned int i_layer =mdtSegment->at(i_hit).Layer;
598 if (mdtSegment->at(i_hit).isOutlier>1)
continue;
599 if (i_layer > i_layer_max) i_layer_max = i_layer;
601 MdtLayerHits[i_station][i_layer]++;
602 MdtLayerHits_index[i_station][i_layer].push_back(i_hit);
605 std::vector<unsigned int> Ly_1st;
607 std::vector<float> Line_A;
608 std::vector<float> Line_B;
609 std::vector<float> Line_Chi2;
610 std::vector<unsigned int> Line_count;
611 std::vector<float> Line_Xor;
612 std::vector<float>Line_Yor ;
613 std::vector<float>Line_Amid;
614 std::vector<float>Line_Xmid;
615 std::vector<float>Line_Ymid;
616 std::vector<float> Line_sum_Z;
617 std::vector<float> Line_sum_R;
618 std::vector<float> Line_rm;
619 std::vector<float> Line_phim;
620 std::vector<float> Maxlayers_A;
621 std::vector<float> Maxlayers_B;
622 std::vector<float> Maxlayers_Chi2;
623 std::vector<float> Maxlayers_RESI;
624 float Maxlayers_Phim = 0;
625 float Maxlayers_R = 0;
626 float Maxlayers_Z = 0;
627 float Maxlayers_Xor = 0;
628 float Maxlayers_Yor = 0;
629 float Maxlayers_PChi2 = 0;
633 Maxlayers_Chi2.clear();
634 Maxlayers_RESI.clear();
636 for (
unsigned int i_layer=0; i_layer<=i_layer_max; i_layer++) {
638 if (MdtLayerHits[i_station][i_layer]==0)
continue;
640 Ly_1st.push_back(i_layer);
643 const int real_layer= Ly_1st.size();
644 std::vector<std::vector<unsigned int> > Ly_flg;
646 for (
int pr=real_layer;
pr>=3;
pr--) {
666 for (
unsigned int i=0;
i<Ly_flg.size();
i++) {
668 std::vector<std::vector<int> >tID;
670 std::vector<std::vector<int> >tIndex;
676 for (
int ti=0; ti<8; ti++) {
677 for (
int tj=0; tj<2; tj++) {
679 tubeindex[ti][tj] = 0;
683 for (
unsigned int j=0; j<Ly_flg[
i].size(); j++) {
685 int i_layer = Ly_flg[
i][j];
686 std::vector<int> tid;
688 std::vector<int> tindex;
690 if (MdtLayerHits[i_station][i_layer]==0)
continue;
692 float tube_1st = 999999.;
693 float tube_2nd = 999999.;
695 int layer_2nd = 9999;
697 for (
unsigned int i_hit=0; i_hit< MdtLayerHits[i_station][i_layer]; i_hit++) {
699 unsigned int i_index = MdtLayerHits_index[i_station][i_layer].at(i_hit);
701 if (mdtSegment->at(i_index).isOutlier>1)
continue;
703 float nbw3 = (mdtSegment->at(i_index).Z)*(aw) + (avR[i_station]-(aw)*avZ[i_station]) ;
704 float dis_tube = std::abs(std::abs(nbw3-mdtSegment->at(i_index).R)- mdtSegment->at(i_index).DriftSpace);
706 if (dis_tube<tube_1st) {
708 layer_2nd = layer_1st;
711 }
else if (dis_tube<tube_2nd) {
717 if ( layer_1st != 9999 ) {
718 mdtSegment->at(layer_1st).isOutlier = 0;
720 tindex.push_back(layer_1st);
723 if ( layer_2nd != 9999 ) {
724 mdtSegment->at(layer_2nd).isOutlier = 1;
726 tindex.push_back(layer_2nd);
730 tIndex.push_back(tindex);
733 for (
unsigned int ti=0; ti<tID.size();ti++) {
734 for (
unsigned int tj=0; tj<tID[ti].size();tj++) {
735 tube_ID[ti][tj] = tID[ti][tj];
736 tubeindex[ti][tj] = tIndex[ti][tj];
740 std::vector<int> isg;
741 std::vector<int> hitarray;
743 int ntry = (
int)floor(
pow(2.,
pr))-1;
745 for (
int ntryi=0; ntryi<=ntry; ntryi++) {
751 for (
int ntryj=1; ntryj<=
pr; ntryj++) {
753 int Isg = (ntryi&(
int)
pow(2.,ntryj-1))? 1 : 0;
755 if (tube_ID[ntryj-1][Isg] != 0) yhit = 1;
756 sumid = sumid * yhit;
760 for (
unsigned int tt=0;
tt<isg.size();
tt++) {
761 int tindex = tubeindex[
tt][isg[
tt]];
762 hitarray.push_back(tindex);
773 float sum_Z_used = 0.;
774 float sum_R_used = 0.;
776 if (hitarray.size()==0)
continue;
778 for (itMdtHit=mdtSegment->begin(); itMdtHit!=mdtSegment->end(); ++itMdtHit) {
782 if(mdtSegment->at(hit_index).isOutlier>1)
continue;
788 for (
unsigned int j=0; j<hitarray.size(); j++) {
790 if (hitarray[j]==hit_index) {
801 rm = itMdtHit->cYmid;
802 Amid = itMdtHit->cAmid;
803 Xmid = itMdtHit->cXmid;
804 Ymid = itMdtHit->cYmid;
812 phim = itMdtHit->cPhip;
813 sigma = (std::abs(itMdtHit->DriftSigma) >
ZERO_LIMIT)? itMdtHit->DriftSigma: SIGMA;
816 std::abs(itMdtHit->DriftSpace) < DRIFTSPACE_LIMIT &&
817 std::abs(itMdtHit->DriftTime) >
ZERO_LIMIT ) {
823 itMdtHit->DriftSpace:
SetDriftSpace(itMdtHit->DriftTime, itMdtHit->R, itMdtHit->Z, phim, phiDir);
828 if (i_station==3) i_st = 0;
829 if (i_station==4) i_st = 1;
830 if (i_station==5) i_st = 2;
831 pbFitResult.
IDMEA[
count] = i_st*10 + itMdtHit->Layer;
838 sum_Z_used = sum_Z_used + itMdtHit->Z;
839 sum_R_used = sum_R_used + itMdtHit->R;
846 for (
int i=0;
i<pbFitResult.
NPOI;
i++) {
848 <<
i <<
"/" << pbFitResult.
XILIN[
i] <<
"/" << pbFitResult.
YILIN[
i]
849 <<
"/" << pbFitResult.
RILIN[
i] <<
"/" << pbFitResult.
WILIN[
i]);
852 if (
count >= MIN_MDT_FOR_FIT) {
859 for (
int cand=0; cand<6; cand++) {
862 Line_A.push_back(1/pbFitResult.
SlopeCand[cand]);
864 Line_Chi2.push_back(pbFitResult.
Chi2Cand[cand]);
865 Line_count.push_back(pbFitResult.
NPOI);
866 Line_Xor.push_back(Xor);
867 Line_Yor .push_back(Yor);
868 Line_Amid.push_back(Amid);
869 Line_Xmid.push_back(Xmid);
870 Line_Ymid.push_back(Ymid);
871 Line_sum_Z.push_back(sum_Z_used/
count);
872 Line_sum_R.push_back(sum_R_used/
count);
873 Line_rm.push_back(rm);
874 Line_phim.push_back(phim);
881 if (Line_Chi2.size()==0)
continue;
883 std::multimap<float, int>chi_map;
885 std::vector<float> t_A;
886 std::vector<float> t_B;
887 std::vector<float> t_Chi2;
888 std::vector<float> t_count;
889 std::vector<float> t_Xor;
890 std::vector<float> t_Yor;
891 std::vector<float> t_Amid;
892 std::vector<float> t_Xmid;
893 std::vector<float> t_Ymid;
894 std::vector<float> t_sum_Z;
895 std::vector<float> t_sum_R;
896 std::vector<float> t_rm;
897 std::vector<float> t_phim;
913 for (
unsigned int ir=0;
ir<Line_Chi2.size();
ir++) chi_map.insert(std::make_pair(Line_Chi2.at(
ir),
ir));
916 t_A.push_back(Line_A.at(jt->second));
917 t_B.push_back(Line_B.at(jt->second));
918 t_Chi2.push_back(Line_Chi2.at(jt->second));
919 t_count.push_back(Line_count.at(jt->second));
920 t_Xor.push_back(Line_Xor.at(jt->second));
921 t_Yor.push_back(Line_Yor.at(jt->second));
922 t_Amid.push_back(Line_Amid.at(jt->second));
923 t_Xmid.push_back(Line_Xmid.at(jt->second));
924 t_Ymid.push_back(Line_Ymid.at(jt->second));
925 t_sum_Z.push_back(Line_sum_Z.at(jt->second));
926 t_sum_R.push_back(Line_sum_R.at(jt->second));
927 t_rm.push_back(Line_rm.at(jt->second));
928 t_phim.push_back(Line_phim.at(jt->second));
930 Maxlayers_A.push_back(Line_A.at(jt->second));
931 Maxlayers_B.push_back(Line_B.at(jt->second));
932 Maxlayers_Chi2.push_back(Line_Chi2.at(jt->second));
936 superPoint->
Npoint = t_count[0];
937 if(i_station==4 &&
pr==real_layer){
938 Maxlayers_Z = t_sum_Z[0];
939 Maxlayers_R = t_A[0]*t_sum_Z[0]+t_B[0];
940 Maxlayers_Phim = t_phim[0];
941 Maxlayers_Xor = t_Xor[0];
942 Maxlayers_Yor = t_Yor[0];
943 Maxlayers_PChi2 = pbFitResult.
PCHI2;
944 Maxlayers_N = t_count[0];
947 if (s_address == -1) {
950 superPoint->
Z = t_sum_Z[0];
951 superPoint->
R = t_A[0]*t_sum_Z[0]+t_B[0];
952 superPoint->
Alin =t_A[0];
953 superPoint->
Blin =t_B[0];
956 superPoint->
Phim = t_phim[0];
957 superPoint->
Xor = t_Xor[0];
958 superPoint->
Yor = t_Yor[0];
959 superPoint->
Chi2 = t_Chi2[0];
964 for (
int cand=0; cand<6; cand++) {
968 superPoint->
Chi2Cand[cand] = t_Chi2[cand];
983 for (
int cand=0; cand<6; cand++) {
993 ATH_MSG_DEBUG(
"... Superpoint chamber/s_address/count/R/Z/Alin/Blin/Phim/Xor/Yor/Chi2/PChi2="
994 << i_station <<
"/" << s_address <<
"/" <<
count <<
"/"
995 << superPoint->
R <<
"/" << superPoint->
Z <<
"/" << superPoint->
Alin <<
"/"
996 << superPoint->
Blin <<
"/" << superPoint->
Phim <<
"/" << superPoint->
Xor <<
"/"
997 << superPoint->
Yor <<
"/" << superPoint->
Chi2 <<
"/" << superPoint->
PChi2);
1001 if(i_station==4 && Maxlayers_A.size()>0){
1002 superPoint->
Npoint = Maxlayers_N;
1003 superPoint->
Z = Maxlayers_Z;
1004 superPoint->
R = Maxlayers_R;
1005 superPoint->
Alin =Maxlayers_A[0];
1006 superPoint->
Blin =Maxlayers_B[0];
1007 superPoint->
Phim = Maxlayers_Phim;
1008 superPoint->
Xor = Maxlayers_Xor;
1009 superPoint->
Yor = Maxlayers_Yor;
1010 superPoint->
Chi2 = Maxlayers_Chi2[0];
1011 superPoint->
PChi2 = Maxlayers_PChi2;
1012 for (
int cand=0; cand<6; cand++) {
1013 if (std::abs(Maxlayers_A[cand]) >
ZERO_LIMIT ) {
1014 superPoint->
SlopeCand[cand] = Maxlayers_A[cand];
1016 superPoint->
Chi2Cand[cand] = Maxlayers_Chi2[cand];