Skip to content

Fix sphere vertex sampling: compare squared radius to squared bound#144

Merged
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/109-sphere-vertex-radius
Jun 13, 2026
Merged

Fix sphere vertex sampling: compare squared radius to squared bound#144
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/109-sphere-vertex-radius

Conversation

@zhaozhiwen

Copy link
Copy Markdown
Collaborator

In-sphere rejection sampling compared the squared magnitude x*x+y*y+z*z against the un-squared max_radius, so the accepted region had radius sqrt(max_radius) instead of max_radius (e.g. max_radius=4 accepted only radius 2). This squares the bound. The sampling cube already spans [-max_radius, max_radius] per component, so rejection sampling stays valid.

Validation: translation unit recompiled cleanly with Geant4 11.4.1 / ROOT 6.38 / Qt 6.9 (ghcr.io/gemc/src:dev-almalinux-10).

Fixes #109

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 gemc#109

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maureeungaro maureeungaro merged commit eaccfc0 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] Sphere vertex sampling compares squared radius against un-squared bound

2 participants