diff --git a/src/physics.cpp b/src/physics.cpp
index 892b39479..dcc771329 100644
--- a/src/physics.cpp
+++ b/src/physics.cpp
@@ -1227,6 +1227,17 @@ void sample_secondary_photons(Particle& p, int i_nuclide)
// Create the secondary photon
bool created_photon = p.create_secondary(wgt, u, E, ParticleType::photon());
+ // Pre-add photon energy to pht_storage so pht_secondary_particles()
+ // subtraction results in net zero
+ if (created_photon && !model::active_pulse_height_tallies.empty()) {
+ auto it = std::find(model::pulse_height_cells.begin(),
+ model::pulse_height_cells.end(), p.lowest_coord().cell());
+ if (it != model::pulse_height_cells.end()) {
+ int index = std::distance(model::pulse_height_cells.begin(), it);
+ p.pht_storage()[index] += E;
+ }
+ }
+
// Tag secondary particle with parent nuclide
if (created_photon && settings::use_decay_photons) {
p.local_secondary_bank().back().parent_nuclide =
diff --git a/tests/regression_tests/pulse_height/local_neutron/inputs_true.dat b/tests/regression_tests/pulse_height/local_neutron/inputs_true.dat
new file mode 100644
index 000000000..e25de58b0
--- /dev/null
+++ b/tests/regression_tests/pulse_height/local_neutron/inputs_true.dat
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+ |
+ |
+
+
+
+
+ fixed source
+ 100
+ 5
+
+
+ 1000000.0 1.0
+
+
+ true
+ false
+
+
+
+ 1
+
+
+ 0.0 10000.0 20000.0 30000.0 40000.0 50000.0 60000.0 70000.0 80000.0 90000.0 100000.0 110000.0 120000.0 130000.0 140000.0 150000.0 160000.0 170000.0 180000.0 190000.0 200000.0 210000.0 220000.0 230000.0 240000.0 250000.0 260000.0 270000.0 280000.0 290000.0 300000.0 310000.0 320000.0 330000.0 340000.0 350000.0 360000.0 370000.0 380000.0 390000.0 400000.0 410000.0 420000.0 430000.0 440000.0 450000.0 460000.0 470000.0 480000.0 490000.0 500000.0 510000.0 520000.0 530000.0 540000.0 550000.0 560000.0 570000.0 580000.0 590000.0 600000.0 610000.0 620000.0 630000.0 640000.0 650000.0 660000.0 670000.0 680000.0 690000.0 700000.0 710000.0 720000.0 730000.0 740000.0 750000.0 760000.0 770000.0 780000.0 790000.0 800000.0 810000.0 820000.0 830000.0 840000.0 850000.0 860000.0 870000.0 880000.0 890000.0 900000.0 910000.0 920000.0 930000.0 940000.0 950000.0 960000.0 970000.0 980000.0 990000.0 1000000.0
+
+
+ 1 2
+ pulse-height
+
+
+
diff --git a/tests/regression_tests/pulse_height/local_neutron/results_true.dat b/tests/regression_tests/pulse_height/local_neutron/results_true.dat
new file mode 100644
index 000000000..ffa284d92
--- /dev/null
+++ b/tests/regression_tests/pulse_height/local_neutron/results_true.dat
@@ -0,0 +1,201 @@
+tally 1:
+4.890000E+00
+4.784900E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+6.000000E-02
+1.800000E-03
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
diff --git a/tests/regression_tests/pulse_height/local/inputs_true.dat b/tests/regression_tests/pulse_height/local_photon/inputs_true.dat
similarity index 97%
rename from tests/regression_tests/pulse_height/local/inputs_true.dat
rename to tests/regression_tests/pulse_height/local_photon/inputs_true.dat
index 50e026bfb..84d033d85 100644
--- a/tests/regression_tests/pulse_height/local/inputs_true.dat
+++ b/tests/regression_tests/pulse_height/local_photon/inputs_true.dat
@@ -2,7 +2,7 @@
-
+
diff --git a/tests/regression_tests/pulse_height/local/results_true.dat b/tests/regression_tests/pulse_height/local_photon/results_true.dat
similarity index 100%
rename from tests/regression_tests/pulse_height/local/results_true.dat
rename to tests/regression_tests/pulse_height/local_photon/results_true.dat
diff --git a/tests/regression_tests/pulse_height/shared_neutron/inputs_true.dat b/tests/regression_tests/pulse_height/shared_neutron/inputs_true.dat
new file mode 100644
index 000000000..b13c53ef8
--- /dev/null
+++ b/tests/regression_tests/pulse_height/shared_neutron/inputs_true.dat
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+ |
+ |
+
+
+
+
+ fixed source
+ 100
+ 5
+
+
+ 1000000.0 1.0
+
+
+ true
+ true
+
+
+
+ 1
+
+
+ 0.0 10000.0 20000.0 30000.0 40000.0 50000.0 60000.0 70000.0 80000.0 90000.0 100000.0 110000.0 120000.0 130000.0 140000.0 150000.0 160000.0 170000.0 180000.0 190000.0 200000.0 210000.0 220000.0 230000.0 240000.0 250000.0 260000.0 270000.0 280000.0 290000.0 300000.0 310000.0 320000.0 330000.0 340000.0 350000.0 360000.0 370000.0 380000.0 390000.0 400000.0 410000.0 420000.0 430000.0 440000.0 450000.0 460000.0 470000.0 480000.0 490000.0 500000.0 510000.0 520000.0 530000.0 540000.0 550000.0 560000.0 570000.0 580000.0 590000.0 600000.0 610000.0 620000.0 630000.0 640000.0 650000.0 660000.0 670000.0 680000.0 690000.0 700000.0 710000.0 720000.0 730000.0 740000.0 750000.0 760000.0 770000.0 780000.0 790000.0 800000.0 810000.0 820000.0 830000.0 840000.0 850000.0 860000.0 870000.0 880000.0 890000.0 900000.0 910000.0 920000.0 930000.0 940000.0 950000.0 960000.0 970000.0 980000.0 990000.0 1000000.0
+
+
+ 1 2
+ pulse-height
+
+
+
diff --git a/tests/regression_tests/pulse_height/shared_neutron/results_true.dat b/tests/regression_tests/pulse_height/shared_neutron/results_true.dat
new file mode 100644
index 000000000..ffa284d92
--- /dev/null
+++ b/tests/regression_tests/pulse_height/shared_neutron/results_true.dat
@@ -0,0 +1,201 @@
+tally 1:
+4.890000E+00
+4.784900E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+6.000000E-02
+1.800000E-03
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+1.000000E-02
+1.000000E-04
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
+0.000000E+00
diff --git a/tests/regression_tests/pulse_height/shared/inputs_true.dat b/tests/regression_tests/pulse_height/shared_photon/inputs_true.dat
similarity index 97%
rename from tests/regression_tests/pulse_height/shared/inputs_true.dat
rename to tests/regression_tests/pulse_height/shared_photon/inputs_true.dat
index c2aef829c..608410c50 100644
--- a/tests/regression_tests/pulse_height/shared/inputs_true.dat
+++ b/tests/regression_tests/pulse_height/shared_photon/inputs_true.dat
@@ -2,7 +2,7 @@
-
+
diff --git a/tests/regression_tests/pulse_height/shared/results_true.dat b/tests/regression_tests/pulse_height/shared_photon/results_true.dat
similarity index 100%
rename from tests/regression_tests/pulse_height/shared/results_true.dat
rename to tests/regression_tests/pulse_height/shared_photon/results_true.dat
diff --git a/tests/regression_tests/pulse_height/test.py b/tests/regression_tests/pulse_height/test.py
index 2cbb9152e..371fcbd0f 100644
--- a/tests/regression_tests/pulse_height/test.py
+++ b/tests/regression_tests/pulse_height/test.py
@@ -6,23 +6,24 @@ from openmc.utility_funcs import change_directory
from tests.testing_harness import PyAPITestHarness
-@pytest.mark.parametrize("shared_secondary,subdir", [
- (False, "local"),
- (True, "shared"),
+@pytest.mark.parametrize("shared_secondary,particle", [
+ (False, "photon"),
+ (False, "neutron"),
+ (True, "photon"),
+ (True, "neutron")
])
-def test_pulse_height(shared_secondary, subdir):
+def test_pulse_height(shared_secondary, particle):
+ subdir = f"shared_{particle}" if shared_secondary else f"local_{particle}"
with change_directory(subdir):
openmc.reset_auto_ids()
model = openmc.Model()
# Define materials
NaI = openmc.Material()
- NaI.set_density('g/cc', 3.7)
+ NaI.set_density('g/cm3', 3.7)
NaI.add_element('Na', 1.0)
NaI.add_element('I', 1.0)
- model.materials = openmc.Materials([NaI])
-
# Define geometry: two spheres in each other
s1 = openmc.Sphere(r=1)
s2 = openmc.Sphere(r=2, boundary_type='vacuum')
@@ -38,14 +39,14 @@ def test_pulse_height(shared_secondary, subdir):
model.settings.shared_secondary_bank = shared_secondary
model.settings.source = openmc.IndependentSource(
energy=openmc.stats.delta_function(1e6),
- particle='photon'
+ particle=particle
)
# Define tallies
tally = openmc.Tally(name="pht tally")
tally.scores = ['pulse-height']
cell_filter = openmc.CellFilter(inner_sphere)
- energy_filter = openmc.EnergyFilter(np.linspace(0, 1_000_000, 101))
+ energy_filter = openmc.EnergyFilter(np.linspace(0, 1e6, 101))
tally.filters = [cell_filter, energy_filter]
model.tallies = [tally]