def write_sdds(self, filename, gap, beam_offset, struct_length):
     s0 = (self.time - self.time[0])*c
     new_s = np.linspace(0, s0.max()*1.1, int(len(s0)*1.1))
     w_wld = wf_model.wld(new_s, gap/2., beam_offset)*struct_length
     if beam_offset == 0:
         w_wxd = np.zeros_like(w_wld)
     else:
         w_wxd = wf_model.wxd(new_s, gap/2., beam_offset)*struct_length
     w_wxd_deriv = np.zeros_like(w_wxd)
     return wf_model.write_sdds(filename, new_s/c, w_wld, w_wxd, w_wxd_deriv)
Пример #2
0
    sp_ctr = 1

    ss = np.linspace(0, (beam[4, :].max() - beam[4, :].min()) * c * 1.01,
                     len_s)
    xx = np.linspace(beam[0, :].min(), beam[0, :].max(), len_x) + beam_offset

    distance = semigap - beam_offset

    sp = sp0 = subplot(sp_ctr,
                       title='Single particle wake',
                       xlabel='s [$\mu$m]',
                       ylabel='Wake [kV/pC/m]')
    sp_ctr += 1

    for index in [0, len_x // 2, -1]:
        z = wf_model.wxd(ss, semigap, xx[index])
        distance = semigap - xx[index]
        sp.plot(ss * 1e6, z * 1e-15, label='%.1f' % (distance * 1e6))

    probe_s = beam[4, :] * c
    probe_x = beam[0, :] + beam_offset

    wake2d_dict = wf_model.wf2d(probe_s, probe_x, semigap, bp.charge,
                                wf_model.wxd)
    beam_hist = wake2d_dict['beam_hist']
    s_edges = wake2d_dict['s_bins']
    x_edges = wake2d_dict['x_bins']

    sp = sp1 = subplot(sp_ctr,
                       title='Wake potential',
                       xlabel='s [$\mu$m]',
Пример #3
0
                     title='$\Delta$ x assuming $R_{12}$=10 m',
                     xlabel='Offset [mm]',
                     ylabel='$\Delta$ x [$\mu$m]',
                     scix=True,
                     sciy=False)
sp_ctr += 1

offset = np.array([-1e-3, 0, 1e-3])

delta_x_list = []
kick_list = []
gap_list = np.array([2.5e-3, 4e-3, 6e-3])

for gap in gap_list:
    label = gap * 1e3
    single_particle_wake = wxd(xx_space, gap / 2)
    sp_single.plot(xx_space * 1e6, single_particle_wake * 1e-15, label=label)
    wake_effect = np.convolve(yy_charge, single_particle_wake)[:len(xx_space)]

    #wake_effect2 = np.zeros_like(xx_space)
    #for n in range(len(xx_space)):
    #    for n2 in range(0,n):
    #        wake_effect2[n] += yy_charge[n2] * single_particle_wake[n-n2]
    #assert np.all(wake_effect == wake_effect2)

    sp_wake_effect.semilogy(xx_space * 1e6, wake_effect * 1e-6, label=label)
    sp_wake_effect2.plot(xx_space * 1e6, wake_effect * 1e-6, label=label)
    q = np.sum(yy_charge)
    kick_factor = np.sum(wake_effect * yy_charge) / q
    kick_list.append(kick_factor)
    delta_x = kick_factor * Ls * 10 / energy_eV
Пример #4
0
                     xlabel='Offset [mm]',
                     ylabel='$\Delta$ x [$\mu$m]',
                     scix=True,
                     sciy=False)
sp_ctr += 1

offset = np.array([-1e-3, 0, 1e-3])

delta_x_list = []
kick_list = []
offset_list = np.array([4.7e-3, 4.8e-3, 4.9e-3])
gap = 10e-3

for beam_offset in offset_list:
    label = '%.1f' % (5 - beam_offset * 1e3)
    single_particle_wake = wxd(xx_space, gap / 2, beam_offset)
    sp_single.plot(xx_space * 1e6, single_particle_wake * 1e-15, label=label)
    wake_effect = np.convolve(yy_charge, single_particle_wake)[:len(xx_space)]

    #wake_effect2 = np.zeros_like(xx_space)
    #for n in range(len(xx_space)):
    #    for n2 in range(0,n):
    #        wake_effect2[n] += yy_charge[n2] * single_particle_wake[n-n2]
    #assert np.all(wake_effect == wake_effect2)

    sp_wake_effect.semilogy(xx_space * 1e6, wake_effect * 1e-6, label=label)
    sp_wake_effect2.plot(xx_space * 1e6, wake_effect * 1e-6, label=label)
    q = np.sum(yy_charge)
    kick_factor = np.sum(wake_effect * yy_charge) / q
    kick_list.append(kick_factor)
    delta_x = kick_factor * Ls * 10 / energy_eV
Пример #5
0
elif hostname == 'pc11292.psi.ch':
    dirname1 = '/sf/data/measurements/2020/10/03/'
    dirname2 = '/sf/data/measurements/2020/10/04/'
elif hostname == 'pubuntu':
    dirname1 = '/home/work/data_2020-10-03/'
    dirname2 = '/home/work/data_2020-10-04/'
    archiver_dir = '/home/work/'

magnet_file = archiver_dir + 'archiver_api_data/2020-10-03.h5'

beam_offset = 4.692e-3
semigap = 5e-3

s_arr = np.linspace(0, 400e-15 * c, int(1e5))

spw_dipole = wf_model.wxd(s_arr, semigap, beam_offset)
spw_quadrupole = wf_model.wxq(s_arr, semigap, beam_offset)

tracker = tracking.Tracker(magnet_file,
                           timestamp,
                           struct_lengths,
                           n_particles,
                           n_emittances,
                           screen_bins,
                           screen_cutoff,
                           smoothen,
                           profile_cutoff,
                           len_profile,
                           bp_smoothen=bp_smoothen,
                           quad_wake=quad_wake)
Пример #6
0
from scipy.constants import c
from wf_model import wxd
from h5_storage import loadH5Recursive
from scipy.io import loadmat

saved = loadH5Recursive('./example_current_profile.h5')
paolos_saved = loadmat('./wxd.mat')
paolos_wxd = paolos_saved['wxd']
paolos_s = paolos_saved['s'].squeeze()

time_profile = saved['time_profile']
current = saved['current']
energy_eV = saved['energy_eV']

s = time_profile * c
s -= s.min()

a = 2.5e-3 / 2

my_wxd = wxd(paolos_s, a)
from scipy.optimize import curve_fit
import numpy as np
import wf_model

import myplotstyle as ms

plt.close('all')

gap = 10e-3
distance_arr = np.linspace(250e-6, 500e-6, int(1e4))

ms.figure('Scaling')
sp = ms.subplot_factory(1, 1)(1, xlabel='Distance [um]')

for s in [1e-6, 10e-6, 25e-6, 50e-6, 75e-6]:
    wake = wf_model.wxd(s, gap / 2., gap / 2. - distance_arr)
    color = sp.plot(distance_arr * 1e6, wake,
                    label='s=%i um' % (s * 1e6))[0].get_color()

    def fit_func(x, scale, order):
        return scale * 1 / x**order

    def fit_func3(x, scale):
        return scale * 1 / x**3

    fit, _ = curve_fit(fit_func, distance_arr, wake, p0=[1e12, 1])
    fit2, _ = curve_fit(fit_func3, distance_arr, wake, p0=[1e12])
    reconstruction = fit_func(distance_arr, *fit)
    reconstruction2 = fit_func3(distance_arr, *fit2)
    sp.plot(distance_arr * 1e6,
            reconstruction,
Пример #8
0
with open(filename, 'rb') as f:
    d = pickle.load(f)

beam0 = d['beam_before_s2']
bp = d['profile']
semigap = d['gap'] / 2.
beam_offset = d['beam_offset']

for beam_offset in [4.5e-3, 4.6e-3, 4.7e-3]:

    ss = np.linspace(0, (beam0[4, :].max() - beam0[4, :].min()) * c * 1.01,
                     len_s)
    xx = np.linspace(beam0[0, :].min(), beam0[0, :].max(), len_x) + beam_offset
    s, x = np.meshgrid(ss, xx)
    #
    z = wf_model.wxd(s, semigap, x)

    #wf_interp = interp2d(ss, xx, z)

    distance = semigap - beam_offset

    ms.figure('Test interp around distance %i um' % round(distance * 1e6))
    subplot = ms.subplot_factory(2, 2)
    sp_ctr = 1

    sp = sp0 = subplot(sp_ctr,
                       title='Single particle wake',
                       xlabel='s [$\mu$m]',
                       ylabel='Wake [kV/pC/m]')
    sp_ctr += 1