14#include "TrkReco/TBuilder.h"
15#include "TrkReco/TCircle.h"
16#include "TrkReco/TLine0.h"
17#include "TrkReco/TLine2D.h"
18#include "TrkReco/TMDC.h"
19#include "TrkReco/TMDCWire.h"
20#include "TrkReco/TMDCWireHit.h"
21#include "TrkReco/TMLine.h"
22#include "TrkReco/TMLink.h"
23#include "TrkReco/TPoint2D.h"
24#include "TrkReco/TRobustLineFitter.h"
25#include "TrkReco/TSegment.h"
26#include "TrkReco/TTrack.h"
28# include "TrkReco/TMDCWireHitMC.h"
29# include "TrkReco/TTrackHEP.h"
32# include "TrkReco/TWindow.h"
37 float salvageLevel,
float szSegmentDistance,
float szLinkDistance,
38 unsigned fittingFlag )
40 , _fitter(
"TBuilder Fitter" )
41 , _maxSigma( maxSigma )
42 , _maxSigmaStereo( maxSigmaStereo )
43 , _salvageLevel( sqrt( salvageLevel ) )
48 _szSegmentDistance( szSegmentDistance )
49 , _szLinkDistance( szLinkDistance ) {
50 if ( fittingFlag & 1 ) _fitter.sag(
true );
51 if ( fittingFlag & 2 ) _fitter.propagation(
true );
52 if ( fittingFlag & 4 ) _fitter.tof(
true );
53 if ( fittingFlag & 8 ) _fitter.freeT0(
true );
58void TBuilder::dump(
const std::string& msg,
const std::string& pre )
const {}
63 std::cout <<
"... building rphi by segments : # of segments = ";
64 std::cout << list.length() << std::endl;
65 for (
unsigned i = 0; i < list.length(); i++ ) list[i]->
dump(
"hits sort flag",
" " );
85 unsigned n = list.length();
86 for (
unsigned i = 0; i <
n; i++ )
92 t->segments().append( segment );
103 std::cout <<
"... building rphi by links : # of links = ";
104 std::cout << list.length() << std::endl;
113 cout <<
" ... cores..." << endl;
114 for (
int ii = 0; ii < cores.length(); ++ii )
116 cout <<
"layer: " << cores[ii]->wire()->layerId()
117 <<
" local: " << cores[ii]->wire()->localId() << endl;
119 cout <<
" ...noncores..." << endl;
120 for (
int ii = 0; ii < nonCores.length(); ++ii )
122 cout <<
"layer: " << nonCores[ii]->wire()->layerId()
123 <<
" local: " << nonCores[ii]->wire()->localId() << endl;
127 unsigned nCores = cores.length();
128 if ( nCores < _minNCores )
131 std::cout <<
"... building rphi failure : # of cores(=" << nCores;
132 std::cout <<
") is less then " << _minNCores << std::endl;
140 std::cout <<
"links in list = " << list.length() << std::endl;
141 std::cout <<
"... making a circle : # cores =" << cores.length() << std::endl;
148 std::cout <<
"... building rphi failure : circle fit error = ";
149 std::cout << err << std::endl;
158 err = _fitter.fit( *
t );
161 if ( err < 0 )
goto discard;
162 t->refine( bad, _maxSigma * 100. );
165 err = _fitter.fit( *
t );
168 t->refine( bad, _maxSigma * 10. );
171 err = _fitter.fit( *
t );
174 t->refine( bad, _maxSigma );
177 err = _fitter.fit( *
t );
180 if ( err < 0 )
goto discard;
181#ifdef TRKRECO_DEBUG_DETAIL
182 c.
dump(
"detail",
" ccl> " );
183 t->dump(
"detail",
" 1st> " );
188 std::cout <<
"... appending non-core hits : # = " << nonCores.length();
189 std::cout << std::endl;
191 t->appendByApproach( nonCores, _salvageLevel );
193 t->dump(
"hits sort flag",
" " );
201 std::cout <<
"... building rphi failure : helix fit error = ";
202 std::cout << err << std::endl;
211 std::cout <<
"... salvaging(TBuilder) : # of given hits=" << hits.length();
212 std::cout <<
", salvage level=" << _salvageLevel << std::endl;
213 Dump( hits,
"hits sort flag" );
216 unsigned nHits = hits.length();
217 if ( nHits == 0 )
return;
220 t.appendByApproach( hits, _salvageLevel );
227 std::cout <<
"... salvaging by segments : # of segments = ";
228 std::cout << list.length() << std::endl;
229 for (
unsigned i = 0; i < list.length(); i++ ) list[i]->
dump(
"hits sort flag",
" " );
234 unsigned n = list.length();
235 for (
unsigned i = 0; i <
n; i++ ) links.append( list[i]->links() );
244 if ( list.length() < 2 )
return NULL;
249 unsigned n = list.length();
250 for (
unsigned i = 0; i <
n; i++ )
252 unsigned j = list[i]->superLayerId() / 2;
253 sl[j].append( list[i] );
254 tl[j].append( lList[i] );
257 std::cout <<
" ... initialLine1 : super layer ptn = ";
258 for (
unsigned i = 0; i < 5; i++ ) std::cout << sl[i].length();
259 std::cout << std::endl;
263 unsigned nSingle = 0;
264 for (
unsigned i = 0; i < 5; i++ )
265 if ( sl[i].length() == 1 ) ++nSingle;
267 std::cout <<
" ... # of single segment layer = " << nSingle << std::endl;
269 if ( nSingle < 2 )
return NULL;
274 for (
unsigned i = 0; i < 5; i++ )
276 if ( sl[i].length() != 1 )
continue;
277 bestCombination.append( sl[i] );
278 forLine.append( tl[i] );
281 int err = line.
fit();
292 std::cout <<
" ... initlialLine2 : # of links = " << lList.length();
293 std::cout << std::endl;
299 int err = fitter.
fit( *line );
313 unsigned n = list.length();
314 for (
unsigned i = 0; i <
n; i++ )
317 int err =
t.szPosition( *list[i], l );
320 bad.append( list[i] );
328 bad.append( list[i] );
338 unsigned nAMaxSL = 0;
339 unsigned nAMinSL = 10;
341 unsigned nA = segments.length();
342 for (
unsigned i = 0; i < nA; i++ )
344 unsigned sl = segments[i]->superLayerId();
345 if ( sl > nAMaxSL ) nAMaxSL = sl;
346 if ( sl < nAMinSL ) nAMinSL = sl;
348 unsigned nExpected = ( nAMaxSL - nAMinSL ) / 2;
350 std::cout <<
" ... initialLine : axial super layer usage = " << nAMinSL;
351 std::cout <<
" ~ " << nAMaxSL << std::endl;
352 std::cout <<
" : expected stereo super layers = ";
353 std::cout << nExpected << std::endl;
368 std::cout <<
" ... initialLine2 : # of selected segments = ";
369 std::cout << tmp.length() << std::endl;
371 if ( ( tmp.length() >= nExpected ) || ( tmp.length() >= 4 ) || last )
383 bool ok = ( tmp.length() >= nExpected );
385 std::cout <<
" ... initialLine2 : # of selected segments = ";
386 std::cout << tmp.length() <<
" : ok, last = ";
387 std::cout << ok <<
", " << last << std::endl;
397 else {
return NULL; }
406 unsigned n = list.length();
407 for (
unsigned i = 0; i <
n; i++ )
410 int err =
t.szPosition( *list[i], l );
413 bad.append( list[i] );
421 bad.append( list[i] );
431 unsigned nAMaxSL = 0;
432 unsigned nAMinSL = 10;
434 unsigned nA = segments.length();
435 for (
unsigned i = 0; i < nA; i++ )
437 unsigned sl = segments[i]->superLayerId();
438 if ( sl > nAMaxSL ) nAMaxSL = sl;
439 if ( sl < nAMinSL ) nAMinSL = sl;
441 unsigned nExpected = ( nAMaxSL - nAMinSL ) / 2;
443 std::cout <<
" ... initialLine : axial super layer usage = " << nAMinSL;
444 std::cout <<
" ~ " << nAMaxSL << std::endl;
445 std::cout <<
" : expected stereo super layers = ";
446 std::cout << nExpected << std::endl;
459 std::cout <<
" ... initialLine1 : # of selected segments = ";
460 std::cout << tmp.length() << std::endl;
462 if ( tmp.length() >= nExpected )
464 lList0.remove( line->
links() );
465 HepAListDeleteAll( lList0 );
476 bool ok = ( tmp.length() >= nExpected );
479 std::cout <<
" ... initialLine2 : # of selected segments = ";
480 std::cout << tmp.length() <<
" : ok, last = ";
481 std::cout << ok <<
", " << last << std::endl;
485 lList0.remove( line->
links() );
486 HepAListDeleteAll( lList0 );
495 HepAListDeleteAll( lList0 );
504 unsigned n = list.length();
505 for (
unsigned i = 0; i <
n; i++ )
507 float distance = line.
distance( *szList[i] );
508 if ( distance < _szSegmentDistance ) outList.append( list[i] );
515 unsigned n = list.length();
516 float maxDistance = 0.;
518 for (
unsigned i = 0; i <
n; i++ )
520 float distance = line.
distance( *szList[i] );
521 if ( distance > maxDistance ) maxId = i;
523 list.remove( maxId );
524 szList.remove( maxId );
529 std::cout <<
"... building stereo by links : # of links = ";
530 std::cout << list.length() << std::endl;
538 unsigned nCores = cores.length();
539 if ( nCores < _minNCores )
542 std::cout <<
"... stereo building failure : # of cores(=" << nCores;
543 std::cout <<
") is less then " << _minNCores << std::endl;
548 sz.appendSz( track, cores, leda_brown );
553 for (
unsigned i = 0; i < nCores; i++ )
556 for (
unsigned i = 0; i < 2; i++ )
561 if ( err ) {
delete &tt; }
564 if ( line.
distance( tt ) < _szLinkDistance )
567 forNewLine.append( tt );
576 std::cout <<
" ... creating a new line" << std::endl;
578 unsigned nNewLine = forNewLine.length();
579 TMLine newLine( forNewLine );
581 int err = fitter.
fit( newLine );
585 HepAListDeleteAll( forNewLine );
586#ifdef TRKRECO_DEBUG_DETAIL
587 std::cout <<
" ... 2nd linear fit failure. nLinks(";
588 std::cout << forNewLine.length() <<
")" << std::endl;
594 sz.append( newLine, leda_green );
598#ifdef TRKRECO_DEBUG_DETAIL
599 Dump( forNewLine,
"sort hits stereo",
" " );
605 for (
unsigned i = 0; i < nNewLine; i++ )
607 if ( last == NULL ) last = forNewLine[i]->link();
610 if ( last == forNewLine[i]->link() )
612 if ( newLine.
distance( *forNewLine[i - 1] ) > newLine.
distance( *forNewLine[i] ) )
613 toRemove.append( forNewLine[i - 1] );
614 else toRemove.append( forNewLine[i] );
617 else { last = forNewLine[i]->link(); }
620 forNewLine.remove( toRemove );
621 nNewLine = forNewLine.length();
623#ifdef TRKRECO_DEBUG_DETAIL
624 Dump( toRemove,
"sort hits stereo",
" x " );
625 Dump( forNewLine,
"sort hits stereo",
" " );
629 for (
unsigned i = 0; i < nNewLine; i++ ) track.
append( *forNewLine[i]->link() );
633 a[4] = track.
charge() * newLine.
a();
634 track._helix->
a( a );
638 err = _fitter.fit( track );
639 track.
refine( bad, _maxSigmaStereo * 100. );
640 err = _fitter.fit( track );
641 track.
refine( bad, _maxSigmaStereo * 10. );
642 err = _fitter.fit( track );
643 track.
refine( bad, _maxSigmaStereo );
644 err = _fitter.fit( track );
647 sz.text(
"stereo finished" );
648 sz.oneShot( track, leda_blue );
652 HepAListDeleteAll( toRemove );
653 HepAListDeleteAll( forNewLine );
662 std::cout <<
"... building stereo by segments : # of segments = ";
663 std::cout << segments.length() << std::endl;
664 for (
unsigned i = 0; i < segments.length(); i++ )
665 segments[i]->
dump(
"hits sort flag",
" " );
671 sz.appendSz(
t, segments, leda_black );
673 std::string
s =
"# of segments = " + std::to_string(
int( segments.length() ) );
681 std::cout <<
"... building stereo failure : no initial line found" << std::endl;
684 s =
"no initial line found : " +
s;
691 sz.append( *line, leda_red );
698 unsigned n = segments.length();
699 for (
unsigned i = 0; i <
n; i++ ) links.append( segments[i]->links() );
708 for (
unsigned i = 0; i <
n; i++ )
714 t.segments().append( segment );
727 std::cout <<
" ... searchInitialLines : # of segments in sl : ";
728 for (
unsigned i = 0; i < 5; i++ ) std::cout << _links[i].length() <<
",";
729 std::cout << std::endl
730 <<
" : max # of super layers=" << nSuperLayerMax
735 if ( nSuperLayerMax > 5 ) lines.append(
searchLines6() );
736 else if ( nSuperLayerMax > 4 ) lines.append(
searchLines5() );
737 else if ( nSuperLayerMax > 3 ) lines.append(
searchLines4() );
738 else if ( nSuperLayerMax > 2 ) lines.append(
searchLines3() );
739 else if ( nSuperLayerMax > 1 ) lines.append(
searchLines2() );
749 for (
unsigned i = 0; i < 6; i++ )
n[i] = _links[i].length();
752 for (
unsigned i0 = 0; i0 <
n[0]; i0++ )
754 for (
unsigned i1 = 0; i1 <
n[1]; i1++ )
756 for (
unsigned i2 = 0; i2 <
n[2]; i2++ )
758 for (
unsigned i3 = 0; i3 <
n[3]; i3++ )
760 for (
unsigned i4 = 0; i4 <
n[4]; i4++ )
762 for (
unsigned i5 = 0; i5 <
n[5]; i5++ )
766 forLine.append( _links[0][i0] );
767 forLine.append( _links[1][i1] );
768 forLine.append( _links[2][i2] );
769 forLine.append( _links[3][i3] );
770 forLine.append( _links[4][i4] );
771 forLine.append( _links[5][i5] );
774 int err = line.
fit();
781 lines.append( line );
790 std::cout <<
" ... searchLines5 : # of lines found = " << lines.length() << std::endl;
800 for (
int i = 0; i < 5; i++ ) l[i] =
nullptr;
801 for (
unsigned skip = 0; skip < 6; skip++ )
811 else if ( skip == 1 ) { l[0] = &_links[0]; }
812 else if ( skip == 2 ) { l[1] = &_links[1]; }
813 else if ( skip == 3 ) { l[2] = &_links[2]; }
814 else if ( skip == 4 ) { l[3] = &_links[3]; }
815 else if ( skip == 5 ) { l[4] = &_links[4]; }
818 for (
unsigned i = 0; i < 5; i++ )
n[i] = l[i]->length();
820 for (
unsigned i0 = 0; i0 <
n[0]; i0++ )
822 for (
unsigned i1 = 0; i1 <
n[1]; i1++ )
824 for (
unsigned i2 = 0; i2 <
n[2]; i2++ )
826 for (
unsigned i3 = 0; i3 <
n[3]; i3++ )
828 for (
unsigned i4 = 0; i4 <
n[4]; i4++ )
832 forLine.append( ( *l[0] )[i0] );
833 forLine.append( ( *l[1] )[i1] );
834 forLine.append( ( *l[2] )[i2] );
835 forLine.append( ( *l[3] )[i3] );
836 forLine.append( ( *l[4] )[i4] );
839 int err = line.
fit();
846 lines.append( line );
855 std::cout <<
" ... searchLines5 : # of lines found = " << lines.length() << std::endl;
865 for (
int i = 0; i < 4; i++ ) l[i] =
nullptr;
866 for (
unsigned skip = 0; skip < 15; skip++ )
875 else if ( skip == 1 ) { l[3] = &_links[4]; }
876 else if ( skip == 2 ) { l[3] = &_links[5]; }
877 else if ( skip == 3 )
882 else if ( skip == 4 ) { l[3] = &_links[5]; }
883 else if ( skip == 5 ) { l[2] = &_links[4]; }
884 else if ( skip == 6 )
890 else if ( skip == 7 ) { l[3] = &_links[5]; }
891 else if ( skip == 8 ) { l[2] = &_links[4]; }
892 else if ( skip == 9 ) { l[1] = &_links[3]; }
893 else if ( skip == 10 )
900 else if ( skip == 11 ) { l[3] = &_links[5]; }
901 else if ( skip == 12 ) { l[2] = &_links[4]; }
902 else if ( skip == 13 ) { l[1] = &_links[3]; }
903 else if ( skip == 14 ) { l[0] = &_links[2]; }
906 for (
unsigned i = 0; i < 4; i++ )
n[i] = l[i]->length();
908 for (
unsigned i0 = 0; i0 <
n[0]; i0++ )
910 for (
unsigned i1 = 0; i1 <
n[1]; i1++ )
912 for (
unsigned i2 = 0; i2 <
n[2]; i2++ )
914 for (
unsigned i3 = 0; i3 <
n[3]; i3++ )
917 forLine.append( ( *l[0] )[i0] );
918 forLine.append( ( *l[1] )[i1] );
919 forLine.append( ( *l[2] )[i2] );
920 forLine.append( ( *l[3] )[i3] );
923 int err = line.
fit();
930 lines.append( line );
938 std::cout <<
" ... searchLines4 : # of lines found = " << lines.length() << std::endl;
948 l[0] = l[1] = l[2] =
nullptr;
949 for (
unsigned skip = 0; skip < 20; skip++ )
957 else if ( skip == 1 ) { l[2] = &_links[3]; }
958 else if ( skip == 2 ) { l[2] = &_links[4]; }
959 else if ( skip == 3 ) { l[2] = &_links[5]; }
960 else if ( skip == 4 ) { l[1] = &_links[2]; }
961 else if ( skip == 5 ) { l[2] = &_links[4]; }
962 else if ( skip == 6 ) { l[2] = &_links[3]; }
963 else if ( skip == 7 )
968 else if ( skip == 8 ) { l[2] = &_links[5]; }
969 else if ( skip == 9 ) { l[1] = &_links[4]; }
970 else if ( skip == 10 ) { l[0] = &_links[1]; }
971 else if ( skip == 11 ) { l[1] = &_links[3]; }
972 else if ( skip == 12 ) { l[2] = &_links[4]; }
973 else if ( skip == 13 ) { l[1] = &_links[2]; }
974 else if ( skip == 14 ) { l[2] = &_links[3]; }
975 else if ( skip == 15 ) { l[2] = &_links[5]; }
976 else if ( skip == 16 )
981 else if ( skip == 17 ) { l[2] = &_links[3]; }
982 else if ( skip == 18 )
987 else if ( skip == 19 ) { l[0] = &_links[3]; }
990 for (
unsigned i = 0; i < 3; i++ )
n[i] = l[i]->length();
992 for (
unsigned i0 = 0; i0 <
n[0]; i0++ )
994 for (
unsigned i1 = 0; i1 <
n[1]; i1++ )
996 for (
unsigned i2 = 0; i2 <
n[2]; i2++ )
999 forLine.append( ( *l[0] )[i0] );
1000 forLine.append( ( *l[1] )[i1] );
1001 forLine.append( ( *l[2] )[i2] );
1004 int err = line.
fit();
1011 lines.append( line );
1018 std::cout <<
" ... searchLines3 : # of lines found = " << lines.length() << std::endl;
1028 l[0] = l[1] =
nullptr;
1029 for (
unsigned skip = 0; skip < 15; skip++ )
1036 else if ( skip == 1 ) { l[1] = &_links[2]; }
1037 else if ( skip == 2 ) { l[1] = &_links[3]; }
1038 else if ( skip == 3 ) { l[1] = &_links[4]; }
1039 else if ( skip == 4 ) { l[1] = &_links[5]; }
1040 else if ( skip == 5 )
1045 else if ( skip == 6 ) { l[1] = &_links[3]; }
1046 else if ( skip == 7 ) { l[1] = &_links[4]; }
1047 else if ( skip == 8 ) { l[1] = &_links[5]; }
1048 else if ( skip == 9 )
1053 else if ( skip == 10 ) { l[1] = &_links[4]; }
1054 else if ( skip == 11 ) { l[1] = &_links[5]; }
1055 else if ( skip == 12 )
1060 else if ( skip == 13 ) { l[1] = &_links[5]; }
1061 else if ( skip == 14 ) { l[0] = &_links[4]; }
1064 for (
unsigned i = 0; i < 2; i++ )
n[i] = l[i]->length();
1066 for (
unsigned i0 = 0; i0 <
n[0]; i0++ )
1068 for (
unsigned i1 = 0; i1 <
n[1]; i1++ )
1071 forLine.append( ( *l[0] )[i0] );
1072 forLine.append( ( *l[1] )[i1] );
1075 int err = line.
fit();
1082 lines.append( line );
1088 std::cout <<
" ... searchLines2 : # of lines found = " << lines.length() << std::endl;
1098 int err = line.
fit();
1099 if ( err ) {
delete &line; }
1100 else { lines.append( line ); }
1103 std::cout <<
" ... searchLines1 : # of lines found = " << lines.length() << std::endl;
1110#ifdef TRKRECO_WINDOW
1111 std::string old = sz.text();
1114 static float _szLinkMaxDistance = 5;
1116 unsigned nLinks = _forLine.length();
1122 unsigned nGoodLinks0 = 0;
1124 unsigned nLoops = 0;
1129 unsigned nGoodLinks = 0;
1130 for (
unsigned i = 0; i < nLinks; i++ )
1132 float distance = line0.
distance( *_forLine[i] );
1133 if ( distance < _szLinkDistance ) targets.append( _forLine[i] );
1134 if ( distance < _szLinkMaxDistance ) { ++nGoodLinks; }
1138 std::cout <<
" ... searchLine : # of close hits(last) = " << nGoodLinks0
1139 <<
", # of close hits = " << nGoodLinks << std::endl;
1143 if ( nGoodLinks0 == nGoodLinks )
break;
1146 TMLine newLine( targets );
1148 int err = fitter.
fit( newLine );
1151#ifdef TRKRECO_WINDOW
1152 std::cout <<
" ... searchLine : failed to fit" << std::endl;
1153 std::string
s =
"line search failed";
1163#ifdef TRKRECO_DEBUG_DETAIL
1164 std::cout <<
" reached to max # of loops(10) : break";
1169#ifdef TRKRECO_WINDOW
1170 std::string ss =
", # of close hits(last) = " + std::to_string(
int( nGoodLinks0 ) ) +
1171 ", # of close hits = " + std::to_string(
int( nGoodLinks ) );
1172 sz.append( line0, leda_brown );
1173 sz.append( newLine, leda_green );
1174 sz.text( old +
", nLoops = " + std::to_string(
int( nLoops ) ) + ss );
1177 sz.remove( newLine );
1181 nGoodLinks0 = nGoodLinks;
1182 targets.removeAll();
1191 unsigned n = links.length();
1192 for (
unsigned i = 1; i <
n; i++ )
1194 if ( links[i - 1]->link() == links[i]->link() )
1196 toRemove.append( links[i] );
1199 if ( i < 2 )
continue;
1200 if ( links[i - 2]->link() == links[i]->link() ) toRemove.append( links[i] );
1202 links.remove( toRemove );
1206 for (
unsigned i = 0; i <
n; i++ )
t.append( *links[i]->link() );
1213 if ( _fitter.getMagneticFieldPointer() == NULL )
1215 std::cout <<
" " << __FILE__ <<
" " << __LINE__ <<
" Could not get MagneticFieldSvc "
1218 const double Bz = -1000 * _fitter.getMagneticFieldPointer()->getReferField();
1221 a[4] =
t.charge() * l.
a();
1225 a[4] = -1. *
t.charge() * l.
a();
1234#ifdef TRKRECO_DEBUG_DETAIL
1235 static unsigned nTrk = 0;
1243 if ( links[0]->hit()->mc() ) pp = links[0]->hit()->mc()->hep()->p().vect();
1249 t.dump(
"detail",
"before fit" );
1250 std::cout <<
"Pdif mag=" << (
t.p() - p0 ).mag() << std::endl;
1258 int err = _fitter.fit(
t );
1260#ifdef TRKRECO_DEBUG_DETAIL
1261 t.dump(
"detail",
"after fit" );
1262 std::cout <<
"Pdif mag=" << (
t.p() - p0 ).mag() << std::endl;
1265 t.refine( bad, _maxSigmaStereo * 100. );
1266 err = _fitter.fit(
t );
1267 t.refine( bad, _maxSigmaStereo * 10. );
1268 err = _fitter.fit(
t );
1269 t.refine( bad, _maxSigmaStereo );
1270#ifdef TRKRECO_DEBUG_DETAIL
1277 err = _fitter.fit(
t );
1279#ifdef TRKRECO_DEBUG_DETAIL
1280 t.dump(
"detail",
" " );
1281 std::cout <<
"Pdif mag=" << (
t.p() - p0 ).mag() << std::endl;
1291 for (
unsigned i = 0; i < 5; i++ ) _nHits[i] = 0;
1293 unsigned nSegments = segments.length();
1295 for (
unsigned i = 0; i < nSegments; i++ )
1298 int err =
t.szPosition( *segments[i], l );
1310 for (
unsigned j = 0; j < segments[i]->cores().length(); ++j )
1312 TMLink& cL = *segments[i]->cores()[j];
1313 if ( !_allLinks.hasMember( cL ) ) _allLinks.append( cL );
1318 for (
unsigned i = 0; i < 6; i++ )
1320 if ( _links[i].length() > 0 ) { ++_nSuperLayers; }
1334 if ( badSegments.length() )
1336 for (
unsigned i = 0; i < 6; i++ )
1338 if ( badSegments[i]->links().length() )
1340 _allLinks.append( badSegments[i]->links() );
1341#ifdef TRKRECO_DEBUG_DETAIL
1342 std::cout <<
" ... bad links added for stereo super layer " << i * 2 + 1
1344 badSegments[i]->dump(
"hits sort flag",
" " );
1351 unsigned nCores = _allLinks.length();
1352 if ( nCores < _minNCores )
1354#ifdef TRKRECO_DEBUG_DETAIL
1355 std::cout <<
" ... initializeForStereo : # of cores(=" << nCores <<
") is less then "
1356 << _minNCores << std::endl;
1360 for (
unsigned j = 0; j < nCores; j++ )
1362 TMLink& link = *_allLinks[j];
1363 for (
unsigned i = 0; i < 2; i++ )
1365 TMLink& tt = *
new TMLink( link );
1374 int err =
t.szPosition( tt );
1384 _forLine.append( tt );
1389 unsigned nA =
t.cores().length();
1390 for (
unsigned i = 0; i < nA; i++ )
1392 ++_nHits[
t.cores()[i]->wire()->axialStereoLayerId() / 4];
1395 std::cout <<
" ... initializeForStereo : axial super layer usage = ";
1396 for (
unsigned i = 0; i < 5; i++ ) std::cout << _nHits[i] <<
",";
1397 std::cout << std::endl
1398 <<
" : # of stereo super layers=" << _nSuperLayers
1405unsigned TBuilder::stereoQuality(
const AList<TMLink>& links )
const {
1406 unsigned n[6] = { 0, 0, 0, 0, 0, 0 };
1409 unsigned nLinks = links.length();
1410 for (
unsigned i = 0; i < nLinks; i++ )
1412 const TMLink& l = *links[i];
1419 unsigned nTotal = 0;
1420 unsigned nMissing = 0;
1421 unsigned innermostStereo = 5;
1422 unsigned outermostStereo = 0;
1423 unsigned innermostAxial = 4;
1424 unsigned outermostAxial = 0;
1425 unsigned innerSL = 6;
1426 unsigned outerSL = 0;
1427 for (
unsigned i = 0; i < 6; i++ )
1429 if ( _links[i].length() > 1 )
1431 if ( i > outermostStereo ) outermostStereo = i;
1432 if ( i < innermostStereo ) innermostStereo = i;
1434 if (
n[i] > 1 ) ++nTotal;
1436 for (
unsigned i = 0; i < 5; i++ )
1438 if ( _nHits[i] > 1 )
1440 if ( i > outermostAxial ) outermostAxial = i;
1441 if ( i < innermostAxial ) innermostAxial = i;
1445 if ( innermostStereo > 1 && innermostAxial < 3 ) innerSL = 2;
1446 else innerSL = innermostStereo;
1447 if ( outermostStereo > 1 && outermostAxial > 2 ) outerSL = 5;
1448 else outerSL = outermostStereo;
1450 for (
unsigned i = 0; i < 6; i++ )
1452 if ( _links[i].length() > 0 )
1455 if ( i <= outerSL && i >= innerSL )
1456 if (
n[i] < 2 ) ++nMissing;
1458 if (
n[i] > 1 ) ++nTotal;
1460 unsigned toBeReturn = 0;
1461 if ( nMissing <= 1 ) toBeReturn = 2;
1462 else if ( nMissing == 2 ) toBeReturn = 1;
1463 if ( nTotal < 2 ) toBeReturn = 0;
1466 std::cout <<
" ... stereoQuality : axial ";
1467 for (
unsigned i = 0; i < 6; i++ ) std::cout << _nHits[i] <<
",";
1468 std::cout << std::endl <<
" : stereo ";
1469 for (
unsigned i = 0; i < 5; i++ ) std::cout <<
n[i] <<
",";
1470 std::cout <<
" : total " << nTotal <<
" super layers, "
1471 <<
" : quality=" << toBeReturn << std::endl;
1481 std::cout <<
"... building stereo by segments(new) : # of segments = ";
1482 std::cout << segments.length() << std::endl;
1483 for (
unsigned i = 0; i < segments.length(); i++ )
1484 segments[i]->
dump(
"hits sort flag",
" " );
1486#ifdef TRKRECO_WINDOW
1489 TTrack* bestCandidate = NULL;
1491 bool ok = initializeForStereo(
t, segments, badSegments );
1492 unsigned nSuperLayers = _nSuperLayers + 1;
1496 if ( !ok )
goto endOfBuilding;
1498 while ( --nSuperLayers )
1503#ifdef TRKRECO_WINDOW
1507 sz.appendSz(
t, segments, leda_black );
1509 std::string
s =
"# of segments = " + std::to_string(
int( segments.length() ) );
1510 sz.appendSz(
t, _allLinks, leda_black );
1511 sz.append( _forLine, leda_brown );
1512 s =
"nSprLyr=" + std::to_string(
int( nSuperLayers ) ) +
1513 ", # of initial lines = " + std::to_string(
int( initialLines.length() ) );
1514 for (
unsigned i = 0; i < initialLines.length(); i++ )
1515 sz.append( *initialLines[i], leda_red );
1520 if ( initialLines.length() == 0 )
continue;
1523 unsigned nInitialLines = initialLines.length();
1526 for (
unsigned i = 0; i < nInitialLines; i++ )
1530 const TMLine& line = *initialLines[i];
1534 if ( poorSeeds.length() )
1536 bool poorCase =
false;
1537 for (
unsigned j = 0; j < poorSeeds.length(); j++ )
1539 if ( poorSeeds[j]->length() == newLine.
links().length() )
1542 tmp.remove( newLine.
links() );
1543 if ( tmp.length() == 0 )
1545#ifdef TRKRECO_DEBUG_DETAIL
1546 std::cout <<
" ... This is a poor seed :"
1548 <<
" : # of poor seeds = " << poorSeeds.length() << std::endl;
1555 if ( poorCase )
continue;
1559 if ( !stereoQuality( newLine.
links() ) )
continue;
1563 t3d =
build( *t3d, newLine );
1564 if ( t3d == NULL )
continue;
1567 unsigned quality = stereoQuality( t3d->
links() );
1573#ifdef TRKRECO_WINDOW
1574 sz.text(
"stereo finished" );
1575 sz.oneShot( *t3d, leda_blue );
1577 if ( bestCandidate )
delete bestCandidate;
1578 bestCandidate = t3d;
1585 tmpL->append( newLine.
links() );
1586 poorSeeds.append( tmpL );
1589#ifdef TRKRECO_WINDOW
1590 sz.text(
"this candidate discarded" );
1591 sz.oneShot( *t3d, leda_black );
1598 if ( bestCandidate )
1600 if ( bestCandidate->
cores().length() < t3d->
cores().length() )
1602#ifdef TRKRECO_WINDOW
1603 sz.text(
"new candidate" );
1604 sz.append( *bestCandidate, leda_brown );
1605 sz.oneShot( *t3d, leda_green );
1606 sz.remove( *bestCandidate );
1608 delete bestCandidate;
1609 bestCandidate = t3d;
1613#ifdef TRKRECO_WINDOW
1614 sz.text(
"this candidate discarded" );
1615 sz.oneShot( *t3d, leda_black );
1622 bestCandidate = t3d;
1623#ifdef TRKRECO_WINDOW
1624 sz.text(
"new candidate" );
1625 sz.oneShot( *bestCandidate, leda_green );
1632 HepAListDeleteAll( initialLines );
1637 _allLinks.removeAll();
1638 for (
unsigned i = 0; i < 6; i++ ) HepAListDeleteAll( _links[i] );
1639 HepAListDeleteAll( _forLine );
1641#ifdef TRKRECO_DEBUG_DETAIL
1642 std::cout <<
" ... # of poor seeds = " << poorSeeds.length() << std::endl;
1644#ifdef TRKRECO_WINDOW
1645 if ( bestCandidate == NULL )
1647 sz.text(
"3D failed" );
1653 if ( bestCandidate )
1656 for (
unsigned i = 0; i < segments.length(); i++ )
1660 if ( used.length() )
1662 bestCandidate->
segments().append( segment );
1663 segment.
tracks().append( bestCandidate );
1668 if ( poorSeeds.length() ) HepAListDeleteAll( poorSeeds );
1670#ifdef TRASA_DEBUG_DETAIL
1671 if ( bestCandidate == NULL ) std::cout <<
"... building stereo(new) failed" << std::endl;
1672 else std::cout <<
"... building stereo(new) ok" << std::endl;
1674 return bestCandidate;
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
#define WireHitPatternLeft
#define WireHitPatternRight
int SortByB(const void *a, const void *b)
Sorter.
AList< TMLink > StereoHits(const AList< TMLink > &links)
returns stereo hits.
void Dump(const CAList< TMLink > &links, const std::string &message=std::string(""), const std::string &prefix=std::string(""))
dumps TMLinks.
unsigned NSuperLayers(const AList< TMLink > &links)
returns # of layers.
void SeparateCores(const AList< TMLink > &input, AList< TMLink > &cores, AList< TMLink > &nonCores)
separate cores and non-cores.
AList< TMLink > Links(const TSegment &, const TTrack &)
returns AList of TMLink used for a track.
const HepVector & a(void) const
returns helix parameters.
TMLine * initialLine(const TTrack &, AList< TSegment > &) const
makes a line.
AList< TMLine > searchLines5(void) const
AList< TMLine > searchLines1(void) const
TMLine * initialLineOld(const TTrack &, AList< TSegment > &) const
void removeFarSegment(const TMLine &, AList< TSegment > &, AList< TMLink > &) const
AList< TMLine > searchLines6(void) const
TTrack * buildRphi(const AList< TMLink > &) const
builds a r/phi track from TMLinks or from Segments.
TMLine * initialLine2(const TTrack &, const AList< TMLink > &) const
virtual ~TBuilder()
Destructor.
TTrack * build(TTrack &t, const TMLine &l) const
void salvage(TTrack &t, AList< TMLink > &hits) const
salvages hits.
AList< TMLine > searchLines2(void) const
TBuilder(const std::string &name, float maxSigma, float maxSigmaStereo, float salvageLevel, float szSegmentDistance, float szLinkDistance, unsigned fittingFlag)
Constructor with salvage level.
TTrack * buildStereoNew(const TTrack &t, AList< TSegment > &goodSegments, AList< TSegment > &badSegments) const
TTrack * buildStereo(const TTrack &t, AList< TSegment > &) const
AList< TSegment > selectStereoSegment(const TMLine &line, const AList< TSegment > &list, const AList< TMLink > &szList) const
TMLine * initialLine1(const TTrack &, const AList< TSegment > &, const AList< TMLink > &) const
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
AList< TMLine > searchLines4(void) const
AList< TMLine > searchInitialLines(unsigned nSuperLayers) const
AList< TMLine > searchLines3(void) const
TMLine searchLine(const TMLine &initialLine) const
A class to represent a circle in tracking.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
bool axial(void) const
returns true if this wire is in an axial layer.
unsigned axialStereoLayerId(void) const
returns id of axial or stereo id.
const HepPoint3D & forwardPosition(void) const
returns position in forward endplate.
const HepPoint3D & backwardPosition(void) const
returns position in backward endplate.
A class to represent a track in tracking.
double distance(const TMLink &) const
returns distance to a position of TMLink itself. (not to a wire)
double a(void) const
returns coefficient a.
double b(void) const
returns coefficient b.
A class to relate TMDCWireHit and TTrack objects.
TMLink * link(void) const
returns a pointer to a TMLink.
unsigned leftRight(void) const
returns left-right. 0:left, 1:right, 2:wire
const TMDCWireHit * hit(void) const
returns a pointer to a hit.
const HepPoint3D & position(void) const
returns position.
const TMDCWire *const wire(void) const
returns a pointer to a wire.
A class to fit a TTrackBase object to a line.
virtual int fit(TTrackBase &) const
A class to relate TMDCWireHit and TTrack objects.
AList< TTrack > & tracks(void)
virtual int fit(void)
fits itself by a default fitter. Error was happened if return value is not zero.
virtual void refine(AList< TMLink > &list, double maxSigma)
bool fitted(void) const
returns true if fitted.
void append(TMLink &)
appends a TMLink.
const AList< TMLink > & links(unsigned mask=0) const
void remove(TMLink &a)
removes a TMLink.
const AList< TMLink > & cores(unsigned mask=0) const
returns a list of masked TMLinks for fit. 'mask' will be applied if mask is not 0.
A class to represent a track in tracking.
AList< TSegment > & segments(void)
returns AList<TSegment>.
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.