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

Merge branch '10-add-detector-center-option-to-geometry' into 'master'

Resolve "Add detector center option to geometry"

Closes #10

See merge request !34
parents 03b9434a 4a413fa5
No related branches found
No related tags found
1 merge request!34Resolve "Add detector center option to geometry"
Pipeline #29832 passed with warnings
......@@ -82,14 +82,21 @@ class CanVolume(DetectorVolume):
Cylinder bottom z position
zmax: float [m] (default: 476.5)
Cylinder top z position
detector_center: tuple [m] (default: (0.0, 0.0) )
Detector center position in the xy-plane
"""
def __init__(self, radius=403.4, zmin=0.0, zmax=476.5):
def __init__(self,
radius=403.4,
zmin=0.0,
zmax=476.5,
detector_center=(0., 0.)):
super().__init__()
self._radius = radius
self._zmin = zmin
self._zmax = zmax
self._volume = self._calc_volume()
self._detector_center = detector_center
def _calc_volume(self):
return np.pi * (self._zmax - self._zmin) * np.power(self._radius, 2)
......@@ -97,8 +104,8 @@ class CanVolume(DetectorVolume):
def random_pos(self):
r = self._radius * np.sqrt(np.random.uniform(0, 1))
phi = np.random.uniform(0, 2 * np.pi)
pos_x = r * np.cos(phi)
pos_y = r * np.sin(phi)
pos_x = r * np.cos(phi) + self._detector_center[0]
pos_y = r * np.sin(phi) + self._detector_center[1]
pos_z = np.random.uniform(self._zmin, self._zmax)
return (pos_x, pos_y, pos_z)
......
......@@ -17,12 +17,14 @@ import numpy as np
class TestGeneralGeometry(unittest.TestCase):
def test_abstract_init(self):
with self.assertRaises(TypeError) as ctx:
d = DetectorVolume()
class TestSphere(unittest.TestCase):
def setUp(self):
self.detector_geometry = SphericalVolume(20, (2, 2, 2))
......@@ -44,9 +46,25 @@ class TestSphere(unittest.TestCase):
class TestCan(unittest.TestCase):
def setUp(self):
self.detector_geometry = CanVolume()
def test_volume(self):
volume = self.detector_geometry.volume
self.assertAlmostEqual(volume, 243604084.28, 2)
def test_position(self):
np.random.seed(1234)
pos = self.detector_geometry.random_pos()
self.assertAlmostEqual(pos[0], -127.07940486491587)
self.assertAlmostEqual(pos[1], -122.54421157149173)
self.assertAlmostEqual(pos[2], 208.57726763689004)
def test_position(self):
np.random.seed(1234)
detector_geometry = CanVolume(detector_center=(100, 100))
pos = detector_geometry.random_pos()
self.assertAlmostEqual(pos[0], -27.07940486491587)
self.assertAlmostEqual(pos[1], -22.54421157149173)
self.assertAlmostEqual(pos[2], 208.57726763689004)
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