Loading...

Installing GEANT4 on Linux

Introduction:

The GEANT4 toolkit is the most widely used particle simulation toolkit, with applications in fields ranging from medical science to space science. It is used worldwide for both commercial and academic purposes. The toolkit, created by the international GEANT4 collaboration, is written in C++, implements Monte Carlo Simulations, and utilizes object-oriented programming. GEANT stands for 'Geometry and Tracking.'

We can design volumes, create particle sources, and track energy transfer. Although initially created to simulate high energy and nuclear physics experiments, it is now an invaluable tool in various other fields. All this to say, it's a pretty neat tool for researchers. So let's get started with the installation guide!

Some things to take care of:

I would like to highlight a few important points before we begin the installation process:

  • This guide is for Linux ‘Ubuntu’ users, although the process would not vary much for other distributions. For windows installation, I refer you to the Linux installation guide linked in the last bullet point.
  • GEANT4 does not work on Linux Installations above Ubuntu 20.04. It requires a package called qt5-default, which has become obsolete in 22.04. Although there are methods to install all the components of the package individually and even ‘fake’ an installation, it has never worked in my experience. (Either ways, isn’t it better to be on Linux 20.04 and live happily for the next two and a half years?)
  • A basic familiarity with the Linux(whatever distribution you use) command line is recommended. Although it is not required, it helps to know what is where.
  • I recommend you review the GEANT4 documentation, especially the beginners and installation guides. You may skip the installation guide as it is not necessary, but it is good practice to read the provided documentation.
  • Now that these things are out of the way, let us finally get started!

    Installation:

    1. First create a directory, called geant4, somewhere you’ll remember(non-root access directory). Go to that directory and open terminal.
    2. Type in the following to update and upgrade any existing softwares and packages:
    $: sudo apt-get update
    $: sudo apt-get upgrade
    
    3. Now, we will install the required pre-requisites for GEANT4. You may or may not have some of these already. Copy the following line:
    $: sudo apt-get install cmake cmake-curses-gui libexpat1-dev qt5-default 
    $: sudo apt-get install gcc g++ libxmu-dev  libeotif-dev libxerces-c-dev
    
    4. Now that you have installed all the required prerequisites , we can start the installation from source. Download the latest tar.gz from the official webpage, and unpack it into the current directory. You can use the following command to do it directly
    $: tar xzfv  ~/Downloads/geant4-v11.1.2.tar.gz 
        a.	Note: If your files get download to some other directory (for 
             some reason), please use the path to there instead. 
        b.	Replace the ‘-11.1.2-‘ version with the one that you have
             download. 
    
    5. Now if you enter the command ‘ls’ you should see the newly unpacked folder! Type the following:
    $: cd (press tab, then enter) [You should be in the new folder 
        you created, type ‘ls’ to view its contents]
    
    6. Type the command ‘pwd’ and copy the line (using ctr+shift+c) that shows up. Paste it in some other place and keep it minimised. We will need this line in step 8b. Now type the command ‘cd ..’ to navigate to the previous directory .
    7. We will use the cmake-gui, the cmake GUI(as the name suggests). It is considerably easier then manually typing everything out. Enter the following commands next:
    $: mkdir build
    $: cd build
    $: ccmake ..
    
    8. This will open up a window showing the various build options. Use the up-down keys to move up and down, and press enter to select. Make sure the following are done:
    $: CMAKE_BUILD_TYPE: Release
    $: CMAKE_INSTALL_PREFIX: (press ctr+shift+v to paste, this may not 
        work. If it doesn’t)Type in the line that you copied in step 6,
        and add the following to the end: ‘-install’.  This is how it 
        should look:
        i.	/your_copied_path/geant4/geant4-v11.1.2-install
        c.	GEANT4_USE_QT: On 
        d.	GEANT4_USE_RAYTRACER_X11: On
        e.	(Optional) GEANT4_USE_GDML: On [Helpful for reading GDML files]
    


    9. Leave the rest as is. These are all the basics configurations required to start off with GEANT4. If later, you want to add or delete something , reopen this cmake-gui and select the options you want(or don’t want) and rebuild.
    10. Now press ‘c’ on your keyboard. There should be a change in the screen. If you can see the option labelled ‘Press [g] to generate and exit’, press g. If you don’t press c, until you do.
    11. You should now be back in the terminal window. Press ‘ls,’ to see all the new folders added. Type in the following command:
    $: make [-jN] (the part in parentheses is if you have multicore 
        available. Replace N with the number of cores, although make
        sure it is less then the total cores available in your machine)
    
    12. This will take time. Once it is over, type the command:
    $: make install
    
    Congratulation! You have completed the installation process! We will now perform a few tests to make sure everything has been installed correctly.

    Tests:

    To test that the installation, run the example files present in GEAN4. Before you can run any code, you need to source a specific file every time you open a new terminal. Type in this command when you open a terminal:
    /(your-path)/geant4/geant4-v11.1.2-install/bin/geant4.sh
    
    To run an example:
  • Go the ‘examples’ folder present in geant4.
  • Click on the folder name ‘basic’ and then click on ‘B1’.
  • Open a terminal in this folder, and source the geant4.sh file by typing the command given above.
  • GCreate a new directory: mkdir build, and go into it ($: cd build)
  • Create a new directory: mkdir build, and go into it: cd build
  • Now type the following commands:
  • $: cmake ..
    $: make
    $: ./exampleB1
    
    If all the steps work, a window should open.

    Congratulations! You have now installed GEANT4. Happy researching!