diff --git a/CRVReco/inc/TrkCrvGeom.hh b/CRVReco/inc/TrkCrvGeom.hh index 5dbd24ba95..34e19ec0b0 100644 --- a/CRVReco/inc/TrkCrvGeom.hh +++ b/CRVReco/inc/TrkCrvGeom.hh @@ -7,8 +7,11 @@ #ifndef CRVReco_TrkCrvGeom_hh #define CRVReco_TrkCrvGeom_hh #include "Offline/DataProducts/inc/SurfaceId.hh" +#include "Offline/RecoDataProducts/inc/KalIntersection.hh" #include "KinKal/General/Vectors.hh" +#include "KinKal/Geometry/Plane.hh" #include "KinKal/Geometry/Rectangle.hh" +#include #include #include #include @@ -30,5 +33,28 @@ namespace mu2e { std::vector trkCrvSectors(); // the shield with the largest PE sum among the cluster's pulses, -1 if none; multiSector set if pulses span shields int trkCrvDominantShield(CrvCoincidenceCluster const& cluster, CosmicRayShield const& crs, bool* multiSector = nullptr); + + constexpr double trkCrvMinCosToNormal = 1e-3; // |direction . plane normal| below which a track is parallel to the plane + + // Covariance of the track position on the plane through point with the sector axes (u, v), for the straight line from a KalSeed + // intersection reaching that plane at time (the intersection state's covariance carried over the straight step; time = ki.time() + // gives the covariance of the state itself, measured in the plane). 0 for a line parallel to the plane. + inline KinKal::PMAT trkCrvPlaneCovariance(KalIntersection const& ki, TrkCrvSector const& g, KinKal::VEC3 const& point, double time) { + if(std::fabs(ki.momentum3().Unit().Dot(g.w)) < trkCrvMinCosToNormal) return KinKal::PMAT(); + return ki.kinematicLine().planeCovariance(time, KinKal::Plane(g.w, g.u, point), trkCrvMinCosToNormal); + } + + // Covariance of the track position at a KalSeed intersection with the sector, in the sector axes (u, v): the KinKal projected + // covariance of the intersection (filled by the extrapolation, rotated from the intersection's local plane axes) if present, + // otherwise that of the intersection state measured in the plane. + inline KinKal::PMAT trkCrvXingCovariance(KalIntersection const& ki, TrkCrvSector const& g) { + auto const& inter = ki.intersection(); + if(!inter.hascov_) return trkCrvPlaneCovariance(ki, g, ki.position3(), ki.time()); + ROOT::Math::SMatrix rot; + KinKal::VEC3 const* axes[2] = {&g.u, &g.v}; + KinKal::VEC3 const* idirs[2] = {&inter.udir_, &inter.vdir_}; + for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j) rot(i, j) = axes[i]->Dot(*idirs[j]); + return ROOT::Math::Similarity(rot, inter.pcov_); + } } #endif diff --git a/CRVReco/inc/TrkCrvMatchTool.hh b/CRVReco/inc/TrkCrvMatchTool.hh index 57a73d9347..0df9574241 100644 --- a/CRVReco/inc/TrkCrvMatchTool.hh +++ b/CRVReco/inc/TrkCrvMatchTool.hh @@ -39,7 +39,7 @@ namespace mu2e { fhicl::Sequence dtXingWindow{Name("DtXingWindow"), Comment("storage window on t_cluster - t_track at the cluster plane [ns]")}; fhicl::Atom maxDv{Name("MaxDv"), Comment("storage window on |across-bar residual| [mm]")}; fhicl::Atom maxDu{Name("MaxDu"), Comment("storage window on |along-bar residual| for two-ended clusters [mm]")}; - fhicl::Atom doGeometric{Name("DoGeometric"), Comment("form geometric candidates from CRV KalIntersections, or, for a line fit with none, from its projections onto the sectors' extended planes")}; + fhicl::Atom doGeometric{Name("DoGeometric"), Comment("form geometric candidates from CRV KalIntersections, including the out-of-bounds near misses the extrapolation records")}; fhicl::Atom requireSameSector{Name("RequireSameSector"), Comment("project only from a crossing of the cluster's own sector (A/B tests)"), false}; fhicl::Sequence sigmaV{Name("SigmaV"), Comment("CRV across-bar resolution [mm], indexed by the cluster's sector type (1 first): one entry per sector type of the loaded CRV geometry, or one entry for all; sector type numbering depends on the geometry")}; fhicl::Sequence sigmaU{Name("SigmaU"), Comment("CRV along-bar resolution of two-ended clusters [mm], by sector type")}; @@ -80,10 +80,8 @@ namespace mu2e { }; double resolution(std::vector const& tab, int sectorType) const; void checkResolutions() const; // throws if a Sigma* list does not describe the loaded CRV geometry's sector types - TrkCrvPlaneCov errorModel(ROOT::Math::SMatrix> const& cov) const; // k^2 C + a^2 I + TrkCrvPlaneCov errorModel(KinKal::PMAT const& cov) const; // k^2 C + a^2 I void probe(TrkCrvXing& x, double speed) const; - // a straight-line fit's crossing of a sector's extended plane, if out of bounds; false if in bounds or parallel - bool projectXing(KalSeed const& ks, int shield, double sigT, TrkCrvXing& x) const; static bool sameCluster(art::Ptr const& a, art::Ptr const& b); std::vector refSurfaces_; diff --git a/CRVReco/inc/TrkCrvPlaneError.hh b/CRVReco/inc/TrkCrvPlaneError.hh deleted file mode 100644 index 9866600cf6..0000000000 --- a/CRVReco/inc/TrkCrvPlaneError.hh +++ /dev/null @@ -1,45 +0,0 @@ -// -// Temporary stand-in for a KinKal projection of a track state's spatial covariance onto a plane; replace with the -// KinKal implementation when it exists (both modules call only trkCrvPlaneCovariance). -// -#ifndef CRVReco_TrkCrvPlaneError_hh -#define CRVReco_TrkCrvPlaneError_hh -#include "KinKal/General/Vectors.hh" -#include "Math/SMatrix.h" -#include - -namespace mu2e { - using TrkCrvCov2 = ROOT::Math::SMatrix>; - constexpr double trkCrvMinCosToNormal = 1e-3; // |direction . plane normal| below which a track is parallel to the plane - - // Covariance of the track position on the plane with normal w, in the in-plane axes (a, b), after a straight step of - // signed path length s from a state (position, momentum p) with 6x6 covariance C (position first). With d = p/|p| - // and P = I - d w^T/(d.w) (move along d onto the plane), the gradient of e.(position on the plane) is P^T e for the - // position block and (s/|p|)(I - d d^T) P^T e for the momentum block. s = 0 gives the covariance of the state itself, - // measured in the plane. Returns a zero matrix for a track parallel to the plane. - template TrkCrvCov2 trkCrvPlaneCovariance(COV const& C, KinKal::VEC3 const& p, KinKal::VEC3 const& a, - KinKal::VEC3 const& b, KinKal::VEC3 const& w, double s) { - TrkCrvCov2 out; - double pm = std::sqrt(p.Mag2()); - if(pm <= 0) return out; - KinKal::VEC3 d = p / pm; - double dw = d.Dot(w); - if(std::fabs(dw) < trkCrvMinCosToNormal) return out; - double g[2][6]; - KinKal::VEC3 const* axes[2] = {&a, &b}; - for(int k = 0; k < 2; ++k) { - KinKal::VEC3 gp = *axes[k] - w * (d.Dot(*axes[k]) / dw); - KinKal::VEC3 gm = (s / pm) * (gp - d * d.Dot(gp)); - double gk[6] = {gp.X(), gp.Y(), gp.Z(), gm.X(), gm.Y(), gm.Z()}; - for(int i = 0; i < 6; ++i) g[k][i] = gk[i]; - } - for(int k = 0; k < 2; ++k) - for(int l = k; l < 2; ++l) { - double v = 0; - for(int i = 0; i < 6; ++i) for(int j = 0; j < 6; ++j) v += g[k][i] * C(i, j) * g[l][j]; - out(k, l) = v; - } - return out; - } -} -#endif diff --git a/CRVReco/src/TrkCrvMatchTool.cc b/CRVReco/src/TrkCrvMatchTool.cc index 754b7fd006..5a0316a062 100644 --- a/CRVReco/src/TrkCrvMatchTool.cc +++ b/CRVReco/src/TrkCrvMatchTool.cc @@ -1,5 +1,4 @@ #include "Offline/CRVReco/inc/TrkCrvMatchTool.hh" -#include "Offline/CRVReco/inc/TrkCrvPlaneError.hh" #include "Offline/CosmicRayShieldGeom/inc/CosmicRayShield.hh" #include "Offline/GeometryService/inc/DetectorSystem.hh" #include "Offline/GeometryService/inc/GeomHandle.hh" @@ -29,7 +28,7 @@ namespace mu2e { for(auto const& s : conf.refSurfaces()) refSurfaces_.emplace_back(s); } - TrkCrvPlaneCov TrkCrvMatchTool::errorModel(TrkCrvCov2 const& cov) const { + TrkCrvPlaneCov TrkCrvMatchTool::errorModel(KinKal::PMAT const& cov) const { TrkCrvPlaneCov out; for(int i = 0; i < 2; ++i) for(int j = i; j < 2; ++j) out(i, j) = trkErrScale_ * trkErrScale_ * cov(i, j) + (i == j ? posErrQuad_ * posErrQuad_ : 0.0); @@ -182,44 +181,6 @@ namespace mu2e { } } - bool TrkCrvMatchTool::projectXing(KalSeed const& ks, int shield, double sigT, TrkCrvXing& x) const { - auto const& g = sectors_[shield]; - // the straight line from the KalIntersection nearest in path to the sector's extended mid-plane - int kbest = -1; - double sbest = 0; - for(size_t k = 0; k < ks.intersections().size(); ++k) { - auto const& ki = ks.intersections()[k]; - double dn = ki.momentum3().Unit().Dot(g.w); - if(std::fabs(dn) < trkCrvMinCosToNormal) continue; - double s = (g.center - ki.position3()).Dot(g.w) / dn; - if(kbest < 0 || std::fabs(s) < std::fabs(sbest)) { kbest = static_cast(k); sbest = s; } - } - if(kbest < 0) return false; - auto const& ki = ks.intersections()[kbest]; - auto d = ki.momentum3().Unit(); - KinKal::VEC3 p = ki.position3() + sbest * d; - KinKal::VEC3 loc = p - g.center; - double dEdgeU = g.uHalf - std::fabs(loc.Dot(g.u)), dEdgeV = g.vHalf - std::fabs(loc.Dot(g.v)); - if(dEdgeU >= 0 && dEdgeV >= 0) return false; // in-bounds crossings belong to the extrapolation's intersections - double speed = std::sqrt(ki.velocity().Mag2()); - x.sid_ = g.sid; - x.inter_ = static_cast(kbest); - x.sector_ = static_cast(shield); - x.pos_ = XYZVectorF(p.X(), p.Y(), p.Z()); - x.dir_ = XYZVectorF(d.X(), d.Y(), d.Z()); - x.time_ = ki.time() + (speed > 0 ? sbest / speed : 0.0); - x.inBounds_ = false; - x.cov_ = errorModel(trkCrvPlaneCovariance(ki.pstate_.stateCovariance(), ki.momentum3(), g.u, g.v, g.w, sbest)); - x.sigT_ = sigT; - x.mom_ = ki.mom(); - x.momErr_ = ki.momerr(); - x.dEdgeU_ = dEdgeU; - x.dEdgeV_ = dEdgeV; - x.edgeSig_ = (x.sigU() > 0 && x.sigV() > 0) ? std::min(x.dEdgeU_ / x.sigU(), x.dEdgeV_ / x.sigV()) : 0.f; - if(layerProbe_) probe(x, speed); - return true; - } - TrkCrvMatch TrkCrvMatchTool::match(art::Ptr const& seed, std::vector> const& usedInFit) const { auto const& ks = *seed; TrkCrvMatch m; @@ -277,8 +238,9 @@ namespace mu2e { x.pos_ = XYZVectorF(p.X(), p.Y(), p.Z()); x.dir_ = XYZVectorF(d.X(), d.Y(), d.Z()); x.time_ = ki.time(); - x.inBounds_ = ki.inBounds(); - x.cov_ = errorModel(trkCrvPlaneCovariance(ki.pstate_.stateCovariance(), ki.momentum3(), g.u, g.v, g.w, 0.0)); + x.inBounds_ = ki.inBounds(); // false for a near miss: an out-of-bounds crossing the extrapolation kept for its bounds fraction + x.inbFrac_ = ki.intersection().hascov_ ? ki.intersection().inbfrac_ : (x.inBounds_ ? 1.0f : 0.0f); + x.cov_ = errorModel(trkCrvXingCovariance(ki, g)); x.sigT_ = sigT; x.mom_ = ki.mom(); x.momErr_ = ki.momerr(); @@ -290,22 +252,6 @@ namespace mu2e { m.xings_.push_back(x); } } - // a straight-line fit with no CRV crossing passes outside every sector: project it onto the extended plane of each - // cluster's sector, so that edge clusters get geometric candidates - bool projectLine = doGeometric_ && m.xings_.empty() && ks.kinematicLineFit(); - std::map projected; // cluster shield -> its projected crossing in m.xings_ - if(projectLine) { - std::set shields; - for(auto const& ci : cinfo_) - if(ci.shield >= 0 && static_cast(ci.shield) < sectors_.size() && sectors_[ci.shield].valid) shields.insert(ci.shield); - for(int s : shields) { - TrkCrvXing x; - if(!projectXing(ks, s, sigT, x)) continue; - projected[s] = static_cast(m.xings_.size()); - m.xings_.push_back(x); - } - } - // candidates for(size_t ic = 0; ic < clusters_.size(); ++ic) { auto const& ci = cinfo_[ic]; @@ -321,10 +267,7 @@ namespace mu2e { // geometric evidence: project from the CRV crossing nearest in path to the cluster's plane (straight line outside the field) int bestx = -1; double bds = 1e30; bool hasPlane = ci.shield >= 0 && static_cast(ci.shield) < sectors_.size() && sectors_[ci.shield].valid; - if(hasPlane && projectLine) { // a projected line: from the projection onto the cluster's own sector - auto ip = projected.find(ci.shield); - if(ip != projected.end()) bestx = ip->second; - } else if(hasPlane) { + if(hasPlane) { auto const& g = sectors_[ci.shield]; for(size_t k = 0; k < m.xings_.size(); ++k) { if(requireSameSector_ && m.xings_[k].sector_ != ci.shield) continue; @@ -350,10 +293,8 @@ namespace mu2e { c.du_ = r.Dot(g.u); c.dv_ = r.Dot(g.v); c.dtXing_ = ci.time - tp; - // track covariance on the cluster's plane: the reference crossing's covariance carried over the straight step; - // a projected crossing carries that of the intersection it was projected from, over the step from there - double dsCov = ki.surfaceId() == x.sid_ ? ds : (ci.pos - ki.position3()).Dot(g.w) / dn; - c.cov_ = errorModel(trkCrvPlaneCovariance(ki.pstate_.stateCovariance(), ki.momentum3(), g.u, g.v, g.w, dsCov)); + // track covariance on the cluster's plane: the reference crossing's covariance carried over the straight step + c.cov_ = errorModel(trkCrvPlaneCovariance(ki, g, pp, tp)); double sv = resolution(sigmaV_, ci.sectorType), su = resolution(sigmaU_, ci.sectorType); double st = ci.singleEnded ? sigmaTSingle_ : resolution(sigmaT_, ci.sectorType); c.chi2_ = c.dtXing_*c.dtXing_/(st*st + x.sigT_*x.sigT_); @@ -381,17 +322,6 @@ namespace mu2e { m.cands_.push_back(c); } } - if(!projected.empty()) { // keep only the projected crossings a geometric candidate refers to, in sector order - std::vector used(m.xings_.size(), false); - for(auto const& c : m.cands_) if(c.xing_ >= 0) used[c.xing_] = true; - std::vector remap(m.xings_.size(), -1); - std::vector kept; - for(size_t k = 0; k < m.xings_.size(); ++k) - if(used[k]) { remap[k] = static_cast(kept.size()); kept.push_back(std::move(m.xings_[k])); } - m.xings_ = std::move(kept); - for(auto& c : m.cands_) if(c.xing_ >= 0) c.xing_ = remap[c.xing_]; - } - // rank: geometric by chi2, then time-only by distance from the time centre std::stable_sort(m.cands_.begin(), m.cands_.end(), [&](TrkCrvCandidate const& a, TrkCrvCandidate const& b) { bool ga = a.hasFlag(TrkCrvCandidate::geomCand), gb = b.hasFlag(TrkCrvCandidate::geomCand); diff --git a/CRVReco/src/TrkCrvMatcher_module.cc b/CRVReco/src/TrkCrvMatcher_module.cc index c860c8681a..0d4f505e8b 100644 --- a/CRVReco/src/TrkCrvMatcher_module.cc +++ b/CRVReco/src/TrkCrvMatcher_module.cc @@ -5,9 +5,8 @@ // is by default the track's entry into the tracker (earliest of TT_Front, TT_Back, TT_Outer); // - space: from the track's CRV crossing nearest to the cluster's sector plane, a straight-line projection onto that // plane gives du, dv and dtXing, and a space+time chi2 with the full (u, v) covariance; clusters inside MaxDu, -// MaxDv and DtXingWindow are geometric candidates; a straight-line fit with no CRV crossing (its line passes -// outside every sector) is projected instead from its intersection nearest the cluster's sector onto that -// sector's extended plane, recorded as a crossing with inBounds false; +// MaxDv and DtXingWindow are geometric candidates. The crossings include the out-of-bounds near misses the +// extrapolation records (KKExtrap NearMissFraction), as crossings with inBounds false; // - every candidate is kept: a track can have several, and a cluster can be a candidate of several tracks. They are // ranked by chi2, then by time, with bestGeom and bestTime per track and bestInSector per sector; across the // collection nShare, bestForCluster and a greedy one-to-one 'exclusive' assignment resolve shared clusters. diff --git a/CRVResponse/src/TrkCrvMatchMCMaker_module.cc b/CRVResponse/src/TrkCrvMatchMCMaker_module.cc index cdb3663087..82e8afb846 100644 --- a/CRVResponse/src/TrkCrvMatchMCMaker_module.cc +++ b/CRVResponse/src/TrkCrvMatchMCMaker_module.cc @@ -17,7 +17,6 @@ #include "messagefacility/MessageLogger/MessageLogger.h" #include "Offline/CRVReco/inc/TrkCrvGeom.hh" -#include "Offline/CRVReco/inc/TrkCrvPlaneError.hh" #include "Offline/CosmicRayShieldGeom/inc/CosmicRayShield.hh" #include "Offline/DataProducts/inc/SurfaceId.hh" #include "Offline/GeometryService/inc/DetectorSystem.hh" @@ -110,9 +109,9 @@ namespace mu2e { unsigned trueCluBest = 0, trueCluProj = 0; // ... best in its sector; projected from another sector double chi2nd = 0, chi2ndProj = 0; // sums of chi2/ndof of those geometric candidates unsigned trueX = 0, trueFound = 0, trueMissed = 0, trueNoGeom = 0; - unsigned recoProj = 0, recoProjTrue = 0, trueMissedProj = 0; // projections of line fits with no CRV crossing - unsigned trueCluNoXing = 0; // own cluster geometric through such a projection - double chi2ndNoXing = 0; // ... their chi2/ndof sum, kept out of chi2nd + unsigned recoNear = 0, recoNearTrue = 0, trueMissedNear = 0; // out-of-bounds near-miss crossings + unsigned trueCluNear = 0; // own cluster geometric through such a near miss + double chi2ndNear = 0; // ... their chi2/ndof sum, kept out of chi2nd }; art::InputTag matchTag_, ksmcTag_, spTag_, trajTag_, stepTag_, ccmcTag_; bool requireSteps_; @@ -386,7 +385,7 @@ namespace mu2e { for(size_t ir = 0; ir < m.xings_.size(); ++ir) { auto& c = counts_[m.xings_[ir].sector_]; int t = mc.recoXingTruth_[ir]; - if(!m.xings_[ir].inBounds_) { ++c.recoProj; if(t >= 0) ++c.recoProjTrue; continue; } // not a crossing the extrapolation found + if(!m.xings_[ir].inBounds_) { ++c.recoNear; if(t >= 0) ++c.recoNearTrue; continue; } // a near miss, not an in-bounds crossing ++c.recoX; if(t < 0) { ++c.recoFake; if(m.xings_[ir].edgeSig_ < edgeSigCut_) ++c.recoFakeEdge; if(mc.recoXingNeighbor_[ir] >= 0) ++c.recoFakeNbr; } else if(mc.xings_[t].rel_ != MCRelationship::same) ++c.recoTrueAnc; @@ -402,7 +401,7 @@ namespace mu2e { if(xm.recoXing_ >= 0 && m.xings_[xm.recoXing_].inBounds_) ++c.trueFound; else { ++c.trueMissed; - if(xm.recoXing_ >= 0) ++c.trueMissedProj; + if(xm.recoXing_ >= 0) ++c.trueMissedNear; for(auto const& rx : m.xings_) if(rx.inBounds_ && rx.sector_ >= 0 && xm.sector_ >= 0 && planeGroup_[rx.sector_] >= 0 && planeGroup_[rx.sector_] == planeGroup_[xm.sector_]) { ++c.trueMissedNbr; break; } } @@ -419,7 +418,7 @@ namespace mu2e { excl = cand.hasFlag(TrkCrvCandidate::exclusive); if(cand.hasFlag(TrkCrvCandidate::bestInSector)) ++c.trueCluBest; double cn = cand.ndof_ > 0 ? cand.chi2_ / cand.ndof_ : 0.0; - if(cand.xing_ >= 0 && !m.xings_[cand.xing_].inBounds_) { ++c.trueCluNoXing; c.chi2ndNoXing += cn; } + if(cand.xing_ >= 0 && !m.xings_[cand.xing_].inBounds_) { ++c.trueCluNear; c.chi2ndNear += cn; } else c.chi2nd += cn; if(!cand.hasFlag(TrkCrvCandidate::sameSector)) { ++c.trueCluProj; c.chi2ndProj += cn; } } @@ -452,16 +451,17 @@ namespace mu2e { auto const& rect = *sectors_[xm.sector_].rect; auto const& rx = m.xings_[c.xing_]; auto const& ki = m.track_->intersections()[rx.inter_]; - KinKal::VEC3 px = ki.position3(); // the state the error is carried from; a projection's crossing is already on the plane + KinKal::VEC3 px = ki.position3(); // the state the error is carried from KinKal::VEC3 mom = ki.momentum3(), d = mom.Unit(); KinKal::VEC3 const& w = rect.normal(); double dw = d.Dot(w); if(std::fabs(dw) < trkCrvMinCosToNormal) continue; double s = (rect.center() - px).Dot(w) / dw; KinKal::VEC3 r = KinKal::VEC3(xm.pos_.X(), xm.pos_.Y(), xm.pos_.Z()) - (px + s * d); - auto const& cov = ki.pstate_.stateCovariance(); - auto ce = trkCrvPlaneCovariance(cov, mom, rect.uDirection(), rect.vDirection(), w, s); - auto c0 = trkCrvPlaneCovariance(cov, mom, rect.uDirection(), rect.vDirection(), w, 0.0); + double speed = std::sqrt(ki.velocity().Mag2()); + auto const& g = sectors_[xm.sector_]; + auto ce = trkCrvPlaneCovariance(ki, g, px + s * d, ki.time() + (speed > 0 ? s / speed : 0.0)); + auto c0 = trkCrvPlaneCovariance(ki, g, px, ki.time()); log << "\n pull shield " << xm.sector_ << " same " << c.hasFlag(TrkCrvCandidate::sameSector) << " single " << c.hasFlag(TrkCrvCandidate::singleEnded) << " s " << s << " dw " << dw << " du " << c.du_ << " dv " << c.dv_ << " sigU " << c.sigU() << " sigV " << c.sigV() @@ -482,19 +482,19 @@ namespace mu2e { log << "TrkCrvMatchMC summary (" << moduleDescription().moduleLabel() << "): tracks " << nTracks_ << ", with MC " << nTracksMC_ << ", whose particle crosses a CRV sector " << nTracksCrossing_ << "\n" << std::setw(10) << "sector" << std::setw(8) << "reco" << std::setw(9) << "true:dep" << std::setw(9) << "true:gap" - << std::setw(9) << "true:anc" << std::setw(7) << "fake" << std::setw(10) << "fake:edge" << std::setw(9) << "fake:nbr" << std::setw(6) << "proj" << std::setw(11) << "proj:true" << " |" << std::setw(7) << "truth" << std::setw(7) << "found" - << std::setw(8) << "missed" << std::setw(9) << "miss:nbr" << std::setw(10) << "miss:proj" << std::setw(12) << "dep-no-geom"; + << std::setw(9) << "true:anc" << std::setw(7) << "fake" << std::setw(10) << "fake:edge" << std::setw(9) << "fake:nbr" << std::setw(6) << "near" << std::setw(11) << "near:true" << " |" << std::setw(7) << "truth" << std::setw(7) << "found" + << std::setw(8) << "missed" << std::setw(9) << "miss:nbr" << std::setw(10) << "miss:near" << std::setw(12) << "dep-no-geom"; for(auto const& [s, c] : counts_) { std::string n = (s >= 0 && static_cast(s) < shieldNames_.size()) ? shieldNames_[s] : std::to_string(s); log << "\n" << std::setw(10) << n << std::setw(8) << c.recoX << std::setw(9) << c.recoTrueDep << std::setw(9) << c.recoTrueGap - << std::setw(9) << c.recoTrueAnc << std::setw(7) << c.recoFake << std::setw(10) << c.recoFakeEdge << std::setw(9) << c.recoFakeNbr << std::setw(6) << c.recoProj << std::setw(11) << c.recoProjTrue << " |" << std::setw(7) << c.trueX << std::setw(7) << c.trueFound - << std::setw(8) << c.trueMissed << std::setw(9) << c.trueMissedNbr << std::setw(10) << c.trueMissedProj << std::setw(12) << c.trueNoGeom; + << std::setw(9) << c.recoTrueAnc << std::setw(7) << c.recoFake << std::setw(10) << c.recoFakeEdge << std::setw(9) << c.recoFakeNbr << std::setw(6) << c.recoNear << std::setw(11) << c.recoNearTrue << " |" << std::setw(7) << c.trueX << std::setw(7) << c.trueFound + << std::setw(8) << c.trueMissed << std::setw(9) << c.trueMissedNbr << std::setw(10) << c.trueMissedNear << std::setw(12) << c.trueNoGeom; } for(auto const& [s, c] : counts_) { std::string n = (s >= 0 && static_cast(s) < shieldNames_.size()) ? shieldNames_[s] : std::to_string(s); log << "\nclusters " << n << " true " << c.trueClu << " geom " << c.trueCluGeom << " exclusive " << c.trueCluExcl << " best " << c.trueCluBest << " chi2nd " << c.chi2nd << " proj " << c.trueCluProj << " chi2ndProj " << c.chi2ndProj - << " noxing " << c.trueCluNoXing << " chi2ndNoXing " << c.chi2ndNoXing; + << " near " << c.trueCluNear << " chi2ndNear " << c.chi2ndNear; } log << "\nbest geometric candidate:"; for(int i = 0; i < nRel; ++i) log << " " << relName[i] << " " << bestGeomRel_[i]; diff --git a/Mu2eKinKal/fcl/prolog.fcl b/Mu2eKinKal/fcl/prolog.fcl index 7ca294bd84..47c9a8ffe6 100644 --- a/Mu2eKinKal/fcl/prolog.fcl +++ b/Mu2eKinKal/fcl/prolog.fcl @@ -393,6 +393,8 @@ Mu2eKinKal : { ToCaloD0 : true ToCaloD1 : true ToCaloMaterial : false # calo front panel material; off until validated against MC truth + NearMissFraction : 0.1 # record out-of-bounds material crossings with at least this fraction of the position covariance in bounds, as inactive material + CRVNearMissFraction : 1e-3 # the same for CRV sectors } LHSEEDXTRAP : { @@ -408,6 +410,8 @@ Mu2eKinKal : { ToCRV : false ToCaloD0 : false ToCaloD1 : false + NearMissFraction : 0.1 # record out-of-bounds material crossings with at least this fraction of the position covariance in bounds, as inactive material + CRVNearMissFraction : 1e-3 # the same for CRV sectors } KLXTRAP : { @@ -423,6 +427,8 @@ Mu2eKinKal : { ToCRV : true ToCaloD0 : true ToCaloD1 : true + NearMissFraction : 0.1 # record out-of-bounds material crossings with at least this fraction of the position covariance in bounds, as inactive material + CRVNearMissFraction : 1e-3 # the same for CRV sectors } CHXTRAP : { @@ -438,6 +444,8 @@ Mu2eKinKal : { ToCRV : true ToCaloD0 : true ToCaloD1 : true + NearMissFraction : 0.1 # record out-of-bounds material crossings with at least this fraction of the position covariance in bounds, as inactive material + CRVNearMissFraction : 1e-3 # the same for CRV sectors } CENTRALHELIX : { diff --git a/Mu2eKinKal/inc/ExtrapolateSweep.hh b/Mu2eKinKal/inc/ExtrapolateSweep.hh index 3089821941..356f5d9ece 100644 --- a/Mu2eKinKal/inc/ExtrapolateSweep.hh +++ b/Mu2eKinKal/inc/ExtrapolateSweep.hh @@ -9,6 +9,10 @@ // - Stop: nothing driving is reachable (reachable), MaxDt passes without a crossing, a terminal target is crossed, a watched reflection occurs, or the search fails (error()). // - Limit: limit(t,recordonly) caps the search at t (optionally to record targets only); KKExtrap uses it for the fitted trajectory before the end piece, where no material can be added, and unlimit() removes the cap. // - Re-crossing guard: a plane, CRV sector or foil is crossed again only after the trajectory has left the slab of half-width intertol around it (departed). +// - Near misses: a target with nearfrac_ > 0 also accepts an out-of-bounds crossing when at least that fraction of the trajectory position covariance, +// projected onto the surface, lies within the surface bounds (KinKal::Intersection::inbfrac_). KKExtrap adds it like an in-bounds crossing; its +// material xing is inactive (it has no effect unless a refit moves it in bounds), and it doesn't count against maxcross_ or the target group. +// The projected covariance is filled for every crossing of such a target. // - Planes: the signed plane distance of a helix or line is monotonic between the extrema of its normal velocity, which are known in closed form (visitPlaneExtrema), so plane roots are bracketed and bisected (planeCrossing); cylinders use KinKal::intersect. // TEMPORARY: this works around KFTrack/KinKal#233 (KinKal::intersect can return a plane root outside the query). Once Offline uses a KinKal release // with KFTrack/KinKal#235, remove visitPlaneExtrema and planeCrossing and use KinKal::intersect for planes too. @@ -19,6 +23,7 @@ #include "KinKal/General/TimeRange.hh" #include "KinKal/General/Vectors.hh" #include "KinKal/Geometry/Intersection.hh" +#include "KinKal/Geometry/Intersect.hh" #include "KinKal/Geometry/ParticleTrajectoryIntersect.hh" #include "KinKal/Geometry/Annulus.hh" #include "KinKal/Geometry/Cylinder.hh" @@ -70,6 +75,7 @@ namespace mu2e { bool drives_ = true; // keep extending while this target is reachable bool terminal_ = false; // a crossing ends the sweep bool inbounds_ = true; // require the crossing inside the surface bounds + double nearfrac_ = 0.0; // if inbounds_, also accept out-of-bounds crossings (near misses) with at least this fraction of the projected position covariance in bounds; 0 to disable bool active_ = true; // initial state; the upstream reflection logic switches targets on and off double mincos_ = 0.0; // minimum |cos| between the surface normal and the direction at the crossing double rmax_ = inf; // unreachable beyond this transverse radius when moving outward (mm) @@ -81,9 +87,10 @@ namespace mu2e { class ExtrapolateSweep { public: struct Crossing { size_t itarget_ = 0; KinKal::Intersection inter_; }; + static bool nearMiss(SweepTarget const& tg, KinKal::Intersection const& inter) { return tg.inbounds_ && !inter.inbounds_; } // an accepted out-of-bounds crossing of a target requiring bounds ExtrapolateSweep(SweepTargetCollection const& targets, KinKal::TimeDir tdir, double maxdt, double maxdtstep, double dptol, double intertol, double minv, int debug) : targets_(targets), tdir_(tdir), maxDt_(maxdt), maxDtStep_(maxdtstep), - dptol_(dptol), intertol_(intertol), minv_(minv), debug_(debug), active_(targets.size()), count_(targets.size(),0), + dptol_(dptol), intertol_(intertol), minv_(minv), debug_(debug), active_(targets.size()), count_(targets.size(),0), seen_(targets.size(),false), tlast_(targets.size(),0.0), coslast_(targets.size(),1.0), notbefore_(targets.size(),std::numeric_limits::quiet_NaN()), guarded_(targets.size(),false), planes_(targets.size(),nullptr), cylinders_(targets.size(),nullptr) { for(size_t itg = 0; itg < targets_.size(); ++itg){ @@ -123,6 +130,7 @@ namespace mu2e { template bool visitPlaneExtrema(KTRAJ const& piece, KinKal::Plane const& plane, KinKal::TimeRange const& range, VISIT&& visit) const; // times where the plane distance is extremal, in sweep order template KinKal::Intersection planeCrossing(KTRAJ const& piece, KinKal::Plane const& plane, KinKal::TimeRange const& query) const; // first plane root in query, bracketed between extrema template void ownBoundary(KTRAJ const& piece, SweepTarget const& tg, KinKal::Intersection& inter) const; // move a root on a piece edge just inside that piece + template bool nearMissCrossing(KTRAJ const& piece, SweepTarget const& tg, KinKal::Intersection& inter) const; // fill the projected covariance of an out-of-bounds crossing and test its bounds fraction template bool departed(KinKal::ParticleTrajectory const& ptraj, size_t itg, double accepted, double proposed) const; // the trajectory left the plane's tolerance slab between two crossing times template bool reachable(KinKal::ParticleTrajectory const& ptraj) const; // a driving target can still be crossed from the trajectory end SweepTargetCollection const& targets_; @@ -130,7 +138,8 @@ namespace mu2e { double maxDt_, maxDtStep_, dptol_, intertol_, minv_; int debug_; std::vector active_; // per target - std::vector count_; // crossings processed per target + std::vector count_; // crossings processed per target, excluding near misses + std::vector seen_; // a crossing (including a near miss) was processed for this target std::vector tlast_; // time of the last processed crossing per target std::vector coslast_; // |cos| between the surface normal and the direction at that crossing std::vector notbefore_; // per target, NaN for no limit @@ -166,7 +175,8 @@ namespace mu2e { double along = rel.Dot(cyl.axis()); double rho = (rel - along*cyl.axis()).R(); if(std::fabs(rho - cyl.radius()) > reach) return false; - return !targets_[itg].inbounds_ || std::fabs(along) <= cyl.halfLength() + reach; + // a near miss can be beyond the bounds by several position sigma, which aren't known here + return !targets_[itg].inbounds_ || targets_[itg].nearfrac_ > 0.0 || std::fabs(along) <= cyl.halfLength() + reach; } return true; } @@ -176,12 +186,17 @@ namespace mu2e { auto itg = crossing_.itarget_; auto const& tg = targets_[itg]; double time = crossing_.inter_.time_; - ++count_[itg]; + bool near = nearMiss(tg,crossing_.inter_); + // a near miss doesn't use up the target or its group: the track can still cross it (or a group member) in bounds + if(!near){ + ++count_[itg]; + if(tg.group_ >= 0) doneGroups_.push_back(tg.group_); + } + seen_[itg] = true; tlast_[itg] = time; coslast_[itg] = std::fabs(crossing_.inter_.norm_.Dot(crossing_.inter_.pdir_)); - if(tg.group_ >= 0) doneGroups_.push_back(tg.group_); guarded_[itg] = (tg.effect_ == SweepTarget::planeshell || tg.effect_ == SweepTarget::crvsector || tg.effect_ == SweepTarget::stfoil) && - tg.pl_ && tg.surf_->inBounds(crossing_.inter_.pos_,intertol_); + tg.pl_ && (near || tg.surf_->inBounds(crossing_.inter_.pos_,intertol_)); searched_ = time; found_ = false; } @@ -330,6 +345,20 @@ namespace mu2e { return result; } + template bool ExtrapolateSweep::nearMissCrossing(KTRAJ const& piece, SweepTarget const& tg, KinKal::Intersection& inter) const { + // cheap pre-filter: the projected covariance's largest sigma bounds how far out of bounds a near miss can be + static constexpr double dirtol = 1.0e-10; // minimum |cos| between the particle direction and the surface normal for a covariance projection + auto tplane = tg.surf_->tangentPlane(inter.pos_); + if(std::fabs(tplane.normal().Dot(inter.pdir_)) < 2*dirtol) return false; + auto pcov = piece.planeCovariance(inter.time_,KinKal::Plane(tplane.normal(),tplane.uDirection(),inter.pos_),dirtol); + double trace = pcov(0,0)+pcov(1,1), det = pcov(0,0)*pcov(1,1)-pcov(0,1)*pcov(1,0); + double lmax = 0.5*(trace + std::sqrt(std::max(trace*trace-4.0*det,0.0))); + static constexpr double nsigma = 5.0; // KinKal::boundsFraction integrates the Gaussian out to 5 sigma + if(!std::isfinite(lmax) || !(lmax > 0.0) || !tg.surf_->inBounds(inter.pos_,nsigma*std::sqrt(lmax))) return false; + KinKal::fillPlaneCovariance(piece,*tg.surf_,inter,intertol_,dirtol); + return inter.hascov_ && inter.inbfrac_ >= tg.nearfrac_; + } + template bool ExtrapolateSweep::departed(KinKal::ParticleTrajectory const& ptraj, size_t itg, double accepted, double proposed) const { // Candidate searches are speculative: only the current trajectory between the accepted and proposed crossings is a witness. @@ -393,7 +422,7 @@ namespace mu2e { // a track at incidence |cos| stays within the tolerance for about tolerance/|cos| of path; skip past it before finding this target again double leave = tg.mincos_ > 0.0 ? 2.0*intertol_/(std::max(coslast_[itg],tg.mincos_)*speed) : 0.0; double guard = std::max(step,leave); - if(count_[itg] > 0) ts = sgn > 0.0 ? std::max(ts,tlast_[itg]+guard) : std::min(ts,tlast_[itg]-guard); + if(seen_[itg]) ts = sgn > 0.0 ? std::max(ts,tlast_[itg]+guard) : std::min(ts,tlast_[itg]-guard); if(std::isfinite(notbefore_[itg])) ts = sgn > 0.0 ? std::max(ts,notbefore_[itg]) : std::min(ts,notbefore_[itg]); auto const* plane = dynamic_cast(tg.surf_); unsigned nroot(0); @@ -427,7 +456,8 @@ namespace mu2e { if(sgn*(inter.time_ - ts) < 0.0 || sgn*(stop - inter.time_) < 0.0) return false; if(!inter.inrange_) throw std::runtime_error("KKExtrap: surface root has no owning piece"); bool grazing = std::fabs(inter.norm_.Dot(inter.pdir_)) < tg.mincos_; - if((inter.inbounds_ || !tg.inbounds_) && !grazing && (!guarded_[itg] || departed(ptraj,itg,tlast_[itg],inter.time_))) return true; + bool near = !inter.inbounds_ && tg.inbounds_ && tg.nearfrac_ > 0.0 && !grazing && nearMissCrossing(piece,tg,inter); + if((inter.inbounds_ || !tg.inbounds_ || near) && !grazing && (!guarded_[itg] || departed(ptraj,itg,tlast_[itg],inter.time_))) return true; // Roots within four intersection tolerances of path length are unresolved by this search; a grazing track first leaves the tolerance. double next = inter.time_ + sgn*(grazing ? std::max(step,2.0*intertol_/(tg.mincos_*speed)) : step); if(!std::isfinite(next) || sgn*(next - ts) <= 0.0) @@ -448,6 +478,7 @@ namespace mu2e { KinKal::TimeRange window(std::min(t0,t1),std::max(t0,t1)); bool found(false); Crossing best; + size_t bestpiece(0); size_t first = ptraj.nearestIndex(window.begin()); size_t last = ptraj.nearestIndex(window.end()); for(size_t ip = first; ip <= last; ++ip){ @@ -466,10 +497,14 @@ namespace mu2e { found = true; best.itarget_ = itg; best.inter_ = inter; + bestpiece = ip; } } } if(found){ + // the projected covariance of a near-miss target crossing (filled already for a near miss), only for the winning candidate as it is costly + if(targets_[best.itarget_].nearfrac_ > 0.0 && !best.inter_.hascov_) + KinKal::fillPlaneCovariance(ptraj.piece(bestpiece),*targets_[best.itarget_].surf_,best.inter_,intertol_); crossing_ = best; found_ = true; searched_ = t0; diff --git a/Mu2eKinKal/inc/KKExtrap.hh b/Mu2eKinKal/inc/KKExtrap.hh index 4f058457c9..22ec917ab6 100644 --- a/Mu2eKinKal/inc/KKExtrap.hh +++ b/Mu2eKinKal/inc/KKExtrap.hh @@ -59,6 +59,7 @@ namespace mu2e { int debug_; mutable std::atomic nRangedOut_{0}, nNotTruncated_{0}; // counted in rangeOut, reported by printSummary double btol_, intertol_, maxdt_, maxdtstep_, minv_; + double nearfrac_, crvnearfrac_; // near-miss bounds fractions for material targets (see ExtrapolateSweep), 0 to disable bool backToTracker_, extrapolateOPA_, toTrackerPerimeter_, upstream_, toCRV_; bool toCaloD0_, toCaloD1_, toCaloMaterial_; // nominal literal like the hard-coded KinKalGeom IPA surface (KinKalGeomMaker::makeDS); TODO: take it from the geometry service. @@ -77,6 +78,8 @@ namespace mu2e { maxdt_(extrapconfig.MaxDt()), maxdtstep_(extrapconfig.MaxDtStep()), minv_(extrapconfig.MinV()), + nearfrac_(extrapconfig.NearMissFraction()), + crvnearfrac_(extrapconfig.CRVNearMissFraction()), backToTracker_(extrapconfig.BackToTracker()), extrapolateOPA_(extrapconfig.ToOPA()), toTrackerPerimeter_(extrapconfig.ToTrackerPerimeter()), @@ -191,6 +194,7 @@ namespace mu2e { ipatg.thick_ = ipathick_; ipatg.maxcross_ = 0; ipatg.mincos_ = std::max(minv_,ipaMinCos_); + ipatg.nearfrac_ = nearfrac_; zrange(*ipa,ipatg.zreglo_,ipatg.zreghi_); tgts.push_back(ipatg); auto const& st = *kkg_h->ST(); @@ -209,6 +213,7 @@ namespace mu2e { tg.thick_ = st.foilThickness(ifoil); tg.maxcross_ = 0; tg.mincos_ = std::max(minv_,stFoilMinCos_); + tg.nearfrac_ = nearfrac_; tg.zreglo_ = stzlo; tg.zreghi_ = stzhi; tgts.push_back(tg); } @@ -253,6 +258,7 @@ namespace mu2e { tg.thick_ = cyl.thickness_; tg.mincos_ = std::max(minv_,dsShellMinCos_); tg.rmax_ = cyl.surface_->radius() + 0.5*cyl.thickness_; + tg.nearfrac_ = nearfrac_; tgts.push_back(tg); } auto plane = [&](SweepTarget& tg, KinKal::Plane const& pl){ @@ -267,6 +273,7 @@ namespace mu2e { tg.plane_ = pmp.surface_; tg.mat_ = &*kkmat_h->material(pmp.material_); tg.thick_ = pmp.thickness_; + tg.nearfrac_ = nearfrac_; plane(tg,*pmp.surface_); tgts.push_back(tg); } @@ -280,6 +287,7 @@ namespace mu2e { tg.mat_ = &*kkmat_h->CRVMaterial(); tg.thick_ = 2*sector.whw_; tg.crvsector_ = §or; + tg.nearfrac_ = crvnearfrac_; plane(tg,*sector.sector_); tgts.push_back(tg); } @@ -298,6 +306,7 @@ namespace mu2e { tg.mat_ = &*kkmat_h->material(*layer.material_); tg.thick_ = layer.thickness_; tg.pipes_ = layer.pipes_; + tg.nearfrac_ = nearfrac_; tg.rmax_ = bore; tgts.push_back(tg); } @@ -462,8 +471,21 @@ namespace mu2e { ktrk.addIntersection(tg.sid_,inter); return true; } + // a near miss (out of bounds, see ExtrapolateSweep) is added as an inactive xing: it has no effect unless a refit moves it in bounds + bool near = ExtrapolateSweep::nearMiss(tg,inter); double thick = tg.pipes_ ? tg.pipes_->wallDepth(inter.pos_) : tg.thick_; - if(tg.crvsector_) thick *= tg.crvsector_->layerFraction(inter.pos_,inter.pdir_); // near a seam, the staggered layers are shared with the next sector + if(tg.crvsector_){ + // near a seam, the staggered layers are shared with the next sector. A near miss uses the closest point on the sector edge + auto lpos = inter.pos_; + if(near){ + auto const& rect = *tg.crvsector_->sector_; + auto rel = lpos - rect.center(); + double u = std::clamp(rel.Dot(rect.uDirection()),-rect.uHalfLength(),rect.uHalfLength()); + double v = std::clamp(rel.Dot(rect.vDirection()),-rect.vHalfLength(),rect.vHalfLength()); + lpos = rect.center() + u*rect.uDirection() + v*rect.vDirection() + rel.Dot(rect.normal())*rect.normal(); + } + thick *= tg.crvsector_->layerFraction(lpos,inter.pdir_); + } if(tg.effect_ == SweepTarget::calopanel && thick <= 0.0) return true; // the pipe plane between the pipes if(tg.effect_ == SweepTarget::crvsector && thick <= 0.0){ ktrk.addIntersection(tg.sid_,inter); return true; } // inside the envelope but between layers // KinKal records why a fit became unusable (e.g. a failed domain walk); the direction just ends @@ -482,27 +504,27 @@ namespace mu2e { case SweepTarget::cylshell: case SweepTarget::ipashell: { auto shell = std::make_shared>(tg.cyl_,tg.sid_,*tg.mat_,inter,reftrajptr,tg.thick_,intertol_); - if(rangesOut(*shell,tdir)) return rangeOut(ktrk,tg,inter); + if(!near && rangesOut(*shell,tdir)) return rangeOut(ktrk,tg,inter); if(tg.effect_ == SweepTarget::cylshell) ktrk.addMaterialCylXing(shell,tdir); else ktrk.addIPAXing(shell,tdir); return true; } case SweepTarget::stfoil: { auto shell = std::make_shared>(tg.ann_,tg.sid_,*tg.mat_,inter,reftrajptr,tg.thick_,intertol_); - if(rangesOut(*shell,tdir)) return rangeOut(ktrk,tg,inter); + if(!near && rangesOut(*shell,tdir)) return rangeOut(ktrk,tg,inter); ktrk.addSTXing(shell,tdir); return true; } case SweepTarget::planeshell: case SweepTarget::calopanel: { auto shell = std::make_shared>(tg.plane_,tg.sid_,*tg.mat_,inter,reftrajptr,thick,intertol_); - if(rangesOut(*shell,tdir)) return rangeOut(ktrk,tg,inter); + if(!near && rangesOut(*shell,tdir)) return rangeOut(ktrk,tg,inter); ktrk.addMaterialPlaneXing(shell,tdir); return true; } case SweepTarget::crvsector: { auto shell = std::make_shared>(tg.rect_,tg.sid_,*tg.mat_,inter,reftrajptr,thick,intertol_); - if(rangesOut(*shell,tdir)) return rangeOut(ktrk,tg,inter); + if(!near && rangesOut(*shell,tdir)) return rangeOut(ktrk,tg,inter); ktrk.addCRVXing(shell,tdir); return true; } diff --git a/Mu2eKinKal/inc/KKFitSettings.hh b/Mu2eKinKal/inc/KKFitSettings.hh index 33e65fa3a7..a257e1148c 100644 --- a/Mu2eKinKal/inc/KKFitSettings.hh +++ b/Mu2eKinKal/inc/KKFitSettings.hh @@ -133,6 +133,8 @@ namespace mu2e { fhicl::Atom ToCaloD0 { Name("ToCaloD0"), Comment("Extrapolate tracks to the calorimeter disk0 surfaces") }; fhicl::Atom ToCaloD1 { Name("ToCaloD1"), Comment("Extrapolate tracks to the calorimeter disk1 surfaces") }; fhicl::Atom ToCaloMaterial { Name("ToCaloMaterial"), Comment("Add material effects from the calorimeter front panels when extrapolating to the calorimeter disks"), false }; + fhicl::Atom NearMissFraction { Name("NearMissFraction"), Comment("Record out-of-bounds material crossings (as inactive material) when at least this fraction of the projected position covariance is in bounds; 0 to disable"), 0.0 }; + fhicl::Atom CRVNearMissFraction { Name("CRVNearMissFraction"), Comment("NearMissFraction for the CRV sectors"), 0.0 }; }; } } diff --git a/Mu2eKinKal/inc/KKShellXing.hh b/Mu2eKinKal/inc/KKShellXing.hh index 8160f9b1ad..ea3044dde5 100644 --- a/Mu2eKinKal/inc/KKShellXing.hh +++ b/Mu2eKinKal/inc/KKShellXing.hh @@ -85,12 +85,14 @@ namespace mu2e { if(neartrajptr != reftrajptr_){ // traj has changed; try intersecting with this piece reftrajptr_ = neartrajptr; - auto newinter = KinKal::intersect(*reftrajptr_,*surf_, reftrajptr_->range(),tol_); + // keep the projected covariance (and bounds fraction) up to date if the crossing has one (see ExtrapolateSweep near misses) + bool pcov = inter_.hascov_; + auto newinter = KinKal::intersect(*reftrajptr_,*surf_, reftrajptr_->range(),tol_,KinKal::TimeDir::forwards,pcov); // a crossing inside the fit can move into a neighboring piece (ie when the fit is split into BField domains): // search the full trajectory near the previous crossing if(!(newinter.onsurface_ && newinter.inrange_)){ static const double dt(1.0); // ns - newinter = KinKal::intersect(ptraj,*surf_,KinKal::TimeRange(inter_.time_-dt,inter_.time_+dt),tol_); + newinter = KinKal::intersect(ptraj,*surf_,KinKal::TimeRange(inter_.time_-dt,inter_.time_+dt),tol_,KinKal::TimeDir::forwards,pcov); if(newinter.onsurface_ && newinter.inrange_)reftrajptr_ = ptraj.nearestTraj(newinter.time_); } // keep the previous crossing rather than one with an invalid time if the surface can't be found diff --git a/Mu2eKinKal/src/ExtrapolateSweepTest_main.cc b/Mu2eKinKal/src/ExtrapolateSweepTest_main.cc index 18a2c13a3f..b5dbdee328 100644 --- a/Mu2eKinKal/src/ExtrapolateSweepTest_main.cc +++ b/Mu2eKinKal/src/ExtrapolateSweepTest_main.cc @@ -739,6 +739,90 @@ namespace { require(limited == 1 && unlimited == 2,"notBefore crossings " + std::to_string(limited) + " and " + std::to_string(unlimited)); } + // Out-of-bounds crossings are accepted as near misses when enough of the projected position covariance is in bounds; + // the near miss doesn't use up its group, and its material xing is inactive so it doesn't split the trajectory. + void nearMiss(TimeDir dir, MatEnv::DetMaterial const& material) { + using Line = KinKal::KinematicLine; + using PTraj = KinKal::ParticleTrajectory; + bool forward = dir == TimeDir::forwards; + double const sigma = 1.0; // position sigma (mm) + auto makeTraj = [&](double x){ + KinKal::ParticleState state(VEC3(x,0.0,0.0),VEC3(0.0,30.0,100.0),0.0,105.658,1); // tilted in v: the line parameters are degenerate along z + KinKal::DMAT cov; + for(unsigned i = 0; i < 6; ++i) cov(i,i) = i < 3 ? sigma*sigma : 1.0e-8; + Line line(KinKal::ParticleStateEstimate(state,cov),VEC3(0.0,0.0,0.0),TimeRange(0.0,1.0)); + line.setRange(TimeRange(0.0,200.0/line.velocity(0.0).Z())); + return PTraj(line); + }; + auto rect = std::make_shared(VEC3(0.0,0.0,1.0),VEC3(1.0,0.0,0.0),VEC3(0.0,0.0,100.0),50.0,50.0); + auto first = [&](PTraj const& traj, SweepTarget const& tg, bool& found){ + SweepTargetCollection targets{tg}; + ExtrapolateSweep sweep(targets,dir,1.0e6,1.0e6,1.0e-4,tol,1.0e-6,0); + sweep.start(forward ? traj.range().begin() : traj.range().end()); + sweep.limit(forward ? traj.range().end() : traj.range().begin(),false); + require(!sweep.needsExtrapolation(traj,dir) && !sweep.failed(),"near-miss search failed"); + found = sweep.hasCrossing(); + return found ? sweep.crossing().inter_ : KinKal::Intersection(); + }; + auto target = [&](double nearfrac){ + auto tg = planeTarget(*rect,mu2e::SurfaceIdEnum::DS_Front,SweepTarget::planeshell,material); + tg.nearfrac_ = nearfrac; + return tg; + }; + bool found(false); + // in bounds: the projected covariance is filled only for near-miss targets + auto inter = first(makeTraj(0.0),target(0.0),found); + require(found && inter.inbounds_ && !inter.hascov_,"in-bounds crossing without near misses"); + inter = first(makeTraj(0.0),target(0.1),found); + require(found && inter.inbounds_ && inter.hascov_ && inter.inbfrac_ > 0.999,"in-bounds crossing lacks its bounds fraction"); + require(std::fabs(std::sqrt(inter.pcov_(0,0))-sigma) < 1.0e-3 && std::fabs(std::sqrt(inter.pcov_(1,1))-sigma*std::sqrt(1.09)) < 1.0e-3,"unexpected projected covariance"); + // half a sigma out of bounds: about 31% in bounds + first(makeTraj(50.5),target(0.0),found); + require(!found,"near miss accepted with near misses disabled"); + inter = first(makeTraj(50.5),target(0.1),found); + require(found && !inter.inbounds_ && inter.onsurface_ && inter.hascov_ && std::fabs(inter.inbfrac_-0.3085) < 0.02,"half-sigma near miss"); + require(ExtrapolateSweep::nearMiss(target(0.1),inter),"near miss not identified"); + // 3 sigma out: below the default fraction, above a small one + first(makeTraj(53.0),target(0.1),found); + require(!found,"3-sigma miss accepted at fraction 0.1"); + inter = first(makeTraj(53.0),target(1.0e-3),found); + require(found && !inter.inbounds_ && inter.inbfrac_ > 1.0e-3 && inter.inbfrac_ < 2.0e-3,"3-sigma near miss at fraction 1e-3"); + // 10 sigma out: rejected by the pre-filter + first(makeTraj(60.0),target(1.0e-3),found); + require(!found,"10-sigma miss accepted"); + // a near miss doesn't use up its group: a later in-bounds group member is still crossed + { + auto traj = makeTraj(50.5); + KinKal::Rectangle later(VEC3(0.0,0.0,1.0),VEC3(1.0,0.0,0.0),VEC3(0.0,0.0,forward ? 150.0 : 50.0),100.0,100.0); + auto a = target(0.1); + auto b = planeTarget(later,mu2e::SurfaceIdEnum::DS_Back,SweepTarget::planeshell,material); + a.group_ = b.group_ = 0; + SweepTargetCollection targets{a,b}; + ExtrapolateSweep sweep(targets,dir,1.0e6,1.0e6,1.0e-4,tol,1.0e-6,0); + sweep.start(forward ? traj.range().begin() : traj.range().end()); + sweep.limit(forward ? traj.range().end() : traj.range().begin(),false); + require(!sweep.needsExtrapolation(traj,dir) && sweep.hasCrossing() && sweep.crossing().itarget_ == 0 && + !sweep.crossing().inter_.inbounds_,"grouped near miss not found first"); + sweep.accept(); + require(!sweep.needsExtrapolation(traj,dir) && sweep.hasCrossing() && sweep.crossing().itarget_ == 1 && + sweep.crossing().inter_.inbounds_,"near miss used up its group"); + sweep.accept(); + require(!sweep.needsExtrapolation(traj,dir) && !sweep.hasCrossing(),"group crossed twice"); + } + // the material of a near miss is inactive and doesn't split the trajectory; an in-bounds crossing does + using Shell = mu2e::KKShellXing; + for(double x : {0.0,50.5}){ + auto traj = makeTraj(x); + inter = first(traj,target(0.1),found); + require(found,"material fixture has no crossing"); + auto shell = std::make_shared(rect,mu2e::SurfaceId(mu2e::SurfaceIdEnum::DS_Front),material,inter,traj.backPtr(),1.0,tol); + KinKal::Material mat(shell,traj); + require(mat.active() == inter.inbounds_,"near-miss material activity"); + mat.extrapolate(traj,dir); + require(traj.pieces().size() == (inter.inbounds_ ? 2u : 1u),"inactive material split the trajectory"); + } + } + void emptySearch() { KinKal::ParticleState state(VEC3(0.0,0.0,0.0),VEC3(0.0,0.0,100.0),0.0,105.658,1); KinKal::KinematicLine line(state,VEC3(0.0,0.0,0.0),TimeRange(0.0,0.1)); @@ -779,6 +863,7 @@ int main() { longPlaneQuery(dir); longPlaneQuery(dir); speculativeRecross(dir,*targetMaterial); + nearMiss(dir,*targetMaterial); for(bool split : {false,true}){ for(bool windows : {false,true}){ for(bool reverse : {false,true}){ diff --git a/RecoDataProducts/inc/TrkCrvMatch.hh b/RecoDataProducts/inc/TrkCrvMatch.hh index b43574d52d..ad5ff77cfd 100644 --- a/RecoDataProducts/inc/TrkCrvMatch.hh +++ b/RecoDataProducts/inc/TrkCrvMatch.hh @@ -39,20 +39,21 @@ namespace mu2e { float uTdiv_ = NAN; // position along the bar from the two-end time difference [mm], NaN if one-ended }; - // one CRV sector crossing of the track's extrapolation (a CRV KalIntersection); for a straight-line fit with no CRV - // KalIntersection, the line's out-of-bounds crossing of the extended plane of a sector holding a candidate + // one CRV sector crossing of the track's extrapolation (a CRV KalIntersection): in bounds, or an out-of-bounds near miss + // that the extrapolation kept because enough of the track position covariance overlaps the sector (see inbFrac_) struct TrkCrvXing { SurfaceId sid_; // CRV sector surface (CRV_EX ... CRV_M8) - int16_t inter_ = -1; // index into KalSeed::intersections(): the crossing, or the intersection a projection starts from + int16_t inter_ = -1; // index into KalSeed::intersections() of the crossing int16_t sector_ = -1; // CRSScintillatorShield index XYZVectorF pos_; // crossing position on the sector mid-plane, detector frame [mm] XYZVectorF dir_; // unit direction of the track at the crossing float time_ = 0; // crossing time [ns] TrkCrvPlaneCov cov_; // track position covariance in the sector plane (u, v), error model applied [mm^2] float sigT_ = 0; // track time error [ns] - float mom_ = 0; // track momentum magnitude at the crossing, or at the starting intersection of a projection [MeV/c] + float mom_ = 0; // track momentum magnitude at the crossing [MeV/c] float momErr_ = 0; // its error [MeV/c] - bool inBounds_ = false; // crossing inside the sector rectangle; false only for a projection, whose candidates run to larger chi2 + bool inBounds_ = false; // crossing inside the sector rectangle; false for a near miss, whose candidates run to larger chi2 + float inbFrac_ = 0; // fraction of the (unscaled) track position covariance inside the sector rectangle; 1 (0) in (out of) bounds if it wasn't computed float dEdgeU_ = 0; // distance inside the sector edge along the bars [mm], negative outside float dEdgeV_ = 0; // distance inside the sector edge across the bars [mm], negative outside float edgeSig_ = 0; // min(dEdgeU_/sigU(), dEdgeV_/sigV()): edge distance in units of the track error @@ -75,7 +76,7 @@ namespace mu2e { float dtXing_ = 0; // cluster avgHitTime - t_track at the cluster plane [ns] float du_ = 0; // cluster - track along the bars, at the cluster plane [mm] float dv_ = 0; // cluster - track across the bars, at the cluster plane [mm] - TrkCrvPlaneCov cov_; // track covariance of (du, dv), carried over the step from the reference crossing (from its starting intersection for a projection), error model applied [mm^2] + TrkCrvPlaneCov cov_; // track covariance of (du, dv), carried over the step from the reference crossing, error model applied [mm^2] float chi2_ = -1; // space + time chi2 (geometric candidates only), with the full (u, v) covariance uint8_t ndof_ = 0; // chi2 degrees of freedom: 2 for single-ended clusters (no along-bar term), else 3 uint8_t nShare_ = 0; // tracks of this collection holding this cluster as a candidate diff --git a/Validation/inc/ValTrkCrvMatch.hh b/Validation/inc/ValTrkCrvMatch.hh index c81c1b28f4..582b30d9ac 100644 --- a/Validation/inc/ValTrkCrvMatch.hh +++ b/Validation/inc/ValTrkCrvMatch.hh @@ -40,17 +40,17 @@ class ValTrkCrvMatch { TH1D* _hNCand; TH1D* _hNGeom; TH1D* _hNXing; - TH1D* _hNXingProj; + TH1D* _hNXingNear; TH1D* _hDtRef; TH1D* _hDtRefBest; TH1D* _hDtRefToF; TH1D* _hChi2; - TH1D* _hChi2Proj; + TH1D* _hChi2Near; TH1D* _hNShare; TH1D* _hFlags; TH1D* _hXingShield; TH1D* _hXingGeomShield; - TH1D* _hXingProjShield; + TH1D* _hXingNearShield; TH2D* _hDtXing; TH2D* _hDu; TH2D* _hDv; diff --git a/Validation/inc/ValTrkCrvMatchMC.hh b/Validation/inc/ValTrkCrvMatchMC.hh index 5348b5c2bf..218cd776f5 100644 --- a/Validation/inc/ValTrkCrvMatchMC.hh +++ b/Validation/inc/ValTrkCrvMatchMC.hh @@ -34,13 +34,13 @@ class ValTrkCrvMatchMC { TH1D* _hTrueCluBest; TH1D* _hRecoXing; TH1D* _hRecoXingTrue; - TH1D* _hRecoXingProj; - TH1D* _hRecoXingProjTrue; + TH1D* _hRecoXingNear; + TH1D* _hRecoXingNearTrue; TH1D* _hTrueXing; TH1D* _hTrueXingFound; - TH1D* _hTrueXingProj; + TH1D* _hTrueXingNear; TH2D* _hXingDist; - TH2D* _hXingDistProj; + TH2D* _hXingDistNear; TH2D* _hXingDt; }; } // namespace mu2e diff --git a/Validation/src/ValTrkCrvMatch.cc b/Validation/src/ValTrkCrvMatch.cc index aa7bb45b15..0bbc1cc54f 100644 --- a/Validation/src/ValTrkCrvMatch.cc +++ b/Validation/src/ValTrkCrvMatch.cc @@ -11,23 +11,23 @@ int mu2e::ValTrkCrvMatch::declare(const art::TFileDirectory& tfs) { _hNCand = tfs.make("NCand", "N candidates per track", 51, -0.5, 50.5); _hNGeom = tfs.make("NGeom", "N geometric candidates per track", 21, -0.5, 20.5); _hNXing = tfs.make("NXing", "N CRV crossings per track (extrapolated, in bounds)", 11, -0.5, 10.5); - _hNXingProj = tfs.make("NXingProj", "N projected CRV crossings per line track with no crossing", 11, -0.5, 10.5); + _hNXingNear = tfs.make("NXingNear", "N near-miss (out-of-bounds) CRV crossings per track", 11, -0.5, 10.5); _hDtRef = tfs.make("dtRef", "t_{trk}(ref) - t_{cluster}, all candidates;ns", 200, -1000., 1000.); _hDtRefBest = tfs.make("dtRefBest", "t_{trk}(ref) - t_{cluster}, best candidate;ns", 200, -400., 400.); _hDtRefToF = tfs.make("dtRefToF", "dtRef - flight time, best candidate;ns", 200, -400., 400.); _hChi2 = tfs.make("chi2ndof", "#chi^{2}/ndof, best in sector, from an in-bounds crossing", 100, 0., 20.); - _hChi2Proj = tfs.make("chi2ndofProj", "#chi^{2}/ndof, best in sector, from a projected crossing", 100, 0., 20.); + _hChi2Near = tfs.make("chi2ndofNear", "#chi^{2}/ndof, best in sector, from a near-miss crossing", 100, 0., 20.); _hNShare = tfs.make("NShare", "tracks sharing the cluster", 11, -0.5, 10.5); _hFlags = tfs.make("Flags", "candidate flag bits", 16, -0.5, 15.5); _hXingShield = tfs.make("XingShield", "CRV crossings per sector (extrapolated, in bounds)", ns, lo, hi); _hXingGeomShield = tfs.make("XingGeomShield", "in-bounds crossings with a geometric candidate in their sector", ns, lo, hi); - _hXingProjShield = tfs.make("XingProjShield", "projected crossings per sector (line tracks with no crossing)", ns, lo, hi); + _hXingNearShield = tfs.make("XingNearShield", "near-miss crossings per sector", ns, lo, hi); _hDtXing = tfs.make("dtXing", "t_{cluster} - t_{trk} at the plane, best in sector;cluster sector;ns", ns, lo, hi, 100, -100., 100.); _hDu = tfs.make("du", "cluster - track along the bars, best in sector;cluster sector;mm", ns, lo, hi, 100, -3000., 3000.); _hDv = tfs.make("dv", "cluster - track across the bars, best in sector;cluster sector;mm", ns, lo, hi, 100, -500., 500.); _hPredMatched = tfs.make("PredMatched", "best geometric candidate;reference crossing sector;cluster sector", ns, lo, hi, ns, lo, hi); _hSlopeNoGeom = tfs.make("SlopeNoGeom", "best in sector, not in dvVsSlope: sector not in this job's geometry;cluster sector", ns, lo, hi); - for (TH1* h : {static_cast(_hXingShield), static_cast(_hXingGeomShield), static_cast(_hXingProjShield), static_cast(_hDtXing), + for (TH1* h : {static_cast(_hXingShield), static_cast(_hXingGeomShield), static_cast(_hXingNearShield), static_cast(_hDtXing), static_cast(_hDu), static_cast(_hDv), static_cast(_hPredMatched), static_cast(_hSlopeNoGeom)}) _axis.label(h->GetXaxis()); _axis.label(_hPredMatched->GetYaxis()); @@ -67,10 +67,10 @@ int mu2e::ValTrkCrvMatch::fill(const mu2e::TrkCrvMatchCollection& coll, art::Eve for (auto const& m : coll) { for (auto const& x : m.xings_) _shieldBin[x.sector_] = _axis.bin(x.sid_); _hNCand->Fill(m.cands_.size()); - int nproj = 0; - for (auto const& x : m.xings_) nproj += !x.inBounds_; - _hNXing->Fill(m.xings_.size() - nproj); - if (nproj > 0) _hNXingProj->Fill(nproj); + int nnear = 0; + for (auto const& x : m.xings_) nnear += !x.inBounds_; + _hNXing->Fill(m.xings_.size() - nnear); + if (nnear > 0) _hNXingNear->Fill(nnear); int ngeom = 0; for (auto const& c : m.cands_) { _hDtRef->Fill(c.dtRef_); @@ -81,8 +81,8 @@ int mu2e::ValTrkCrvMatch::fill(const mu2e::TrkCrvMatchCollection& coll, art::Eve ++ngeom; if (!c.hasFlag(TrkCrvCandidate::bestInSector)) continue; int b = clusterBin(c.sector_); - bool proj = c.xing_ >= 0 && static_cast(c.xing_) < m.xings_.size() && !m.xings_[c.xing_].inBounds_; - if (c.ndof_ > 0) (proj ? _hChi2Proj : _hChi2)->Fill(c.chi2_ / c.ndof_); + bool near = c.xing_ >= 0 && static_cast(c.xing_) < m.xings_.size() && !m.xings_[c.xing_].inBounds_; + if (c.ndof_ > 0) (near ? _hChi2Near : _hChi2)->Fill(c.chi2_ / c.ndof_); _hDtXing->Fill(b, c.dtXing_); if (!c.hasFlag(TrkCrvCandidate::singleEnded)) _hDu->Fill(b, c.du_); _hDv->Fill(b, c.dv_); @@ -113,7 +113,7 @@ int mu2e::ValTrkCrvMatch::fill(const mu2e::TrkCrvMatchCollection& coll, art::Eve } for (auto const& x : m.xings_) { if (!x.inBounds_) { - _hXingProjShield->Fill(_axis.bin(x.sid_)); + _hXingNearShield->Fill(_axis.bin(x.sid_)); continue; } _hXingShield->Fill(_axis.bin(x.sid_)); diff --git a/Validation/src/ValTrkCrvMatchMC.cc b/Validation/src/ValTrkCrvMatchMC.cc index c6b5603a1e..64e345a53b 100644 --- a/Validation/src/ValTrkCrvMatchMC.cc +++ b/Validation/src/ValTrkCrvMatchMC.cc @@ -14,18 +14,18 @@ int mu2e::ValTrkCrvMatchMC::declare(const art::TFileDirectory& tfs) { _hTrueCluBest = tfs.make("TrueCluBest", "own cluster is the best in its sector", ns, lo, hi); _hRecoXing = tfs.make("RecoXing", "reco crossings per sector (extrapolated, in bounds)", ns, lo, hi); _hRecoXingTrue = tfs.make("RecoXingTrue", "in-bounds reco crossings with a true crossing of the same sector", ns, lo, hi); - _hRecoXingProj = tfs.make("RecoXingProj", "projected crossings per sector (line tracks with no crossing)", ns, lo, hi); - _hRecoXingProjTrue = tfs.make("RecoXingProjTrue", "projected crossings with a true crossing of the same sector", ns, lo, hi); + _hRecoXingNear = tfs.make("RecoXingNear", "near-miss (out-of-bounds) crossings per sector", ns, lo, hi); + _hRecoXingNearTrue = tfs.make("RecoXingNearTrue", "near-miss crossings with a true crossing of the same sector", ns, lo, hi); _hTrueXing = tfs.make("TrueXing", "true crossings of the track's particle per sector", ns, lo, hi); _hTrueXingFound = tfs.make("TrueXingFound", "true crossings with an in-bounds reco crossing", ns, lo, hi); - _hTrueXingProj = tfs.make("TrueXingProj", "true crossings matched only by a projected crossing", ns, lo, hi); + _hTrueXingNear = tfs.make("TrueXingNear", "true crossings matched only by a near-miss crossing", ns, lo, hi); _hXingDist = tfs.make("XingDist", "|reco - true crossing|, in-bounds reco;sector;mm", ns, lo, hi, 100, 0., 500.); - _hXingDistProj = tfs.make("XingDistProj", "|reco - true crossing|, projected reco;sector;mm", ns, lo, hi, 100, 0., 500.); + _hXingDistNear = tfs.make("XingDistNear", "|reco - true crossing|, near-miss reco;sector;mm", ns, lo, hi, 100, 0., 500.); _hXingDt = tfs.make("XingDt", "reco - true crossing time;sector;ns", ns, lo, hi, 100, -20., 20.); for (TH1* h : {static_cast(_hTrueClu), static_cast(_hTrueCluGeom), static_cast(_hTrueCluBest), - static_cast(_hRecoXing), static_cast(_hRecoXingTrue), static_cast(_hRecoXingProj), - static_cast(_hRecoXingProjTrue), static_cast(_hTrueXing), static_cast(_hTrueXingFound), - static_cast(_hTrueXingProj), static_cast(_hXingDist), static_cast(_hXingDistProj), + static_cast(_hRecoXing), static_cast(_hRecoXingTrue), static_cast(_hRecoXingNear), + static_cast(_hRecoXingNearTrue), static_cast(_hTrueXing), static_cast(_hTrueXingFound), + static_cast(_hTrueXingNear), static_cast(_hXingDist), static_cast(_hXingDistNear), static_cast(_hXingDt)}) _axis.label(h->GetXaxis()); return 0; @@ -51,7 +51,7 @@ int mu2e::ValTrkCrvMatchMC::fill(const mu2e::TrkCrvMatchMCCollection& coll, art: if (xm.geom_) { _hTrueXing->Fill(b); bool reco = xm.recoXing_ >= 0 && static_cast(xm.recoXing_) < m.xings_.size(); - if (reco) (m.xings_[xm.recoXing_].inBounds_ ? _hTrueXingFound : _hTrueXingProj)->Fill(b); + if (reco) (m.xings_[xm.recoXing_].inBounds_ ? _hTrueXingFound : _hTrueXingNear)->Fill(b); } if (xm.trueCluster_ < 0) continue; _hTrueClu->Fill(b); @@ -64,15 +64,15 @@ int mu2e::ValTrkCrvMatchMC::fill(const mu2e::TrkCrvMatchMCCollection& coll, art: for (size_t ir = 0; ir < m.xings_.size() && ir < mc.recoXingTruth_.size(); ++ir) { auto const& rx = m.xings_[ir]; int b = _axis.bin(rx.sid_); - bool proj = !rx.inBounds_; - (proj ? _hRecoXingProj : _hRecoXing)->Fill(b); + bool near = !rx.inBounds_; + (near ? _hRecoXingNear : _hRecoXing)->Fill(b); int t = mc.recoXingTruth_[ir]; if (t < 0 || static_cast(t) >= mc.xings_.size()) continue; - (proj ? _hRecoXingProjTrue : _hRecoXingTrue)->Fill(b); + (near ? _hRecoXingNearTrue : _hRecoXingTrue)->Fill(b); auto const& xm = mc.xings_[t]; if (!xm.geom_ || xm.rel_ != MCRelationship::same) continue; - (proj ? _hXingDistProj : _hXingDist)->Fill(b, std::sqrt((rx.pos_ - xm.pos_).Mag2())); - if (!proj) _hXingDt->Fill(b, rx.time_ - xm.time_); + (near ? _hXingDistNear : _hXingDist)->Fill(b, std::sqrt((rx.pos_ - xm.pos_).Mag2())); + if (!near) _hXingDt->Fill(b, rx.time_ - xm.time_); } } return 0;