Seg Fault Whenever Particle Leaves Sensitive Detector

I am trying to simulate an X-Ray interaction with a SiLi detector however every time a particle interacts with any volume which I have designated a sensitive detector there is a seg fault. The fault occurs when the particle exits the detector.

Here is the error, for the sake of debugging I set an additional geometry, a hollow aluminum shell, to be a sensitive detector, that is the volume which is causing the seg fault in this case however the error is the same when interacting with the SiLi detector.

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

Start closing geometry.
G4GeometryManager::ReportVoxelStats -- Voxel Statistics

    Total memory consumed for geometry optimisation:   1 kByte
    Total CPU time elapsed for geometry optimisation: 0 seconds

    Voxelisation: top CPU users:
    Percent   Total CPU    System CPU       Memory  Volume
    -------   ----------   ----------     --------  ----------
       0.00         0.00         0.00            1k World

    Voxelisation: top memory users:
    Percent     Memory      Heads    Nodes   Pointers    Total CPU    Volume
    -------   --------     ------   ------   --------   ----------    ----------
     100.00          1k         4       10         42         0.00    World
### Run 0 starts.
### Run 0 start.
=====================================
  G4EventManager::ProcessOneEvent()  
=====================================
1 vertices passed from G4Event.
Primary particle (gamma) --- Transfered with momentum (0.0108661,0.00991875,-0.0581683)
A new track 0x7f7f6c10ddf0 (trackID 1, parentID 0) is passed to G4StackManager.
1 primaries are passed from G4EventTransformer.
!!!!!!! Now start processing an event !!!!!!!
### pop requested out of 1 stacked tracks.
Track 0x7f7f6c10ddf0 (trackID 1, parentID 0) is passed to G4TrackingManager.

*********************************************************************************************************
* G4Track Information:   Particle = gamma,   Track ID = 1,   Parent ID = 0
*********************************************************************************************************

Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
    0        0        0     52.1      0.06        0        0         0 av_2_impr_1_CeramicLog_pv_1 initStep
    1    0.204    0.186       51      0.06        0     1.12      1.12 av_2_impr_1_SourceLog_pv_2 Transportation
    2    0.205    0.188       51      0.06        0   0.0103      1.13 av_2_impr_1_HousingLog_pv_0 Transportation
    3    0.392    0.358       50      0.06        0     1.03      2.17 faradayPhys Transportation
    4    0.411    0.375     49.9      0.06        0    0.103      2.27       World Transportation

 *** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4tracking.dylib] G4TrackingManager::ProcessOneTrack(G4Track*) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4event.dylib] G4EventManager::DoProcessing(G4Event*) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4run.dylib] G4RunManager::ProcessOneEvent(int) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4run.dylib] G4RunManager::DoEventLoop(int, char const*, int) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4run.dylib] G4RunManager::BeamOn(int, char const*, int) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4run.dylib] G4RunMessenger::SetNewValue(G4UIcommand*, G4String) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4intercoms.dylib] G4UIcommand::DoIt(G4String) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4intercoms.dylib] G4UImanager::ApplyCommand(char const*) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4intercoms.dylib] G4UIbatch::ExecCommand(G4String const&) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4intercoms.dylib] G4UIbatch::SessionStart() (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4intercoms.dylib] G4UImanager::ExecuteMacroFile(char const*) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4intercoms.dylib] G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4intercoms.dylib] G4UIcommand::DoIt(G4String) (no debug info)
[/usr/local/geant4.10.05-install/lib/libG4intercoms.dylib] G4UImanager::ApplyCommand(char const*) (no debug info)
[/Users/gabrielbridges/Desktop/GAPS/Lab_new/./Lab_build/Lab] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
[<unknown binary>] (no debug info)
WARNING - Attempt to delete the assembly store while geometry closed !
WARNING - Attempt to delete the physical volume store while geometry closed !
WARNING - Attempt to delete the logical volume store while geometry closed !
WARNING - Attempt to delete the solid store while geometry closed !
WARNING - Attempt to delete the region store while geometry closed !

If anyone could point me in a direction to fix this problem I would be very grateful.

Have you tried running your code without setting your sensitive detector assigned to the logical volume? If the problem disappears, there likely is an issue in your sensitive detector code. If this is the case, please upload your sensitive detector code.

Makoto

The code runs when I do not set any logical volumes to be a sensitive detector, I am sure your assessment is correct however I can not figure out what is amiss with the SD code.

Here are the source and header files for my sensitive detector code.


I couldn’t find any particular issue in your sensitive detector code. Are you running it in a sequential mode or multithreaded mode?

Besides of this, I noticed your primary track (gamma) started at (0.,0.,52.1) toward -z direction, got into the world volume at (0.411,0.375,49.9), and crashed before it exits from the world volume. Is there any other volume? Could you please post the tracking/verbose output when you remove your sensitive detector? Your traceback says the SegFault happened in the G4TrackingManager::ProcessOneTrack(G4Track*) method. This is a very weird place to have SegFault if the track is still traveling toward the boundary of the world volume.

Here is the traceback with no volume set as a sensitive detector. There are currently 6 volumes in my simulation, three of those are a model of the radioactive source which produces the X-rays, 1 is the faraday cage which is simply a hollow aluminum shell, 1 is the SiLi detector itself, and the final one is an aluminum mount which the SiLi detector rests on. The seg fault always occurs immediately after the particle leaves any volume which is a SD. I am running the code in sequential mode.

