CSC Geant4 Tutorial

Introduction - Setting the environment to use Geant4

The Geant4 source code and kernel libraries are installed in /CSC2/apps/staff/gcosmo/geant4.
The version installed is Geant4 2.0 + patch01.
To configure your environment to use Geant4, you need to execute the following shell script
(example for tcsh):
    source /CSC2/apps/staff/gcosmo/config.csh
The script will configure the environment and set all necessary paths to retrieve Geant4 associated tools.
 

The Geant4 hodoscope exercise

Introduction

The example CSCG4Ex has a simplified fixed-target detector geometry which consists of two arms before and after the magnetic field region. The first arm has a scintillator hodoscope plane and five layers of chambers. The second arm can be rotated and has a scintillator hodoscope plane, five layers of chambers and an array of CsI EM calorimeter. Students are expected to add a hadronic calorimeter made of lead/scintillator down-stream to the EM calorimeter.
 

Building the exercise

Retrieve the code of the hodoscope's exercise from the installation area, by doing the following:
    cp -r /CSC2/apps/staff/gcosmo/work $HOME
After configured your environment as described above, start building the Geant4 application:
    cd $HOME/work/CSC
    gmake
    rehash
All Geant4 user applications are structured as following:
A directory include containing all class header files (*.hh) and/or inline function implementation files (*.icc).
A director src containing all class implementation sources (*.cc).
A source file, whose name corresponds to the user's application name and including the main body (CSCG4Ex.cc).
A GNUmakefile script for building the application.
One or more input macro files (*.mac) to be used interactively or in batch-mode as input to the application.
Once the user code has been compiled, the final executable is placed in $G4WORKDIR/bin/$G4SYSTEM ready to be used. All temporary objects files are placed in $G4WORKDIR/tmp/$G4SYSTEM.
To remove the compiled objects for the exercise, one should just do the following:
    cd $HOME/work/CSC
    gmake clean

Running the exercise

Check that your terminal display is correctly set:
    setenv DISPLAY <my-display-ID>
Once compiled the user code in $HOME/work/CSC as described above, just invoke the application from $HOME/work/CSC:
    CSCG4Ex
Geant4 will start the initialisation phase. Once you get the prompt, you can run one of the input macros provided with the example. For example, to start a graphical session with a predefined set of simulated events, type:
    /control/execute sample1.mac
After the macro will be completely executed the prompt will be returned.

The executable image can be run in both interactive and batch modes. Three sample macro files demonstrate the basic features of this example: sample1.mac and sample3.mac are macros involving visualization, while sample2.mac is a batch script producing up to 3000 events. To run the executable in batch mode, add a macro file name as argumnent to the application CSCG4Ex. For example, try the following:

    CSCG4Ex sample2.mac

UI commands defined for this example

/mydet/armAngle
      Rotation angle of the second arm.
/mydet/fieldValue
      Field strength
/mydet/momentum
      Mean momentum of primaries
/mydet/sigmaMomentum
      Sigma momentum of primaries
/mydet/sigmaAngle
      Sigma angle divergence of primaries
/mydet/randomizePrimary
      Boolean flag for randomizing primary particle types.
/mydet/verbose
      Verbose level for each event.

Brief descriptions of classes

Main

CSCG4Ex

The main() method which constructs G4RunManager, CSCG4ExVisManager (derived class of G4VVisManager), G4UIterminal and some user classes.
 

User mandatory classes

CSCG4ExDetectorConstruction (derived from G4VUserDetectorConstruction)

This class constructs all materials and detector geometry. Sensitive detectors are also constructed and attached to the logical volumes.
Geometry of the detectors are defined by three ways, ordinary placement, parameterisation and replica.
This class also has a capability of changing geometry between two runs.

CSCG4ExPhysicsList (derived from G4VUserPhysicsList)

This class constructs all ordinary applicable particles and physics processes of electro-magnetic and hadronic interactions, decays and
transportation. The range cut-off is set to 1 mm.

CSCG4ExPrimaryGeneratorAction (derived from G4VUserPrimaryGeneratorAction)

This class shoots one primary particle for one event. Momentum, direction and particle type of the primary are randomized.
 
 

Geometry related classes

CSCG4ExMagneticField (derived from G4MagneticField)

This class define the magnetic field and its strength.

CSCG4ExCellParameterisation (derived from G4VPVParameterisation)

This class defines the parameterisation scheme of CsI EM calorimeter cells.
 
 

Optional user action classes

CSCG4ExEventAction (derived from G4UserEventAction)

This class defines a simple analysis routine executed at the end of each event.

CSCG4ExTrackingAction (derived from G4UserTrackingAction)

This class sets a flag of G4TrackingManager for generating a trajectory only if the currently processing particle is a primary particle.
 
 

Hits and sensitive detector classes

CSCG4ExHodoscopeHit (derived from G4VHit) and CSCG4ExHodoscope (derived from G4VSensitiveDetector)

CSCG4ExHodoscopeHit object stores the finger ID number and the time. It also stores the position, rotation matrix and a pointer to the logical volume of the finger for the sake of drawing.
CSCG4ExHodoscope creates CSCG4ExHodoscopeHit objects.

CSCG4ExDriftChamberHit (derived from G4VHit) and CSCG4ExDriftChamber (derived from G4VSensitiveDetector)

CSCG4ExDriftChamberHit object stores the layer ID number, local and global coordinates of the hit position and time. CSCG4ExDriftChamber constructs CSCG4ExDriftChamberHit objects.

CSCG4ExEmCalorimeterHit (derived from G4VHit) and CSCG4ExEmCalorimeter (derived from G4VSensitiveDetector)

CSCG4ExEmCalorimeterHit object stores the row and column ID numbers of the cell and sum of the energy deposited in the cell. It also stores the position, rotation matrix and a pointer to the logical volume of the cell for drawing purposes.
The color of drawn hit cell depends on the deposited energy.
CSCG4ExEmCalorimeter creates CSCG4ExEmCalorimeterHit objects.
 
 

Visualization and GUI classes

CSCG4ExVisManager (derived from G4VisManager)

This class defines the visualization drivers used in this program.
 

CSCG4ExDetectorConstMessenger, CSCG4ExEventActionMessenger, CSCG4ExMagneticFieldMessenger and CSCG4ExPrimaryGeneratorMessenger (derived from G4UImessenger)

These classes are the messenger classes which define UI commands to be invoked at run-time.
 

Exercises

Exercise 1

   - compile, link and execute the example
   - understanding Geant4: modify the verbose level, run commands
   - draw secondaries
 

Exercise 2

   - modify the calorimeter geometry:
     implementation of a Pb/Scinti Hadron calorimeter
 

Exercise 3

   - handling simulation outputs:
     addition of a Hadron calorimeter sensitive detector.

Here is how an event displayed with the additional hadron calorimeter should look like:


The archived source code for the exercise (with solutions) is available here.

All the information about the Geant4 toolkit can be found online from the World Wide Web: http://cern.ch/geant4


Makoto Asai, Gabriele Cosmo, Mark Verderi - Last modified: Saturday, September 23, 2000