From faa4b041cfba9cdb39a14b691b84198e922a9a63 Mon Sep 17 00:00:00 2001 From: GuySten Date: Thu, 14 May 2026 23:52:47 +0300 Subject: [PATCH 1/4] do not count zero energy pulse heights --- src/tallies/tally_scoring.cpp | 4 ++++ tests/unit_tests/test_pulse_height.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/unit_tests/test_pulse_height.py diff --git a/src/tallies/tally_scoring.cpp b/src/tallies/tally_scoring.cpp index 5dcd07331d6..e5d91ae4a59 100644 --- a/src/tallies/tally_scoring.cpp +++ b/src/tallies/tally_scoring.cpp @@ -2752,6 +2752,10 @@ void score_pulse_height_tally(Particle& p, const vector& tallies) // Temporarily change energy of particle to pulse-height value p.E_last() = p.pht_storage()[index]; + // Skip pulses with zero energy + if (p.E_last() == 0.0) + continue; + // Initialize an iterator over valid filter bin combinations. If // there are no valid combinations, use a continue statement to ensure // we skip the assume_separate break below. diff --git a/tests/unit_tests/test_pulse_height.py b/tests/unit_tests/test_pulse_height.py new file mode 100644 index 00000000000..3dd320b2478 --- /dev/null +++ b/tests/unit_tests/test_pulse_height.py @@ -0,0 +1,24 @@ +import openmc + + +def test_negative_pulse_height(run_in_tmpdir): + surf = openmc.Sphere(r=10.0, boundary_type='vacuum') + cell = openmc.Cell(region=-surf) + model = openmc.Model() + model.geometry = openmc.Geometry([cell]) + model.settings.run_mode = 'fixed source' + model.settings.source = openmc.IndependentSource( + space=openmc.stats.Point(), + energy=openmc.stats.Discrete([5.0e6], [1.0]), + particle='photon', + ) + model.settings.particles = 100 + model.settings.batches = 1 + model.settings.electron_treatment = 'led' + + tally = openmc.Tally() + tally.scores = ['pulse-height'] + model.tallies = openmc.Tallies([tally]) + model.run(apply_tally_results=True) + + assert (tally.mean == 0.0).all(), "Zero energy pulses should not be counted" From db41401c95b4822efa4e5d4550cb8b2e2e648dec Mon Sep 17 00:00:00 2001 From: GuySten Date: Thu, 14 May 2026 23:55:28 +0300 Subject: [PATCH 2/4] ran clang-format --- src/tallies/tally_scoring.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tallies/tally_scoring.cpp b/src/tallies/tally_scoring.cpp index e5d91ae4a59..5aea2dbfc78 100644 --- a/src/tallies/tally_scoring.cpp +++ b/src/tallies/tally_scoring.cpp @@ -2755,7 +2755,7 @@ void score_pulse_height_tally(Particle& p, const vector& tallies) // Skip pulses with zero energy if (p.E_last() == 0.0) continue; - + // Initialize an iterator over valid filter bin combinations. If // there are no valid combinations, use a continue statement to ensure // we skip the assume_separate break below. From a5130887f71e310702929cc079ccb28edf264a20 Mon Sep 17 00:00:00 2001 From: GuySten Date: Thu, 14 May 2026 23:56:31 +0300 Subject: [PATCH 3/4] fix typo --- tests/unit_tests/test_pulse_height.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_pulse_height.py b/tests/unit_tests/test_pulse_height.py index 3dd320b2478..1206458c9b2 100644 --- a/tests/unit_tests/test_pulse_height.py +++ b/tests/unit_tests/test_pulse_height.py @@ -1,7 +1,7 @@ import openmc -def test_negative_pulse_height(run_in_tmpdir): +def test_zero_energy_pulse_heights(run_in_tmpdir): surf = openmc.Sphere(r=10.0, boundary_type='vacuum') cell = openmc.Cell(region=-surf) model = openmc.Model() From e2f98f01df30c2acb1c28a76512fadea5c56028b Mon Sep 17 00:00:00 2001 From: GuySten Date: Fri, 15 May 2026 05:35:03 +0300 Subject: [PATCH 4/4] update regression test --- tests/regression_tests/pulse_height/results_true.dat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/regression_tests/pulse_height/results_true.dat b/tests/regression_tests/pulse_height/results_true.dat index c57e8ff1c83..ec8e2032a13 100644 --- a/tests/regression_tests/pulse_height/results_true.dat +++ b/tests/regression_tests/pulse_height/results_true.dat @@ -1,6 +1,6 @@ tally 1: -4.140000E+00 -3.443000E+00 +3.000000E-02 +3.000000E-04 1.000000E-02 1.000000E-04 1.000000E-02