42 std::cout <<
" drop summary " << std::endl;
43 for (
unsigned int i = 0; i <
m_dropDepthMax + 1; ++i) { std::cout <<
" Accepted " << m_dropDepthAcceptCounts[i] << std::endl; }
44 for (
unsigned int i = 0; i <
m_dropDepthMax; ++i) { std::cout <<
" Rejected " << m_dropDepthRejectCounts[i] << std::endl; }
51 m_dropDepthAcceptCounts.clear();
52 m_dropDepthAcceptCounts.resize(
max + 1, 0);
53 m_dropDepthRejectCounts.clear();
54 m_dropDepthRejectCounts.resize(
max + 1, 0);
115 if (
m_debugLevel >= 1) std::cout <<
" bad phi for road: road " <<
m_phiRoad <<
" dir phi " << roadLine.
phi() << std::endl;
120 std::cout <<
" bad phi for chamber: chamber " <<
m_phiChamber <<
" dir phi " << chamberLine.
phi() << std::endl;
130 std::cout <<
" SegmentFinder::setting: " << std::endl
141 std::cout <<
" Options: ";
142 if (
m_fullScan) std::cout <<
" -- full scan ";
145 if (
m_doDrop) std::cout <<
" -- drop hits ";
149 std::cout << std::endl;
157 std::cout <<
"In handleHits: dcs " << dcsIn.size() <<
" clusters " << clsIn.size() << std::endl;
176 seedsMl1 = dcsPerMl.first;
177 seedsMl2 = dcsPerMl.second;
184 std::cout <<
" two layer scan " << std::endl;
185 for (
const auto & it : segments.data()) { std::cout <<
" " << it << std::endl; }
190 segments.set(preSelSegs);
193 std::cout <<
" after cleaning " << std::endl;
194 for (
const auto & it : segments.data()) { std::cout <<
" " << it << std::endl; }
197 unsigned int usedHits(0);
198 for (
const auto & it : segments.data()) { usedHits += it.hitsOnTrack(); }
205 fullScan(seedsMl1, dcsPerMl.first, clsIn, segments);
208 std::cout <<
" segments after scan multilayer 1 " << std::endl;
209 for (
const auto & it : segments.data()) { std::cout <<
" " << it << std::endl; }
212 fullScan(seedsMl2, dcsPerMl.second, clsIn, segments);
215 std::cout <<
" segments after scan multilayer 2 " << std::endl;
216 for (
const auto & it : segments.data()) { std::cout <<
" " << it << std::endl; }
223 fullScan(seeds, dcs, clsIn, segments);
239 std::cout <<
"CurvedSegmentFinder was passed a NULL pointer to the ChamberGeometry" << std::endl;
250 std::cout <<
" final segments " << std::endl;
251 for (
auto & selectedSegment : selectedSegments) { std::cout << selectedSegment << std::endl; }
254 return selectedSegments;
259 ml1.reserve(dcs.size());
260 ml2.reserve(dcs.size());
262 if (circ.id().ml() == 0)
263 ml1.emplace_back(circ);
265 ml2.emplace_back(circ);
267 return std::make_pair(std::move(ml1), std::move(ml2));
272 if (dcs.size() <= 2)
return dcs;
278 DCCit it_start_serie;
279 DCCit it = dcs.begin();
280 DCCit it_end = dcs.end() - 1;
282 while (it <= it_end) {
287 while (it != it_end && isNeighbour(*it, *(it + 1))) { ++it; }
290 if (std::distance(it_start_serie, it + 1) < maxSerie) {
292 for (; it_start_serie != it + 1; ++it_start_serie) {
294 if (it_start_serie->driftState() ==
DriftCircle::InTime) { seeds.push_back(*it_start_serie); }
300 if (it == dcs.end())
break;
309 if (segs.empty())
return segs;
314 segments.reserve(segs.size());
316 if (
m_debugLevel >= 3) { std::cout <<
" refitting segments " << std::endl; }
319 for (
const Segment& inSegment : segs) {
321 if (inSegment.hasCurvatureParameters()) {
322 segments.emplace_back(inSegment);
329 bool goodSeg{
true}, hasDroppedHit{
false};
330 unsigned int dropDepth = 0;
344 std::cout <<
" -- " << inSegment;
345 std::cout <<
" -- new DCS " << hitsOnLine.size() << std::endl;
346 for (
const DCOnTrack& cit : hitsOnLine) { std::cout <<
" " << cit << std::endl; }
350 if (matchWithLine.
hitsOnTrack() <= 2) {
continue; }
354 if (inSegment.hasT0Shift()) {
355 if (!
m_fitter->fit(result, inSegment.line(), hitsOnLine,
m_hitSelector.selectHitsOnTrack(hitsOnLine),
356 inSegment.t0Shift())) {
357 if (
m_debugLevel >= 4) std::cout <<
" failed fit " << std::endl;
361 if (!
m_fitter->fit(result, inSegment.line(), hitsOnLine,
m_hitSelector.selectHitsOnTrack(hitsOnLine))) {
362 if (
m_debugLevel >= 4) std::cout <<
" failed fit " << std::endl;
367 std::cout <<
" after fit " << std::endl;
368 std::cout << result << std::endl;
379 resultSeg.
clusters(inSegment.clusters());
391 if (
m_debugLevel >= 2) { std::cout <<
" segment lossed after refit and dropping " << resultSeg << std::endl; }
398 segments.emplace_back(std::move(resultSeg));
400 std::cout <<
" new segment added " << segments.size() << std::endl;
401 std::cout << segments.back() << std::endl;
404 if (
m_debugLevel >= 2) std::cout <<
" segment lost during hit dropping " << std::endl;
414 std::cout <<
" dropDepth too large keeping segment " << segment << std::endl;
415 std::cout <<
" dropDepth " << dropDepth << std::endl;
418 std::cout <<
" t0 fit residual " <<
hit.residual() << std::endl;
420 std::cout <<
" NO t0 fit residual " <<
hit.residual() << std::endl;
426 ++m_dropDepthAcceptCounts[dropDepth];
432 if (
m_debugLevel >= 5) std::cout <<
" dropDepth " << dropDepth <<
" " << segment << std::endl;
435 if (segment.
ndof() <= 0) {
439 ++m_dropDepthRejectCounts[dropDepth];
448 bool hasBadHit =
false;
452 double res = std::abs(
hit.residual());
467 if (
m_debugLevel >= 5) std::cout <<
" keeping candidate " << segment << std::endl;
471 ++m_dropDepthAcceptCounts[dropDepth];
477 if (
m_debugLevel >= 5) std::cout <<
" dropHits " << segment << std::endl;
484 ++m_dropDepthRejectCounts[dropDepth];
496 double bestChi2(1e9);
502 for (
unsigned int i = 0; i <
selection.size(); ++i) {
511 if (
m_debugLevel >= 5) std::cout <<
" failed fit (dropHits) " << std::endl;
513 if (
m_debugLevel >= 5) std::cout <<
" dropping hit " << i <<
" " << segment.
dcs()[i] << std::endl;
516 segs.push_back(std::move(result));
517 Segment& newSegment = segs.back();
533 newSegment.
dcs(hitsOnLine);
538 std::cout <<
" Hits on track content changed after match, redoing fit " << matchWithLine.
hitsOnTrack()
540 std::cout <<
" fit result " << newSegment << std::endl;
545 if (
m_debugLevel >= 5) std::cout <<
" failed fit (dropHits2) " << std::endl;
552 usePrecise = result.hasT0Shift();
556 newSegment.
dcs(hitsOnLine);
557 if (
m_debugLevel >= 5) std::cout <<
" redid refit " << newSegment << std::endl;
568 segs.back().clusters(segment.
clusters());
582 double chi2 = segs.back().chi2();
584 if (segs.empty() || bestChi2 >
chi2) {
586 indexBest = segs.size() - 1;
589 if (
m_debugLevel >= 5) std::cout <<
" fit result " << segs.back() << std::endl;
598 hasDroppedHit =
true;
600 if (indexBest == -1) {
601 if (
m_debugLevel >= 5) std::cout <<
" not good candidate found " << std::endl;
605 ++m_dropDepthRejectCounts[dropDepth];
610 segment = segs[indexBest];
611 if (
m_debugLevel >= 5) std::cout <<
" best candidate " << segment << std::endl;
613 bool drop =
dropHits(segment, hasDroppedHit, dropDepth);
623 if (segments.size() <= 1)
return segments;
635 std::cout <<
" sorting segments " << std::endl;
636 for (
auto & segment : segments) { std::cout << segment << std::endl; }
639 selectedSegments.push_back(segments.front());
645 SegIt it = segments.begin() + 1;
646 SegIt it_end = segments.end();
647 for (; it != it_end; ++it) {
648 unsigned int shareHits(0);
650 for (
auto & selectedSegment : selectedSegments) {
652 shareHits = sharedHits(*it, selectedSegment);
653 if (shareHits != 0) {
654 unsigned int nmdtHitsIt = it->hitsOnTrack();
655 unsigned int nmdtHitsSit = selectedSegment.hitsOnTrack();
658 if (it->hasCurvatureParameters()) {
659 if (selectedSegment.hasCurvatureParameters())
continue;
660 if (shareHits == it->hitsOnTrack()) {
661 if ((selectedSegment.chi2() < it->chi2()) || (std::abs(it->deltaAlpha()) < 0.01)) {
665 }
else if (selectedSegment.hasCurvatureParameters()) {
666 if (std::abs(it->line().phi() - selectedSegment.line().phi()) < 0.05 &&
667 std::abs(it->deltaAlpha() - selectedSegment.deltaAlpha()) < 0.01) {
669 if (std::abs(resWithLine.
residual(selectedSegment.line().position())) < 0.1) {
676 selectedSegment.ambigue(2);
682 if (nmdtHitsSit > nmdtHitsIt) {
688 if (!selectedSegment.clusters().empty() && it->clusters().empty()) {
692 if (std::abs(it->chi2() - selectedSegment.chi2()) > selectedSegment.hitsOnTrack()) {
698 if (std::abs(it->line().phi() - selectedSegment.line().phi()) < 0.05) {
700 if (std::abs(resWithLine.
residual(selectedSegment.line().position())) < 0.1) {
707 selectedSegment.ambigue(2);
711 selectedSegments.push_back(*it);
713 if (shareHits != 0) selectedSegments.back().ambigue(2);
717 return selectedSegments;
727 for (
const auto & line : lines) {
731 std::cout <<
" failed direction cut " << line.direction() *
m_roadDir <<
" line: " << line.phi() <<
" road "
741 if (
m_debugLevel >= 19) { std::cout <<
" too few hits associated " << matchWithLine.
hitsOnTrack() << std::endl; }
746 std::cout <<
" too many outliers: hoo " << matchWithLine.
hitsOutOfTime() <<
" delta " << matchWithLine.
deltas()
747 <<
" hot " << matchWithLine.
hitsOnTrack() << std::endl;
754 if (
m_debugLevel >= 3) std::cout <<
" failed fit " << std::endl;
761 std::cout <<
" failed direction cut (2) " << result.line().direction() *
m_roadDir <<
" line: " << result.line().phi()
784 if (
m_debugLevel >= 3) std::cout <<
" candidate dropped due to hit ratio " << seg << std::endl;
788 if (
m_debugLevel >= 3) { std::cout <<
" new segment candidate " << seg << std::endl; }
791 segments.insert(seg);
801 unsigned int tubesMl1 {0}, tubesMl2 {0};
804 for (; doit != doit_end; ++doit) {
807 if (doit->id().ml() == 0)
813 DCCit dcit = ct.begin();
814 DCCit dcit_end = ct.end();
815 for (; dcit != dcit_end; ++dcit) {
816 if (dcit->id().ml() == 0)
822 if (tubesMl1 + tubesMl2 != ct.size() + result.first.size()) {
824 std::cout <<
" ERROR in empty tube calculation: ml1 " << tubesMl1 <<
" ml2 " << tubesMl2 <<
" tot "
825 << ct.size() + result.first.size() << std::endl;
833 std::cout <<
" ---- mismatch!!! " << std::endl;
834 DCCit eit = result.second.begin();
835 DCCit eit_end = result.second.end();
836 for (; eit != eit_end; ++eit) { std::cout <<
" match result " << *eit << std::endl; }
837 std::cout << seg << std::endl;
856 if (seeds_ml1.size() * seeds_ml2.size() > 2500)
return;
859 for (
const auto & it1 : seeds_ml1) {
860 for (DCVec::const_reverse_iterator it2 = seeds_ml2.rbegin(); it2 != seeds_ml2.rend(); ++it2) {
874 if (seeds.size() > 50)
return;
876 for (
DCCit it = seeds.begin(); it != seeds.end(); ++it) {
877 for (DCVec::const_reverse_iterator rit = seeds.rbegin(); rit != seeds.rend(); ++rit) {
879 if (std::distance(seeds.begin(), it) >= std::distance(rit, seeds.rend() - 1))
break;
882 if (std::abs(it->position().y() - rit->position().y()) < 1.)
break;
891 if (segs.empty())
return dcs;
897 DCCit dit = dcs.begin();
898 DCCit dit_end = dcs.end();
900 for (; dit != dit_end; ++dit) {
902 for (
const auto & seg : segs) {
904 if (pos != seg.dcs().end() && pos->state() !=
DCOnTrack::CloseDC && sameTube(*pos, *dit)) {
909 if (!found) { newdcs.push_back(*dit); }
917 SegIt sit = segs.begin();
918 SegIt sit_end = segs.end();
928 bool hasClustersBefore =
false;
929 bool hasClustersAfter =
false;
931 CLCit cit = cls.begin();
932 CLCit cit_end = cls.end();
933 for (; cit != cit_end; ++cit) {
935 if (cit->id().measuresPhi() == 1) {
937 std::cout <<
" phi hit, not associated: id " << cit->id().id() <<
" pos " << cit->position() << std::endl;
943 double error = std::sqrt(cit->err() * cit->err() + resSeg.
trackError2(*cit));
947 std::cout <<
" handling cluster " << cit->id() <<
" res " <<
res <<
" pull " << pull <<
" hit error " << cit->err()
948 <<
" track error " << sqrt(resSeg.
trackError2(*cit)) <<
" pos " << cit->position();
953 if (std::abs(pull) < pullCut) {
954 assCls.push_back(*cit);
955 if (cit->position().y() < 0.) hasClustersBefore =
true;
956 if (cit->position().y() > 0.) hasClustersAfter =
true;
957 if (
m_debugLevel >= 4) std::cout <<
" associated" << std::endl;
959 if (
m_debugLevel >= 4) std::cout <<
" dropped" << std::endl;
963 if (assCls.empty())
return;
966 unsigned int ncl = 0;
967 if (hasClustersBefore) ++ncl;
968 if (hasClustersAfter) ++ncl;
978 }
else if (seg.
hitsMl2() == 0) {
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
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