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;
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;
277 DCCit it = dcs.begin();
278 DCCit it_end = dcs.end() - 1;
280 while (it <= it_end) {
285 while (it != it_end && isNeighbour(*it, *(it + 1))) { ++it; }
288 if (std::distance(it_start_serie, it + 1) < maxSerie) {
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;
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;
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;
433 if (segment.
ndof() <= 0) {
436 std::lock_guard<std::mutex> lock(
m_mutex);
437 ++m_dropDepthRejectCounts[dropDepth];
446 bool hasBadHit =
false;
450 double res = std::abs(hit.residual());
465 if (
m_debugLevel >= 5) std::cout <<
" keeping candidate " << segment << std::endl;
468 std::lock_guard<std::mutex> lock(
m_mutex);
469 ++m_dropDepthAcceptCounts[dropDepth];
475 if (
m_debugLevel >= 5) std::cout <<
" dropHits " << segment << std::endl;
481 std::lock_guard<std::mutex> lock(
m_mutex);
482 ++m_dropDepthRejectCounts[dropDepth];
494 double bestChi2(1e9);
500 for (
unsigned int i = 0; i <
selection.size(); ++i) {
509 if (
m_debugLevel >= 5) std::cout <<
" failed fit (dropHits) " << std::endl;
511 if (
m_debugLevel >= 5) std::cout <<
" dropping hit " << i <<
" " << segment.
dcs()[i] << 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;
566 segs.back().clusters(segment.
clusters());
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];
608 segment = segs[indexBest];
609 if (
m_debugLevel >= 5) std::cout <<
" best candidate " << segment << std::endl;
611 bool drop =
dropHits(segment, hasDroppedHit, 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;
725 for (
const auto & line : lines) {
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)
811 DCCit dcit = ct.begin();
812 DCCit dcit_end = ct.end();
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) {
877 if (std::distance(seeds.begin(), it) >= std::distance(rit, seeds.rend() - 1))
break;
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) {
902 if (pos != seg.dcs().end() && pos->state() !=
DCOnTrack::CloseDC && sameTube(*pos, *dit)) {
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;
929 CLCit cit = cls.begin();
930 CLCit cit_end = cls.end();
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) {
std::pair< std::vector< unsigned int >, bool > res
void curvedSegments(const ChamberGeometry &mdtGeo, SegVec &Segs) const
class representing a drift circle meaurement on segment
@ CloseDC
too large drift time
This class represents a drift time measurement.
@ InTime
drift time too small to be compatible with drift spectrum
Implementation of 2 dimensional vector class.
unsigned int deltas() const
unsigned int showerHits() const
unsigned int hitsMl1() const
unsigned int hitsMl2() const
unsigned int hitsOnTrack() const
const DCOnTrackVec & match(const DCVec &dcs)
unsigned int matchDifference() const
returns the number of DCOnTrack that have a different status after the match, returns 0 if used with ...
unsigned int closeHits() const
void set(const Line &l, double deltaCut, MatchStrategy strategy, double tubeRadius)
unsigned int hitsOutOfTime() const
double residual(const LocVec2D &pos) const
class to calculate residual of a hit with a segment and calculate the local track errors
double trackError2(const DriftCircle &dc) const
calculate the track error at the position of a drift circle
const DataVec & data() const
void setDeltaCutT0(double deltaCut)
void fullScan(const DCVec &seeds, const DCVec &dcs, const CLVec &cls, ResolvedCollection< Segment, IsSubsetSegment< SortDcsByY > > &segments) const
void printSettings() const
print settings
void setMaxDropDepth(int max)
std::shared_ptr< const DCSLFitter > m_fitter
void setRecoverMDT(bool doRecover)
void associateClusters(SegVec &segs, const CLVec &cls) const
void setRPCPullCut(double cut)
bool dropHits(Segment &segment, bool &hasDroppedHit, unsigned int &dropDepth) const
bool m_removeSingleOutliers
SegVec findSegments(const DCVec &dcs) const
static DCVec selectSeeds(const DCVec &dcs, int maxSerie)
void setDropHits(bool doDrop)
DCSLHitSelector m_hitSelector
void setRemoveSingleOutliers(bool removeSingleOutliers)
void handleSeedPair(const DriftCircle &seed1, const DriftCircle &seeds2, const DCVec &dcs, const CLVec &cls, MatchDCWithLine &matchWithLine, ResolvedCollection< Segment, IsSubsetSegment< SortDcsByY > > &segments) const
bool m_singleMultiLayerScan
void setPhiRoad(double phiRoad, double phiChamber, double sinPhiCut=0.2, bool useRoadPhi=true, bool useChamberPhi=true)
void setDeltaCut(double cut)
unsigned int m_dropDepthMax
void setRatioEmptyTubesCut(double ratioEmptyTubesCut)
void setUseChamberPhi(bool useChamberPhi)
void setTGCPullCut(double cut)
double m_ratioEmptyTubesCut
double tubeRadius() const
static std::pair< DCVec, DCVec > splitInMulitlayers(const DCVec &dcs)
void setResidualCutT0(double resCut)
bool goodHitRatio(Segment &seg) const
void handleHits(const DCVec &dcs, const CLVec &clusters, ResolvedCollection< Segment, IsSubsetSegment< SortDcsByY > > &segments) const
static void updateMatch(Segment &seg, MatchDCWithLine &matchWithLine)
void setSeedCleaning(bool doCleanup)
void updateDirections()
update the cached values for the phi road and chamber road
bool directionCheck(const LocVec2D &LocVec2D) const
void setUseSegmentQuality(bool useQ)
void twoMultiLayerScan(const DCVec &seeds_ml1, const DCVec &seeds_ml2, const DCVec &dcs, const CLVec &cls, ResolvedCollection< Segment, IsSubsetSegment< SortDcsByY > > &segments) const
void setSortSegmentsUsingAllHits(bool doAllHitsSort)
MatchCrossedTubes m_matchCrossed
const ChamberGeometry * m_mdtGeometry
SegVec cleanSegments(const SegVec &segments) const
SegVec refitSegments(const SegVec &segs) const
static DCVec removeDCOnSegments(const DCVec &dcs, const SegVec &segs)
void setChi2DropCut(double chi2)
bool m_doCurvedSegmentFinder
void setCurvedSegmentFinder(bool doCurvedSegmentFinder)
void crossedTubes(Segment &seg) const
void setSingleMultiLayerScan(bool doScan)
const DCVec & emptyTubes() const
void hitsOnTrack(unsigned int hitsOnTrack)
void showerHits(unsigned int showerHits)
const Line & line() const
void crossedTubes(unsigned int crossedTubesMl1, unsigned int crossedTubesMl2)
void hitsOutOfTime(unsigned int hitsOutOfTime)
void hitsPerMl(unsigned int hml1, unsigned int hml2)
const CLVec & clusters() const
void deltas(unsigned int dts)
unsigned int crossedTubesMl2() const
const DCOnTrackVec & dcs() const
unsigned int crossedTubesMl1() const
void closeHits(unsigned int closeHits)
unsigned int ndof() const
unsigned int hitsMl1() const
unsigned int hitsMl2() const
void clusterLayers(unsigned int ncl)
std::vector< Line > LineVec
static LineVec tangentLines(const DriftCircle &dc1, const DriftCircle &dc2)
double chi2(TH1 *h0, TH1 *h1)
const std::string selection
Function object to check whether two Segments are sub/super sets or different.
DCOnTrackVec::const_iterator DCOnTrackCit
std::vector< Cluster > CLVec
std::pair< DCOnTrackVec, DCVec > MatchResult
counts the number of hits shared by the two segments
std::vector< bool > HitSelection
CLVec::const_iterator CLCit
DCVec::const_iterator DCCit
std::vector< Segment > SegVec
std::vector< DriftCircle > DCVec
std::vector< DCOnTrack > DCOnTrackVec
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
counts the number of hits shared by the two segments