Skip to content

Add option to specify number of events to select.#76

Merged
michalkreps merged 9 commits into
lhcb:mainfrom
leadreyfus:master
May 19, 2026
Merged

Add option to specify number of events to select.#76
michalkreps merged 9 commits into
lhcb:mainfrom
leadreyfus:master

Conversation

@leadreyfus
Copy link
Copy Markdown

@leadreyfus leadreyfus commented Oct 22, 2025

A bug with gRandom->SetSeed(x) and gRandom->GetSeed() was introduced in ROOT 6.24/00 , which causes issues with seeded (an unseeded) generation.
Using evtgen yields the same distribution before rapidsim smearing/boosting as the effectively retrieved seed is always 624 instead of a random number (expected from gRandom->SetSeed(0))

Breakdown of the issue (using ROOT 6.28/10):
When setting a seed, the requested seed would not be registered:

root [2] gRandom->SetSeed(12)
root [3] gRandom->GetSeed()
(unsigned int) 624

And SetSeed(0) works as expected:

root [4] gRandom->SetSeed(0)
root [5] gRandom->GetSeed()
(unsigned int) 1143603968

But not setting a seed returns 624:

   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/10                        https://root.cern |
  | (c) 1995-2023, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Nov 27 2023, 21:04:13                 |
  | From tags/v6-28-10@v6-28-10                                      |
  | With g++ (GCC) 13.1.0                                            |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] gRandom->GetSeed()
(unsigned int) 624

which I believe is causing RapidSim to have some unseeded behaviour and some seeded, yielding seemingly independent samples that have, in fact, the same underlying kinematics. I am not 100% sure of my claim but this is what I observed in my samples.

The proposed fix is to call GetSeed() and SetSeed() using TRandom:::

 ▶ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/10                        https://root.cern |
  | (c) 1995-2023, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Nov 27 2023, 21:04:13                 |
  | From tags/v6-28-10@v6-28-10                                      |
  | With g++ (GCC) 13.1.0                                            |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] gRandom->TRandom::GetSeed()
(unsigned int) 4357
root [1] gRandom->TRandom::SetSeed(42)
root [2] gRandom->TRandom::GetSeed()
(unsigned int) 42
root [3] gRandom->TRandom::SetSeed(0)
root [4] gRandom->TRandom::GetSeed()
(unsigned int) 645542426

Léa added 2 commits October 22, 2025 11:18
@leadreyfus
Copy link
Copy Markdown
Author

After some digging, it seems that I can reproduce some issues specifically using a version of rapidsim that is installed within the lb-conda environment rapidsim (used within LHCb).

One issue that I observe nonetheless is that it is impossible to have seeded behaviour with this bug, as the set seed will always be 624.

The other issue I am observing using lb-conda is that I would generate 2 unseeded samples of B0->D*enu decays with EvtGen, giving me some momenta distributions in the lab frame that seemed independent, but after boosting all particles to the B0 rest frame, the momenta were the same in both samples (as in event i of sample 1 has exact same momentum as event i of sample 2). This issue does not seem to happen with RapidSim compiled by hand in an environment that has EvtGen. For this study I used LCG_104c.

@leadreyfus
Copy link
Copy Markdown
Author

@dcraik @gcowan Could it be possible to merge in order to propagate the changes to lb-conda?
I can also provide some scripts/steps to reproduce the issue if needed.
fyi @chrisburr

chrisburr added a commit to regro-cf-autotick-bot/rapidsim-feedstock that referenced this pull request Oct 22, 2025
chrisburr added a commit to regro-cf-autotick-bot/rapidsim-feedstock that referenced this pull request Oct 22, 2025
@michalkreps michalkreps changed the title Fix gRandom seeding bug introduced in ROOT 6.24 Add option to specify number of events to select. May 19, 2026
@michalkreps
Copy link
Copy Markdown
Collaborator

Issue with Random number generator seed has been fixed in #77 but this has also nice new feature to terminate generation after specified number of events are selected. Thus after fixing conflicts I renamed PR and accept this.

@michalkreps michalkreps merged commit 5fcfc32 into lhcb:main May 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants