KAHIBARO
Discord Login Register

26.5. Recording Energy Deposition

Where Energy Deposition Fits in the Proton-in-Water Example

In the proton beam in water example, recording energy deposition is the key step that turns a visual simulation into a quantitative dose study. You have already defined the water phantom geometry and the proton beam, and you have selected an appropriate physics list. Now you must capture how much energy the protons (and their secondaries) deposit in the water so that you can later compute depth dose and observe the Bragg peak.

In Geant4, energy deposition is not stored automatically. You, as the user, must decide where and how to accumulate it. For this example, the main goal is to measure the energy deposited in the water phantom per event, and later, per slice of depth inside the phantom.

Using Steps to Access Deposited Energy

Energy is deposited step by step as particles move through materials. Each Geant4 step carries information about the local energy loss in that small portion of the track. The class that provides this is G4Step.

For this example, the natural place to read the step information is the user stepping action. The stepping action is called for every step of every track, so it is the right tool for accumulating local quantities such as energy deposition.

Inside your derived SteppingAction class, you will use methods of G4Step to obtain the deposited energy, and you will then pass this information to a run level accumulator, typically through the EventAction or RunAction.

The most important method for this example is:
G4double edep = step->GetTotalEnergyDeposit();

This gives the energy deposited in the current step within the current volume.

In this example, always use
$$E_{\text{dep,step}} = \texttt{step->GetTotalEnergyDeposit()}$$
as the basic quantity for energy deposition. Never try to infer energy loss by comparing particle kinetic energies, because that can lead to double counting or missing nonlocal effects.

Choosing the Volume Where Energy Is Recorded

The proton beam can produce secondaries that leave the water phantom, enter the world volume, or interact in other structures if they exist. For the proton in water project, the quantity of interest is the energy deposited inside the water phantom alone.

To enforce this, you should check that a given step occurs in the water phantom before accumulating its deposited energy. This is done by examining the logical or physical volume of the step.

A common pattern is:

  1. Get the pre step point from the step.
  2. Get its associated volume.
  3. Compare that volume with the logical or physical volume that represents the water phantom.

For example, you can retrieve the logical volume pointer of the phantom from your detector construction and then store it for later use inside the stepping action. In each call to the stepping action, you compare the step’s volume pointer with the stored phantom volume pointer. Only if they match do you add GetTotalEnergyDeposit() to your accumulator.

This guarantees that only energy deposited in the water is counted, which is crucial when you later normalize and interpret the depth dose curve.

When recording dose in the water phantom, only accumulate energy deposition for steps inside the phantom volume. Always check the step volume before adding energy. This avoids including deposition in the world or other auxiliary volumes.

Accumulating Energy per Event

For the depth dose study, you want to know the total energy deposited in the phantom per incident proton event. An event in Geant4 corresponds to one primary proton track and all of its resulting secondaries.

The structure is typically as follows.

In SteppingAction:
You obtain the step’s deposited energy, and if the step is in the phantom, you add it to an event level sum. The event level sum is usually maintained in EventAction.

In EventAction:
You provide a method such as AddEdep(G4double edep) that is called from the stepping action for each relevant step. Internally, EventAction holds a member variable like fEdep initialized to zero at the start of the event, and incremented every time AddEdep is called.

At the end of the event (in EndOfEventAction), you have the total energy deposited in the phantom for that event. You can then pass this value to the RunAction, to a histogram through the analysis manager, or to an ntuple for later analysis.

This separation keeps the stepping code simple and the logic of summing and storing results inside the event and run actions, which are designed for that purpose.

For the proton in water example, the canonical per event energy deposition is
$$E_{\text{dep,event}} = \sum_{\text{all steps in phantom}} E_{\text{dep,step}}.$$
Always reset the event accumulator at the beginning of each event, and never reuse the same variable across multiple events without resetting it.

Units and Interpreting Deposited Energy

Geant4 uses the internal unit system where energy is expressed in MeV by default. The value returned by GetTotalEnergyDeposit() is in internal units and must be interpreted with this in mind.

When working with dose or when printing out values, it is important to convert to consistent units. For example, if you compute dose, you will divide the total deposited energy by the mass of the region. If you keep energy in MeV and convert only at the end, you must also convert the mass into compatible units.

A typical pattern is to accumulate edep in MeV, then when you need to print or store a human readable result, divide by an appropriate energy unit such as MeV or keV. The same applies when you later normalize the depth dose in the following chapter.

In this project, assume energy deposition is in MeV. When printing or storing results, always use explicit unit conversion such as edep / MeV or edep / keV. Never assume that a bare double represents Joules or any SI unit without checking.

Preparing for Depth-Resolved Energy Deposition

The present chapter focuses on recording total energy deposition, but the next steps in the project require energy as a function of depth inside the water phantom. You will achieve this by dividing the phantom into slices and associating each step with a particular slice index.

The recording logic, however, remains the same:
you will still use GetTotalEnergyDeposit() in the stepping action and still check that the step is in the phantom. Instead of adding all energy to a single event sum, you will add it to the appropriate bin for that slice.

Thus, the method you have implemented here for total energy deposition is the foundation for the more detailed spatial distribution of energy. Once you are confident that the total energy per event is recorded correctly, you can safely extend the scheme to multiple slices and finally produce the depth dose and Bragg peak.

Views: 9

Comments

Please login to add a comment.

Don't have an account? Register now!