Commit 8f9c836
Normalize run weights before stochastic event distribution
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 #103
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 48f83e5 commit 8f9c836
1 file changed
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
107 | 117 | | |
108 | | - | |
109 | 118 | | |
110 | | - | |
| 119 | + | |
111 | 120 | | |
112 | 121 | | |
113 | 122 | | |
| |||
0 commit comments