Skip to content

Commit 87735c8

Browse files
zhaozhiwenclaude
andcommitted
Fix sphere vertex sampling: compare squared radius to squared bound
In-sphere rejection sampling compared x*x+y*y+z*z (a squared magnitude) against the un-squared max_radius, so the accepted region had radius sqrt(max_radius) instead of max_radius. Square the bound. The sampling cube already spans [-max_radius, max_radius] per component, so rejection sampling stays valid. Fixes #109 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 48f83e5 commit 87735c8

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

gemc/gparticle/gparticle.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ G4ThreeVector Gparticle::calculateVertex() {
166166
z = randomizeNumberFromSigmaWithModel(0, max_radius, gutilities::uniform);
167167
radius = x * x + y * y + z * z;
168168
}
169-
while (radius > max_radius);
169+
while (radius > max_radius * max_radius);
170170

171171
// Offset the sampled point by the nominal vertex.
172172
x = x + v.x();

0 commit comments

Comments
 (0)