def test_Ekin(self): print('\nTest momentum') beam = pytlwall.Beam(p_MeV_c=0.1) self.assertEqual(0.87, round(beam.betarel, 2)) self.assertEqual(2.00, round(beam.gammarel, 3)) self.assertEqual(938.3, round(beam.Ekin_MeV, 1)) self.assertEqual(0.1, round(beam.p_MeV_c, 1))
def test_default(self): print('\nTesting default values') beam = pytlwall.Beam() self.assertEqual(1, beam.betarel) self.assertEqual(float('inf'), beam.gammarel) self.assertEqual(float('inf'), beam.Ekin_MeV) self.assertEqual(float('inf'), beam.p_MeV_c)
def test_Ekin(self): print('\nTest kinetic energy') beam = pytlwall.Beam(Ekin_MeV=0.1) self.assertEqual(0.015, round(beam.betarel, 3)) self.assertEqual(1.0, round(beam.gammarel, 3)) self.assertEqual(0.1, round(beam.Ekin_MeV, 1)) self.assertEqual(13.7, round(beam.p_MeV_c, 1))
def test_betarel(self): print('\nTest beta') beam = pytlwall.Beam(betarel=0.106) self.assertEqual(0.106, beam.betarel) self.assertEqual(1.006, round(beam.gammarel, 3)) self.assertEqual(5.3, round(beam.Ekin_MeV, 1)) self.assertEqual(100.0, round(beam.p_MeV_c, 1))
def test_gammarel(self): print('\nTest gamma') beam = pytlwall.Beam(gammarel=1.006) self.assertEqual(0.109, round(beam.betarel, 3)) self.assertEqual(1.006, round(beam.gammarel, 3)) self.assertEqual(5.6, round(beam.Ekin_MeV, 1)) self.assertEqual(102.9, round(beam.p_MeV_c, 1))
def read_beam(self, cfg_file=None): if cfg_file is not None: self.read_cfg(cfg_file) if self.config.has_section('beam_info') is False: return None test_beam_shift = self.config.getfloat('beam_info', 'test_beam_shift') if self.config.has_option('beam_info', 'betarel'): betarel = self.config.getfloat('beam_info', 'betarel') if self.config.has_option('beam_info', 'mass_MeV_c2'): mass_MeV_c2 = self.config.getfloat('beam_info', 'mass_MeV_c2') beam = pytlwall.Beam(betarel=betarel, test_beam_shift=test_beam_shift, mass_MeV_c2=mass_MeV_c2) else: beam = pytlwall.Beam(betarel=betarel, test_beam_shift=test_beam_shift) return beam if self.config.has_option('beam_info', 'gammarel'): gammarel = self.config.getfloat('beam_info', 'gammarel') if self.config.has_option('beam_info', 'mass_MeV_c2'): mass_MeV_c2 = self.config.getfloat('beam_info', 'mass_MeV_c2') beam = pytlwall.Beam(gammarel=gammarel, test_beam_shift=test_beam_shift, mass_MeV_c2=mass_MeV_c2) else: beam = pytlwall.Beam(gammarel=gammarel, test_beam_shift=test_beam_shift) return beam if self.config.has_option('beam_info', 'Ekin_MeV'): Ekin_MeV = self.config.getfloat('beam_info', 'Ekin_MeV') if self.config.has_option('beam_info', 'mass_MeV_c2'): mass_MeV_c2 = self.config.getfloat('beam_info', 'mass_MeV_c2') beam = pytlwall.Beam(Ekin_MeV=Ekin_MeV, test_beam_shift=test_beam_shift, mass_MeV_c2=mass_MeV_c2) else: beam = pytlwall.Beam(Ekin_MeV=Ekin_MeV, test_beam_shift=test_beam_shift) return beam if self.config.has_option('beam_info', 'p_MeV_c'): p_MeV_c = self.config.getfloat('beam_info', 'p_MeV_c') if self.config.has_option('beam_info', 'mass_MeV_c2'): mass_MeV_c2 = self.config.getfloat('beam_info', 'mass_MeV_c2') beam = pytlwall.Beam(p_MeV_c=p_MeV_c, test_beam_shift=test_beam_shift, mass_MeV_c2=mass_MeV_c2) else: beam = pytlwall.Beam(p_MeV_c=p_MeV_c, test_beam_shift=test_beam_shift) return beam
import pytlwall import pandas as pd import pytlwall.plot_util as plot # Define Beam beam = pytlwall.Beam(betarel=0.9, test_beam_shift=0.002) # Define Frequencies list freq = pytlwall.Frequencies(fmin=2, fmax=8, fstep=2) # Define Layers layers = [] layer0 = pytlwall.Layer(layer_type='CW', thick_m=0.1, muinf_Hz=0., epsr=1., sigmaDC=1.e6, k_Hz=float('inf'), tau=0., RQ=0., boundary=False) layers.append(layer0) boundary = pytlwall.Layer(layer_type='V', boundary=True) layers.append(boundary) # Define Chamber characteristics pipe_len_m = 1. pipe_rad_m = 0.0184 chamber_shape = 'CIRCULAR' betax = 1. betay = 1.
def beam_interface(): choice = '' beam = pytlwall.Beam() while choice.lower() != 'back' and choice.lower() != 'x': submenu_beam() choice = input('Your choice: ') if choice.lower() == 'beta': choice = input('Insert beta value ') try: value = float(choice) except ValueError: print(f'Value used {beam.betarel}') if value > 0 and value < 1: beam.betarel = value else: print(f'Beta must be between 0 and 1, value used ' f' {beam.betarel}') elif choice.lower() == 'gamma': choice = input('Insert gamma value ') try: value = float(choice) except ValueError: print(f'Value used {beam.gammarel}') if value > 0: beam.gammarel = value else: print(f'Gamma must be greater than 0, used value ' f' {beam.gammarel}') elif choice.lower() == 'mass': choice = input(f'Insert mass value, default = {prot_mass}') try: value = float(choice) except ValueError: print(f'Value used {beam._m_MeV_c2}') if value > 0: beam._m_MeV_c2 = value else: print(f'Mass must be greater than 0, used value ' f' {beam._m_MeV_c2}') elif choice.lower() == 'p': choice = input('Insert momentum value in MeV/c ') try: value = float(choice) except ValueError: print(f'Value used {beam.p_MeV_c}') if value > 0: beam.p_MeV_c = value else: print(f'Momentum must be greater than 0, used value ' f' {beam.p_MeV_c}') elif choice.lower() == 'ekin': choice = input('Insert kinetic energy value in MeV ') try: value = float(choice) except ValueError: print(f'Value used {beam.Ekin_MeV}') if value > 0: beam.Ekin_MeV = value else: print(f'Kinetic energy must be greater than 0, used value ' f' {beam.Ekin_MeV}') elif choice.lower() == 'shift': choice = input('Insert beam test shift in meters ') try: value = float(choice) except ValueError: print(f'Value used {beam.Ekin_MeV}') if value > 0: beam.test_beam_shift = value else: print(f'The shift must be greater than 0, used value ' f' {beam.test_beam_shift}') return beam
def test_momentum_neg(self): print('\nTest negative value for momentum') beam = pytlwall.Beam(p_MeV_c=-4.99) self.assertEqual(1, beam.betarel)
def test_Ekin_neg(self): print('\nTest negative value for kinetic energy') beam = pytlwall.Beam(Ekin_MeV=-0.99) self.assertEqual(1, beam.betarel)
def test_betarel_gt1(self): print('\nTest beta greater than 1') beam = pytlwall.Beam(betarel=1.99) self.assertEqual(1, beam.betarel)
def test_betarel_neg(self): print('\nTest negative value for beta') beam = pytlwall.Beam(betarel=-0.99) self.assertEqual(1, beam.betarel)
def test_string(self): print('\nTest string value for beta') beam = pytlwall.Beam(betarel='betarel') self.assertEqual(1, beam.betarel)