Introduction to GEANT4
From UCL HEP PBT Wiki
m |
m |
||
Line 1: | Line 1: | ||
== <span style="color:#000080"> Introduction </span> == | == <span style="color:#000080"> Introduction </span> == | ||
- | |||
GEANT4 is a software toolkit based on C++. In your code you have to define: | GEANT4 is a software toolkit based on C++. In your code you have to define: | ||
Line 36: | Line 35: | ||
* <span style="color:#ff0000"> Event </span>: a collection of information from tracks and trajectories | * <span style="color:#ff0000"> Event </span>: a collection of information from tracks and trajectories | ||
* <span style="color:#ff0000"> Run </span>: a collection of events | * <span style="color:#ff0000"> Run </span>: a collection of events | ||
- | |||
== <span style="color:#000080"> The function main() </span> == | == <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 <span style="color:#ff0000"> MyDetectorConstruction </span>, <span style="color:#ff0000"> MyPhysicsList </span>, <span style="color:#ff0000"> MyPrimaryGeneratorAction </span>, <span style="color:#ff0000"> MyEventAction </span> and <span style="color:#ff0000"> MyRunAction </span> are derived classes from the GEANT4 base classes: | 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 <span style="color:#ff0000"> MyDetectorConstruction </span>, <span style="color:#ff0000"> MyPhysicsList </span>, <span style="color:#ff0000"> MyPrimaryGeneratorAction </span>, <span style="color:#ff0000"> MyEventAction </span> and <span style="color:#ff0000"> MyRunAction </span> are derived classes from the GEANT4 base classes: | ||
Line 71: | Line 68: | ||
== <span style="color:#000080"> Experimental setup </span> == | == <span style="color:#000080"> Experimental setup </span> == | ||
- | |||
You derive your own class from <span style="color:#ff0000"> G4VUserDetectorConstruction </span> base class. In the derived class you will: | You derive your own class from <span style="color:#ff0000"> G4VUserDetectorConstruction </span> base class. In the derived class you will: | ||
Line 78: | Line 74: | ||
* Construct materials and electromagnetic fields using <span style="color:#ff0000"> G4Logical Volume </span> | * Construct materials and electromagnetic fields using <span style="color:#ff0000"> G4Logical Volume </span> | ||
* Place volumes of your detector geometry using <span style="color:#ff0000"> G4VPhysical Volume </span> | * Place volumes of your detector geometry using <span style="color:#ff0000"> G4VPhysical Volume </span> | ||
- | |||
<u> Simple example of class <span style="color:#ff0000"> MyDetectorConstruction </span> </u>: | <u> Simple example of class <span style="color:#ff0000"> MyDetectorConstruction </span> </u>: | ||
Line 100: | Line 95: | ||
Now construct the detector. Your detector is always placed in a mother volume called the world volume. | Now construct the detector. Your detector is always placed in a mother volume called the world volume. | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 114: | Line 108: | ||
G4VPhysicalVolume* pWorldPhys = new G4PVPlacement(0,G4ThreeVector(),pWorldLog,"World",0,false,0); | G4VPhysicalVolume* pWorldPhys = new G4PVPlacement(0,G4ThreeVector(),pWorldLog,"World",0,false,0); | ||
- | |||
// Water box | // Water box | ||
Line 126: | Line 119: | ||
“WaterBox”, pWorldLog, false, copyNo); ... } | “WaterBox”, pWorldLog, false, copyNo); ... } | ||
</pre> | </pre> | ||
- | |||
The elements and materials are defined using classes <span style="color:#ff0000"> G4Element </span> and <span style="color:#ff0000"> G4Material </span>. For example water, hydrogen and oxygen are defined as: | The elements and materials are defined using classes <span style="color:#ff0000"> G4Element </span> and <span style="color:#ff0000"> G4Material </span>. For example water, hydrogen and oxygen are defined as: | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 149: | Line 140: | ||
water->AddElement(O, natoms=1); ...} | water->AddElement(O, natoms=1); ...} | ||
</pre> | </pre> | ||
- | |||
[http://geant4.web.cern.ch/geant4/UserDocumentation/Doxygen/examples_doc/html/group__extended__common__detectorConstruction.html Here] you can find more examples of DetectorConstruction classes. | [http://geant4.web.cern.ch/geant4/UserDocumentation/Doxygen/examples_doc/html/group__extended__common__detectorConstruction.html Here] you can find more examples of DetectorConstruction classes. | ||
- | |||
== <span style="color:#000080"> Physics processes </span> == | == <span style="color:#000080"> Physics processes </span> == | ||
- | |||
You can build your own physics list or chose from already built physics lists. To build your own physics lists, you can use two base physics list classes: <span style="color:#ff0000"> G4VUserPhysicsList </span> and <span style="color:#ff0000"> G4ModularPhysicsList </span>. The class <span style="color:#ff0000"> G4VUserPhysicsList </span> is used for simple physics lists while <span style="color:#ff0000"> G4ModularPhysicsList </span> is used to build more complex physics lists. There exist also already built pre-packaged physics lists. | You can build your own physics list or chose from already built physics lists. To build your own physics lists, you can use two base physics list classes: <span style="color:#ff0000"> G4VUserPhysicsList </span> and <span style="color:#ff0000"> G4ModularPhysicsList </span>. The class <span style="color:#ff0000"> G4VUserPhysicsList </span> is used for simple physics lists while <span style="color:#ff0000"> G4ModularPhysicsList </span> is used to build more complex physics lists. There exist also already built pre-packaged physics lists. | ||
- | |||
=== <span style="color:#000080"> Simple physics lists </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> to define them. This class has three methods: | If the particles in your simulation undergo a descrete number of physics processes you can use the class <span style="color:#ff0000"> G4VUserPhysicsList </span> to define them. This class has three methods: | ||
Line 168: | Line 154: | ||
* ConstructProcesses() : Define all necessary processes and assign them to proper particles; | * ConstructProcesses() : Define all necessary processes and assign them to proper particles; | ||
* SetCuts() : Define production thresholds in terms of range; | * SetCuts() : Define production thresholds in terms of range; | ||
- | |||
<u> Simple example of class <span style="color:#ff0000"> MyPhysicsList </span> </u>: | <u> Simple example of class <span style="color:#ff0000"> MyPhysicsList </span> </u>: | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 189: | Line 173: | ||
</pre> | </pre> | ||
- | |||
Now implement the methods ConstructParticle(), ConstructProcess() and SetCuts(): | Now implement the methods ConstructParticle(), ConstructProcess() and SetCuts(): | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 209: | Line 191: | ||
</pre> | </pre> | ||
- | + | 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 | |
- | 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 | + | |
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2"> | <div style="column-count:2;-moz-column-count:2;-webkit-column-count:2"> | ||
Line 222: | Line 203: | ||
</div> | </div> | ||
- | + | and their list is available [http://geant4.cern.ch/support/proc_mod_catalog/processes/ here]. For each particle in ConstructParticle() assign all the physics processes you want to consider in your simulation: | |
- | For each particle | + | |
- | consider in your simulation: | + | |
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
void MyPhysicsList::ConstructProcess() { | void MyPhysicsList::ConstructProcess() { | ||
Line 236: | Line 214: | ||
ConstructGeneral(); // Other processes } | ConstructGeneral(); // Other processes } | ||
</pre> | </pre> | ||
- | |||
In methods ConstructEM() and ConstructGeneral() assign the physics processes to the corresponding particles: | In methods ConstructEM() and ConstructGeneral() assign the physics processes to the corresponding particles: | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 282: | Line 258: | ||
</pre> | </pre> | ||
- | + | This is the full [http://geant4.cern.ch/support/proc_mod_catalog/particles/ list] of physics processes available for every particle. Finally, in method SetCuts() you can define cuts on the particles: | |
- | This is the full [http://geant4.cern.ch/support/proc_mod_catalog/particles/ list] of physics processes available for every particle. Finally, method SetCuts() | + | |
Line 297: | Line 272: | ||
SetCutValue(defaultCutValue, "e-"); | SetCutValue(defaultCutValue, "e-"); | ||
</pre> | </pre> | ||
- | |||
=== <span style="color:#000080"> Detailed physics lists </span> === | === <span style="color:#000080"> Detailed physics lists </span> === | ||
- | |||
If you want to build more realistic physics list you have to use the class <span style="color:#ff0000"> G4VModularPhysicsList </span>. For example, the photon from the example above can undergo compton scattering apart from conversion. In <span style="color:#ff0000"> G4VModularPhysicsList </span> you can group the physics processes into separate modules: EM physics, hadronic physics, decay physics etc. | If you want to build more realistic physics list you have to use the class <span style="color:#ff0000"> G4VModularPhysicsList </span>. For example, the photon from the example above can undergo compton scattering apart from conversion. In <span style="color:#ff0000"> G4VModularPhysicsList </span> you can group the physics processes into separate modules: EM physics, hadronic physics, decay physics etc. | ||
- | |||
<u> Simple example of class <span style="color:#ff0000"> MyPhysicsList </span> </u>: | <u> Simple example of class <span style="color:#ff0000"> MyPhysicsList </span> </u>: | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 337: | Line 308: | ||
</pre> | </pre> | ||
- | + | Now, build the physics lists: | |
- | Now | + | |
- | + | ||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 384: | Line 353: | ||
} ... } | } ... } | ||
</pre> | </pre> | ||
- | |||
and | and | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 403: | Line 370: | ||
</pre> | </pre> | ||
- | |||
=== <span style="color:#000080"> Pre-packaged physics lists </span> === | === <span style="color:#000080"> Pre-packaged physics lists </span> === | ||
- | |||
Some built-in pre-packaged physics lists are available [http://geant4.web.cern.ch/geant4/support/proc_mod_catalog/physics_lists/referencePL.shtml here]. You can use them as a starting point of your simulation. | Some built-in pre-packaged physics lists are available [http://geant4.web.cern.ch/geant4/support/proc_mod_catalog/physics_lists/referencePL.shtml here]. You can use them as a starting point of your simulation. | ||
- | |||
<u> Simple example of <span style="color:#ff0000"> pre-packaged physics list </span> </u>: | <u> Simple example of <span style="color:#ff0000"> pre-packaged physics list </span> </u>: | ||
- | |||
In function <span style="color:#ff0000"> main() </span>: | In function <span style="color:#ff0000"> main() </span>: | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 425: | Line 387: | ||
For example, if you want to simulate clinical proton beam of energy 150 MeV you can use pre-packaged physics list e.g. QGSP_BIC, QGSP_BERT and FTFP_BERT. If you are interested in Bragg curve physics, use a physics list ending in "EMV" or "EMX" e.g. QGSP_BERT_EMV. | For example, if you want to simulate clinical proton beam of energy 150 MeV you can use pre-packaged physics list e.g. QGSP_BIC, QGSP_BERT and FTFP_BERT. If you are interested in Bragg curve physics, use a physics list ending in "EMV" or "EMX" e.g. QGSP_BERT_EMV. | ||
+ | |||
+ | === <span style="color:#000080"> Building your own physics list </span> === | ||
+ | |||
+ | See Computed tomography tutorial. | ||
- | |||
== <span style="color:#000080"> Generate primary particles </span> == | == <span style="color:#000080"> Generate primary particles </span> == | ||
- | |||
You derive your own class from <span style="color:#ff0000"> G4VUserPrimaryGeneratorAction </span> base class. | You derive your own class from <span style="color:#ff0000"> G4VUserPrimaryGeneratorAction </span> base class. | ||
Line 435: | Line 399: | ||
* <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"> 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:#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. | ||
- | |||
<u> Simple example of class <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using particle gun </u>: | <u> Simple example of class <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using particle gun </u>: | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 464: | Line 426: | ||
G4ParticleGun* fParticleGun; }; | G4ParticleGun* fParticleGun; }; | ||
</pre> | </pre> | ||
- | |||
<u> Simple example of class <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using general particle source </u>: | <u> Simple example of class <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using general particle source </u>: | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> | ||
Line 490: | Line 450: | ||
</pre> | </pre> | ||
- | + | [http://geant4.web.cern.ch/geant4/UserDocumentation/Doxygen/examples_doc/html/group__extended__common__primaryGenerator.html Here] you can find how to implement MyPrimaryGeneratorAction class in your code. | |
- | [http://geant4.web.cern.ch/geant4/UserDocumentation/Doxygen/examples_doc/html/group__extended__common__primaryGenerator.html Here] you can find how to implement MyPrimaryGeneratorAction class | + | |
- | |||
== <span style="color:#000080"> Optional user classes </span> == | == <span style="color:#000080"> Optional user classes </span> == | ||
Line 521: | Line 479: | ||
Status is attached to each <span style="color:#ff0000"> G4StepPoint </span> to show how step was determined. You can use ''PostStepPoint'' to get status of current step and ''PreStepPoint'' to get status of previous step. For example to get the x coordinate of a step you do the following: | Status is attached to each <span style="color:#ff0000"> G4StepPoint </span> to show how step was determined. You can use ''PostStepPoint'' to get status of current step and ''PreStepPoint'' to get status of previous step. For example to get the x coordinate of a step you do the following: | ||
- | |||
<pre style="color: #800000; background-color: #dcdcdc"> | <pre style="color: #800000; background-color: #dcdcdc"> |