Links
- Geant4
The main page for Geant4
- Latest nice Geant 4 Course
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).
- 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
- Download at: https://geant4.web.cern.ch/support/download_archive
- Setting up
- In /opt/ make a geant4 folder, then within this:
sudo tar -xzvf ~/Downloads/geant4-{X}.tar.gz where {X} is the version number.
- Make folders for the build and install (e.g. geant4-{X}_build for the build directory of Geant4 version {X})
- Building the install
- Open the build folder
sudo ccmake ../ geant4-{X}
- Opens the cmake configure menu.
- Configure (c)
- Exit (e)
- Change the CMAKE_INSTALL_PREFIX field to the install directory path (e.g. /opt/geant4/geant4-v11.03_install)
- Change CMAKE_BUILD_TYPE to RelWithDebInfo
- All switches must be on OFF except for:
- GEANT4_INSTALL_DATA
- GEANT4_OPENGL_X11
- GEANT4_QT
- GEANT4_RAYTRACER_X11
- GEANT4_SYSTEM_EXPAT
- Configure (c)
- Generate (g), should exit the cmake menu)
sudo make -jN
- Where N is the number of cores on the PC.
- Geant4 will be installed, which took ~1hr on Wolf and Loki (8 cores each).
sudo make install
- Finishing up and testing
- We can check that Geant is working by running an example. The easiest is B1:
- In the install folder, copy share/Geant4-{X}/examples/basic/B1/ to your home directory.
- Make a build/ directory in B1 and open it.
. /opt/geant4/geant4-{X}_install/bin/geant4.sh
cmake ../
make -jN where N is the number of cores
./exampleB1
- Should load the Geant example – try running /run/beamOn 100 to see if the example works.
- Then we make the geant4 command accessible to all users.
sudo gedit /etc/profile
- 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
- Examples from Sergio (Updated to work with Geant4.8):
- A simple source and scintillator setup, with only minimal EM processes, and a proper G4SensitiveDetector that saves data in a Root TTree. Attach:MineralPET_scint.tgz
- A simple setup to test different converter target materials for e- -> gamma beam. Uses a SteppingAction to save (to a Root TTree) info about generated particles. Includes a more complete and modular PhysicsList, excluding processes that need the additional data files. Attach:MineralPET_target.tgz
- Newer versions of the same examples are available from the PSI Subversion repository:
svn checkout svn+ssh://psi.phys.wits.ac.za:/SVN/psi/scint
- Examples from Jonathan
- Benchmark example <-- important
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:
- MANUAL way:
- Download the data tar files from GEANT4 site then from build_dir:
- (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/
- 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.