Problem 2253

Summary: EXC_ARITHMETIC thrown from G4Exp in G4HadronElastic Physics
Product: Geant4 Reporter: Laurie Nevay <laurie.nevay>
Component: processes/hadronicAssignee: Vladimir.Ivantchenko
Status: RESOLVED FIXED    
Severity: major    
Priority: P4    
Version: 10.6   
Hardware: Apple   
OS: Mac OS X   
Attachments: zip of 6 screenshots of debugger showing memory frames, code and values

Description Laurie Nevay 2020-06-24 19:56:27 CEST
Created attachment 627 [details]
zip of 6 screenshots of debugger showing memory frames, code and values

Hello,

Using Geant4.10.6.p01, Mac OSX 10.14.6, Apple LLVM version 10.0.1 (clang-1001.0.46.4).  Also with GCC 8.3.1 on SLC7

My program crashes due to too big a number being put into a int32_t in the function fpfloor in G4Exp.hh.  The exception is EXC_ARITHMETIC (code=EXC_I386_SSEEXTERR, subcode=0x1933).

I'm using a modular physics list composed of

G4HadronicPhysicsFTFP_BERT, G4EmStandardPhysics, G4HadronElasticPhysics, G4DecayPhysics G4IonPhysics, G4IonElasticPhysics + EMD process for generic ions.

I'm using an LHC-energy Pb ion (6.37TeV*82 = 522.3TeV) onto porous graphite, copper and tungsten (the LHC collimators). Eventually my program will crash and the trace back shows it in G4HadronElastic::SampleInvariantT.  It tends to happen with a light fragment (H, Deuterium etc) with a high energy (here 16TeV) when interacting with Tungsten.  I'm attaching some screenshots of lldb (in CLion for debugging with the Maintainer build).  Such light high energy fragments are really common for this application and I see this crash within 500 events with a variety of seeds.

G4Exp is called with a really large negative value, but the Geant4 implementation results in the error.  Conceptually, the answer should be 0 or extremely close to it.

I tried modifying this in G4Exp but this affected a lot of things (perhaps unsurprisingly) and my attempt didn't work (rounding to 0 for extremely large negative arguments).

Do you have any suggestions how we can fix this or get around it?  Could I just return std::exp(x)? Presumably some small speed penalty but this would be ok if it would work.

I believe I can't catch or deal with this exception on my program side, so I think it needs to be fixed on the Geant4 side.

Many thanks,
Laurie Nevay
Comment 1 Vladimir.Ivantchenko 2020-07-20 16:58:51 CEST
Hello Laurie,

your analysis is correct. In a short turn usage of std::exp may be a solution. Thank you for the screenshots, I will try to add a protection to remove the issue.

Vladimir
Comment 2 Vladimir.Ivantchenko 2020-07-27 16:55:11 CEST
Hello,

the fix is merged to the development branch of Geant4 and will be available with the next release and/or patch. In a mean time, I can send the fix privately, please, let me know.

Vladimir
Comment 3 Laurie Nevay 2020-12-15 14:24:26 CET
Hello,

Could you explain the fix to me or point me to the difference please? I ask because I'm looking at which of my 10.6 patches I should apply to my new 10.7 build and I only see whitespace changes in G4Exp.hh.

Many thanks,
Laurie