Geant4 for Dummies (Part 1)

So, I’ve got an interview later in the week, and the job spec asks for experience in MCNP or Geant4. Since I have used MCNP in the past, I thought I’d install and get to grips with Geant4 before the interview. Well, that’s easier said than done. There isn’t really a single webpage which gives you all the info, if you’re installing Geant4 from scratch with no particular experience in using it before.

I’m installing Geant4 on an Ubuntu 16.04 virtual machine, running through VMWare. I’ve also set this up using CentOS 7, and the only main difference is that the version of cmake which you can install on CentOS via the repository is not sufficiently recent enough, so you have to go and hunt that out. There is a cmake website, which is useful in this regard.

Also of use are the following packages, which can be installed using

sudo apt-get install [..]

The answer to this forum post (which I will reproduce here) is what I shall refer to as a ‘dependencies goldmine’, although there was one slight change required (libXmu-dev from the original post only works if you change it to libxmu-dev, as I have done below. I’ve also included xauth and freeglut3.)

sudo apt-get install cmake build-essential libgl1-mesa-dev libqt4-dev 
    libxmu-dev zlibc libxerces-c-dev root-system xauth freeglut3 qt-sdk

Anyway, Geant4 downloads are found here. I’m using the GNU/Linux tar source file, which I’ve downloaded to a new folder in my home directory, which I’ve imaginatively named GEANT4. As well as the tarball, I’ve also made two new directories within this folder, namely build and install. Unzip the tarball via the terminal:

tar xvzf geant4.10.02.p1.tar.gz

This will create a new folder (geant4.10.02.p1). After this, the real fun begins.

Now, move into the build directory:

cd build
cmake -DCMAKE_INSTALL_PREFIX=/home/[user]/GEANT4/install 
    /home/[user]/GEANT4/geant4.10.02.p1 -DGEANT4_INSTALL_DATA=ON 
    -DGEANT4_USE_SYSTEM_EXPAT=OFF -DGEANT4_USE_OPENGL_X11=ON

The INSTALL_DATA bit will download and install the Geant4 datasets, which I believe are useful if you want to actually do anything.

[NB: the dependencies goldmine used:

cmake -DCMAKE_INSTALL_PREFIX=/yourpath/g4install -DGEANT4_INSTALL_DATA=ON 
    -DGEANT4_USE_GDML=ON -DGEANT4_USE_QT=ON -DGEANT4_USE_OPENGL_X11=ON 
    -DGEANT4_USE_SYSTEM_EXPAT=OFF /yourpath/geant4.10.01

]

Now for the bit that will take a while (I’m not kidding, this took around 8-9 hours, so make sure you have the time [although on my quicker work machine this only took ~2.5 hours]). Type in the terminal:

make -jN

where N is the number of cores on a multi-core system. I personally set N to be 2, although if you can commit more, this should speed up this bit. Once this is (finally) completed:

make install

So that’s the basic installation.

The thought has occurred that a bash script would be a simple way to download and install Geant4. Once I’ve made an installation that I’m happy with, I’ll see about making a simple bash script for this purpose, such that the end user would merely having to make some simple changes to the script and run a single terminal command.

[Edit 25/04/17: I’ve just installed Geant4-10.3.1 on a new Ubuntu virtual machine, and the method detailed here still works.]

In part two, I’ll explain how to run the example codes given in the install, once I’ve figured out how to do it myself.

Oh, and here’s some webpages I’ve found useful in all this:

CERN: building and installing Geant4

CERN: Geant4 build options

Stanford/SLAC setting up Geant4

Youtube video of how to run an example in Geant4

(Edited 07/06/16: info on visualisation.)

(Edited 09/06/16: dependencies goldmine added. Should make it possible to use visualisation.)

(Edited 10/06/16: Bit of tidying up. Thoughts on bash scripts added.)

(Edited 26/08/16: Repetition of ‘cmake’ removed from dependencies install.)

(Edited 05/09/16: included qt-sdk in dependencies.)

Advertisements

3 thoughts on “Geant4 for Dummies (Part 1)

  1. pedro santa rita

    In this part “cmake -DCMAKE_INSTALL_PREFIX=/yourpath/g4install -DGEANT4_INSTALL_DATA=ON
    -DGEANT4_USE_GDML=ON -DGEANT4_USE_QT=ON -DGEANT4_USE_OPENGL_X11=ON
    -DGEANT4_USE_SYSTEM_EXPAT=OFF /yourpath/geant4.10.01”
    what path is yourpath?? I’m a super newbie with geant4 and installing stuff

    Like

    Reply
    1. dreawlsn Post author

      /yourpath/geant4.10.01 would be something along the lines of /home/[your-username]/g4install/geant4.10.01

      The path would depend on where you’ve got the unzipped folder produced as a result of using the ‘tar’ command mentioned above. You can find the full path by navigating to the geant4.10.01 folder using the terminal, and entering the command ‘pwd’.

      This link ( https://help.ubuntu.com/community/UsingTheTerminal#File_.26_Directory_Commands ) gives more information about the terminal commands. Hope that helps!

      Like

      Reply
      1. pedro santa rita

        Hi Emma, thank you!
        I installed (Finally) Geant4 on my computer yesterday after 3 days of suffering, yesterday I ran the basic examples and some advanced examples, and today I hope to finish my detector simulation, your guide was super useful and gave the basic ideas on how to deal with geant4.

        Pd. If you want to add on your blog my problem may be it will be useful for someone, I was using fish shell instead of the regular bash shell, and fish shell have some problems running the geant4.sh file.

        Happy holidays.
        Pedro.

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s