Replicating the same simulation on different geometries

I have a simulation where particles are generated with random directions towards my mass model.

I would like to test some changes in the mass model. The easiest way to do this would be to generate the exact same particles on a different geometry, but from what I know I can input the same starting seed, but if I change the geometry all the following seeds will be different.

From what I recall from the Geant4 school, this is due to the fact that the last number produced in the event is used as seed for the following one. Thus even if I input the same starting seed, a different geometry will produce different subsequent seeds and I wont be able to replicate the exact same particle distribution.

Is there a way around this?

Thanks a lot

You can save the random seeds for each event to file using UI commands:

/random/setSavingFlag 1
/random/saveEachEventFlag 1

and then restore it with:

/random/resetEngineFromEachEvent true

Or, alternatively, do it manually (e.g. in the primary generator) using

CLHEP::HepRandom::getTheEngine()->saveStatus (fileName);


CLHEP::HepRandom::getTheEngine()->restoreStatus (fileName);

You may also have a look to example TestEm4 : especially readme and rndmSeed.mac