Example #1
0
    def test_physics(self):
        """
        Check physics_processes datacard works okay

        Check that we lose same energy in mean_energy_loss mode for two
        particles with different seeds and that we have no transverse scatter.

        Check that we lose different energy amount in standard mode and that we
        do have a transverse scatter
        """
        # I want to check that we can set mean energy loss even when reference
        # particle has no energy loss
        file_de = run_simulation("none", "mean_energy_loss", False,
                                                                  -1., -1., 5.)
        bunch_de = Bunch.new_dict_from_read_builtin('maus_root_virtual_hit',
                                                           file_de, "pid")[211]
        # should lose energy in absorber
        de_hits_1 = bunch_de.get_hits('station', 1) # pions us of material
        de_hits_2 = bunch_de.get_hits('station', 2) # pions ds of material
        # check we lose energy through the absorber
        self.assertNotAlmostEqual(de_hits_1 [0]['pz'], de_hits_2[1]['pz'], 3)
        # check two particles lose same energy through absorber (no stochastics)
        self.assertAlmostEqual(de_hits_2 [0]['pz'], de_hits_2[1]['pz'], 3)
        # check no transverse
        self.assertAlmostEqual(de_hits_2[1]['px'], 0., 3)

        file_strag = run_simulation("none", "standard", False, -1., -1., 5.)
        bunch_strag = Bunch.new_dict_from_read_builtin('maus_root_virtual_hit',
                                                      file_strag, "pid")[211]
        strag_hits = bunch_strag.get_hits('station', 2) # pions ds of material
        # check two particles lose different energy through absorber 
        # (no stochastics)
        self.assertNotAlmostEqual(strag_hits[0]['pz'], strag_hits[1]['pz'], 3)
        # check for transverse distribution
        self.assertNotAlmostEqual(strag_hits[0]['px'], 0., 7)
Example #2
0
    def test_physics(self):
        """
        Check physics_processes datacard works okay

        Check that we lose same energy in mean_energy_loss mode for two
        particles with different seeds and that we have no transverse scatter.

        Check that we lose different energy amount in standard mode and that we
        do have a transverse scatter
        """
        # I want to check that we can set mean energy loss even when reference
        # particle has no energy loss
        file_de = run_simulation("none", "mean_energy_loss", False, -1., -1.,
                                 5.)
        bunch_de = Bunch.new_dict_from_read_builtin('maus_root_virtual_hit',
                                                    file_de, "pid")[211]
        # should lose energy in absorber
        de_hits_1 = bunch_de.get_hits('station', 1)  # pions us of material
        de_hits_2 = bunch_de.get_hits('station', 2)  # pions ds of material
        # check we lose energy through the absorber
        self.assertNotAlmostEqual(de_hits_1[0]['pz'], de_hits_2[1]['pz'], 3)
        # check two particles lose same energy through absorber (no stochastics)
        self.assertAlmostEqual(de_hits_2[0]['pz'], de_hits_2[1]['pz'], 3)
        # check no transverse
        self.assertAlmostEqual(de_hits_2[1]['px'], 0., 3)

        file_strag = run_simulation("none", "standard", False, -1., -1., 5.)
        bunch_strag = Bunch.new_dict_from_read_builtin('maus_root_virtual_hit',
                                                       file_strag, "pid")[211]
        strag_hits = bunch_strag.get_hits('station', 2)  # pions ds of material
        # check two particles lose different energy through absorber
        # (no stochastics)
        self.assertNotAlmostEqual(strag_hits[0]['pz'], strag_hits[1]['pz'], 3)
        # check for transverse distribution
        self.assertNotAlmostEqual(strag_hits[0]['px'], 0., 7)
