Problem Running Basic Example B1

mkelsey and John,

I think the procedure for installing GEANT4, found here:

https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/installguide.html#geant4-build-options

is confusing when it comes to the build options part. Maybe I am making harder than it is, but it is not clear to me in which directory the build options should be turned on, what command should be used, etc.

I therefore tried what John suggested in the geant4…-build directory. This is what happened.

Jamess-MacBook-Pro:~ jamesbowen$ cd geant4-v11.0.0-build/
Jamess-MacBook-Pro:geant4-v11.0.0-build jamesbowen$ cmake -DGEANT4_USE_OPENGL_X11=ON
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.

CMake Error: The source directory “/Users/jamesbowen/geant4-v11.0.0-build” does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
Jamess-MacBook-Pro:geant4-v11.0.0-build jamesbowen$

I then went into the source directory that is inside the build directory and tried again…same thing happened. Is there anything else I need here?

From what I gather, I also need to go through the build and install process again after doing this. Is that correct?

It is confusing, but my take is that’s the nature of CMake (I’m an old “GNUmakefile” sort…). Here’s how I’ve understood it:

The source directory is what you download and unpack (or clone from Git, or whatever). Don’t mess with it; don’t use it for building or installing.

The build directory is where all the compilation and creating will be done. To set it up, you go to that directory and use a command like

cmake -DSOME_OPTION=VALUE -DOTHER_OPTION=VALUE [etc.] /path/to/source/directory

Notice that last argument: You have to tell CMake where to find the sources, but you don’t have to tell it where the build directory is (it’s where you are now).

The install directory is where you want your users to find the finished libraries, and the databases, and the setup scripts, when everything is finished. By default, plain CMake tries to put everything under /usr/local, but we recommend that you put your G4 builds somewhere else, and specify that somewhere else with the -DCMAKE_INSTALL_PREFIX=/path/to/install/directory option back at the first step.

All of the configuration and build commands (cmake, make, make install, etc.) get run in the build directory. If you imagine that the source directory is “read only”, and the install directory is “write only”, then the build directory is where you make things happen to connect those two.

Again, this is how I think about the process; I hope it’s helpful.

Thanks mkelsey. I think I understand the command format and logic behind them now. What I am still not clear on is where I find the sources for turning on OpenGL. I don’t have the BuildProducts sub-directory in my build/source directory that John mentioned earlier. The command involving the /opt directory, which I can’t remember where I got, seemed to work on my other machine a year ago. However, I don’t see an /opt directory either, and John thinks I should steer clear of that command now.

I think it might have worked, or at the very least did error. It looks like I needed a “.” after the command that John gave me earlier. This is what happened.

"Jamess-MacBook-Pro:geant4-v11.0.0-build jamesbowen$ cmake -DGEANT4_USE_OPENGL_X11=ON .
– Checking C++ feature CXXSTDLIB_FILESYSTEM_NATIVE - Success
– Found OpenGL: /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/OpenGL.framework
– Found XQuartzGL: /usr/X11R6/include
– Found X11: /usr/X11R6/include
– Looking for XOpenDisplay in /usr/X11R6/lib/libX11.dylib;/usr/X11R6/lib/libXext.dylib
– Looking for XOpenDisplay in /usr/X11R6/lib/libX11.dylib;/usr/X11R6/lib/libXext.dylib - found
– Looking for gethostbyname
– Looking for gethostbyname - found
– Looking for connect
– Looking for connect - found
– Looking for remove
– Looking for remove - found
– Looking for shmat
– Looking for shmat - found
– Looking for IceConnectionNumber in ICE
– Looking for IceConnectionNumber in ICE - found
– Pre-configuring dataset G4NDL (4.6)
– Pre-configuring dataset G4EMLOW (8.0)
– Pre-configuring dataset PhotonEvaporation (5.7)
– Pre-configuring dataset RadioactiveDecay (5.6)
– Pre-configuring dataset G4PARTICLEXS (4.0)
– Pre-configuring dataset G4PII (1.3)
– Pre-configuring dataset RealSurface (2.2)
– Pre-configuring dataset G4SAIDDATA (2.0)
– Pre-configuring dataset G4ABLA (3.1)
– Pre-configuring dataset G4INCL (1.0)
– Pre-configuring dataset G4ENSDFSTATE (2.3)
WARNING
Geant4 has been pre-configured to look for datasets
in the directory:

/Users/jamesbowen/geant4-v11.0.0-install/share/Geant4-11.0.0/data

but the following datasets are NOT present on disk at
that location:

