Problem 1921 - G4UIcommand.cc double to string rounds to typically 7 digits
Summary: G4UIcommand.cc double to string rounds to typically 7 digits
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: intercoms (show other problems)
Version: 10.2
Hardware: All All
: P4 normal
Assignee: asai
URL:
: 2070 2155 (view as problem list)
Depends on:
Blocks:
 
Reported: 2016-11-28 11:58 CET by Helmut.Burkhardt
Modified: 2019-03-28 11:10 CET (History)
2 users (show)

See Also:


Attachments
Modified G4UIcommand.cc using std::setprecision(17) for double to string (32.31 KB, text/plain)
2016-11-28 11:58 CET, Helmut.Burkhardt
Details

Note You need to log in before you can comment on or make changes to this problem.
Description Helmut.Burkhardt 2016-11-28 11:58:09 CET
Created attachment 430 [details]
Modified G4UIcommand.cc using std::setprecision(17) for double to string

Background applications on large accelerators require high accuracy in geometry, like micrometers in kilometres or over 9 significant digits. I was surprised to see that gun positions and energies are reduced to typically 7 digits.

Traced to
G4UIcommand.cc
os << doubleValue; 
using default precision or less than float.

Seen in 4 places in G4UIcommand.cc

G4String G4UIcommand::ConvertToString(G4double doubleValue)
G4String G4UIcommand::ConvertToString(G4double doubleValue,const char* unitName)
G4String G4UIcommand::ConvertToString(G4ThreeVector vec)
G4String G4UIcommand::ConvertToString(G4ThreeVector vec,const char* unitName)

Proposed fix is to replace
"os << “ 
  by 
"os << std::setprecision(17) <<“ 
to avoid any loss in double precision.

Worked for me to get precise gun values - modified file attached.

Maybe be good to check also in other places where ostringstream is used.

Best regards,
   Helmut
Comment 1 asai 2016-11-29 00:25:08 CET
Thank you for reporting the issue. We will fix it very soon, but the fix won't go with version 10.3 scheduled on this coming Friday. It will go with the next patch release, and we will also make a retroactive patch for 10.2.
Kind regards,
Makoto Asai
Comment 2 asai 2017-02-10 12:03:53 CET
The fix is included in the coming patch. Please note that this double precision printout is implemented as an option, and you need to issue a UI command "/control/useDoublePrecision". Thanks for reporting this issue.
Makoto
Comment 3 asai 2018-07-27 04:04:18 CEST
*** Problem 2070 has been marked as a duplicate of this problem. ***
Comment 4 asai 2019-03-28 11:10:42 CET
*** Problem 2155 has been marked as a duplicate of this problem. ***