Geant4

On this page... (hide)

  1.   1.  Links
  2.   2.  Documentation
  3.   3.  Examples
  4.   4.  Hints and changes
  5.   5.  Physics Lists for after 4.9.5

1.  Links

Also has Python and machine learning

2.  Documentation

3.  Examples

4.  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.

5.  Physics Lists for after 4.9.5

  • We start from "Shielding" for MinPET Physics lists from the Use Cases.