G4NDL (4.6)
G4EMLOW (8.0)
PhotonEvaporation (5.7)
RadioactiveDecay (5.6)
G4PARTICLEXS (4.0)
G4PII (1.3)
RealSurface (2.2)
G4SAIDDATA (2.0)
G4ABLA (3.1)
G4INCL (1.0)
G4ENSDFSTATE (2.3)

If you want to have these datasets installed automatically
simply re-run cmake and set the GEANT4_INSTALL_DATA
variable to ON. This will configure the build to download
and install these datasets for you. For example, on the
command line, do:

cmake -DGEANT4_INSTALL_DATA=ON <otherargs>

The variable can also be toggled in ccmake or cmake-gui.
If you're running on a Windows system, this is the best
solution as CMake will unpack the datasets for you
without any further software being required

Alternatively, you can install these datasets manually
now or after you have installed Geant4. To do this,
download the following files:

https://cern.ch/geant4-data/datasets/G4NDL.4.6.tar.gz
https://cern.ch/geant4-data/datasets/G4EMLOW.8.0.tar.gz
https://cern.ch/geant4-data/datasets/G4PhotonEvaporation.5.7.tar.gz
https://cern.ch/geant4-data/datasets/G4RadioactiveDecay.5.6.tar.gz
https://cern.ch/geant4-data/datasets/G4PARTICLEXS.4.0.tar.gz
https://cern.ch/geant4-data/datasets/G4PII.1.3.tar.gz
https://cern.ch/geant4-data/datasets/G4RealSurface.2.2.tar.gz
https://cern.ch/geant4-data/datasets/G4SAIDDATA.2.0.tar.gz
https://cern.ch/geant4-data/datasets/G4ABLA.3.1.tar.gz
https://cern.ch/geant4-data/datasets/G4INCL.1.0.tar.gz
https://cern.ch/geant4-data/datasets/G4ENSDFSTATE.2.3.tar.gz

and unpack them under the directory:

/Users/jamesbowen/geant4-v11.0.0-install/share/Geant4-11.0.0/data

As we supply the datasets packed in gzipped tar files,
you will need the 'tar' utility to unpack them.

Nota bene: Missing datasets will not affect or break
           compilation and installation of the Geant4
           libraries.

– The following Geant4 features are enabled:
CMAKE_CXX_STANDARD: Compiling against C++ Standard ‘17’
GEANT4_BUILD_MULTITHREADED: Build multithread enabled libraries
GEANT4_BUILD_TLS_MODEL: Building with TLS model ‘initial-exec’
GEANT4_USE_SYSTEM_EXPAT: Using system EXPAT library
GEANT4_USE_OPENGL_X11: Build Geant4 OpenGL driver with X11 support

– Configuring done
– Generating done
– Build files have been written to: /Users/jamesbowen/geant4-v11.0.0-build
Jamess-MacBook-Pro:geant4-v11.0.0-build jamesbowen$ "

I mean “did not error.”

Okay, just when things appeared to be going smoothly, I got a seg fault when running example B1. This is that happened.

"
Jamess-MacBook-Pro:B1-build jamesbowen$ ./exampleB1
Available UI session types: [ tcsh, csh ]

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

-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : PART70001
issued by : G4NuclideTable
ENSDFSTATE.dat is not found.
*** Fatal Exception *** core dump ***

CAUGHT SIGNAL: 11 ### address: 0x10, signal = SIGSEGV, value = 11, description = segmentation violation. Address not mapped to object.

