29 m_deltaCut{deltaCut}, m_roadWidth{roadWidth},
30 m_fitter (std::make_shared<DCSLFitter>()),
39 std::lock_guard<std::mutex> lock(
m_mutex);
40 std::cout <<
" drop summary " << std::endl;
41 for (
unsigned int i = 0;
i <
m_dropDepthMax + 1; ++
i) { std::cout <<
" Accepted " << m_dropDepthAcceptCounts[
i] << std::endl; }
42 for (
unsigned int i = 0;
i <
m_dropDepthMax; ++
i) { std::cout <<
" Rejected " << m_dropDepthRejectCounts[
i] << std::endl; }
48 std::lock_guard<std::mutex> lock(
m_mutex);
49 m_dropDepthAcceptCounts.clear();
50 m_dropDepthAcceptCounts.resize(
max + 1, 0);
51 m_dropDepthRejectCounts.clear();
52 m_dropDepthRejectCounts.resize(
max + 1, 0);
113 if (
m_debugLevel >= 1) std::cout <<
" bad phi for road: road " <<
m_phiRoad <<
" dir phi " << roadLine.
phi() << std::endl;
118 std::cout <<
" bad phi for chamber: chamber " <<
m_phiChamber <<
" dir phi " << chamberLine.
phi() << std::endl;
128 std::cout <<
" SegmentFinder::setting: " << std::endl
139 std::cout <<
" Options: ";
140 if (
m_fullScan) std::cout <<
" -- full scan ";
143 if (
m_doDrop) std::cout <<
" -- drop hits ";
147 std::cout << std::endl;
155 std::cout <<
"In handleHits: dcs " << dcsIn.size() <<
" clusters " << clsIn.size() << std::endl;
159 std::stable_sort(dcs.begin(), dcs.end(),
SortDcsByY());
174 seedsMl1 = dcsPerMl.first;
175 seedsMl2 = dcsPerMl.second;
182 std::cout <<
" two layer scan " << std::endl;
183 for (
const auto &
it : segments.data()) { std::cout <<
" " <<
it << std::endl; }
188 segments.set(preSelSegs);
191 std::cout <<
" after cleaning " << std::endl;
192 for (
const auto &
it : segments.data()) { std::cout <<
" " <<
it << std::endl; }
195 unsigned int usedHits(0);
196 for (
const auto &
it : segments.data()) { usedHits +=
it.hitsOnTrack(); }
203 fullScan(seedsMl1, dcsPerMl.first, clsIn, segments);
206 std::cout <<
" segments after scan multilayer 1 " << std::endl;
207 for (
const auto &
it : segments.data()) { std::cout <<
" " <<
it << std::endl; }
210 fullScan(seedsMl2, dcsPerMl.second, clsIn, segments);
213 std::cout <<
" segments after scan multilayer 2 " << std::endl;
214 for (
const auto &
it : segments.data()) { std::cout <<
" " <<
it << std::endl; }
221 fullScan(seeds, dcs, clsIn, segments);
237 std::cout <<
"CurvedSegmentFinder was passed a NULL pointer to the ChamberGeometry" << std::endl;
248 std::cout <<
" final segments " << std::endl;
249 for (
auto & selectedSegment : selectedSegments) { std::cout << selectedSegment << std::endl; }
252 return selectedSegments;
257 ml1.reserve(dcs.size());
258 ml2.reserve(dcs.size());
260 if (circ.id().ml() == 0)
261 ml1.emplace_back(circ);
263 ml2.emplace_back(circ);
265 return std::make_pair(std::move(ml1), std::move(ml2));
270 if (dcs.size() <= 2)
return dcs;
276 DCCit it_start_serie;
278 DCCit it_end = dcs.end() - 1;
280 while (
it <= it_end) {
285 while (
it != it_end && isNeighbour(*
it, *(
it + 1))) { ++
it; }
290 for (; it_start_serie !=
it + 1; ++it_start_serie) {
292 if (it_start_serie->driftState() ==
DriftCircle::InTime) { seeds.push_back(*it_start_serie); }
298 if (
it == dcs.end())
break;
307 if (segs.empty())
return segs;
312 segments.reserve(segs.size());
314 if (
m_debugLevel >= 3) { std::cout <<
" refitting segments " << std::endl; }
317 for (
const Segment& inSegment : segs) {
319 if (inSegment.hasCurvatureParameters()) {
320 segments.emplace_back(inSegment);
327 bool goodSeg{
true}, hasDroppedHit{
false};
328 unsigned int dropDepth = 0;
337 bool usePrecise = resultSeg.hasT0Shift();
342 std::cout <<
" -- " << inSegment;
343 std::cout <<
" -- new DCS " << hitsOnLine.size() << std::endl;
344 for (
const DCOnTrack& cit : hitsOnLine) { std::cout <<
" " << cit << std::endl; }
348 if (matchWithLine.
hitsOnTrack() <= 2) {
continue; }
352 if (inSegment.hasT0Shift()) {
354 inSegment.t0Shift())) {
355 if (
m_debugLevel >= 4) std::cout <<
" failed fit " << std::endl;
360 if (
m_debugLevel >= 4) std::cout <<
" failed fit " << std::endl;
365 std::cout <<
" after fit " << std::endl;
366 std::cout <<
result << std::endl;
374 resultSeg.showerHits(inSegment.showerHits());
377 resultSeg.clusters(inSegment.clusters());
389 if (
m_debugLevel >= 2) { std::cout <<
" segment lossed after refit and dropping " << resultSeg << std::endl; }
396 segments.emplace_back(std::move(resultSeg));
398 std::cout <<
" new segment added " << segments.size() << std::endl;
399 std::cout << segments.back() << std::endl;
402 if (
m_debugLevel >= 2) std::cout <<
" segment lost during hit dropping " << std::endl;
412 std::cout <<
" dropDepth too large keeping segment " <<
segment << std::endl;
413 std::cout <<
" dropDepth " << dropDepth << std::endl;
416 std::cout <<
" t0 fit residual " << hit.residual() << std::endl;
418 std::cout <<
" NO t0 fit residual " << hit.residual() << std::endl;
423 std::lock_guard<std::mutex> lock(
m_mutex);
424 ++m_dropDepthAcceptCounts[dropDepth];
430 if (
m_debugLevel >= 5) std::cout <<
" dropDepth " << dropDepth <<
" " <<
segment << std::endl;
436 std::lock_guard<std::mutex> lock(
m_mutex);
437 ++m_dropDepthRejectCounts[dropDepth];
446 bool hasBadHit =
false;
450 double res = std::abs(hit.residual());
468 std::lock_guard<std::mutex> lock(
m_mutex);
469 ++m_dropDepthAcceptCounts[dropDepth];
478 if (
segment.hitsOnTrack() <= 3) {
481 std::lock_guard<std::mutex> lock(
m_mutex);
482 ++m_dropDepthRejectCounts[dropDepth];
492 segs.reserve(
segment.hitsOnTrack());
494 double bestChi2(1e9);
509 if (
m_debugLevel >= 5) std::cout <<
" failed fit (dropHits) " << std::endl;
514 segs.push_back(std::move(
result));
515 Segment& newSegment = segs.back();
531 newSegment.
dcs(hitsOnLine);
536 std::cout <<
" Hits on track content changed after match, redoing fit " << matchWithLine.
hitsOnTrack()
538 std::cout <<
" fit result " << newSegment << std::endl;
543 if (
m_debugLevel >= 5) std::cout <<
" failed fit (dropHits2) " << std::endl;
550 usePrecise =
result.hasT0Shift();
554 newSegment.
dcs(hitsOnLine);
555 if (
m_debugLevel >= 5) std::cout <<
" redid refit " << newSegment << std::endl;
563 segs.back().showerHits(
segment.showerHits());
566 segs.back().clusters(
segment.clusters());
567 segs.back().clusterLayers(
segment.clusterLayers());
580 double chi2 = segs.back().chi2();
582 if (segs.empty() || bestChi2 >
chi2) {
584 indexBest = segs.size() - 1;
587 if (
m_debugLevel >= 5) std::cout <<
" fit result " << segs.back() << std::endl;
596 hasDroppedHit =
true;
598 if (indexBest == -1) {
599 if (
m_debugLevel >= 5) std::cout <<
" not good candidate found " << std::endl;
602 std::lock_guard<std::mutex> lock(
m_mutex);
603 ++m_dropDepthRejectCounts[dropDepth];
621 if (segments.size() <= 1)
return segments;
633 std::cout <<
" sorting segments " << std::endl;
634 for (
auto &
segment : segments) { std::cout <<
segment << std::endl; }
637 selectedSegments.push_back(segments.front());
643 SegIt it = segments.begin() + 1;
644 SegIt it_end = segments.end();
645 for (;
it != it_end; ++
it) {
646 unsigned int shareHits(0);
648 for (
auto & selectedSegment : selectedSegments) {
650 shareHits = sharedHits(*
it, selectedSegment);
651 if (shareHits != 0) {
652 unsigned int nmdtHitsIt =
it->hitsOnTrack();
653 unsigned int nmdtHitsSit = selectedSegment.hitsOnTrack();
656 if (
it->hasCurvatureParameters()) {
657 if (selectedSegment.hasCurvatureParameters())
continue;
658 if (shareHits ==
it->hitsOnTrack()) {
659 if ((selectedSegment.chi2() <
it->chi2()) || (std::abs(
it->deltaAlpha()) < 0.01)) {
663 }
else if (selectedSegment.hasCurvatureParameters()) {
664 if (std::abs(
it->line().phi() - selectedSegment.line().phi()) < 0.05 &&
665 std::abs(
it->deltaAlpha() - selectedSegment.deltaAlpha()) < 0.01) {
667 if (std::abs(resWithLine.
residual(selectedSegment.line().position())) < 0.1) {
674 selectedSegment.ambigue(2);
680 if (nmdtHitsSit > nmdtHitsIt) {
686 if (!selectedSegment.clusters().empty() &&
it->clusters().empty()) {
690 if (std::abs(
it->chi2() - selectedSegment.chi2()) > selectedSegment.hitsOnTrack()) {
696 if (std::abs(
it->line().phi() - selectedSegment.line().phi()) < 0.05) {
698 if (std::abs(resWithLine.
residual(selectedSegment.line().position())) < 0.1) {
705 selectedSegment.ambigue(2);
709 selectedSegments.push_back(*
it);
711 if (shareHits != 0) selectedSegments.back().ambigue(2);
715 return selectedSegments;
729 std::cout <<
" failed direction cut " <<
line.direction() *
m_roadDir <<
" line: " <<
line.phi() <<
" road "
739 if (
m_debugLevel >= 19) { std::cout <<
" too few hits associated " << matchWithLine.
hitsOnTrack() << std::endl; }
744 std::cout <<
" too many outliers: hoo " << matchWithLine.
hitsOutOfTime() <<
" delta " << matchWithLine.
deltas()
745 <<
" hot " << matchWithLine.
hitsOnTrack() << std::endl;
752 if (
m_debugLevel >= 3) std::cout <<
" failed fit " << std::endl;
759 std::cout <<
" failed direction cut (2) " <<
result.line().direction() *
m_roadDir <<
" line: " <<
result.line().phi()
782 if (
m_debugLevel >= 3) std::cout <<
" candidate dropped due to hit ratio " << seg << std::endl;
786 if (
m_debugLevel >= 3) { std::cout <<
" new segment candidate " << seg << std::endl; }
789 segments.insert(seg);
799 unsigned int tubesMl1 {0}, tubesMl2 {0};
802 for (; doit != doit_end; ++doit) {
805 if (doit->id().ml() == 0)
813 for (; dcit != dcit_end; ++dcit) {
814 if (dcit->id().ml() == 0)
820 if (tubesMl1 + tubesMl2 !=
ct.size() +
result.first.size()) {
822 std::cout <<
" ERROR in empty tube calculation: ml1 " << tubesMl1 <<
" ml2 " << tubesMl2 <<
" tot "
823 <<
ct.size() +
result.first.size() << std::endl;
831 std::cout <<
" ---- mismatch!!! " << std::endl;
834 for (; eit != eit_end; ++eit) { std::cout <<
" match result " << *eit << std::endl; }
835 std::cout << seg << std::endl;
854 if (seeds_ml1.size() * seeds_ml2.size() > 2500)
return;
857 for (
const auto &
it1 : seeds_ml1) {
858 for (DCVec::const_reverse_iterator it2 = seeds_ml2.rbegin(); it2 != seeds_ml2.rend(); ++it2) {
872 if (seeds.size() > 50)
return;
874 for (
DCCit it = seeds.begin();
it != seeds.end(); ++
it) {
875 for (DCVec::const_reverse_iterator rit = seeds.rbegin(); rit != seeds.rend(); ++rit) {
880 if (std::abs(
it->position().y() - rit->position().y()) < 1.)
break;
889 if (segs.empty())
return dcs;
895 DCCit dit = dcs.begin();
896 DCCit dit_end = dcs.end();
898 for (; dit != dit_end; ++dit) {
900 for (
const auto & seg : segs) {
907 if (!
found) { newdcs.push_back(*dit); }
915 SegIt sit = segs.begin();
916 SegIt sit_end = segs.end();
926 bool hasClustersBefore =
false;
927 bool hasClustersAfter =
false;
931 for (; cit != cit_end; ++cit) {
933 if (cit->id().measuresPhi() == 1) {
935 std::cout <<
" phi hit, not associated: id " << cit->id().id() <<
" pos " << cit->position() << std::endl;
941 double error = std::sqrt(cit->err() * cit->err() + resSeg.
trackError2(*cit));
945 std::cout <<
" handling cluster " << cit->id() <<
" res " <<
res <<
" pull " <<
pull <<
" hit error " << cit->err()
946 <<
" track error " << sqrt(resSeg.
trackError2(*cit)) <<
" pos " << cit->position();
951 if (std::abs(
pull) < pullCut) {
952 assCls.push_back(*cit);
953 if (cit->position().y() < 0.) hasClustersBefore =
true;
954 if (cit->position().y() > 0.) hasClustersAfter =
true;
955 if (
m_debugLevel >= 4) std::cout <<
" associated" << std::endl;
957 if (
m_debugLevel >= 4) std::cout <<
" dropped" << std::endl;
961 if (assCls.empty())
return;
964 unsigned int ncl = 0;
965 if (hasClustersBefore) ++ncl;
966 if (hasClustersAfter) ++ncl;
976 }
else if (seg.
hitsMl2() == 0) {