Skip to content
Snippets Groups Projects
Commit 69b7f27a authored by Johannes Schumann's avatar Johannes Schumann
Browse files

Add zenith range to spherical volume and add tests

parent 0d13b594
No related branches found
No related tags found
No related merge requests found
Pipeline #34192 passed with warnings
...@@ -186,13 +186,17 @@ class SphericalVolume(DetectorVolume): ...@@ -186,13 +186,17 @@ class SphericalVolume(DetectorVolume):
center: tuple [m] center: tuple [m]
Coordinate center of the sphere Coordinate center of the sphere
(x, y, z) (x, y, z)
zenith: float [1] (default (-1.0, 1.0)
Zenith range given as cos(θ)
""" """
def __init__(self, radius, coord_origin=(0, 0, 0)): def __init__(self, radius, coord_origin=(0, 0, 0), zenith=(-1, 1)):
super().__init__() super().__init__()
self._radius = radius self._radius = radius
self._coord_origin = coord_origin self._coord_origin = coord_origin
self._volume = self._calc_volume() self._volume = self._calc_volume()
self._solid_angle = 4 * np.pi self._cosZmin = zenith[0]
self._cosZmax = zenith[1]
self._solid_angle = 2 * np.pi * (self._cosZmax - self._cosZmin)
def _calc_volume(self): def _calc_volume(self):
return 4 / 3 * np.pi * np.power(self._radius, 3) return 4 / 3 * np.pi * np.power(self._radius, 3)
...@@ -209,7 +213,7 @@ class SphericalVolume(DetectorVolume): ...@@ -209,7 +213,7 @@ class SphericalVolume(DetectorVolume):
def random_dir(self): def random_dir(self):
phi = np.random.uniform(0, 2 * np.pi) phi = np.random.uniform(0, 2 * np.pi)
cos_theta = np.random.uniform(-1, 1) cos_theta = np.random.uniform(self._cosZmin, self._cosZmax)
return (phi, cos_theta) return (phi, cos_theta)
def header_entries(self, nevents=0): def header_entries(self, nevents=0):
......
...@@ -42,6 +42,19 @@ class TestSphere(unittest.TestCase): ...@@ -42,6 +42,19 @@ class TestSphere(unittest.TestCase):
radius = np.sqrt(np.sum(np.power((np.array(pos) - 2), 2))) radius = np.sqrt(np.sum(np.power((np.array(pos) - 2), 2)))
assert radius <= 20 assert radius <= 20
def test_limited_zenith(self):
np.random.seed(1234)
geometry = CanVolume(zenith=(-0.4, 0.5))
self.assertAlmostEqual(geometry.solid_angle, 5.654866776461628)
direction = geometry.random_dir()
self.assertAlmostEqual(direction[1], 0.15989789393584863)
geometry = CanVolume(zenith=(0.1, 0.3))
direction = geometry.random_dir()
self.assertAlmostEqual(direction[1], 0.25707171674275386)
geometry = CanVolume(zenith=(-0.3, -0.2))
direction = geometry.random_dir()
self.assertAlmostEqual(direction[1], -0.2727407394717358)
class TestCan(unittest.TestCase): class TestCan(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -69,6 +82,7 @@ class TestCan(unittest.TestCase): ...@@ -69,6 +82,7 @@ class TestCan(unittest.TestCase):
def test_limited_zenith(self): def test_limited_zenith(self):
np.random.seed(1234) np.random.seed(1234)
geometry = CanVolume(zenith=(-0.4, 0.5)) geometry = CanVolume(zenith=(-0.4, 0.5))
self.assertAlmostEqual(geometry.solid_angle, 5.654866776461628)
direction = geometry.random_dir() direction = geometry.random_dir()
self.assertAlmostEqual(direction[1], 0.15989789393584863) self.assertAlmostEqual(direction[1], 0.15989789393584863)
geometry = CanVolume(zenith=(0.1, 0.3)) geometry = CanVolume(zenith=(0.1, 0.3))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment