Parse multipole field parameters through getG4Number to honor units#155
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
get_field_parameter_doubleused barestd::stod, which silently truncates unit expressions:stod("30*deg")returns30.0and drops*deg. So multipole/dipole parameters written the documented way (vx/vy/vzas"10*cm",rotation_angleas"30*deg",strengthas"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_stepingfield_options.ccalready uses it).get_field_parameter_intstays onstoi: its only consumer ispole_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