Example #3
0
    def test_create_from_twiss_parameters(self):
        """Test maus_cpp.covariance_matrix.create_from_penn_parameters"""
        try:
            maus_cpp.covariance_matrix.create_from_twiss_parameters()
            self.assertTrue(False, "Should have thrown a TypeError")
        except TypeError:
            pass
        cm1 = maus_cpp.covariance_matrix.create_from_twiss_parameters \
                      (mass=105.658, momentum=200.,
                       emittance_x=6., beta_x=333.,
                       emittance_y=6., beta_y=333.,
                       emittance_l=100., beta_l=10.)
        cm2 = maus_cpp.covariance_matrix.create_from_twiss_parameters \
                      (mass=105.658, momentum=200.,
                       emittance_x=6., beta_x=333.,
                       emittance_y=6., beta_y=333.,
                       emittance_l=100., beta_l=10.,
                       alpha_x=0., alpha_y=0., alpha_l=0.,
                       dispersion_x=0., dispersion_prime_x=0.,
                       dispersion_y=0., dispersion_prime_y=0.)
        for i in range(1, 7):
            for j in range(i, 7):
                self.assertEqual(cm1.get_element(i, j), cm2.get_element(i, j))

        cm3 = maus_cpp.covariance_matrix.create_from_twiss_parameters \
                      (mass=105.658, momentum=200.,
                       emittance_x=6., beta_x=333.,
                       emittance_y=5., beta_y=250.,
                       emittance_l=1., beta_l=10.,
                       alpha_x=1., alpha_y=2., alpha_l=1.,
                       dispersion_x=1., dispersion_prime_x=1.,
                       dispersion_y=3., dispersion_prime_y=3.)
        cm4 = maus_cpp.covariance_matrix.create_from_twiss_parameters \
                      (105.658, 200.,
                       6., 333., 5., 250., 1., 10.,
                       1., 2., 1., 1., 1., 3., 3.)
        for i in range(1, 7):
            for j in range(i, 7):
                self.assertEqual(cm3.get_element(i, j), cm4.get_element(i, j))
        bunch = Bunch.build_ellipse_2d(10., 1., 1., 200., 105.658, False)
        for i in range(0, 2):
            for j in range(0, 2):
                self.assertLess(2.*abs(bunch[i, j]-cm4.get_element(i+1, j+1))/ \
                                   abs(bunch[i, j]+cm4.get_element(i+1, j+1)),
                                   1.e-3)
        bunch = Bunch.build_ellipse_2d(333., 1., 6., 200., 105.658, False)
        for i in range(2, 4):
            for j in range(2, 4):
                a = bunch[i - 2, j - 2]
                b = cm4.get_element(i + 1, j + 1)
                self.assertLess(2. * abs(a - b) / abs(a + b), 1.e-3)
        bunch = Bunch.build_ellipse_2d(250., 2., 5., 200., 105.658, False)
        for i in range(4, 6):
            for j in range(4, 6):
                a = bunch[i - 4, j - 4]
                b = cm4.get_element(i + 1, j + 1)
                self.assertLess(2. * abs(a - b) / abs(a + b), 1.e-3)
    def test_create_from_twiss_parameters(self):
        """Test maus_cpp.covariance_matrix.create_from_penn_parameters"""
        try:
            maus_cpp.covariance_matrix.create_from_twiss_parameters()
            self.assertTrue(False, "Should have thrown a TypeError")
        except TypeError:
            pass
        cm1 = maus_cpp.covariance_matrix.create_from_twiss_parameters \
                      (mass=105.658, momentum=200.,
                       emittance_x=6., beta_x=333.,
                       emittance_y=6., beta_y=333.,
                       emittance_l=100., beta_l=10.)
        cm2 = maus_cpp.covariance_matrix.create_from_twiss_parameters \
                      (mass=105.658, momentum=200.,
                       emittance_x=6., beta_x=333.,
                       emittance_y=6., beta_y=333.,
                       emittance_l=100., beta_l=10.,
                       alpha_x=0., alpha_y=0., alpha_l=0.,
                       dispersion_x=0., dispersion_prime_x=0.,
                       dispersion_y=0., dispersion_prime_y=0.)
        for i in range(1, 7):
            for j in range(i, 7):
                self.assertEqual(cm1.get_element(i, j), cm2.get_element(i, j))
 
        cm3 = maus_cpp.covariance_matrix.create_from_twiss_parameters \
                      (mass=105.658, momentum=200.,
                       emittance_x=6., beta_x=333.,
                       emittance_y=5., beta_y=250.,
                       emittance_l=1., beta_l=10.,
                       alpha_x=1., alpha_y=2., alpha_l=1.,
                       dispersion_x=1., dispersion_prime_x=1.,
                       dispersion_y=3., dispersion_prime_y=3.)
        cm4 = maus_cpp.covariance_matrix.create_from_twiss_parameters \
                      (105.658, 200.,
                       6., 333., 5., 250., 1., 10.,
                       1., 2., 1., 1., 1., 3., 3.)
        for i in range(1, 7):
            for j in range(i, 7):
                self.assertEqual(cm3.get_element(i, j), cm4.get_element(i, j))
        bunch = Bunch.build_ellipse_2d(10., 1., 1., 200., 105.658, False)
        for i in range(0, 2):
            for j in range(0, 2):
                self.assertLess(2.*abs(bunch[i, j]-cm4.get_element(i+1, j+1))/ \
                                   abs(bunch[i, j]+cm4.get_element(i+1, j+1)),
                                   1.e-3)
        bunch = Bunch.build_ellipse_2d(333., 1., 6., 200., 105.658, False)
        for i in range(2, 4):
            for j in range(2, 4):
                a = bunch[i-2, j-2]
                b = cm4.get_element(i+1, j+1)
                self.assertLess(2.*abs(a-b)/abs(a+b), 1.e-3)
        bunch = Bunch.build_ellipse_2d(250., 2., 5., 200., 105.658, False)
        for i in range(4, 6):
            for j in range(4, 6):
                a = bunch[i-4, j-4]
                b = cm4.get_element(i+1, j+1)
                self.assertLess(2.*abs(a-b)/abs(a+b), 1.e-3)
