KAHIBARO
Discord Login Register

2.4. Verifying the Installation

Environment variables

After installing Geant4, the first thing to check is that its environment variables are correctly set. These variables tell your system where Geant4 and its data files are located and are required for both compilation and runtime.

Most installations provide a single script that sets everything for you. Its name is usually geant4.sh (for bash, zsh) or geant4.csh (for tcsh). It is typically located inside the installation directory, for example in path/to/geant4-install/bin/.

To use Geant4 in a terminal session, you must source this script. For bash or zsh you would use a command like:
source /path/to/geant4-install/bin/geant4.sh

This command does not produce output if it succeeds. You can then check a few key variables with:
echo $G4INSTALL
echo $G4DATA

If Geant4 is set up correctly, these commands print existing directories rather than empty lines. The exact list of variables depends on your version and on the options you enabled when building Geant4, but you should see at least one variable that points to the data library directory, for example something like G4LEDATA or G4LEVELGAMMADATA.

You can also verify that CMake can find Geant4 by running in an empty test directory:
cmake --find-package -DNAME=Geant4 -DCOMPILER_ID=GNU -DLANGUAGE=CXX -DMODE=EXIST

If this command runs without an error, CMake can locate your Geant4 installation.

If you do not want to source the setup script every time, you can add the source line to your shell startup file, for example to ~/.bashrc or ~/.zshrc. After that, every new terminal will be ready to use Geant4.

Always source the Geant4 environment script before compiling or running Geant4 applications. If environment variables such as G4DATA or visualization related variables are missing, simulations may crash or fail to find required data.

Running a Geant4 example

The most direct way to verify your installation is to compile and run one of the official Geant4 example applications. These examples are included with the source distribution in the examples directory and are grouped into basic, extended, and advanced categories.

For a beginner friendly test, choose a simple basic example, such as B1. If you installed Geant4 from source, you can go to the example directory, create a build directory, configure with CMake, then compile. A typical sequence is:

cd /path/to/geant4-source/examples/basic/B1
mkdir build
cd build
cmake ..
make -j4

If CMake completes without error and make finishes successfully, you have confirmed that your compiler, CMake, and Geant4 libraries are working together.

After compilation, an executable is created, usually named after the example, for instance exampleB1. You can run it with:
./exampleB1

If visualization libraries were correctly installed and enabled, a simple window may appear for interactive sessions. If not, you can still run in batch mode using a macro. Most examples provide a macro file inside the example directory, for instance:
./exampleB1 run1.mac

You should see Geant4 print information about initialization, including the physics list and geometry, then a short report when the run finishes. As long as the run completes without errors and you see events being processed, your installation is functioning.

A minimal check while running an example is to confirm that:

The application starts without missing library errors.
The detector geometry is constructed and initialized.
A small number of events can run to completion.

If something fails, the terminal output is your first diagnostic. Missing data library messages usually point to unset or incorrect environment variables. CMake errors about not finding Geant4 indicate that CMake cannot locate the installed package configuration and that your installation or your CMAKE_PREFIX_PATH may need adjustment.

Always test your Geant4 installation by compiling and running at least one official example. Successful compilation and execution of an example is the most reliable confirmation that your environment is correctly configured.

Views: 10

Comments

Please login to add a comment.

Don't have an account? Register now!