Exercises and Solutions - Day 4

Exercises: Exercises of the day

Exercises and solutions - Part III

The solutions are indicated in blue.

Part III - Retrieval of information from tracks, steps and particle classes

Exercise 4-4
Introduce a conditional statement in the ProcessHits method of the sensitive detector, in order that hits are only created, filled and stored in the hits collection for primary electron tracks:

From the G4Step object "step", one can retrieve the track. And from the track object, the track ID can be obtained (see code in green):
if(step -> GetTrack() -> GetTrackID() == 1) {
  DetectorHit* hit = new DetectorHit();

  hit -> SetEnergyDeposit(energyDeposit);
  hit -> SetBinCenter(binCenter);
  hitsCollection -> insert(hit);
}
Click here for the source file.

Exercise 4-5
Modify the conditional statement of the previous example, in order that hits are only created for photons (the primary electrons produce secondary photons):

if(step -> GetTrack() -> GetDefinition() == G4Gamma::Definition()) {
  DetectorHit* hit = new DetectorHit();

  hit -> SetEnergyDeposit(energyDeposit);
  hit -> SetBinCenter(binCenter);
  hitsCollection -> insert(hit);
}
Don't forget to include the header for the gamma particle definition. Click here for the source file.

Exercise 4-6
You can find here the header file for a user tracking action class (the Geant4 exercise example does not yet included a user tracking action). The aim is to complete the class implementation and to integrate the class into the existing application:

  1. Class implementation:
    Introduce a counting mechnism in the method UserPostTrackingAction, which keeps track of the total number of secondary electrons produced in the simulation:
  2. Integration of user action class into the example: