Difference between revisions of "Geant4"
(5 intermediate revisions by one other user not shown) | |||
Line 2: | Line 2: | ||
[http://geant4.cern.ch/ Geant4] is a software toolkit for the simulation of the passage of particles through matter. It is used by a large number of experiments and projects in a variety of application domains, including high energy physics, astrophysics and space science, medical physics and radiation protection. It is free to install and run, and does not require RSICC approval. | [http://geant4.cern.ch/ Geant4] is a software toolkit for the simulation of the passage of particles through matter. It is used by a large number of experiments and projects in a variety of application domains, including high energy physics, astrophysics and space science, medical physics and radiation protection. It is free to install and run, and does not require RSICC approval. | ||
− | == Using | + | == Using Geant4 == |
Geant4 is a simulation toolkit in which the user implements various classes in order to run their simulation; it is not like MCNP or other programs in which there is an input deck. The user needs to compile and link their code before running a simulation. This tutorial will describe using Geant4 on an implemented example from the toolkit. | Geant4 is a simulation toolkit in which the user implements various classes in order to run their simulation; it is not like MCNP or other programs in which there is an input deck. The user needs to compile and link their code before running a simulation. This tutorial will describe using Geant4 on an implemented example from the toolkit. | ||
− | Geant4 is installed in <code> /opt/geant4.9.5</code>. The data files are located in <code> /opt/geant4.9.5/share/Geant4-9.5.1/data</code>, and the examples in <code> | + | Geant4 is installed in <code> /opt/geant4.9.5</code>. The data files are located in <code> /opt/geant4.9.5/share/Geant4-9.5.1/data</code>, and the examples in <code> /opt/geant4.9.5/share/Geant4-9.5.1/examples</code>.Please compile your Geant4 code on the head node <code>necluster</code>. Compute nodes do not have all the development libraries needed. |
− | /opt/geant4.9.5/share/Geant4-9.5.1/examples</code>. | + | |
+ | === Example === | ||
+ | First create a directory in which you plan to do your Geant4 Development: | ||
+ | |||
+ | <code>mkdir Geant4WorkDir </code> | ||
+ | |||
+ | It is recommended to use <code>cmake</code> with both a build and a source directory: | ||
+ | |||
+ | <code>mkdir Geant4WorkDir/basic-src Geant4WorkDir/basic-build</code> | ||
+ | |||
+ | Setup of the Geant4 variables is done with: | ||
+ | |||
+ | <code>source /opt/geant4.9.5/bin/geant4.sh</code>, and can be checked with <code>printenv | grep G4</code>. | ||
+ | |||
+ | Next, we will copy all of the basic examples into our source directory: | ||
+ | |||
+ | <code> | ||
+ | cd Geant4WorkDir/ | ||
+ | |||
+ | cp -r /opt/geant4.9.5/share/Geant4-9.5.1/examples/basic/* basic-src/ | ||
+ | |||
+ | ls basic-src/</code> | ||
+ | |||
+ | Finally, we compile the code by building a makefile with <code>cmake</code>, and then running <code>make</code>. | ||
+ | |||
+ | <code> | ||
+ | cd basic-build/ | ||
+ | |||
+ | cmake -i /home/murffer/Geant4WorkDir/basic-src/ | ||
+ | </code> | ||
+ | |||
+ | The <code>-i</code> option to cmake runs in interactive mode. Select the Debug option, and change the install directory to something other than <code>/usr/bin</code>. I changed mine to <code>/home/murffer/Geant4WorkDir/basic-src</code>. | ||
+ | <code> | ||
+ | make | ||
+ | |||
+ | make install | ||
+ | </code> | ||
+ | The example can then be executed: | ||
+ | <code> | ||
+ | cd ../basic-src/B4/B4d | ||
+ | /home/murffer/Geant4WorkDir/basic-src/bin/exampleB4d run1.mac | ||
+ | </code> | ||
+ | with the final lines of the output being: | ||
+ | <code> | ||
+ | ----> print histograms statistic | ||
+ | EAbs : mean = 22.425706304686 MeV rms = 22.026959205583 MeV | ||
+ | EGap : mean = 207.54521746955 keV rms = 417.49822664632 keV | ||
+ | LAbs : mean = 1.5516788317101 cm rms = 1.7340235417956 cm | ||
+ | LGap : mean = 1.0939232182903 mm rms = 2.1946830757275 mm | ||
+ | Graphics systems deleted. | ||
+ | Visualization Manager deleting... | ||
+ | </code> |
Latest revision as of 14:56, 30 March 2012
About Geant4
Geant4 is a software toolkit for the simulation of the passage of particles through matter. It is used by a large number of experiments and projects in a variety of application domains, including high energy physics, astrophysics and space science, medical physics and radiation protection. It is free to install and run, and does not require RSICC approval.
Using Geant4
Geant4 is a simulation toolkit in which the user implements various classes in order to run their simulation; it is not like MCNP or other programs in which there is an input deck. The user needs to compile and link their code before running a simulation. This tutorial will describe using Geant4 on an implemented example from the toolkit.
Geant4 is installed in /opt/geant4.9.5
. The data files are located in /opt/geant4.9.5/share/Geant4-9.5.1/data
, and the examples in /opt/geant4.9.5/share/Geant4-9.5.1/examples
.Please compile your Geant4 code on the head node necluster
. Compute nodes do not have all the development libraries needed.
Example
First create a directory in which you plan to do your Geant4 Development:
mkdir Geant4WorkDir
It is recommended to use cmake
with both a build and a source directory:
mkdir Geant4WorkDir/basic-src Geant4WorkDir/basic-build
Setup of the Geant4 variables is done with:
source /opt/geant4.9.5/bin/geant4.sh
, and can be checked with printenv | grep G4
.
Next, we will copy all of the basic examples into our source directory:
cd Geant4WorkDir/
cp -r /opt/geant4.9.5/share/Geant4-9.5.1/examples/basic/* basic-src/
ls basic-src/
Finally, we compile the code by building a makefile with cmake
, and then running make
.
cd basic-build/
cmake -i /home/murffer/Geant4WorkDir/basic-src/
The -i
option to cmake runs in interactive mode. Select the Debug option, and change the install directory to something other than /usr/bin
. I changed mine to /home/murffer/Geant4WorkDir/basic-src
.
make
make install
The example can then be executed:
cd ../basic-src/B4/B4d
/home/murffer/Geant4WorkDir/basic-src/bin/exampleB4d run1.mac
with the final lines of the output being:
----> print histograms statistic
EAbs : mean = 22.425706304686 MeV rms = 22.026959205583 MeV
EGap : mean = 207.54521746955 keV rms = 417.49822664632 keV
LAbs : mean = 1.5516788317101 cm rms = 1.7340235417956 cm
LGap : mean = 1.0939232182903 mm rms = 2.1946830757275 mm
Graphics systems deleted.
Visualization Manager deleting...