Backtrace:
[PID=73323, TID=-1][ 0/19]> 0 ??? 0x7469736f70206b63 0x0 + 8388362703413996387
[PID=73323, TID=-1][ 1/19]> 1 libG4run.dylib 0x00000001060b6dfd ZN18G4ExceptionHandler6NotifyEPKcS1_19G4ExceptionSeverityS1 + 1229
[PID=73323, TID=-1][ 2/19]> 2 libG4global.dylib 0x00000001087cd9f0 Z11G4ExceptionPKcS0_19G4ExceptionSeverityS0 + 64
[PID=73323, TID=-1][ 3/19]> 3 libG4particles.dylib 0x00000001067b2be0 _ZN14G4NuclideTable15GenerateNuclideEv + 608
[PID=73323, TID=-1][ 4/19]> 4 libG4particles.dylib 0x00000001067b2917 _ZN14G4NuclideTableC2Ev + 247
[PID=73323, TID=-1][ 5/19]> 5 libG4particles.dylib 0x00000001067b27da _ZN14G4NuclideTable15GetNuclideTableEv + 58
[PID=73323, TID=-1][ 6/19]> 6 libG4particles.dylib 0x000000010679b966 _ZN10G4IonTableC1Ev + 182
[PID=73323, TID=-1][ 7/19]> 7 libG4particles.dylib 0x00000001067bdbe2 _ZN15G4ParticleTableC2Ev + 322
[PID=73323, TID=-1][ 8/19]> 8 libG4particles.dylib 0x00000001067bd56f _ZN15G4ParticleTable16GetParticleTableEv + 127
[PID=73323, TID=-1][ 9/19]> 9 libG4event.dylib 0x000000010616a080 _ZN20G4PrimaryTransformerC1Ev + 96
[PID=73323, TID=-1][10/19]> 10 libG4event.dylib 0x0000000106151ed9 _ZN14G4EventManagerC2Ev + 265
[PID=73323, TID=-1][11/19]> 11 libG4run.dylib 0x00000001060d5b45 _ZN18G4RunManagerKernelC2ENS_7RMKTypeE + 421
[PID=73323, TID=-1][12/19]> 12 libG4run.dylib 0x00000001060ea7a8 _ZN20G4MTRunManagerKernelC2Ev + 24
[PID=73323, TID=-1][13/19]> 13 libG4run.dylib 0x00000001060c37ea _ZN12G4RunManagerC2ENS_6RMTypeE + 522
[PID=73323, TID=-1][14/19]> 14 libG4run.dylib 0x00000001060c8e31 _ZN14G4MTRunManagerC2Ev + 33
[PID=73323, TID=-1][15/19]> 15 libG4tasking.dylib 0x0000000105d19204 _ZN16G4TaskRunManagerC2EPN3PTL14VUserTaskQueueEbi + 36
[PID=73323, TID=-1][16/19]> 16 libG4tasking.dylib 0x0000000105d09081 _ZN19G4RunManagerFactory16CreateRunManagerE16G4RunManagerTypePN3PTL14VUserTaskQueueEbi + 1521
[PID=73323, TID=-1][17/19]> 17 exampleB1 0x00000001056caab1 main + 113
[PID=73323, TID=-1][18/19]> 18 libdyld.dylib 0x00007fff72961cc9 start + 1

Abort trap: 6
Jamess-MacBook-Pro:B1-build jamesbowen$
"
Do any of you have any idea as to what might have caused this?

P.S. Sorry about the bold letters. I will try to catch that next time.

Success! It shows tat it found all the OpenGL stuff. So now when you do make you should see messages about it building the G4OpenGL library (or whatever the captialization is). Then you can do make install, and then you can go and rebuild your application (exampleB1 or whatever).

If you launch your executable without a macro file, you should be able to type /vis/list, and at the very top it should include

OpenGLImmediateX (OGLIX, OGLI)
OpenGLStoredX (OGLSX, OGL, OGLS)

(you’ll have to scroll back a lot, because the output is a fair bit of glossorhea :-/ )

If you put three backquotes before pasting in, and another three backquotes at the end, it’ll treat it as a “preformatted” insert, and not interpret as markup. It’s kind of like the Slack and GitHub interfaces.

[ Edited to remove literal backquotes, as they got interpreted. ]

Thanks mkelsey. Did you see my last entry about the crash when I tried to run example B1. That did not happen last time. Before my re-installation, it ran, just without outputting the image.

This is your clue (in general, always look for the very first error message). If you look back at the output of your cmake action, you’ll see a nice discussion about how it didn’t find any of the Geant4 datasets. Those are big files (or big directories of tiny files) that are used by many of the Geant4 processes to tabulate the physics.

You can download and install them by hand, and just tell CMake where you put them, or you can let CMake take care of it for you. The Installation Guide should explain all this to you.

Thanks mkelsey. I will take a look at this and let you know how it goes.

mkelsey,

I issued the command “cmake -DGEANT4_INSTALL_DATA=ON .” I thought this might correct it, and a lot of files were apparently downloaded when I did. I still got the following error:

“”"Jamess-MacBook-Pro:B1-build jamesbowen$ ./exampleB1
Available UI session types: [ tcsh, csh ]

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

-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : PART70001
issued by : G4NuclideTable
ENSDFSTATE.dat is not found.
*** Fatal Exception *** core dump ***

CAUGHT SIGNAL: 11 ### address: 0x10, signal = SIGSEGV, value = 11, description = segmentation violation. Address not mapped to object.

