示例#1
0
    def test_cluster_correlation(
            self):  # Check the cluster correlation function
        dut_alignment.correlate_cluster(input_cluster_files=self.data_files,
                                        output_correlation_file=os.path.join(
                                            self.output_folder,
                                            'Correlation.h5'),
                                        n_pixels=self.n_pixels,
                                        pixel_size=self.pixel_size)
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Correlation_result.h5'),
            os.path.join(self.output_folder, 'Correlation.h5'),
            exact=True)
        self.assertTrue(data_equal, msg=error_msg)

        # Retest with tiny chunk size to force chunked correlation
        dut_alignment.correlate_cluster(input_cluster_files=self.data_files,
                                        output_correlation_file=os.path.join(
                                            self.output_folder,
                                            'Correlation_2.h5'),
                                        n_pixels=self.n_pixels,
                                        pixel_size=self.pixel_size,
                                        chunk_size=293)
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Correlation_result.h5'),
            os.path.join(self.output_folder, 'Correlation_2.h5'),
            exact=True)
        self.assertTrue(data_equal, msg=error_msg)
 def test_track_finding(self):
     # Test 1:
     track_analysis.find_tracks(
         input_tracklets_file=os.path.join(tests_data_folder,
                                           'Tracklets_small.h5'),
         input_alignment_file=os.path.join(tests_data_folder,
                                           r'Alignment_result.h5'),
         output_track_candidates_file=os.path.join(self.output_folder,
                                                   'TrackCandidates.h5'))
     data_equal, error_msg = test_tools.compare_h5_files(
         os.path.join(tests_data_folder, 'TrackCandidates_result.h5'),
         os.path.join(self.output_folder, 'TrackCandidates.h5'))
     self.assertTrue(data_equal, msg=error_msg)
     # Test 2: chunked
     track_analysis.find_tracks(
         input_tracklets_file=os.path.join(tests_data_folder,
                                           'Tracklets_small.h5'),
         input_alignment_file=os.path.join(tests_data_folder,
                                           r'Alignment_result.h5'),
         output_track_candidates_file=os.path.join(self.output_folder,
                                                   'TrackCandidates_2.h5'),
         chunk_size=293)
     data_equal, error_msg = test_tools.compare_h5_files(
         os.path.join(tests_data_folder, 'TrackCandidates_result.h5'),
         os.path.join(self.output_folder, 'TrackCandidates_2.h5'))
     self.assertTrue(data_equal, msg=error_msg)
示例#3
0
    def test_apply_alignment(self):
        dut_alignment.apply_alignment(
            input_hit_file=os.path.join(tests_data_folder, 'Merged_result.h5'),
            input_alignment=os.path.join(self.output_folder,
                                         'Prealignment_result.h5'),
            output_hit_aligned_file=os.path.join(tests_data_folder,
                                                 'Tracklets.h5'),
            force_prealignment=True)
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Tracklets_result.h5'),
            os.path.join(self.output_folder, 'Tracklets.h5'))
        self.assertTrue(data_equal, msg=error_msg)

        # Retest with tiny chunk size to force chunked alignment apply
        dut_alignment.apply_alignment(
            input_hit_file=os.path.join(tests_data_folder, 'Merged_result.h5'),
            input_alignment=os.path.join(self.output_folder,
                                         'Prealignment_result.h5'),
            output_hit_aligned_file=os.path.join(tests_data_folder,
                                                 'Tracklets_2.h5'),
            force_prealignment=True,
            chunk_size=293)
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Tracklets_result.h5'),
            os.path.join(self.output_folder, 'Tracklets_2.h5'))
        self.assertTrue(data_equal, msg=error_msg)
示例#4
0
    def test_cluster_merging(self):
        cluster_files = [
            os.path.join(tests_data_folder, 'Cluster_DUT%d_cluster.h5') % i
            for i in range(4)
        ]
        dut_alignment.merge_cluster_data(cluster_files,
                                         output_merged_file=os.path.join(
                                             self.output_folder, 'Merged.h5'),
                                         n_pixels=self.n_pixels,
                                         pixel_size=self.pixel_size)
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Merged_result.h5'),
            os.path.join(self.output_folder, 'Merged.h5'))
        self.assertTrue(data_equal, msg=error_msg)

        # Retest with tiny chunk size to force chunked merging
        dut_alignment.merge_cluster_data(cluster_files,
                                         output_merged_file=os.path.join(
                                             self.output_folder,
                                             'Merged_2.h5'),
                                         pixel_size=self.pixel_size,
                                         n_pixels=self.n_pixels,
                                         chunk_size=293)

        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Merged_result.h5'),
            os.path.join(self.output_folder, 'Merged_2.h5'))
        self.assertTrue(data_equal, msg=error_msg)
