17#include "CLHEP/String/Strings.h"
33unsigned TConformalFinder::_stage = ConformalOutside;
41static const float PI2 = 2. *
M_PI;
42static const float WIDTH[] = {
PI2 / 40,
61 unsigned perfectSegmentFinding,
65 unsigned minNLinksForSegment,
66 unsigned minNCoreLinks,
67 unsigned minNSegments,
68 unsigned salvageLoadWidth,
70 unsigned stereoLoadWidth,
71 float szSegmentDistance,
74: _fastFinder(fastFinder),
75 _slowFinder(slowFinder),
77 _perfectSegmentFinding(perfectSegmentFinding),
78 _segmentSeparation(4),
79 _minNLinksForSegment(minNLinksForSegment),
80 _minNLinksForSegmentInRefine(2),
81 _maxNLinksForSegment(8),
82 _maxWidthForSegment(4),
83 _minNCoreLinks(minNCoreLinks),
84 _minNSegments(minNSegments),
85 _minUsedFractionSlow2D(0.5),
86 _salvageLoadWidth(salvageLoadWidth),
87 _stereoMode(stereoMode),
88 _stereoLoadWidth(stereoLoadWidth),
92 _builder(
"conformal builder",
101 , _rphiWindow(
"rphi window")
104 _linkMaxDistance[0] = 0.02;
105 _linkMaxDistance[1] = 0.025;
106 _linkMaxDistance[2] = 0.025;
107 _linkMinDirAngle[0] = 0.97;
108 _linkMinDirAngle[1] = 0.95;
109 _linkMinDirAngle[2] = 0.95;
113 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
114 if(scmgn!=StatusCode::SUCCESS) {
115 std::cout<< __FILE__<<
"Unable to open Magnetic field service"<<std::endl;
124 if (msg.find(
"state") != std::string::npos) {
128 std::cout <<
"#axial=" << _hits[0].length();
129 std::cout <<
",#stereo=" << _hits[1].length();
131 if (msg.find(
"summary") != std::string::npos || msg.find(
"detail") != std::string::npos) {
174 for (
unsigned i = 0; i < 3; i++) {
176 HepAListDeleteAll(_allHits[i]);
178 _allHits[i].removeAll();
179 _hits[i].removeAll();
180 _unused[i].removeAll();
182 for (
unsigned i = 0; i < 2; i++) {
183 for (
unsigned j = 0; j < 6; j++) {
184#ifdef TRKRECO_DEBUG_DETAIL
185 cout<<
"_allSegments length = "<<_allSegments[i][j].length()<<
" _allUnused length = "<<_allUnused[i][j].length()<<endl;
187 HepAListDeleteAll(_allSegments[i][j]);
188 _allUnused[i][j].removeAll();
191 _2DTracks.removeAll();
192 _3DTracks.removeAll();
196TConformalFinder::selectGoodHits(
void) {
197 for (
unsigned i = 0; i < 2; i++) {
198 unsigned n = _allHits[i].length();
199 for (
unsigned j = 0; j <
n; j++) {
200 unsigned state = _allHits[i][j]->hit()->state();
204 _hits[i].append(_allHits[i][j]);
206 _unused[i].append(_allHits[i][j]);
209 _hits[2].append(_hits[0]);
210 _hits[2].append(_hits[1]);
211 _unused[2].append(_unused[0]);
212 _unused[2].append(_unused[1]);
216 _rphiWindow.skip(
false);
217 _rphiWindow.skipAllWindow(
false);
218 _rphiWindow.append(_allHits[2]);
219 _rphiWindow.append(_hits[2], leda_pink);
226TConformalFinder::findSegments(
void) {
230 unsigned n = _hits[2].length();
231 for (
unsigned i = 0; i <
n; i++) {
232 TMLink & l = * _hits[2][i];
262 for (
unsigned i = 0; i < 11; i++) {
265 unsigned superLayerId;
268 case 0: superLayerId = 0;
id = 1;
break;
269 case 1: superLayerId = 1;
id = 1;
break;
270 case 2: superLayerId = 0;
id = 0;
break;
271 case 3: superLayerId = 1;
id = 0;
break;
272 case 4: superLayerId = 2;
id = 0;
break;
273 case 5: superLayerId = 2;
id = 1;
break;
274 case 6: superLayerId = 3;
id = 1;
break;
275 case 7: superLayerId = 4;
id = 1;
break;
276 case 8: superLayerId = 5;
id = 1;
break;
277 case 9: superLayerId = 3;
id = 0;
break;
278 case 10: superLayerId = 4;
id = 0;
break;
288 unsigned n = tmp.length();
291 for (
unsigned j = 0; j <
n; j++) {
293 if (
s->links().length() < _minNLinksForSegment)
295 else if (
s->links().length() > _maxNLinksForSegment)
301 for (
unsigned j = 0; j < bad.length(); j++) {
302 _unused[id].append(bad[j]->links());
303 _unused[2].append(bad[j]->links());
305 HepAListDeleteAll(bad);
328 _allSegments[id][superLayerId].append(tmp);
329 _allUnused[id][superLayerId] = _allSegments[id][superLayerId];
333#ifdef TRKRECO_DEBUG_DETAIL
334 std::cout <<
"... segment finding finished" << std::endl;
339TConformalFinder::linkSegments(
unsigned level) {
341 unsigned superLayer = 5;
342 while (--superLayer) {
344 unsigned n = segments.length();
346 for (
unsigned i = 0; i <
n; i++) {
349 if (base.
tracks().length()) {
350 std::cout <<
"TConformalFinder::linkSegments !!! segment has ";
351 std::cout <<
"an assignment to track(s)" << std::endl;
361 while (--superLayer) {
365 unsigned n = segments.length();
366 for (
unsigned i = 0; i <
n; i++) {
369 if (base.
tracks().length()) {
370 std::cout <<
"TConformalFinder::linkSegments !!! segment has ";
371 std::cout <<
"an assignment to track(s)" << std::endl;
386 TSegment * best = link(base, p,
v, targets, candidates, level);
387 if ((best ==
NULL) && (level > 0) && (superLayer > 1)) {
388 best = link(base, p,
v, targets2, candidates, level);
390 if (best) candidates.insert(best);
394 unsigned m = candidates.length();
395 for (
unsigned j = 0; j < m; j++)
396 candidates[j]->outerLinks().append(base);
439 cout<<
"SuperLayer: "<<superLayer<<endl;
441 unsigned n = segments.length();
442 for (
unsigned i = 0; i <
n; i++) {
444 cout<<
"Layer: "<<base.
links()[0]->hit()->wire()->layerId()
445 <<
" Local: "<<base.
links()[0]->hit()->wire()->localId()
446 <<
" innerSeg: "<<base.
innerLinks().length()<<endl;
453 displayStatus(
"Conf::linkSegments ... results");
459TConformalFinder::resolveSegments(
AList<TTrack> & trackCandidates)
const {
461 std::cout <<
"... resolving assignments" << std::endl;
466 unsigned n = trackCandidates.length();
467 for (
unsigned i = 0; i <
n; i++) {
468 TTrack &
t = * trackCandidates[i];
470 unsigned nS = segments.length();
471 for (
unsigned j = 0; j < nS; j++) {
472 if (segments[j]->tracks().length() > 1)
473 multi.append(segments[j]);
480 for (
unsigned i = 0; i <
n; i++) {
483 unsigned nT = tracks.length();
488 unsigned nL = links.length();
489 for (
unsigned j = 0; j < nL; j++) {
491 bool overlap =
false;
492 for (
unsigned k = 0; k < nT; k++) {
494 if (
t.links().hasMember(l))
497 multiLinks.append(l);
502 std::cout <<
" segment : ";
503 s.dump(
"hits sort flag");
504 std::cout <<
" # of assigned tracks = " << nT << std::endl;
505 std::cout <<
" # of overlap TMLinks = " << multiLinks.length();
506 std::cout << std::endl;
509 nL = multiLinks.length();
510 for (
unsigned j = 0; j < nL; j++) {
511 TMLink & l = * multiLinks[j];
513 float bestDiff = 999999999.;
515 for (
unsigned k = 0; k < nT; k++) {
520 float diff = fabs(distance - l.
hit()->
drift());
521 if (diff < bestDiff) {
527 for (
unsigned k = 0; k < nT; k++) {
529 if (&
t == best)
continue;
535 std::cout <<
" " << l.
wire()->
name() <<
" -> ";
536 std::cout << best->
name() << std::endl;
544TConformalFinder::removeBadSegments(
TTrack &
t)
const {
546 std::cout <<
"... removing bad segments : # used seg = ";
547 std::cout <<
t.segments().length() << std::endl;
549#ifdef TRKRECO_DEBUG_DETAIL
550 for (
unsigned i = 0; i <
t.segments().length(); i++)
551 t.segments()[i]->dump(
"hits sort flag",
" ");
558 unsigned n = segments.length();
559 for (
unsigned i = 0; i <
n; i++) {
562 unsigned nLinks = links.length();
564 unsigned nCores =
Cores(links).length();
565 unsigned nCoresSegment =
s.nCores();
568 if ((nCores < _minNCoreLinks) && (nCores < ((nCoresSegment + 1) / 2))){
573 unsigned id = segments[i]->superLayerId();
575 if (!
id) innerMost = &
s;
584 if (! bads.length())
return bads;
587 std::cout <<
" bad segments : # = " << bads.length() << std::endl;
591 for (
unsigned i = 0; i <
n; i++) {
596 unsigned nLinks = links.length();
597 unsigned nCores =
Cores(links).length();
598 std::cout <<
" # used links = " << nLinks;
599 std::cout <<
", # used cores = " << nCores << std::endl;
600 s.dump(
"hits sort flag",
" ");
603 s.tracks().remove(
t);
604 t.segments().remove(
s);
612 std::cout <<
"... refitting" << std::endl;
613 t.dump(
"detail",
"2nd> ");
620TConformalFinder::link(
const TSegment & base,
625 unsigned level)
const {
628 std::cout <<
" link : base = " << std::endl;
629 base.
dump(
"vector hits mc sort",
"-> ");
630 std::cout <<
" p=" << p <<
", v=" <<
v.unit() << std::endl;
638 unsigned n = candidates.length();
639 float maxAngle = -999.;
640 float minDistance = _linkMaxDistance[level];
641 float maxDirAngle = _linkMinDirAngle[level];
644 for (
unsigned j = 0; j <
n; j++) {
645 TSegment & current = * candidates[j];
647#ifdef TRKRECO_DEBUG_DETAIL
648 current.
dump(
"vector hits mc sort",
" ");
649 std::cout <<
" dist,dirAngle,angle=" << current.
distance(p,
v);
650 std::cout <<
"," << ((current.
position() - p).
unit()).dot(
v.unit());
651 std::cout <<
"," <<
v.dot(current.
direction()) << std::endl;
657 if (distance > _linkMaxDistance[level])
continue;
660 if (dir.x() >
M_PI) dir.setX(dir.x() -
PI2);
661 else if (dir.x() < -
M_PI) dir.setX(
PI2 + dir.x());
663 float dirAngle = dir.unit().dot(
v.unit());
665 if (dirAngle < _linkMinDirAngle[level])
continue;
671 if (dirAngle > maxDirAngle) {
672 maxDirAngle = dirAngle;
675 alternatives.append(current);
679 std::cout <<
" # of best + alternatives = " << alternatives.length() << std::endl;
681 std::cout <<
" Best is ";
686 alternatives.remove(best);
687 if (best)
return best;
692TConformalFinder::deleteTrack(
TTrack &
t)
const {
694 unsigned n = segments.length();
695 for (
unsigned i = 0; i <
n; i++) {
697 s.tracks().remove(
t);
704TConformalFinder::removeUsedSegments(
const AList<TTrack> & tracks) {
705 unsigned n = tracks.length();
706 for (
unsigned i = 0; i <
n; i++) {
710 unsigned nS = segments.length();
711 for (
unsigned j = 0; j < nS; j++) {
713 unsigned sId =
s.superLayerId();
719 case 0: as = 1;
id = 0;
break;
720 case 1: as = 1;
id = 1;
break;
721 case 2: as = 0;
id = 0;
break;
722 case 3: as = 0;
id = 1;
break;
723 case 4: as = 0;
id = 2;
break;
724 case 5: as = 1;
id = 2;
break;
725 case 6: as = 1;
id = 3;
break;
726 case 7: as = 1;
id = 4;
break;
727 case 8: as = 1;
id = 5;
break;
728 case 9: as = 0;
id = 3;
break;
729 case 10: as = 0;
id = 4;
break;
735 if (links.length() == 0) {
736 s.tracks().remove(
t);
737 toBeRemoved.append(
s);
739 std::cout <<
"!!! why this happends???" << std::endl;
740 std::cout <<
" no used link" << std::endl;
746 _allUnused[as][id].remove(
s);
750 unsigned nO = outers.length();
753 for (
unsigned i = 0; i < nO; i++) {
754 outers[i]->innerLinks().remove(
s);
760 unused.remove(links);
762 unsigned nUnused = unused.length();
788 segments.remove(toBeRemoved);
794 unsigned n = tracks.length();
795 for (
unsigned i = 0; i <
n; i++) {
797 unsigned nL = links.length();
798 for (
unsigned j = 0; j < nL; j++) {
800 tracks[i]->approach(l);
811 _stage = ConformalInitialization;
814 static bool first =
true;
826 std::cout <<
name() <<
" ... processing"
827 <<
" axial=" << axial.length()
828 <<
",stereo=" << stereo.length()
829 <<
",tracks=" << tracks.length()
839 _allHits[2].append(_allHits[0]);
840 _allHits[2].append(_allHits[1]);
845 cout<<
"axial Hits:"<<_allHits[0].length()<<
" good axial hits:"<<_hits[0].length()
846 <<endl<<
"stereo Hits:"<<_allHits[1].length()<<
" good setero hits:"<<_hits[1].length()
851 if (_perfectSegmentFinding)
852 findSegmentsPerfect();
858 cout<<
"axial Seg: "<<_allSegments[0][0].length()<<
", "<<_allSegments[0][1].length()
859 <<
", "<<_allSegments[0][2].length()<<
", "<<_allSegments[0][3].length()
860 <<
", "<<_allSegments[0][4].length()<<
", "<<_allSegments[0][5].length()
861 <<
" stereo Seg: "<<_allSegments[1][0].length()<<
", "<<_allSegments[1][1].length()
862 <<
", "<<_allSegments[1][2].length()<<
", "<<_allSegments[1][3].length()
863 <<
", "<<_allSegments[1][4].length()<<
", "<<_allSegments[1][5].length()<<endl;
865 for(
int i=0; i<2; ++i) {
866 if (i == 0) cout<<
"Axial......"<<endl;
867 else cout<<
"Stereo......"<<endl;
868 for(
int j=0; j<6; ++j) {
869 for(
int k=0; k<_allSegments[i][j].length(); ++k){
870 cout<<
"SL(a/s): "<<j<<
" seeds in Seg"<<k<<
": "<<_allSegments[i][j][k]->links().length()<<endl;
871 for(
int kk=0; kk<_allSegments[i][j][k]->links().length(); ++kk)
872 cout<<
" layerId: "<<_allSegments[i][j][k]->links()[kk]->hit()->wire()->layerId()
873 <<
" localId: "<<_allSegments[i][j][k]->links()[kk]->hit()->wire()->localId()<<endl;
881 _T0ResetDone =
false;
884 fastFinding2D(level);
885 updateTLinks(_2DTracks);
889 std::cout <<
"TConformalFinder ... T0 reset is done" << std::endl;
895 _rphiWindow.skip(
false);
897 fastFinding3D(level);
898 updateTLinks(_2DTracks);
899 updateTLinks(_3DTracks);
902 _rphiWindow.skip(
false);
903 displayTracks(_2DTracks, _allUnused,
"all 2D after fast level 0");
904 displayTracks(_3DTracks, _allUnused,
"all 3D after fast level 0");
911 fastFinding2D(level);
912 updateTLinks(_2DTracks);
915 _rphiWindow.skip(
false);
917 fastFinding3D(level);
918 updateTLinks(_2DTracks);
919 updateTLinks(_3DTracks);
922 _rphiWindow.skip(
false);
923 displayTracks(_2DTracks, _allUnused,
"all 2D after fast level 1");
924 displayTracks(_3DTracks, _allUnused,
"all 3D after fast level 1");
932 slowFinding2D(level);
933 updateTLinks(_2DTracks);
935 _rphiWindow.skip(
false);
938 fastFinding3D(level);
939 updateTLinks(_2DTracks);
940 updateTLinks(_3DTracks);
943 _rphiWindow.skip(
false);
945 displayTracks(_2DTracks, _allUnused,
"all 2D after slow level 2");
946 displayTracks(_3DTracks, _allUnused,
"all 3D after slow level 2");
951 int zsltrk = _2DTracks.length();
952 std::cout <<
name() <<
" ... # 3D tracks = " << _3DTracks.length()
953 <<
", # 2D tracks = " << _2DTracks.length() << std::endl;
954 for (
unsigned i = 0; i < zsltrk; i++){
956 cout<<
"pt:"<<_2DTracks[i]->pt()<<
" impact:"<<_2DTracks[i]->impact()<<endl;
964 tracks2D = _2DTracks;
966 for(
int i=0;i<_3DTracks.length();i++){
968 _3DTracks[i]->setFinderType(2);
973 for(
int nn = 0; nn < tracks2D.length(); ++nn){
974 cout<<
"2D: "<<nn<<
" radius: "<<tracks2D[nn]->radius()<<endl;
975 for (
int mm = 0; mm < tracks2D[nn]->links().length(); ++mm)
976 cout<<
"layer: "<<tracks2D[nn]->links()[mm]->wire()->layerId()
977 <<
" local: "<<tracks2D[nn]->links()[mm]->wire()->localId()<<endl;
980 cout<<
"unused axial Seg: "<<_allUnused[0][0].length()<<
", "<<_allUnused[0][1].length()
981 <<
", "<<_allUnused[0][2].length()<<
", "<<_allUnused[0][3].length()
982 <<
", "<<_allUnused[0][4].length()<<
", "<<_allUnused[0][5].length()
983 <<
" unused stereo Seg: "<<_allUnused[1][0].length()<<
", "<<_allUnused[1][1].length()
984 <<
", "<<_allUnused[1][2].length()<<
", "<<_allUnused[1][3].length()
985 <<
", "<<_allUnused[1][4].length()<<
", "<<_allUnused[1][5].length()
988 for(
int i=0; i<2; ++i) {
989 if (i == 0) cout<<
"unused axial hits: "<<endl;
990 else cout<<
"unused stereo hits: "<<endl;
991 for(
int k = 0; k < _allHits[i].length(); ++k) {
992 if (_allHits[i][k]->hit()->state() &
WireHitUsed)
continue;
993 else cout<<
" layerId: "<<_allHits[i][k]->hit()->wire()->layerId()
994 <<
" localId: "<<_allHits[i][k]->hit()->wire()->localId()<<endl;
996 if (i == 0) cout<<
"unused axial link in segs: "<<endl;
997 else cout<<
"unused stereo link in segs: "<<endl;
998 for(
int j=0; j<6; ++j) {
999 for(
int k=0; k<_allUnused[i][j].length(); ++k){
1000 cout<<
"sl: "<<i<<
" "<<j<<
" length of seg "<<k<<
": "<<_allUnused[i][j][k]->links().length()<<endl;
1001 for(
int kk=0; kk<_allUnused[i][j][k]->links().length(); ++kk)
1002 cout<<
" layerId: "<<_allUnused[i][j][k]->links()[kk]->hit()->wire()->layerId()
1003 <<
" localId: "<<_allUnused[i][j][k]->links()[kk]->hit()->wire()->localId()<<endl;
1040TConformalFinder::fastFinding3D(
unsigned level) {
1042#ifdef TRKRECO_DEBUG_DETAIL
1043 std::cout <<
"... fast finding (3D) : level = " << level << std::endl;
1046 if (_stage == ConformalSlow2D) {
1047 _stage = ConformalSlow3D;
1050 _stage = ConformalFast3DLevel0;
1052 _stage = ConformalFast3DLevel1;
1059 unsigned n = _2DTracks.length();
1060 for (
unsigned i = 0; i <
n; i++) {
1062 const TTrack &
t = * _2DTracks[i];
1065 cout<<
"links in 2Dtracks: "<<
t.links().length()<<endl;
1066 for (
int ii = 0; ii <
t.links().length(); ++ii) {
1067 cout<<
"layerId: "<<
t.links()[ii]->wire()->layerId()
1068 <<
" localId: "<<
t.links()[ii]->wire()->localId()<<endl;
1070 cout<<
"center: "<<
t.center()<<
" radius = "<<
t.radius()<<endl;
1073#ifdef TRKRECO_DEBUG_DETAIL
1074 std::cout <<
"==> fast 3D building : " <<
t.name() << std::endl;
1075 t.dump(
"hits sort flag",
" 2D track hits=");
1079 unsigned NS = segments.length();
1080 if (
NS >= 30 )
continue;
1090 if (_stereoMode == 2)
1091 badSegments = stereoSegmentsFromBadHits(
t);
1099#ifdef TRKRECO_WINDOW
1100 displayStatus(
"Conf::fast3D ... seed");
1101 _rphiWindow.append(segments, leda_blue);
1102 _rphiWindow.append(badSegments, leda_red);
1103 _rphiWindow.oneShot(
t, leda_green);
1114 HepAListDeleteAll(badSegments);
1117#ifdef TRKRECO_DEBUG_DETAIL
1118 std::cout <<
"... 3D failure" << std::endl;
1120#ifdef TRKRECO_WINDOW
1121 displayStatus(
"Conf::fastd3D ... 3D failed");
1122 _rphiWindow.append(segments, leda_blue);
1123 _rphiWindow.oneShot(
t, leda_red);
1129#ifdef TRKRECO_DEBUG_DETAIL
1130 std::cout <<
"... 3D failure (bad quality)" << std::endl;
1132#ifdef TRKRECO_WINDOW
1133 displayStatus(
"Conf::fastd3D ... 3D failed (bad quality)");
1134 _rphiWindow.append(segments, leda_blue);
1135 _rphiWindow.oneShot(*
s, leda_red);
1150 s->name(
t.name() +
"-3D");
1152#ifdef TRKRECO_WINDOW
1153 displayStatus(
"Conf::fastd3D ... 3D ok");
1154 _rphiWindow.append(segments, leda_blue);
1155 _rphiWindow.oneShot(*
s, leda_green);
1159 salvage(*
s, 3, bads);
1162 touched.append(_2DTracks[i]);
1171 removeUsedSegments(tmp);
1173 if(tracks3D.length()>20)
break;
1174#ifdef TRKRECO_DEBUG_DETAIL
1175 std::cout <<
"... 3D finished : " <<
s->name() << std::endl;
1176 s->dump(
"detail",
" ");
1178#ifdef TRKRECO_WINDOW
1179 displayStatus(
"Conf::fastd3D ... finished");
1180 _rphiWindow.oneShot(*
s, leda_green);
1185 _3DTracks.append(tracks3D);
1186 _2DTracks.remove(tracks3D);
1187 _2DTracks.remove(touched);
1188 for (
unsigned i = 0; i < touched.length(); i++) {
1189 deleteTrack(* touched[i]);
1194#ifdef TRKRECO_WINDOW
1196TConformalFinder::displayStatus(
const std::string & m)
const {
1197 _rphiWindow.clear();
1198 _rphiWindow.text(m);
1199 _rphiWindow.append(_allHits[2], leda_pink);
1200 _rphiWindow.append(_hits[2], leda_cyan);
1201 _rphiWindow.append(_unused[2]);
1202 displayAppendSegments(_allSegments, leda_grey1);
1203 displayAppendSegments(_allUnused, leda_orange);
1208 leda_color c)
const {
1209 for (
unsigned i = 0; i < 2; i++) {
1210 for (
unsigned j = 0; j < 6; j++) {
1212 unsigned n = segments.length();
1213 for (
unsigned k = 0; k <
n; k++) {
1214 _rphiWindow.append(* segments[k], c);
1223 const std::string & c)
const {
1224 displayStatus(
"Conf::display ... " + c);
1225 for (
unsigned i = 0; i < l.length(); i++)
1226 _rphiWindow.append(* l[i], leda_green);
1232TConformalFinder::quality2D(
TTrack &
t,
unsigned level)
const {
1233#ifdef TRKRECO_WINDOW
1234 std::string
s =
"Conf::quality2D ... level " + itostring(level);
1238 if(fabs(
t.radius()) < 15.)
return false;
1243 if (nSuperLayers < _minNSegments) {
1245 std::cout <<
"... quality check : level=" << level <<
" : bad" << std::endl;
1246 std::cout <<
" reason : # segments(superlayer) =" << nSuperLayers;
1247 std::cout <<
" < " << _minNSegments << std::endl;
1249#ifdef TRKRECO_WINDOW
1250 s +=
" rejected because of few segments(superlayers)";
1252 _rphiWindow.oneShot(
t, leda_red);
1257#ifdef TRKRECO_WINDOW
1258 s +=
" ok : # of used segments(superlayers) = ";
1259 s += itostring(nSuperLayers);
1260 s +=
" > " + itostring(_minNSegments);
1262 _rphiWindow.oneShot(
t, leda_green);
1272 if (n3 != nSuperLayers) {
1277 std::cout <<
"... quality check : level = " << level <<
" : bad";
1278 std::cout << std::endl;
1279 std::cout <<
" reason : super layer pattern(n2) = 0 " << std::endl;
1281#ifdef TRKRECO_WINDOW
1282 s +=
" rejected because of bad super-layer pattern(n2=0)";
1284 _rphiWindow.oneShot(
t, leda_red);
1324 std::cout <<
"... quality check : level = " << level;
1325 std::cout <<
" : ok, super layer pattern = " << std::endl;
1328 for (
unsigned j = 0; j < 6; j++) {
1329 unsigned k = (sl >> (j * 2)) % 2;
1334 std::cout << std::endl;
1336#ifdef TRKRECO_WINDOW
1337 s +=
" ok : super layer ptn = " + ptn;
1339 _rphiWindow.oneShot(
t, leda_green);
1346TConformalFinder::fastFinding2D(
unsigned level) {
1348#ifdef TRKRECO_DEBUG_DETAIL
1349 std::cout <<
"... fast finding (2D) : level = " << level << std::endl;
1352 _stage = ConformalFast2DLevel0;
1354 _stage = ConformalFast2DLevel1;
1359 unsigned idBase = _2DTracks.length() + _3DTracks.length();
1360 unsigned nTrial = 0;
1361 unsigned seedLayer = 5;
1372 while ((seedLayer--) > 1) {
1376 unsigned n = segments[seedLayer].length();
1378 for (
unsigned i = 0; i <
n; i++) {
1379 TSegment & seed = * segments[seedLayer][i];
1380 std::string
name =
"f" + itostring(nTrial + idBase);
1385 std::cout <<
">>> fast 2D : super layer " << seedLayer <<
", ";
1386 std::cout << i <<
" : ";
1406 cout<<
"seeds in fastFinding2D: "<<seeds.length()<<endl;
1407 for (
int kk = 0; kk < seeds.length(); ++kk)
1408 cout<<
"LayerId: "<<seeds[kk]->links()[0]->wire()->layerId()
1409 <<
" LocalId: "<<seeds[kk]->links()[0]->wire()->localId()<<endl;
1416 for (
int k = 0; k < seeds.length(); ++k)
1417 seeds[k]->solveLR();
1419#ifdef TRKRECO_WINDOW
1420 displayStatus(
"Conf::fast2D ... seed segments");
1421 _rphiWindow.oneShot(seeds, leda_green);
1426 std::cout <<
"==> fast building 2D : seed layer = " << seedLayer;
1427 std::cout <<
", " <<
name << std::endl;
1437 bool ok = quality2D(*
t, 0);
1450 if (bads.length()) {
1451 ok = quality2D(*
t, 1);
1453 seeds = refineSegments(*
t);
1454 if (seeds.length() >= _minNSegments) {
1463 salvage(*
t, 1, bads);
1466 refineLinks(*
t, 2);
1471 ok = quality2D(*
t, 2);
1486 std::cout <<
"... 2D finished : " <<
t->name() << std::endl;
1487 t->dump(
"hits sort flag pull",
" ");
1489#ifdef TRKRECO_WINDOW
1490 displayStatus(
"Conf::fast2D ... finished");
1491 _rphiWindow.oneShot(*
t, leda_green);
1496 trackCandidates.append(
t);
1500 resolveSegments(trackCandidates);
1512 removeUsedSegments(trackCandidates);
1522 _2DTracks.append(trackCandidates);
1525 resolveHits(_2DTracks);
1532 std::cout <<
"p = " << p << std::endl;
1533 float r = sqrt(4. / p.mag2());
1534 float phi = p.phi();
1535 return cdc.
wire(r, phi);
1539TConformalFinder::pickUpSegmentsInConformal(
float phi[12],
1541 unsigned axialStereoSwitch)
const {
1544 center.setPhi(phi[0]);
1547 for (
unsigned sl = 0; sl < 2; sl++) {
1549 if (! (axialStereoSwitch & 1))
continue;
1552 if (! (axialStereoSwitch & 2))
continue;
1554 for (
unsigned i = 0; i < 6; i++) {
1556 unsigned n = list.length();
1557 for (
unsigned j = 0; j <
n; j++) {
1561 if (center.dot(p) < 0.)
continue;
1565 unsigned m = inners.length();
1566 for (
unsigned k = 0; k < m; k++) {
1567 float dPhi = phi[i * 2 + sl] -
1568 inners[k]->position().phi();
1569 dPhi = fabs(fmod(dPhi,
PI2));
1570 if (dPhi > (
PI2 - dPhi)) dPhi =
PI2 - dPhi;
1571 if (dPhi < WIDTH[i * 2 + sl] * loadWidth) {
1578 if (found)
continue;
1580 m = outers.length();
1581 for (
unsigned k = 0; k < m; k++) {
1582 float dPhi = phi[i * 2 + sl + 1] -
1583 outers[k]->position().phi();
1584 dPhi = fabs(fmod(dPhi,
PI2));
1585 if (dPhi > (
PI2 - dPhi)) dPhi =
PI2 - dPhi;
1586 if (dPhi < WIDTH[i * 2 + sl] * loadWidth) {
1599TConformalFinder::pickUpLinksInConformal(
float phi[12],
1601 unsigned axialStereoSwitch)
const {
1603 center.setPhi(phi[0]);
1606 unsigned nBad = _unused[2].length();
1607 for (
unsigned i = 0; i < nBad; i++) {
1608 unsigned sl = _unused[2][i]->wire()->superLayerId();
1609 unsigned as = sl % 2;
1611 if (! (axialStereoSwitch & 1))
continue;
1614 if (! (axialStereoSwitch & 2))
continue;
1617 const HepPoint3D & p = _unused[2][i]->position();
1618 if (center.dot(p) < 0.)
continue;
1620 float dPhi = phi[sl] - _unused[2][i]->position().phi();
1621 dPhi = fabs(fmod(dPhi,
PI2));
1622 if (dPhi > (
PI2 - dPhi)) dPhi =
PI2 - dPhi;
1623 if (dPhi < WIDTH[sl] * loadWidth) {
1624 outList.append(_unused[2][i]);
1627 dPhi = phi[sl + 1] - _unused[2][i]->position().phi();
1628 dPhi = fabs(fmod(dPhi,
PI2));
1629 if (dPhi > (
PI2 - dPhi)) dPhi =
PI2 - dPhi;
1630 if (dPhi < WIDTH[sl] * loadWidth)
1631 outList.append(_unused[2][i]);
1637TConformalFinder::crossPointsInConformal(
const AList<TSegment> & inList,
1640 static const float confRadius2[] = {4. / ( 8.3 * 8.3),
1651 4. / (87.4 * 87.4)};
1656 unsigned n = inList.length();
1657 for (
unsigned i = 0; i <
n; i++) {
1658 const HepPoint3D & p = inList[i]->position();
1662 center *= 1. / float(
n);
1666 int err = line.fit();
1669 std::cout <<
"crossPoints ... failed due to line fit failure" << std::endl;
1671 HepAListDeleteAll(forLine);
1676 for (
unsigned i = 0; i < 12; i++) {
1678 float c = - line.a() * line.b();
1679 float d = 1. + line.a() * line.a();
1680 float e = sqrt(confRadius2[i] * d - line.b() * line.b());
1681 p[0].setX((c + e) / d);
1682 p[0].setY(line.a() * p[0].x() + line.b());
1683 p[1].setX((c - e) / d);
1684 p[1].setY(line.a() * p[1].x() + line.b());
1686 float mag0 = (center - p[0]).mag();
1687 float mag1 = (center - p[1]).mag();
1689 if (mag0 < mag1) points[i] = p[0];
1690 else points[i] = p[1];
1691#ifdef TRKRECO_DEBUG_DETAIL
1692 std::cout <<
"0,1 = " << p[0] <<
", " << p[1] << std::endl;
1696#ifdef TRKRECO_DEBUG_DETAIL
1697 std::cout <<
"... center is : " << center << std::endl;
1698 std::cout <<
"... cross points are : " << std::endl;
1699 for (
unsigned i = 0; i < 12; i++) {
1700 std::cout <<
" " << i <<
" : " << points[i] << std::endl;
1703#ifdef TRKRECO_WINDOW
1704 displayStatus(
"Conf::crossPoints ... line to salvage for conf plane");
1705 _rphiWindow.append(inList, leda_green);
1706 _rphiWindow.oneShot(line, leda_blue);
1709 HepAListDeleteAll(forLine);
1714TConformalFinder::stereoSegments(
const TTrack &
t)
const {
1716 std::cout <<
"... finding stereo segments" << std::endl;
1721 unsigned n = bases.length();
1722 if (
n == 0)
return seeds;
1726 int err = crossPoints(
t, points);
1732 std::cout <<
"... stereo segment finding failed" << std::endl;
1739 AList<TSegment> list = pickUpSegments(points,
float(_stereoLoadWidth), 2);
1745 for (
unsigned i = 0; i <
n; i++) {
1748 unsigned sl = ll[0]->wire()->axialStereoLayerId()/4;
1754 for (
unsigned i = 0; i < 5; i++) {
1755 if (dir[i].mag() < .5) {
1757 while ((j < 5) && (dir[j].mag() < .5))
1760 if (dir[j].mag() < .5) {
1762 while ((j > 0) && (dir[j].mag() < .5))
1769#ifdef TRKRECO_DEBUG_DETAIL
1770 std::cout <<
" ... direction :" << std::endl;
1771 for (
unsigned i = 0; i < 6; i++)
1772 std::cout <<
" " << i <<
" : " << dir[i] << std::endl;
1773 std::cout <<
" ... direction cos :" << std::endl;
1777 unsigned nL = list.length();
1778 for (
unsigned i = 0; i < 6; ++i)
1779 toBeChecked[i].removeAll();
1781 for (
unsigned j = 0; j < nL; ++j) {
1784 unsigned sl = ll[0]->wire()->axialStereoLayerId()/4;
1785 toBeChecked[sl].append(
s);
1788 for (
unsigned i = 0; i < 6; ++i) {
1789 unsigned nToBeChecked = toBeChecked[i].length();
1790 if (nToBeChecked < 4)
continue;
1791 unsigned nBadList = badList.length();
1792 for (
unsigned j = 0; j < nToBeChecked; ++j) {
1793 if((badList.length() - nBadList) >= nToBeChecked - 4)
break;
1799 if (sl < 2) aSl = 0;
1800 else if (sl < 4) aSl = 2;
1802 if (dir[aSl].dot(sDir) < 0.7) badList.append(
s);
1803 if (sl == 2 || sl == 3 || sl == 4) {
1804 if (dir[aSl - 1].dot(sDir) < 0.6) badList.append(
s);
1807 if (dir[aSl + 1].dot(sDir) < 0.6) badList.append(
s);
1810 toBeChecked[i].remove(badList);
1811 if (toBeChecked[i].length() > 4) {
1813 unsigned nSegs = toBeChecked[i].length();
1814 for (
unsigned j = 0; j < nSegs; ++j) {
1816 if (
s.links().length() > 3) tmp.append(
s);
1818 toBeChecked[i].remove(tmp);
1819 for (
unsigned j = 0; j < tmp.length(); ++j) {
1821 for (
unsigned k = 0; k < toBeChecked[i].length(); ++k) {
1822 TSegment & ss = * toBeChecked[i][k];
1824 for (
unsigned kk = 0; kk < threeLinks.length(); ++kk) {
1825 TMLink & ll = * threeLinks[kk];
1826 if (tmpLinks.hasMember(ll)) {
1835 toBeChecked[i].remove(badList);
1836 if (toBeChecked[i].length() > 4) {
1838 unsigned nSegs = toBeChecked[i].length();
1839 for(
unsigned k=0; k < nSegs; ++k){
1844 for(
unsigned y=0;
y<nSegs;
y++){
1845 for(
unsigned x=1;
x<nSegs-
y;
x++){
1848 if(s1.
links().length() < s2.
links().length()){
1850 *temp[
x-1] = *temp[
x];
1855 for(
unsigned j=4; j<nSegs; ++j){
1863 toBeChecked[i].remove(badList);
1866 for(
unsigned j = 0; j < toBeChecked[i].length(); ++j){
1905 list.remove(badList);
1909 std::cout <<
" ... bad segments :" << std::endl;
1910 for (
unsigned i = 0; i < badList.length(); i++)
1911 badList[i]->
dump(
"hits sort",
" ");
1918TConformalFinder::direction(
const TSegment & segment)
const {
1922 if (
s->outerLinks().length() != 1)
break;
1923 const TSegment * o =
s->outerLinks()[0];
1929 if (forLine.length() == 0)
1931 else if (forLine.length() < 2) {
1932 HepAListDeleteAll(forLine);
1938 int err = line.fit();
1941 std::cout <<
"direction ... failed due to line fit failure" << std::endl;
1943 HepAListDeleteAll(forLine);
1947 HepAListDeleteAll(forLine);
1948 Vector3 tmp(-1., -(line.a() + line.b()));
1955TConformalFinder::salvage(
TTrack & track,
1958#ifdef TRKRECO_DEBUG_DETAIL
1959 std::cout <<
"... salvaging in real plane" << std::endl;
1964 int err = crossPoints(track, points);
1966#ifdef TRKRECO_DEBUG_DETAIL
1967 std::cout <<
"... salvaging failed in calculation of intersection"
1975 float(_salvageLoadWidth),
1977 toBeChecked.remove(bads);
1978 toBeChecked.remove(track.
segments());
1979 toBeChecked = trackSide(track, toBeChecked);
1983 unsigned nB = toBeChecked.length();
1984 for (
unsigned i = 0; i < nB; i++) {
1986 unsigned nL = tmp.length();
1987 for (
unsigned j = 0; j < nL; j++) {
1988 if (tmp[j]->hit()->track())
continue;
1989 links.append(tmp[j]);
1994 AList<TMLink> all = pickUpLinks(points,
float(_salvageLoadWidth), asSwitch);
1996 std::cout<<
" pickUpLinks length = "<<all.length()<<std::endl;
1999 all = trackSide(track, all);
2000 all.remove(track.
links());
2002 std::cout<<
" after reomove pickUpLinks length = "<<all.length()<<std::endl;
2006#ifdef TRKRECO_WINDOW
2011 _builder.
salvage(track, links);
2015 for (
unsigned i = 0; i < nB; i++) {
2016 TSegment & segment = * toBeChecked[i];
2018 if (used.length() == 0)
continue;
2021 segment.
tracks().append(track);
2024#ifdef TRKRECO_WINDOW
2025 displayStatus(
"Conf::salvage ... results");
2027 _rphiWindow.append(
y, leda_red);
2028 _rphiWindow.append(toBeChecked, leda_red);
2029 _rphiWindow.oneShot(track, leda_green);
2037TConformalFinder::crossPoints(
const TTrack & track,
2040#ifdef TRKRECO_DEBUG_DETAIL
2041 std::cout <<
" cross points are :" << std::endl;
2071 static const float R[] = { 7.3,
2083 static const float R2[] = {
R[0]*
R[0],
2100 double r = fabs(track.
radius());
2102 double d2 = c.
mag2();
2103 double d = sqrt(d2);
2104 double sl = - c.
x() / c.
y();
2107 for (
unsigned i = 0; i < 12; i++) {
2108 double minR = r <
R[i] ? r :
R[i];
2109 double maxR = r <
R[i] ?
R[i] : r;
2111#ifdef TRKRECO_DEBUG_DETAIL
2112 std::cout <<
" r,R ... " << minR <<
", " << maxR <<
", " << d << std::endl;
2115 if ((r + R[i] < d) || (minR + d < maxR)) {
2120 double a = R2[i] + d2 - r2;
2121 double s = sqrt(4. * R2[i] * d2 - a * a);
2122 double q = 0.5 * a / c.
y();
2123 points[i].
x(0.5 * (c.
x() * a + c.
y() *
s) / d2);
2124 points[i].
y(
q + sl * points[i].
x());
2126 if (co.
cross(points[i] - c) * track.
charge() * Bz > 0.) {
2127 points[i].
x(0.5 * (c.
x() * a - c.
y() *
s) / d2);
2128 points[i].
y(
q + sl * points[i].
x());
2130#ifdef TRKRECO_DEBUG_DETAIL
2131 std::cout <<
" " << i <<
" : " << points[i] << std::endl;
2132 std::cout <<
" chg=" << track.
charge()<<std::endl;
2133 std::cout <<
", c=" << c <<
", co=" <<std::endl;
2134 std::cout <<
", " << co.
cross(points[i] - c) * track.
charge() << std::endl;
2135 std::cout <<
" " << 0.5 * (c.
x() * a + c.
y() *
s) / d2;
2136 std::cout <<
", " <<
q + sl * (0.5 * (c.
x() * a + c.
y() *
s) / d2);
2137 std::cout <<
" " << 0.5 * (c.
x() * a - c.
y() *
s) / d2;
2138 std::cout <<
", " <<
q + sl * (0.5 * (c.
x() * a - c.
y() *
s) / d2);
2139 std::cout << std::endl;
2148TConformalFinder::pickUpSegments(
const TPoint2D x[12],
2150 unsigned axialStereoSwitch)
const {
2156 for (
unsigned sl = 0; sl < 2; sl++) {
2159 if (! (axialStereoSwitch & 1))
continue;
2163 if (! (axialStereoSwitch & 2))
continue;
2165 for (
unsigned i = 0; i < nMax; i++) {
2171 case 0:layerId = 2;
break;
2172 case 1:layerId = 3;
break;
2173 case 2:layerId = 4;
break;
2174 case 3:layerId = 9;
break;
2175 case 4:layerId = 10;
break;
2179 case 0:layerId = 0;
break;
2180 case 1:layerId = 1;
break;
2181 case 2:layerId = 5;
break;
2182 case 3:layerId = 6;
break;
2183 case 4:layerId = 7;
break;
2184 case 5:layerId = 8;
break;
2189 if (x[layerId] == O)
continue;
2190 float a = WIDTH[layerId] * loadWidth;
2191 float phi0 =
x[layerId].phi();
2192 float phi1 =
x[layerId+1].phi();
2193 float phiC = (phi0 +
phi1) / 2.;
2194 float phiD = fabs(phi0 - phiC);
2195 if (phiD > M_PI_2) {
2202 unsigned n = list.length();
2203#ifdef TRKRECO_DEBUG_DETAIL
2204 std::cout <<
" pickUpSegments ... phi0,1,C,D=" << phi0 <<
",";
2205 std::cout <<
phi1 <<
"," << phiC <<
"," << phiD <<
" nhits "<<
n<< std::endl;
2207 for (
unsigned j = 0; j <
n; j++) {
2210#ifdef TRKRECO_DEBUG_DETAIL
2211 s.dump(
"hits sort",
" ");
2216 unsigned m = inners.length();
2217 for (
unsigned k = 0; k < m; k++) {
2218 float phi = inners[k]->position().phi();
2219 if (phi < 0.) phi +=
PI2;
2220 float dPhi = fabs(phi - phiC);
2221 if (dPhi >
M_PI) dPhi =
PI2 - dPhi;
2222#ifdef TRKRECO_DEBUG_DETAIL
2223 std::cout <<
" " << inners[k]->wire()->name();
2224 std::cout <<
", phi,dPhi=" << phi <<
"," << dPhi << std::endl;
2233 if (found)
continue;
2235 m = outers.length();
2236 for (
unsigned k = 0; k < m; k++) {
2237 float phi = outers[k]->position().phi();
2238 if (phi < 0.) phi +=
PI2;
2239 float dPhi = fabs(phi - phiC);
2240 if (dPhi >
M_PI) dPhi =
PI2 - dPhi;
2241#ifdef TRKRECO_DEBUG_DETAIL
2242 std::cout <<
" " << outers[k]->wire()->name();
2243 std::cout <<
", phi,dPhi=" << phi <<
"," << dPhi << std::endl;
2258TConformalFinder::pickUpLinks(
const TPoint2D x[12],
2260 unsigned axialStereoSwitch)
const {
2265 unsigned nBad = _unused[2].length();
2266 for (
unsigned i = 0; i < nBad; i++) {
2267 unsigned sl = _unused[2][i]->wire()->superLayerId();
2269 if (_unused[2][i]->wire()->axial()) as = 0;
2271 if (! (axialStereoSwitch & 1))
continue;
2274 if (! (axialStereoSwitch & 2))
continue;
2277 float a = WIDTH[sl] * loadWidth;
2278 float phi0 =
x[sl].phi();
2279 float phi1 =
x[sl + 1].phi();
2280 float phi = _unused[2][i]->position().phi();
2282 if (phi < 0.) phi +=
PI2;
2285 phi0 =
x[sl + 1].phi();
2287 float dPhi =
phi1 - phi0;
2291 if (phi > phi0 && phi <
phi1) outList.append(_unused[2][i]);
2296 if (phi < phi0 || phi >
phi1) outList.append(_unused[2][i]);
2298#ifdef TRKRECO_DEBUG_DETAIL
2299 std::cout <<
"TConformalFinder:: pickUpLinks " << std::endl;
2300 std::cout <<
"a "<<a <<
" phi0 "<<phi0<<
" phi1 "<<
phi1<<
" phi "<< phi<<
" dPhi "<<dPhi << std::endl;
2307TConformalFinder::slowFinding2D(
unsigned level) {
2309#ifdef TRKRECO_DEBUG_DETAIL
2310 std::cout <<
"... slow finding (2D) : level = " << level << std::endl;
2313 _stage = ConformalSlow2D;
2318 unsigned id = _2DTracks.length() + _3DTracks.length();
2319 unsigned seedLayer = 5;
2320 while (seedLayer--) {
2324 unsigned n = tmp.length();
2325 for (
unsigned i = 0; i <
n; i++) {
2328 if (current.
links().length() < 3)
continue;
2329 if (current.
innerLinks().length() != 1)
continue;
2330 if (current.
innerLinks()[0]->links().length() < 3)
continue;
2332 seeds.append(current);
2335 std::string
name =
"s" + itostring(
id);
2338 std::cout <<
"==> slow building : " <<
name << std::endl;
2342 for (
int k = 0; k < seeds.length(); ++k)
2343 seeds[k]->solveLR();
2349 salvage(*
t, 1, bads);
2350 if (! trackQuality(*
t)) {
2357 trackCandidates.append(
t);
2360 std::cout <<
"... 2D finished : " <<
t->name() << std::endl;
2361 t->dump(
"hits sort flag pull",
" ");
2363#ifdef TRKRECO_WINDOW
2364 displayStatus(
"Conf::expand ... finished");
2365 _rphiWindow.oneShot(*
t, leda_green);
2367 removeUsedSegments(trackCandidates);
2368 _2DTracks.append(trackCandidates);
2369 id = _2DTracks.length() + _3DTracks.length();
2382#ifdef TRKRECO_WINDOW
2383 displayStatus(
"Conf::expand ... seeds");
2384 _rphiWindow.oneShot(seeds, leda_green);
2387 std::cout <<
"... expand : # of seeds = " << seeds.length() << std::endl;
2390 if (seeds.length() > 2) {
2393 if (! trackQuality(*
t)) {
2405 t->segments().append(seeds);
2411TConformalFinder::expand(
TTrack & ti)
const {
2412#ifdef TRKRECO_WINDOW
2413 displayStatus(
"Conf::expand ... seed track");
2414 _rphiWindow.oneShot(ti, leda_green);
2417 std::cout <<
"... expand : by a track" << std::endl;
2422 unsigned nSegments = seeds.length();
2423 unsigned nCores =
t->nCores();
2424 unsigned nTrial = 0;
2431 targetSuperLayer(sl, inner, outer);
2433 unsigned target = inner;
2441 if (segments.length() == 0) {
2442 unsigned fl[5] = {2, 3, 4, 9, 10};
2443 unsigned inner2 = 0;
2444 unsigned outer2 = 5;
2445 for (
int i = 0; i < 5; i++) {
2446 if (fl[i] == inner) inner2 = i;
2447 if (fl[i] == outer) outer2 = i;
2449 if (inner > 2&& inner2>0) target = fl[inner2 - 1];
2451 target = fl[outer2 + 1];
2453 if (target == 13)
break;
2454 segments = targetSegments(*
t, target);
2457 std::cout <<
"... expand : segments to be checked = ";
2458 std::cout << segments.length() << std::endl;
2460#ifdef TRKRECO_WINDOW
2461 displayStatus(
"Conf::expand ... candidate segments");
2462 _rphiWindow.append(segments, leda_blue);
2463 _rphiWindow.oneShot(*
t, leda_green);
2467 unsigned n = segments.length();
2469 for (
unsigned i = 0; i <
n; i++) {
2470 segments[i]->solveLR();
2472 seed0.append(segments[i]);
2475 if ((t0->
segments().length() <= nSegments) ||
2476 (t0->
nCores() <= nCores) ||
2481 std::cout <<
"... expand : candidate deleted" << std::endl;
2488 std::cout <<
"... expand : target superlayer = " << target;
2489 std::cout <<
", # of track candidates = " << tracks.length()
2494 if (tracks.length() == 0) {
2498 if (newSl & (1 << (target))) {
2500 std::cout <<
"... expand : links to be appended = ";
2501 std::cout << links.length() << std::endl;
2503#ifdef TRKRECO_WINDOW
2504 displayStatus(
"Conf::expand ... candidate links");
2505 _rphiWindow.append(links, leda_blue);
2506 _rphiWindow.oneShot(*
t, leda_green);
2510 if ((t0->
nCores() <= nCores) ||
2515 std::cout <<
"... expand : candidate deleted" << std::endl;
2525 std::cout <<
"... expand : # of track candidates = " << tracks.length()
2530 unsigned nTracks = tracks.length();
2531 if (nTracks == 0)
break;
2532 TTrack * tNew = tracks[0];
2533 unsigned nBestCores = tNew->
nCores();
2534 for (
unsigned i = 1; i < nTracks; i++) {
2535 if (tracks[i]->nCores() > nBestCores) {
2536 deleteTrack(* tNew);
2538 nBestCores = tNew->
nCores();
2541 deleteTrack(* tracks[i]);
2544 nSegments = tNew->
segments().length();
2545 nCores = nBestCores;
2549 if (! trackQuality(* tNew)) {
2550 deleteTrack(* tNew);
2558 if (
t == & ti) std::cout <<
"... expand : failed" << std::endl;
2559 else std::cout <<
"... expand : track expanded" << std::endl;
2561#ifdef TRKRECO_WINDOW
2562 displayStatus(
"Conf::expand ... finished");
2563 _rphiWindow.oneShot(*
t, leda_green);
2570TConformalFinder::targetSuperLayer(
unsigned sl,
2572 unsigned & outer)
const {
2575 bool innerFound =
false;
2576 bool outerFound =
false;
2577 for (
unsigned i = 0; i < 5; i++) {
2578 unsigned fl[5] ={2, 3, 4, 9, 10};
2580 if (sl & (1 << (fl[i]))) innerFound =
true;
2584 if (sl & (1 << (fl[4 - i]))) outerFound =
true;
2585 else outer = fl[4 - i];
2591TConformalFinder::targetSegments(
const TTrack &
t,
unsigned sl)
const {
2596 int err = crossPoints(
t, points);
2599 std::cout <<
" ... no target found" << std::endl;
2606 unsigned n = toBeChecked.length();
2607 for (
unsigned i = 0; i <
n; i++) {
2608 if (toBeChecked[i]->superLayerId() == sl)
2609 targets.append(toBeChecked[i]);
2616TConformalFinder::targetLinks(
const TTrack &
t,
unsigned sl)
const {
2621 int err = crossPoints(
t, points);
2624 std::cout <<
" ... no target found" << std::endl;
2631 unsigned n = toBeChecked.length();
2632 for (
unsigned i = 0; i <
n; i++) {
2633 if (toBeChecked[i]->wire()->superLayerId() == sl)
2634 targets.append(toBeChecked[i]);
2641TConformalFinder::refineSegments(
const TTrack &
t)
const {
2644 unsigned n = original.length();
2645 for (
unsigned i = 0; i <
n; i++) {
2647 if (tmp.length() >= _minNLinksForSegmentInRefine)
2648 outList.append(original[i]);
2652 unsigned nStart = 0;
2655 unsigned fl[5] = {2, 3, 4, 9, 10};
2656 for (
unsigned i = 0; i < 5; i++) {
2657 if (sl & (1 << fl[i])) {
2659 if (nC == 1) nS = i;
2672 outList.removeAll();
2673 if (nCMax >= _minNSegments) {
2674 for (
unsigned i = 0; i <
n; i++) {
2675 unsigned id = original[i]->superLayerId();
2676 if ((
id >= fl[nStart]) && (
id < fl[nStart + nCMax]))
2677 outList.append(original[i]);
2682 std::cout <<
"... refine segments : orignal sl = ";
2684 std::cout <<
", output sl = ";
2686 std::cout << std::endl;
2693TConformalFinder::trackQuality(
const TTrack &
t)
const {
2698 if(fabs(
t.radius())<15.)
return false;
2700#ifdef TRKRECO_WINDOW
2701 std::cout <<
"... trackQuality : n1,n3,nMissing=" <<
n1 <<
"," << n3;
2704#ifdef TRKRECO_WINDOW
2705 displayStatus(
"trackQuality");
2707 _rphiWindow.oneShot(
t, leda_red);
2709 _rphiWindow.oneShot(
t, leda_green);
2711 if (n3 < 2)
return false;
2718TConformalFinder::refineLinks(
TTrack &
t,
unsigned minN)
const {
2721 unsigned n = links.length();
2722 for (
unsigned i = 0; i <
n; i++)
2723 sl[links[i]->wire()->superLayerId()].append(links[i]);
2725 for (
unsigned i = 0; i < 11; i++)
2726 if (sl[i].length() < minN)
2727 toBeRemoved.append(sl[i]);
2728 t.remove(toBeRemoved);
2730 std::cout <<
"... refining links : removed links = " << toBeRemoved.length();
2731 std::cout << std::endl;
2742 unsigned n = a.length();
2743 for (
unsigned i = 0; i <
n; i++) {
2744 TPoint2D x = a[i]->wire()->xyPosition();
2746 if (co.
cross(x - c) *
t.charge() * Bz < 0.)
2753TConformalFinder::trackSide(
const TTrack &
t,
2760 unsigned n = a.length();
2761 for (
unsigned i = 0; i <
n; i++) {
2764 unsigned nB =
b.length();
2765 for (
unsigned j = 0; j < nB; j++) {
2769 if (co.
cross(x - c) *
t.charge()* Bz > 0.) {
2781TConformalFinder::resolveHits(
AList<TTrack> & tracks)
const {
2782 unsigned nTracks = tracks.length();
2783 if (nTracks < 2)
return;
2785 for (
unsigned i = 0; i < nTracks - 1; i++) {
2786 TTrack & t0 = * tracks[i];
2788 unsigned n0 = links0.length();
2790 for (
unsigned j = i + 1; j < nTracks; j++) {
2791 TTrack & t1 = * tracks[j];
2793 unsigned n1 = links1.length();
2797 for (
unsigned k = 0; k < n0; k++) {
2798 TMLink & l = * links0[k];
2801 if (links1.hasMember(l)) {
2806 if (l0.pull() > l1.pull())
2813 if (remove1.length()) {
2819 if (remove0.length()) {
2827TConformalFinder::stereoSegmentsFromBadHits(
const TTrack &
t)
const {
2830 for (
unsigned i = 0; i < 6; i++)
2835 int err = crossPoints(
t, points);
2837#ifdef TRKRECO_DEBUG_DETAIL
2838 std::cout <<
"... conf::stereoSegBadHits : "
2839 <<
"error in calculation of intersection" << std::endl;
2845 unsigned nBad = _unused[2].length();
2846 for (
unsigned i = 0; i < nBad; i++) {
2847 unsigned sl = _unused[2][i]->wire()->superLayerId();
2848 unsigned asl = _unused[2][i]->wire()->axialStereoLayerId()/4;
2850 if (_unused[2][i]->wire()->axial())
2854 if (as == 0)
continue;
2856 float a = WIDTH[sl] * _salvageLoadWidth;
2857 float phi0 = points[sl].
phi();
2858 float phi1 = points[sl + 1].
phi();
2859 float phi = _unused[2][i]->position().phi();
2860 if (phi < 0.) phi +=
PI2;
2863 phi0 = points[sl + 1].
phi();
2865 float dPhi =
phi1 - phi0;
2869 if (phi > phi0 && phi <
phi1)
2871 output[asl / 4]->append(* _unused[2][i]);
2876 if (phi < phi0 || phi >
phi1)
2877 output[asl / 4]->append(* _unused[2][i]);
2885TConformalFinder::findSegmentsPerfect(
void) {
2889 unsigned nHits = _hits[2].length();
2890 for (
unsigned i = 0; i < nHits; i++) {
2891 TMLink & l = * _hits[2][i];
2899 for (
unsigned i = 0; i < 11; i++) {
2900 unsigned superLayerId = i / 2;
2901 unsigned id = i % 2;
2906 for (
unsigned j = 0; j < nHep; j++)
2910 unsigned n = links[i].length();
2911 for (
unsigned j = 0; j <
n; j++) {
2912 TMLink & l = * links[i][j];
2914 if (! l.
hit()->
mc()) {
2915 std::cout <<
"TConformalFinder::findSegmentsPerfect !!! "
2916 <<
"no MC info. found ... aborted" << std::endl;
2919 const unsigned id = mc->
hep()->
id();
2923 seeds[id]->append(l);
2928 for (
unsigned j = 0; j < nHep; j++) {
2929 if (! seeds[j])
continue;
2931 const unsigned length = seeds[j]->length();
2932 if (length < _minNLinksForSegment)
continue;
2933 if (length > _maxNLinksForSegment)
continue;
2934 if (
Width(* seeds[j]) > _maxWidthForSegment)
continue;
2937 s.append(* seeds[j]);
2940 _allSegments[id][superLayerId].append(segments);
2941 _allUnused[id][superLayerId] = _allSegments[id][superLayerId];
2944 for (
unsigned j = 0; j < nHep; j++) {
2951#ifdef TRKRECO_DEBUG_DETAIL
2952 std::cout <<
"... segment finding(perfect) finished" << std::endl;
2957TConformalFinder::findSegmentsTsf(
void) {
2960 unsigned n = _hits[2].length();
2961 for (
unsigned i = 0; i <
n; i++) {
2962 TMLink & l = * _hits[2][i];
2970 for (
unsigned i = 0; i < 11; ++i)
2973 for (
unsigned i = 0; i < 11; i++) {
2974 unsigned superLayerId;
2977 case 0: superLayerId = 0;
id = 1;
break;
2978 case 1: superLayerId = 1;
id = 1;
break;
2979 case 2: superLayerId = 0;
id = 0;
break;
2980 case 3: superLayerId = 1;
id = 0;
break;
2981 case 4: superLayerId = 2;
id = 0;
break;
2982 case 5: superLayerId = 2;
id = 1;
break;
2983 case 6: superLayerId = 3;
id = 1;
break;
2984 case 7: superLayerId = 4;
id = 1;
break;
2985 case 8: superLayerId = 5;
id = 1;
break;
2986 case 9: superLayerId = 3;
id = 0;
break;
2987 case 10: superLayerId = 4;
id = 0;
break;
2994 _allSegments[id][superLayerId].append(tmp);
2995 _allUnused[id][superLayerId] = _allSegments[id][superLayerId];
HepGeom::Vector3D< double > HepVector3D
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per saves r n generator level $ !Flag for chat level in output
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per saves r n generator level $ !Flag for chat level in !Latex Output unit
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
**********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
CLHEP::Hep3Vector Vector3
void bitDisplay(unsigned val)
const HepPoint3D ORIGIN
Constants.
#define WireHitConformalFinder
unsigned Width(const AList< TMLink > &list)
returns width(wire cell unit) of given AList<TMLink>. This function assumes that all TMLink's are in ...
unsigned SuperLayer(const AList< TMLink > &list)
returns super layer pattern.
unsigned NSuperLayers(const AList< TMLink > &list)
returns # of layers.
AList< TMLink > Cores(const AList< TMLink > &input)
unsigned NMissingAxialSuperLayers(const AList< TMLink > &links)
unsigned NMajorLinks(const TSegment &a)
returns # of links in the major link.
unsigned NUniqueLinks(const TSegment &a)
checks property of segments.
TSegment * OuterMostUniqueLink(const TSegment &a)
returns a segment to the outer-most unique segment.
AList< TSegment > UniqueLinks(const TSegment &a)
returns a list of unique segments in links.
AList< TSegment > MajorLinks(const TSegment &a)
returns a list of segments in major links.
AList< TMLink > Links(const TSegment &s, const TTrack &t)
returns AList of TMLink used for a track.
#define TrackOldConformalFinder
virtual double getReferField()=0
TTrack * buildRphi(const AList< TMLink > &) const
builds a r/phi track from TMLinks or from Segments.
void salvage(TTrack &t, AList< TMLink > &hits) const
salvages hits.
TTrack * buildStereoNew(const TTrack &t, AList< TSegment > &goodSegments, AList< TSegment > &badSegments) const
TTrack * buildStereo(const TTrack &t, AList< TSegment > &) const
A class to represent a circle in tracking.
virtual int debugLevel(void) const
returns debug level.
virtual void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
A class for a histogram used in tracking.
AList< TSegment > segments(void) const
returns an AList<TSegment0> using clusters() function.
void fillPhi(const AList< TMLink > &links)
fills with hits.
A class to represent a Track Finder Segment(TSF).
AList< TSegment > segments(const AList< TMLink > &links)
finds segments.
A class to represent a MC wire hit in MDC.
const TTrackHEP *const hep(void) const
returns a pointer to a GEN_HEPEVT.
float drift(unsigned) const
returns drift distance.
const TMDCWireHitMC *const mc(void) const
returns a pointer to TMDCWireHitMC.
A class to represent a wire in MDC.
unsigned superLayerId(void) const
returns super layer id.
std::string name(void) const
returns name.
const TMDCWire *const wire(unsigned wireId) const
returns a pointer to a wire. 0 will be returned if 'wireId' is invalid.
static TMDC * getTMDC(void)
A class to represent a track in tracking.
A class to relate TMDCWireHit and TTrack objects.
const HepPoint3D & positionOnWire(void) const
returns the closest point on wire to a track.
const HepPoint3D & positionOnTrack(void) const
returns the closest point on track to wire.
const TMDCWireHit * hit(void) const
returns a pointer to a hit.
const TMDCWire *const wire(void) const
returns a pointer to a wire.
A class to represent a point in 2D.
double cross(const TPoint2D &) const
A class to relate TMDCWireHit and TTrack objects.
const HepVector3D & direction(void) const
returns direction.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
AList< TSegment > & outerLinks(void)
const HepPoint3D & position(void) const
returns position.
double distance(const TSegment &) const
calculates distance between two clusters. Smaller value indicates closer.
AList< TSegment > & innerLinks(void)
AList< TTrack > & tracks(void)
A virtual class for a track class in tracking.
virtual int fit(void)
fits itself by a default fitter. Error was happened if return value is not zero.
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.
unsigned nCores(unsigned mask=0) const
returns # of masked TMLinks for fit. 'mask' will be applied if mask is not 0.
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.
unsigned id(void) const
returns an id started from 0.
static const AList< TTrackHEP > & list(void)
returns a list of TTrackHEP's.
static void maskBadHits(const AList< TTrack > &, float maxSigma2)
masks hits with large chisq as associated hits. Pull in TMLink is used.
static bool goodTrack(const TTrack &, bool track2D=false)
checks goodness of a track.
A class to represent a track in tracking.
AList< TSegment > & segments(void)
returns AList<TSegment>.
const std::string & name(void) const
returns/sets name.
TPoint2D center(void) const
returns position of helix center.
double radius(void) const
returns signed radius.
int approach(TMLink &) const
calculates the closest approach to a wire in real space. Results are stored in TMLink....
double charge(void) const
returns charge.
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)