Backtrace:
[PID=87816, TID=-1][ 0/20]> 0 ??? 0x6f20656572742068 0x0 + 8007511623851057256
[PID=87816, TID=-1][ 1/20]> 1 libG4run.dylib 0x0000000101c4adfd ZN18G4ExceptionHandler6NotifyEPKcS1_19G4ExceptionSeverityS1 + 1229
[PID=87816, TID=-1][ 2/20]> 2 libG4global.dylib 0x00000001042359f0 Z11G4ExceptionPKcS0_19G4ExceptionSeverityS0 + 64
[PID=87816, TID=-1][ 3/20]> 3 libG4particles.dylib 0x0000000103ce9be0 _ZN14G4NuclideTable15GenerateNuclideEv + 608
[PID=87816, TID=-1][ 4/20]> 4 libG4particles.dylib 0x0000000103ce9917 _ZN14G4NuclideTableC2Ev + 247
[PID=87816, TID=-1][ 5/20]> 5 libG4particles.dylib 0x0000000103ce97da _ZN14G4NuclideTable15GetNuclideTableEv + 58
[PID=87816, TID=-1][ 6/20]> 6 libG4particles.dylib 0x0000000103cd2966 _ZN10G4IonTableC1Ev + 182
[PID=87816, TID=-1][ 7/20]> 7 libG4particles.dylib 0x0000000103cf4be2 _ZN15G4ParticleTableC2Ev + 322
[PID=87816, TID=-1][ 8/20]> 8 libG4particles.dylib 0x0000000103cf456f _ZN15G4ParticleTable16GetParticleTableEv + 127
[PID=87816, TID=-1][ 9/20]> 9 libG4event.dylib 0x0000000101cfd080 _ZN20G4PrimaryTransformerC1Ev + 96
[PID=87816, TID=-1][10/20]> 10 libG4event.dylib 0x0000000101ce4ed9 _ZN14G4EventManagerC2Ev + 265
[PID=87816, TID=-1][11/20]> 11 libG4run.dylib 0x0000000101c69b45 _ZN18G4RunManagerKernelC2ENS_7RMKTypeE + 421
[PID=87816, TID=-1][12/20]> 12 libG4run.dylib 0x0000000101c7e7a8 _ZN20G4MTRunManagerKernelC2Ev + 24
[PID=87816, TID=-1][13/20]> 13 libG4run.dylib 0x0000000101c577ea _ZN12G4RunManagerC2ENS_6RMTypeE + 522
[PID=87816, TID=-1][14/20]> 14 libG4run.dylib 0x0000000101c5ce31 _ZN14G4MTRunManagerC2Ev + 33
[PID=87816, TID=-1][15/20]> 15 libG4tasking.dylib 0x00000001018b4204 _ZN16G4TaskRunManagerC2EPN3PTL14VUserTaskQueueEbi + 36
[PID=87816, TID=-1][16/20]> 16 libG4tasking.dylib 0x00000001018a4081 _ZN19G4RunManagerFactory16CreateRunManagerE16G4RunManagerTypePN3PTL14VUserTaskQueueEbi + 1521
[PID=87816, TID=-1][17/20]> 17 exampleB1 0x0000000101268ab1 main + 113
[PID=87816, TID=-1][18/20]> 18 libdyld.dylib 0x00007fff72961cc9 start + 1
[PID=87816, TID=-1][19/20]> 19 ??? 0x0000000000000001 0x0 + 1

Abort trap: 6
Jamess-MacBook-Pro:B1-build jamesbowen$ “”"

I will keep reading through the installation procedure, but can you think of anything outright that I missed?

P.S. I put three quotes in, but bold still showed up.

did you set the required environment variables? this is required for every new command line that you open…

https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/postinstall.html#required-environment-settings-on-unix

weller,

To set the environment, I went to the directory /Users/jamesbowen/geant4-v11.0.0-install/bin, and issued the command “source geant4.sh”. Is there anything else I need to do to set the environment?

If you sourced geant4.sh in the same session, that should have done it. If you opened a new terminal, then you need to do the source geant4.sh again.

After doing that, you can take a look at what was set; I like to use

printenv | grep ^G4

so you can see only the Geant4 envvars. You should see something like the following:

