From 7fddfa220d9b9b7c2156d083240ae711ca511326 Mon Sep 17 00:00:00 2001 From: Zhiwen Zhao Date: Fri, 12 Jun 2026 23:40:17 -0400 Subject: [PATCH] Parse multipole field parameters through getG4Number to honor units MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit get_field_parameter_double used bare std::stod, which silently truncates unit expressions: stod("30*deg") returns 30.0 and drops "*deg". So multipole/dipole parameters written the documented way (vx/vy/vz as "10*cm", rotation_angle as "30*deg", strength as "2*tesla") were interpreted in raw internal units, producing fields with the wrong magnitude, position, and rotation — silently, with no error. Route the double accessor through gutilities::getG4Number, which parses unit expressions (minimum_step in gfield_options.cc already uses it). get_field_parameter_int stays on stoi: its only consumer is pole_number, a unitless count. Fixes #107 Co-Authored-By: Claude Fable 5 --- gemc/gfields/gfield.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gemc/gfields/gfield.h b/gemc/gfields/gfield.h index a16f11c7..d8fe85e9 100644 --- a/gemc/gfields/gfield.h +++ b/gemc/gfields/gfield.h @@ -7,6 +7,7 @@ // gemc #include #include +#include constexpr const char* GFIELD_LOGGER = "gfield"; @@ -148,7 +149,7 @@ class GField : public GBase, public G4MagneticField { * \param key Map key to retrieve. * \return Parsed floating-point value. */ - double get_field_parameter_double(const std::string& key) { return stod(gfield_definitions.field_parameters[key]); } + double get_field_parameter_double(const std::string& key) { return gutilities::getG4Number(gfield_definitions.field_parameters[key]); } /** * \brief Hook for configuring module loggers from options.