Recent Changes - Search:

Public

Physics

Engineering

Literature
Journal Club
People

MineralPET
DAQ

Computing

Africa


Geant4

Links

Also has Python and machine learning

Usage via CVMFS

The WLCG provides a lot of pre-compiled HEPP software via the CVMFS service. This can be installed on machines to stream software from cache servers, rather than installing locally. Our workstations and High Throughput Compute cluster have CVMFS available. Instructions to install CVMFS on your own machine can be found on the HEPPackagesForScientificLinux page.

An LCG release need to be set up in you environment. Most of our Git repositories include a convenience script for this. Behind the scenes, this is done using the LCG script, specifying the release version and machine platform e.g:

source /cvmfs/sft.cern.ch/lcg/views/setupViews.sh LCG_107 x86_64-ubuntu2404-gcc13-opt # For didingwe
source /cvmfs/sft.cern.ch/lcg/views/setupViews.sh LCG_107 x86_64-ubuntu2204-gcc11-opt # For ukhozi & odin
source /cvmfs/sft.cern.ch/lcg/views/setupViews.sh LCG_107 x86_64-el9-gcc11-opt # For the psi-cluster

The Geant versions currently available are as follows:

  • LCG_107: Geant4: 11.3.0 ROOT: 6.34.02
  • LCG_106: Geant4: 11.2.1 ROOT: 6.32.02
  • LCG_105a: Geant4: 11.2.0 ROOT: 6.30.04
  • LCG_104a: Geant4: 11.1.2 ROOT: 6.28/06

Installation from source

We are using version 11.0.3 (as of 02.02.23).

  1. Before starting, make sure you have the all the Geant4 dependencies:
    • All recommended packages can be installed with the HEP_OSLibs package.
    • For Ubuntu, the required packages can be installed manually as: sudo apt install cmake cmake-curses-gui gcc g++ libexpat1-dev libxmu-dev libmotif-dev qtcreator qtbase5-dev qt5-qmake
  2. Download at: https://geant4.web.cern.ch/support/download_archive
  3. Setting up
    1. In /opt/ make a geant4 folder, then within this:
    2. sudo tar -xzvf ~/Downloads/geant4-{X}.tar.gz where {X} is the version number.
    3. Make folders for the build and install (e.g. geant4-{X}_build for the build directory of Geant4 version {X})
  4. Building the install
    1. Open the build folder
      1. sudo ccmake ../ geant4-{X}
    2. Opens the cmake configure menu.
      1. Configure (c)
      2. Exit (e)
      3. Change the CMAKE_INSTALL_PREFIX field to the install directory path (e.g. /opt/geant4/geant4-v11.03_install)
      4. Change CMAKE_BUILD_TYPE to RelWithDebInfo
      5. All switches must be on OFF except for:
        1. GEANT4_INSTALL_DATA
        2. GEANT4_OPENGL_X11
        3. GEANT4_QT
        4. GEANT4_RAYTRACER_X11
        5. GEANT4_SYSTEM_EXPAT
      6. Configure (c)
      7. Generate (g), should exit the cmake menu)
    3. sudo make -jN
      1. Where N is the number of cores on the PC.
      2. Geant4 will be installed, which took ~1hr on Wolf and Loki (8 cores each).
    4. sudo make install
  5. Finishing up and testing
    1. We can check that Geant is working by running an example. The easiest is B1:
      1. In the install folder, copy share/Geant4-{X}/examples/basic/B1/ to your home directory.
      2. Make a build/ directory in B1 and open it.
      3. . /opt/geant4/geant4-{X}_install/bin/geant4.sh
      4. cmake ../
      5. make -jN where N is the number of cores
      6. ./exampleB1
    2. Should load the Geant example – try running /run/beamOn 100 to see if the example works.
    3. Then we make the geant4 command accessible to all users.
      1. sudo gedit /etc/profile
      2. Add . /{PATH}/geant4.sh right at the end of the file (outside any if clauses or loops), where {PATH} is the full path to geant4.sh.

Documentation

Examples

Hints and changes

  • RNG Seeding : G4.8.2 uses the new CLHEP 2, which requires the CLHEP:: namespace - just specify it or add some "using" statements
    • To re-seed the Random Number Generator for many repeats of a MC from GEANT4 on differnt cores. In the main program of the GEANT4 application -
     choose the Random engine
    CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
    if (argc>=3) {
        CLHEP::HepRandom::setTheSeed(atoi(argv[2]));
    }
in this way you can run, for example
  • ./<geant4app> <macro>.mac 1
  • ./<geant4app> <macro>.mac 2
  • cmake : Discussion about using cmake or make to compile projects.
  • GEANT on the Cluster :
