Hands-on

Code for download: session1_start.tar.gz

Hands-on 1a:

Geant4 is already installed on the machines in the directory /nfsapp/physics. You can define the environment needed to build & run Geant4 application using the provided script:

source /nfsapp/physics/geant4.bash -n

The -n parameter is used to select the latest Geant4 version installed, 11.0.p1.

Build & run the example:

Download the start source code session1_start.tar.gz. (On Linux, the file will be saved as session1_start.tar.gz in $HOME/Downloads directory.)

Untar the file:

tar xvf session1_start.tar.gz

Rename the session1_start directory as exampleED:

mv session1_start exampleED

Create the example build directory, run cmake and make to build the application:

mkdir exampleED_build
cd exampleED_build
cmake ../exampleED
make

Run the created executable:

./exampleED

You can also find the instruction how to build and run the example at the Geant4 examples Web page.

Get familiar with the provided code

You can skip DetectorConstruction.cc and PrimaryGeneratorAction.cc which will be explored later

Get familiar with Geant4 Qt User Interface

  • Use the provided button (an arrow in a green circle) to run 1 event, observe the picture and the output in the Output window.
  • Run 1 event from the command line. You have to type this command in the Session window: /run/beamOn 1
  • Run 1 event via a selection of the command from the Help menu.
  • Set tracking verbose level to 1 and observe the output: /tracking/verbose 1

Hands-on 1b:

Add your first modification

Add printing of the event number at the begin of event and another printing about the end of event in the EventAction class.

G4cout << ">>> Start event: " << event->GetEventID() << G4endl;
G4cout << ">>> End event: " << event->GetEventID() << G4endl;

Check the G4Event class functions in the Geant4 source code browser. Fill G4Event.hh in ‘File Name Search’, then click on ‘/event/include/G4Event.hh’ and then you should see GetEventID() among the class functions.

Hint: Each line of the code above should be inserted in the relevant function of the EventAction class in the EventAction.cc file.

Solution: session1_solution.tar.gz