2
test_accumulate_coloured_particles.py
4
# This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
6
# MAUS is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# MAUS is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with MAUS. If not, see <http://www.gnu.org/licenses/>.
24
MAUS_ROOT_DIR = os.getenv("MAUS_ROOT_DIR")
25
SIM_PATH = os.path.join(MAUS_ROOT_DIR, "bin", "simulate_mice.py")
26
TEST_DIR = os.path.join(MAUS_ROOT_DIR, "tests", "integration", \
27
"test_simulation", "test_accumulate_coloured_particles")
28
CONFIG_PATH = os.path.join(TEST_DIR, "test_particles_config.txt")
29
FILE_NAME = os.environ['MAUS_ROOT_DIR']+'/tmp/accumulate_tracks'
31
def run_simulations():
33
Run simulation to generate some data. We only want to do this once, so I
34
pull it out into a separate part of the test.
36
test_out = open(FILE_NAME, 'w')
37
subproc = subprocess.Popen([SIM_PATH, '-configuration_file', CONFIG_PATH], \
38
stdout=test_out, stderr=subprocess.STDOUT)
44
This method cleans up the vrml and simulation.out files produced by the
45
simulation. The first method must check the vrml file but it is not needed
48
for filename in glob.glob('g4_*.wrl'):
50
for filename in glob.glob('*.out'):
53
class AccumulateColouredParticles(unittest.TestCase): #pylint: disable = R0904
55
This class has two tests. One checks that particles are accumulated into one
56
vrml output file when the tag is selected in configuration defaults. The
57
second checks that the DrawByParticleID model has been registered so
58
particles will have specified colours in the vrml.
60
def setUp(self): # pylint: disable=C0103, C0202
61
""" Run Simulation """
64
def test_for_accumulated_tracks(self): #pylint: disable=R0201
65
""" Check that we have accumulated particles """
66
if len(glob.glob('g4_*.wrl')) > 1:
67
raise Exception('more than one vrml, tracks not accumulated')
70
def test_coloured_particles(self):
71
""" Check that we have coloured particles """
72
test_in = open(FILE_NAME, 'r')
74
for lines in test_in.readlines():
75
if lines.find('G4TrajectoryDrawByParticleID') >= 0:
77
self.assertEqual(found_model, 1, 'DrawByParticleID model not found')
80
if __name__ == '__main__':