appends stereo hits to a track.
535 {
536#ifdef TRKRECO_DEBUG_DETAIL
537 std::cout << _name << "(stereo) ... building in 3D" << std::endl;
538 std::cout << "... dump of stereo candidate hits" << std::endl;
539 Dump(list,
"sort flag",
" ");
540#endif
541
542
544#ifdef TRKRECO_DEBUG_DETAIL
545 std::cout << "... rejected by nLinks(";
546 std::cout << list.length() << ") < ";
548#endif
549 return NULL;
550 }
551
552
553 int ichg;
555 else ichg = -1;
556 unsigned nlyr[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
557 unsigned llyr[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
558
559
560
561
562
563
564 unsigned n = list.length();
566 unsigned iforLine = 0;
567 for (
unsigned i = 0; i <
n; i++) {
569
571 TMLink * lnext = list[i + 1];
572
573
574
575 int LorR = consectiveHits(* l, * lnext, ichg);
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
592
593
597 }
598 else {
601 }
602
603
606 if(err1 == 0 && err2 == 0){
607 double deltaZ = fabs(l->
position().y() -
609 if (deltaZ < 1.5) {
610
611
614 l->
zPair(iforLine + 1);
615 lnext->
zPair(iforLine);
616 }
617#ifdef TRKRECO_DEBUG_DETAIL
618 else {
619 std::cout << " ... rejected because delta z > 1.5";
620 std::cout << std::endl;
621 }
622#endif
623 }
624#ifdef TRKRECO_DEBUG_DETAIL
625 else {
626 if (err1) {
627 std::cout << " ... s-z calculation error with ";
628 std::cout << l->
wire()->
name() << std::endl;
629 }
630 if (err2) {
631 std::cout << " ... s-z calculation error with ";
632 std::cout << lnext->
wire()->
name() << std::endl;
633 }
634 }
635#endif
636 }
637 }
638
639
640
646 if (err) {
648 continue;
649 }
650 else {
651
654
655
657
659 iforLine += 1;
660 }
661 }
662 else {
663
664
670 if(err){
671 delete tl;
672 }
673 else {
674
676 forLine.append(tl);
677
678
680
682
683 iforLine += 1;
684 }
685
686
692 if(err) {
694 }
695 else{
696
699
700
702
704 iforLine += 1;
705 }
706 }
707 }
708
709#ifdef TRKRECO_DEBUG_DETAIL
710 std::cout << "... dump of sz links" << std::endl;
711 Dump(forLine,
"sort flag",
" ");
712 for (unsigned i = 0; i < 18; i++) {
713 std::cout << i << " : " << nlyr[i] << ", " << llyr[i] << std::endl;
714 }
715#endif
716
717
719#ifdef TRKRECO_DEBUG_DETAIL
720 std::cout << "... rejected by sz nLinks(";
721 std::cout << forLine.length() << ") < ";
723#endif
724 HepAListDeleteAll(forLine);
725 return NULL;
726 }
727
728
734 double min_chi2[5] = {9999.,9999.,9999.,9999.,9999.};
735 double min_a[5] = {9999.,9999.,9999.,9999.,9999.};
736
737#ifdef TRKRECO_DEBUG_DETAIL
738
739
740
741
742
743 bool display = false;
744
745
746
747
748#endif
749
750
751 for (unsigned isl=0; isl < 5; isl++) {
754
755#ifdef TRKRECO_DEBUG_DETAIL
756 std::cout << " ... stereo supter layer " << isl << std::endl;
757#endif
758
759
760 if (isl < 2) {
761
762
764 ->first()->axialStereoLayerId();
765 unsigned ily2 = ily1 + 1;
766 unsigned ily3 = ily2 + 1;
767
768
769 unsigned ilst = llyr[ily1] + 1;
770 unsigned ifst = ilst - nlyr[ily1];
771 for (unsigned i =ifst; i<ilst; i++) {
772 TMLink & l = * forLine[i];
773 tmpLine.append(l);
776 if (l.
zPair() < i ) {
777 tmpLine.append(m);
778 }
779 else {
780
781 tmpLine.remove(l);
782 continue;
783 }
784 }
785
786
787 unsigned jlst = llyr[ily2] + 1;
788 unsigned jfst = jlst - nlyr[ily2];
789 for (unsigned j =jfst; j< jlst; j++) {
790 TMLink & l2 = * forLine[j];
791 tmpLine.append(l2);
794 if (l2.
zPair() < j) {
795 tmpLine.append(m2);
796 }
797 else {
798
799 tmpLine.remove(l2);
800 continue;
801 }
802 }
803
804
805 unsigned klst = llyr[ily3] + 1;
806 unsigned kfst = klst - nlyr[ily3];
807 for (unsigned k=kfst; k < klst; k++) {
808 TMLink & l3 = * forLine[k];
809 tmpLine.append(l3);
812 if (l3.
zPair() < k) {
813 tmpLine.append(m3);
814 }
815 else {
816
817 tmpLine.remove(l3);
818 continue;
819 }
820 }
821
822
823
824
825
826
827
828 int relation12 = -1;
829 int relation23 = -1;
830
831
834 isl);
835
836 if (l.
zStatus() == 20 && relation12 < 0)
839 isl);
840
841
844 isl);
845 if (l.
zStatus() == 20 && relation23 < 0)
848 isl);
849
850
851 if(relation12 || relation23 ) {
852#ifdef TRKRECO_DEBUG_DETAIL
853 std::cout << " ... bad relations";
854 std::cout << " : segment rejected";
855 Dump(tmpLine,
"detail stereo",
" ");
856 if (display) {
858 int err = line.fit();
859
860
861
862
863 }
864#endif
865
866 tmpLine.remove(l3);
867 if (l3.
zStatus() == 20) tmpLine.remove(m3);
868 continue;
869 }
870
871
872 unsigned ntmp = tmpLine.length();
873 if(ntmp < 3) {
874 std::cout << "!!! is this possible !!!???" << std::endl;
875
876 tmpLine.remove(l3);
877 if(l3.
zStatus() == 20) tmpLine.remove(m3);
878 continue;
879 }
880
881
883 int err = line.fit();
884 if (err < 0) {
885#ifdef TRKRECO_DEBUG_DETAIL
886 std::cout << " ... line fit error";
887 std::cout << " : segment rejected" << std::endl;
888 Dump(line.links(),
"detail stereo",
" ");
889 if (display) {
890
891
892
893
894 }
895#endif
896
897 tmpLine.remove(l3);
898 if(l3.
zStatus() == 20) tmpLine.remove(m3);
899 continue;
900 }
901
902
903
904
905 double chi2 = line.reducedChi2();
908 chi2 < min_chi2[isl]) {
909 goodLine = tmpLine;
910 min_chi2[isl] = chi2;
911 min_a[isl] = line.a();
912#ifdef TRKRECO_DEBUG_DETAIL
913 std::cout << " ... segment accepted : " << std::endl;
914#endif
915 }
916#ifdef TRKRECO_DEBUG_DETAIL
917 else {
918 std::cout << " ... bad quality : segment rejected :";
919 std::cout << "chi2=" << chi2;
920 std::cout << ", b=" << line.b() << std::endl;
921 }
922 Dump(line.links(),
"detail stereo",
" ");
923 if (display) {
924
925
926
927
928 }
929#endif
930
931
932 if(l3.
zStatus() ==20) tmpLine.remove(m3);
933 tmpLine.remove(l3);
934 }
935
936 if(l2.
zStatus() ==20) tmpLine.remove(m2);
937 tmpLine.remove(l2);
938 }
939
940 if(l.
zStatus() ==20) tmpLine.remove(m);
941 tmpLine.remove(l);
942 }
943
944
945 if(isl==0) gdSLine0 = goodLine;
946 if(isl==1) gdSLine1 = goodLine;
947 goodLine.removeAll();
948
949 }
950 else {
951
952
953
954
955
957 ->first()->axialStereoLayerId();
958 unsigned ily2 = ily1 + 1;
959 unsigned ily3 = ily2 + 1;
960 unsigned ily4 = ily3 + 1;
961 if (nlyr[ily1] == 0 ||
962 nlyr[ily2] == 0 ||
963 nlyr[ily3] == 0 ||
964 nlyr[ily4] == 0) continue;
965
966
967 unsigned ilst = llyr[ily1] + 1;
968 unsigned ifst = ilst - nlyr[ily1];
969 for(unsigned i =ifst; i<ilst;i++ ){
970 TMLink & l = * forLine[i];
971 tmpLine.append(l);
975 tmpLine.append(m);
976 } else {
977 tmpLine.remove(l);
978 continue;
979 }
980 }
981
982
983 unsigned jlst = llyr[ily2] + 1;
984 unsigned jfst = jlst - nlyr[ily2];
985 for(unsigned j =jfst; j< jlst; j++){
986 TMLink & l2 = * forLine[j];
987 tmpLine.append(l2);
991 tmpLine.append(m2);
992 } else {
993 tmpLine.remove(l2);
994 continue;
995 }
996 }
997
998
999 unsigned klst = llyr[ily3] + 1;
1000 unsigned kfst = klst - nlyr[ily3];
1001 for( unsigned k=kfst; k < klst; k++ ){
1002 TMLink & l3 = * forLine[k];
1003 tmpLine.append(l3);
1007 tmpLine.append(m3);
1008 } else {
1009 tmpLine.remove(l3);
1010 continue;
1011 }
1012 }
1013
1014
1015 unsigned hlst = llyr[ily4] + 1;
1016 unsigned hfst = hlst - nlyr[ily4];
1017 for( unsigned h=hfst; h < hlst; h++ ){
1018 TMLink & l4 = * forLine[h];
1019 tmpLine.append(l4);
1023 tmpLine.append(m4);
1024 } else {
1025 tmpLine.remove(l4);
1026 continue;
1027 }
1028 }
1029
1030
1031
1032
1033
1034
1035
1036
1037 int relation12 = -1;
1038 int relation23 = -1;
1039 int relation34 = -1;
1040
1041
1042
1043
1044
1045
1046
1049 isl);
1050 if (l.
zStatus() == 20 && relation12 < 0)
1051 relation12 =
1054 isl);
1055
1056
1059 isl);
1060 if (l.
zStatus() == 20 && relation23 < 0)
1061 relation23 =
1064 isl);
1065
1066
1069 isl);
1070 if (l3.
zStatus() == 20 && relation34 < 0)
1071 relation34 =
1074 isl);
1075
1076
1077 if(relation12 || relation23 || relation34) {
1078
1079#ifdef TRKRECO_DEBUG_DETAIL
1080 std::cout << " ... bad relations";
1081 std::cout << " : segment rejected";
1082 Dump(tmpLine,
"detail stereo",
" ");
1083 if (display) {
1085 int err = line.fit();
1086
1087
1088
1089
1090 }
1091#endif
1092
1093 tmpLine.remove(l4);
1094 if(l4.
zStatus() == 20) tmpLine.remove(m4);
1095 continue;
1096 }
1097
1098
1099 unsigned ntmp = tmpLine.length();
1100 if(ntmp < 4) {
1101 tmpLine.remove(l4);
1102 if(l4.
zStatus() == 20) tmpLine.remove(m4);
1103 continue;
1104 }
1105
1106
1108 int err = line.fit();
1109 if (err < 0) {
1110#ifdef TRKRECO_DEBUG_DETAIL
1111 std::cout << " ... line fit error";
1112 std::cout << " : segment rejected" << std::endl;
1113 Dump(line.links(),
"detail stereo",
" ");
1114 if (display) {
1115
1116
1117
1118
1119 }
1120#endif
1121
1122 tmpLine.remove(l4);
1123 if(l4.
zStatus() == 20) tmpLine.remove(m4);
1124 continue;
1125 }
1126
1127
1128
1129 double chi2 = line.reducedChi2();
1132 chi2 < min_chi2[isl]) {
1133
1134
1135 goodLine = tmpLine;
1136 min_chi2[isl] = chi2;
1137 min_a[isl] = line.a();
1138
1139#ifdef TRKRECO_DEBUG_DETAIL
1140 std::cout << " segment accepted : " << std::endl;
1141#endif
1142 }
1143#ifdef TRKRECO_DEBUG_DETAIL
1144 else {
1145 std::cout << " ... bad quality : segment rejected :";
1146 std::cout << " chi2=" << chi2;
1147 std::cout << ", b=" << line.b() << std::endl;
1148 }
1149 Dump(line.links(),
"detail stereo",
" ");
1150 if (display) {
1151
1152
1153
1154
1155 }
1156#endif
1157
1158
1159 if(l4.
zStatus() ==20) tmpLine.remove(m4);
1160 tmpLine.remove(l4);
1161 }
1162
1163 if(l3.
zStatus() ==20) tmpLine.remove(m3);
1164 tmpLine.remove(l3);
1165 }
1166
1167 if(l2.
zStatus() ==20) tmpLine.remove(m2);
1168 tmpLine.remove(l2);
1169 }
1170
1171 if(l.
zStatus() ==20) tmpLine.remove(m);
1172 tmpLine.remove(l);
1173 }
1174
1175
1176 if(isl==2) gdSLine2 = goodLine;
1177 if(isl==3) gdSLine3 = goodLine;
1178 if(isl==4) gdSLine4 = goodLine;
1179 goodLine.removeAll();
1180 }
1181 }
1182
1183
1184
1185
1186
1187 unsigned Nsgmnts[5] = {0,0,0,0,0};
1188 Nsgmnts[0] = gdSLine0.length();
1189 Nsgmnts[1] = gdSLine1.length();
1190 Nsgmnts[2] = gdSLine2.length();
1191 Nsgmnts[3] = gdSLine3.length();
1192 Nsgmnts[4] = gdSLine4.length();
1193
1194 unsigned NusedSgmnts = 0;
1195 for(unsigned jsl = 0; jsl < 5; jsl++) {
1196 if(Nsgmnts[jsl] > 0) NusedSgmnts +=1;
1197 }
1198
1199
1200 if (NusedSgmnts == 0) {
1201#ifdef TRKRECO_DEBUG_DETAIL
1202 std::cout << "... rejected because no segment found" << std::endl;
1203#endif
1204 HepAListDeleteAll(forLine);
1205 return NULL;
1206 }
1207
1208
1210 forNewLine.append(gdSLine0);
1211 forNewLine.append(gdSLine1);
1212 forNewLine.append(gdSLine2);
1213 forNewLine.append(gdSLine3);
1214 forNewLine.append(gdSLine4);
1215
1216
1217 unsigned nNewLine = forNewLine.length();
1219 TLine0 newLine(forNewLine);
1220
1221
1222 int err = newLine.fit();
1223
1224 double newLine_chi2 = newLine.reducedChi2();
1225 double newLine_a = newLine.a();
1226
1227
1228
1229
1230
1231 if(((R > 80. && newLine_chi2 > 4.0) ||(R < 80. && newLine_chi2 > 13.0))&& NusedSgmnts > 1){
1232
1233 double max_diff_a = 0.;
1234 unsigned this_sly = 999;
1235 for(unsigned isl=0; isl < 5; isl++){
1236 if(Nsgmnts[isl]==0) continue;
1237 double diff_a = fabs((min_a[isl]-newLine_a)/newLine_a);
1238 if(diff_a > max_diff_a){
1239 max_diff_a = diff_a;
1240 this_sly = isl;
1241 }
1242 }
1243
1244
1245 if((R< 50. && max_diff_a > 0.4) || (R > 50. && max_diff_a > 0.3)) {
1246
1247
1248 Nsgmnts[this_sly]=0;
1249
1250
1251 if(this_sly == 0){
1252 newLine.removeSLY(gdSLine0);
1253 } else if (this_sly == 1){
1254 newLine.removeSLY(gdSLine1);
1255 } else if (this_sly == 2){
1256 newLine.removeSLY(gdSLine2);
1257 } else if (this_sly == 3){
1258 newLine.removeSLY(gdSLine3);
1259 } else if (this_sly == 4){
1260 newLine.removeSLY(gdSLine4);
1261 }
1262
1263
1264 unsigned NnewLine_2 = newLine.links().length();
1265 if(NnewLine_2 < 3) {
1266#ifdef TRKRECO_DEBUG_DETAIL
1267 std::cout << "... rejected because of few links for line" << std::endl;
1268#endif
1269 HepAListDeleteAll(forLine);
1270 return NULL;
1271 }
1272
1273 int err = newLine.fit();
1274 if (err < 0) {
1275#ifdef TRKRECO_DEBUG_DETAIL
1276 std::cout << "... rejected because of line fit failure" << std::endl;
1277#endif
1278 HepAListDeleteAll(forLine);
1279 return NULL;
1280 }
1281 double newLine_chi2_2 = newLine.chi2()/NnewLine_2;
1282 }
1283 }
1284
1285
1287 double maxSigma = 1.0;
1288 if(R < 80) maxSigma = 1.5;
1289 newLine.refine(bad, maxSigma);
1290 if(newLine.links().length()< 2) {
1291#ifdef TRKRECO_DEBUG_DETAIL
1292 std::cout << "... rejected because of few links for line after refine";
1293 std::cout << std::endl;
1294#endif
1295 HepAListDeleteAll(forLine);
1296 return NULL;
1297 }
1298 err = newLine.fit();
1299 if (err < 0) {
1300#ifdef TRKRECO_DEBUG_DETAIL
1301 std::cout << "... rejected because of line fit failure(2)" << std::endl;
1302#endif
1303 HepAListDeleteAll(forLine);
1304 return NULL;
1305 }
1306
1307
1308 for(unsigned isl = 0; isl < 5; isl++){
1309 if(Nsgmnts[isl] == 0) {
1310 double maxdist = 0.5;
1311 if(R < 80) maxdist = 1.25;
1312 newLine.appendByszdistance(forLine, 2*isl+1, maxdist);
1313 }
1314 }
1315 err = newLine.fit();
1316 if (err < 0) {
1317#ifdef TRKRECO_DEBUG_DETAIL
1318 std::cout << "... rejected because of line fit failure(3)" << std::endl;
1319#endif
1320 HepAListDeleteAll(forLine);
1321 return NULL;
1322 }
1323
1324
1325 maxSigma = 1.0;
1326 newLine.refine(bad, maxSigma);
1327 if(newLine.links().length()< 2) {
1328#ifdef TRKRECO_DEBUG_DETAIL
1329 std::cout << "... rejected because of few links for line after 2nd refine";
1330 std::cout << std::endl;
1331#endif
1332 HepAListDeleteAll(forLine);
1333 return NULL;
1334 }
1335
1336
1337 err = newLine.fit();
1338 if (err < 0) {
1339 HepAListDeleteAll(forLine);
1340#ifdef TRKRECO_DEBUG_DETAIL
1341 std::cout << " appendStereo cut ... new line 2nd linear fit failure. ";
1342 std::cout <<
"# of links = " <<
n <<
",";
1343 std::cout << "," << nNewLine << std::endl;
1344#endif
1345 return NULL;
1346 }
1347
1348
1349 unsigned NnewLine_3 = newLine.links().length();
1350 double newLine_chi2_3 = newLine.chi2()/NnewLine_3;
1351
1352
1353
1354
1355
1357 unsigned nn = good.length();
1358 for (unsigned i = 0; i < nn; i++) {
1359 track.
append(* good[i]->link());
1360 }
1361
1362
1365 a[3] = newLine.b();
1366 a[4] = track.
charge() * newLine.a();
1368
1369
1371 if (err < 0) goto discard;
1374 if (err < 0) goto discard;
1377 if (err < 0) goto discard;
1380 if (err < 0) goto discard;
1381
1382
1384
1385
1386 HepAListDeleteAll(forLine);
1387 return & track;
1388
1389
1390discard:
1391#ifdef TRKRECO_DEBUG_DETAIL
1392 std::cout << " ... rejected by fitting failure : ";
1393 std::cout << " err = " << err << std::endl;
1394#endif
1395 HepAListDeleteAll(forLine);
1396 return NULL;
1397}
const HepVector & a(void) const
returns helix parameters.
A class to represent a track in tracking.
unsigned axialStereoLayerId(void) const
returns id of axial or stereo id.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
const TMDCLayer *const layer(void) const
returns a pointer to a layer.
unsigned localId(void) const
returns local id in a wire layer.
static TMDC * getTMDC(void)
const AList< TMDCLayer > *const superLayer(unsigned id) const
returns a pointer to a super-layer. 0 will be returned if 'id' is invalid.
TMLink * link(void) const
returns a pointer to a TMLink.
int zPair(void) const
returns id# of the pair, if zStatus == 20 (2 consective hits).
unsigned leftRight(void) const
returns left-right. 0:left, 1:right, 2:wire
int zStatus(void) const
returns stauts of stereo hit
const HepPoint3D & position(void) const
returns position.
unsigned nLinksStereo(void) const
returns min. # of stereo hits(TMLinks) requried.
void append(TMLink &)
appends a TMLink.
const Helix & helix(void) const
returns helix parameter.
int szPosition(TMLink &link) const
calculates arc length and z for a stereo hit.
double charge(void) const
returns charge.
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)