The situation I describe below is not addressed in the Geant4 documentation. I’m hoping that a G4 developer can respond here, and possibly expand the documentation to cover this situation.
Our simulation framework includes a set of macro commands to allow users to adjust the physics configuration. We do this by making use of the proper modular physics lists, starting with one of the official reference lists (FTFP_BERT, Shielding, etc.) and adding or modifying physics constructors by way of
Because of Geant4’s configuration requirements, we have to register a physics list at the very beginning of
main(), before we get to instantiate the UI. So we register the basic list first, and the user can then use macro commands to adjust its content.
I’ve run into a problem with this, where if the user adds new physics, which provides new particles (via the proper
ConstructParticle() action), we get a cascade of errors at
/run/initialize complaining that particles are being instantiated outside the PreInit state. This despite the fact that we open the UI in PreInit, and G4 is in the PreInit state when
/run/initialize is called.
As near as I can tell, it seems that the PL’s
ConstructParticle() function gets called at the time it is passed to the RunManager. Any additional physics constructors passed in later do not get their
ConstructParticle() functions called. This results is a series of error messages when those “late” constructors try to do their thing, and the job crashes.
Should we be calling
ConstructParticle() ourselves, when a new block of physics is requested via UI command? Should we re-call the whole PL’s
ConstructParticle() function to trigger this?