From 591352984eda31df998c4ab28813df3f0ceb4ee4 Mon Sep 17 00:00:00 2001 From: Rob Mina Date: Thu, 12 Nov 2026 13:25:21 -0600 Subject: [PATCH 1/2] TrkCrvMatch: geometric candidates for straight-line tracks that miss every CRV sector --- CRVReco/inc/TrkCrvMatchTool.hh | 2 + CRVReco/src/TrkCrvMatchTool.cc | 74 +++++++++++++++++++++++++++-- CRVReco/src/TrkCrvMatcher_module.cc | 4 +- RecoDataProducts/inc/TrkCrvMatch.hh | 5 +- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/CRVReco/inc/TrkCrvMatchTool.hh b/CRVReco/inc/TrkCrvMatchTool.hh index e4cc39c5f4..6619cf13c9 100644 --- a/CRVReco/inc/TrkCrvMatchTool.hh +++ b/CRVReco/inc/TrkCrvMatchTool.hh @@ -81,6 +81,8 @@ namespace mu2e { double resolution(std::vector const& tab, int sectorType) const; TrkCrvPlaneCov errorModel(ROOT::Math::SMatrix> 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/src/TrkCrvMatchTool.cc b/CRVReco/src/TrkCrvMatchTool.cc index 5f54a6a75a..678f355b0c 100644 --- a/CRVReco/src/TrkCrvMatchTool.cc +++ b/CRVReco/src/TrkCrvMatchTool.cc @@ -157,6 +157,44 @@ 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) < 1e-3) 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; @@ -227,6 +265,21 @@ 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) { @@ -243,7 +296,10 @@ 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) { + 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) { 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; @@ -269,8 +325,10 @@ 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 - c.cov_ = errorModel(trkCrvPlaneCovariance(ki.pstate_.stateCovariance(), ki.momentum3(), g.u, g.v, g.w, ds)); + // 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)); 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_); @@ -298,6 +356,16 @@ 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) { diff --git a/CRVReco/src/TrkCrvMatcher_module.cc b/CRVReco/src/TrkCrvMatcher_module.cc index b6c3df468b..c860c8681a 100644 --- a/CRVReco/src/TrkCrvMatcher_module.cc +++ b/CRVReco/src/TrkCrvMatcher_module.cc @@ -5,7 +5,9 @@ // 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; +// 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; // - 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/RecoDataProducts/inc/TrkCrvMatch.hh b/RecoDataProducts/inc/TrkCrvMatch.hh index 1e398489ff..3f741f517d 100644 --- a/RecoDataProducts/inc/TrkCrvMatch.hh +++ b/RecoDataProducts/inc/TrkCrvMatch.hh @@ -39,10 +39,11 @@ 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) + // 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 struct TrkCrvXing { SurfaceId sid_; // CRV sector surface (CRV_EX ... CRV_M8) - int16_t inter_ = -1; // index into KalSeed::intersections() + int16_t inter_ = -1; // index into KalSeed::intersections(): the crossing, or the intersection a projection starts from 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 From 8775fa36352fc73ff7df755fd442613b8e08ba84 Mon Sep 17 00:00:00 2001 From: Rob Mina Date: Fri, 13 Nov 2026 07:57:01 -0600 Subject: [PATCH 2/2] TrkCrvMatch: keep projected crossings apart in the MC summary and Validation; comments, shared parallel cut (review) --- CRVReco/inc/TrkCrvMatchTool.hh | 2 +- CRVReco/inc/TrkCrvPlaneError.hh | 3 +- CRVReco/src/TrkCrvMatchTool.cc | 4 +-- CRVResponse/src/TrkCrvMatchMCMaker_module.cc | 29 +++++++++++------- RecoDataProducts/inc/TrkCrvMatch.hh | 6 ++-- Validation/inc/ValTrkCrvMatch.hh | 3 ++ Validation/inc/ValTrkCrvMatchMC.hh | 4 +++ Validation/src/ValTrkCrvMatch.cc | 27 ++++++++++++----- Validation/src/ValTrkCrvMatchMC.cc | 32 ++++++++++++-------- 9 files changed, 72 insertions(+), 38 deletions(-) diff --git a/CRVReco/inc/TrkCrvMatchTool.hh b/CRVReco/inc/TrkCrvMatchTool.hh index 6619cf13c9..8a9188bae8 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")}; + 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 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; the last entry serves higher types); 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")}; diff --git a/CRVReco/inc/TrkCrvPlaneError.hh b/CRVReco/inc/TrkCrvPlaneError.hh index 8b67b4f979..9866600cf6 100644 --- a/CRVReco/inc/TrkCrvPlaneError.hh +++ b/CRVReco/inc/TrkCrvPlaneError.hh @@ -10,6 +10,7 @@ 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| @@ -23,7 +24,7 @@ namespace mu2e { if(pm <= 0) return out; KinKal::VEC3 d = p / pm; double dw = d.Dot(w); - if(std::fabs(dw) < 1e-3) return out; + 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) { diff --git a/CRVReco/src/TrkCrvMatchTool.cc b/CRVReco/src/TrkCrvMatchTool.cc index 678f355b0c..a846bc0273 100644 --- a/CRVReco/src/TrkCrvMatchTool.cc +++ b/CRVReco/src/TrkCrvMatchTool.cc @@ -165,7 +165,7 @@ namespace mu2e { 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) < 1e-3) continue; + 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; } } @@ -306,7 +306,7 @@ namespace mu2e { auto const& xk = m.xings_[k]; KinKal::VEC3 pk(xk.pos_.X(), xk.pos_.Y(), xk.pos_.Z()), dk(xk.dir_.X(), xk.dir_.Y(), xk.dir_.Z()); double dn = dk.Dot(g.w); - if(std::fabs(dn) < 1e-3) continue; + if(std::fabs(dn) < trkCrvMinCosToNormal) continue; double ds = std::fabs((ci.pos - pk).Dot(g.w) / dn); if(ds < bds) { bds = ds; bestx = static_cast(k); } } diff --git a/CRVResponse/src/TrkCrvMatchMCMaker_module.cc b/CRVResponse/src/TrkCrvMatchMCMaker_module.cc index 3fc3ec34f3..cdb3663087 100644 --- a/CRVResponse/src/TrkCrvMatchMCMaker_module.cc +++ b/CRVResponse/src/TrkCrvMatchMCMaker_module.cc @@ -110,6 +110,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 }; art::InputTag matchTag_, ksmcTag_, spTag_, trajTag_, stepTag_, ccmcTag_; bool requireSteps_; @@ -382,8 +385,9 @@ namespace mu2e { bool crosses = false; for(size_t ir = 0; ir < m.xings_.size(); ++ir) { auto& c = counts_[m.xings_[ir].sector_]; - ++c.recoX; int t = mc.recoXingTruth_[ir]; + if(!m.xings_[ir].inBounds_) { ++c.recoProj; if(t >= 0) ++c.recoProjTrue; continue; } // not a crossing the extrapolation found + ++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; else if(mc.xings_[t].edep_ > 0) ++c.recoTrueDep; @@ -395,11 +399,12 @@ namespace mu2e { if(!xm.geom_) { if(xm.edep_ > 0) ++c.trueNoGeom; continue; } crosses = true; ++c.trueX; - if(xm.recoXing_ >= 0) ++c.trueFound; + if(xm.recoXing_ >= 0 && m.xings_[xm.recoXing_].inBounds_) ++c.trueFound; else { ++c.trueMissed; + if(xm.recoXing_ >= 0) ++c.trueMissedProj; for(auto const& rx : m.xings_) - if(rx.sector_ >= 0 && xm.sector_ >= 0 && planeGroup_[rx.sector_] >= 0 && planeGroup_[rx.sector_] == planeGroup_[xm.sector_]) { ++c.trueMissedNbr; break; } + if(rx.inBounds_ && rx.sector_ >= 0 && xm.sector_ >= 0 && planeGroup_[rx.sector_] >= 0 && planeGroup_[rx.sector_] == planeGroup_[xm.sector_]) { ++c.trueMissedNbr; break; } } } for(auto const& xm : mc.xings_) { // is the particle's own cluster in each sector associated geometrically? @@ -414,7 +419,8 @@ 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; - c.chi2nd += cn; + if(cand.xing_ >= 0 && !m.xings_[cand.xing_].inBounds_) { ++c.trueCluNoXing; c.chi2ndNoXing += cn; } + else c.chi2nd += cn; if(!cand.hasFlag(TrkCrvCandidate::sameSector)) { ++c.trueCluProj; c.chi2ndProj += cn; } } } @@ -446,11 +452,11 @@ 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(rx.pos_.X(), rx.pos_.Y(), rx.pos_.Z()); + KinKal::VEC3 px = ki.position3(); // the state the error is carried from; a projection's crossing is already on the plane KinKal::VEC3 mom = ki.momentum3(), d = mom.Unit(); KinKal::VEC3 const& w = rect.normal(); double dw = d.Dot(w); - if(std::fabs(dw) < 1e-3) continue; + 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(); @@ -476,18 +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(7) << "truth" << std::setw(7) << "found" - << std::setw(8) << "missed" << std::setw(9) << "miss:nbr" << 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) << "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"; 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(7) << c.trueX << std::setw(7) << c.trueFound - << std::setw(8) << c.trueMissed << std::setw(9) << c.trueMissedNbr << 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.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; } 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; + << " best " << c.trueCluBest << " chi2nd " << c.chi2nd << " proj " << c.trueCluProj << " chi2ndProj " << c.chi2ndProj + << " noxing " << c.trueCluNoXing << " chi2ndNoXing " << c.chi2ndNoXing; } log << "\nbest geometric candidate:"; for(int i = 0; i < nRel; ++i) log << " " << relName[i] << " " << bestGeomRel_[i]; diff --git a/RecoDataProducts/inc/TrkCrvMatch.hh b/RecoDataProducts/inc/TrkCrvMatch.hh index 3f741f517d..b43574d52d 100644 --- a/RecoDataProducts/inc/TrkCrvMatch.hh +++ b/RecoDataProducts/inc/TrkCrvMatch.hh @@ -50,9 +50,9 @@ namespace mu2e { 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 [MeV/c] + float mom_ = 0; // track momentum magnitude at the crossing, or at the starting intersection of a projection [MeV/c] float momErr_ = 0; // its error [MeV/c] - bool inBounds_ = false; // crossing inside the sector rectangle + bool inBounds_ = false; // crossing inside the sector rectangle; false only for a projection, whose candidates run to larger chi2 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 +75,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 from the reference crossing over the step, error model applied [mm^2] + 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] 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 e48fa0ba0a..c81c1b28f4 100644 --- a/Validation/inc/ValTrkCrvMatch.hh +++ b/Validation/inc/ValTrkCrvMatch.hh @@ -40,14 +40,17 @@ class ValTrkCrvMatch { TH1D* _hNCand; TH1D* _hNGeom; TH1D* _hNXing; + TH1D* _hNXingProj; TH1D* _hDtRef; TH1D* _hDtRefBest; TH1D* _hDtRefToF; TH1D* _hChi2; + TH1D* _hChi2Proj; TH1D* _hNShare; TH1D* _hFlags; TH1D* _hXingShield; TH1D* _hXingGeomShield; + TH1D* _hXingProjShield; TH2D* _hDtXing; TH2D* _hDu; TH2D* _hDv; diff --git a/Validation/inc/ValTrkCrvMatchMC.hh b/Validation/inc/ValTrkCrvMatchMC.hh index 3c27027f3a..5348b5c2bf 100644 --- a/Validation/inc/ValTrkCrvMatchMC.hh +++ b/Validation/inc/ValTrkCrvMatchMC.hh @@ -34,9 +34,13 @@ class ValTrkCrvMatchMC { TH1D* _hTrueCluBest; TH1D* _hRecoXing; TH1D* _hRecoXingTrue; + TH1D* _hRecoXingProj; + TH1D* _hRecoXingProjTrue; TH1D* _hTrueXing; TH1D* _hTrueXingFound; + TH1D* _hTrueXingProj; TH2D* _hXingDist; + TH2D* _hXingDistProj; TH2D* _hXingDt; }; } // namespace mu2e diff --git a/Validation/src/ValTrkCrvMatch.cc b/Validation/src/ValTrkCrvMatch.cc index d39bbd6912..aa7bb45b15 100644 --- a/Validation/src/ValTrkCrvMatch.cc +++ b/Validation/src/ValTrkCrvMatch.cc @@ -10,21 +10,24 @@ int mu2e::ValTrkCrvMatch::declare(const art::TFileDirectory& tfs) { _hNTrk = tfs.make("NTrk", "N tracks", 21, -0.5, 20.5); _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", 11, -0.5, 10.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); _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", 100, 0., 20.); + _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.); _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", ns, lo, hi); - _hXingGeomShield = tfs.make("XingGeomShield", "crossings with a geometric candidate in their sector", ns, lo, hi); + _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); _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(_hDtXing), + for (TH1* h : {static_cast(_hXingShield), static_cast(_hXingGeomShield), static_cast(_hXingProjShield), static_cast(_hDtXing), static_cast(_hDu), static_cast(_hDv), static_cast(_hPredMatched), static_cast(_hSlopeNoGeom)}) _axis.label(h->GetXaxis()); _axis.label(_hPredMatched->GetYaxis()); @@ -53,7 +56,7 @@ int mu2e::ValTrkCrvMatch::declare(const art::TFileDirectory& tfs) { int mu2e::ValTrkCrvMatch::fill(const mu2e::TrkCrvMatchCollection& coll, art::Event const& event) { // increment this by 1 any time the definitions of the histograms or the // histogram contents change, and will not match previous versions - _hVer->Fill(1.0); + _hVer->Fill(2.0); // a cluster's sector: the SurfaceId of a crossing with the same shield index in the product's geometry auto clusterBin = [&](int16_t shield) { @@ -64,7 +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()); - _hNXing->Fill(m.xings_.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 ngeom = 0; for (auto const& c : m.cands_) { _hDtRef->Fill(c.dtRef_); @@ -75,7 +81,8 @@ int mu2e::ValTrkCrvMatch::fill(const mu2e::TrkCrvMatchCollection& coll, art::Eve ++ngeom; if (!c.hasFlag(TrkCrvCandidate::bestInSector)) continue; int b = clusterBin(c.sector_); - if (c.ndof_ > 0) _hChi2->Fill(c.chi2_ / c.ndof_); + 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_); _hDtXing->Fill(b, c.dtXing_); if (!c.hasFlag(TrkCrvCandidate::singleEnded)) _hDu->Fill(b, c.du_); _hDv->Fill(b, c.dv_); @@ -105,6 +112,10 @@ int mu2e::ValTrkCrvMatch::fill(const mu2e::TrkCrvMatchCollection& coll, art::Eve _hPredMatched->Fill(_axis.bin(m.xings_[c.xing_].sid_), clusterBin(c.sector_)); } for (auto const& x : m.xings_) { + if (!x.inBounds_) { + _hXingProjShield->Fill(_axis.bin(x.sid_)); + continue; + } _hXingShield->Fill(_axis.bin(x.sid_)); if (x.best_ >= 0) _hXingGeomShield->Fill(_axis.bin(x.sid_)); for (size_t L = 0; L < x.layers_.size(); ++L) { diff --git a/Validation/src/ValTrkCrvMatchMC.cc b/Validation/src/ValTrkCrvMatchMC.cc index 8fa26f738a..c6b5603a1e 100644 --- a/Validation/src/ValTrkCrvMatchMC.cc +++ b/Validation/src/ValTrkCrvMatchMC.cc @@ -12,15 +12,21 @@ int mu2e::ValTrkCrvMatchMC::declare(const art::TFileDirectory& tfs) { _hTrueClu = tfs.make("TrueClu", "own cluster of the track's particle per sector", ns, lo, hi); _hTrueCluGeom = tfs.make("TrueCluGeom", "own cluster is a geometric candidate", ns, lo, hi); _hTrueCluBest = tfs.make("TrueCluBest", "own cluster is the best in its sector", ns, lo, hi); - _hRecoXing = tfs.make("RecoXing", "reco crossings per sector", ns, lo, hi); - _hRecoXingTrue = tfs.make("RecoXingTrue", "reco crossings with a true crossing of the same 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); _hTrueXing = tfs.make("TrueXing", "true crossings of the track's particle per sector", ns, lo, hi); - _hTrueXingFound = tfs.make("TrueXingFound", "true crossings with a reco crossing", ns, lo, hi); - _hXingDist = tfs.make("XingDist", "|reco - true crossing|;sector;mm", ns, lo, hi, 100, 0., 500.); + _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); + _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.); _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(_hTrueXing), - static_cast(_hTrueXingFound), static_cast(_hXingDist), static_cast(_hXingDt)}) + 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(_hXingDt)}) _axis.label(h->GetXaxis()); return 0; } @@ -28,7 +34,7 @@ int mu2e::ValTrkCrvMatchMC::declare(const art::TFileDirectory& tfs) { int mu2e::ValTrkCrvMatchMC::fill(const mu2e::TrkCrvMatchMCCollection& coll, art::Event const& event) { // increment this by 1 any time the definitions of the histograms or the // histogram contents change, and will not match previous versions - _hVer->Fill(1.0); + _hVer->Fill(2.0); for (auto const& mc : coll) { if (mc.match_.isNull() || !mc.match_.isAvailable()) continue; @@ -44,7 +50,8 @@ int mu2e::ValTrkCrvMatchMC::fill(const mu2e::TrkCrvMatchMCCollection& coll, art: int b = _axis.bin(xm.sid_); if (xm.geom_) { _hTrueXing->Fill(b); - if (xm.recoXing_ >= 0) _hTrueXingFound->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 (xm.trueCluster_ < 0) continue; _hTrueClu->Fill(b); @@ -57,14 +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_); - _hRecoXing->Fill(b); + bool proj = !rx.inBounds_; + (proj ? _hRecoXingProj : _hRecoXing)->Fill(b); int t = mc.recoXingTruth_[ir]; if (t < 0 || static_cast(t) >= mc.xings_.size()) continue; - _hRecoXingTrue->Fill(b); + (proj ? _hRecoXingProjTrue : _hRecoXingTrue)->Fill(b); auto const& xm = mc.xings_[t]; if (!xm.geom_ || xm.rel_ != MCRelationship::same) continue; - _hXingDist->Fill(b, std::sqrt((rx.pos_ - xm.pos_).Mag2())); - _hXingDt->Fill(b, rx.time_ - xm.time_); + (proj ? _hXingDistProj : _hXingDist)->Fill(b, std::sqrt((rx.pos_ - xm.pos_).Mag2())); + if (!proj) _hXingDt->Fill(b, rx.time_ - xm.time_); } } return 0;