From 79e3e9a036eb8a57fb807ff4f63134c88f0c0ad5 Mon Sep 17 00:00:00 2001
From: Alvaro Tolosa Delgado <alvaro.tolosa.delgado@cern.ch>
Date: Mon, 18 Mar 2024 08:45:36 +0100
Subject: [PATCH] It turns out that GetNegativeEndZ may be <0, leading to
 undefined behaviour when the value is used as 'half-length' replacing
 GetNegativeEndZ by GetPositiveEndZ fixes the problem because GetPositiveEndZ
 is the user value that corresponds to half-length

---
 DDG4/src/Geant4ShapeConverter.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/DDG4/src/Geant4ShapeConverter.cpp b/DDG4/src/Geant4ShapeConverter.cpp
index 81e871474..0023c3d7d 100644
--- a/DDG4/src/Geant4ShapeConverter.cpp
+++ b/DDG4/src/Geant4ShapeConverter.cpp
@@ -109,7 +109,7 @@ namespace dd4hep {
       if ( std::fabs(std::fabs(sh->GetNegativeEndZ()) - std::fabs(sh->GetPositiveEndZ())) < 1e-10 )   {
         return new G4TwistedTubs(sh->GetName(),sh->GetPhiTwist() * DEGREE_2_RAD,
                                  sh->GetRmin() * CM_2_MM, sh->GetRmax() * CM_2_MM,
-                                 sh->GetNegativeEndZ() * CM_2_MM,
+                                 sh->GetPositiveEndZ() * CM_2_MM,
                                  sh->GetNsegments(),
                                  (sh->GetPhi2()-sh->GetPhi1()) * DEGREE_2_RAD);
       }
-- 
GitLab