示例#5
0
    def test_prealignment(self):  # Check the hit alignment function
        dut_alignment.prealignment(
            input_correlation_file=os.path.join(tests_data_folder,
                                                'Correlation_result.h5'),
            output_alignment_file=os.path.join(self.output_folder,
                                               'Alignment.h5'),
            z_positions=self.z_positions,
            pixel_size=self.pixel_size,
            non_interactive=True,
            fit_background=False,
            iterations=3
        )  # Due to too little test data the alignment result is only rather stable for more iterations

        # FIXME: residuals should be checked not prealingment data
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Prealignment_result.h5'),
            os.path.join(self.output_folder, 'Alignment.h5'),
            exact=False,
            rtol=0.05,  # 5 % error allowed
            atol=5)  # 5 um absolute tolerance allowed
        self.assertTrue(data_equal, msg=error_msg)

        dut_alignment.prealignment(
            input_correlation_file=os.path.join(tests_data_folder,
                                                'Correlation_difficult.h5'),
            output_alignment_file=os.path.join(self.output_folder,
                                               'Alignment_difficult.h5'),
            z_positions=self.z_positions,
            pixel_size=self.pixel_size,
            non_interactive=True,
            fit_background=True,
            iterations=2
        )  # Due to too little test data the alignment result is only rather stable for more iterations
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Alignment_difficult_result.h5'),
            os.path.join(self.output_folder, 'Alignment_difficult.h5'),
            exact=False,
            rtol=0.05,  # 5 % error allowed
            atol=5)  # 5 um absolute tolerance allowed
        self.assertTrue(data_equal, msg=error_msg)
示例#6
0
 def test_hit_clustering(self):
     # Test 1:
     hit_analysis.cluster_hits(self.data_files[0],
                               max_x_distance=1,
                               max_y_distance=2)
     data_equal, error_msg = test_tools.compare_h5_files(
         os.path.join(tests_data_folder, 'Cluster_result.h5'),
         os.path.join(self.output_folder,
                      'TestBeamData_FEI4_DUT0_small_cluster.h5'),
         exact=False)
     self.assertTrue(data_equal, msg=error_msg)
     # Test 2: smaller chunks
     hit_analysis.cluster_hits(self.data_files[0],
                               max_x_distance=1,
                               max_y_distance=2,
                               chunk_size=4999)
     data_equal, error_msg = test_tools.compare_h5_files(
         os.path.join(tests_data_folder, 'Cluster_result.h5'),
         os.path.join(self.output_folder,
                      'TestBeamData_FEI4_DUT0_small_cluster.h5'),
         exact=False)
     self.assertTrue(data_equal, msg=error_msg)
示例#7
0
 def test_noisy_pixel_remover(self):
     # Test 1:
     hit_analysis.remove_noisy_pixels(self.noisy_data_file,
                                      threshold=10.0,
                                      n_pixel=(1152, 576),
                                      pixel_size=(18.4, 18.4))
     data_equal, error_msg = test_tools.compare_h5_files(
         os.path.join(tests_data_folder, 'HotPixel_result.h5'),
         os.path.join(self.output_folder,
                      'TestBeamData_Mimosa26_DUT0_small_noisy_pixels.h5'))
     self.assertTrue(data_equal, msg=error_msg)
     # Test 2: smaller chunks
     hit_analysis.remove_noisy_pixels(self.noisy_data_file,
                                      threshold=10.0,
                                      n_pixel=(1152, 576),
                                      pixel_size=(18.4, 18.4),
                                      chunk_size=4999)
     data_equal, error_msg = test_tools.compare_h5_files(
         os.path.join(tests_data_folder, 'HotPixel_result.h5'),
         os.path.join(self.output_folder,
                      'TestBeamData_Mimosa26_DUT0_small_noisy_pixels.h5'))
     self.assertTrue(data_equal, msg=error_msg)
示例#8
0
    def test_simulation(self):
        ''' Check the full simulation '''
        self.simulate_data.reset()
        self.simulate_data.set_std_settings()
        self.assertEqual(self.simulate_data.n_duts, 6)

        self.simulate_data.create_data_and_store('simulated_data',
                                                 n_events=10000)

        for dut_index in range(self.simulate_data.n_duts):
            data_equal, error_msg = test_tools.compare_h5_files(
                'simulated_data_DUT%d.h5' % dut_index,
                os.path.join(tests_data_folder,
                             'simulated_data_DUT%d.h5' % dut_index),
                exact=False)
            self.assertTrue(data_equal, msg=error_msg)
