Skip to content

Commit

Permalink
More unittests for gammas.py
Browse files Browse the repository at this point in the history
Add test for no interaction.
Add test for no pair production for E < 1.022 MeV
  • Loading branch information
tomkooij committed Jun 6, 2016
1 parent 4755e07 commit 45ef53f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion sapphire/tests/simulations/test_gammas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import random

import numpy as np
from mock import patch
Expand Down Expand Up @@ -97,13 +98,31 @@ def test_simulate_detector_mips_gammas_pair(self, mock_l_compton, mock_l_pair, m
mock_l_pair.return_value = 1e-3

mock_compton.return_value = 42.
p = np.array([10])
E = np.array([10., 7.]) # MeV
p = E * 1e6 # eV
theta = np.array([0.])

for _ in range(100):
mips = gammas.simulate_detector_mips_gammas(p, theta)
self.assertFalse(mock_compton.called)
self.assertLessEqual(mips, gammas.max_E)

# not enough energy for pair production
E = np.array([0.5, 0.7]) # MeV
p = E * 1e6 # eV
theta = np.array([0., 0.])
for _ in range(100):
self.assertEqual(gammas.simulate_detector_mips_gammas(p, theta), 0)

@patch.object(random, 'expovariate')
def test_simulate_detector_mips_no_interaction(self, mock_expovariate):
p = np.array([10e6])
theta = np.array([0.])

# force no interaction
mock_expovariate.return_value = 1e3
self.assertEqual(gammas.simulate_detector_mips_gammas(p, theta), 0)


if __name__ == '__main__':
unittest.main()

0 comments on commit 45ef53f

Please sign in to comment.