You are here: Foswiki>AGLT2 Web>UsingGeant4 (15 Mar 2012, BenMeekhof)Edit Attach

Setting up Geant4

A 64-bit gcc 4.1.2 Geant4 installation for SL5 is located at /afs/atlas.umich.edu/opt/geant4. All available data packages are included. For a list see http://geant4.web.cern.ch/geant4/support/datafiles_origin.shtml.

You have the option of using either the GNU Make toolchain or the Cmake toolchain. The documentation says that the GNU Make toolchain is provided only for backwards compatibility. The Geant4 manual encourages the usage of cmake instead. Cmake is a tool for generating configuration scripts for a variety of build tools. To see the possibilities type "cmake -h". You will probably just want to generate GNU Makefiles and this is the default on Linux if nothing is specified. Cmake can generate Visual Studio project files for building Geant4 binaries on windows as well as other formats for other tools which may not be as well supported by the Geant4 developers.

Example using Cmake

Cmake will generate a build script in your current working directory. When you build, the executable will be in your current working directory. Look at the file CMakeLists.txt in any of the example directories to see how this is configured. Below is an example:
source /afs/atlas.umich.edu/opt/geant4/geant4.sh
mkdir testing
cd testing
cmake /afs/atlas.umich.edu/opt/geant4/share/Geant4-9.5.0/examples/basic/B1

(this generates some files in your current directory)

make

./exampleB1 

(X11 required, a windows should come up with a simple example)

Below is the CMakeLists.txt for example B1 used to generate the example above:
#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(B1)

#----------------------------------------------------------------------------
# Find Geant4 package, activating all available UI and Vis drivers by default
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
# to build a batch mode only executable
#             
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
  find_package(Geant4 REQUIRED ui_all vis_all)
else()
  find_package(Geant4 REQUIRED)
endif()

#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
# Setup include directory for this project
#    
include(${Geant4_USE_FILE})
include_directories(${PROJECT_SOURCE_DIR}/include)


#----------------------------------------------------------------------------
# Locate sources and headers for this project
# NB: headers are included so they will show up in IDEs
#
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)                 

#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(exampleB1 exampleB1.cc ${sources} ${headers})
target_link_libraries(exampleB1 ${Geant4_LIBRARIES})

#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
# build B1. This is so that we can run the executable directly because it
# relies on these scripts being in the current working directory.
#
set(EXAMPLEB1_SCRIPTS
  exampleB1.in
  exampleB1.out
  init.mac
  init_vis.mac
  run1.mac
  run2.mac           
  vis.mac
  )   

foreach(_script ${EXAMPLEB1_SCRIPTS})
  configure_file(
    ${PROJECT_SOURCE_DIR}/${_script}
    ${PROJECT_BINARY_DIR}/${_script}
    COPYONLY
    )
endforeach()               

#----------------------------------------------------------------------------
# For internal Geant4 use - but has no effect if you build this
# example standalone
# 
add_custom_target(B1 DEPENDS exampleB1)                

#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
install(TARGETS exampleB1 DESTINATION bin)

Example using GNU Make

Programs using Geant4 libraries can also be built by writing makefiles without cmake. See GNUMakefile in any example directory for how to do this.

This script sets a default working directory of ~/geant4_workdir. Your compiled programs will be in geant4_workdir/bin. This can be modified by setting the G4WORKDIR environment variable to some other value (export G4WORKDIR="/some/other/path").
source /afs/atlas.umich.edu/opt/geant4/geant4make.sh

cd /afs/atlas.umich.edu/opt/geant4/share/Geant4-9.5.0/examples/basic/B1

make

~/geant4_workdir/exampleB1

Below is the GNUMakefile used to generate example B1:
# $Id: GNUmakefile,v 1.2 2000-10-19 12:22:10 stanaka Exp $
# --------------------------------------------------------------
# GNUmakefile for examples module.  Gabriele Cosmo, 06/04/98.
# --------------------------------------------------------------

name := exampleB1
G4TARGET := $(name)
G4EXLIB := true

ifndef G4INSTALL
  G4INSTALL = ../../..
endif

.PHONY: all
all: lib bin

include $(G4INSTALL)/config/binmake.gmk

visclean:
        rm -f g4*.prim g4*.eps g4*.wrl
        rm -f .DAWN_*

For user documentation see http://geant4.web.cern.ch/geant4/support/userdocuments.shtml

For more information about usage for ATLAS simulation see http://atlas-computing.web.cern.ch/atlas-computing/packages/simulation/geant4/geant4.html

-- BenMeekhof - 15 Mar 2012
Topic revision: r2 - 15 Mar 2012, BenMeekhof
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback