def testRun_matrixWithOffset(self):
     m = list(pull.create_run_matrix(10, 10, 5, 5))
     self.assertEqual(len(m), 10 * 10)
     for mc, data in m:
         self.assertGreaterEqual(mc, 5)
         self.assertGreaterEqual(data, 5)
         self.assertLessEqual(mc, 15)
         self.assertLessEqual(data, 15)
 def testRun_matrixSimple(self):
     m = pull.create_run_matrix(10, 10, 0, 0)
     self.assertEqual(len(list(m)), 10 * 10)
     for mc, data in m:
         self.assertGreaterEqual(mc, 1)
         self.assertGreaterEqual(data, 1)
         self.assertLessEqual(mc, 10)
         self.assertLessEqual(data, 10)
示例#3
0
 def testRun_matrixWithOffset(self):
     m = list(pull.create_run_matrix(10, 10, 5, 5))
     self.assertEqual(len(m), 10 * 10)
     for mc, data in m:
         self.assertGreaterEqual(mc, 5)
         self.assertGreaterEqual(data, 5)
         self.assertLessEqual(mc, 15)
         self.assertLessEqual(data, 15)
示例#4
0
 def testRun_matrixSimple(self):
     m = pull.create_run_matrix(10, 10, 0, 0)
     self.assertEqual(len(list(m)), 10 * 10)
     for mc, data in m:
         self.assertGreaterEqual(mc, 1)
         self.assertGreaterEqual(data, 1)
         self.assertLessEqual(mc, 10)
         self.assertLessEqual(data, 10)
    def split(self, n):
        '''
            In this case the split function has to establish the size of the
            matrix and create jobs with sub-matrices.

            Case 1:
                - use_n_toy = 10
                - offset_toy_mc = 0
                - offset_toy_data = 0
                - n = 5

            Case 2:
                - use_n_toy = 10
                - offset_toy_mc = 5
                - offset_toy_data = 5
                - n = 5

            For case 1 we can either construct five 4 x 5, 5 x 4 or 2 x 10 
            matrices. For case 2 we can construct five 1 x 5 or 5 x 1 matrices.
            In either case it would make sense to have the smallest unit either
            a column or a row.

            In order not to double-count, use_n_toy needs to be reduced per job.

        '''
        import src.unfolding_tests.create_unfolding_pull_data as pull
        if n == 1:
            return self
        run_matrix = pull.create_run_matrix(self.n_toy_mc,
                                                     self.n_toy_data,
                                                     self.offset_toy_mc,
                                                     self.offset_toy_data)
        self.run_matrix = list(run_matrix)
        # after this the run matrix is empty (generator)!
        l = list(self.run_matrix) 
        n_per_job = int(len(l) / n)

        run_matrices = []
        for _ in range(n):
            run_matrix = []
            for _ in range(n_per_job):
                if l:
                    run_matrix.append(l.pop())
            run_matrices.append(run_matrix)
        if l:  # if anything is left
            for i in l:
                run_matrices[-1].append(i)

        jobs = []
        for r in run_matrices:
            offsets_and_ranges = UnfoldingPullJob.get_offsets_and_ranges(r)
            offset_toy_mc, offset_toy_data = offsets_and_ranges[:2]
            n_toy_mc, n_toy_data = offsets_and_ranges[2:]
            j = UnfoldingPullJob(self.input_file_name, self.method,
                                 self.channel, self.centre_of_mass,
                                 self.variable, n_toy_mc,
                                 n_toy_data,
                                 self.output_folder, offset_toy_mc,
                                 offset_toy_data, self.k_value,
                                 self.tau_value, r)
            jobs.append(j)

        return jobs