Skip to content

Generalize Poisson distribution to allow zeros#2408

Open
sethrj wants to merge 32 commits into
celeritas-project:developfrom
sethrj:general-poisson
Open

Generalize Poisson distribution to allow zeros#2408
sethrj wants to merge 32 commits into
celeritas-project:developfrom
sethrj:general-poisson

Conversation

@sethrj

@sethrj sethrj commented May 21, 2026

Copy link
Copy Markdown
Member

The current Poisson already has a special case for large N (using Gaussian); this cleans up the code a bit by extending it with another special case for N=0, and avoiding extra computations based on which case.

@sethrj sethrj requested a review from Copilot May 21, 2026 11:55
@sethrj sethrj added physics Particles, processes, and stepping algorithms minor Refactoring or minor internal changes/fixes labels May 21, 2026
@sethrj sethrj removed request for hhollenb and whokion May 21, 2026 11:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends PoissonDistribution to support the degenerate case lambda == 0 (always returning zero without RNG usage) and refactors several optical/EM sampling sites to take advantage of that behavior, reducing branching and avoiding unnecessary work in “no photons” cases.

Changes:

  • Generalize PoissonDistribution to allow lambda >= 0, add a lambda==0 method path, and clamp Gaussian-approximation results to nonnegative values.
  • Simplify WLS/Cherenkov offload sampling by always calling the sampler and relying on PoissonDistribution{0} to yield zero.
  • Update EM excitation-loss sampling to no longer special-case xs_exc_ > 0 (relying on Poisson(0) behavior).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/corecel/random/distribution/PoissonDistribution.test.cc Adds a regression test for lambda==0 returning zeros and consuming no RNG samples.
src/corecel/random/distribution/PoissonDistribution.hh Adds explicit lambda==0 path and refactors method selection/state; clamps Gaussian approximation output.
src/celeritas/optical/interactor/WavelengthShiftInteractor.hh Uses PoissonDistribution{0} to represent “no emission” and samples unconditionally in operator().
src/celeritas/optical/gen/ScintillationOffload.hh Adjusts Gaussian rounding approach for photon counts while keeping clamping behavior.
src/celeritas/optical/gen/CherenkovOffload.hh Stores a precomputed PoissonDistribution member for repeated sampling and removes early-return branch.
src/celeritas/em/distribution/EnergyLossUrbanDistribution.hh Removes xs_exc_ > 0 guard, relying on Poisson(0) to yield zero collisions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/corecel/random/distribution/PoissonDistribution.hh
Comment thread src/celeritas/optical/interactor/WavelengthShiftInteractor.hh Outdated
@github-actions

github-actions Bot commented May 21, 2026

Copy link
Copy Markdown

Test summary

 5 715 files   9 303 suites   18m 47s ⏱️
 2 328 tests  2 284 ✅  43 💤 1 ❌
32 881 runs  32 709 ✅ 171 💤 1 ❌

For more details on these failures, see this check.

Results for commit 43089a2.

♻️ This comment has been updated with latest results.

@amandalund amandalund left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sethrj!

Comment thread src/celeritas/optical/gen/ScintillationOffload.hh Outdated
Comment thread src/celeritas/optical/interactor/WavelengthShiftInteractor.hh
Comment thread src/celeritas/optical/interactor/WavelengthShiftInteractor.hh
Comment thread src/corecel/random/distribution/PoissonDistribution.hh Outdated
Comment thread src/corecel/random/distribution/PoissonDistribution.hh Outdated
sethrj added 9 commits May 22, 2026 07:37
Implement a templated RoundedNonnegDistribution that wraps an underlying
floating-point distribution and returns rounded non-negative integers.
Add focused unit tests for rounding/clamping behavior, one-underlying-sample
usage, and deterministic uniform sampling output. Register the new test in
corecel CMake test definitions.

Prompt: "Using #sym:TruncatedDistribution  as a template, create a RoundedNonnegDistribution that efficiently samples from an underlying distribution and returns a non-negative integer. Template parameters should be underlying distribution and integer type (default to celeritas::size_type)."
Assisted-by: GitHub Copilot (GPT-5.3-Codex)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 29 out of 29 changed files in this pull request and generated 7 comments.

Comment thread src/corecel/random/distribution/RoundedNonnegDistribution.hh
Comment thread src/corecel/random/distribution/TruncatedDistribution.hh Outdated
Comment thread src/corecel/random/distribution/TruncatedDistribution.hh
Comment thread src/corecel/random/distribution/PoissonDistribution.hh Outdated
Comment thread src/corecel/random/distribution/PoissonDistribution.hh
Comment thread src/corecel/random/distribution/PoissonDistribution.hh Outdated
Comment thread src/celeritas/em/distribution/EnergyLossUrbanDistribution.hh Outdated
Comment thread src/celeritas/em/distribution/EnergyLossUrbanDistribution.hh Outdated
Comment thread src/celeritas/optical/gen/ScintillationGenerator.hh Outdated
Comment thread src/corecel/random/distribution/PoissonDistribution.hh
@sethrj sethrj enabled auto-merge (squash) June 4, 2026 16:45
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.68085% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.19%. Comparing base (6a97cc5) to head (43089a2).

Files with missing lines Patch % Lines
...as/optical/interactor/WavelengthShiftInteractor.hh 63.63% 3 Missing and 1 partial ⚠️
...corecel/random/distribution/PoissonDistribution.hh 96.87% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #2408   +/-   ##
========================================
  Coverage    87.19%   87.19%           
========================================
  Files         1399     1400    +1     
  Lines        44114    44150   +36     
  Branches     13314    13317    +3     
========================================
+ Hits         38465    38497   +32     
- Misses        4414     4416    +2     
- Partials      1235     1237    +2     
Files with missing lines Coverage Δ
.../em/distribution/EnergyLossGaussianDistribution.hh 100.00% <ø> (ø)
...tas/em/distribution/EnergyLossUrbanDistribution.hh 96.77% <100.00%> (+0.02%) ⬆️
...eleritas/em/msc/detail/UrbanMscMinimalStepLimit.hh 93.93% <ø> (ø)
src/celeritas/em/msc/detail/UrbanMscScatter.hh 92.85% <100.00%> (ø)
src/celeritas/ext/detail/GeantProcessImporter.cc 86.26% <100.00%> (ø)
src/celeritas/optical/gen/CherenkovOffload.hh 100.00% <100.00%> (ø)
src/celeritas/optical/gen/ScintillationData.hh 95.00% <100.00%> (-0.24%) ⬇️
src/celeritas/optical/gen/ScintillationOffload.hh 100.00% <100.00%> (+2.27%) ⬆️
...eritas/optical/gen/detail/ScintSpectrumInserter.hh 91.66% <ø> (ø)
...eritas/optical/surface/GaussianRoughnessSampler.hh 100.00% <100.00%> (ø)
... and 15 more

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor Refactoring or minor internal changes/fixes physics Particles, processes, and stepping algorithms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants