Problem 1676 - NaN direction generated, which causes Infinite Loop in G4SubtractionSolid::DistanceToIn()
Summary: NaN direction generated, which causes Infinite Loop in G4SubtractionSolid::Di...
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: processes (show other problems)
Version: 10.0
Hardware: PC Linux
: P5 normal
Assignee: Marc.Verderi
URL:
Depends on:
Blocks:
 
Reported: 2014-09-16 10:47 CEST by smueller
Modified: 2016-05-17 18:43 CEST (History)
1 user (show)

See Also:


Attachments
Application reproducing the problem (37.97 KB, application/x-gzip)
2014-09-16 12:11 CEST, Gabriele Cosmo
Details

Note You need to log in before you can comment on or make changes to this problem.
Description smueller 2014-09-16 10:47:37 CEST
When running my application, after some time an event configuration is reached which provokes an infinite loop in  G4SubtractionSolid::DistanceToIn(p,v).

The message I get is the following:

-----------------------------------------------------------
    *** Dump for Boolean solid - rB48 ***
    ===================================================
 Solid type: G4SubtractionSolid
 Parameters of constituent solids:
===========================================================
-----------------------------------------------------------
    *** Dump for solid - B48 ***
    ===================================================
 Solid type: G4Box
 Parameters:
    half length X: 569 mm
    half length Y: 2000 mm
    half length Z: 1828.8 mm
-----------------------------------------------------------
-----------------------------------------------------------
    *** Dump for Displaced solid - placedB ***
    ===================================================
 Solid type: G4DisplacedSolid
 Parameters of constituent solid:
===========================================================
-----------------------------------------------------------
    *** Dump for solid - B43s ***
    ===================================================
 Solid type: G4Box
 Parameters:
    half length X: 300 mm
    half length Y: 2050 mm
    half length Z: 10.325 mm
-----------------------------------------------------------
===========================================================
 Transformations:
    Direct transformation - translation :
           (300,0,-1249.475)
                          - rotation    :

   [ (           1             0             0)
     (           0             1             0)
     (           0             0             1) ]

===========================================================
===========================================================

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : GeomSolids1001
      issued by : G4SubtractionSolid::DistanceToIn(p,v)
Illegal condition caused by solids: B48 and B43s
Looping detected in point (nan,nan,nan), from original point (nan,nan,nan) and direction (0.7903103663410459,-0.4908280694712698,0.3667387777055873)
Computed candidate distance: 0*mm. Returning candidate distance.

*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Upon further investigation, I realize that the (nan,nan,nan) coordinates appear in the post-step information of the first step of a secondary electron:

