Problem with visualizing the detector or running the simulation

I have written a code for simulation of an HPGe (High purity Germanium) semiconductor detector. It compiles make file successfully. When I try to create an executable using make -j4, it creates successfully with some warnings like this…

$ make
Scanning dependencies of target hpge
[ 12%] Building CXX object CMakeFiles/hpge.dir/hpge_main.cc.o
[ 25%] Building CXX object CMakeFiles/hpge.dir/src/hpgeActionInitialization.cc.o
[ 37%] Building CXX object CMakeFiles/hpge.dir/src/hpgeDetectorConstruction.cc.o
In file included from /home/subhrod/G4_project/Examples_G4/zzHPGe_design/src/hpgeDetectorConstruction.cc:1:
/home/subhrod/G4_project/Examples_G4/zzHPGe_design/include/hpgeDetectorConstruction.hh: In constructor ‘hpgeDetectorConstruction::hpgeDetectorConstruction()’:
/home/subhrod/G4_project/Examples_G4/zzHPGe_design/include/hpgeDetectorConstruction.hh:56:22: warning: ‘hpgeDetectorConstruction::taperULog’ will be initialized after [-Wreorder]
   56 |     G4LogicalVolume* taperULog;
      |                      ^~~~~~~~~
/home/subhrod/G4_project/Examples_G4/zzHPGe_design/include/hpgeDetectorConstruction.hh:55:15: warning:   ‘G4Sphere* hpgeDetectorConstruction::taperL’ [-Wreorder]
   55 |     G4Sphere* taperL;
      |               ^~~~~~
/home/subhrod/G4_project/Examples_G4/zzHPGe_design/src/hpgeDetectorConstruction.cc:25:1: warning:   when initialized here [-Wreorder]
   25 | hpgeDetectorConstruction::hpgeDetectorConstruction() : G4VUserDetectorConstruction(), //specifying the variables..
      | ^~~~~~~~~~~~~~~~~~~~~~~~