{michaels-mbp:319} printenv | grep ^G4
G4SYSTEM=Darwin-clang
G4NEUTRONHPDATA=/Applications/GEANT4/data/G4NDL4.6
G4LEDATA=/Applications/GEANT4/data/G4EMLOW7.9.1
G4LEVELGAMMADATA=/Applications/GEANT4/data/PhotonEvaporation5.5
G4RADIOACTIVEDATA=/Applications/GEANT4/data/RadioactiveDecay5.4
G4PARTICLEXSDATA=/Applications/GEANT4/data/G4PARTICLEXS2.1
G4PIIDATA=/Applications/GEANT4/data/G4PII1.3
G4REALSURFACEDATA=/Applications/GEANT4/data/RealSurface2.1.1
G4SAIDXSDATA=/Applications/GEANT4/data/G4SAIDDATA2.0
G4ABLADATA=/Applications/GEANT4/data/G4ABLA3.1
G4INCLDATA=/Applications/GEANT4/data/G4INCL1.0
G4ENSDFSTATEDATA=/Applications/GEANT4/data/G4ENSDFSTATE2.2

(These are on my Mac, for Geant4 10.6). The last one is what the nuclide table is looking for.

It looks like I have it too.

“”“Jamess-MacBook-Pro:~ jamesbowen$ cd geant4-v11.0.0-install/bin/
Jamess-MacBook-Pro:bin jamesbowen$ source geant4.sh
Jamess-MacBook-Pro:bin jamesbowen$ printenv | grep ^G4
G4LEVELGAMMADATA=/Users/jamesbowen/share/Geant4-11.0.0/data/PhotonEvaporation5.7
G4LEDATA=/Users/jamesbowen/share/Geant4-11.0.0/data/G4EMLOW8.0
G4NEUTRONHPDATA=/Users/jamesbowen/share/Geant4-11.0.0/data/G4NDL4.6
G4ENSDFSTATEDATA=/Users/jamesbowen/share/Geant4-11.0.0/data/G4ENSDFSTATE2.3
G4RADIOACTIVEDATA=/Users/jamesbowen/share/Geant4-11.0.0/data/RadioactiveDecay5.6
G4ABLADATA=/Users/jamesbowen/share/Geant4-11.0.0/data/G4ABLA3.1
G4PIIDATA=/Users/jamesbowen/share/Geant4-11.0.0/data/G4PII1.3
G4PARTICLEXSDATA=/Users/jamesbowen/share/Geant4-11.0.0/data/G4PARTICLEXS4.0
G4SAIDXSDATA=/Users/jamesbowen/share/Geant4-11.0.0/data/G4SAIDDATA2.0
G4REALSURFACEDATA=/Users/jamesbowen/share/Geant4-11.0.0/data/RealSurface2.2
G4INCLDATA=/Users/jamesbowen/share/Geant4-11.0.0/data/G4INCL1.0
Jamess-MacBook-Pro:bin jamesbowen$”""

Yet I am still getting the same segmentation fault. I am really not sure what to try next.

That’s what should have happened. Check the directory that your envvar points to (btw, you want the three backquotes by themselves on a line):

{michaels-mbp:321} echo $G4ENSDFSTATEDATA
/Applications/GEANT4/data/G4ENSDFSTATE2.2
{michaels-mbp:322} ls $G4ENSDFSTATEDATA
ENSDFSTATE.dat	History		README

As a follow up, this error should not be causing a segmentation fault. The error message clearly shows that G4 isn’t finding the file it wants, but then it segfaults during the process of generating the error message.

The first line of the segfault you quoted,

CAUGHT SIGNAL: 11 ### address: 0x10, signal = SIGSEGV, value = 11,
 description = segmentation violation. Address not mapped to object.

has a clue. The address “0x10” looks very much like an offset into some object, where the object has a base address of 0x00000000. That suggests the code is dereferencing a null pointer, which is clearly not allowed.

Unfortunately, the traceback you show doesn’t include any debugging symbols (it doesn’t show function arguments, nor file and line numbers).

I know it’s a pain in the arse to keep rebuilding, but you’ll be able to get more information (potentially enough to file a G4 bug report) if you have a debugging build. In your build directory, you can do

cmake -DCMAKE_BUILD_TYPE=Debug .
make -j4 clean install

Which will give you libraries with no optimization and full debugging symbols. This will increase the disk usage significantly, so if you’re worried about that, you could use “RelWithDebugInfo” instead.

Once you’ve got this, the traceback should show exactly where the segfault happened in the source code. Plus, you’ll be able to run in the debugger and inspect variables, etc.

mkelsey,

Thanks again for your reply. This is what I got when I checked the directory that envvar points to.

“”"
Jamess-MacBook-Pro:B1-build jamesbowen$ echo $G4ENSDFSTATEDATA
/Users/jamesbowen/share/Geant4-11.0.0/data/G4ENSDFSTATE2.3
Jamess-MacBook-Pro:B1-build jamesbowen$
“”"
I will go through the debugging build next.