Several proton beams with spread out Bragg peaks


Jump to: navigation, search



This tutorial is based on the Monoenergetic proton pencil beam example. The code run with several beam energies to produce spread out Bragg peak.

The water cube is divided into slices using class G4PVReplica. At each slice the deposited dose and energy for every energy beam is computed. The energy and the dose are scored using classes G4UserSteppingAction and G4UserRunAction. The proton beams are simulated using G4ParticleGun class. There is an option to chose among several EM and the QGSP_BIC_EMY physics lists.


This image shows only one proton beam energy. The water box is divided into slices using class G4PVReplica. Photons are in green, protons are in blue, neutrons are in yellow.

How to run the tutorial

Connect to the HEP cluster and create folder ProtonSBFolder in your area
ssh -X's password: type your password here

[username@plus1 ~]$ mkdir ProtonSBFolder 

[username@plus1 ~]$ cd ProtonSBFolder  
Setup your environment
[username@plus1 PhotonSBFolder]$ source /unix/pbt/software/dev/bin/  
Copy the code to your working directory and rename it
[username@plus1 PhotonSBFolder]$ cp -r /unix/pbt/tutorials/basic/ProtonSB .
[username@plus1 PhotonSBFolder]$ mv ProtonSB ProtonSB_source
Inside /home/username/ProtonSBFolder/ create a directory
[username@plus1 PhotonSBFolder]$ mkdir ProtonSB_build  
To compile the code enter this directory and run cmake and make
[username@plus1 PhotonSBFolder]$ cd ProtonSB_build 

[username@plus1 ProtonSB_build]$ cmake -DGeant4_DIR=/unix/pbt/software/dev /home/username/ProtonSBFolder/ProtonSB_source 

[username@plus1 ProtonSB_build]$ make  
Run macro proton.mac
[username@plus1 ProtonSB_build]$ ./protonSB proton.mac

How to analyze data

The code produces two text files DoseFile.txt and PlotDose.txt. The file DoseFile.txt contains energy and dose deposition for every layer and for every beam energy. The file PlotDose.txt contains only depth vs dose for each layer for every beam energy. These text files can be analyzed with MATLAB or ROOT.

Text files

This is the content of DoseFile.txt with proton beam energies 50, 52, 54 and 56 MeV. This is the content of the PlotDose.txt.

Root file

You can use script PlotSimulation.C to plot the spread out Bragg peak. The script uses PlotDose.txt. Copy the script to your current ProtonSB_build directory:

cp /home/username/ProtonSBFolder/ProtonSB_source/PlotSimulation.C .

Then, run the script:

[username@plus1 ProtonSB_build]$ root -l 

root [1] .x PlotSimulation.C

This will create SOBP.root file with the following plot:


Run with different settings

You can change the physics process, incident proton beam energies, number of slices etc. by modifying macros proton.mac and protonLoop.mac. This is the content of proton.mac:

# proton.mac
/control/verbose 2
/run/verbose 2
/tracking/verbose 0
/run/particle/verbose 1
# set geometry
/protonSB/det/setSizeX  4 cm
/protonSB/det/setSizeYZ 4 cm
/protonSB/det/setSliceSizeYZ 4 cm
/protonSB/det/sliceNumber 50
# set physics process
/protonSB/phys/addPhysics QGSP_BIC_EMY
#/protonSB/phys/addPhysics emlivermore
#/protonSB/phys/addPhysics empenelope
# production tresholds (recommended range
#cut off not bigger than 10% of slice thickness)
/protonSB/phys/setCuts 0.2 mm
#/protonSB/phys/setGCut 1 um
#/protonSB/phys/setECut 1 um
#/protonSB/phys/setPCut 1 um
# initialize
# visualisation
#/control/execute visualisation.mac
/control/loop protonLoop.mac ene 50 56 2

This is the content of protonLoop.mac:

# protonLoop.mac
/gun/particle proton
# particle energy
/gun/energy {ene} MeV
# beam size
#/photonSB/gun/rndm 3 mm
# step limit (recommended not bigger than 5% of
# slice thickness)
/protonSB/stepMax 0.1 mm
/protonSB/event/printModulo 50
# number of events
/run/beamOn 6000

Change of the beam energies

You can change the proton beam energies by modifying this line in proton.mac

/control/loop protonLoop.mac ene 50 56 2

where "50" is the initial value, "56" is the final value and "2" is the step size in MeV.


If you want to use visualisation (with DAWN), in macro proton.mac uncomment line #/control/execute visualisation.mac. Then, run the code. You will have four images from the four proton beams.

For proton energy of 50 MeV:

For proton energy of 52 MeV:

For proton energy of 54 MeV:

For proton energy of 56 MeV:

Protons are in blue, neutrons are in yellow, photons are in green.


List of spread out Bragg peaks files with brief description

Personal tools