Introduction to GEANT4
From UCL HEP PBT Wiki
for
Introduction to GEANT4
Jump to:
navigation
,
search
== <span style="color:#000080"> Introduction </span> == 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: * <span style="color:#ff0000"> G4VUserDetectorConstruction </span>: Describe the experimental setup, geometry and materials * <span style="color:#ff0000"> G4VUserPhysicsList </span>: Define particles, physics processes and range cuts * <span style="color:#ff0000"> G4VUserPrimaryGeneratorAction </span>: Describe particle source, source dimensions, initial position, energy spectrum, angular distributions ; Optional classes: * <span style="color:#ff0000"> G4UserRunAction </span>: Define and store histograms * <span style="color:#ff0000"> G4UserEventAction </span>: Event selection and analysis of simulation data * <span style="color:#ff0000"> G4UserStackingAction </span>: Customize priority of tracks * <span style="color:#ff0000"> G4UserTrackingAction </span>: Decide whether a trajectory should be stored or not * <span style="color:#ff0000"> G4UserSteppingAction </span>: Kill, suspend, postpone a track ; Manager class * <span style="color:#ff0000"> G4RunManager </span>: Manages the simulation process == <span style="color:#000080"> The function main() </span> == The function <span style="color:#ff0000"> main() </span> defines the skeleton of your simulation code. Inside the function you instantiate <span style="color:#ff0000"> G4RunManager </span> and notify it of your mandatory and optional classes. Example <span style="color:#ff0000"> main() </span> function: <span style="color:#800000"> { </span> <span style="color:#800000"> ... </span> <span style="color:#800000"> // Run manager construction </span> <span style="color:#800000"> G4RunManager* runManager = new G4RunManager; </span> <span style="color:#800000"> // mandatory user initialization classes </span> <span style="color:#800000"> runManager->SetUserInitialization(new MyDetectorConstruction); </span> <span style="color:#800000"> runManager->SetUserInitialization(new MyPhysicsList); </span> <span style="color:#800000"> // mandatory user action classes </span> <span style="color:#800000"> runManager->SetUserAction(new MyPrimaryGeneratorAction); </span> <span style="color:#800000"> // optional user action classes </span> <span style="color:#800000"> runManager->SetUserAction(new MyEventAction); </span> <span style="color:#800000"> runManager->SetUserAction(new MyRunAction); </span> <span style="color:#800000"> ... </span> <span style="color:#800000"> } </span> == <span style="color:#000080"> Experimental setup </span> == You can define your experiment by using three base classes: * 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"> G4Logical 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: <span style="color:#800000"> G4VSolid* pBoxSolid = new G4Box(“WaterBox”, 1.*m, 2.*m, 3.*m); </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, false, copyNo); </span> Your detector is always placed in a mother volume called a world volume. The world volume is defined in a similar way: <span style="color:#800000"> G4VSolid* pWorld = new G4Box("World",5*m,5*m,5*m); </span> <span style="color:#800000"> G4LogicalVolume* pWorldLog = new G4LogicalVolume(pWorld,vacuum, "World"); </span> <span style="color:#800000"> G4VPhysicalVolume* pWorldPhys = new G4PVPlacement(0,G4ThreeVector(),pWorldLog,"World",0,false,0); </span> The elements and materials used in the experiment are defined using classes <span style="color:#ff0000"> G4Element </span> and <span style="color:#ff0000"> G4Material </span>. For example material water and elements hydrogen and oxygen are defined as: <span style="color:#800000"> G4Element* H = new G4Element("Hydrogen","H",z=1.,a= 1.01*g/mole); </span> <span style="color:#800000"> G4Element* O = new G4Element("Oxygen","O",z=8.,a=16.00*g/mole); </span> <span style="color:#800000"> density = 1.000*g/cm3; </span> <span style="color:#800000"> G4Material* H2O = new G4Material("Water",density,ncomp=2); </span> <span style="color:#800000"> H2O->AddElement(H, natoms=2); </span> <span style="color:#800000"> H2O->AddElement(O, natoms=1); </span> == <span style="color:#000080"> Physics processes </span> == == <span style="color:#000080"> Generate primary particles </span> == <span style="color:#ff0000"> G4VUserPrimaryGeneratorAction </span> is a mandatory user action class to control the generation of primary particles. The particle generation is done via classes <span style="color:#ff0000"> G4ParticleGun </span> and <span style="color:#ff0000"> G4GeneralParticleSource </span>. * <span style="color:#ff0000"> G4ParticleGun </span> is used to simulate a beam of particles. It shoots a primary particle of a certain energy and direction from a given point at a given time. * <span style="color:#ff0000"> G4GeneralParticleSource </span> simulates a beam of particles and the primary vertex is randomly chosen on surface of a given volume with pre-defined energy spectra, spatial and angular distribution. == <span style="color:#000080"> Optional user classes </span> ==
Return to
Introduction to GEANT4
.
Views
Page
Discussion
View source
History
Personal tools
Log in
Navigation
Main page
Community portal
Current events
Recent changes
Random page
Help
Search
Toolbox
What links here
Related changes
Special pages