When declaring a G4GenericMessenger command with DeclareMethodWithUnit or DeclarePropertyWithUnit (but not when using DeclareMethod or DeclareProperty) based on a G4double Property or Method taking a G4double, the command still cuts off the input to the length of a float. This causes loss of precision on input parameters, but more importantly causes differences between simulations runs with default parameters set in code and those same default parameters set in macros. An example is provided (based on standard example B1 in 4.10.04) at https://github.com/wdconinc/geant4-messenger-double-precision. Steps to reproduce (including showing diff of added code): 1. git clone https://github.com/wdconinc/geant4-messenger-double-precision 2. cd geant4-messenger-double-precision 3. git diff 2a1af5fa668b36b3bd4de8b8512f805abe349874..HEAD 4. mkdir build && pushd build && cmake .. && make && popd 5. build/exampleB1 run3.mac Expected results: - The output *after* each 'set' operation should have the number of digits for double precision (i.e. 8) instead of for float precision (i.e. 5). Actual results: - The following output is generated (line numbers added): 1: before_/B1/setPU_100_deg: 1.74532925 2: after_/B1/setPU_100_deg: 1.74533 3: before_/B1/setP_1.12345678901234567890: 1.74533 4: after_/B1/setP_1.12345678901234567890: 1.12345679 5: before_/B1/setMU_100_deg: 1.12345679 6: after_/B1/setMU_100_deg: 1.74533 7: before_/B1/setM_1.12345678901234567890: 1.74533 8: after_/B1/setM_1.12345678901234567890: 1.12345679 - Setting the parameter as PropertyWithUnit returns float (line 2). - Setting the parameter as MethodWithUnit returns float (line 6). Workarounds: - None known.
Downstream report: https://github.com/JeffersonLab/remoll/issues/130
Thank you for reporting the issue. This has been addressed and the fix has been released with version 10.3-p01 (10.4 also has this fix). Please use /control/useDoublePrecision command. Regards, Makoto *** This problem has been marked as a duplicate of problem 1921 ***
I can confirm that adding /control/useDoublePrecision or G4UImanager::UseDoublePrecisionStr(true) does indeed solve this problem. However, I want to note that problem 1921 was referring to output streams while this problem is referring to input. Arguably, truncating input is a more significant issue.
I understand your concern, but G4UIcmdWithADoubleAndUnit class actually uses the same strstream conversion mechanism. Thus, this same control command could solve the issue.