An Introduction to Geant4 - Nuclear Physics - University of Liverpool
An Introduction to Geant4 - Nuclear Physics - University of Liverpool
An Introduction to Geant4 - Nuclear Physics - University of Liverpool
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong><br />
David Oxley<br />
<strong>University</strong> <strong>of</strong> <strong>Liverpool</strong><br />
<strong>Nuclear</strong> <strong>Physics</strong><br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
<strong>Introduction</strong>: GEANT4<br />
• <strong>Geant4</strong> is monte-carlo simulation <strong>to</strong>olkit<br />
– http://geant4.web.cern.ch/geant4<br />
• Simulates radiation interactions with matter<br />
• GEometry ANd Tracking<br />
• HEP background<br />
• C++ based / Object orientated<br />
Be aware when <strong>to</strong> use Geant<br />
Freedom <strong>to</strong> do anything you want*<br />
vs<br />
Not being able <strong>to</strong> take anything for<br />
granted<br />
*providing you know how <strong>to</strong> do it<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Where <strong>to</strong> go for help?<br />
Other users within the group.<br />
<strong>Geant4</strong> report/guide my website or Laura’s website<br />
http://geant4.cern.ch/G4UsersDocuments/Overview/html/index.html<br />
<strong>Geant4</strong> Application Developer’s Guide:<br />
http://geant4.cern.ch/G4UsersDocuments/UsersGuides/ForApplicationD<br />
eveloper/html/index.html<br />
You will need this, this course does not replace it.<br />
HyperNews Forum<br />
http://hypernews.slac.stanford.edu/HyperNews/geant4/cindex<br />
Self-help forum, where users and developers help each other.<br />
Existing <strong>to</strong>pics may include your answers.<br />
Explain your problem, what you have done: either another user, or a<br />
developer will help.<br />
All developers I have had <strong>to</strong> ask have been very helpful.<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Setup<br />
<strong>Geant4</strong> should be installed across the network and useable on any <strong>of</strong><br />
the systems.<br />
Set environment variables each time you open xterm.<br />
Open an xterm, and enter the three commands below.<br />
Entering the first command should result in a list <strong>of</strong> text outputs<br />
being shown in the xterm.<br />
<strong>Geant4</strong> will then run in this (and only this) xterm.<br />
If you close the xterm and open a new one, you will need <strong>to</strong> execute<br />
the commands again.<br />
• source /usr/share/geant4/env.csh<br />
• setenv G4LEDATA “/usr/local/geant4/data/G4EMLOW4.3”<br />
• source /usr/local/aida/openscientist/v16rl/aida-setup.csh<br />
If this does not happen computer support may need <strong>to</strong> install a<br />
package on your machine.<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Checking the geant4 setup<br />
• I provide an example code on my website (3 versions)<br />
• http://ns.ph.liv.ac.uk/imaging-group/group-members/dave-oxley.php<br />
• V3: One smartPET detec<strong>to</strong>r,<br />
– data stream read out,<br />
– source defined in a macros<br />
• V4: Two SmartPET detec<strong>to</strong>rs in coincidence<br />
– Two separate singles data streams and one coincidence data stream<br />
– Source defined in a macros<br />
• V5: Two SmartPET detec<strong>to</strong>rs in PET configuration<br />
– Coincidence between the two<br />
– Motion <strong>of</strong> detec<strong>to</strong>rs at 10deg angular steps (controlable in macros)<br />
– One coincidence output reading out angle as well<br />
• Copy any <strong>of</strong> these <strong>to</strong> a direc<strong>to</strong>ry where geant4 should run<br />
• Type “make” <strong>to</strong> build the simulation<br />
• Type “g4run ” i.e. g4run V3 <strong>to</strong> execute<br />
• The command line should say “Idle>” this means geant4 is<br />
running<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Units in <strong>Geant4</strong><br />
• Users Guide section 3.3<br />
• <strong>Geant4</strong> kernel uses a fixed set <strong>of</strong> units.<br />
• Define your variables in a unit by multiplying.<br />
Example:<br />
int length = 5*cm;<br />
double mass = 68*kg;<br />
• Extract values from geant4.<br />
• Change them in<strong>to</strong> the necessary unit by dividing.<br />
Example:<br />
int xside = length; // will be in Geant standard units (mm’s for length)<br />
Int xside2 = length/cm; // will be in cm<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Some Basics<br />
• Simplest Geant simulation needs three classes and a main <strong>to</strong> run<br />
– Geometry<br />
– Primary Genera<strong>to</strong>r Action<br />
– <strong>Physics</strong> List<br />
Main<br />
PrimaryGenera<strong>to</strong>r Geometry <strong>Physics</strong><br />
Running <strong>Geant4</strong>:<br />
Use the command line<br />
Hard code your commands in<strong>to</strong> your main<br />
Use a macros a script containing a list <strong>of</strong> commands executed<br />
sequentially<br />
Use a GUI (I have never done)<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Defining your materials<br />
• Materials are defined based upon their chemical structure<br />
• First define your element(s)<br />
• Then define your material<br />
• Assigned weighted quantities <strong>of</strong> element <strong>to</strong> material<br />
• Two examples: Argon (element), Water (composite)<br />
• A<strong>to</strong>mic number, molar mass, density<br />
Example: Water H 2<br />
O<br />
• Two ingredients : Two hydrogen , one oxygen<br />
• Define hydrogen<br />
• Define Oxygen<br />
• Define Water<br />
• Assign two hydrogen a<strong>to</strong>ms and one oxygen a<strong>to</strong>m <strong>to</strong> water<br />
vid Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> Geant
Defining your materials in C++<br />
Define liquid Argon:<br />
G4double density = 1.390*g/cm3;<br />
G4double molMass = 39.95*g/mole;<br />
G4Material* lAr = new G4Material(name="liquidArgon", z=18.,molMass,<br />
density);<br />
Define Water:<br />
molMass = 1.01*g/mole;<br />
G4Element* elH = new G4Element(name="Hydrogen",symbol="H" ,<br />
z= 1., molMass);<br />
molMass = 16.00*g/mole;<br />
G4Element* elO = new G4Element(name="Oxygen" ,symbol="O" , z=<br />
8., molMass);<br />
density = 1.000*g/cm3;<br />
G4Material* H2O = new<br />
G4Material(name="Water",density,ncomponents=2);<br />
H2O->AddElement(elH, na<strong>to</strong>ms=2);<br />
H2O->AddElement(elO, na<strong>to</strong>ms=1);<br />
User Guide section 4.2
Designing your world<br />
• Define all objects within the world<br />
– Shape<br />
– Size<br />
SOLID (G4SOLID)<br />
– Material<br />
– Position<br />
LOGIC (G4LOGIC)<br />
PHYSICAL (G4PVPLACEMENT)<br />
To start, use the classes provided<br />
– Box, Cylinder, Sphere<br />
– Many more existing classes, User’s Guide (4.1.2)<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Defining your world in C++<br />
• Define a cube <strong>of</strong> liquid water (3x4x8)cm at p1 = (5,2,3)cm<br />
– We need a cube or box: Look at the G4Box construc<strong>to</strong>r<br />
G4Box (const G4String& pName,<br />
G4double halfX,<br />
G4double halfY,<br />
G4double halfZ)<br />
G4LogicalVolume(G4VSolid pSolid,<br />
G4Material pMaterial,<br />
const G4String& Name)<br />
G4PVPlacement( G4RotationMatrix* pRot,<br />
const G4ThreeVec<strong>to</strong>r& tlate,<br />
G4LogicalVolume* pCurrentLogical,<br />
const G4String& pName,<br />
G4LogicalVolume* pMotherLogical,<br />
G4bool pSurfChk=false,<br />
G4int pCopyNo)
Defining your world in C++<br />
• Define a cube <strong>of</strong> water (3x4x8)cm at p1 = (5,2,3)cm<br />
– We need a cube or box: Look at the G4Box construc<strong>to</strong>r<br />
(1)G4Box *thisBox = new G4Box(“ThisBoxsName”,1.5*cm,2*cm,4*cm);<br />
creates a box with these dimensions, it is not made <strong>of</strong> anything or put<br />
anywhere yet!<br />
(2) G4LogicalVolume *thisBox_log =<br />
new G4LogicalVolume(thisBox,H20,”BoxLogName”);<br />
tells <strong>Geant4</strong> that this box is <strong>to</strong> be made <strong>of</strong> water<br />
(3) G4PVPlacement *thisBox_phys = new G4PVPlacement<br />
(0,<br />
G4ThreeVec<strong>to</strong>r(5*cm,2*cm,3*cm),<br />
thisBox_log,<br />
”BoxPhysName”,<br />
world, // its mother<br />
false,<br />
0);
Summary: Geometry<br />
Solid Volume<br />
Shape , Size<br />
G4Box (box(!)), G4Tubs(cylinder)<br />
G4Orb (sphere)<br />
Logical Volume<br />
Material<br />
G4LogicalVolume<br />
H 2<br />
O<br />
Physical Volume<br />
Rotation, Translation<br />
G4PVPlacement<br />
y<br />
z<br />
H 2<br />
O<br />
x
Defining a source<br />
• Two types covered here<br />
– Beams<br />
– Stationary sources<br />
• Beams are defined in a source file in the Primary Genera<strong>to</strong>r Action<br />
• Stationary sources can be defined there using random numbers <strong>to</strong><br />
generate isotropic distributions<br />
• Or use pre-defined class in a macro G4GeneralParticleSource<br />
Primary<br />
Secondary<br />
e-<br />
Source<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Primary Genera<strong>to</strong>r Action<br />
• Generate particles using G4GeneralParticleSource() or<br />
G4GeneralParticleGun(G4int Number<strong>of</strong>Particles)<br />
• Source for stationary sources<br />
/gps/source/intensity 1 # intensity, relative <strong>to</strong> other sources<br />
/gps/particle gamma # particle type<br />
/gps/pos/type Point # source shape<br />
/gps/pos/centre 0. 0. 0. cm # source central position<br />
/gps/ang/typ iso<br />
# distribution<br />
/gps/energy 200 keV # energy<br />
http://reat.space.qinetiq.com/gps/new_gps_sum_files/gps_sum.htm<br />
• Gun for a beam experiment (see attachment or User’s<br />
Guide 2.6.1):<br />
– Assign a particle name (type α,β,γ)<br />
– Assign a kinetic energy<br />
– Assign a momentum direction<br />
– Assign a position the particles originate from<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
<strong>Physics</strong> List<br />
• <strong>Geant4</strong> doesn’t “au<strong>to</strong>matically” include any physics<br />
• You need <strong>to</strong> tell <strong>Geant4</strong> what physical interactions you are<br />
interested in<br />
• Originates from particles physics background where “new<br />
physics” would need implementing<br />
• Include:<br />
– Particles you want (bosons, mesons etc.)<br />
– Interactions you want (pho<strong>to</strong>electric, Comp<strong>to</strong>n, Pair production<br />
– The correct energy range: different for the energy range you are<br />
interested in<br />
– Standard, low energy, very low energy<br />
– Beware <strong>of</strong> your cut values<br />
• Example physics list attached<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
<strong>Physics</strong> List: Cuts<br />
• Cut value defines the extent <strong>to</strong> which a particle is tracked<br />
• Cuts are defined in distance<br />
• Converted in<strong>to</strong> energy based on the material<br />
Cut value = 1mm<br />
SOLID GERMANIUM<br />
GAS<br />
100keV<br />
1mm<br />
e -<br />
100keV<br />
Electron won’t be tracked<br />
Distance < Cut<br />
Electron will be tracked<br />
Distance > Cut
The main<br />
• The main file loads in these three classes<br />
• See attached example<br />
• See User Guide for example , section 2.1.1<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
• Visualize<br />
Run an example
Running a useful geant4<br />
simulation<br />
• Although the simulation described above will run, it won’t<br />
produce an output<br />
• <strong>Geant4</strong> has objects where interactions are not readout (i.e.<br />
the frame <strong>of</strong> an array or some lead shielding<br />
• If the user is interested in the interactions, the volume must<br />
be made “sensitive”<br />
NaI<br />
Sensitive<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Running a useful geant4<br />
simulation<br />
• Although the simulation described above will run, it won’t<br />
produce an output<br />
• <strong>Geant4</strong> has objects where interactions are not readout (i.e.<br />
the frame <strong>of</strong> an array or some lead shielding)<br />
• If the user is interested in the interactions, the volume must<br />
be made “sensitive”<br />
Gamma Camera<br />
Sensitive<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Extracting information from Geant<br />
• Two additional classes (minimum):<br />
– Sensitive Detec<strong>to</strong>r<br />
– Hit<br />
– (Event Action) is useful, but not essential<br />
• Which volumes are made sensitive is defined in the geometry class<br />
– At logical stage<br />
• Hit defines the object <strong>of</strong> an interaction<br />
– Energy deposit, Position, Interaction type, Detec<strong>to</strong>r segment<br />
• Hits will only be defined in sensitive detec<strong>to</strong>rs (not in passive<br />
volumes)<br />
• Hits are assigned their attributes (Energy, position) not in the hit<br />
class, but in the sensitive detec<strong>to</strong>r class<br />
Geometry<br />
Sensitive<br />
Detec<strong>to</strong>r<br />
Hit<br />
Output<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Compare C++ codes<br />
• Geometry: assigns a volume <strong>to</strong> be sensitive<br />
• Sensitive detec<strong>to</strong>r:<br />
– builds a Hit<br />
– assigns it <strong>to</strong> HitCollection<br />
• Hit class defines attributes <strong>of</strong> the hit<br />
• Sensitive Detec<strong>to</strong>r either:<br />
– outputs HitCollection<br />
– or sends HitCollection <strong>to</strong> EventAction file<br />
• EventAction:<br />
– necessary <strong>to</strong> process several HitCollections<br />
– examine several HitCollections, establish HitCollection<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
Other, simpler Option<br />
• Scoring<br />
• Easier than sensitive detec<strong>to</strong>r/ hit.<br />
• Envolves less coding<br />
• Never used it myself not in these lectures or my codes<br />
• Good presentation<br />
• geant4.slac.stanford.edu/Space06/presentations/05_Friday/<br />
03-Aso_SpaceScorer.ppt<br />
David Oxley<br />
<strong>An</strong> <strong>Introduction</strong> <strong>to</strong> <strong>Geant4</strong>
<strong>An</strong>alysing the output<br />
• Build root tree within Geant<br />
• Personally, output .csv-file analyse <strong>of</strong>fline in root, java, C,<br />
matlab<br />
• Write data <strong>to</strong> external file<br />
<strong>of</strong>stream file(“/home/dco/geant4/files/output.csv”);<br />
// declares the output stream name (in this case “file” and<br />
assigns it a location<br />
file
DO’s<br />
Finally…<br />
DON’T’s<br />
Consult the user guide with any<br />
problems or for more detail<br />
Consult the HyperNews forum if<br />
you get stuck<br />
Just start playing around with one<br />
<strong>of</strong> the codes<br />
If you get a bug in it you can’t fix,<br />
you can always download it again<br />
Always think about what you<br />
need in terms <strong>of</strong> physics and<br />
cut values<br />
Do discard physics and events you don’t<br />
need:<br />
you are the expert <strong>of</strong> your work<br />
Treat this lecture as a<br />
replacement <strong>of</strong> the User Guide:<br />
<strong>Geant4</strong> is very complex and<br />
cannot be explained fully in two<br />
hours<br />
Don’t wait until you are a C++<br />
expert before you start<br />
Don’t read the whole user guide<br />
before you start<br />
Don’t assume <strong>Geant4</strong> will “just<br />
get it right”<br />
Don’t let <strong>to</strong>o much detail slow<br />
you down