Energy per Event
Table of Contents
Accumulating step energy
In Geant4, energy deposition happens step by step as particles move through matter. To obtain the total energy deposited in an event, you must accumulate the contributions from all relevant steps that occur during that event.
The basic idea is simple. At each step, you read the deposited energy with G4Step::GetTotalEnergyDeposit(), convert it to convenient units, and add it to an event-level variable. At the end of the event, you use this accumulated value for analysis and then reset it for the next event.
Always accumulate energy deposition per event inside an event-specific context, such as EventAction. Never store per-event sums in static or global variables without clear event boundaries, or you will mix data from different events.
A common pattern is to define an AddEdep(G4double) method in your EventAction that increases an internal member like fEdep by the value passed to it. Your SteppingAction then calls this method for each step that deposits energy. At the end of the event, typically in EndOfEventAction, you read fEdep to fill histograms or ntuples in your analysis system.
When accumulating, pay attention to units. Geant4 returns energies in MeV by default, so if you want keV or another unit, apply the conversion consistently, for example store everything in MeV internally and only convert when printing or writing human readable output.
If your detector has multiple elements, you usually maintain one accumulator per detector element, often indexed by an ID. Event-level energy deposition then becomes either the sum over all elements or a vector of per-element energies. The important point is that, regardless of detector complexity, the accumulation is always performed step by step and reset at the beginning of each new event.
Views: 8
KAHIBARO