17.3. Global Time
Table of Contents
`GetGlobalTime()`
Global time is the simulation time associated with a particle track or step, measured from the beginning of the current event. In Geant4, you access it through the method G4Track::GetGlobalTime() or, more commonly in stepping and sensitive detector code, through the pre and post step points.
You can think of global time as the clock that starts at zero when an event begins and advances as particles are created, transported, and interact. Every step of every track in the event has an associated global time value.
In C++ you typically access global time inside a stepping action or sensitive detector like this:
G4double tGlobal =
step->GetPreStepPoint()->GetGlobalTime();or, if you need the time at the end of the step:
G4double tGlobal =
step->GetPostStepPoint()->GetGlobalTime();The returned value is in internal Geant4 time units (seconds), so you should always multiply by a unit when you use it:
#include "G4SystemOfUnits.hh"
G4double t_ns = tGlobal / ns;
Important rule: GetGlobalTime() is the time since the start of the event, not since the primary was created and not since the track was created. It always increases along the causal chain of particles in one event.
Global time is defined for every track, including primary and secondary particles. When a secondary is created, its initial global time equals the global time of the step that produced it, because it is generated at that point in the event history.
This makes GetGlobalTime() useful for several timing related tasks: computing time of flight between two detector elements by subtracting times of hits, ordering hits in a detector by their arrival time, applying detector timing windows to reject late hits, and simulating coincidence timing in systems such as PET scanners.
Within runs, global time resets for each new event. If you need a continuous time stamp that spans multiple events, you must build it yourself, usually by storing the event ID together with the global time, or by adding an offset that you manage in your own code.
In analysis code you should always store times with explicit units and convert them to human friendly numbers before writing output. For example:
auto analysisManager = G4AnalysisManager::Instance();
analysisManager->FillNtupleDColumn(colIdTime, tGlobal / ns);This ensures that when you read the data later, you know that the column is in nanoseconds and can compare it consistently with other timing information in your simulation.
Views: 9
KAHIBARO