Unrecognizable error

Hello! I am developing a full application that simulates a cylindrical BGO calorimeter where neutrons are launched from its inside.

I’ve followed carefully all that I have found in order to do it but when I run it I see this:



          ################################
          !!! G4Backtrace is activated !!!
          ################################


**************************************************************
 Geant4 version Name: geant4-11-00-patch-01 [MT]   (8-March-2022)
                       Copyright : Geant4 Collaboration
                      References : NIM A 506 (2003), 250-303
                                 : IEEE-TNS 53 (2006), 270-278
                                 : NIM A 835 (2016), 186-225
                             WWW : http://geant4.org/
**************************************************************


### CAUGHT SIGNAL: 11 ### address: 0x0,  signal =  SIGSEGV, value =   11, description = segmentation violation. Unknown segmentation fault error: 0.

Backtrace:
[PID=15529, TID=-1][0/6]> 0   ???                                 0x0000000000000400 0x0 + 1024
[PID=15529, TID=-1][1/6]> 1   last                                0x0000000101b85997 _ZN20DetectorConstruction19ConstructSDandFieldEv + 87
[PID=15529, TID=-1][2/6]> 2   libG4run.dylib                      0x00000001027cb57e _ZN12G4RunManager18InitializeGeometryEv + 302
[PID=15529, TID=-1][3/6]> 3   libG4run.dylib                      0x00000001027cb424 _ZN12G4RunManager10InitializeEv + 260
[PID=15529, TID=-1][4/6]> 4   last                                0x0000000101b8423c main + 172
[PID=15529, TID=-1][5/6]> 5   dyld                                0x000000010e00851e start + 462

[1]    15529 abort      ./last

I cannot see where the issue is. The application started to crash like this after I made the BGO a sensitive detector and added stepping action in order to record the deposition energy.

Thanks in advance!

Did you have any warnings on compilation?

These are my warnings at the moment:

❯ make
Consolidate compiler generated dependencies of target last
[ 10%] Building CXX object CMakeFiles/last.dir/src/SensitiveDetector.cc.o
/Users/diegocostasrodriguez/software/geant4/last_try/src/SensitiveDetector.cc:16:15: warning: unused variable 'postStepPoint' [-Wunused-variable]
        G4StepPoint *postStepPoint = aStep->GetPostStepPoint();
                     ^
/Users/diegocostasrodriguez/software/geant4/last_try/src/SensitiveDetector.cc:13:11: warning: unused variable 'track' [-Wunused-variable]
        G4Track *track = aStep->GetTrack();
                 ^
/Users/diegocostasrodriguez/software/geant4/last_try/src/SensitiveDetector.cc:10:74: warning: unused parameter 'ROhist' [-Wunused-parameter]
G4bool SensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
                                                                         ^
3 warnings generated.
[ 20%] Linking CXX executable last
[100%] Built target last

I tried removing the EventAction and SteppingAction and just keep the first Ntuple I created -which records the hits in the BGO sensitive volume- but the same error when running the executable persists.

Thanks in advance!

The program crashes on start up?

A quick way to hunt down the error is have your user defined actions (run action, detector construction) print a line when they are constructed, i.e. in the class constructor. You can see what the last class initialized before crashing and try to pin point what the issue is. Because you are crashing on running the executable and not when run beamOn, my guess is it is not a stepping action issue, unless you run a macro that automatically runs on start up

Thanks for the tip.

I tracked the error to the DetectorConstruction. The start up error occurs when I implement this in the header file:

private:
	
	G4LogicalVolume *logicDetector;
	virtual void ConstructSDandField();

to then use it in the source file for:

void DetectorConstruction::ConstructSDandField()
{
	SensitiveDetector *sensDet = new SensitiveDetector("SensitiveDetector");
	
	logicDetector->SetSensitiveDetector(sensDet);
}

I think the error comes from this ConstructSDandField(). I do not know if this is something that has changed in G4-v11 but when I write this function in my DetectorConstruction.cc, the program cannot start.

Thanks again!

Hello again,

I just realized that all the three parts running initialize even when the start up error occurs.

I print something in the DetectorConstruction constructor, in the ActionInitialization and in the SensitiveDetector, and they all initialize but the error is still there.

Thanks again!

Have you checked that logicDetector is not nullptr when ConstructSDandField is run? That would be an obvious cause of the segfault. Otherwise, all I can recommend in addition is to compile your application in Debug mode and run it through lldb. There’s a discussion on this in this thread: Using gdb debugger in an efficient way, albeit for gdb, but the two are similar (a search for “gdb” in the forums will bring up more on debugging).

Otherwise, look through the Application Developer Guide and Examples for info on implementing detector/sd construction.

Hi,

I’ve just realized that my issue is just the same as this:

but the solution Lorenzo provides, the

return true;

at the end of the G4bool in the SensitiveDetector does not work for me, I already have that. The same line that was giving error to him is the one that is making my program crash with aboves output, do you know what may be the issue here?

Thanks in advance!

Sorry, there’s not enough information here to triage the issue - the best option is to run through the debugger which will provide a full analysis, or to put G4cout statements around the point(s) you think may be triggering the error.