The cluster has CVMFS available on all nodes. LCG releases include Geant4, ROOT and many other HEP software packages. The setup script can be sourced like so:
source /cvmfs/sft.cern.ch/lcg/views/setupViews.sh LCG_104 x86_64-centos7-gcc11-opt
Omit the target triplet to see a list of all triplets available for a given release or omit the release name to list all available releases. LCG releases are described at lcginfo.cern.ch (CERN account required).
  • Building Geant4 on Ubuntu
    • Install the following
      • sudo apt-get install cmake git
      • sudo apt-get install libx11-dev libxpm-dev libxft-dev libxext-dev
      • sudo apt-get install qt4-qmake libqt4-dev libxmu-dev
    • Download tar file from Geant4 website: for example geant4.10.02.p03.tar.gz
    • Extract files (it will place them into a dir such as "geant4.10.02.p03")
    • Create a build dir:
      • mkdir geant4.10.02.p03-build
      • cd geant4.10.02.p03-build
    • Then cmake as below: (NOTE there are two ways to do this depending if you let cmake AUTOMATICALLY download the required datafiles for you or if you MANUALLY do this)
    • AUTOMATIC way enter:
      • cmake -DCMAKE_INSTALL_PREFIX=/<PATH_TO_your_yet_to_be_created_install_dir>/geant4.10.02.p03-install -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGEANT4_INSTALL_DATA=ON \\
        	    -DGEANT4_USE_QT=ON -DGEANT4_USE_OPENGL_X11=ON -DGEANT4_USE_RAYTRACER_X11=ON ../geant4.10.02.p03
      • make
      • make install
      • (NOTE: If anything stops due to errors, you are usually missing some libraries so install them: $ sudo apt-get install library-dev for some library)
      • Edit .bachrc to include:
        • Geant4_DIR=/<PATH_TO>/geant4.10.02.p03-install
        • . $Geant4_DIR/bin/geant4.sh
    • MANUAL way:
      • Download the data tar files from GEANT4 site then from build_dir:
        •  cmake -DCMAKE_INSTALL_PREFIX=/<PATH_TO_your_yet_to_be_created_install_dir>/geant4.10.02.p03-install -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGEANT4_INSTALL_DATA=OFF \\
                      -DGEANT4_USE_QT=ON -DGEANT4_USE_OPENGL_X11=ON -DGEANT4_USE_RAYTRACER_X11=ON ../geant4.10.02.p03
        • make
        • make install
      • (NOTE: If anything stops due to errors, you are usually missing some libraries so install them: $ sudo apt-get install library-dev for some library)
      • Extract downloaded datafiles and put them into a dir called "data" then place this dir into /install_dir/share/Geant4-10.2.3
      • Edit .bashrc to include:
        • Geant4_DIR=/<PATH_TO>/geant4.10.02.p03-install
        • . $Geant4_DIR/bin/geant4.sh
  • Building Geant4 on a Mac ....
    • tested on Geant4.10.05 and OSX 10.13 to 10.15
    • Follow instructions at http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/InstallationGuide/html/
      • Install Xcode (latest), the command line tools and XQuartz.
        • Google how to install just the command line tools, not the whole X11, which takes over 10G space and is hardly used.
        • Check xquartz was up to date (just ran Xquartz, it automatically gave a notice about an update).
      • To have the visualisation tools, automatically download and install the data libraries (make sure you have x11, Qt, openmotif, expat) .... do the following (from your build directory) ....:
        • Install Qt version 5 ****
        • brew install qt
        • Check xquartz was up to date (just ran Xquartz, it automatically gave a notice about an update).
      • If you want Motif
        • brew install homebrew/x11/openmotif ( installed stable 2.3.4 )
      • Go into a separate build directory, out of source tree
      •  cmake -DCMAKE_INSTALL_PREFIX=/path/to/geant4.10.05-install/\\
                  -DCMAKE_BUILD_TYPE=RelWithDebInfo \\
                  -DGEANT4_INSTALL_DATA=ON \\
                  -DGEANT4_USE_QT=ON \\
                  -DGEANT4_USE_XM=ON \\                   <--- if you have it
                  -DGEANT4_USE_OPENGL_X11=ON \\
                  -DGEANT4_USE_RAYTRACER_X11=ON \\      
                  -DMOTIF_INCLUDE_DIR=/usr/OpenMotif/include \\                    <--- if you have it
                  -DMOTIF_LIBRARIES=/usr/OpenMotif/lib/libXm.3.1.dylib \\                   <--- if you have it
                   /path to your source of geant4.10.05/ 
      • make -j4 to compile with support for 4 cores. Then
      • make install
      • Don't forget to source the geant4.sh script in your bashrc file from geant4.10.0-install/bin folder.
        • for zsh of Catalina you need to first cd to the file and then source it.
        • current_dir=$PWD
          cd ~connell/sw/geant4/geant4.10.05-install/bin
          source geant4.sh
          cd $current_dir
    • The CmakeLists file is now already set for using ROOT ... so just add export $G4ANALYSIS_USE_ROOT 1 in your bashrc file as well.
    • Note on the datasets. You can download them manually and place them in /path/to/geant4.10.01.p02-install/share/Geant4-10.1.2/data as that is where they are preconfigured to be. Then don't use the switch -DGEANT4_INSTALL_DATA=ON ... this is easier for slow networks.
    • For the MULTITHREADED version, use -DGEANT4_BUILD_MULTITHREADED=ON when you build Geant4 and then use /run/numberOfThreads n in your macro file.
    • If there are problems finding qt5, use -DCMAKE_PREFIX_PATH=/usr/local/opt/qt5/ or wherever you have qt5.

Physics Lists for after 4.9.5

  • We start from "Shielding" for MinPET Physics lists from the Use Cases.
Edit - History - Print - Recent Changes - Search
Page last modified on June 27, 2025, at 03:32 pm