/home/subhrod/G4_project/Examples_G4/zzHPGe_design/src/hpgeDetectorConstruction.cc: In member function ‘virtual G4VPhysicalVolume* hpgeDetectorConstruction::Construct()’:
/home/subhrod/G4_project/Examples_G4/zzHPGe_design/src/hpgeDetectorConstruction.cc:84:24: warning: declaration of ‘physiWorld’ shadows a member of ‘hpgeDetectorConstruction’ [-Wshadow]
   84 |     G4VPhysicalVolume *physiWorld = new G4PVPlacement(0,                                  //rotation
      |                        ^~~~~~~~~~
In file included from /home/subhrod/G4_project/Examples_G4/zzHPGe_design/src/hpgeDetectorConstruction.cc:1:
/home/subhrod/G4_project/Examples_G4/zzHPGe_design/include/hpgeDetectorConstruction.hh:33:24: note: shadowed declaration is here
   33 |     G4VPhysicalVolume* physiWorld;
      |                        ^~~~~~~~~~
[ 50%] Building CXX object CMakeFiles/hpge.dir/src/hpgeEventAction.cc.o
[ 62%] Building CXX object CMakeFiles/hpge.dir/src/hpgePrimaryGeneratorAction.cc.o
[ 75%] Building CXX object CMakeFiles/hpge.dir/src/hpgeRunAction.cc.o
[ 87%] Building CXX object CMakeFiles/hpge.dir/src/hpgeStackingAction.cc.o
[100%] Linking CXX executable hpge
[100%] Built target hpge

But after running the executable ./hpge I am getting the output which is executable.txt (52.1 KB)
consisting Segmentation fault (core dumped)
Is it only the visualization problem or running problem that I can not figure out. By running the executable ./hpge I think it is taking the materials and the detector geometry successfully in the simulation. Though I am not sure, you can check it in the executable.txt file.
I will be very thankful if someone helps me to figure out the problem and the way to fix it.

Fix the warnings. Then if the problem persists, come back to us.

Hello @allison
I have resolved the warnings. It is not showing any other warnings. The data that gives me while I am creating executable is…

$ make
Scanning dependencies of target hpge
[ 12%] Building CXX object CMakeFiles/hpge.dir/hpge_main.cc.o
[ 25%] Building CXX object CMakeFiles/hpge.dir/src/hpgeActionInitialization.cc.o
[ 37%] Building CXX object CMakeFiles/hpge.dir/src/hpgeDetectorConstruction.cc.o
[ 50%] Building CXX object CMakeFiles/hpge.dir/src/hpgeEventAction.cc.o
[ 62%] Building CXX object CMakeFiles/hpge.dir/src/hpgePrimaryGeneratorAction.cc.o
[ 75%] Building CXX object CMakeFiles/hpge.dir/src/hpgeRunAction.cc.o
[ 87%] Building CXX object CMakeFiles/hpge.dir/src/hpgeStackingAction.cc.o
[100%] Linking CXX executable hpge
[100%] Built target hpge

After that, still I am having Segmentation fault (core dumped). executable.txt (58.2 KB) is the output from the terminal while I am running the executable using the command ./hpge.

Thank you, sir.

OK. Great. Next step: run with a debugger:
gdb ./hpge
and when it crashes type where. Let us know the traceback output.

Hi @allison
I have used the debugger gdb ./hpge
and now I am getting this…

$ gdb ./hpge 
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./hpge...
(No debugging symbols found in ./hpge)
(gdb) 

Here in (gdb) I need to put some command to perform the debugging.
WhenI try this where and other commands like show configuration, it gives me this…

(gdb) where
No stack.
(gdb) x86_64-linux-gnu
Undefined command: "x86_64-linux-gnu".  Try "help".
(gdb) show configuration
This GDB was configured as follows:
   configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu
             --with-auto-load-dir=$debugdir:$datadir/auto-load
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load
             --with-expat
             --with-gdb-datadir=/usr/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/lib/gdb (relocatable)
             --without-libunwind-ia64
             --with-lzma
             --with-babeltrace
             --without-intel-pt
             --with-mpfr
             --without-xxhash
             --with-python=/usr (relocatable)
             --without-guile
             --disable-source-highlight
             --with-separate-debug-dir=/usr/lib/debug (relocatable)
             --with-system-gdbinit=/etc/gdb/gdbinit

("Relocatable" means the directory can be moved with the GDB installation
tree, and GDB will still find it.)

I actually do not know about gdb at all. Please suggest me what to do next.

Sorry - after gdb ./hpge you need to type run.

Hi @allison
After running the debugger, The same viewer (opengl) poped up with my detector geometry and then I tried to run beam by /run/beamOn then the viewer window aumatically closes and the terminal gives me this:

$ gdb ./hpge 
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./hpge...
(No debugging symbols found in ./hpge)
(gdb) run
Starting program: /home/subhrod/G4_project/Examples_G4/zzHPGe_design/build/hpge 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/x86_64-linux-gnu/libthread_db.so.1".
Available UI session types: [ Qt, GAG, tcsh, csh ]
[New Thread 0x7fffed253700 (LWP 31158)]
[New Thread 0x7fffe76b4700 (LWP 31159)]
[New Thread 0x7fffe6eb3700 (LWP 31160)]
[New Thread 0x7fffe644d700 (LWP 31161)]
[Detaching after fork from child process 31163]
[New Thread 0x7fffe52a7700 (LWP 31164)]
[New Thread 0x7fffe4aa6700 (LWP 31165)]
[New Thread 0x7fffd18ff700 (LWP 31166)]
[New Thread 0x7fffd10fe700 (LWP 31167)]

Thread 1 "hpge" received signal SIGSEGV, Segmentation fault.
0x000055555555d34f in hpgeEventAction::EndOfEventAction(G4Event const*) ()

Now I can understand that I have a problem with my EventAction
The code that I have written for this, is:

#include "hpgeEventAction.hh"

#include "G4Event.hh"
#include "G4EventManager.hh"
#include "G4TrajectoryContainer.hh"
#include "G4Trajectory.hh"
#include "G4ios.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

hpgeEventAction::hpgeEventAction()
: G4UserEventAction()
{}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

hpgeEventAction::~hpgeEventAction()
{}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void hpgeEventAction::BeginOfEventAction(const G4Event*)
{}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void hpgeEventAction::EndOfEventAction(const G4Event* event)
{
  // get number of stored trajectories

  G4TrajectoryContainer* trajectoryContainer = event->GetTrajectoryContainer();
  G4int n_trajectories = 0;
  if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();

  // periodic printing

  G4int eventID = event->GetEventID();
  if ( eventID < 100 || eventID % 100 == 0) {
    G4cout << ">>> Event: " << eventID  << G4endl;
    if ( trajectoryContainer ) {
      G4cout << "    " << n_trajectories
             << " trajectories stored in this event." << G4endl;
    }
    G4VHitsCollection* hc = event->GetHCofThisEvent()->GetHC(0);
    G4cout << "    "  
           << hc->GetSize() << " hits stored in this event" << G4endl;
  }
}  

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

Can you please point out the problem.
Thank you so much for the support @allison .

Hi @ SubhroD

First, can I just ask if one of our examples, for example example B1, runs OK for you?

OK. Assuming B1 runs OK, it must be something to do with your example. Your EndOfEventAction looks OK but I note that you do not protect event itself nor hc. Good programming would suggest you have an if(event)... or an if(hc)... statement somewhere.

The next step for a serious computer programmer would be to build Geant4 in Debug mode (-DCMAKE_BUILD_TYPE=Debug) and rebuild your example. Then gdb will give you the exact line that causes the crash.

John

Hi, allison.
How to fix the warnings about [-Wreorder]?

In general, it’s better to post a new topic than resurrect one from a year and a half ago!

The warning is related to initialization order in a constructor - see the “Initialization order” section on cppreference for details and examples. The shadowing warning is just that the physiWorld data member has been redeclared when it shouldn’t be as far as I can tell from the output.

:ok_hand:, I got it. Thanks for your help!