Skip to content

Draw transport random numbers from a per-thread generator - #16055

Open
sawenzel wants to merge 3 commits into
AliceO2Group:devfrom
sawenzel:swenzel/g4mt-pr2-sim-random
Open

sawenzel wants to merge 3 commits into
AliceO2Group:devfrom
sawenzel:swenzel/g4mt-pr2-sim-random

Conversation

@sawenzel

@sawenzel sawenzel commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

This introduces o2::base::simRandom(), the random number generator used for seeding and drawing during particle transport. A thread can install its own generator with o2::base::setSimRandom(); a thread that has none gets gRandom. This prepares the simulation for multithreaded Geant4, where a single gRandom would be shared, and raced on, by all worker threads.

Everything that seeds or draws during transport now goes through it: the sub-event seeding in O2SimDevice, the per-track seeding in PreTrack and in the stack, and the stepping draws in CPV, FDD, FT0, HMPID, PHOS, TPC, TRD and ZDC. This includes the draws that went through fMC->GetRandom() or TH1::GetRandom(), since both end up in gRandom. VMCSeederService now seeds Geant4 directly from the transport generator, with the same recipe as geant4_vmc's SetRandomSeed, which always reads gRandom. The seeder is set up once on the main thread in InitGeometry.

Note that this does not change anything for the current simulation, since no thread installs its own generator yet. A seeded o2-sim run (10 Pythia8 pp events, all detectors, Geant4, -j 8) gives identical kinematics and hits compared with dev. A unit test checks the default and that threads keep separate, reproducible sequences.

Relates to https://its.cern.ch/jira/browse/O2-7305

Assisted by Claude Code.

This adds o2::base::simRandom(), the generator used for seeding and drawing during transport, and moves the simulation to it.

- simRandom() returns a generator installed for the calling thread, and gRandom otherwise, so the sequential simulation is unchanged.
- Sub-event, per-track and stack seeding and the stepping draws in CPV, FDD, FT0, HMPID, PHOS, TPC, TRD and ZDC use it.
- VMCSeederService seeds Geant4 from it directly, with the recipe of TG4RunManager::SetRandomSeed, which reads gRandom.
- A unit test checks the default and that threads keep separate sequences.

This prepares the simulation for multithreaded Geant4, where gRandom would be shared by all workers.

https://its.cern.ch/jira/browse/O2-7305

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sawenzel and others added 2 commits November 6, 2026 07:22
This replaces the just-in-time compiled Geant4 seeding with a function that the Geant4 configuration installs.

- The JIT code needed CLHEP/Random/Random.h on ROOT_INCLUDE_PATH, which the alienv module environment does not provide.
- g4Config.C links Geant4 and installs the same seeding recipe through VMCSeederService::setGeant4Seeder.

https://its.cern.ch/jira/browse/O2-7305

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cave::BeginPrimary seeded gRandom directly; it now uses o2::base::simRandom() like the other transport-time seeding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant