Geant4 Basics

Geant4 Tutorials

Wisp GUI



Geant4 Quickstart Guide

The aim of the quickstart guide is to get new users acquianted with the structure of a Geant4 application and allow them to becom productive as quickly as possible.

Once the Geant4 development environment is set up, in order to create a Geant4 application at least the following three steps are required:
  1. Create the experiment geometry.
  2. Create the particle source.
  3. Write the application main-method.

Both the experiment geometry and the particle source are provided as separate classes by the user.

Step 0: Preparations

The Geant4 development environment needs to be setup. If you have not already done so, follow the installation guide: installation guide

Step 1: Define geometry

The geometry is a description of all the solid objects in the simulation which can interact with the particles which are being simulated. Because of Geant4's roots as a simulation system for particle accelerators, this is called the Detector Construction.

The experiment geometry is provided as a class which inherits from the abstract class G4VUserDetectorConstruction. It must overload the method G4VPhysicalVolume* Construct() which returns a pointer to the experiment geometry.

 class BasicDetectorConstruction : public G4VUserDetectorConstruction{
	G4VPhysicalVolume* Construct(){

In Geant4, any simulated object is defined in three steps. First, a solid (an instance of G4Solid) is created. A G4Solid is basically a 3D shape, like a cube or a sphere.

 G4Box* solidWorld = new G4Box("World",world_sizeX,world_sizeY,world_sizeZ);
 G4Box* solidTarget new G4Box("Target",target_sizeX, target_sizeY, target_sizeZ);

By assigning a material to a solid, an instance of G4LogicalVolume is created. There are any ways to define materials in Geant4. One way is to request a pre-defined material from NIST material database by using the singleton G4NistManager.

 //Get pointer to materials database
 G4NistManager* nist = G4NistManager::Instance();
 //Build lead and air materials
 G4Material* Pb =  nist->FindOrBuildMaterial("G4_Pb");
 G4Material* air = nist->FindOrBuildMaterial("G4_AIR");
 //Fill the world with air. Create a lead target to fire particles at.
 G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, air, "myWorld");
 G4LogicalVolume* logicTarget = new G4LogicalVolume(solidTarget, Pb, "myTarget");

The logical volume is turned into a physical volume (an instance of G4VPhysicalVolume) by placing it inside a mother volume, defining its position and orientation. The only volume that has no mother volume is the "world" volume, which contains the simulation geometry.

 //Create world mother volume
 G4VPhysicalVolume* physWorld = new G4PVPlacement(
						0, 			//no rotation
						G4ThreeVector(),	//at (0,0,0)
						logicWorld,		//its logical volume
						"World",		//its name
						0,			//its mother  volume
						false,	                //no boolean operation
						0,			//copy number
						true);			//overlaps checking  

 //Place lead target in world volume
 G4VPhysicalVolume* physTarget = new G4PVPlacement(
						0, 			//no rotation
						G4ThreeVector(),	//at (0,0,0)
						logicWorld,		//its logical volume
						"Target",		//its name
						logicWorld,		//its mother  volume
						false,	                //no boolean operation
						0,			//copy number
						true);			//overlaps checking 

Finally, the detector construction class returns a pointer to the constructed geometry world volume containing the constructed geometry.

 return physWorld;

Link to the complete detector construction class definition.

Go to page 2: Defining a particle source

page 1 / page 2 / page 3 / page 4