Skip to content

Add truncated distribution sampler#2304

Merged
sethrj merged 6 commits intoceleritas-project:developfrom
amandalund:truncated
Mar 10, 2026
Merged

Add truncated distribution sampler#2304
sethrj merged 6 commits intoceleritas-project:developfrom
amandalund:truncated

Conversation

@amandalund
Copy link
Contributor

This adds a helper class for sampling from an arbitrary distribution restricted to some finite bounds. This is used in a few places where we were sampling from a truncated normal distribution and added as an energy distribution type for the optical primary generator so we can sample from a Gaussian without generating negative energies.

I also removed the rather subtle copy and move operations that allow setting new distribution parameters while possibly keeping or transferring the spare value in the normal distribution. Since we're now generating scintillation photons one at a time, this isn't used anymore (except in the scintillation unit test). If we do ever have another use case where we need to repeatedly generate normally distributed values with different distribution parameters we can always restore this.

@amandalund amandalund requested a review from sethrj as a code owner March 9, 2026 19:10
@amandalund amandalund added physics Particles, processes, and stepping algorithms minor Refactoring or minor internal changes/fixes labels Mar 9, 2026
@github-actions
Copy link

github-actions bot commented Mar 9, 2026

Test summary

 5 930 files   9 549 suites   21m 34s ⏱️
 2 201 tests  2 166 ✅  35 💤 0 ❌
32 770 runs  32 629 ✅ 141 💤 0 ❌

Results for commit 071a9bd.

♻️ This comment has been updated with latest results.

Copy link
Member

@sethrj sethrj left a comment

Choose a reason for hiding this comment

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

Nice!

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.22%. Comparing base (9def02c) to head (071a9bd).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/celeritas/phys/PrimaryGenerator.cc 16.66% 5 Missing ⚠️
src/celeritas/inp/EventsIO.json.cc 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2304      +/-   ##
===========================================
- Coverage    87.23%   87.22%   -0.02%     
===========================================
  Files         1353     1354       +1     
  Lines        43155    43176      +21     
  Branches     13165    13171       +6     
===========================================
+ Hits         37646    37660      +14     
- Misses        4301     4307       +6     
- Partials      1208     1209       +1     
Files with missing lines Coverage Δ
.../em/distribution/EnergyLossGaussianDistribution.hh 100.00% <100.00%> (ø)
src/celeritas/inp/Events.hh 69.23% <ø> (ø)
src/celeritas/optical/gen/PrimaryGenerator.hh 100.00% <ø> (ø)
...rc/celeritas/optical/gen/ScintillationGenerator.hh 98.76% <100.00%> (-0.05%) ⬇️
...eritas/optical/surface/GaussianRoughnessSampler.hh 100.00% <100.00%> (ø)
src/corecel/inp/Distributions.hh 100.00% <100.00%> (ø)
src/corecel/inp/DistributionsIO.json.cc 100.00% <100.00%> (ø)
src/corecel/random/data/DistributionData.hh 100.00% <100.00%> (ø)
...orecel/random/distribution/DistributionInserter.cc 100.00% <100.00%> (ø)
...corecel/random/distribution/DistributionVisitor.hh 92.30% <100.00%> (+0.30%) ⬆️
... and 4 more

... and 3 files with indirect coverage changes

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

@sethrj
Copy link
Member

sethrj commented Mar 10, 2026

@amandalund Coverage test points out that the variant-based code isn't being tested yet. Could you add a quick one?

@sethrj sethrj merged commit ef0fe7b into celeritas-project:develop Mar 10, 2026
77 of 79 checks passed
@amandalund amandalund deleted the truncated branch March 10, 2026 15:22
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.

2 participants