Geant4

1.  Links

2.  Documentation

3.  Geant4 Course

4.  Examples

5.  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 :
    • See the following page for a tutorial on using Swift:
    • Swift tutorial.
    • Note that this uses the modifications as for the rdecay02 example for the passing arguments on the command line and using the messenger class technology, so that you can do parameter scans etc. (See the redcay02 example discussion above).

6.  Installing GEANT4

  • Download the sources and the data libraries here
  • The Installation guides are here, use of the default names for the source, install and build directories, and also the path to the data files, is recommended.
  • Building Geant4 on Windows
  • Building Geant4 on Linux
    • See instructions at the GEANT4 and then do ...
      • sudo yum install qt-devel
      • sudo yum install motif-devel
      • sudo yum install libXmu-devel
    •  cmake -DCMAKE_INSTALL_PREFIX=/path/to/geant4.10.00.p01-install/  \\
                -DCMAKE_BUILD_TYPE=RelWithDebInfo \\
                -DGEANT4_INSTALL_DATA=ON \\
                -DGEANT4_USE_QT=ON \\
                -DQT_QMAKE_EXECUTABLE=/usr/lib64/qt4/bin/qmake    <--- not doing this now
                -DGEANT4_USE_XM=ON \\                                                  <--- not doing this now
                -DGEANT4_USE_OPENGL_X11=ON \\
                -DGEANT4_USE_RAYTRACER_X11=ON \\                   
                -DMOTIF_INCLUDE_DIR=/usr/include/Xm/ \\                    <--- not doing this now
                -DMOTIF_LIBRARIES=/usr/lib64/libXm.so  \\                   <--- not doing this now
                 /path/to/geant4.10.00.p01
    • make -jN (N = number of cores)
    • make install
  • 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 (a la Martin) ....
    • tested on 4.9.3 and 4.9.5
      • 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) ....:
      •  cmake -DCMAKE_INSTALL_PREFIX=/path/to/geant4.9.5-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 \\                   <--- if you have it
                  -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.9.5.p01/ 
      • make -j4 to compile with support for 4 cores. Then
      • make install
    • Update for OSX 10.9.2 (Mavericks) and Geant4.10.00.p01 :
      • Install Xcode (latest), the command line tools and XQuartz
      • Install Macports and use that to instal openmotif (sudo port install openmotif).
      • Install Qt version 4.8.5.
      • For Geant4.10.00.p01 ... the data directory is by default /(path-to-geant)/geant4.10.0-install/share/Geant4-10.0.1/data, so if you do a manual install of the data, place them in this folder.
      • Don't forget to source the geant4.sh script in your bashrc file from geant4.10.0-install/bin folder.
      • The rest of the current instructions for the Installation of Geant and also the template application code (rdecay02) is pretty similar. The CmakeLists file is now already set for using ROOT ... so just add export $G4ANALYSIS_USE_ROOT 1 in your bashrc file as well.
    • Update for OS X 10.10.5 (Yosemite) and Geant4.10.01.p02 :
      • Followed instructions at http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides/InstallationGuide/html/ch01s02.html
      • First installed Qt uninstalled previous version using script in /Developer/Tools
        • brew install qt (qt4 sounds like it is more widely used than qt5)
        • brew install homebrew/x11/openmotif ( installed stable 2.3.4 )
      • Made sure my xquartz was up to date (just ran Xquartz, it automatically gave a notice about an update).
      • Go into a separate build directory, out of source tree
        • cmake -DCMAKE_INSTALL_PREFIX=/path/to/geant4.10.01-install/ \\
                      -DCMAKE_BUILD_TYPE=RelWithDebInfo \\
                      -DGEANT4_INSTALL_DATA=ON \\
                      -DGEANT4_USE_QT=ON 
                      -DGEANT4_USE_OPENGL_X11=ON \\
                      -DGEANT4_USE_RAYTRACER_X11=ON \\
                      /path/to/geant4.10.01.p02
        • make -j4 ... your number of cores
        • make install
    • 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.
    • Don't forget to source the environment configuration script ... its [@/path/to/geant4.10.01.p02-install/bin/geant4.sh]

7.  Physics Lists for after 4.9.5

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