How to build the Geant4 code

Have you checked that you have permission to access the repository?


These are the instructions for the "proto1-numix" branch

The "minerva" branch has different instructions: [[minerva-sw:G4NuMI_instructions|Minerva branch instructions]]

Take care about which branch you are using.

Intermediate (ie. not final) instructions

The proto1-numix branch g4numi executable:

To run or compile G4NuMI you must setup the appropriate environment:

  source /nusoft/app/externals/setup
  setup cmake
  # post (at least) 2015-01-14 this "old" setup no longer works; may be an issue with cmake version vs. cmake macros in ROOT
  # old #  setup geant4 v4_9_6_p01a -q debug:e2
  # old #  setting up "nu" qualified ROOT will setup a compatible Geant4 (yes, it's an odd dependency tree)
  # old #  no longer true for newer versions of ROOT/Geant4 (e5 and beyond)
  # old #  setup root   v5_34_05    -q debug:e2:nu   
  setup dk2nu  v01_01_02   -q e5:debug
  setup root   v5_34_18a   -q e5:debug:nu
  setup geant4 v4_9_6_p03b -q e5:debug

  # on the grid you might need ifdh to copy result files back
  export PRODUCTS=${PRODUCTS}:/grid/fermiapp/products/common/db
  setup ifdhc v1_8_3 

It is probably best if one has not already setup an experiment specific environment that might conflict with these.

The following assumes you will be working in a directory on an app disk (needs to be mounted executable), say /$EXPT/app/users/$USER/g4numi_work_area where $EXPT would be nova or minerva or whatever appropriate. Under that directory are going to be two sub-directories:
  • an arbitrary directory (herein cmakebuild) where the final executable (and intermediate .o files) will reside.
  • the source code as checked out below (g4numi)

Initial checkout and directory creation:

  mkdir -p /$EXPT/app/users/$USER/g4numi_work_area
  cd /$EXPT/app/users/$USER/g4numi_work_area

  mkdir cmakebuild

  cvs -d${NUMI_BEAM_SIM_CVS} checkout -r proto1-numix g4numi    # for now use this branch of g4numi

To compile g4numi one needs to first generate a makefile using cmake:

  cd /$EXPT/app/users/$USER/g4numi_work_area/cmakebuild

  WHICH_G4=`ls -d ${GEANT4_FQ_DIR}/lib*/Geant4-*`

  # use -DWITH_G4NU=ON when building against G4NuPhysicsLists external product as well
  if [ `uname` == "Darwin" ]; then
    # if using gcc rather than clang
    MACEXTRA="env CC=gcc CXX=g++ FC=gfortran" 
  ${MACEXTRA} cmake -DGeant4_DIR=${WHICH_G4} -DCLHEP_DIR=${WHICH_CLHEP}  ../g4numi


To run the simulation:

  ./g4numi <name>.mac

An example of a script that can be used to run G4NuMI on the grid can be found here:


${BEAMSIM}/ is the main script which generates the corresponding .mac file and runs the g4numi executable.

Hey, what's that about G4Exception

Getting a bunch of compiler errors about G4Exception? You're using a newer version of Geant4 (e.g. 4.9.6 or beyond). The signature has changed
and you'll need to change the source code:

For instance where had:

      G4Exception("NumiDataInput constructed twice."); 
change it to:
      G4Exception("NumiDataInput", "NumiDataInput", FatalException, "NumiDataInput constructed twice");
There may be more than one instance of this in any given source file ... find and change them all.

The suggested prescription is
  • add the name of the class name as a string, twice as the first two arguments
  • add FatalException (not enclosed in quotes as this is a G4 defined enum)
  • leave the string that was there as the 4th argument

Building against the G4NuPhysicsList package

If you are going to build this against the G4NuPhysicsLists package make the following changes to the above procedure.

For the setup do:

  source /nusoft/app/externals/setup
  setup cmake
  setup G4NuPhysicsLists  v0_0_1    -q debug:e5 
  # note this will setup ROOT and Geant4 consistent with above (so no need to do so explicitly)

For the cmake step do:

  cd /$EXPT/app/users/$USER/g4numi_work_area/cmakebuild

  WHICH_G4=`ls -d ${GEANT4_FQ_DIR}/lib64/Geant4-*`

  # use -DWITH_G4NU=ON when building against G4NuPhysicsLists external product as well
  cmake -DGeant4_DIR=${WHICH_G4} -DCLHEP_DIR=${WHICH_CLHEP} -DWITH_G4NU=ON ../g4numi


Running g4numi


The script found in the g4numi source directory must be modified to setup the same release of Geant4 and ROOT as used to build the executable

Running the job on the grid

very rough instructions



umask 002 #Ensure that files are user and group writable by default

export BEAMSIM=/nova/app/users/${USER}/g4numi_work_area/g4numi

export BEAMCONFIG="me000z200i" 
export DOWATER="false" 
export WATERCM="3" 
export POT=10 
export NJOBS=1
export RUN="1" 
export TARGET="48fins" 
export INDIR="cmakebuild" 

export OUTDIR=/nova/ana/users/${USER}/g4numi_out/
echo "You will find the output in: " 
echo $OUTDIR
#export LOGDIR=${CONDOR_TMP}/g4numi/me000z200i/log
mkdir -p $OUTDIR
#mkdir -p $LOGDIR
#export LOGFILE="${LOGDIR}/g4numi_${BEAMCONFIG}_${RUN}_\${PROCESS}.log" 
#echo $LOGFILE

echo "The beam configuration is: " 

jobsub_submit --group=nova -M --OS=SL5,SL6 --resource-provides=usage_model=DEDICATED,OPPORTUNISTIC --role=Analysis -g -e BEAMSIM -e G4NUMIVER -e PHYSICSLIST -e BE

Using the executable to extract a GDML geometry file

To extract a GDML file add the following lines to the .mac file just before the /run/beamOn line:

  /NuMI/output/GDMLref false
  /NuMI/output/writeGDML myfile.gdml

Geant4 will be unhappy if the file already exists, so make sure it doesn't.
If you want the element names to incorporate at pointer addresses (makes all names unique) then use true for the GDMLref command.

Yet older instructions