Skip to content

Parse multipole field parameters through getG4Number to honor units#155

Merged
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/107-field-unit-parsing
Jun 13, 2026
Merged

Parse multipole field parameters through getG4Number to honor units#155
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/107-field-unit-parsing

Conversation

@zhaozhiwen

Copy link
Copy Markdown
Collaborator

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.

Validation: the multipole field plugin (gfield_multipoles.cc, the consumer) compiles clean against the new accessor (Geant4 11.4.1 dev container).

Fixes #107

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 gemc#107

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maureeungaro maureeungaro merged commit 9ff0868 into gemc:main Jun 13, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[High] Multipole field parameters bypass unit parsing (stod/stoi ignore unit expressions)

2 participants