1
# This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
# MAUS is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# MAUS is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with MAUS. If not, see <http://www.gnu.org/licenses/>.
16
"""Tests for MapCppTrackerTrackFit"""
18
# pylint: disable = C0103
25
import maus_cpp.globals
26
import maus_cpp.converter
27
import maus_cpp.mice_module
29
# pylint: disable = R0904
30
class MapCppTrackerTrackFitTestCase(unittest.TestCase):
31
"""Tests for MapCppTrackerTrackFit"""
33
cfg = json.loads(Configuration.Configuration().getConfigJSON())
35
helical_geom = "TrackerTest.dat"
36
straight_geom = "TrackerTest_NoField.dat"
37
cfg['simulation_geometry_filename'] = helical_geom
38
cfg['reconstruction_geometry_filename'] = helical_geom
41
def setUpClass(cls): # pylint: disable = C0103
42
"""Sets a mapper and configuration"""
44
cls.mappers = [MAUS.MapCppTrackerClusterRecon(), \
45
MAUS.MapCppTrackerSpacePointRecon(), \
46
MAUS.MapCppTrackerPatternRecognition(), \
47
MAUS.MapCppTrackerTrackFit()]
49
if maus_cpp.globals.has_instance():
50
cls.test_config = maus_cpp.globals.get_configuration_cards()
51
maus_cpp.globals.death()
55
#success = self.mapper.birth(json.dumps(self.cfg))
56
#self.assertTrue(success)
58
def testGoodStraightProcess(self):
59
"""Check that the mapper process function produces expected
60
output with good straight track data"""
61
if maus_cpp.globals.has_instance():
62
maus_cpp.globals.death()
63
self.cfg['simulation_geometry_filename'] = self.straight_geom
64
self.cfg['reconstruction_geometry_filename'] = self.straight_geom
65
self.cfg['SciFiPRHelicalOn'] = 0
66
self.cfg['SciFiPRStraightOn'] = 1
68
maus_cpp.globals.birth(json.dumps(self.cfg))
69
maus_cpp.globals.set_reconstruction_mice_modules(
70
maus_cpp.mice_module.MiceModule(self.straight_geom))
72
for m in self.mappers:
73
m.birth(json.dumps(self.cfg))
75
# Read in a spill of mc data containing 5 straight tracks
77
('%s/tests/test_data/scifi_test_data/test_straight_digits.json' %
78
os.environ.get("MAUS_ROOT_DIR"))
85
for m in self.mappers:
86
data = m.process(data)
88
spill_out = maus_cpp.converter.json_repr(data)
89
self.assertTrue('recon_events' in spill_out)
90
self.assertEqual(1, len(spill_out['recon_events']))
91
# Check the first event
92
revt = spill_out['recon_events'][0]
93
self.assertTrue('sci_fi_event' in revt)
94
self.assertTrue('digits' in revt['sci_fi_event'])
95
self.assertEqual(31, len(revt['sci_fi_event']['digits']))
96
self.assertTrue('clusters' in revt['sci_fi_event'])
97
self.assertEqual(30, len(revt['sci_fi_event']['clusters']))
98
self.assertTrue('spacepoints' in revt['sci_fi_event'])
99
self.assertEqual(10, len(revt['sci_fi_event']['spacepoints']))
100
self.assertTrue('straight_pr_tracks' in revt['sci_fi_event'])
101
self.assertEqual(2, len(revt['sci_fi_event']['straight_pr_tracks']))
102
self.assertTrue('helical_pr_tracks' in revt['sci_fi_event'])
103
self.assertEqual(0, len(revt['sci_fi_event']['helical_pr_tracks']))
104
self.assertTrue('tracks' in revt['sci_fi_event'])
105
self.assertEqual(2, len(revt['sci_fi_event']['tracks']))
107
maus_cpp.globals.death()
109
def testGoodHelicalProcess(self):
110
"""Check that the mapper process function produces expected
111
output with good helical track data"""
112
if maus_cpp.globals.has_instance():
113
maus_cpp.globals.death()
114
self.cfg['simulation_geometry_filename'] = self.helical_geom
115
self.cfg['reconstruction_geometry_filename'] = self.helical_geom
116
self.cfg['SciFiPRHelicalOn'] = 1
117
self.cfg['SciFiStraightOn'] = 0
119
maus_cpp.globals.birth(json.dumps(self.cfg))
120
maus_cpp.globals.set_reconstruction_mice_modules(
121
maus_cpp.mice_module.MiceModule(self.helical_geom))
123
for m in self.mappers:
124
m.birth(json.dumps(self.cfg))
126
test1 = ('%s/tests/test_data/scifi_test_data/test_helical_digits.json' %
127
os.environ.get("MAUS_ROOT_DIR"))
128
fin = open(test1,'r')
131
data = fin.readline()
133
for m in self.mappers:
134
data = m.process(data)
136
spill_out = maus_cpp.converter.json_repr(data)
137
self.assertTrue('recon_events' in spill_out)
138
self.assertEqual(1, len(spill_out['recon_events']))
139
# Check the first event
140
revt = spill_out['recon_events'][0]
141
self.assertTrue('digits' in revt['sci_fi_event'])
142
self.assertEqual(34, len(revt['sci_fi_event']['digits']))
143
self.assertTrue('clusters' in revt['sci_fi_event'])
144
self.assertEqual(30, len(revt['sci_fi_event']['clusters']))
145
self.assertTrue('spacepoints' in revt['sci_fi_event'])
146
self.assertEqual(10, len(revt['sci_fi_event']['spacepoints']))
147
self.assertTrue('straight_pr_tracks' in revt['sci_fi_event'])
148
self.assertEqual(0, len(revt['sci_fi_event']['straight_pr_tracks']))
149
self.assertTrue('helical_pr_tracks' in revt['sci_fi_event'])
150
self.assertEqual(2, len(revt['sci_fi_event']['helical_pr_tracks']))
151
self.assertTrue('tracks' in revt['sci_fi_event'])
152
self.assertEqual(2, len(revt['sci_fi_event']['tracks']))
154
maus_cpp.globals.death()
157
def tearDownClass(cls): # pylint: disable = C0103
158
"""Sets a mapper and configuration,
159
and checks that we can death() MapCppTrackerRecon"""
160
cls.mapper = MAUS.MapCppTrackerRecon()
161
if maus_cpp.globals.has_instance():
162
maus_cpp.globals.death()
163
if cls.test_config != "":
164
maus_cpp.globals.birth(cls.test_config)
165
# Check we death() the mapper
169
if __name__ == '__main__':