13#include "CLHEP/String/Strings.h"
14#include "TrkReco/TBuilder.h"
15#include "TrkReco/TMDC.h"
16#include "TrkReco/TMDCWire.h"
17#include "TrkReco/TMDCWireHit.h"
18#include "TrkReco/TMLink.h"
19#include "TrkReco/TCircle.h"
20#include "TrkReco/TLine0.h"
21#include "TrkReco/TMLine.h"
22#include "TrkReco/TTrack.h"
23#include "TrkReco/TSegment.h"
24#include "TrkReco/TPoint2D.h"
25#include "TrkReco/TLine2D.h"
26#include "TrkReco/TRobustLineFitter.h"
28#include "TrkReco/TMDCWireHitMC.h"
29#include "TrkReco/TTrackHEP.h"
32#include "TrkReco/TWindow.h"
40 float szSegmentDistance,
44 _fitter(
"TBuilder Fitter"),
46 _maxSigmaStereo(maxSigmaStereo),
47 _salvageLevel(sqrt(salvageLevel)),
50 _szSegmentDistance(szSegmentDistance),
51 _szLinkDistance(szLinkDistance) {
52 if (fittingFlag & 1) _fitter.
sag(
true);
54 if (fittingFlag & 4) _fitter.
tof(
true);
55 if (fittingFlag & 8) _fitter.
freeT0(
true);
69 std::cout <<
"... building rphi by segments : # of segments = ";
70 std::cout << list.length() << std::endl;
71 for (
unsigned i = 0; i < list.length(); i++)
72 list[i]->
dump(
"hits sort flag",
" ");
91 unsigned n = list.length();
92 for (
unsigned i = 0; i <
n; i++) {
96 t->segments().append(segment);
109 std::cout <<
"... building rphi by links : # of links = ";
110 std::cout << list.length() << std::endl;
119 cout<<
" ... cores..."<<endl;
120 for(
int ii = 0; ii < cores.length(); ++ii) {
121 cout<<
"layer: "<<cores[ii]->wire()->layerId()
122 <<
" local: "<<cores[ii]->wire()->localId()<<endl;
124 cout<<
" ...noncores..."<<endl;
125 for(
int ii = 0; ii < nonCores.length(); ++ii) {
126 cout<<
"layer: "<<nonCores[ii]->wire()->layerId()
127 <<
" local: "<<nonCores[ii]->wire()->localId()<<endl;
131 unsigned nCores = cores.length();
132 if (nCores < _minNCores) {
134 std::cout <<
"... building rphi failure : # of cores(=" << nCores;
135 std::cout <<
") is less then " << _minNCores << std::endl;
143 std::cout <<
"links in list = "<<list.length()<<std::endl;
144 std::cout <<
"... making a circle : # cores =" << cores.length() << std::endl;
150 std::cout <<
"... building rphi failure : circle fit error = ";
151 std::cout << err << std::endl;
160 err = _fitter.
fit(*
t);
163 if (err < 0)
goto discard;
164 t->refine(bad, _maxSigma * 100.);
167 err = _fitter.
fit(*
t);
170 t->refine(bad, _maxSigma * 10.);
173 err = _fitter.
fit(*
t);
176 t->refine(bad, _maxSigma);
179 err = _fitter.
fit(*
t);
182 if (err < 0)
goto discard;
183#ifdef TRKRECO_DEBUG_DETAIL
184 c.
dump(
"detail",
" ccl> ");
185 t->dump(
"detail",
" 1st> ");
190 std::cout <<
"... appending non-core hits : # = " << nonCores.length();
191 std::cout << std::endl;
193 t->appendByApproach(nonCores, _salvageLevel);
195 t->dump(
"hits sort flag",
" ");
203 std::cout <<
"... building rphi failure : helix fit error = ";
204 std::cout << err << std::endl;
214 std::cout <<
"... salvaging(TBuilder) : # of given hits=" << hits.length();
215 std::cout <<
", salvage level=" << _salvageLevel << std::endl;
216 Dump(hits,
"hits sort flag");
219 unsigned nHits = hits.length();
220 if (nHits == 0)
return;
223 t.appendByApproach(hits, _salvageLevel);
231 std::cout <<
"... salvaging by segments : # of segments = ";
232 std::cout << list.length() << std::endl;
233 for (
unsigned i = 0; i < list.length(); i++)
234 list[i]->
dump(
"hits sort flag",
" ");
239 unsigned n = list.length();
240 for (
unsigned i = 0; i <
n; i++)
241 links.append(list[i]->links());
252 if (list.length() < 2)
return NULL;
257 unsigned n = list.length();
258 for (
unsigned i = 0; i <
n; i ++) {
259 unsigned j = list[i]->superLayerId() / 2;
260 sl[j].append(list[i]);
261 tl[j].append(lList[i]);
264 std::cout <<
" ... initialLine1 : super layer ptn = ";
265 for (
unsigned i = 0; i < 5; i++) std::cout << sl[i].length();
266 std::cout << std::endl;
270 unsigned nSingle = 0;
271 for (
unsigned i = 0; i < 5; i++)
272 if (sl[i].length() == 1) ++nSingle;
274 std::cout <<
" ... # of single segment layer = " << nSingle << std::endl;
276 if (nSingle < 2)
return NULL;
281 for (
unsigned i = 0; i < 5; i++) {
282 if (sl[i].length() != 1)
continue;
283 bestCombination.append(sl[i]);
284 forLine.append(tl[i]);
287 int err = line.
fit();
299 std::cout <<
" ... initlialLine2 : # of links = " << lList.length();
300 std::cout << std::endl;
306 int err = fitter.
fit(* line);
320 unsigned n = list.length();
321 for (
unsigned i = 0; i <
n; i++) {
323 int err =
t.szPosition(* list[i], l);
343 unsigned nAMaxSL = 0;
344 unsigned nAMinSL = 10;
346 unsigned nA = segments.length();
347 for (
unsigned i = 0; i < nA; i++) {
348 unsigned sl = segments[i]->superLayerId();
349 if (sl > nAMaxSL) nAMaxSL = sl;
350 if (sl < nAMinSL) nAMinSL = sl;
352 unsigned nExpected = (nAMaxSL - nAMinSL) / 2;
354 std::cout <<
" ... initialLine : axial super layer usage = " << nAMinSL;
355 std::cout <<
" ~ " << nAMaxSL << std::endl;
356 std::cout <<
" : expected stereo super layers = ";
357 std::cout << nExpected << std::endl;
370 std::cout <<
" ... initialLine2 : # of selected segments = ";
371 std::cout << tmp.length() << std::endl;
373 if ((tmp.length() >= nExpected) ||
374 (tmp.length() >= 4) ||
385 bool ok = (tmp.length() >= nExpected);
387 std::cout <<
" ... initialLine2 : # of selected segments = ";
388 std::cout << tmp.length() <<
" : ok, last = ";
389 std::cout << ok <<
", " << last << std::endl;
410 unsigned n = list.length();
411 for (
unsigned i = 0; i <
n; i++) {
413 int err =
t.szPosition(* list[i], l);
433 unsigned nAMaxSL = 0;
434 unsigned nAMinSL = 10;
436 unsigned nA = segments.length();
437 for (
unsigned i = 0; i < nA; i++) {
438 unsigned sl = segments[i]->superLayerId();
439 if (sl > nAMaxSL) nAMaxSL = sl;
440 if (sl < nAMinSL) nAMinSL = sl;
442 unsigned nExpected = (nAMaxSL - nAMinSL) / 2;
444 std::cout <<
" ... initialLine : axial super layer usage = " << nAMinSL;
445 std::cout <<
" ~ " << nAMaxSL << std::endl;
446 std::cout <<
" : expected stereo super layers = ";
447 std::cout << nExpected << std::endl;
458 std::cout <<
" ... initialLine1 : # of selected segments = ";
459 std::cout << tmp.length() << std::endl;
461 if (tmp.length() >= nExpected) {
462 lList0.remove(line->
links());
463 HepAListDeleteAll(lList0);
473 bool ok = (tmp.length() >= nExpected);
476 std::cout <<
" ... initialLine2 : # of selected segments = ";
477 std::cout << tmp.length() <<
" : ok, last = ";
478 std::cout << ok <<
", " << last << std::endl;
481 lList0.remove(line->
links());
482 HepAListDeleteAll(lList0);
490 HepAListDeleteAll(lList0);
501 unsigned n = list.length();
502 for (
unsigned i = 0; i <
n; i++) {
503 float distance = line.
distance(* szList[i]);
504 if (distance < _szSegmentDistance) outList.append(list[i]);
513 unsigned n = list.length();
514 float maxDistance = 0.;
516 for (
unsigned i = 0; i <
n; i++) {
517 float distance = line.
distance(* szList[i]);
518 if (distance > maxDistance) maxId = i;
521 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) {
541 std::cout <<
"... stereo building failure : # of cores(=" << nCores;
542 std::cout <<
") is less then " << _minNCores << std::endl;
547 sz.appendSz(track, cores, leda_brown);
552 for (
unsigned i = 0; i < nCores; i++) {
554 for (
unsigned i = 0; i < 2; i++) {
562 if (line.
distance(tt) < _szLinkDistance) {
564 forNewLine.append(tt);
575 std::cout <<
" ... creating a new line" << std::endl;
577 unsigned nNewLine = forNewLine.length();
578 TMLine newLine(forNewLine);
580 int err = fitter.
fit(newLine);
583 HepAListDeleteAll(forNewLine);
584#ifdef TRKRECO_DEBUG_DETAIL
585 std::cout <<
" ... 2nd linear fit failure. nLinks(";
586 std::cout << forNewLine.length() <<
")" << std::endl;
592 sz.append(newLine, leda_green);
596#ifdef TRKRECO_DEBUG_DETAIL
597 Dump(forNewLine,
"sort hits stereo",
" ");
603 for (
unsigned i = 0; i < nNewLine; i++) {
604 if (last == NULL) last = forNewLine[i]->link();
606 if (last == forNewLine[i]->link()) {
607 if (newLine.
distance(* forNewLine[i - 1]) >
609 toRemove.append(forNewLine[i - 1]);
611 toRemove.append(forNewLine[i]);
615 last = forNewLine[i]->link();
619 forNewLine.remove(toRemove);
620 nNewLine = forNewLine.length();
622#ifdef TRKRECO_DEBUG_DETAIL
623 Dump(toRemove,
"sort hits stereo",
" x ");
624 Dump(forNewLine,
"sort hits stereo",
" ");
628 for (
unsigned i = 0; i < nNewLine; i++)
629 track.
append(* forNewLine[i]->link());
633 a[4] = track.
charge() * newLine.
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);
663 std::cout <<
"... building stereo by segments : # of segments = ";
664 std::cout << segments.length() << std::endl;
665 for (
unsigned i = 0; i < segments.length(); i++)
666 segments[i]->
dump(
"hits sort flag",
" ");
672 sz.appendSz(
t, segments, leda_black);
674 std::string
s =
"# of segments = " + itostring(
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++)
700 links.append(segments[i]->links());
708 for (
unsigned i = 0; i <
n; i++) {
712 t.segments().append(segment);
726 std::cout <<
" ... searchInitialLines : # of segments in sl : ";
727 for (
unsigned i = 0; i < 5; i++)
728 std::cout << _links[i].length() <<
",";
729 std::cout << std::endl
730 <<
" : max # of super layers="
731 << nSuperLayerMax << std::endl;
735 if (nSuperLayerMax > 5)
737 else if (nSuperLayerMax > 4)
739 else if (nSuperLayerMax > 3)
741 else if (nSuperLayerMax > 2)
743 else if (nSuperLayerMax > 1)
755 for (
unsigned i = 0; i < 6; i++)
756 n[i] = _links[i].length();
759 for (
unsigned i0 = 0; i0 <
n[0]; i0++) {
760 for (
unsigned i1 = 0; i1 <
n[1]; i1++) {
761 for (
unsigned i2 = 0; i2 <
n[2]; i2++) {
762 for (
unsigned i3 = 0; i3 <
n[3]; i3++) {
763 for (
unsigned i4 = 0; i4 <
n[4]; i4++) {
764 for (
unsigned i5 = 0; i5 <
n[5]; i5++) {
767 forLine.append(_links[0][i0]);
768 forLine.append(_links[1][i1]);
769 forLine.append(_links[2][i2]);
770 forLine.append(_links[3][i3]);
771 forLine.append(_links[4][i4]);
772 forLine.append(_links[5][i5]);
775 int err = line.
fit();
790 std::cout <<
" ... searchLines5 : # of lines found = "
791 << lines.length() << std::endl;
802 for (
unsigned skip = 0; skip < 6; skip++) {
810 else if (skip == 1) {
813 else if (skip == 2) {
816 else if (skip == 3) {
819 else if (skip == 4) {
822 else if (skip == 5) {
827 for (
unsigned i = 0; i < 5; i++)
828 n[i] = l[i]->length();
830 for (
unsigned i0 = 0; i0 <
n[0]; i0++) {
831 for (
unsigned i1 = 0; i1 <
n[1]; i1++) {
832 for (
unsigned i2 = 0; i2 <
n[2]; i2++) {
833 for (
unsigned i3 = 0; i3 <
n[3]; i3++) {
834 for (
unsigned i4 = 0; i4 <
n[4]; i4++) {
837 forLine.append((* l[0])[i0]);
838 forLine.append((* l[1])[i1]);
839 forLine.append((* l[2])[i2]);
840 forLine.append((* l[3])[i3]);
841 forLine.append((* l[4])[i4]);
844 int err = line.
fit();
859 std::cout <<
" ... searchLines5 : # of lines found = "
860 << lines.length() << std::endl;
871 for (
unsigned skip = 0; skip < 15; skip++) {
878 else if (skip == 1) {
881 else if (skip == 2) {
884 else if (skip == 3) {
888 else if (skip == 4) {
891 else if (skip == 5) {
894 else if (skip == 6) {
899 else if (skip == 7) {
902 else if (skip == 8) {
905 else if (skip == 9) {
908 else if (skip == 10) {
914 else if (skip == 11) {
917 else if (skip == 12) {
920 else if (skip == 13) {
923 else if (skip == 14) {
928 for (
unsigned i = 0; i < 4; i++)
929 n[i] = l[i]->length();
931 for (
unsigned i0 = 0; i0 <
n[0]; i0++) {
932 for (
unsigned i1 = 0; i1 <
n[1]; i1++) {
933 for (
unsigned i2 = 0; i2 <
n[2]; i2++) {
934 for (
unsigned i3 = 0; i3 <
n[3]; i3++) {
936 forLine.append((* l[0])[i0]);
937 forLine.append((* l[1])[i1]);
938 forLine.append((* l[2])[i2]);
939 forLine.append((* l[3])[i3]);
942 int err = line.
fit();
956 std::cout <<
" ... searchLines4 : # of lines found = "
957 << lines.length() << std::endl;
968 for (
unsigned skip = 0; skip < 20; skip++) {
974 else if (skip == 1) {
977 else if (skip == 2) {
980 else if (skip == 3) {
983 else if (skip == 4) {
986 else if (skip == 5) {
989 else if (skip == 6) {
992 else if (skip == 7) {
996 else if (skip == 8) {
999 else if (skip == 9) {
1002 else if (skip == 10) {
1005 else if (skip == 11) {
1008 else if (skip == 12) {
1011 else if (skip == 13) {
1014 else if (skip == 14) {
1017 else if (skip == 15) {
1020 else if (skip == 16) {
1024 else if (skip == 17) {
1027 else if (skip == 18) {
1031 else if (skip == 19) {
1036 for (
unsigned i = 0; i < 3; i++)
1037 n[i] = l[i]->length();
1039 for (
unsigned i0 = 0; i0 <
n[0]; i0++) {
1040 for (
unsigned i1 = 0; i1 <
n[1]; i1++) {
1041 for (
unsigned i2 = 0; i2 <
n[2]; i2++) {
1043 forLine.append((* l[0])[i0]);
1044 forLine.append((* l[1])[i1]);
1045 forLine.append((* l[2])[i2]);
1048 int err = line.
fit();
1061 std::cout <<
" ... searchLines3 : # of lines found = "
1062 << lines.length() << std::endl;
1073 for (
unsigned skip = 0; skip < 15; skip++) {
1078 else if (skip == 1) {
1081 else if (skip == 2) {
1084 else if (skip == 3) {
1087 else if (skip == 4) {
1090 else if (skip == 5) {
1094 else if (skip == 6) {
1097 else if (skip == 7) {
1100 else if (skip == 8) {
1103 else if (skip == 9) {
1107 else if (skip == 10) {
1110 else if (skip == 11) {
1113 else if (skip == 12) {
1117 else if (skip == 13) {
1120 else if (skip == 14) {
1125 for (
unsigned i = 0; i < 2; i++)
1126 n[i] = l[i]->length();
1128 for (
unsigned i0 = 0; i0 <
n[0]; i0++) {
1129 for (
unsigned i1 = 0; i1 <
n[1]; i1++) {
1131 forLine.append((* l[0])[i0]);
1132 forLine.append((* l[1])[i1]);
1135 int err = line.
fit();
1147 std::cout <<
" ... searchLines2 : # of lines found = "
1148 << lines.length() << std::endl;
1159 int err = line.
fit();
1168 std::cout <<
" ... searchLines1 : # of lines found = "
1169 << lines.length() << std::endl;
1177#ifdef TRKRECO_WINDOW
1178 std::string old = sz.text();
1181 static float _szLinkMaxDistance = 5;
1183 unsigned nLinks = _forLine.length();
1189 unsigned nGoodLinks0 = 0;
1191 unsigned nLoops = 0;
1195 unsigned nGoodLinks = 0;
1196 for (
unsigned i = 0; i < nLinks; i++) {
1197 float distance = line0.
distance(* _forLine[i]);
1198 if (distance < _szLinkDistance)
1199 targets.append(_forLine[i]);
1200 if (distance < _szLinkMaxDistance) {
1206 std::cout <<
" ... searchLine : # of close hits(last) = " << nGoodLinks0
1207 <<
", # of close hits = " << nGoodLinks << std::endl;
1211 if (nGoodLinks0 == nGoodLinks)
break;
1216 int err = fitter.
fit(newLine);
1218#ifdef TRKRECO_WINDOW
1219 std::cout <<
" ... searchLine : failed to fit" << std::endl;
1220 std::string
s =
"line search failed";
1229#ifdef TRKRECO_DEBUG_DETAIL
1230 std::cout <<
" reached to max # of loops(10) : break";
1235#ifdef TRKRECO_WINDOW
1236 std::string ss =
", # of close hits(last) = " + itostring(
int(nGoodLinks0))
1237 +
", # of close hits = " + itostring(
int(nGoodLinks));
1238 sz.append(line0, leda_brown);
1239 sz.append(newLine, leda_green);
1240 sz.text(old +
", nLoops = " + itostring(
int(nLoops)) + ss);
1247 nGoodLinks0 = nGoodLinks;
1248 targets.removeAll();
1258 unsigned n = links.length();
1259 for (
unsigned i = 1; i <
n; i++) {
1260 if (links[i - 1]->link() == links[i]->link()) {
1261 toRemove.append(links[i]);
1266 if (links[i - 2]->link() == links[i]->link())
1267 toRemove.append(links[i]);
1269 links.remove(toRemove);
1273 for (
unsigned i = 0; i <
n; i++)
1274 t.append(* links[i]->link());
1282 std::cout<<
" "<<__FILE__<<
" "<<__LINE__<<
" Could not get MagneticFieldSvc "<<std::endl;
1286 a[4] =
t.charge() * l.
a();
1288 a[4] = -1. *
t.charge() * l.
a();
1297#ifdef TRKRECO_DEBUG_DETAIL
1298 static unsigned nTrk = 0;
1306 if (links[0]->hit()->mc())
1307 pp = links[0]->hit()->mc()->hep()->p().vect();
1313 t.dump(
"detail",
"before fit");
1314 std::cout <<
"Pdif mag=" << (
t.p() - p0).mag() << std::endl;
1322 int err = _fitter.
fit(
t);
1324#ifdef TRKRECO_DEBUG_DETAIL
1325 t.dump(
"detail",
"after fit");
1326 std::cout <<
"Pdif mag=" << (
t.p() - p0).mag() << std::endl;
1329 t.refine(bad, _maxSigmaStereo * 100.);
1330 err = _fitter.
fit(
t);
1331 t.refine(bad, _maxSigmaStereo * 10.);
1332 err = _fitter.
fit(
t);
1333 t.refine(bad, _maxSigmaStereo);
1334#ifdef TRKRECO_DEBUG_DETAIL
1341 err = _fitter.
fit(
t);
1343#ifdef TRKRECO_DEBUG_DETAIL
1344 t.dump(
"detail",
" ");
1345 std::cout <<
"Pdif mag=" << (
t.p() - p0).mag() << std::endl;
1353TBuilder::initializeForStereo(
const TTrack &
t,
1357 for (
unsigned i = 0; i < 5; i++)
1360 unsigned nSegments = segments.length();
1362 for (
unsigned i = 0; i < nSegments; i++) {
1364 int err =
t.szPosition(* segments[i], l);
1375 for (
unsigned j = 0; j < segments[i]->cores().length(); ++j) {
1376 TMLink & cL = * segments[i]->cores()[j];
1377 if(!_allLinks.hasMember(cL)) _allLinks.append(cL);
1382 for (
unsigned i = 0; i < 6; i++) {
1383 if (_links[i].length() > 0) {
1399 if (badSegments.length()) {
1400 for (
unsigned i = 0; i < 6; i++) {
1401 if (badSegments[i]->links().length()) {
1402 _allLinks.append(badSegments[i]->links());
1403#ifdef TRKRECO_DEBUG_DETAIL
1404 std::cout <<
" ... bad links added for stereo super layer "
1405 << i * 2 + 1 << std::endl;
1406 badSegments[i]->dump(
"hits sort flag",
" ");
1413 unsigned nCores = _allLinks.length();
1414 if (nCores < _minNCores) {
1415#ifdef TRKRECO_DEBUG_DETAIL
1416 std::cout <<
" ... initializeForStereo : # of cores(=" << nCores
1417 <<
") is less then " << _minNCores << std::endl;
1421 for (
unsigned j = 0; j < nCores; j++) {
1422 TMLink & link = * _allLinks[j];
1423 for (
unsigned i = 0; i < 2; i++) {
1432 int err =
t.szPosition(tt);
1441 _forLine.append(tt);
1446 unsigned nA =
t.cores().length();
1447 for (
unsigned i = 0; i < nA; i++)
1449 ++_nHits[
t.cores()[i]->wire()->axialStereoLayerId()/4];
1452 std::cout <<
" ... initializeForStereo : axial super layer usage = ";
1453 for (
unsigned i = 0; i < 5; i++)
1454 std::cout << _nHits[i] <<
",";
1455 std::cout << std::endl
1456 <<
" : # of stereo super layers="
1457 << _nSuperLayers << std::endl;
1465 unsigned n[6] = {0, 0, 0, 0, 0, 0};
1468 unsigned nLinks = links.length();
1469 for (
unsigned i = 0; i < nLinks; i++) {
1470 const TMLink & l = * links[i];
1477 unsigned nTotal = 0;
1478 unsigned nMissing = 0;
1479 unsigned innermostStereo = 5;
1480 unsigned outermostStereo = 0;
1481 unsigned innermostAxial = 4;
1482 unsigned outermostAxial = 0;
1483 unsigned innerSL = 6;
1484 unsigned outerSL = 0;
1485 for (
unsigned i = 0; i < 6; i++) {
1486 if (_links[i].length() > 1) {
1487 if(i > outermostStereo) outermostStereo = i;
1488 if(i < innermostStereo) innermostStereo = i;
1490 if (
n[i] > 1) ++nTotal;
1492 for (
unsigned i = 0; i < 5; i++) {
1493 if (_nHits[i] > 1) {
1494 if (i > outermostAxial) outermostAxial = i;
1495 if (i < innermostAxial) innermostAxial = i;
1499 if(innermostStereo > 1 && innermostAxial < 3) innerSL = 2;
1500 else innerSL = innermostStereo;
1501 if(outermostStereo > 1 && outermostAxial > 2) outerSL = 5;
1502 else outerSL = outermostStereo;
1504 for (
unsigned i = 0; i < 6; i++) {
1505 if (_links[i].length() > 0) {
1507 if (i <= outerSL && i >= innerSL)
1511 if (
n[i] > 1) ++nTotal;
1513 unsigned toBeReturn = 0;
1514 if (nMissing <= 1) toBeReturn = 2;
1515 else if (nMissing == 2) toBeReturn = 1;
1516 if (nTotal < 2) toBeReturn = 0;
1519 std::cout <<
" ... stereoQuality : axial ";
1520 for (
unsigned i = 0; i < 6; i++)
1521 std::cout << _nHits[i] <<
",";
1522 std::cout << std::endl
1524 for (
unsigned i = 0; i < 5; i++)
1525 std::cout <<
n[i] <<
",";
1526 std::cout <<
" : total " << nTotal <<
" super layers, "
1527 <<
" : quality=" << toBeReturn << std::endl;
1540 std::cout <<
"... building stereo by segments(new) : # of segments = ";
1541 std::cout << segments.length() << std::endl;
1542 for (
unsigned i = 0; i < segments.length(); i++)
1543 segments[i]->
dump(
"hits sort flag",
" ");
1545#ifdef TRKRECO_WINDOW
1548 TTrack * bestCandidate = NULL;
1550 bool ok = initializeForStereo(
t, segments, badSegments);
1551 unsigned nSuperLayers = _nSuperLayers + 1;
1555 if (! ok)
goto endOfBuilding;
1557 while (--nSuperLayers) {
1561#ifdef TRKRECO_WINDOW
1565 sz.appendSz(
t, segments, leda_black);
1567 std::string
s =
"# of segments = " + itostring(
int(segments.length()));
1568 sz.appendSz(
t, _allLinks, leda_black);
1569 sz.append(_forLine, leda_brown);
1570 s =
"nSprLyr=" + itostring(
int(nSuperLayers)) +
1571 ", # of initial lines = " + itostring(
int(initialLines.length()));
1572 for (
unsigned i = 0; i < initialLines.length(); i++)
1573 sz.append(* initialLines[i], leda_red);
1578 if (initialLines.length() == 0)
continue;
1581 unsigned nInitialLines = initialLines.length();
1584 for (
unsigned i = 0; i < nInitialLines; i++) {
1587 const TMLine & line = * initialLines[i];
1591 if (poorSeeds.length()) {
1592 bool poorCase =
false;
1593 for (
unsigned j = 0; j < poorSeeds.length(); j++) {
1594 if (poorSeeds[j]->length() == newLine.
links().length()) {
1596 tmp.remove(newLine.
links());
1597 if (tmp.length() == 0) {
1598#ifdef TRKRECO_DEBUG_DETAIL
1599 std::cout <<
" ... This is a poor seed :"
1601 <<
" : # of poor seeds = "
1602 << poorSeeds.length() << std::endl;
1609 if (poorCase)
continue;
1613 if (! stereoQuality(newLine.
links()))
1618 t3d =
build(* t3d, newLine);
1619 if (t3d == NULL)
continue;
1622 unsigned quality = stereoQuality(t3d->
links());
1627#ifdef TRKRECO_WINDOW
1628 sz.text(
"stereo finished");
1629 sz.oneShot(* t3d, leda_blue);
1631 if (bestCandidate)
delete bestCandidate;
1632 bestCandidate = t3d;
1639 tmpL->append(newLine.
links());
1640 poorSeeds.append(tmpL);
1642#ifdef TRKRECO_WINDOW
1643 sz.text(
"this candidate discarded");
1644 sz.oneShot(* t3d, leda_black);
1651 if (bestCandidate) {
1652 if (bestCandidate->
cores().length() <
1653 t3d->
cores().length()) {
1654#ifdef TRKRECO_WINDOW
1655 sz.text(
"new candidate");
1656 sz.
append(* bestCandidate, leda_brown);
1657 sz.oneShot(* t3d, leda_green);
1658 sz.remove(* bestCandidate);
1660 delete bestCandidate;
1661 bestCandidate = t3d;
1664#ifdef TRKRECO_WINDOW
1665 sz.text(
"this candidate discarded");
1666 sz.oneShot(* t3d, leda_black);
1672 bestCandidate = t3d;
1673#ifdef TRKRECO_WINDOW
1674 sz.text(
"new candidate");
1675 sz.oneShot(* bestCandidate, leda_green);
1682 HepAListDeleteAll(initialLines);
1687 _allLinks.removeAll();
1688 for (
unsigned i = 0; i < 6; i++)
1689 HepAListDeleteAll(_links[i]);
1690 HepAListDeleteAll(_forLine);
1692#ifdef TRKRECO_DEBUG_DETAIL
1693 std::cout <<
" ... # of poor seeds = " << poorSeeds.length() << std::endl;
1695#ifdef TRKRECO_WINDOW
1696 if (bestCandidate == NULL) {
1697 sz.text(
"3D failed");
1703 if (bestCandidate) {
1705 for (
unsigned i = 0; i < segments.length(); i++) {
1706 TSegment & segment = * segments[i];
1708 if (used.length()) {
1709 bestCandidate->
segments().append(segment);
1710 segment.
tracks().append(bestCandidate);
1715 if (poorSeeds.length())
1716 HepAListDeleteAll(poorSeeds);
1718#ifdef TRASA_DEBUG_DETAIL
1719 if (bestCandidate == NULL)
1720 std::cout <<
"... building stereo(new) failed" << std::endl;
1722 std::cout <<
"... building stereo(new) ok" << std::endl;
1724 return bestCandidate;
#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.
virtual double getReferField()=0
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 freeT0(void) const
sets/returns free T0 flag.
bool tof(void) const
sets/returns propagation-delay correction flag.
int fit(TTrackBase &) const
bool sag(void) const
sets/returns sag correction flag.
IMagneticFieldSvc * getMagneticFieldPointer(void) const
bool propagation(void) const
sets/returns propagation-delay correction flag.
unsigned state(void) const
returns state.
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)
removes bad points by pull. The bad points are removed from the track, and are returned in 'list'.
bool fitted(void) const
returns true if fitted.
void append(TMLink &)
appends a TMLink.
const AList< TMLink > & links(unsigned mask=0) const
returns a list of masked TMLinks assigned to this track. 'mask' will be applied if mask is not 0.
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.