*********************************************************************************************************
* G4Track Information:   Particle = e-,   Track ID = 5115,   Parent ID = 5082
*********************************************************************************************************

Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
    0     -391      959 1.12e+03      1.03        0        0         0     CONC153 initStep

 >>AlongStepDoIt (after all invocations):
    ++List of invoked processes 
      1) CoupledTransportation
      2) mesh_DD 
      3) mesh_DC 
      4) mesh_DB 
      5) mesh_DA 
      6) mesh_FD 
      7) mesh_FC 
      8) mesh_FB 
      9) mesh_FA 
      10) msc 
      11) eIoni

    ++G4Step Information 
      Address of G4Track    : 0x4362080
      Step Length (mm)      : 0.1535850668493046
      Energy Deposit (MeV)  : 0.05150576776319787
      -----------------------------------------------------------------------
        StepPoint Information               PreStep            PostStep
      -----------------------------------------------------------------------
         Position - x (mm)   :     -390.78879935867                 nan     
         Position - y (mm)   :    959.2433323881514                 nan     
         Position - z (mm)   :    1121.774141621281                 nan     
         Global Time (ns)    :    6.744509893198652   6.745031399582996
         Local Time (ns)     :                    00.0005215063843444881
         Proper Time (ns)    :                    00.0001730161971133884
         Momentum Direct - x :                  nan  0.1578428848227827
         Momentum Direct - y :                  nan -0.1633103342387628
         Momentum Direct - z :                  nan  0.9738661912406885
         Momentum - x (MeV/c):                  nan  0.2207124824514427
         Momentum - y (MeV/c):                  nan -0.2283576438702391
         Momentum - z (MeV/c):                  nan   1.361761886736875
         Total Energy (MeV)  :    1.540255758733544   1.488749990970346
         Kinetic Energy (MeV):    1.029256848733544  0.9777510809703462
         Velocity (mm/ns)    :    282.8068863977833   281.5758396087471
         Volume Name         :              CONC153             CONC153 
         Safety (mm)         :                    0   40.60918201505554
         Polarization - x    :                    0                   0       
         Polarization - y    :                    0                   0       
         Polarization - Z    :                    0                   0       
         Weight              : 3.041403825178903e-093.041403825178903e-09
         Step Status         :            Undefined       PostStep Proc
         Process defined Step:            Undefined               eBrem   
      -----------------------------------------------------------------------

    ++List of secondaries generated (x,y,z,kE,t,PID):  No. of secodaries = 0

 **PostStepDoIt (after all invocations):
    ++List of invoked processes 
      1) CoupledTransportation
      2) msc
      3) eBrem (Forced)

    ++G4Step Information
      Address of G4Track    : 0x4362080
      Step Length (mm)      : 0.1535850668493046
      Energy Deposit (MeV)  : 0.05150576776319787
      -----------------------------------------------------------------------
        StepPoint Information               PreStep            PostStep
      -----------------------------------------------------------------------
         Position - x (mm)   :     -390.78879935867                 nan
         Position - y (mm)   :    959.2433323881514                 nan
         Position - z (mm)   :    1121.774141621281                 nan
         Global Time (ns)    :    6.744509893198652   6.745031399582996
         Local Time (ns)     :                    00.0005215063843444881
         Proper Time (ns)    :                    00.0001730161971133884
         Momentum Direct - x :                  nan  0.1552205293158106
         Momentum Direct - y :                  nan -0.1618184922652031
         Momentum Direct - z :                  nan  0.9745364861512041
         Momentum - x (MeV/c):                  nan  0.2161837537753424
         Momentum - y (MeV/c):                  nan -0.2253730820424056
         Momentum - z (MeV/c):                  nan    1.35728796117267
         Total Energy (MeV)  :    1.540255758733544   1.483535957458107
         Kinetic Energy (MeV):    1.029256848733544  0.9725370474581072
         Velocity (mm/ns)    :    282.8068863977833    281.441110846168
         Volume Name         :              CONC153             CONC153
         Safety (mm)         :                    0                 nan
         Polarization - x    :                    0                   0
         Polarization - y    :                    0                   0
         Polarization - Z    :                    0                   0
         Weight              : 3.041403825178903e-093.041403825178903e-09
         Step Status         :            Undefined       PostStep Proc
         Process defined Step:            Undefined               eBrem
      -----------------------------------------------------------------------

    ++List of secondaries generated (x,y,z,kE,t,PID):  No. of secodaries = 1
      [Note]Secondaries from AlongStepDoIt included.
            nan       nan       nan 0.005214033512239045 6.745031399582996              gamma

#Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
    1      nan      nan      nan     0.973   0.0515    0.154     0.154     CONC153 eBrem

 >>AlongStepDoIt (after all invocations):
    ++List of invoked processes
      1) CoupledTransportation
      2) mesh_DD
      3) mesh_DC
      4) mesh_DB
      5) mesh_DA
      6) mesh_FD
      7) mesh_FC
      8) mesh_FB
      9) mesh_FA
      10) msc
      11) eIoni

    ++G4Step Information
      Address of G4Track    : 0x4362080
      Step Length (mm)      : 0
      Energy Deposit (MeV)  : 0
      -----------------------------------------------------------------------
        StepPoint Information               PreStep            PostStep
      -----------------------------------------------------------------------
         Position - x (mm)   :                  nan                 nan
         Position - y (mm)   :                  nan                 nan
         Position - z (mm)   :                  nan                 nan
         Global Time (ns)    :    6.745031399582996   6.745031399582996
         Local Time (ns)     : 0.00052150638434448810.0005215063843444881
         Proper Time (ns)    : 0.00017301619711338840.0001730161971133884
         Momentum Direct - x :   0.1552205293158106  0.1552205293158106
         Momentum Direct - y :  -0.1618184922652031 -0.1618184922652031
         Momentum Direct - z :   0.9745364861512041  0.9745364861512041
         Momentum - x (MeV/c):   0.2161837537753424  0.2161837537753424
         Momentum - y (MeV/c):  -0.2253730820424056 -0.2253730820424056
         Momentum - z (MeV/c):     1.35728796117267    1.35728796117267
         Total Energy (MeV)  :    1.483535957458107   1.483535957458107
         Kinetic Energy (MeV):   0.9725370474581072  0.9725370474581072
         Velocity (mm/ns)    :     281.441110846168    281.441110846168
         Volume Name         :              CONC153             CONC153
         Safety (mm)         :                  nan               5e-10
         Polarization - x    :                    0                   0
         Polarization - y    :                    0                   0
         Polarization - Z    :                    0                   0
         Weight              : 3.041403825178903e-093.041403825178903e-09
         Step Status         :        PostStep Proc     AlongStep Proc.
         Process defined Step:                eBrem             mesh_FA
      -----------------------------------------------------------------------

    ++List of secondaries generated (x,y,z,kE,t,PID):  No. of secodaries = 1
            nan       nan       nan 0.005214033512239045 6.745031399582996              gamma

 **PostStepDoIt (after all invocations):
    ++List of invoked processes
      1) CoupledTransportation
      2) msc
      3) eIoni (Forced)

    ++G4Step Information
      Address of G4Track    : 0x4362080
      Step Length (mm)      : 0
      Energy Deposit (MeV)  : 0
      -----------------------------------------------------------------------
        StepPoint Information               PreStep            PostStep
      -----------------------------------------------------------------------
         Position - x (mm)   :                  nan                 nan
         Position - y (mm)   :                  nan                 nan
         Position - z (mm)   :                  nan                 nan
         Global Time (ns)    :    6.745031399582996   6.745031399582996
         Local Time (ns)     : 0.00052150638434448810.0005215063843444881
         Proper Time (ns)    : 0.00017301619711338840.0001730161971133884
         Momentum Direct - x :   0.1552205293158106  0.1552205293158106
         Momentum Direct - y :  -0.1618184922652031 -0.1618184922652031
         Momentum Direct - z :   0.9745364861512041  0.9745364861512041
         Momentum - x (MeV/c):   0.2161837537753424  0.2161837537753424
         Momentum - y (MeV/c):  -0.2253730820424056 -0.2253730820424056
         Momentum - z (MeV/c):     1.35728796117267    1.35728796117267
         Total Energy (MeV)  :    1.483535957458107   1.483535957458107
         Kinetic Energy (MeV):   0.9725370474581072  0.9725370474581072
         Velocity (mm/ns)    :     281.441110846168    281.441110846168
         Volume Name         :              CONC153          OutOfWorld
         Safety (mm)         :                  nan                 nan
         Polarization - x    :                    0                   0
         Polarization - y    :                    0                   0
         Polarization - Z    :                    0                   0
         Weight              : 3.041403825178903e-093.041403825178903e-09
         Step Status         :        PostStep Proc
         Process defined Step:                eBrem             mesh_FA
      -----------------------------------------------------------------------

    ++List of secondaries generated (x,y,z,kE,t,PID):  No. of secodaries = 1
      [Note]Secondaries from AlongStepDoIt included.
            nan       nan       nan 0.005214033512239045 6.745031399582996              gamma

#Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
    2      nan      nan      nan     0.973        0        0     0.154  OutOfWorld mesh_FA

The event then enters the infinite loop when processing the daughter gamma:

*********************************************************************************************************
* G4Track Information:   Particle = gamma,   Track ID = 5122,   Parent ID = 5115
*********************************************************************************************************

Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
    0      nan      nan      nan   0.00521        0        0         0       World initStep
-----------------------------------------------------------
    *** Dump for Boolean solid - rB48 ***
    ===================================================
 Solid type: G4SubtractionSolid
 Parameters of constituent solids:
===========================================================
-----------------------------------------------------------
    *** Dump for solid - B48 ***
    ===================================================
 Solid type: G4Box
 Parameters:
    half length X: 569 mm
    half length Y: 2000 mm
    half length Z: 1828.8 mm
-----------------------------------------------------------
-----------------------------------------------------------
    *** Dump for Displaced solid - placedB ***
    ===================================================
 Solid type: G4DisplacedSolid
 Parameters of constituent solid:
===========================================================
-----------------------------------------------------------
    *** Dump for solid - B43s ***
    ===================================================
 Solid type: G4Box
 Parameters:
    half length X: 300 mm
    half length Y: 2050 mm
    half length Z: 10.325 mm