Example #5
0
 def read_bunch(self):
     """
     Read the input file
     """
     print self.bunch_read
     return Bunch.new_dict_from_read_builtin(*self.bunch_read)\
                                                           [self.bunch_index]
Example #6
0
 def read_bunch(self):
     """
     Read the input file
     """
     print self.bunch_read
     return Bunch.new_dict_from_read_builtin(*self.bunch_read)\
                                                           [self.bunch_index]
Example #7
0
    def test_create_from_penn_parameters(self):
        """Test maus_cpp.covariance_matrix.create_from_penn_parameters"""
        try:
            maus_cpp.covariance_matrix.create_from_penn_parameters()
            self.assertTrue(False, "Should have thrown a TypeError")
        except TypeError:
            pass
        cm1 = maus_cpp.covariance_matrix.create_from_penn_parameters \
                      (mass=105.658, momentum=200., emittance_t=6., beta_t=333.,
                       emittance_l=1., beta_l=10.)
        cm2 = maus_cpp.covariance_matrix.create_from_penn_parameters \
                      (mass=105.658, momentum=200., emittance_t=6., beta_t=333.,
                       emittance_l=1., beta_l=10., alpha_t=0., alpha_l=0.,
                       charge=1., bz=0., ltwiddle=0., dispersion_x=0.,
                       dispersion_prime_x=0., dispersion_y=0.,
                       dispersion_prime_y=0.)
        for i in range(1, 7):
            for j in range(i, 7):
                self.assertEqual(cm1.get_element(i, j), cm2.get_element(i, j))

        cm3 = maus_cpp.covariance_matrix.create_from_penn_parameters \
                      (mass=105.658, momentum=200., emittance_t=6., beta_t=333.,
                       emittance_l=1., beta_l=10., alpha_t=1., alpha_l=1.,
                       charge=-1., bz=4.e-3, ltwiddle=1., dispersion_x=1.,
                       dispersion_prime_x=1., dispersion_y=1.,
                       dispersion_prime_y=1.)
        cm4 = maus_cpp.covariance_matrix.create_from_penn_parameters \
                      (105.658, 200., 6., 333.,
                       1., 10., 1., 1.,
                       -1., 4.e-3, 1., 1., 1., 1., 1.)
        for i in range(1, 7):
            for j in range(i, 7):
                self.assertEqual(cm3.get_element(i, j), cm4.get_element(i, j))
        bunch = Bunch.build_ellipse_2d(10., 1., 1., 200., 105.658, False)
        for i in range(0, 2):
            for j in range(0, 2):
                self.assertLess(2.*abs(bunch[i, j]-cm4.get_element(i+1, j+1))/ \
                                   abs(bunch[i, j]+cm4.get_element(i+1, j+1)),
                                   1.e-3)
        bunch = Bunch.build_penn_ellipse(6., 105.658, 333., 1., 200., 1.,
                                         4.e-3, -1.)
        for i in range(0, 4):
            for j in range(0, 4):
                self.assertAlmostEqual(bunch[i, j],
                                       cm4.get_element(i + 3, j + 3))
    def test_create_from_penn_parameters(self):
        """Test maus_cpp.covariance_matrix.create_from_penn_parameters"""
        try:
            maus_cpp.covariance_matrix.create_from_penn_parameters()
            self.assertTrue(False, "Should have thrown a TypeError")
        except TypeError:
            pass
        cm1 = maus_cpp.covariance_matrix.create_from_penn_parameters \
                      (mass=105.658, momentum=200., emittance_t=6., beta_t=333.,
                       emittance_l=1., beta_l=10.)
        cm2 = maus_cpp.covariance_matrix.create_from_penn_parameters \
                      (mass=105.658, momentum=200., emittance_t=6., beta_t=333.,
                       emittance_l=1., beta_l=10., alpha_t=0., alpha_l=0.,
                       charge=1., bz=0., ltwiddle=0., dispersion_x=0.,
                       dispersion_prime_x=0., dispersion_y=0.,
                       dispersion_prime_y=0.)
        for i in range(1, 7):
            for j in range(i, 7):
                self.assertEqual(cm1.get_element(i, j), cm2.get_element(i, j))

        cm3 = maus_cpp.covariance_matrix.create_from_penn_parameters \
                      (mass=105.658, momentum=200., emittance_t=6., beta_t=333.,
                       emittance_l=1., beta_l=10., alpha_t=1., alpha_l=1.,
                       charge=-1., bz=4.e-3, ltwiddle=1., dispersion_x=1.,
                       dispersion_prime_x=1., dispersion_y=1.,
                       dispersion_prime_y=1.)
        cm4 = maus_cpp.covariance_matrix.create_from_penn_parameters \
                      (105.658, 200., 6., 333.,
                       1., 10., 1., 1.,
                       -1., 4.e-3, 1., 1., 1., 1., 1.)
        for i in range(1, 7):
            for j in range(i, 7):
                self.assertEqual(cm3.get_element(i, j), cm4.get_element(i, j))
        bunch = Bunch.build_ellipse_2d(10., 1., 1., 200., 105.658, False)
        for i in range(0, 2):
            for j in range(0, 2):
                self.assertLess(2.*abs(bunch[i, j]-cm4.get_element(i+1, j+1))/ \
                                   abs(bunch[i, j]+cm4.get_element(i+1, j+1)),
                                   1.e-3)
        bunch = Bunch.build_penn_ellipse(6., 105.658, 333.,
                                         1., 200., 1., 4.e-3, -1.)
        for i in range(0, 4):
            for j in range(0, 4):
                self.assertAlmostEqual(bunch[i, j], cm4.get_element(i+3, j+3))
