Skip to content

Normalize run weights before stochastic event distribution#164

Merged
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/103-run-weight-normalization
Jun 13, 2026
Merged

Normalize run weights before stochastic event distribution#164
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/103-run-weight-normalization

Conversation

@zhaozhiwen

Copy link
Copy Markdown
Collaborator

distributeEvents drew randomNumber from U[0,1] and compared it to a running sum of the raw file weights. The weights are relative and not required to sum to 1, so for a file like 11 1 / 12 7 / 13 2 (cumulative bins 1/8/10) every draw is <= 1 and the first run always wins — runs 12 and 13 get zero events, with no warning. The inner comment even stated the unenforced assumption.

Compute the total weight once and scale each draw by it (and guard a non-positive total). Scaling the draw rather than mutating runWeights keeps the logged weight table showing the user's original values.

Validation: a 1/7/2 weights file over 1000 events now distributes 97/697/206 (~10/70/20%) in the Geant4 11.4.1 dev container; before, all 1000 went to the first run.

Fixes #103

distributeEvents drew randomNumber from U[0,1] and compared it to a
running sum of the raw file weights. The weights are relative and not
required to sum to 1, so for a file like "11 1 / 12 7 / 13 2" (cumulative
bins 1/8/10) every draw is <= 1 and the first run always wins — runs 12
and 13 get zero events, with no warning. The code only worked when the
weights happened to sum to 1.

Compute the total weight once and scale each draw by it (and guard a
non-positive total). Scaling the draw rather than mutating runWeights
keeps the logged weight table showing the user's original values.

Verified: a 1/7/2 weights file over 1000 events now distributes 97/697/206
(~10/70/20%); before, all 1000 went to the first run (Geant4 11.4.1 dev
container).

Fixes gemc#103

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maureeungaro maureeungaro merged commit 422513a into gemc:main Jun 13, 2026
30 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.

[High] EventDispenser: run weights are not normalized before stochastic sampling

2 participants