-----------------------------------------------------------
===========================================================
 Transformations:
    Direct transformation - translation :
           (300,0,-1249.475)
                          - rotation    :

   [ (           1             0             0)
     (           0             1             0)
     (           0             0             1) ]

===========================================================
===========================================================

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : GeomSolids1001
      issued by : G4SubtractionSolid::DistanceToIn(p,v)
Illegal condition caused by solids: B48 and B43s
Looping detected in point (nan,nan,nan), from original point (nan,nan,nan) and direction (0.7903103663410459,-0.4908280694712698,0.3667387777055873)
Computed candidate distance: 0*mm. Returning candidate distance.

*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

I have checked the coordinates, the PreStep of the e- is inside the volume CONC153, nowhere near a border surface, and no connection to the bodies B48 and B43s mentioned in the Error message.


I don't understand what's going on here. At first I thought it had something to do with scoring, but later I found the same issues also when running without scoring.

In any case, it is very inconvenient that the error message in the infinite loop quickly makes logfiles explode!
Comment 1 Gabriele Cosmo 2014-09-16 10:55:13 CEST
Could you please provide a test case that we can look at to reproduce the problem? Thanks.
Comment 2 Gabriele Cosmo 2014-09-16 12:11:26 CEST
Created attachment 282 [details]
Application reproducing the problem

Dear Gabriele,

I have attached the code of my project. It goes immediately into an infinite loop on out UBUNTU-cluster if I run it with the "no_vis_infLoop.mac" macro.

Since I use 8 scoring grids, we had to increment the
static const G4int fMaxNav = 8;   // rename to kMaxNoNav ??

from 8 to 16 both in

source/geometry/navigation/include/G4MultiNavigator.hh

and

source/geometry/navigation/include/G4PathFinder.hh

when building GEANT4 on our cluster. I remember deactivating the scoring changed the event histories (why?) so I don't know if this particular event crashes also when turning off scoring. It might even be that on your machine, it doesn't enter the infinite loop at all (but maybe at a later event).

I do not have any experience with Valgrind, but it is installed on our cluster, so I could try to use it if this would become necessary.

Cheers,

	Stefan
Comment 3 John Apostolakis 2014-12-05 16:18:30 CET
It seems that this particle was generated with a (nan, nan, nan) momentum and that this is the reason that the solid is not able to give a sensible answer.
      
         Momentum Direct - x :                  nan 
         Momentum Direct - y :                  nan 
         Momentum Direct - z :                  nan 
         Momentum - x (MeV/c):                 nan
         Momentum - y (MeV/c):                  nan
         Momentum - z (MeV/c):                  nan 

As this particle is a primary, it seems to be the primary generator which is causing it to have this value of the momentum.

Could you please confirm that this is not the problem ?

In the meantime, I will try to check too.
Comment 4 smueller 2015-01-07 14:15:36 CET
Dear John,

no, the particle under question is not a primary particle. The primary particle
is simply an e- at 18 GeV emitted in +z-direction.

What I see is that at a certain point, one of the many (too many?) secondary
electrons created when the primary e- hits the beamdump aquires a (nan,nan,nan)
position in the first Post-Step process. Then at this position, it creates a
daughter photon.

The event then enters the infinite loop when processing the daughter gamma.

I see that version 4.10.1 just came out, maybe this solves the problem?

        Stefan
Comment 5 John Apostolakis 2015-06-06 03:02:50 CEST
The solid and navigator cannot cope with a problematic direction.  Also they will not cause it.

Either a physics process or the magnetic field integration (less likely) would need to be the source of the ( NaN, NaN, NaN ) direction.

It should be possible to have the 'particleChange' output of physics processes checked to ensure that such a direction is immediately caught.  If such a check does not already exist, it should be added in the appropriate checking method.  ( This may be optional. ) 

Until the origin of the incorrect direction is identified, it is difficult to make progress.
Comment 6 Marc.Verderi 2016-05-17 18:43:24 CEST
The problem has been identified as coming from G4LowEPComptonModel where an argument for arc trigonometric functions was above 1., generating NaN.
The author of the bug report confirmed on a private patch that the problem was resolved.
The fix has been provided in emlowen-V10-02-05 .