Problem 2070 - G4GenericMessenger::DeclareMethodWithUnit on G4double truncates input to float
Summary: G4GenericMessenger::DeclareMethodWithUnit on G4double truncates input to float
Status: RESOLVED DUPLICATE of problem 1921
Alias: None
Product: Geant4
Classification: Unclassified
Component: intercoms (show other problems)
Version: 10.4
Hardware: All Linux
: P4 minor
Assignee: asai
URL:
Depends on:
Blocks:
 
Reported: 2018-07-26 20:27 CEST by Wouter Deconinck
Modified: 2018-07-27 05:53 CEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description Wouter Deconinck 2018-07-26 20:27:38 CEST
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.
Comment 1 Wouter Deconinck 2018-07-26 20:30:39 CEST
Downstream report: https://github.com/JeffersonLab/remoll/issues/130
Comment 2 asai 2018-07-27 04:04:18 CEST
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 ***
Comment 3 Wouter Deconinck 2018-07-27 05:46:35 CEST
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.
Comment 4 asai 2018-07-27 05:53:59 CEST
I understand your concern, but G4UIcmdWithADoubleAndUnit class actually uses the same strstream conversion mechanism. Thus, this same control command could solve the issue.