Introduction to GEANT4

From UCL HEP PBT Wiki

(Difference between revisions)
Jump to: navigation, search
m
m
Line 67: Line 67:
* Describing the shape and the size of your detector: <span style="color:#ff0000"> G4VSolid </span>  
* Describing the shape and the size of your detector: <span style="color:#ff0000"> G4VSolid </span>  
-
* Adding properties - material and electromagnetic field: <span style="color:#ff0000"> G4VLogical Volume </span>  
+
* Adding properties - material and electromagnetic field: <span style="color:#ff0000"> G4Logical Volume </span>  
-
* Placing it in another volume - in one or many positions: <span style="color:#ff0000"> G4Physical Volume </span>  
+
* Placing it in another volume - in one or many positions: <span style="color:#ff0000"> G4VPhysical Volume </span>  
For example if you want to make an experiment using a water box detector it ca be defined in the following way:
For example if you want to make an experiment using a water box detector it ca be defined in the following way:
Line 75: Line 75:
<span style="color:#800000"> G4VSolid* pBoxSolid = new G4Box(“WaterBox”, 1.*m, 2.*m, 3.*m); </span>  
<span style="color:#800000"> G4VSolid* pBoxSolid = new G4Box(“WaterBox”, 1.*m, 2.*m, 3.*m); </span>  
-
<span style="color:#800000"> G4VLogicalVolume* pBoxLog = new G4LogicalVolume( pBoxSolid, water, “WaterBox”); </span>  
+
<span style="color:#800000"> G4LogicalVolume* pBoxLog = new G4LogicalVolume( pBoxSolid, water, “WaterBox”); </span>  
<span style="color:#800000"> G4VPhysicalVolume* aBoxPhys = new G4PVPlacement( pRotation, G4ThreeVector(posX, posY, posZ), pBoxLog, “WaterBox”, pWorldLog,
<span style="color:#800000"> G4VPhysicalVolume* aBoxPhys = new G4PVPlacement( pRotation, G4ThreeVector(posX, posY, posZ), pBoxLog, “WaterBox”, pWorldLog,

Revision as of 11:17, 6 July 2014

Contents

Introduction

GEANT4 is a software toolkit based on C++. In your code you have to define:

  • Your experimental setup - geometry, materials and primary particles.
  • Which physics process you are interested in.
  • You may take actions during the simulation - inspect and store results.

The interaction with GEANT4 is done via base classes.

Mandatory classes
  • G4VUserDetectorConstruction : Describe the experimental setup, geometry and materials
  • G4VUserPhysicsList : Define particles, physics processes and range cuts
  • G4UserPrimaryGeneratorAction : Describe particle source, source dimensions, initial position, energy spectrum, angular distributions
Optional classes
  • G4UserRunAction : Define and store histograms
  • G4UserEventAction : Event selection and analysis of simulation data
  • G4UserStackingAction : Customize priority of tracks
  • G4UserTrackingAction : Decide whether a trajectory should be stored or not
  • G4UserSteppingAction : Kill, suspend, postpone a track
Manager class
  • G4RunManager : Manages the simulation process

The function main()

The function main() defines the skeleton of your simulation code. Inside the function you instantiate G4RunManager and notify it of your mandatory and optional classes. Example main() function:

{

...

// Run manager construction

G4RunManager* runManager = new G4RunManager;


// mandatory user initialization classes

runManager->SetUserInitialization(new MyDetectorConstruction);

runManager->SetUserInitialization(new myPhysicsList);


// mandatory user action classes

runManager->SetUserAction(new MyPrimaryGeneratorAction);


// optional user action classes

runManager->SetUserAction(new MyEventAction);

runManager->SetUserAction(new MyRunAction);

...

}

Experimental setup

You can define your experiment by using three base classes:

  • Describing the shape and the size of your detector: G4VSolid
  • Adding properties - material and electromagnetic field: G4Logical Volume
  • Placing it in another volume - in one or many positions: G4VPhysical Volume

For example if you want to make an experiment using a water box detector it ca be defined in the following way:


G4VSolid* pBoxSolid = new G4Box(“WaterBox”, 1.*m, 2.*m, 3.*m);

G4LogicalVolume* pBoxLog = new G4LogicalVolume( pBoxSolid, water, “WaterBox”);

G4VPhysicalVolume* aBoxPhys = new G4PVPlacement( pRotation, G4ThreeVector(posX, posY, posZ), pBoxLog, “WaterBox”, pWorldLog, false, copyNo);


Your detector is always placed in a mother volume called a world volume. The world volume is defined in a similar way:


G4VSolid* pWorld = new G4Box("World",5*m,5*m,5*m);

G4LogicalVolume* pWorldLog = new G4LogicalVolume(pWorld,vacuum, "World");

G4VPhysicalVolume* pWorldPhys = new G4PVPlacement(0,G4ThreeVector(),pWorldLog,"World",0,false,0);


The elements and materials used in the experiment are defined using classes G4Element and G4Material. For example water is defined as:


G4Element* H = new G4Element("Hydrogen","H",z=1.,a= 1.01*g/mole);

G4Element* O = new G4Element("Oxygen","O",z=8.,a=16.00*g/mole);


density = 1.000*g/cm3;

G4Material* H2O = new G4Material("Water",density,ncomp=2);

H2O->AddElement(H, natoms=2);

H2O->AddElement(O, natoms=1);

Physics processes

Generate primary particles

Optional user classes

Personal tools