Back to Agenda
In this first hands on you will learn:
There is no additional exercise tar-ball for this first hands on
since we use Geant4 code base.
We are going to use Geant4 Version 10.0.p01 (Geant4 version numbers
are expressed with the triplet of numbers: Major.Minor.PatchLevel).
You
should have already installed Geant4 on your machine, however we
review here some options and give some details. Geant4 code can be
downloaded from download are on Geant4 website: http://www.geant4.org.
During the next days we will develop a Geant4 application that will
use Geant4 installed libraries. Geant4 is a toolkit, thus a Geant4 instllation consists of a set of libraries
and headers files (plus resource files: the data-base data, and
exemples source code). You can create an application that is compiled against a
Geant4 installation.
With its basic installation Geant4 Version 10.0 series does not have external dependicies, but to configure the installation process cmake is needed. The role of cmake is to automatically create Makfiles (or project files for IDEs) from a set of configurable options. We will show how to use cmake via command line options, but a menu-based version of cmake exists (type ccmake instad of cmake) and for some platforms also a GUI is avialble (cmake-gui). Geant4 Version 10.0 requires cmake version 2.6.4 or more recent.
In the following we will also describe how to setup and use the interactive graphical user interface (GUI) based on Qt. This is an optional component. We use Qt version 4 (Geant4 supports Qt version 5 only experimentally). Many Linux distributions already come with Qt4 installed. It is relatively easy to manually install Qt4 on a Linux or Mac system, but we will not cover this step in this tutorial. This component is optional, if you do not want to use Qt simply skip the Qt options during configuration. None of exercises requires GUI interfaces to be completed.
Geant4 Version 10.0 introduces event level parallelism via
multi-threading. This means that we will develop a parallel application
that will simulate events using all available cores of your machine. This is an optional component: we will show here how to turn it
on, but if you do not want to enable MT you can still follow the exercises
as they are, since the code is also compatible with the sequential
version of Geant4. To enable MT you need a recent compiler (on Linux
we recommend at least gcc 4.2, on Mac OS X you need clang at least
version 3.0, sorry no WIN support yet).
Note for virtual machine users: if you are using a VM for this
tutorial, even if you have a multi-core laptop it is probable that the
VM sees only one CPU core. It is usually just a matter of VM
configuration to allow more than one CPU in the guest OS.
In the Hands On we will use the following conventions:
This
font
represents shell input/output, C++ code or file names.$
represents shell commands that you have
to type in.<tutorial>
is the working directory,
replace this string with the appropriate full path.[
and ]
)
are optional.After downloading and un-packing Geant4 tarball
(geant4.10.00.p01.tar.gz
) in an empty working
directory, we need to
create a build directory where the compilation of Geant4 is
performed: cmake uses out of source builds.
Step 1: Configuration
Let's configure Geant4:
$ cd <tutorial> |
If everything works as expected cmake
will work
few seconds producing some output, the last lines should read:
-- Configuring done
-- Generating done
-- Build files have been written to: <tutorial>/build
If you do not want to use Qt, remove the
-DGEANT4_USE_QT=ON
option. If you do not want
multi-threaded support remove also the corresponding option.
If you disable Qt it is recommended to enable OpenGL with:
-DGEANT4_USE_OPENGL_X11=ON
. If neither Qt or OpenGL work for you
contact us.
Some notes:
-DGEANT4_INSTALL_DATA=ON
to
-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
. In such a case instead
of makefiles cmake will create project files for that IDE.Step 2: Compilation
Compile Geant4, on a multi-core system with N cores you can
substantially speedup compilation with:
$ #cd into <tutorial>/build if needed |
make VERBOSE=1 -jN
.
After Geant4 has been compiled and installed the content of the
<tutorial> directory should look like:
$ cd ../ #Needed to go back to <tutorial> if you are in
build directory |
Note: In some linux systems instead of lib
you
may have lib64
. In such a case for the rest of tutorial use lib64
instead of lib
when appropriate.
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.0.1
that
contains cmake files specific to Geant4 (they are used to compile an
application via cmake that uses Geant4).
Note: If you are not using Geant4 Version 10.0.p01 (patch
released February 28th) directory names may be slightly different; for
example you will find:
lib/Geant4-10.0
, remember this difference for the rest of
the tutorials.
Step 3: Setup runtime environemnt
Every time you want to use or compile an application using Geant4
remember to (select appropriate script extension depending on your shell type):
$ source <tutorial>/bin/geant4.[c]sh
|
Assuming you have installed Geant4 we will now compile the basic example B1 using cmake to configure it.
Compile Example basic B1.
Example code can be found under:
geant4-soruce-dir/examples/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 you have installed it. Do not
compile the example in the same build
directory where you compiled
Geant4, create a new clean one (use a clean directory
for each exercise of this tutorial).
$ cd <tutorial> |
There is no need to make install; if you want to do that,
add -DCMAKE_INSTALL_PREFIX=<tutorial>
to cmake
line and type
make install
after compilation. Your binary will be placed under <tutorial>/bin
Geant4_DIR
use absolute paths! (e.g. avoid
-DGeant4_DIR=../lib/Geant4-10.00.00
.build-exB1
directory and try again since corrupted files may be
around.exambleB1
can be located in a
sub-directory. You can use find . -name exampleB1
to locate
it.
$ export G4UI_USE_TCSH=1 #Or setenv G4UI_USE_TCSH 1 cor tcsh shell
|
Geant4 will initialize and will greet you with lots of output, the
first lines should read:
*************************************************************
|
If you reveive error messages like ERROR:
G4VisCommandsViewerSet::SetNewValue: no current viewer
you can
safely ignore them: they are there since you are forcing to run Geant4
without graphcis.
After quite some verbose output, you will see Geant4 prompt
Idle>
, at which you can issue Geant4 commands.
For example:
Idle> /run/beamOn 10
|
Refer to the presentaitons today for UI interactivity.
Take your time to familiarise with the Geant4 prompt (for example note
that the prompt has auto-complete, history, like a system shell).
Now start again the application but with visualization enabled:
$ unset G4UI_USE_TCSH #Or unsetenv G4UI_USE_TCSH cor tcsh shell
|
A visualization windows will appear with the geometry
displayed:
If you have compiled Geant4 with Qt support the graphic windows will
be embedded in the GUI. Play with the interface, in particular take a
look at the help menu.
Compile a second exercise.
Browse the geant4/examples
directory and try out compilation of few
exercises. Compile following the instructions of the previous exercise. Refering to the
presentation about exercises, try out the exercise that
most is relevant for your field. Imprtant: some exercises may
require additional components of Geant4 (e.g. GDML), thus will not
compile in this setup.