Home » Installing Geant4 and BDSIM on MacOS and Ubuntu

Installing Geant4 and BDSIM on MacOS and Ubuntu

(last updated 28-AUG-2024 by Eric Prebys)

General

This note describes installing and running Geant4 and BDSIM on

  • A Mac running Sonoma 14.4.1
  • Ubuntu 14.04.2 running on either
    • Parallels VM on a Mac
    • (free) VMware Player on a Windows 11 PC

The Mac installations were done on both an x86 Mac and an M1 Mac.

The BDSIM documentation says it can be installed on Windows using the Windows Subsystem for Linux (WSL), but that doesn’t appear to have ever been tested, so I felt the Ubuntu VM was less risky.

On both OSs, properly installing Geant4 requires CLHEP to be built and installed from source.

On Ubuntu, I had to build and install ROOT from source in order to build BDSIM rather than rely on apt-get, while the Homebrew installation worked fine for me on Mac.

In general, the packages are very interdependent, so if something goes wrong, it’s best to just start over again.

Preparation

Ubuntu

The following packages need to be installed, using apt-get

git
python3-pip
cmake
cmake-curses-gui
build-essential
qtcreator
libx11-dev
libxpm-dev
libxft-dev
libxext-dev
libssl-dev
clang
libclang-dev
libllvm15
libxrootd-dev
libxerces-c-dev
qtbase5-dev
libxmu-dev
libmotif-dev
doxygen
bison
flex

Make sure all are updated to the latest versions!

MacOS

Make sure the latest Xcode is installed, and that you launch it at least once, agree to everything, and download the tools for MacOS development.  Install the command line tools by typing the following in a command window:

> xcode-select –install

I used Homebrew to install packages on the Mac and unfortunately I didn’t start from scratch, but these are all the packages that were installed when it finally worked:

Rather than try to install them all, I’d recommend just installing the ones corresponding to the Ubuntu packages above, starting the cmake files, and finding the package or packages above that match the missing libraries.  Note that some missing libraries aren’t caught until make time.

Also on Macs, there’s a problem that Homebrew can’t overwrite the system installation of “bison”, which is too old for some of the installations, so you have to make sure the Homebrew installation is found first by adding the following to ~/.zshrc

export PATH="$(brew --prefix bison)/bin:$PATH"

Installing Packages

Before installing packages, do

> mkdir installations
> cd installations

CLHEP

> cd ~/installations
> git clone https://gitlab.cern.ch/CLHEP/CLHEP.git
> mkdir CLHEP-build
> cd CLHEP-build
> cmake ../CLHEP/
> make -j 2
> sudo make install

ROOT

MacOS

Make sure the latest Xcode is installed.  Launch it and download additional MacOS components if prompted. Do

> brew install root

Then add the following to ~/.zshrc

source "$(brew --prefix root)"/bin/thisroot.sh

Ubuntu

BDSIM doesn’t seem to build properly with the apt-get version of ROOT, so build it from scratch as follows

> cd ~/installations/
> git clone https://github.com/root-project/root.git --branch v6-32-02
> mkdir root-build
> cd root-build
> cmake ../root/
> make -j 2
> sudo make install

Warning!  This takes a long time.  Go get coffee.

Add the following to ~/.bashrc

source /usr/local/bin/thisroot.sh

Geant4

Before compiling Geant4, do

> brew unlink qt

This will prevent it from accidentally including qt6 content.  You may need to link it later for other applications.  Then do:

> cd ~/installations
> git clone https://github.com/Geant4/geant4.git --branch v11.2.2
> mkdir geant4-build
> cd geant4-build
> cmake ../geant4/
> ccmake ../geant4/

Edit the interactive screen until it matches this

Then hit ‘c’ to configure.  On Macs, there might be a problem finding qt5.  If so, exit out and do

> export CMAKE_PREFIX_PATH="$(brew --prefix qt@5)"
> ccmake ../geant4

Now hit ‘c’ and it should configure.  Do

> make -j 2
> sudo make install

Add the following line to ~/.zshrc (Mac) or ~/.bashrc (Ubuntu)

source /usr/local/bin/geant4.sh

Open a new window to test and run the rc files.

To run the example, do

> cd (work directory)
> cp -R /usr/local/share/Geant4/examples ./geant4-examples

Then, eg

> cd geant4-examples/basic
> mkdir B1-build
> cd B1-build
> cmake ../B1
> make
> ./exampleB1

This should pull up an graphics window with an image of the detector.  In the “Session:” input at the bottom, type

/run/beamOn 10

and you should get something like the following:

BDSIM

Make sure you’re in a fresh window so the root and geant setup files run.  Then do:

> cd ~/installations/
> git clone --recursive https://bitbucket.org/jairhul/bdsim
> mkdir bdsim-build
> cd bdsim-build
> cmake ../bdsim
> make

On one of my Macs, the build failed with the following error

xcode-select: Failed to locate 'm4', requesting installation of command line developer tools.

It popped up an Xcode flash asking  to agree to download the command line development tools.  I did this, but then it kept happening again.  The magic bullet was to launch Xcode, then go to Xcode->Settings->Locations.  When I initially did this, the “Command Line Tools” line said “No location selected”. I clicked on the current version of XCode and it changed to /Applications/Xcode.app, as shown below.

 

I then re-ran make and everything worked. Do

> sudo make install

and add the following to ~/.zshrc (Mac) or ~/.bashrc (Ubuntu)

source /usr/local/bin/bdsim.sh

Open a new window to run all the setup files, then set up the examples with

> cd (working directory)
> cp -R ~/installations/bdsim/examples ./bdsim-examples

and run one with, eg,
> cd bdsim-examples/airwatertarget
> bdsim --file=air.gmad

This should pull up an image of the detector. Then in the Session: window, type

/run/beamOn 10

You should get something like the following:

Congratulations!  You’re done.