*********************************************************************************************************
* G4Track Information:   Particle = gamma,   Track ID = 1,   Parent ID = 0
*********************************************************************************************************

Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
    0        0        0     52.1      0.06        0        0         0 av_2_impr_1_CeramicLog_pv_1 initStep
    1   -0.185   -0.566       51      0.06        0     1.24      1.24 av_2_impr_1_SourceLog_pv_2 Transportation
    2   -0.187   -0.572       51      0.06        0   0.0114      1.25 av_2_impr_1_HousingLog_pv_0 Transportation
    3   -0.357    -1.09       50      0.06        0     1.14      2.39 faradayPhys Transportation
    4   -0.374    -1.14     49.9      0.06        0    0.114      2.51       World Transportation
    5    -8.69    -26.6     0.95      0.06        0     55.8      58.3 DetectorPhys Transportation
    6    -9.06    -27.7    -1.25      0.06        0     2.51      60.8       World Transportation
    7    -9.91    -30.3    -6.25      0.06        0      5.7      66.5 faradayPhys Transportation
    8    -9.93    -30.4    -6.35      0.06        0    0.114      66.6       World Transportation
    9     -434 -1.33e+03 -2.5e+03      0.06        0 2.84e+03  2.91e+03  OutOfWorld Transportation
Track (trackID 1, parentID 0) is processed with stopping code 2
### pop requested out of 0 stacked tracks.
### 0 waiting tracks are re-classified to
     0 urgent tracks and 0 waiting tracks.
NULL returned from G4StackManager.
Terminate current event processing.
=====================================
  G4EventManager::ProcessOneEvent()  
=====================================
1 vertices passed from G4Event.
Primary particle (gamma) --- Transfered with momentum (0.02363678038237826,0.02953478063849073,-0.04657251706523334)
A new track 0x7fe92207bc20 (trackID 1, parentID 0) is passed to G4StackManager.
1 primaries are passed from G4EventTransformer.
!!!!!!! Now start processing an event !!!!!!!
### pop requested out of 1 stacked tracks.
Track 0x7fe92207bc20 (trackID 1, parentID 0) is passed to G4TrackingManager.

*********************************************************************************************************
* G4Track Information:   Particle = gamma,   Track ID = 1,   Parent ID = 0
*********************************************************************************************************

Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
    0        0        0     52.1      0.06        0        0         0 av_2_impr_1_CeramicLog_pv_1 initStep
    1    0.553    0.691       51      0.06        0      1.4       1.4 av_2_impr_1_SourceLog_pv_2 Transportation
    2    0.558    0.698       51      0.06        0   0.0129      1.42 av_2_impr_1_HousingLog_pv_0 Transportation
    3     1.07     1.33       50      0.06        0     1.29      2.71 faradayPhys Transportation
    4     1.12      1.4     49.9      0.06        0    0.129      2.83       World Transportation
    5     25.8     32.2     1.25      0.06        0     62.7      65.5 DetectorPhys Transportation
    6     26.2     32.7    0.522      0.06        0    0.938      66.4 DetectorPhys Rayl
    7     27.3       33    -1.25      0.06        0     2.13      68.6       World Transportation
    8     30.5       34    -6.25      0.06        0     6.01      74.6 faradayPhys Transportation
    9     30.6       34    -6.35      0.06        0     0.12      74.7       World Transportation
   10 1.63e+03      497 -2.5e+03      0.06        0    3e+03  3.07e+03  OutOfWorld Transportation
Track (trackID 1, parentID 0) is processed with stopping code 2
### pop requested out of 0 stacked tracks.
### 0 waiting tracks are re-classified to
     0 urgent tracks and 0 waiting tracks.
NULL returned from G4StackManager.
Terminate current event processing.
 Run terminated.

It seems the error happened when a track gets into a volume that has a sensitive detector rather than exiting the detector. [<unknown binary>] in your traceback is strange.
Could you add some G4cout into your LabDetectorSD::ProcessHits() to see if this method is actually invoked?

After adding many G4Cout statements to my LabDetectorSD::ProcessHits() it would appear that the method is not being invoked before the seg fault. I would include traceback but it is unchanged.

This result indicates the cause of this problem. Could you upload your detector construction class (.cc and .hh)?

Here they are, many things are constructed in the LabDetectorConstruction file but only the SiLi detector will be made sensitive, it begins at line 237 and finishes at 312

I have also set the Faraday Cage to be a sensitive detector for the time being, for debugging purposes, but the error persists even when the cage is not sensitive.

Thank you very much for your time and assistance, after grinding my way though the detector construction code I have found the problem. The part of the code responsible for assigning the SD to the SD manager was broken and therefore the SD was not working.

I was writing a reply.
The issue is the data member “SiLiSD” which is never initialized.
Un-initialized pointer may have any random value based on the OS, not necessarily null. Thus, the line #171 may not be true. And if this “SiLiSD” has a wild value, this invalid value is set to the logical volume as the pointer to the sensitive detector, and causes the segmentation fault.
In general, it is always a good idea to initialize all the data members within the constructor of the class.

Makoto

Line #171 of your LabDetectorConstruction.cc, I mean.