示例#9
0
    def test_alignment(self):
        dut_alignment.alignment(input_track_candidates_file=os.path.join(
            tests_data_folder, 'TrackCandidates_prealigned.h5'),
                                input_alignment_file=os.path.join(
                                    tests_data_folder, 'Alignment.h5'),
                                n_pixels=[(1152, 576)] * 6,
                                pixel_size=[(18.4, 18.4)] * 6)

        # FIXME: test should check residuals not alignment resulds
        # FIXME: translation error can be in the order of um, angle error not
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Alignment.h5'),
            os.path.join(tests_data_folder, 'Alignment_result.h5'),
            exact=False,
            rtol=0.01,  # 1 % error allowed
            atol=5)  # 0.0001 absolute tolerance allowed
        self.assertTrue(data_equal, msg=error_msg)
    def test_track_fitting(self):
        # Test 1: Fit DUTs and always exclude one DUT (normal mode for unbiased residuals and efficiency determination)
        track_analysis.fit_tracks(
            input_track_candidates_file=os.path.join(
                tests_data_folder, 'TrackCandidates_result.h5'),
            input_alignment_file=os.path.join(tests_data_folder,
                                              r'Alignment_result.h5'),
            output_tracks_file=os.path.join(self.output_folder, 'Tracks.h5'),
            selection_track_quality=1)
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Tracks_result.h5'),
            os.path.join(self.output_folder, 'Tracks.h5'),
            exact=False)
        self.assertTrue(data_equal, msg=error_msg)

        # Test 2: As test 1 but chunked data analysis, should result in the same tracks
        track_analysis.fit_tracks(
            input_track_candidates_file=os.path.join(
                tests_data_folder, 'TrackCandidates_result.h5'),
            input_alignment_file=os.path.join(tests_data_folder,
                                              r'Alignment_result.h5'),
            output_tracks_file=os.path.join(self.output_folder, 'Tracks_2.h5'),
            selection_track_quality=1,
            chunk_size=4999)
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Tracks_result.h5'),
            os.path.join(self.output_folder, 'Tracks_2.h5'),
            exact=False)
        self.assertTrue(data_equal, msg=error_msg)

        # Test 3: Fit all DUTs at once (special mode for constrained residuals)
        track_analysis.fit_tracks(
            input_track_candidates_file=os.path.join(
                tests_data_folder, 'TrackCandidates_result.h5'),
            input_alignment_file=os.path.join(tests_data_folder,
                                              r'Alignment_result.h5'),
            output_tracks_file=os.path.join(self.output_folder,
                                            'Tracks_All.h5'),
            exclude_dut_hit=False,
            selection_track_quality=1)
        # Fit DUTs consecutevly, but use always the same DUTs. Should result in the same data as above
        track_analysis.fit_tracks(
            input_track_candidates_file=os.path.join(
                tests_data_folder, 'TrackCandidates_result.h5'),
            input_alignment_file=os.path.join(tests_data_folder,
                                              r'Alignment_result.h5'),
            output_tracks_file=os.path.join(self.output_folder,
                                            'Tracks_All_Iter.h5'),
            selection_hit_duts=range(4),
            exclude_dut_hit=False,
            selection_track_quality=1)
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Tracks_All.h5'),
            os.path.join(self.output_folder, 'Tracks_All_Iter.h5'),
            exact=False)
        self.assertTrue(data_equal, msg=error_msg)
        # Fit DUTs consecutevly, but use always the same DUTs defined for each DUT separately. Should result in the same data as above
        track_analysis.fit_tracks(
            input_track_candidates_file=os.path.join(
                tests_data_folder, 'TrackCandidates_result.h5'),
            input_alignment_file=os.path.join(tests_data_folder,
                                              r'Alignment_result.h5'),
            output_tracks_file=os.path.join(self.output_folder,
                                            'Tracks_All_Iter_2.h5'),
            selection_hit_duts=[range(4),
                                range(4),
                                range(4),
                                range(4)],
            exclude_dut_hit=False,
            selection_track_quality=1)
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Tracks_All.h5'),
            os.path.join(self.output_folder, 'Tracks_All_Iter_2.h5'),
            exact=False)
        self.assertTrue(data_equal, msg=error_msg)

        # Fit tracks and eliminate merged tracks
        track_analysis.fit_tracks(
            input_track_candidates_file=os.path.join(
                tests_data_folder, 'TrackCandidates_result.h5'),
            input_alignment_file=os.path.join(tests_data_folder,
                                              r'Alignment_result.h5'),
            output_tracks_file=os.path.join(self.output_folder,
                                            'Tracks_merged.h5'),
            selection_track_quality=1,
            min_track_distance=True  # Activate track merge cut
        )
        data_equal, error_msg = test_tools.compare_h5_files(
            os.path.join(tests_data_folder, 'Tracks_merged_result.h5'),
            os.path.join(self.output_folder, 'Tracks_merged.h5'),
            exact=False)
        self.assertTrue(data_equal, msg=error_msg)