There are options to set various distributions to sample for the energy, momentum and position of particles generated by a source but time appears to always have to be set manually by the user before calling GeneratePrimaryVertex. Is there any specific reason there is not an option to enable a time distribution?
It might be a “philosophical” reason. In Geant4, the geometry, materials, etc. are generally treated as a fixed, static background. Each event runs through time, of course, but the next event starts over at the same initial state of the world. So usually, every event starts with t=0 and you look at the relative times of things which happen within an event.
There are cases where that’s not true – if you’re simulating pileup in a slow detector, for example. But in that case, you’ve already had to write a non-trivial PrimaryGeneratorAction, so setting the timestamp is not a big deal.
If you’re simulating radioactive decays, then Geant4 will do the timestamping for you automatically – the emplaced G4Ions will have a time t=0, but all the daughters, and everything after that, will have a timestamp based on the exponential from the half-life.
My use case here is in considering digitization where the resulting signal may depend on the time during the clock cycle a particle is generated at. Also with a view to simulating pile up in downstream analysis. In this situation it seems easier to randomize the time of the vertex rather than the randomly offset of the clock.
I accept everything I want to do is possible and easy at the moment but could be made even easier by internalising it into the G4SingleParticleSource and configurable through a standard macro.
I definitely see your use case; we have similar issues with trigger jitter. You can do it on the analysis side, but it’s much more of a pain to apply the same phase shift to a whole bunch of output data.
Since G4SingleParticleSource
is something you instantiate yourself, you could work around it by making a subclass with a UI command for a time-jitter setting, and setting the time yourself before or after you call to base.
Waiting for the Geant4 developers to do it for you is much less efficient