# Problem with visualizing the detector or running the simulation

**URL:** <https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861>\
**Category:** Recording, Visualizing and Persisting Data\
**Created:** [April 7, 2021, 7:15am UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861 "2021-04-07T07:15:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![SubhroD](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/subhrod/32/2656_2.png) [@SubhroD](https://geant4-forum.web.cern.ch/u/SubhroD)\
**Post date:** [April 7, 2021, 7:15am UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/1 "2021-04-07T07:15:43Z")

</div>

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…

```auto
$ 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](https://geant4-forum.web.cern.ch/uploads/short-url/zk6Tm5i4EH8PnUIslhQdj2xifp.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.

---

<div class="post-metadata">

**Author:** ![allison](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@allison](https://geant4-forum.web.cern.ch/u/allison)\
**Post date:** [April 7, 2021, 7:34am UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/2 "2021-04-07T07:34:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SubhroD](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/subhrod/32/2656_2.png) [@SubhroD](https://geant4-forum.web.cern.ch/u/SubhroD)\
**Post date:** [April 7, 2021, 10:13am UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/3 "2021-04-07T10:13:03Z")

</div>

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…

```auto
$ 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](https://geant4-forum.web.cern.ch/uploads/short-url/eYliSmgG8HRoFAjzefI6BwAAztl.txt) (58.2 KB) is the output from the terminal while I am running the executable using the command `./hpge`.

Thank you, sir.

---

<div class="post-metadata">

**Author:** ![allison](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@allison](https://geant4-forum.web.cern.ch/u/allison)\
**Post date:** [April 7, 2021, 1:08pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/4 "2021-04-07T13:08:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SubhroD](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/subhrod/32/2656_2.png) [@SubhroD](https://geant4-forum.web.cern.ch/u/SubhroD)\
**Post date:** [April 7, 2021, 2:02pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/5 "2021-04-07T14:02:09Z")

</div>

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

```auto
$ 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…

```auto
(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.

---

<div class="post-metadata">

**Author:** ![allison](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@allison](https://geant4-forum.web.cern.ch/u/allison)\
**Post date:** [April 7, 2021, 3:14pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/6 "2021-04-07T15:14:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SubhroD](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/subhrod/32/2656_2.png) [@SubhroD](https://geant4-forum.web.cern.ch/u/SubhroD)\
**Post date:** [April 7, 2021, 3:35pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/7 "2021-04-07T15:35:41Z")

</div>

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:

```auto
$ 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:

```auto
#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 .

---

<div class="post-metadata">

**Author:** ![allison](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@allison](https://geant4-forum.web.cern.ch/u/allison)\
**Post date:** [April 8, 2021, 3:38pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/8 "2021-04-08T15:38:21Z")

</div>

Hi @ [SubhroD](https://geant4-forum.web.cern.ch/u/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

---

<div class="post-metadata">

**Author:** ![Xuan\_Pang](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/xuan_pang/32/4824_2.png) [@Xuan\_Pang](https://geant4-forum.web.cern.ch/u/Xuan_Pang)\
**Post date:** [November 30, 2022, 11:25am UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/9 "2022-11-30T11:25:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bmorgan](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/bmorgan/32/7_2.png) [@bmorgan](https://geant4-forum.web.cern.ch/u/bmorgan)\
**Post date:** [November 30, 2022, 1:30pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/10 "2022-11-30T13:30:45Z")

</div>

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](https://en.cppreference.com/w/cpp/language/constructor) 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.

---

<div class="post-metadata">

**Author:** ![Xuan\_Pang](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/xuan_pang/32/4824_2.png) [@Xuan\_Pang](https://geant4-forum.web.cern.ch/u/Xuan_Pang)\
**Post date:** [December 5, 2022, 12:14pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/12 "2022-12-05T12:14:08Z")

</div>

👌, I got it. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![bmorgan](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/bmorgan/32/7_2.png) [@bmorgan](https://geant4-forum.web.cern.ch/u/bmorgan)\
**Post date:** [July 22, 2024, 4:09pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-visualizing-the-detector-or-running-the-simulation/4861/14 "2024-07-22T16:09:39Z")

</div>


