Exercises - Day 4

Content
Introduction
Exercises
Part I
Part II
Part III
Part IV

Solutions
Part I
Part II
Part III
Part IV

Web
SW references

Manual
Appl. Dev. Man

Presentations
Slides

Main
Main

Introduction

Today's exercises cover the following items:

  • Sensitive Detector and Readout Geometry
  • Hits and Hits Collection
  • Retrieval of information from tracks, steps and particle classes
  • Simple data analysis

The Geant4 application example, which is presented on the main page, serves again as the basis of the exercises. Do not use the example with your modifications from the last two days, but download again the original tar-ball (you may find the instructions on the main page).
The exercises include the modification and/or extension of the following classes:

  • SensitiveDetector
  • DetectorReadOutGeometry
  • DetectorHit
  • UserEventAction

Exercises

Part I - Introductory exercises

Exercise 4-1
Get familiar with the classes of the example application, which are subject of the exercises (see the list above). Also try to understand the class hierarchies (abstract base class, concrete user implementation) of the relevant classes (see the below diagrams).

The following diagram shows the class hierarchy of the sensitive detector, hit, hits collection and readout geometry (click here for a PDF file):

Class Diagram 4A (Day 4)

The class hierarchy of user event action classes is shown in the second diagram (click here for a PDF file):

Class Diagram 4B (Day 4)

Answer following questions:
  • What are the base classes of the following user classes?
    • SensitiveDetector
    • DetectorReadOutGeometry
    • DetectorHit
    • UserEventAction
  • Try to remember: Which of above classes is mandatory for a Geant4 application?
  • Does a sensitive detector require a readout geometry?
  • What is the primary mandate of a sensitive detector?
  • Which method of the sensitive detector (SD) is called for each particle step inside the logical volume the SD is attached to (provided the track is alive)?
  • In which member function of the DetectorReadOutGeometry class is the readout geometry constructed? What is the return value of this function?
  • The readout geometry uses replicas of thin slices. Along which coordinate axis are the slices placed?
  • The hit class of our example is capable of storing two different quantities. What are they?
  • When are hit objects created in our application example:
    1. At the beginning of an event,
    2. at the end of an event,
    3. at the beginning of a step or
    4. at the end of a step?
  • At what level of tracking is the information of hits filled into analysis objects in our simulation application: Step, Event or Run?
  • What are the names of the member functions, where DetectorHit objects are created and filled, and where the hit information filled into analysis objects?
  • A G4Event object holds a pointer to a class which stores all hits collections at the end of an event. What is the name of this class?
  • What is required to retrieve the pointer to a hits collection from this class: The hits collection name or the collection index?

Part II - Sensitive Detector and Hits

Exercise 4-2*
Extend the functionality of the hit class, in order that lateral coordinates (x and y) of hits can also be stored. Implement appropriate get and set functions. Moreover extend the copy constructor and the assignment operator accordingly.

  • Note: This exercise only affects the hit class, but not the sensitive detector. The introduced functionalities will be used in the next exercise.

Exercise 4-3
This exercise provides a transition to part III (The topics covered in part II and III are closely linked, since the functionality of sensitive detectors allows to keep track of information which is basically retrieved from objects of classes like G4Track, G4Step or G4DynamicParticle):
In the ProcessHits method of your sensitive detector, retrieve the lateral coordinates of the particle step, and store them in the modified Hit class by using the new get functions.

  • From which step-point do you need to retrieve the information?
  • Note: You don't need the readout geometry for this example.
  • Hint: The G4ThreeVector class provides the following methods to retrieve the x, y and z coordinates: x(), y() and z().

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 for primary particle tracks:

  • How can primary particle tracks be distinguished from secondary particle tracks?

Exercise 4-5
Modify the conditional statement of the previous example, in order that hits are only created for secondary gammas:

  • How can you check the particle type?

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:
    • Create a new source file UserTrackingAction.cc, which contains the implementation of this function.
    • The class definition already contains a data member "counter" of type G4int, which should be used to accumulate the number of secondary electrons.
    • Don't forget to initialize the counter.
  2. Integration of user action class into the example:
    • Where do you have to instantiate and register the user tracking action class?

Part IV - Analysis

iAIDA can store analysis objects (histograms, tuples etc.) either in XML format or in HBOOK format (compatible with old-fashioned FORTRAN CERN library). The exercise code shows how to perform either option: the XML option is commented out, while the HBOOK one is active. You may choose to edit the exercise to do the other way around. The actions to plot the histogram created by the exercise are summarized below in either case.

XML histogram
The execution of the exercise creates a energydeposition.xml file
HBOOK histogram
The execution of the exercise creates a energydeposition.hbook file
For the following exercise the AIDA tutorial example must be downloaded and compiled:

  1. The analysis exercise should be performed in a c-shell environment. Execute:
    tcsh

  2. Create a new directory, e.g.
    mkdir analysis

  3. Copy the tar-ball AIDATutorial.tgz from /home/instructor/course/ into this directory and extract it:
    cd analysis
    cp /home/instructor/course/AIDATutorial.tgz .
    tar xzvf AIDATutorial.tgz

  4. Set up the environment in your current working shell
    source env.tcsh

  5. Compile the analysis example:
    make

  6. The executable AIDATutorial is located in the current directory. Synopsis:
    ./AIDATutorial < AIDA XML file > < name of IHistogram1D object >
    E.g.:
    /AIDATutorial $HOME/exerciseday4/energydeposition.xml energydeposit

  7. The program creates an output file "histogram.ps" in the current directory.

 

In the directory where your energydeposition.hbook file has been created:

Type PAW; this invokes the CERN Library FORTRAN analysis tool:

PAW

******************************************************
*
*  W E L C O M E to P A W
*
* Version 2.14/04 12 January 2004
*
******************************************************
Workstation type (?=HELP) <CR>=1 :     

Within PAW, type the following commands:

> histogram/file 1 energydeposition.hbook

> histogram/plot 1

> exit

 

 

Exercise 4-7
Create plots of the longitudinal energy deposition for different particle beams and beam energies (prepare macro files to run the simulation application for each particle-energy combination); you may use the AIDATutorial program or PAW to plot the histograms:

  • Electrons: 2 MeV, 10 MeV and 15 MeV (1000 primary events each)
  • Protons: 50 MeV, 70 MeV and 90 MeV (100 primary events each)
  • Gammas: 20 keV and 40 keV (10000 primary events each)