Normalize run weights before stochastic event distribution#164
Merged
maureeungaro merged 1 commit intoJun 13, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
distributeEventsdrewrandomNumberfromU[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 like11 1 / 12 7 / 13 2(cumulative bins 1/8/10) every draw is<= 1and 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
runWeightskeeps the logged weight table showing the user's original values.Validation: a
1/7/2weights 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