def plot_output():
    """
    Plot output from the simulation
    """
    bunch_list = Bunch.new_list_from_read_builtin('maus_root_virtual_hit',
                                                  'maus_output.root')
    for bunch in bunch_list:
        canvas, hist, graph = bunch.root_scatter_graph('x', 'y', 'mm', 'mm',
                                      xmin=-600, xmax=600, ymin=-600, ymax=600,
                                     	hist_title_string='z='+str(bunch[0]['z']))
    return (canvas, hist, graph)
Example #10
0
    def test_reference_physics(self):
        """
        Check that reference_physics_processes works okay

        Want to check that the hadronic, energy straggling, decay, scattering
        are disabled in reference particle mode; and that energy loss is either
        disabled or mean only (deterministic).

        So fire hadron that decays i.e. pion; assert that there is some energy
        lost in material when required; assert that the energy loss is the same
        for two consecutive particles (i.e. no stochastic contribution); check
        energy loss by check that the time through RF cavity is 0 (for 0 phase).
        Better to write reference particle parameters, but unfortunately that
        isn't implemented yet.

        Long 100 m baseline is chosen st pion is likely to decay.
        """
        file_no_de = run_simulation("none", "none", False, -1., -1., 5.)
        bunch_no_de = Bunch.new_dict_from_read_builtin('maus_root_virtual_hit',
                                                         file_no_de, "pid")[211]
        # assert no energy lost in absorber
        self.assertAlmostEqual(bunch_no_de[0]['pz'], bunch_no_de[1]['pz'], 3)
        # assert no energy change in RF => reference particle also sees no
        # energy loss in absorber
        self.assertAlmostEqual(bunch_no_de[1]['pz'], bunch_no_de[2]['pz'], 3)
        # assert no scattering
        self.assertAlmostEqual(bunch_no_de[1]['px'], 0., 3)

        file_de = run_simulation("mean_energy_loss", "mean_energy_loss",
                                                          False, -1., -1., 5.)
        bunch_de = Bunch.new_dict_from_read_builtin('maus_root_virtual_hit',
                                                            file_de, "pid")[211]
        # assert energy lost in absorber
        self.assertNotAlmostEqual(bunch_de[0]['pz'], bunch_de[1]['pz'], 3)
        # assert no energy change in RF => reference particle also sees same
        # energy loss in absorber
        self.assertAlmostEqual(bunch_de[1]['pz'], bunch_de[2]['pz'], 3)
        # assert no scattering
        self.assertAlmostEqual(bunch_no_de[1]['px'], 0., 3)
