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> <u> Simple example of <span style="color:#ff0000"> G4VUserDetectorConstruction </span> </u>: <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> == There are two base physics list classes: <span style="color:#ff0000"> G4VUserPhysicsList </span> and <span style="color:#ff0000"> G4ModularPhysicsList </span>. === <span style="color:#000080"> Simple physics lists </span> === If the particles in your simulation undergo a descrete number of physics processes you can use the class <span style="color:#ff0000"> G4VUserPhysicsList </span>. This class 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; <u> Simple example of <span style="color:#ff0000"> G4VUserPhysicsList </span> </u>: <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 implement the methods ConstructParticle(), ConstructProcess() and SetCuts(): <span style="color:#800000"> void MyPhysicsList :: ConstructParticle() { </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 you can select those which are relevant to your simulation. The processes are grouped in seven categories and their full list is available [http://geant4.cern.ch/support/proc_mod_catalog/processes/ here]: <div style="column-count:2;-moz-column-count:2;-webkit-column-count:2"> * electromagnetic * hadronic * decay * photolepton-hadron * optical * parameterization * transportation </div> In method ConstructProcess() define your physics processes: <span style="color:#800000"> void MyPhysicsList :: ConstructProcess() { </span> <span style="color:#800000"> AddTransportation(); // Assign transportation process to all particles </span> <span style="color:#800000"> ConstructEM(); // Electromagnetic processes </span> <span style="color:#800000"> ConstructGeneral(); // Other processes } </span> In methods ConstructEM() and ConstructGeneral() assign the physics processes to the corresponding particles: <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> <span style="color:#800000"> void MyPhysicsList :: ConstructGeneral() { </span> <span style="color:#800000"> G4Decay* theDecayProcess = new G4Decay() </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"> if theDecayProcess->IsApplicable(*particle)) { </span> <span style="color:#800000"> pmanager->AddProcess(theDecayProcess); </span> <span style="color:#800000"> pmanager->SetProcessOrdering(theDecayProcess,idxPostStep); </span> <span style="color:#800000"> pmanager->SetProcessOrdering(theDecayProcess,idxAtRest); }}} </span> This is the [http://geant4.cern.ch/support/proc_mod_catalog/particles/ full list] of physics processes available for each particles. Finally, 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> === A realistic physics list has a lot of different physics processes. For example, the photon from the above example can undergo compton scattering apart from conversion. In this case we use <span style="color:#ff0000"> G4VModularPhysicsList </span> which is derived from <span style="color:#ff0000"> G4VUserPhysicsList </span>. In <span style="color:#ff0000"> G4VModularPhysicsList </span> you can group the physics processes into EM physics, hadronic physics, optical physics groups etc. <u> Simple example of <span style="color:#ff0000"> G4VModularPhysicsList </span> </u>: <span style="color:#800000"> MyModPhysList::MyModPhysList() : G4ModularPhysicsList() { </span> <span style="color:#800000"> defaultCutValue = 1.0*mm; </span> <span style="color:#800000"> RegisterPhysics(new ProtonPhysics()); // All physics processes having to do with protons </span> <span style="color:#800000"> RegisterPhysics(new ElectronPhysics()); // All physics processes having to do with electrons </span> <span style="color:#800000"> RegisterPhysics(new DecayPhysics()); // Physics of unstable particles </span> where for example class ProtonPhysics() is defined as: <span style="color:#800000"> class ProtonPhysics() : public G4VPhysicsConstructor { </span> <span style="color:#800000"> public: </span> <span style="color:#800000"> ProtonPhysics(const G4String& name="proton"); </span> <span style="color:#800000"> virtual ~ProtonPhysics(); </span> <span style="color:#800000"> virtual void ConstructParticle(); </span> <span style="color:#800000"> virtual void ConstructProcess(); } </span> Particle production thresholds are defined in method SetCuts(): <span style="color:#800000"> void MyModPhysList::SetCuts() </span> <span style="color:#800000"> {SetCutsWithDefault();} </span> === <span style="color:#000080"> Pre-packaged physics lists </span> === Some pre-packaged electromagnetic and hadronic physics lists are available [http://geant4.cern.ch/support/proc_mod_catalog/physics_lists/ here]. == <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