Skip to content

Commit 7fddfa2

Browse files
zhaozhiwenclaude
andcommitted
Parse multipole field parameters through getG4Number to honor units
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 <noreply@anthropic.com>
1 parent 48f83e5 commit 7fddfa2

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

gemc/gfields/gfield.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// gemc
88
#include <gemc/gfactory/gfactory.h>
99
#include <gemc/gbase/gbase.h>
10+
#include <gemc/guts/gutilities.h>
1011

1112

1213
constexpr const char* GFIELD_LOGGER = "gfield";
@@ -148,7 +149,7 @@ class GField : public GBase<GField>, public G4MagneticField {
148149
* \param key Map key to retrieve.
149150
* \return Parsed floating-point value.
150151
*/
151-
double get_field_parameter_double(const std::string& key) { return stod(gfield_definitions.field_parameters[key]); }
152+
double get_field_parameter_double(const std::string& key) { return gutilities::getG4Number(gfield_definitions.field_parameters[key]); }
152153

153154
/**
154155
* \brief Hook for configuring module loggers from options.

0 commit comments

Comments
 (0)