Title: A Hands-on introduction to Geant4
1A Hands-on introduction to Geant4
- Andrea DellAcqua
- CERN-EP/ATC
- dellacqu_at_mail.cern.ch
2Monday, Oct. 8th
- 900-1230
- Introduction
- Installation
- DAWN display features
- Rotation Matrixes
- 3-vectors
- 1400-1700
- Geometry (part I)
- Simple solids
- Logical Volumes
- Positioning
- Visualization Attributes
Slides at http//home.cern.ch/ada/course/monday/in
dex.htm
3Introduction
4Geant4 - Why?
- Geant3 was a detector simulation program
developed for the LEP era - Fortran, ZEBRA
- Electromagnetic physics directly from EGS
- Hadronic physics added as an afterthought (and
always by interfacing with external packages) - Powerful but simplistic geometry model
- Physics processes very often limited to LEP
energy range (100 Gev) - (Painfully) debugged with the help and the
collaboration of 100s of physicist from all over
the world - LHC detectors need powerful simulation tools for
the next 20 years - reliability, extensibility, maintainability,
openness - good physics, with the possibility of extending
5Geant4 - Why?
- Geant3
- The geometry model is limited to a pre-defined
set of basic shapes. Adding a new shape requires
changing the code of several (20) routines.
Interface to CAD systems in not possible - Tracking is the result of several iterations (by
different people) and as such it has become a
garbled mess. Not for the fainthearted - EM physics is built in, but several processes are
missing and their implementation would be very
hard - Hadronic physics is implemented via external (and
obsolete) packages. Modifications require the
authors intervention
- Geant4
- The geometry has been based since the beginning
on a CAD-oriented model. The introduction of a
new shape does not influence tracking - Tracking has been made independent from
geometrical navigation, tracking in
electromagnetic fields (or any field) has been
improved - EM and hadronic physics implemented in terms of
processes. A process can be easily added or
modified by the user and assigned to the relevant
particles with no change in the tracking. The cut
philosophy has been changed so as to make result
less dependent on the cuts used for the
simulation. Framework for physics
parameterisation in place
6Geant4 - How?
- The principle points behind the Geant4
development have been - Ease on maintainability
- openness of the design
- performance
- development by a rather substantial group of
physicists - An Object Oriented approach facilitates the
achievement of these goals - the problem domain is naturally split into
categories which can be tackled by different
groups (with different expertise) - the process (if done properly) is
self-documenting. The components are relatively
independent from each other and can easily be
replaced without affecting the whole program too
much
7Geant4 - How? (2)
- Geant4 is a toolkit
- the framework part in Geant4 has been reduced to
a minimum, so as to allow the user to implement
his/her own program structure - bits and pieces of Geant4 can be used
independently from the rest - no main program is provided
- libraries have been made as granular as possible,
in order to reduce (re-) compilation time and to
allow the user to only link against those parts
of G4 which are needed - C as implementation language
- de-facto standard for what concerns OO
programming these days - high performance
- big commercial support, well known in the
scientific world - there is practically no Fortran in Geant4
anymore, hence the user must know some elements
of C in order to get the best from G4
8Geant4 - How? (3)
- Make Geant4 as independent as possible from
commercial packages - You dont need an Objectivity license to run
Geant4! - Interfaces to commercial products have been
provided whenever it was felt appropriate (so
you can use Objectivity to store your data) - The only commercial package which was needed to
run Geant4 was Rogue Waves Tools.h which did
provide utility classes (as vectors, strings,
containers and iterators), waiting for the
Standard Template Library to become available. An
interface to STL has been made available with the
4.0.1 release, hence Tools.h in not needed
anymore (in principle) - The Geant4 code is written in reasonable C
- migration to ISO/ANSI C to follow when most of
the compilers will deal with it - for the moment use Stroustrups 2nd edition...
9Geant4 documentation
- For a complete documentation set go to
- http//wwwinfo.cern.ch/asd/geant4/geant4.html
- There youll find
- Information on how to install a Geant4
application - Documentation on how to get started with Geant4
and how to build your detector simulation program - Class diagrams which document the G4 design
- A complete Class Documentation set
- Useful links
10Geant4 status
- In terms of performance and potentiality, Geant4
should be at least at the same level of Geant3 - First production version (geant4.0.0) released
at the end of 1998 - Full of bugs
- Several part still under heavy development
- Many improvements proposed, AD cycles still
undergoing - Physics part still being improved
- new version (geant4.0.1) available since the end
of July - bug fixes
- Interface to STL
- Breaks users code (
- geant4.1.0 foreseen by the end of 1999
- new hadronic physics, bug fixes
- move to ISO/ANSI C, based on STL, drop Tools.h
11A word on STL
- STL provides a set of utility classes (vectors,
lists, maps) to be used as tools - No compiler (as of today) provides a consistent
set - Tools.h was chosen (when the G4 project was
started) as an interim replacement for STL, with
the idea of migrating to STL as soon as a
standard implementation would become available - 4.0.1 provides an interface to STL (prototype)
but - using the ObjectSpace STL on HP and SUN
- using the native STL on Linux (but needs
modifying a system include to get it running on
RedHat 5.2!) - We are going to use Tools.h for the moment,
waiting for better days...
12Installation
13How to install Geant4
- To run a Geant4 application you must
- Install the Geant4 libraries on your system
- The source code is available from the web
- Install the CLHEP library and code
- These can be taken from
- or from
http//wwwinfo.cern.ch/asd/geant4/geant4.html and
then click on source
/afs/cern.ch/sw/lhcxx
/afs/cern.ch/atlas/project/geant4/CLHEP
14How to install Geant4 (2)
- In case you want to use Tools.h, install the
Rogue Wave Tools.h libraries and code - This is the only commercial component need by
Geant4 as of today - Used for container classes (like vectors, maps,
lists) but soon to be replaced by an interface
built on top of the Standard Template Library
(STL) - The RW stuff is commercial, but waiting for the
STL interface, you can steal it from - or from
/afs/cern.ch/atlas/project/geant4/rogue
http//home.cern.ch/rimoldi/g4simulation/geant4.ht
ml
15How to install Geant4 (3)
- Once you got all this code on your machine, you
simply follow a straightforward procedure - Set the G4SYSTEM variable
- Set the CLHEP_BASE_DIR variable to point to where
you put the CLHEP stuff - Set the RWBASE variable to point to where you
installed RW Tools.h - cd to the source directory of your geant4
installation and make all libraries
setenv G4SYSTEM SUN-CC
setenv CLHEP_BASE_DIR /afs/cern.ch/atlas/project/g
eant4/CLHEP/G4SYSTEM/pro
setenv RWBASE /afs/cern.ch/atlas/project/geant4/ro
gue/G4SYSTEM
cd /afs/cern.ch/atlas/project/geant4/4.0.1/geant4.
0.1/source gmake
16How to install Geant4 (4)
- In case you want to use the STL interface, set
the G4USE_STL variable - setenv G4USE_STL 1
- if you are using a system where the ObjectSpace
implementation of STL is required, set the
G4USE_OSPACE variable and tell the system where
the ObjectSpace stuff was installed - setenv G4USE_OSPACE 1
- setenv OSPACE_BASE_DIR /afs/cern.ch/sw/lhcxx/speci
fic/sun/ObjectSpace/2.1/ToolKit
17How to install Geant4 (5)
- G4SYSTEM is the variable one must set to tell
gmake which system and compiler are you running
on - G4SYSTEM can be
AIX-xlC AIX 4.3, xlC set for AIX
(default) SUN-CC SunOS 5.6, CC 4.2
HP-aCC HP/UX 10.20, aCC A.01.09 SGI-CC SGI-IR
IX 6.2, C 7.2 DEC-cxx DEC-OSF/1 4.0, DEC
C Linux-g Linux (RH 5.1), egcs
1.1 WIN32-VC-NICE NiceNT and MSVC 5.0,
installed locally together with
CYGWIN32 WIN32-G-NICE NiceNT and CYGWIN32 with
g as base compiler
18How to install Geant4 (6)
- The visualization libraries will need some
special treatment - Go to the source/visualization directory of your
Geant4 installation - Read the README file over there and choose the
graphics drivers you want to get installed - make the visualization libraries
cd /afs/cern.ch/atlas/project/geant4/4.0.1/geant4.
0.1/source/visualization
setenv G4VIS_BUILD_DAWN_DRIVER 1 setenv
G4VIS_BUILD_DAWNFILE_DRIVER 1
gmake
19How to build an example
- Set the G4INSTALL variable to point where Geant4
was installed - Set the CLHEP_BASE_DIR and RWBASE variable as in
the case of the Geant4 installation - Set the G4SYSTEM variable
- Set the G4WORKDIR variable to point to your
working directory - go into the example directory (e.g
G4WORKDIR/N02), run gmake and pray The
executable will be put in G4WORKDIR/bin/G4SYSTEM
setenv G4INSTALL /afs/cern.ch/atlas/project/geant4
/4.0.1/geant4.0.0
setenv G4WORKDIR /export/home/userN/geant4
20How to build an example (2)
- For examples using graphics you have to set a few
more variables. We are going to use the simplest
among the graphics systems implemented with
Geant4, DAWN - Tell the visualisation that we are going to use
DAWN - Tell the visualisation where to find the DAWN
executable - Reset your PATH to include G4DAWN_HOME
setenv G4VIS_USE_DAWN 1 setenv G4DAWN_MULTI_WINDOW
1
setenv G4DAWN_HOME /afs/cern.ch/atlas/project/gean
t4/DAWN/SUN-CC
set path ( path G4DAWN_HOME )
21To sum up...
- The variables to set for this course (every time
you log in) are - These definitions (bar G4WORKDIR) should be
grouped into a file to be sourced at the
beginning of a session
setenv G4INSTALL /afs/.fnal.gov/ups/geant/v4.0.1/g
eant4 setenv CLHEP_BASE_DIR /afs/.fnal.gov/ups/gea
nt/v4.0.1/CLHEP/G4SYSTEM/1.4 setenv RWBASE
/afs/.fnal.gov/ups/geant/v4.0.1/rogue/G4SYSTEM se
tenv G4SYSTEM SUN-CC setenv G4WORKDIR
/afs/fnal.gov/files/home/room1/classN/geant4 seten
v G4VIS_USE_DAWN 1 setenv G4DAWN_MULTI_WINDOW
1 setenv G4DAWN_HOME /afs/.fnal.gov/ups/geant/v4.0
.1/DAWN/SUN-CC set path ( path G4DAWN_HOME )
source G4Setup_Sun.sh (find one under
/afs/.fnal.gov/ups/geant/v4.0.1)
22How GNUmake works in Geant4
- The GNUmake process in Geant4 is mainly
controlled by the following scripts (placed into
G4INSTALL/config) - architecture.gmk
- defines the architecture specific settings and
paths - common.gmk
- defines all general GNUmake rules for building
objects and libraries - globlib.gmk
- defines all general GNUmake rules for building
compound libraries - binmake.gmk
- defines all general GNUmake rules for building
executables - GNUmakefiles
- placed inside each directory in the Geant4
distribution and defining specific directives to
build a library (or a set of libraries) or an
executable
23How GNUmake works in Geant4 (2)
- The kernel libraries are placed by default in
G4INSTALL/lib/G4SYSTEM - Executable binaries are placed in
G4WORKDIR/bin/G4SYSTEM - Temporary files (object files, dependency files,
data products of the compilation process) are
placed in G4WORKDIR/tmp/G4SYSTEM - dont delete it!!! You would have to recompile
all your files!!! - G4WORKDIR is set by default to G4INSTALL and it
should be reset by the user
24Naming conventions
- Sorry, but it is necessary
- All Geant4 source files have a .cc extensions,
all Geant4 header files carry a .hh extension - All Geant4 classes have their name prefixed with
a G4 - G4RunManager, G4Step, G4LogicalVolume
- Abstract classes add a V to the prefix
- G4VHit, G4VPhysicalVolume
- Each word in a composite name is capitalized
- G4UserAction, G4VPVParameterisation
- Methods and functions obey the same naming
conventions as the class names - G4RunManagerSetUserAction(), G4LogicalVolumeGe
tName()
25Basic types
- For basic numeric types, different compilers on
different plattforms provide different value
ranges - To assure portability, Geant4 redefines the basic
types for them to have always the same bit yield - the definitions of these types are all placed in
a single header file (globals.hh), which also
provides inclusion of all system headers, as well
as global functions needed by the Geant4 kernel
int ? G4int long ? G4long float ? G4float double
? G4double bool ? G4bool (native, or from RW, or
from CLHEP) string ? G4String (from RW, and now
from STL)
26The main program
- Geant4 is a detector simulation toolkit, hence it
does not provide a main() method - Users must supply their own main program to build
their simulation program - The G4RunManager class is the only manager class
in the Geant4 kernel which should be explicitly
instantiated in the main program to specify - How the detector geometry should be built
- Which physics processes one is interested in
- How the primary particles in an event should be
produced - Additional requests during the simulation
procedures
27G4RunManager
- G4RunManager is the root class of the Geant4
hierarchy - It controls the main flow of the program
- Construct the manager classes of Geant4 (in its
constructor) - Manages initialization procedures including
methods in the user initialization classes (in
its method Initialize() ) - Manages event loops (in its method BeamOn() )
- Terminates manager classes in Geant4 (in its
destructor)
28User initialization and action classes
- Geant4 has two kinds of user defined classes
- User initialization classes
- used for customizing the Geant4 initialization
- assigned to G4RunManager by invoking the
SetUserInitialization() method - User action classes
- used during the run processing
- assigned to G4RunManager by invoking the
SetUserAction() method - The implementation of three user defined classes
is mandatory - setting up of the geometry
- event kinematics
- physics processes
29Mandatory user classes
- Three user classes have to be implemented by the
user (two initialization classes and one action
class) - The base classes of these mandatory classes are
abstract and no default implementation is
provided - G4RunManager checks whether objects belonging to
these classes have been instanciated when
Initialize() and BeamOn() are invoked - Users must inherit from the abstract base classes
provided by Geant4 and derive their own classes
30Mandatory user classes (2)
- G4VUserDetectorConstruction (initialization)
- the detector set-up must be described in a class
derived from this - Materials
- Geometry of the detector
- Definition of sensitive detectors
- Readout schemes
- G4VUserPhysicsList (initialization)
- Particles and processes to be used in the
simulation - cutoff parameters
- G4VUserPrimaryGeneratorAction (action)
- Primary event kinematics
31Optional user action classes
- G4UserRunAction
- run by run
- G4UserEventAction
- event by event
- G4UserStackingAction
- to control the order with which particles are
propagated through the detector - G4UserTrackingAction
- Actions to be undertaken at each end of the step
- G4UserSteppingAction
- Actions to be undertaken at the end of every step
32An example of main() (batch program)
include G4RunManager.hh // from Geant4,
declaration of the run manager include
G4UImanager.hh // from Geant4, declaration of
the User Interface manager include
MyDetectorConstruction.hh // by the user
definition of the detector geometry include
MyPhysicsList.hh // by the user, list of
physics processes to be added include
MyPrimaryGenerator.hh // by the user,
kinematics of the event int main ()
G4RunManager runManagernew G4RunManager
// the run manager runManager-gtSetUserInitializa
tion(new MyDetectorConstruction) // the
geometry runManager-gtSetUserInitialization(new
MyPhysicsList) // the physics
runManager-gtSetUserAction(new
MyPrimaryGenerator) // the kinematics runMana
ger-gtInitialize() // run
initialization G4UImanager UIG4UImanagerGetUI
pointer() // pointer to the
UI UI-gtApplyCommand(run/verbose 1) //
set the printlevel int numberOfEvent3
// nr. of evts to be run runManager-gtBeamOn(numb
erOfEvent) // generate the events delete
runManager // end of run return 0
33Batch mode with macro file
int main(int argc, char argv) // construct
the default run manager G4RunManager runManager
new G4RunManager runManager-gtSetUserInitiali
zation(new MyDetectorConstruction) runManager-gtS
etUserInitialization(new MyPhysicsList) runManage
r-gtSetUserAction(new MyPrimaryGeneratorAction)
runManager-gtInitialize() // read a macro file
G4UIManager UI G4UImanagerGetUIpointer()
G4String command /control/execute G4String
fileName argv1 UI-gtApplyCommand(commandfile
Name) delete runManager return 0
34Batch mode with macro file (2)
- The previous example can be run with the command
- gt myProgram run.macro
- where myProgram is the name of the executable
and run.macro is a command macro which could look
like - set verbose level for this run
- /run/verbose 2
- /event/verbose 0
- /tracking/verbose 2
- 100 electrons of 1GeV Energy
- /gun/particle e-
- /gun/energy 1 GeV
- /run/beamOn 100
35Interactive mode
int main(int argc, char argv) G4RunManager
runManager new G4RunManager runManager-gtSetU
serInitialization(new MyDetectorConstruction) ru
nManager-gtSetUserInitialization(new
MyPhysicsList) G4VisManager visManager new
MyVisManager visManager-gtinitialize() runMana
ger-gtSetUserAction(new MyPrimaryGeneratorAction)
runManager-gtInitialize() G4UIsession
session new G4UIterminal session-gtSessionStart
() delete session delete visManager delete
runManager return 0
36Interactive mode (2)
- The previous example will be run with the command
- gt myProgram
- where myProgram is the name of your executable
object - After the initialization phase, Geant4 will
prompt - Idlegt
- At this point, an interactive session can begin
- Idlegt /vis/create_view/new_graphics_system DAWN
- Idlegt /vis/draw/current
- Idlegt /run/verbose 1
- Idlegt /event/verbose 1
- Idlegt /tracking/verbose 1
- Idlegt /gun/particle mu
- Idlegt /gun/energy 10 GeV
- Idlegt /run/beamOn 1
- Idlegt /vis/show/view
37ExampleN02
- Very basic example, depicting some kind of fix
target experimental setup - not very well written but very much complete and
good for reference - Change directory to geant4/N02 which contains
- a GNUmakefile
- very basic, essentially defining the name of the
executable and running binmake.gmk - the main program (exampleN02.cc)
- a macro file (prerun.g4mac)
- an include directory
- class header files
- a src directory
- implementation of all methods
38ExampleN02 (contd)
- create the executable with gmake
- run the executable by typing
- G4WORKDIR/bin/G4SYSTEM/exampleN02
- start the DAWN graphics system by typing
- /vis/create_view/new_graphics_system DAWN
- draw the experimental setup by
- /vis/draw/current
- and get the GUI by
- /vis/show/view
- tell the tracking of storing all track segments
by - /tracking/storeTrajectory 1
- and run one event
- /run/beamOn 1
39ExampleN02 (contd)
- You can change the beam condition by using the
/gun commands - /gun/List // to have a list of all
possible particles - /gun/particle e
- /gun/energy 10 GeV
- /gun/position 0 10 30 cm
- /gun/direction .3 .3 .1
- have a look at the online help to see what can
you do...
40ExampleN02 (contd)
41DAWN
- DAWN is a vectorized 3D PostScript processor
developed at the Fukui University - Well suited to prepare high quality outputs for
presentation and/or documentation - Useful for detector geometry debugging (it comes
with a facility, DAVID, which allows to detect
overlapping volumes) - Remote visualization, cut view, off-line
re-visualization are supported by DAWN - A DAWN process is automatically invoked as a
co-process of Geant4 when visualization is
performed and 3D data is passed with
inter-process communication via a file or the
TCP/IP socket
42DAWN (2)
- There are two kinds of DAWN drivers
- DAWN-File
- DAWN-Network
- The DAWN-File driver send 3D data to DAWN via an
intermediate file (called g4.prim) in the current
directory. The contents of the file can be
re-visualized (without running Geant4) by simply
running DAWN on it - dawn g4.prim
- The DAWN-Network driver send 3D data to DAWN via
the TCP/IP socket or the named pipe and it can be
used to perform remote visualization - If you have no network, set the environment
variable G4DAWN_NAMED_PIPE to 1, to switch the
default socket connection to the named pipe
within the same host machine
43DAWN GUI (page 1)
Next page
Camera distance
Angles
Camera Position
Size
Viewing mode
Axes
44DAWN GUI (page 2)
45DAWN GUI (page 3)
46DAWN GUI (page 4)
Save the picture in an EPS file
Dont forget this!
Have a preview of the picture
47Geant4 and CLHEP
- Geant4 makes a rather substantial use of CLHEP
components - System of units
- Vector classes and matrices
- G4ThreeVector (typedef to Hep3Vector)
- G4RotationMatrix (typedef to HepRotation)
- G4LorentzVector (typedef to HepLorentzVector)
- G4LorentzRotation (typedef to HepLorentzRotation)
- Geometrical classes
- G4Plane3D (typedef to HepPlane3D)
- G4Transform3D (typedef to HepTransform3D)
- G4Normal3D (typedef to HepNormal3D)
- G4Point3D (typedef to HepPoint3D)
- G4Vector3D (typedef to HepVector3D)
48System of units
- Geant4 offers the possibility to choose and use
the units one prefers for any quantity - Geant4 uses an internal and consistent set of
units based on - millimeter (mm)
- nanosecond (ns)
- Mega electron Volt (MeV)
- Positron charge (eplus)
- Degree Kelvin (kelvin)
- Amount of substance (mole)
- Luminosity intensity (candela)
- Radian (radian)
- steradian (steradian)
49System of units (2)
- All the units are defined from the basic ones
- These definitions are available in the file
- source/global/management/include/SystemOfUnits
- and are now part of CLHEP
- The user is free to change the system of units to
be used by the kernel
millimetermm1 meter m 1000mm . m3
mmm ..
50System of units (3)
- Avoid hard coded data
- you better specify the unit of the data you are
going to introduce - The Geant4 code is written respecting these
specification and this makes the code independent
from the system of units chosen by the user - Be careful!!!
- Some built-in commands for the User interface
require the unit to be specified
G4double Size 15.km, KineticEnergy 90.3GeV,
density 11mg/cm3
G4double radius10.m // internally
converted radius10000 . G4double xposition
(radiuscos(alpharad))cm // is this really what
you want to do?? G4double yposition
(radiussin(alpharad))cm
/gun/energy 10 GeV
51System of units (4)
- To output the data on the unit you wish you must
DIVIDE the data by the corresponding unit - You can let Geant4 decide which is the most
appropriate unit to represent your data. It is
just sufficient to specify which category
(length, time, energy) does it belong to - You can print the whole table of units by using
the static function
cout ltlt KineticEnergy/KeV ltlt KeV ltltendl
cout ltlt G4BestUnit(StepSize, Length) ltltendl
G4UnitDefinitionPrintUnitsTable
52System of units (5)
- You may introduce new units if you wish
- by completing the file SystemOfUnits.hh
- by using the class G4UnitDefinition and creating
a new object of it - G4UnitDefinition (name, symbol, category, value)
include SystemOfUnits.hh static const G4double
inch 2.54cm
G4UnitDefinition (km/hour,km/h,Speed,km/(360
0s)) G4UnitDefinition (meter/ns,m/ns,Speed
,m/ns)
533-Vectors
- Geant4 makes use of the CLHEP HepVector3D and
Hep3Vector for implementing several 3-dimensional
object (G4ThreeVector, G4ParticleMomentum) - The definition of a 3-vector is pretty
straightforward - G4ThreeVector pnew G4ThreeVector(10,20,100)
- Every component can be accessed very easily
- G4double pxp-gtx()
- and set very easily
- p-gtsetZ(50)
- the components in polar coordinates are give by
- phi(), theta(), mag()
- and set using
- setPhi(), setTheta(), setMag()
543-Vectors (2)
- They can be normalized
- p-gtunit()
- rotated around one of the cartesian axes
- p-gtrotateY(2.73)
- or around any other 3-vector
- p-gtrotate(1.57,G4ThreeVector(10,20,30))
- for reference
- CLHEP_BASE_DIR/include/CLHEP/Vector/ThreeVector.h
- wwwinfo.cern.ch/asd/lhc/clhep/manual/RefGuide/Ve
ctor/Hep3Vector.html
55Rotation Matrixes
- Geant4 uses the rotation matrix implementation
which comes with CLHEP (HepRotation, typedefd
into G4RotationMatrix) - include G4RotationMatrix.hh
- .
- G4RotationMatrix rm new G4RotationMatrix
- You can then rotate about the coordinate axes
- rm-gtrotateX(45deg) // rotation about X
- and combine several rotations into a 3D one
- rm-gtrotateX(30deg)
- rm-gtrotateY(20deg)
56Rotation Matrixes (2)
- You can rotate about a specified vector
- rm-gtrotate(45deg,Hep3Vector(1.,1.,.3))
- or specify the direction of the three cartesian
axes after the rotation - rm-gtrotateAxes( Hep3Vector(-sin(a),0,cos(a)),
- Hep3Vector(cos(a),0,sin(a)),
- Hep3Vector(0,1,0))
- a rotation matrix can be inverted by using the
invert method - rm-gtinvert()
57Rotation Matrixes (3)
- The angles made by the rotated axes against the
original axes can be obtained with the set of
functions - phiX(),phiY(),phiZ(),thetaX(),thetaY(),thetaZ()
- or one can get the rotation angle and the
rotation axis (awkward) - G4double angle
- G4ThreeVector axis
- rm-gtgetAngleAxis(angle,axis)
- to reset a rotation matrix use the default
constructor - rmG4RotationMatrix()
- documentation at
- CLHEP_BASE_DIR/include/CLHEP/Vector/Rotation.h
- wwwinfo.cern.ch/asd/lhc/clhep/manual/RefGuide/Ve
ctor/HepRotation.html
58Geometry
59Materials
- In nature, general materials (compounds,
mixtures) are made by elements and elements are
made by isotopes. These are the three main
classes designed in Geant4 - The G4Element class describes the properties of
the atoms atomic number, number of nucleons,
atomic mass, shell energy - The G4Isotope class permits to describe the
isotopic composition of a material - The G4Material class describes the macroscopic
properties of the matter density, state,
temperature, pressure, radiation length, mean
free path, dE/dx - G4Material is the class visible to the rest of
the toolkit and it is used by the tracking, the
geometry and physics
60Define a simple material
- A simple material can be created by specifying
its name, density, mass of a mole and atomic
number - The pointer to the material will then be used to
specify the material a given logical volume is
made of
include G4Material.hh G4double
density1.390g/cm3 G4double a39.95g/mole G4do
uble z18. G4String name G4Material LAr
new G4Material(nameLiquid Argon, z, a,
density)
61Define a molecule
- A molecule is built from its components, by
specifying the number of atoms in the molecule.
include G4Element.hh include
G4Material.hh ... G4double a1.01g/mole G4doub
le z G4String name,symbol G4Element H new
G4Element(nameHydrogen, symbolH,z1.,a) a
16.0g/mole G4Element O new
G4Element(nameOxygen, symbolO,z8.,a) G4do
uble density1.000g/cm3 G4int
ncomponent,natoms G4Material H2O new
G4Material(nameWater,density,ncomponents2) H2
O-gtAddElement(H,natoms2) H2O-gtAddElement(O,natom
s1)
62Define a mixture (by fractional mass)
- Air is built from Nitrogen and Oxygen by giving
the fractional mass of each component
include G4Element.hh include
G4Material.hh ... G4double a14.01g/mole G4dou
ble z G4String name,symbol G4Element N new
G4Element(nameNitrogen, symbolN,z7.,a) a
16.0g/mole G4Element O new
G4Element(nameOxygen, symbolO,z8.,a) G4do
uble fractionmass,density1.290mg/cm3 G4int
ncomponent,natoms G4Material Air new
G4Material(nameAir,density,ncomponents2) Air-
gtAddElement(N,fractionmass70percent) Air-gtAddEl
ement(O,fractionmass30percent)
63Materials as mixtures of materials
- ArCO2 can be defined as mixture of an element and
a material
include G4Element.hh include
G4Material.hh ... G4double a,z,fractionmass,dens
ity G4String name,symbol G4int
ncomponents,natoms G4Element Ar new
G4Element(nameArgon, symbolAr,z18.,a39.95
g/mole) G4Element C new G4Element(nameCarbon
, symbolC, z6., a12.00g/mole) G4Element
O new G4Element(nameOxygen,
symbolO,z8.,a16.00g/mole) G4Material CO2
new G4Material(nameCO2,density1.977mg/cm3,n
components2) CO2-gtAddElement(C,natoms1) CO2-gtA
ddElement(O,natoms2) G4Material ArCO2new
G4Material(nameArCO2,density1.8mg/cm3,ncompon
ents2) ArCO2-gt AddElement(Ar,fractionmass93per
cent) ArCO2-gt AddMaterial(CO2,fractionmass7perc
ent)
64Materials in non STP conditions
include G4Element.hh include
G4Material.hh ... G4double a,z,fractionmass,dens
ity G4String name,symbol, ncomponent,natoms G4El
ement Ar new G4Element(nameArgon,
symbolAr,z18.,a39.95g/mole) G4Element C
new G4Element(nameCarbon, symbolC, z6.,
a12.00g/mole) G4Element O new
G4Element(nameOxygen, symbolO,z8.,a16.00g
/mole) G4double temperature300.kelvin G4doubl
e pressure2atmosphere G4Material CO2 new
G4Material(nameCO2,density1.977mg/cm3,ncompon
ents2 kStateGas,temperature,pressure) CO2-gtA
ddElement(C,natoms1) CO2-gtAddElement(O,natoms2)
G4Material ArCO2new G4Material(nameArCO2,d
ensity1.8mg/cm3,ncomponents2
kStateGas,temperature,pressure) ArCO2-gt
AddElement(Ar,fractionmass93percent) ArCO2-gt
AddMaterial(CO2,fractionmass7percent)
65Printing materials and elements
- Materials and elements (and the tables maintained
internally by Geant4) can be printed very easily
with
include G4Element.hh include
G4Material.hh ... coutltltArCO2 coutltlt(G4Element
GetElementTable()) coutltlt(G4MaterialGetMater
ialTable())
66Detector geometry
- A detector geometry in Geant4 is made of a number
of volumes. - The largest volume is called the World volume. It
must contain all other volumes in the detector
geometry - The other volumes are created and placed inside
previous volumes, including the World. - Each volume is created by describing its shape
and its physical characteristics and then placing
it inside a containing volume. - The coordinate system used to specify where the
daughter volume is placed is the one of the
mother.
67Detector Geometry (2)
- Volumes cannot overlap in Geant4!!!
- Use boolean operations instead!
Geant4
Geant3
MANY
ONLY
68G4VUserDetectorConstruction
- G4VUserDetectorConstruction is one of the three
abstract classes in Geant4 the user MUST inherit
from to create his/her implementation of the
detector geometry - An instance of a class inherited from
G4VUserDetectorConstruction is passed to the
G4RunManager by calling SetUserInitialization().
The Run Manager keeps a pointer to the detector
geometry which the user wants to use and checks
(before startup) that this pointer has indeed
been set - G4VUserDetectorConstructions method Construct()
is invoked by the Run Manager to set up the
detector geometry. Construct() should hence set
up everything needed for the geometry definition - Construct() returns a pointer the the Worlds
Physical Volume
69Volumes
- To have a volume implemented in Geant4 one has to
go through three steps. - A Solid is used to describe a volumes shape. A
solid is a geometrical object that has a shape
and specific values for each of that shapes
dimensions - A Logical Volume is use for describing a volumes
full properties. It starts from its geometrical
properties (the solid) and adds physical
characteristics, like the material, the
sensitivity, the magnetic field, the color - What remains to describe is the position of the
volume. For doing that, one creates a Physical
volumes, which places a copy of the logical
volume inside a larger, containing volume.
70Solids
- The STEP standard supports multiple solid
representations - Constructive Solid Geometry (CSG)
- SWEPT solids
- Boundary Represented solids (BREPs)
- Different representations are suitable for
different purposes, applications, required
complexity and levels of detail. - CSGs give superior performance and they are easy
to use, but they cannot reproduce complex solids
as used in CAD systems - BREPs allow to reproduce the most complex solids,
thus allowing the exchange of models with CAD
systems, but they are normally quite inefficient,
as far as tracking is concerned
71Solids
- To create a simple box one has simply to define
its name and its dimensions along each cartesian
axes
include G4Box.hh . G4double
expHall_x3.0m G4double expHall_y1.0m G4doubl
e expHall_z1.0m G4Box experimentalHall_box
new G4Box(Exp. Hall box,expHall_x,expHall_y,ex
pHall_z)
72CSG Solids
- CSG solids are defined directly as 3D primitives
- They are described by a minimal set of parameters
necessary to define the shape and the size of the
solid - CSG solids are Boxes, Tubes and their sections,
Cones and their sections, Spheres, Wedges, Toruses
73G4Box
- The definition of a Box in Geant4 can be found
in - To create a box use the constructor
G4INSTALL/source/geometry/solids/CSG/include/G4Bo
x.hh
G4Box(const G4String pName, G4double pX,
G4double pY, G4double pZ) where pX half length
in X pY half length in Y pZ half length in
Z G4Box a_boxnew G4Box(My Box,10cm,0.5m,30
cm)
74G4Tubs
- The definition of a Tube (or a section of it) is
in - use the constructor
G4INSTALL/source/geometry/solids/CSG/include/G4Tu
bs.hh
G4Tubs(const G4String pName, G4double pRmin,
G4double pRmax, G4double pDz, G4double pSPhi,
G4double pDPhi) where pRmin Inner
Radius pRmax Outer Radius pDZ half length in
Z pSPhi starting phi angle pDPhi angular span
of the section G4Tubs a_tubenew G4Tubs(a
Tube,10cm,30cm,20cm,0.,270.deg)
75G4Cons
- The definition of a cone (or a section of it) is
in - Use the constructor
G4INSTALL/source/geometry/solids/CSG/include/G4Co
ns.hh
G4Cons(const G4String pName, G4double pRmin1,
G4double pRmax1, G4double pRmin2,
G4double pRmax2, G4double pDz,
G4double pSPhi, G4double pDPhi) where pRmin
1,pRmax1 Inner/Outer Radius at
z-pDz pRmin2,pRmax2 Inner/Outer Radius at
zpDz pDZ half length in Z pSPhi starting
phi angle pDPhi angular span of the
section G4Cons a_conenew G4Cons(a
Cone,1cm,5cm,10cm,30cm,20cm,0.,180.deg)
76G4Trd
- The definition of a trapezoid is in
- The general constructor is
G4INSTALL/source/geometry/solids/CSG/include/G4Tr
d.hh
G4Trd(const G4String pName, G4double dx1,
G4double dx2, G4double dy1, G4double
dy2, G4double pDz) where dx1 Half
length along x at the surface positioned at
-dz dx2 Half length along x at the surface
positioned at dz dy1 Half length along y at
the surface positioned at -dz dy2 Half length
along y at the surface positioned at
dz dz Half length along z axis G4Trd
a_trdnew G4Trd(a Trd,10cm,20cm,1m,1m,2m)
77Other CSG shapes
- G4Hype
- an hyperbolic with curved sides parallel to the z
axis - G4Para
- a general Parallelepiped
- G4Trap
- a general trapezoid (possibly twisted)
- G4Sphere
- a (section of a) sphere
For additional informations about these shapes
have a look in G4INSTALL/source/geometry/solids/G
SG/include
78Polycone and polyhedra
- A polycone solid is a shape defined by a set of
inner and outer conical or cylindrical surface
sections and two planes perpendicular to the Z
axis. Each conical surface is defined by its
radius at two different planes perpendicular to
the Z axis. Inner and outer conical surfaces are
defined using common Z planes
G4Polycone( G4String name, const G4double
start_angle, // starting angle const
G4double opening_angle, // opening angle
const int num_z_planes, // nr. of planes
const G4double z_start, // starting value of z
const G4double z_values, // z coordinate of
each plane const G4double RMIN, // inner
radius of the cone at each plane const
G4double RMAX) // outer radius of the cone at
each plane
79Polycone and polyhedra
- The polyhedra solid is a shape defined by an
inner and outer polygonal surface and two planes
perpendicular to the Z axis. Each polygonal
surface is created by linking a series of
polygons created at different planes
perpendicular to the Z axis. All these polygons
have the same nr of sides
G4Polyhedra( G4String name, const
G4double start_angle, // starting angle
const G4double opening_angle, // opening angle
const G4int n_sides // nr. of sides
const G4int num_z_planes, // nr. of planes
const G4double z_start, // starting value of z
const G4double z_values, // z coordinate of
each plane const G4double RMIN, // inner
radius of the cone at each plane const
G4double RMAX) // outer radius of the cone at
each plane
80Logical volumes
- To create a Logical volume one must start from a
solid and a material.
include G4LogicalVolume.hh include
G4Box.hh include G4Material.hh . G4Box
a_box new G4Box(A box,dx,dy,dz) G4double
a39.95g/mole G4double density1.390g/cm3 G4Ma
terial LAr new G4Material(nameLiquid
Argon,z18.,a,density) G4LogicalVolume
a_box_log new G4LogicalVolume(a_box,LAr,a
simple box)
81Positioning a volume
- To position a volume, one must start with a
logical volume and decide what volume (which must
already exist) to place it inside, where to
position it (wrt the mothers reference system)
and how to rotate it - A physical volume is simply a positioned instance
of a logical volume
include G4VPhysicalVolume.hh include
G4PVPlacement.hh G4RotationMatrix rmnew
G4RotationMatrix rm-gtrotateX(30deg) G4Double
aboxPosX-1.0m G4VPhysicalVolume
a_box_phys new G4PVPlacement(rm, // pointer
to G4RotMatrix!! G4ThreeVector(aboxPosX,0,0),
// position a_box_log, // its logical
volume a box, // its name experimental
Hall_log, // its mother false, // no
boolean ops. 1) // the copy nr.
82Positioning a volume (2)
- An exception exist to the rule that a physical
volume must be placed inside a mother volume. The
World volume must be created as a G4PVPlacement
with a null mother pointer and be positioned
unrotated at the origin of the global coordinate
system
include G4PVPlacement.hh G4VPhysicalVolume
experimentalHall_phys new G4PVPlacement(0,
// No rotation! G4ThreeVector(0.,0.,0.)
, // No Translation! experimentalHall_log,
// The logical volume Experimental
Hall, // its name 0, // No
mother volume! false, // no
boolean operations 0) // copy
number
83Frame
- This example introduces the three mandatory
classes to be implemented for a Geant4
application to run (and a visualization manager,
needed for graphics applications) - have a look to the various files in the src/ and
include/ directories, figure out which methods
have been implemented - the example, as it is, will not compile. The aim
of the example is - to create the world volume. To this purpose, the
FrameDetectorConstruction class contains three
variables (experimentalHall_x,y,z) which can be
used as dimensions for the world volume - implement elements, materials, mixtures
- create solids, logical volumes and physical
volumes and position them into the world volume,
try to rotate and translate them, try composite
rotations to understand how the system works...
84Frame (2)
- Try and build a calorimeter (!) made of
trapezoidal wedges (dimensions and nr. of wedges
are provided in the program)
85Visualization Attributes
86Visualization Attributes
- Visualization attributes are a set of information
associated with objects which can be visualized - This information is just used for visualization
and it is not included in the geometrical
information such as shapes, position and
orientation - A set of visualization attributes is held by an
object of class G4VisAttributes
87Visibility
- Visibility is a boolean flag used to control the
visibility of the objects passed to the
Visualization Manager for visualization - Visibility is set by
- G4VisAttributesSetVisibility(G4bool
visibility) - If visibilityfalse, visualization is skipped for
those objects to which this set of attributes is
assigned - The following public data member is by default
defined - static const G4VisAttributes Invisible
- This can be referred at as G4VisAttributesInvisi
ble - experimentalHall_log-gtSetVisAttributes(G4VisAttrib
utesInvisible)
88Color
- G4VisAttributes holds its color entry as an
object of the class G4Colour - G4Colour has four field which represent the RGBA
(red,green,blue,alpha) of a color. Each component
takes a value between 0 and 1. Alpha is the
opacity, not used in the present version - A G4Colour object is created by giving the red,
blue and green components of the color - G4Color( G4double red1.0,G4double
green1.0,G4double blue1.0, - G4double a1.0)
- The default value of each component is 1, which
means white
89Color (2)
- G4Colour white () // white
- G4Colour white (1.,1.,1.) // white
- G4Colour gray (.5,.5,.5) // gray
- G4Colour black (0.,0.,0.) // black
- G4Colour red (1.,0.,0.) // red
- G4Colour green (0.,1.,0.) // green
- G4Colour blue (0.,0.,1.) // blue
- G4Colour cyan (0.,1.,1.) // cyan
- G4Colour magenta (1.,0.,1.) // magenta
- G4Colour yellow (1.,1.,0.) // yellow
90Color (3)
- One can set the RGBA components directly into
G4VisAttributes - void G4VisAttributesSetColour ( G4double red,
- G4double green,
- G4double blue,
- G4double alpha1.0)
- The following G4VisAttributes constructor is also
supported - G4VisAttributesG4VisAttributes(const G4Colour
color)
91Forced wireframe and forced solid styles
- Several drawing styles can be selected for the
volumes. For instance, one can select to
visualize detector components in wireframe or
with surfaces. In the former, only the edges of
the detector are drawn, so the detector looks
transparent. In the latter, the detector looks
opaque with shading effects - The forced wireframe and forced solid styles make
it possible to mix wireframe and solid
visualization. For instance, one can make the
mother volume transparent and still look inside
when in solid mode - Forced wireframe and forced solid are available
via - void G4VisAttributesSetForceWireframe(G4bool
force) - void G4VisAttributesSetForceSolid(G4bool force)
92Constructors for G4VisAttributes
- The following constructors are supported for
G4VisAttributes - G4VisAttributes()
- G4VisAttributes(G4bool visibility)
- G4VisAttributes(const G4Colour colour)
- G4VisAttributes(G4bool visibility, const
G4Colour colour)
93How to assign G4VisAttributes to a volume
- In constructing the detector components, one may
assign a set of visualization attributes to each
Logical Volume in order to visualize it later - G4LogicalVolume holds a pointer to a
G4VisAttributes. This field is set and referenced
by using - void G4LogicalVolumeSetVisAttributes(const
G4VisAttributes pVa) - void G4LogicalVolumeSetVisAttributes(const
G4VisAttributes Va) - If you want to display you experimental hall in
cyan and in forced wireframe style you do - ExpHall_lognew G4LogicalVolume(ExpHall_box,Air,e
xp_hall) - ..
- G4VisAttributes expHallVisAttnew
G4VisAttributes(G4Colour(0.,1.,1.)) - expHallVisAtt-gtSetForceWireframe(true)
- ExpHall_log-gtSetVisAttributes(expHallVisAtt)