Geant4 examples Sébastien Incerti On behalf of the Geant4 collaboration with special thanks to Luciano Pandola, INFN
PART 1 Setting up your Geant4 environment
3 Getting started (1/2) We assume you have downloaded the Geant4 files for Vmware (Player for Windows users, Fusion for Mac users), from the web site Start the Vmware Player/Fusion software Open the Geant4 files Make sure to activate file exchange between Windows/Mac and the Vmware environment
4 Getting started (2/2) Log in Username : local1 Password : local1 Environment variables for Geant4 and associated tools are automatically defined when you open your session, from the file /usr/local/env/Cshrc You can define Geant4 user environment variables in your /home/local1/.ucshrc file
5 Environment variables (1/2) Already set when you when you log in Variables are defined using the command setenv VARIABLE value You can access the value of the variable using echo $VARIABLE For Geant4 system $G4INSTALL Directory where Geant4 is installed Value is $G4SYSTEM Operating system Value is Linux-g++ $G4WORKDIR Directory where executable code will be stored Value is
6 Environment variables (2/2) For data libraries $G4LEVELGAMMADATA Directory with the database of nuclear levels Value is $G4RADIOACTIVEDATA Directory with the databse of radioactive decay Value is $G4LEDATA Directory with the databse of low energy EM Physics Value is $G4NEUTRONHPDATA Directory with the databse of low energy neutrons (thermal-20 MeV) Value is $G4ELASTICDATA Directory with the databse of hadronic elastic scattering Value is $G4ABLADATA Directory with the databse of hadronic ablation models Value is
7 Geant4 examples A number of ready-to-use examples are available in Geant4 Located in $G4INSTALL/examples Three categories Novice : basic functionalities of Geant4 Extended : specific functionalities (specific Physics processes, biasing, magnetic fields…) Advanced : full simulation of realistic use cases (medical physics, space, calorimetry…)
PART 2 Running N03 without macros with macros
9 Let’s try example N03 Copy N03 to your home : cd cp –R $G4INSTALL/examples/novice/N03. cd N03 Read at the README file : simulation of a simple sampling calorimeter… Compile & link the example gmake Warning : environment variables must always be set before compiling & running an executable file.
10 Running without macros Once compiled and linked, you can run the executable using simply : $G4WORKDIR/bin/Linux-g++/exampleN03 Use your Tab key for faster recognition of existing directories You get the following screen output No argument after executable name
11 ************************************************************* Geant4 version Name: geant patch-01 (25-January-2008) Copyright : Geant4 Collaboration Reference : NIM A 506 (2003), WWW : ************************************************************* ***** Table : Nb of materials = 13 ***** [...] > The calorimeter is 10 layers of: [ 10mm of Lead + 5mm of liquidArgon ] [...] You have successfully registered the following graphics systems. Current available graphics systems are: ASCIITree (ATree) [...] Idle> ************************************************************* Geant4 version Name: geant patch-01 (25-January-2008) Copyright : Geant4 Collaboration Reference : NIM A 506 (2003), WWW : ************************************************************* ***** Table : Nb of materials = 13 ***** [...] > The calorimeter is 10 layers of: [ 10mm of Lead + 5mm of liquidArgon ] [...] You have successfully registered the following graphics systems. Current available graphics systems are: ASCIITree (ATree) [...] Idle> Running without macros
12 What happened ? 1.the run is initialized 1.definition of materials, 2.build of geometry 3.set physics processes 4.set production cuts a macro file vis.mac is automatically read to register the visualization drivers (default OGLIX) and the set-up is shown on a graphic window (OpenGL) 3.you get the Idle> prompt where you can enter commands interactively e.g. change geometry, decide which particle to shoot, which energy, execute another macro, shoot a particle,.. Running without macros
13 10 layers : 10 mm Lead + 5 mm Liquid Argon no magnetic field The default geometry What you get with the VRMLFILE visualization driver
14 Let’s try to shoot a particle: Idle> /run/beamOn 1 By default, a 50 MeV e - is shot impinging perpendicularly on the calorimeter phot: Total cross sections from Sandia parametrisation. Sampling according PhotoElectric model [...] ========= Table of registered couples ======================== Index : 1 used in the geometry : Yes recalculation needed : No Material : Lead cuts : gamma 1 mm e- 1 mm e+ 1 mm Energy thresholds : gamma keV e MeV e MeV Region(s) which use this couple : DefaultRegionForTheWorld phot: Total cross sections from Sandia parametrisation. Sampling according PhotoElectric model [...] ========= Table of registered couples ======================== Index : 1 used in the geometry : Yes recalculation needed : No Material : Lead cuts : gamma 1 mm e- 1 mm e+ 1 mm Energy thresholds : gamma keV e MeV e MeV Region(s) which use this couple : DefaultRegionForTheWorld Initialization of physics tables Calculation of energy cuts Running without macros
15 Running without macros > End of event: 0 Absorber: total energy: MeV total track length: cm Gap: total energy: keV total track length: mm Run terminated. Run Summary Number of events processed : 1 User=0.01s Real=0.35s Sys=0.09s End of Run mean Energy in Absorber : MeV eV mean Energy in Gap : keV eV mean trackLength in Absorber : cm Ang mean trackLength in Gap : mm +- 0 fm > End of event: 0 Absorber: total energy: MeV total track length: cm Gap: total energy: keV total track length: mm Run terminated. Run Summary Number of events processed : 1 User=0.01s Real=0.35s Sys=0.09s End of Run mean Energy in Absorber : MeV eV mean Energy in Gap : keV eV mean trackLength in Absorber : cm Ang mean trackLength in Gap : mm +- 0 fm Event summary Run summary
16 You also get a visualization of the event you have just shot (50 MeV e - ) primary e - gamma-rays Default color code: red = negative charge blue = positive charge green = neutral Running without macros What you get with the DAWNFILE visualization driver
17 Geant4 macros are ASCII files containing a sequence of Geant4 commands: # /run/verbose 2 /event/verbose 0 /tracking/verbose 1 # /gun/particle mu+ /gun/energy 300 MeV /run/beamOn 3 $G4WORKDIR/bin/Linux-g++/exampleN03 run1.mac The argument following the executable name is taken as a macro name, e.g. run1.mac Shoot 3 + of energy 300 MeV Running with macros
18 ---> End of event: 2 Absorber: total energy: MeV total track length: cm Gap: total energy: MeV total track length: cm Run terminated. Run Summary Number of events processed : 3 User=0.01s Real=3.78s Sys=0.06s End of Run mean Energy in Absorber : MeV MeV mean Energy in Gap : MeV keV mean trackLength in Absorber : cm mm mean trackLength in Gap : cm um > End of event: 2 Absorber: total energy: MeV total track length: cm Gap: total energy: MeV total track length: cm Run terminated. Run Summary Number of events processed : 3 User=0.01s Real=3.78s Sys=0.06s End of Run mean Energy in Absorber : MeV MeV mean Energy in Gap : MeV keV mean trackLength in Absorber : cm mm mean trackLength in Gap : cm um Summary of event #2 (the 3 rd one!) Summary of the full run Running with macros
19 primary + gamma-rays delta-ray Screenshot of the 3 events Running with macros What you get with the DAWNFILE visualization driver
20 $G4WORKDIR/bin/Linux-g++/exampleN03 run1.mac Note that is equivalent to $G4WORKDIR/bin/Linux-g++/exampleN03 [...] Idle> /control/execute run1.mac $G4WORKDIR/bin/Linux-g++/exampleN03 [...] Idle> /control/execute run1.mac command to run an external macro (but in the second case you will get the Idle> prompt back) Running with macros
21 $G4WORKDIR/bin/Linux-g++/exampleN03 Idle> /control/execute newgeom.mac Idle> /control/execute run1.mac $G4WORKDIR/bin/Linux-g++/exampleN03 Idle> /control/execute newgeom.mac Idle> /control/execute run1.mac /N03/det/setNbOfLayers 1 /N03/det/setAbsMat Water /N03/det/setAbsThick 40 cm /N03/det/setGapMat Air /N03/det/setGapThick 0 cm /N03/det/setSizeYZ 40 cm /N03/det/setField 3 tesla /N03/det/update 1) First macro changes geometry: only one layer of absorber (40 cm of water), no gap (thickness = 0 cm) practically a solid block of water Change transverse dimensions, set a 3 T magnetic field 2) Second macro shoots the MeV +, as before Change geometry on-the-fly
22 primary + B B B B Geometry, materials, magnetic field and primary particles can be tuned by ASCII macros, without recompiling the code ! x y What you get with the DAWNFILE visualization driver Change geometry on-the-fly
23 Summary Geant4 provides several examples to show basic and advanced functionalities (novice/extended) and full- scale realistic applications (advanced). Environmental variables should be properly set to compile and run Geant4 applications. Geant4 applications can be run interactively (namely, giving commands by keyboard) or by macros. A few macros are distributed with the examples. Simulation parameters (geometry, visualization, primary particles, materials) can be tuned without recompiling the code.