From f817f0618e6c70b2814b12b6fbd461b16919cdd5 Mon Sep 17 00:00:00 2001
From: Wouter Deconinck <wdconinc@gmail.com>
Date: Wed, 10 Nov 2021 00:21:41 +0000
Subject: [PATCH] Avoid nan momentum in low energy neutrals with energy < mass

---
 JugFast/src/components/MatchClusters.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/JugFast/src/components/MatchClusters.cpp b/JugFast/src/components/MatchClusters.cpp
index 9f1b9943..ee48e6e5 100644
--- a/JugFast/src/components/MatchClusters.cpp
+++ b/JugFast/src/components/MatchClusters.cpp
@@ -203,7 +203,7 @@ private:
                                                  const eic::ConstCluster* optional_hclus, const double mass,
                                                  const int32_t pid, const eic::Index& newID) const {
     const float energy   = (optional_hclus) ? eclus.energy() + optional_hclus->energy() : eclus.energy();
-    const float momentum = sqrt(energy * energy - mass * mass);
+    const float momentum = energy < mass ? 0 : std::hypot(energy, mass);
     const eic::VectorPolar p{momentum, eclus.position().theta(), eclus.position().phi()};
     // setup our particle
     eic::ReconstructedParticle part;
-- 
GitLab