~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/map/MapCppTrackerIntegratedTrackFit/_test_MapCppTrackerTrackFit.py

  • Committer: Christopher Hunt
  • Date: 2018-07-04 14:12:12 UTC
  • Revision ID: christopher.hunt08@imperial.ac.uk-20180704141212-orzzl40mi53xc6kh
Added files for field integrated kalman filter. Now to test it...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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/>.
 
15
 
 
16
"""Tests for MapCppTrackerTrackFit"""
 
17
 
 
18
# pylint: disable = C0103
 
19
 
 
20
import os
 
21
import json
 
22
import unittest
 
23
import Configuration
 
24
import MAUS
 
25
import maus_cpp.globals
 
26
import maus_cpp.converter
 
27
import maus_cpp.mice_module
 
28
 
 
29
# pylint: disable = R0904
 
30
class MapCppTrackerTrackFitTestCase(unittest.TestCase):
 
31
    """Tests for MapCppTrackerTrackFit"""
 
32
 
 
33
    cfg = json.loads(Configuration.Configuration().getConfigJSON())
 
34
 
 
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
 
39
 
 
40
    @classmethod
 
41
    def setUpClass(cls): # pylint: disable = C0103
 
42
        """Sets a mapper and configuration"""
 
43
 
 
44
        cls.mappers = [MAUS.MapCppTrackerClusterRecon(), \
 
45
          MAUS.MapCppTrackerSpacePointRecon(), \
 
46
          MAUS.MapCppTrackerPatternRecognition(), \
 
47
          MAUS.MapCppTrackerTrackFit()]
 
48
        cls.test_config = ""
 
49
        if maus_cpp.globals.has_instance():
 
50
            cls.test_config = maus_cpp.globals.get_configuration_cards()
 
51
            maus_cpp.globals.death()
 
52
 
 
53
    def testInit(self):
 
54
        """Check birth"""
 
55
        #success = self.mapper.birth(json.dumps(self.cfg))
 
56
        #self.assertTrue(success)
 
57
 
 
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
 
67
 
 
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))
 
71
 
 
72
        for m in self.mappers:
 
73
            m.birth(json.dumps(self.cfg))
 
74
 
 
75
        # Read in a spill of mc data containing 5 straight tracks
 
76
        test1 = \
 
77
          ('%s/tests/test_data/scifi_test_data/test_straight_digits.json' %
 
78
          os.environ.get("MAUS_ROOT_DIR"))
 
79
        fin = open(test1,'r')
 
80
        fin.readline()
 
81
        fin.readline()
 
82
        fin.readline()
 
83
        data = fin.readline()
 
84
 
 
85
        for m in self.mappers:
 
86
            data = m.process(data)
 
87
 
 
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']))
 
106
 
 
107
        maus_cpp.globals.death()
 
108
 
 
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
 
118
 
 
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))
 
122
 
 
123
        for m in self.mappers:
 
124
            m.birth(json.dumps(self.cfg))
 
125
 
 
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')
 
129
        fin.readline()
 
130
        fin.readline()
 
131
        data = fin.readline()
 
132
 
 
133
        for m in self.mappers:
 
134
            data = m.process(data)
 
135
 
 
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']))
 
153
 
 
154
        maus_cpp.globals.death()
 
155
 
 
156
    @classmethod
 
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
 
166
        cls.mapper.death()
 
167
        cls.mapper = None
 
168
 
 
169
if __name__ == '__main__':
 
170
    unittest.main()