Example #11
0
    def test_reference_physics(self):
        """
        Check that reference_physics_processes works okay

        Want to check that the hadronic, energy straggling, decay, scattering
        are disabled in reference particle mode; and that energy loss is either
        disabled or mean only (deterministic).

        So fire hadron that decays i.e. pion; assert that there is some energy
        lost in material when required; assert that the energy loss is the same
        for two consecutive particles (i.e. no stochastic contribution); check
        energy loss by check that the time through RF cavity is 0 (for 0 phase).
        Better to write reference particle parameters, but unfortunately that
        isn't implemented yet.

        Long 100 m baseline is chosen st pion is likely to decay.
        """
        file_no_de = run_simulation("none", "none", False, -1., -1., 5.)
        bunch_no_de = Bunch.new_dict_from_read_builtin('maus_root_virtual_hit',
                                                       file_no_de, "pid")[211]
        # assert no energy lost in absorber
        self.assertAlmostEqual(bunch_no_de[0]['pz'], bunch_no_de[1]['pz'], 3)
        # assert no energy change in RF => reference particle also sees no
        # energy loss in absorber
        self.assertAlmostEqual(bunch_no_de[1]['pz'], bunch_no_de[2]['pz'], 3)
        # assert no scattering
        self.assertAlmostEqual(bunch_no_de[1]['px'], 0., 3)

        file_de = run_simulation("mean_energy_loss", "mean_energy_loss", False,
                                 -1., -1., 5.)
        bunch_de = Bunch.new_dict_from_read_builtin('maus_root_virtual_hit',
                                                    file_de, "pid")[211]
        # assert energy lost in absorber
        self.assertNotAlmostEqual(bunch_de[0]['pz'], bunch_de[1]['pz'], 3)
        # assert no energy change in RF => reference particle also sees same
        # energy loss in absorber
        self.assertAlmostEqual(bunch_de[1]['pz'], bunch_de[2]['pz'], 3)
        # assert no scattering
        self.assertAlmostEqual(bunch_no_de[1]['px'], 0., 3)
Example #12
0
 def __init__(self):
     """Initialise an empty equality test"""
     BaseTest.__init__(self)
     self.bunch     = Bunch()
     self.tolerance = xboa.Common.float_tolerance    
     self.test_out  = 'fail'
Example #13
0
class HitEqualityTest(BaseTest):
    """
    Hit equality test checks that two hits are equal within some floating point
    tolerance.
      bunch           = check that hits in the bunch are the same as those in 
                        the test bunch
      float_tolerance = floating point tolerance for the test
      test_result     = string, either 'pass' or 'fail' depending on whether 
                        test passed or failed
    """
    def __init__(self):
        """Initialise an empty equality test"""
        BaseTest.__init__(self)
        self.bunch     = Bunch()
        self.tolerance = xboa.Common.float_tolerance    
        self.test_out  = 'fail'

    def __repr__(self):
        """Return a string; eval(repr(test) ) will return an identical test"""
        return 'hit_equality_test.new('+repr(self.tolerance)+\
                repr(self.test_out)+repr(self.bunch)+')'

    def __str__(self):
        return 'hit_equality_test with bunch of: '+str(self.bunch)+\
               ' tolerance: '+str(self.tolerance)+' result: '+\
               str(self.test_out)

    def new(tolerance, test_result, bunch):
        """initialise a new test"""
        a_test = HitEqualityTest()
        a_test.bunch     = bunch
        a_test.tolerance = tolerance
        a_test.test_out  = test_result    
        return a_test
    new = staticmethod(new)

    def run_test(self, test_bunch):
        """
        Compare test_bunch with stored bunch. return an updated copy of self 
        with test bunch and updated test_result
        """
        het_out = copy.deepcopy(self)
        het_out.test_out = 'pass'
        het_out.bunch       = test_bunch
        if not self.bunch.hit_equality(test_bunch, self.tolerance):
            het_out.test_out = 'fail'

    def test_result(self):
        """
        Return test result ('pass' or 'fail') depending on whether the test
        passed or failed
        """
        return self.test_out

    def deepcopy(self):
        """Return a copy of self (allocating new memory)"""
        return HitEqualityTest.new(self.tolerance, self.test_out, self.bunch)

    def make_plots(test_list):
        """No plots to make - so does nothing"""
        pass
    make_plots = staticmethod(make_plots)