How to track time from beginning to end of a run?

Hi everyone,

Apologies as I am fairly new to Geant4. I am trying to track the time that it takes for an entire run to complete (essentially, I am spawning a given amount of radioisotopes in a single run and I would like to know how long it takes for all these to decay and the run to end).

I am aware that there is a function called GetGlobalTime() which returns the global time of a given step point, however a single run may have multiple steps and I only want to get the time it takes for the whole run to complete.

Any help would be appreciated!

You need to be careful about talking about “runs” vs. “events” vs. “steps.” This is described in detail in the documentation.

A run consists of a large number of events (/run/beamOn). In each event, you can have one or more primary particles, which interact in your geometry and create secondary particles.

Within a single event, each particle, or track, will take a number of steps through the geometry, depositing energy, scattering, producing secondaries, etc.

If you want to know how long a given primary particle (radioisotope atom) takes to decay, Geant4 will tell you that directly. In your SteppingAction, look for the primary particle with a post-step status of fStopAndKill. At that point, ask the post-step point GetLocalTime(). That will give you the duration of the track since it was created. If you plot a histogram of GetLocalTime() for a large number of events, you’ll see the exponential decay distribution.