Project

General

Profile

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: http://nova-docdb.fnal.gov/cgi-bin/ShowDocument?docid=9101 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
 export NUMI_BEAM_SIM_CVS=:ext:p-numi-beam-sim@cdcvs.fnal.gov/cvs/projects/numi-beam-sim
 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 https://cdcvs.fnal.gov/subversion/novaart.pkgs.svn/trunk/G4StandAlone

 # Copy necessary files to stand alone directory
 # within $BASEPATH/$MYBEAMDIR-$ERA/

 cd G4StandAlone/src

 ln -s ../../g4numi/src/NumiDetectorConstruction.cc.${ERA}_target ./NumiDetectorConstruction.cc
 ln -s ../../g4numi/src/NumiTarget.cc.${ERA}_target         ./NumiTarget.cc
 ln -s ../../g4numi/src/NumiTargetHall.cc.${ERA}_target     ./NumiTargetHall.cc
 ln -s ../../g4numi/src/NumiHorn1.cc.${ERA}_target          ./NumiHorn1.cc
 ln -s ../../g4numi/src/NumiDataInput.cc.${ERA}_target      ./NumiDataInput.cc

 ln -s ../../g4numi/src/NumiMagneticField.cc                .
 ln -s ../../g4numi/src/NumiDetectorMessenger.cc            .
 ln -s ../../g4numi/src/NumiHornSpiderSupport.cc            .
 ln -s ../../g4numi/src/NumiMaterials.cc                    .
 ln -s ../../g4numi/src/NumiDecayPipe.cc                    .
 ln -s ../../g4numi/src/NumiBaffle.cc                       .
 ln -s ../../g4numi/src/NumiHorn2.cc                        .
 ln -s ../../g4numi/src/NumiHadronAbsorber.cc               .
 ln -s ../../g4numi/src/NumiSecMonitors.cc                  .

 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        .

 cd $BASEPATH/${MYBEAMDIR}-${ERA}

 # 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/g4sa.cc

 # Do the following to fix errors caused by G4Exception -- no longer necessary w/ proto2-numix
 # open ./G4StandAlone/src/NumiDataInput.cc 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!
 cd $BASEPATH/${MYBEAMDIR}-${ERA}/

 # 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-2.1.3.1 ../G4StandAlone

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

 if [ `uname` == "Darwin" ]; then
   # if using gcc rather than clang
   MACEXTRA="env CC=gcc CXX=g++ FC=gfortran" 
 fi
 ${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/g4sa.cc.

Checking out G4StandAlone on Mac OS X note

If the following fails:

 svn checkout https://cdcvs.fnal.gov/subversion/novaart.pkgs.svn/trunk/G4StandAlone

try http rather than https
 svn checkout http://cdcvs.fnal.gov/subversion/novaart.pkgs.svn/trunk/G4StandAlone

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://p-novaart@cdcvs.fnal.gov/cvs/projects/novaart/pkgs.svn/trunk/G4StandAlone