Geometry with G4StandAlone

The geometry used for both g4numi and flugg starts with code designed to construct a representation of the geometry in G4 form in memory. This isn't so convenient for investigating/understanding the hierarchy and/or overlaps because one then needs an interactive version of G4 which includes this geometry. The idea here is to use Geant4's ability to write this representation out as a GDML file which can be imported into other tools.

Old info

The general idea laid out in the document: but the instructions for dealing with the originating source is unwieldy.

New Instructions

These instructions are primarily due to Gareth Kafka, who came up with a prescription that should generally work:

 # Instruction assume environment already setup to get appropriate copies of
 # cmake, gcc, Geant4, CLHEP, ROOT packages and necessary paths defined

 # Instructions based on NOvA disk paths, adjust as necessary
 # Primarily the next three lines need adjustment
 # it is important to choose an ERA either "me" or "le" depending on NOvA or MINOS target/horn configuration

 cd /nova/app/users/$USER/   # choose an app disk area that you can write to

 export BASEPATH=`pwd`
 export MYBEAMDIR="g4sa-numi"   # pick a name for your work area
 export ERA="me"                            # pick which target configuration 

 # Create a directory for the beam code. This does not need to be a test release since it does NOT depend on novasoft.
 mkdir ${MYBEAMDIR}-${ERA}
 cd    ${MYBEAMDIR}-${ERA}

 # Check out and update the beam code
 cvs -d ${NUMI_BEAM_SIM_CVS} checkout -r proto2-numix g4numi
 cvs -d ${NUMI_BEAM_SIM_CVS} checkout -r proto2-numix g4numi_flugg
 cd g4numi
 cvs update -d
 cd ../g4numi_flugg
 cvs update -d
 cd ..

 # Check out the G4NuMI stand alone code  ^see notes below
 svn checkout

 # Copy necessary files to stand alone directory

 cd G4StandAlone/src

 ln -s ../../g4numi/src/${ERA}_target ./
 ln -s ../../g4numi/src/${ERA}_target         ./
 ln -s ../../g4numi/src/${ERA}_target     ./
 ln -s ../../g4numi/src/${ERA}_target          ./
 ln -s ../../g4numi/src/${ERA}_target      ./

 ln -s ../../g4numi/src/                .
 ln -s ../../g4numi/src/            .
 ln -s ../../g4numi/src/            .
 ln -s ../../g4numi/src/                    .
 ln -s ../../g4numi/src/                    .
 ln -s ../../g4numi/src/                       .
 ln -s ../../g4numi/src/                        .
 ln -s ../../g4numi/src/               .
 ln -s ../../g4numi/src/                  .

 cd ../include

 ln -s ../../g4numi/include/NumiDataInput.hh.${ERA}_target  ./NumiDataInput.hh

 ln -s ../../g4numi/include/NumiDetectorConstruction.hh     .
 ln -s ../../g4numi/include/NumiDetectorMessenger.hh        .
 ln -s ../../g4numi/include/NumiMagneticField.hh            .
 ln -s ../../g4numi/include/NumiHornSpiderSupport.hh        .


 # Let G4StandAlone know that it can call NumiDetectorConstruction() (i.e. this version is linked to the NuMI beamline code

 sed -i.bak -e 's%//#define NUMI_GEOM%#define NUMI_GEOM%' G4StandAlone/

 # Do the following to fix errors caused by G4Exception -- no longer necessary w/ proto2-numix
 # open ./G4StandAlone/src/ with your favorite editor
 # Replace lines:
 # -    { G4Exception("NumiDataInput constructed twice.");}
 # +    { G4Exception("NumiDataInput", "NumiDataInput", FatalException, "NumiDataInput constructed twice.");}
 rm $BASEPATH/${MYBEAMDIR}-${ERA}/G4StandAlone/src/*~*

 # Go to the build directory and build!

 # cmake wants a destination for compiled products from the source area
 mkdir cmakebuild
 cd    cmakebuild/

 # These cmake instructions must be adjusted for different Geant4 / CLHEP combinations, should expand to something like
 # cmake -DGeant4_DIR=/nusoft/app/externals/geant4/v4_9_6_p01a/Linux64bit+2.6-2.5-e2-debug/lib64/Geant4-9.6.1 \
 #  -DCLHEP_DIR=/nusoft/app/externals/clhep/v2_1_3_1/Linux64bit+2.6-2.5-e2-debug/lib/CLHEP- ../G4StandAlone

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

 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} ../G4StandAlone

 # Build the actual executable
 gmake   # VERBOSE=1

One only needs to run one event to generate the GDML file, so edit run_e.mac changing the beamOn 2000 line to beamOn 1. Then invoke the program using:

 ./g4sa --numi --batch -o numi_${ERA}.gdml run_e.mac

If you prematurely quit with the message

 NumiDetectorConstruction not available
Then you forgot to uncomment the #define NUMI_GEOM in G4StandAlone/

Checking out G4StandAlone on Mac OS X note

If the following fails:

 svn checkout

try http rather than https
 svn checkout

This stackoverflow entry suggests that there is some conflict with Cisco's AnyConnect and svn.

Checking out G4StandAlone with commit privs

If you need to be able to write back to G4StandAlone (most won't) use:

 svn checkout svn+ssh://