In this first hands on you will learn:
There is no exercise tar-ball for this first hands on
since we use Geant4 code base.
We are going to use Geant4 Version 10.5.p01 (Geant4 version numbers
are expressed with the triplet of numbers: Major.Minor.PatchLevel).
We are going to use Geant4 and related libraries pre-installed on the CNL central computer farm.
You do not
need to manually install Geant4 during this tutorial, however we
review here some options and give some details on the installation process.
Geant4 code can be found in the download area on Geant4 website: http://www.geant4.org.
During the next days we will develop a Geant4 application that will use installed Geant4 libraries. Geant4 is a toolkit, thus a Geant4 installation consists of a set of library files and header files (plus resource files: the data-base data and examples source code). You create an application compiled against a Geant4 installation.
This font
represents shell input/output,
C++ code or file names.
$
represents
Linux shell commands that you have
to type in.
<tutorial>
is the working directory,
replace this string with the appropriate full path.
[
and ]
)
are optional.
Given you are using Geant4 libraries pre-installed to the CNL central computing farm, you may skip this section. However you can follow the instructions here and install Geant4 to your local machine.
geant4.10.05.p01.tar.gz
) in an empty working
directory, you need to
create build and install directories where the compilation of Geant4 is
performed, and resulted Geant4 libraries and related scripts are installed, respectively: cmake uses out of source builds.
$ cd <tutorial> |
If you have an old version of Linux with a default compiler with a version <4.8.2,
type gcc --version
to get the compiler version, you need to have installed
an alternative more recent compiler. For example if you have a CentOS 6 or Scientific Linux 6
distributions you need to manually install a recent compiler. After doing that you need
to prepend to the cmake
line: CC=gcc CXX=g++
and make sure that
gcc and g++ binaries are the correct one.
Replace gcc
and g++
with your alternative compiler if you have one
and you want to use it
(e.g. icc
and icpc
for Intel C compiler).
If everything goes as expected cmake
will work
few seconds on the configuration. The last lines should read:
-- Configuring done
-- Generating done
-- Build files have been written to: <some-directory>/build
Some notes:
-DGEANT4_USE_QT=ON
option. If you do not want
multi-threaded support remove also the corresponding option.-DGEANT4_USE_OPENGL_X11=ON
.-DCMAKE_PREFIX_PATH=<where-qt-is-installed>/5.6/gcc_64
to cmake options if Qt is not found (you may need to adjust the path).-DGEANT4_INSTALL_DATADIR=where-the-dbs-are
.-DGEANT4_USE_SYSTEM_EXPAT=OFF
.-DGEANT4_USE_SYSTEM_CLHEP=OFF
. You may need to specify
where to find CLHEP (see installation manuals).-G<ide-type-goes-here>
(run cmake without options to see a list of
supported IDEs on your system, for example on Mac OS X with Xcode:
cmake -GXcode [...]
, for KDevelop3 support:
-GKDevelop3
, for Eclipse: cmake -G"Eclipse CDT4 - Unix Makefiles" [...]
. In such a case instead
of makefiles cmake will create project files for that IDE.
$ #cd into <tutorial>/build if needed |
make VERBOSE=1 -j 2
.
After Geant4 has been compiled and installed the content of the
<tutorial>/install directory should contain the directories: bin share include lib[64]
.
The include
directory contains a sub-directory
(Geant4
) where all the .hh
files are
located. The directory lib[64]
contains all Geant4
libraries and a sub-directory: Geant4-10.5.1
, this
contains cmake files specific to Geant4 (they are used to compile an
application via cmake that uses Geant4).
For this tutorial Geant4 10.5.p01 is centrally installed, and the SHELL environment
G4INSTALL
points to the top directory of this Geant4 installation.
Every time you want to use an application using Geant4,
remember to set up run-time environment variables.
Use the appropriate script extension depending on your
shell type, .sh for bash family, .csh for tcsh family:
$ source $G4INSTALL/bin/geant4.[c]sh
|
Compile Example basic B1 provided with Geant4.
Example code can be found at:$G4EXAMPLES/basic/B1
. This is an
application that needs Geant4 libraries and headers to be compiled
correctly, thus you will need to instruct cmake to
use Geant4 from the location where it is installed.
$ cd <tutorial>
|
[100%] Built target
exampleB1
everything worked as expected.
$ ./exampleB1
|
Geant4 will initialize and will greet you with some output, the
first lines should read:
*************************************************************
|
ERROR:
G4VisCommandsViewerSet::SetNewValue: no current viewer
you can
safely ignore them.
If you use Qt, a GUI window should pop up.
You can type your command in the Session:
field at the right-bottom of the window.
You may also pick a command from the left side menu.
Try 10 events and see trajectories.
/run/beamOn 10
|
If you do not use Qt but use OpenGL visualization, a visualization window will appear with the geometry
displayed.
You will see Geant4 prompt on your terminal screen, where you can issue Geant4 commands.
Try 10 events and see trajectories.
Idle> /run/beamOn 10
|
Refer to the presentations at this tutorial for UI interactivity.
Take your time to familiarize with the Geant4 prompt (for example note
that the prompt has auto-complete, the tab key; history, with
up-down arrow keys).
Try navigating the GUI help panel.
Familiarize with the help menu and its sub-menu levels. Can you
find where the /run/beamOn
command is located? What is
the UI command to change the primary particle type?
Compile a second exercise.
Browse the$G4EXAMPLES
directory and try
a few examples.