From 18a24eeef753a82c0c5358974864226789aacdac Mon Sep 17 00:00:00 2001 From: Rob Mina Date: Fri, 6 Nov 2026 13:43:45 -0600 Subject: [PATCH 1/2] Truncate trajectory for ranged-out particles. --- Mu2eKinKal/inc/KKExtrap.hh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Mu2eKinKal/inc/KKExtrap.hh b/Mu2eKinKal/inc/KKExtrap.hh index db70ad6451..738a1a0880 100644 --- a/Mu2eKinKal/inc/KKExtrap.hh +++ b/Mu2eKinKal/inc/KKExtrap.hh @@ -121,10 +121,12 @@ namespace mu2e { ktrk.addExtrapolationFailure(failure); } - // The particle stops in this material: the forwards direction ends before it, keeping the crossings already added. + // The particle stops in this material: the forwards direction and the trajectory end at the crossing, keeping the crossings already added. template bool KKExtrap::rangeOut(KKTrack& ktrk, SweepTarget const& tg, KinKal::Intersection const& inter) const { if(debug_ > 0) std::cout << "KKExtrap: ranged out in " << tg.sid_ << " at " << inter.time_ << std::endl; ktrk.setRangedOut(); + // the extension can run domains past the crossing; KinKal removes them, and refuses the cut if an active hit or material lies beyond it + if(!ktrk.truncate(TimeDir::forwards,inter.time_) && debug_ > 0) std::cout << "KKExtrap: trajectory not truncated at " << inter.time_ << std::endl; return false; } From 609ff61ec12d7997f77d99c783de59a4d5ea0ef2 Mon Sep 17 00:00:00 2001 From: Rob Mina Date: Tue, 17 Nov 2026 06:52:22 -0600 Subject: [PATCH 2/2] Address review comments, bump envset. --- .muse | 2 +- Mu2eKinKal/inc/ExtrapolateSweep.hh | 2 ++ Mu2eKinKal/inc/KKExtrap.hh | 20 ++++++++++++++++++-- Mu2eKinKal/src/CentralHelixFit_module.cc | 5 +++++ Mu2eKinKal/src/KKTruthSeed_module.cc | 5 +++++ Mu2eKinKal/src/KinematicLineFit_module.cc | 5 +++++ Mu2eKinKal/src/LoopHelixFit_module.cc | 1 + Mu2eKinKal/src/RegrowKinematicLine_module.cc | 4 +++- Mu2eKinKal/src/RegrowLoopHelix_module.cc | 4 +++- 9 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.muse b/.muse index e8900473aa..13380aa2a8 100644 --- a/.muse +++ b/.muse @@ -1,5 +1,5 @@ # prefer to build with this environment -ENVSET p110 +ENVSET p111 # add Offline/bin to path PATH bin # recent commits can take enforce these flags diff --git a/Mu2eKinKal/inc/ExtrapolateSweep.hh b/Mu2eKinKal/inc/ExtrapolateSweep.hh index eba667c8e7..3089821941 100644 --- a/Mu2eKinKal/inc/ExtrapolateSweep.hh +++ b/Mu2eKinKal/inc/ExtrapolateSweep.hh @@ -10,6 +10,8 @@ // - 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). // - 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. // Adding a material target: see KKExtrap::targets and KKExtrap::addCrossing. #ifndef Mu2eKinKal_ExtrapolateSweep_hh #define Mu2eKinKal_ExtrapolateSweep_hh diff --git a/Mu2eKinKal/inc/KKExtrap.hh b/Mu2eKinKal/inc/KKExtrap.hh index ea545fbba9..4f058457c9 100644 --- a/Mu2eKinKal/inc/KKExtrap.hh +++ b/Mu2eKinKal/inc/KKExtrap.hh @@ -16,6 +16,7 @@ #include "Offline/GeometryService/inc/GeometryService.hh" #include #include +#include #include #include #include @@ -42,6 +43,8 @@ namespace mu2e { // and, for a new Effect, a case in addCrossing that builds its KinKal material xing; a surface that is neither a Plane nor a Cylinder is searched with KinKal::intersect // and is never cut by withinReach; add a case to ExtrapolateSweepTest and, if optional, a KKExtrapConfig switch. SweepTargetCollection targets(bool updir) const; + // end of job: how many tracks ranged out, and in how many KinKal refused to truncate the trajectory at the stop + void printSummary(std::string const& label) const; private: // where a track entered a calorimeter crystal case inner support: the material still to cross at the carbon fiber ring inner radius struct SupportEntry { double path_ = 0.0; KKGeom::CaloInnerSupport::Crossing xing_ = KKGeom::CaloInnerSupport::cfRing; double time_ = 0.0; }; @@ -54,6 +57,7 @@ namespace mu2e { TimeDir tdir, SupportEntries& entries) const; template bool reflect(ExtrapolateSweep& xs, KinKal::ParticleTrajectory const& ftraj, TimeDir tdir) const; int debug_; + mutable std::atomic nRangedOut_{0}, nNotTruncated_{0}; // counted in rangeOut, reported by printSummary double btol_, intertol_, maxdt_, maxdtstep_, minv_; bool backToTracker_, extrapolateOPA_, toTrackerPerimeter_, upstream_, toCRV_; bool toCaloD0_, toCaloD1_, toCaloMaterial_; @@ -125,11 +129,23 @@ namespace mu2e { template bool KKExtrap::rangeOut(KKTrack& ktrk, SweepTarget const& tg, KinKal::Intersection const& inter) const { if(debug_ > 0) std::cout << "KKExtrap: ranged out in " << tg.sid_ << " at " << inter.time_ << std::endl; ktrk.setRangedOut(); - // the extension can run domains past the crossing; KinKal removes them, and refuses the cut if an active hit or material lies beyond it - if(!ktrk.truncate(TimeDir::forwards,inter.time_) && debug_ > 0) std::cout << "KKExtrap: trajectory not truncated at " << inter.time_ << std::endl; + ++nRangedOut_; + // the extension can run domains past the crossing; KinKal removes them, and refuses the cut if an active hit or material lies beyond it. + // A refused cut keeps the trajectory past the stop, so it is counted and reported at the end of the job (printSummary). + // KinKal currently also refuses for material sites the fit never processed (KFTrack/KinKal#234 review): if a later KinKal + // release stops doing that, the refused count should fall to zero and this check can be revisited + if(!ktrk.truncate(TimeDir::forwards,inter.time_)){ + ++nNotTruncated_; + if(debug_ > 0) std::cout << "KKExtrap: trajectory not truncated at " << inter.time_ << std::endl; + } return false; } + inline void KKExtrap::printSummary(std::string const& label) const { + if(nRangedOut_ > 0) std::cout << "KKExtrap " << label << ": " << nRangedOut_ << " tracks ranged out, " << nNotTruncated_ + << " of them not truncated at the stop (KinKal refused the cut)" << std::endl; + } + inline SweepTargetCollection KKExtrap::targets(bool updir) const { GeomHandle kkg_h; GeomHandle kkmat_h; diff --git a/Mu2eKinKal/src/CentralHelixFit_module.cc b/Mu2eKinKal/src/CentralHelixFit_module.cc index 11e4fb51a2..b4c9743575 100644 --- a/Mu2eKinKal/src/CentralHelixFit_module.cc +++ b/Mu2eKinKal/src/CentralHelixFit_module.cc @@ -143,6 +143,7 @@ namespace mu2e { virtual ~CentralHelixFit() {} void beginRun(art::Run& run) override; void produce(art::Event& event) override; + void endJob() override; protected: bool goodFit(KKTRK const& ktrk) const; void sampleFit(KKTRK& ktrk) const; @@ -260,6 +261,10 @@ namespace mu2e { kkg.surfaces(ssids_,surfacess_to_sample_); } + void CentralHelixFit::endJob() { + if(extrap_) extrap_->printSummary(moduleDescription().moduleLabel()); + } + void CentralHelixFit::produce(art::Event& event ) { GeomHandle calo_h; GeomHandle nominalTracker_h; diff --git a/Mu2eKinKal/src/KKTruthSeed_module.cc b/Mu2eKinKal/src/KKTruthSeed_module.cc index f5da3624cb..f4b2287953 100644 --- a/Mu2eKinKal/src/KKTruthSeed_module.cc +++ b/Mu2eKinKal/src/KKTruthSeed_module.cc @@ -97,6 +97,7 @@ namespace mu2e { explicit KKTruthSeed(const Parameters& settings); void beginRun(art::Run& run) override; void produce(art::Event& event) override; + void endJob() override; private: // true muon state (pos, mom, time) from the MC trajectory point nearest a detector-frame location. @@ -334,6 +335,10 @@ namespace mu2e { return tsseed; } + void KKTruthSeed::endJob() { + if(extrap_) extrap_->printSummary(moduleDescription().moduleLabel()); + } + void KKTruthSeed::produce(art::Event& event) { GeomHandle calo_h; GeomHandle nominalTracker_h; diff --git a/Mu2eKinKal/src/KinematicLineFit_module.cc b/Mu2eKinKal/src/KinematicLineFit_module.cc index 1ecc83e40c..1057526b56 100644 --- a/Mu2eKinKal/src/KinematicLineFit_module.cc +++ b/Mu2eKinKal/src/KinematicLineFit_module.cc @@ -138,6 +138,7 @@ namespace mu2e { virtual ~KinematicLineFit(); void beginRun(art::Run& run) override; void produce(art::Event& event) override; + void endJob() override; private: // utility functions KTRAJ makeSeedTraj(CosmicTrackSeed const& hseed) const; @@ -240,6 +241,10 @@ namespace mu2e { kkg_h->surfaces(ssids_,surfacess_to_sample_); } + void KinematicLineFit::endJob() { + if(extrap_) extrap_->printSummary(moduleDescription().moduleLabel()); + } + void KinematicLineFit::produce(art::Event& event ) { GeomHandle calo_h; GeomHandle nominalTracker_h; diff --git a/Mu2eKinKal/src/LoopHelixFit_module.cc b/Mu2eKinKal/src/LoopHelixFit_module.cc index 94249e6cb3..1566c9dfb6 100644 --- a/Mu2eKinKal/src/LoopHelixFit_module.cc +++ b/Mu2eKinKal/src/LoopHelixFit_module.cc @@ -548,6 +548,7 @@ namespace mu2e { } void LoopHelixFit::endJob() { + if(extrap_) extrap_->printSummary(moduleDescription().moduleLabel()); if(print_ > 0) { printf("[LoopHelixFit::%s::%s] Saw %i helix seeds, %i had ambiguous dz/dt slopes, accepted %i downstream and %i upstream fits\n", __func__, moduleDescription().moduleLabel().c_str(), nSeen_, nAmbiguous_, nDownstream_, nUpstream_); diff --git a/Mu2eKinKal/src/RegrowKinematicLine_module.cc b/Mu2eKinKal/src/RegrowKinematicLine_module.cc index f50de269fd..ddd7ea02a9 100644 --- a/Mu2eKinKal/src/RegrowKinematicLine_module.cc +++ b/Mu2eKinKal/src/RegrowKinematicLine_module.cc @@ -279,7 +279,9 @@ namespace mu2e { } void RegrowKinematicLine::endJob() - {} + { + if(extrap_) extrap_->printSummary(moduleDescription().moduleLabel()); + } } DEFINE_ART_MODULE(mu2e::RegrowKinematicLine) diff --git a/Mu2eKinKal/src/RegrowLoopHelix_module.cc b/Mu2eKinKal/src/RegrowLoopHelix_module.cc index 9276be7b9c..0ec542d741 100644 --- a/Mu2eKinKal/src/RegrowLoopHelix_module.cc +++ b/Mu2eKinKal/src/RegrowLoopHelix_module.cc @@ -360,7 +360,9 @@ namespace mu2e { } void RegrowLoopHelix::endJob() - {} + { + if(extrap_) extrap_->printSummary(moduleDescription().moduleLabel()); + } } DEFINE_ART_MODULE(mu2e::RegrowLoopHelix)