@bryngemark found this while comparing inclusive overlay files and the sim hits in the tagger trigger pad. The tagger trigger pad is really close to the primary vertex, so that is why we were able to observe this bug there.
So I think that the primary generator action (and only the primary generator action) is not being seeded correctly. This is a bug that should be "easy" to fix because we just need to move the seeding of the PGA to after the seeding of Geant4 (since the PGA uses G4's CLHEP seed). The reason we haven't seen this before is because this only affects primary vertex smearing between runs.
A simple solution is to use Geant4's internal random generator (which uses the seed after it is set in onNewRun). Basically, we would remove the random_ member variable of the Primary Generator Action, and instead use G4UniformRand() (which still needs to be scaled). i.e. replace
@bryngemark found this while comparing inclusive overlay files and the sim hits in the tagger trigger pad. The tagger trigger pad is really close to the primary vertex, so that is why we were able to observe this bug there.
The primary generator action has its own random number generator that it seeds when it is constructed: https://github.com/LDMX-Software/SimCore/blob/0a05e1d9ca7a745080e1c0cf436a99f95d0ebe30/src/SimCore/PrimaryGeneratorAction.cxx#L38-L39
The run manager creates the primary generator action in RunManager::Initialize:
https://github.com/LDMX-Software/SimCore/blob/0a05e1d9ca7a745080e1c0cf436a99f95d0ebe30/src/SimCore/RunManager.cxx#L124-L125
which is called in Simulator::onProcessStart:
https://github.com/LDMX-Software/SimCore/blob/0a05e1d9ca7a745080e1c0cf436a99f95d0ebe30/src/SimCore/Simulator.cxx#L327-L328
But the random seed is not set until Simulator::onNewRun:
https://github.com/LDMX-Software/SimCore/blob/0a05e1d9ca7a745080e1c0cf436a99f95d0ebe30/src/SimCore/Simulator.cxx#L283-L291
So I think that the primary generator action (and only the primary generator action) is not being seeded correctly. This is a bug that should be "easy" to fix because we just need to move the seeding of the PGA to after the seeding of Geant4 (since the PGA uses G4's CLHEP seed). The reason we haven't seen this before is because this only affects primary vertex smearing between runs.
A simple solution is to use Geant4's internal random generator (which uses the seed after it is set in
onNewRun
). Basically, we would remove therandom_
member variable of the Primary Generator Action, and instead useG4UniformRand()
(which still needs to be scaled). i.e. replacehttps://github.com/LDMX-Software/SimCore/blob/0a05e1d9ca7a745080e1c0cf436a99f95d0ebe30/src/SimCore/PrimaryGeneratorAction.cxx#L140-L142
with