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. This is example <span style="color:#ff0000"> main() </span> function, where MyDetectorConstruction, MyPhysicsList, MyPrimaryGeneratorAction, MyEventAction and MyRunAction are derived classes from the GEANT4 base classes: <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 the 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> == Two kinds of base physics list classes are available for users to derive from <span style="color:#ff0000"> G4VUserPhysicsList </span> and <span style="color:#ff0000"> G4ModularPhysicsList </span>. There exist also prepackaged physics list provided by GEANT4. === <span style="color:#000080"> Simple physics lists </span> === The class <span style="color:#ff0000"> G4VUserPhysicsList </span> is used for simple physics lists. It has three methods: * ConstructParticles(): define all necessary particles; * ConstructProcesses(): define all necessary processes and assign them to proper particles; * SetCuts(): define production thresholds in terms of range; This example shows how to define your own class derived from the <span style="color:#ff0000"> G4VUserPhysicsList </span> base class. <span style="color:#800000"> class MyPhysicsList:public G4VUserPhysicsList() </span> <span style="color:#800000"> { public: </span> <span style="color:#800000"> MyPhysicsList(); </span> <span style="color:#800000"> ~MyPhysicsList(); </span> <span style="color:#800000"> void ConstructParticle(); </span> <span style="color:#800000"> void ConstructProcess(); </span> <span style="color:#800000"> void SetCuts(); } </span> Now you must implement the methods ConstructParticle(), ConstructProcess() and SetCuts(). <span style="color:#800000"> void MyPhysicsList :: ConstructParticles() </span> <span style="color:#800000"> { //Define the particles </span> <span style="color:#800000"> G4Electron::ElectronDefinition(); </span> <span style="color:#800000"> G4Positron::PositronDefinition(); </span> <span style="color:#800000"> G4Proton::ProtonDefinition(); </span> <span style="color:#800000"> G4Neutron::NeutronDefinition(); </span> <span style="color:#800000"> G4Gamma::GammaDefinition(); ... } </span> GEANT4 provides a variety of physics processes. These processes are decoupled from one another and the user can select those processes which are relevant to his/her simulation. There are seven categories of processes provided by GEANT4: # electromagnetic #* standard #* low Energy (Livermore Library / Penelope) # hadronic # decay # photolepton-hadron # optical # parameterization - "fast simulation" physics # transportation In method ConstructProcess() you have to define your physics processes: <span style="color:#800000"> void MyPhysicsList :: ConstructProcess() </span> <span style="color:#800000"> { // Assign transportation process to all particles </span> <span style="color:#800000"> AddTransportation(); </span> <span style="color:#800000"> // Electromagnetic processes </span> <span style="color:#800000"> ConstructEM(); </span> <span style="color:#800000"> // Other processes </span> <span style="color:#800000"> ConstructGeneral(); ... } </span> where the method ConstructEM() is defined as: <span style="color:#800000"> void MyPhysicsList::ConstructEM() </span> <span style="color:#800000"> { aParticleIterator->reset(); </span> <span style="color:#800000"> while( (*aParticleIterator)() ){ </span> <span style="color:#800000"> G4ParticleDefinition* particle = aParticleIterator->value(); </span> <span style="color:#800000"> G4ProcessManager* pmanager = particle->GetProcessManager(); </span> <span style="color:#800000"> G4String particleName = particle->GetParticleName(); </span> <span style="color:#800000"> if (particleName == "gamma") { </span> <span style="color:#800000"> pmanager->AddDiscreteProcess(new G4GammaConversion); ...} </span> and the method ConstructGeneral() is defined as: <span style="color:#800000"> void MyPhysicsList::ConstructGeneral() </span> The method SetCuts() is defined as: <span style="color:#800000"> void MyPhysicsList :: SetCuts() </span> <span style="color:#800000"> { defaultCutValue = 1.0*mm; </span> <span style="color:#800000"> SetCutValue(defaultCutValue, "gamma"); </span> <span style="color:#800000"> SetCutValue(defaultCutValue, "e+"); </span> <span style="color:#800000"> SetCutValue(defaultCutValue, "e-"); </span> === <span style="color:#000080"> Detailed physics lists </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