def _test_content_hypersphere(self): # disabled because it is slow print("Test content hypersphere") for i in range(5): numpy.seterr(all='ignore') test_bunch = Bunch() content_predicted = numpy.linalg.det(self.diag)*math.pi**2/2. test_bunch = Bunch.new_hit_shell(7, 4.*self.diag, ['x', 'y', 'px', 'py'], '') test_bunch.append(Hit.new_from_dict({'x':0., 'y':0., 'px':0., 'py':0.})) for hit in test_bunch: hit['x'] += 1.*i hit['px'] += 2.*i hit['y'] += 3.*i hit['py'] += 4.*i my_weights = VoronoiWeighting(['x', 'y', 'px', 'py'], numpy.array([[2., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.],])) my_weights.apply_weights(test_bunch, False) my_weights.plot_two_d_projection(['x', 'y']) my_weights.plot_two_d_projection(['px', 'py']) #self.assertEqual(len(my_weights.tile_content_list), len(test_bunch)+1) content_actual = sum(my_weights.tile_content_list) print("Content", content_actual, "Predicted", content_predicted) self.assertAlmostEqual(content_actual, content_predicted, 0) input()
def test_content_square(self): test_bunch = Bunch() for x in range(-2, 3): for y in range(-2, 3): test_hit = Hit.new_from_dict({'x':x, 'y':y}) test_bunch.append(test_hit) limit_bunch = Bunch.new_hit_shell(3, numpy.array([[9.5, 0.],[0., 9.5]]), ['x', 'y'], '') my_weights = VoronoiWeighting(['x', 'y'], numpy.array([[2., 0.],[0., 1.]])) my_weights.apply_weights(test_bunch, False) my_weights.plot_two_d_projection(['x', 'y']) self.assertEqual(len(my_weights.tile_content_list), len(test_bunch)) self.assertAlmostEqual(sum(my_weights.tile_content_list), 9., 3)
def test_content_circle(self): test_bunch = Bunch() n_events = 361 for theta in range(0, n_events-1): x = 2.*math.sin(math.radians(theta)) y = 2.*math.cos(math.radians(theta)) test_hit = Hit.new_from_dict({'x':x, 'y':y}) test_bunch.append(test_hit) test_hit = Hit.new_from_dict({'x':0., 'y':0.}) test_bunch.append(test_hit) limit_bunch = Bunch.new_hit_shell(3, numpy.array([[9.5, 0.],[0., 9.5]]), ['x', 'y'], '') my_weights = VoronoiWeighting(['x', 'y'], numpy.array([[2., 0.],[0., 1.]])) my_weights.apply_weights(test_bunch, False) my_weights.plot_two_d_projection(['x', 'y']) self.assertEqual(len(my_weights.tile_content_list), n_events) non_zero_content = [cont for cont in my_weights.tile_content_list \ if cont > 1e-6] self.assertEqual(len(non_zero_content), 1) self.assertAlmostEqual(non_zero_content[0], math.pi, 3)