Back to Agenda
cmake
the code and build it. Try
out the application:
$ cd <tutorial> |
The second arm can be rotated between runs. The
magnetic-field value can also be changed. User defined UI commands allow
to change arm rotation and magnetic field value at run time.
At the end of this hands on the complete geometry will look
like:
Reminder on different ways to create a geometry setup:
G4PVPlacement
(these have been already covered in Hands On 2).G4PVParametrised
to place multiple copies
of the same volume with dimensions/position parametrised
by the copy number.
Check the DetectorConstruction.hh
file, since many
variables you will need are already defined there.
Implement the second hodoscope.
The second hodoscope is composed of 25 planes of dimensions:
10x40x1 cm. The hodoscopes tiles are composed of scintillator material.
Instantiate
a single shape and a single logical volume. Place 25 physical volume placements
in the second arm mother volume (this mother volume is already created).
Each tile is positioned at Y=Z=0 with
respect to the mother volume, while the X coordinates depends on the
tile numnber.
Hint: Check what is done for the hodoscope of the first
arm. Remember dimensions passed to Geant4 solid classes are half
dimensions.
DetectorConstruction.cc File: |
// =============================================
|
Build the drift chambers.
The second arm contains 5 drift chambers made of argon gas with
dimensions 300x60x2 cm. These are equally spaced inside the second arm
starting from -2.5 m to -0.5 m along the Z coordinate.
Hint: Use same methods used for step 1.
DetectorConstruction.cc File: |
// Step 2: Add 5 drift chambers made of argon, with dimensions (X,Y,Z):
|
Add a virtual wire plane in the drift chambers.
Add a plane of wires in the drift chambers of step
2. To simplify our problem we do not describe the single wires,
instead we add a new argon-filled volume of dimensions 300x60x0.02 cm
in the center of each of the five drift chambers.
This exercise is technically simple (a single placement), however it
shows a very useful concept: we create a single instance of this
volume and we place it once inside the mother logical volume (the
drift chamber logical volume), since the mother volume is repeated
five times, each chamber gets its own wire plane. We are
reducing the number of class instances needed for the description
of our geometry (and thus reducing the memory footprint of our
application, beside making the code more compact and readable).
DetectorConstruction.cc File: |
// Step 3: Add a virtual wire plane of (300,60,0.02)cm
|
Build an electromagnetic calorimeter.
An electromagnetic calorimeter has the goal to measure the energy
of absorbed particles. Its dimensions are such that an electron or
gamma of the typical beam energy is fully absorbed, while hadrons
(such as protons), only leave a fraction of their
energy in an electromagnetic calorimeter (because it is too
short). In our example we implement a homogeneous calorimeter made of
a matrix of CsI
crystals (a charged particles emits light when interacting with this
material, the quantity of light produced is proportional to the
energy lost by the particle).
Build a 300x60x30 cm CsI calorimeter. The calorimeter is made of a
matrix of 15x15x30 cm crystals. Instead of using placements we show
how to use parametrised solids. The idea is that the position of the
placement is a function of the crystal number. The parametrization
class is already available for you in
CellParametrisation
. Check the method
CellParameterisation::ComputeTransformation(...)
to
understand how the calorimeter cells are implemented.
The calorimeter should be placed at 2 m downstream along Z in the second arm
mother volume.
DetectorConstruction.cc File: |
// Step 4: Build CsI EM-calorimeter of (300,60,30)cm
|
Implement the hadronic calorimeter
This is a sampling calorimeter made of lead as absorber material
(used for its high density) interleaved with plates of scintillator
(the active material). It is called sampling because only a fraction of
the energy lost by the particles is measured (the one lost in the
active material), this is proportional to the total energy
loss and hence to the impinging particle energy (you may be aware of
the problem of non-compensation, but we will not discuss it
here).
Implement the calorimeter using replicas to slice a larger volume into
smaller units. Each cell has 20 layers of 4 cm thick lead plate and 1 cm
thick scintillator plate. The size of the plate is 30 cm square. The
calorimeter has 10 towers of 2 cells each. Here is a
schematic drawing of the calorimeter. From left to right: the full
calorimeter with a single tower;
a single tower is divided in two cells; the third picture shows a single
cell
with a single layer; finally a single layer with the active scintillator tile.
Beam is perpendicular to the screen.
/tutorial/detector/armAngle
,
/tutorial/field/value
to move the second arm and set the
magnetic field. Note that geometry can be changed only between
runs. The methods DefineCommands
gives an example on how
to define application specific commands (this is an advanced topic not
discussed in this Hands-On's). Use the
help
UI command to get help on commands.
DetectorConstruction.cc File: |
// Step 5: Add a "sandwich" hadronic calorimeter of dimensions:
|
Provide visualization attributes for the second arm volumes.
Note that hadronic calorimeter sub-structure is by default made invisible to reduce visual clutter. This is helpful to hide the geometry details less important to the simulation.
DetectorConstruction File: |
// visualization attributes ------------------------------------------------
|
G4VHit
):
an energy deposit in space and time. Typically we are not
interested in hits in all detector elements, but instead we want to
retrieve information only for the relevant detector
components, to simulate the detector read-out (e.g. the scintillator tiles
in the hadronic calorimeter, and not the lead absorber).
In Geant4 this is achieved with the concepts of hits and
sensitive detectors (SD): you can attach a SD (a user class
inheriting from G4VSensitiveDetector
) to a logical
volume, in this way Geant4 will call your user-code when a particle is
tracked in this specific volume. Information can be retrieved from the
G4Step
(e.g. energy
deposited along the step) and a new hit is created (or an
existing hit is updated). Geant4 will keep track of all hits created
in the application. These can be retrieved at the end of the event for further
post-processing and writing to output.
We will show how to measure a quantity, for each event,
from the hodoscopes. The goal is to measure at what time and in which hodoscope
tile there was a hit.
The exercise is divided in three parts, and you will have to modify
four files:
HodoscopeHit.hh
and HodoscopeHit.cc
files
implement the hit class for the hodoscope.HodoscopeSD.cc
implements the hodoscope sensitive
detector.DetectorConstruction.cc
instantiates the sensitive detector
and attaches it to the correct logical volume.
Create a hit class.
This concrete Hit class represents a data container for only two
quantities: an integer value, representing the index of the hodoscope tile
that fired; and a double value, representing the time in which the
hodoscope tile fired. Reminder: a hodoscope is a simple set of
scintillators that measure the time in which a charged particle
passes through it. It can be used to performed time-of-flight
measurement and coarse-granularity position measurements.
You will need to modify the HodoscopeHit
class. The class skeleton is
already prepared, you should add two data members that identify which hodoscope
tile has fired and register the time of the hit.
Note, that empty Constructor, the operators new and delete have been already
implemented. You should remove the empty implementation and
implement the correct methods. Implement/modify the Print
method to dump
the hit content.
Important note on operator new
and
operator delete
: hits can put some
pressure on CPU, because, for each event, many hits may be created
and deleted at the end of the
event. Allocating on the heap is a
(relatively) CPU-intensive operation, thus the handling of hits may
cause some
performance degradation in a complex application.
To mitigate this we
use an allocator that allows for an efficient re-use memory and
avoid many calls to new/delete.
The first time a hit is created a memory pool is created that can hold
(like in an array) many hits. Each time a hit is created
with new operator we first look in this pool for an available
pre-allocated memory location. If an empty slot is available, we
re-use it, otherwise we grow the pool to contain more
hits.
With this technique we reduce substantially the new/delete cycles needed
for the simulation.
An additional complication is that in multi-threading
environments special attention is needed for the use of allocators.
We recognize this is an advanced topic that requires some
more advanced knowledge of C++. If you do not feel
comfortable with this discussion, you can remove from the HodoscopeHit.hh file
the lines defining the new and delete operators, the application will
work perfectly and since the hits are very simple and the simulation
program is not too complex you will not see any CPU penalty.
This exercise implements a single sensitive detector and one hit type. In Hands On 4 additional sensitive detectors are used with hits in the drift chambers and in the calorimeters. You can study that code to see additional types of hits (calorimeter hits are of some interest since accumulate energy from several steps instead of creating a new hit at each step).
HodoscopeHit.hh file: |
class HodoscopeHit : public G4VHit
|
HodoscopeHit.cc file: |
|
Create and manipulate hodoscope hits.
For this exercise you will modify HodoscopeSD.cc
file.
Some part of
the code is already implemented, in particular the
initialization of the hits collection, use this code as a reference
for your future applications: it is important to understand the details of
how the registering of
hits with the Geant4 kernel works.
What you need to do for this exercise is to modify the method
ProcessHits
and implement the logic to extract time and
position. This is the method that Genat4 kernel will call every time a
particle passes through the volume associated with this SD. The
G4Step
object encodes the information regarding the
simulation step in the geometry volume.
Hint 1: Given a G4Step
two points are defined
(G4StepPoint
) that delimit the step itself (pre- and post-).
From each
point you can retrieve which volume the step belongs to via the
touchable history:
G4TouchableHistory* touchable = static_cast<G4TouchableHistory*>(
stepPoint->GetTouchable() ); |
DetectorConstruction.cc
).G4StepPoint
defining a G4Step
, which one of the two should you use,
pre- or post- step point? Why? The answer to this question is one of
the most trickiest part of Geant4 for a new user, be sure to
understand the reason why the two points are not equivalent!ProcessHits
.
A realistic detector electronics will responds with a
single measurement: to simulate this behavior every time a new step is
processed we check if the hit for the hodoscope tile that fired already
exists, if so we update the time information if the new hit happens
earlier than the already recorded one.
HodoscopeSD.cc file: |
|
Construct the SD and attach it to the correct logical volume.
We can now create an instance of the HodoscopeSD and attach it
to the correct logical volume. Add a separate instance of the SD to
each arm hodoscope. Give the names "/hodoscope1" and "/hodoscope2" to
these SDs. The same class is used for two logical volumes, the
two instances are recognized by Geant4 only via their names.
We are going to modify the method
ConstructSDandField
in the DetectorCostruction class.
If you are already a user of older version of Geant4
(up to version 9.6) this is one of the new
main features introduced in version 10.0 to be compatible with multi-threading.
To reduce memory consumption geometry is
shared among threads, but sensitive-detectors are not.
DetectorConstruction.cc file: |
void DetectorConstruction::ConstructSDandField()
|
G4UserEventAction
class provides interfaces
to interact with Geant4 at the beginning and at the end of each
event. G4UserRunAction
allows for the creation of a user-custom
G4Run
object and it executes user-code at the beginning and at the
end of a run (this will be covered in the Hands On
4). G4VUserPrimaryGeneratorAction
controls the
creation of primaries, G4UserSteppingAction
allows to
retrieve information at each step (indipendentely of sensitive detectors), G4UserTrackingAction
allows for interaction with each G4Track
and finally
G4UserStackingAction
allows to control the urgency of
each new G4Track
(advanced).
Note for users of older versions of Geant4:
Multi-threading requires user actions to be thread-private (differently
from initialization classes that are shared among threads). A new user initialization class is available in
version 10: G4VUserActionInitialization
this provides a
method Build()
in which all user actions are instantiated
(this method is called by each worker thread). A second method
BuildForMaster
is called by the master thread. Among all
user actions the G4UserRunAction
is the only one that can
also be instantiated for the master
thread, this is to allow for reduction
of results from worker threads to master thread
(e.g. sum the partial results of each thread into a global
result). This will be covered in the Hands On 4.
Using a G4UserEventAction
print on screen the number
of hits and the time registered in the hodoscopes.
For this exercise you will need to modify in file EventAction.cc
the method EndOfEventAction
, this method is called by
Geant4 at the end of the simulation of each event. The pointer to the
current G4Event
is passed to the user-code. From this
object you will retrieve the hits collections for the two
hodoscopes and dump to screen the collected information.
Part of the EventAction
code is already implemented.
In particular take a moment to study the method
BeginOfEventAction
: in this method we retrieve the IDs of
the two collections. Note the if
statement that allows
for an efficient search of the IDs, given the collection names, only
once. Searching with strings is a time consuming operation, this
method allows for reducing the CPU time, if many collections are
created this is an important optimization to consider.
Important: The code assumes you have called the two SDs: "/hodoscope1" and "/hodoscope2" and that they create a hit collection called "hodosopeColl". Change these if you have modified the names.
The EventAction
is instantiated in the
ActionInitialization
class. Take a look at it and see how
the EventAction
is created.
The solution shows how to introduce some run-time checks of the
effective existence of the hits. While this is not necessary in this
simple code, this is a good code practice:
in large applications the presence of hits collections may be
decided at run time depending on the job configuration.
EventAction.cc file: |
|