:mod:`ocelot.cpbd.beam` ======================= .. py:module:: ocelot.cpbd.beam .. autoapi-nested-parse:: definition of particles, beams and trajectories Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: ocelot.cpbd.beam.Twiss ocelot.cpbd.beam.Particle ocelot.cpbd.beam.Beam ocelot.cpbd.beam.BeamArray ocelot.cpbd.beam.Trajectory ocelot.cpbd.beam.ParticleArray ocelot.cpbd.beam.SliceParameters Functions ~~~~~~~~~ .. autoapisummary:: ocelot.cpbd.beam.recalculate_ref_particle ocelot.cpbd.beam.get_envelope ocelot.cpbd.beam.get_current ocelot.cpbd.beam.gauss_from_twiss ocelot.cpbd.beam.waterbag_from_twiss ocelot.cpbd.beam.ellipse_from_twiss ocelot.cpbd.beam.moments ocelot.cpbd.beam.m_from_twiss ocelot.cpbd.beam.beam_matching ocelot.cpbd.beam.sortrows ocelot.cpbd.beam.convmode_py ocelot.cpbd.beam.s2cur_auxil_py ocelot.cpbd.beam.s_to_cur ocelot.cpbd.beam.slice_analysis_py ocelot.cpbd.beam.simple_filter ocelot.cpbd.beam.interp1 ocelot.cpbd.beam.slice_analysis_transverse ocelot.cpbd.beam.global_slice_analysis_extended ocelot.cpbd.beam.global_slice_analysis ocelot.cpbd.beam.parray2beam ocelot.cpbd.beam.generate_parray ocelot.cpbd.beam.generate_beam .. data:: _logger .. data:: ne_flag :annotation: = True .. data:: nb_flag :annotation: = True .. py:class:: Twiss(beam=None) class - container for twiss parameters .. method:: __str__(self) Return str(self). .. py:class:: Particle(x=0.0, y=0.0, px=0.0, py=0.0, s=0.0, p=0.0, tau=0.0, E=0.0, q=0.0) particle to be used for tracking .. method:: __str__(self) Return str(self). .. py:class:: Beam(x=0, xp=0, y=0, yp=0) .. attribute:: properties :annotation: = ['g', 'dg', 'emit_xn', 'emit_yn', 'p', 'pz', 'px', 'py'] .. method:: g(self) :property: .. method:: dg(self) :property: .. method:: emit_xn(self) :property: .. method:: emit_yn(self) :property: .. method:: p(self) :property: .. method:: pz(self) :property: .. method:: px(self) :property: .. method:: py(self) :property: .. method:: len(self) .. method:: to_array(self, nslice=100, window_len=None) .. method:: sizes(self) .. py:class:: BeamArray(nslice=0) Bases: :class:`ocelot.cpbd.beam.Beam` .. method:: idx_max(self) .. method:: len(self) .. method:: charge(self) .. method:: params(self) .. method:: sort(self) .. method:: equidist(self) .. method:: smear(self, sw) .. method:: get_s(self, s) .. method:: get_E(self) .. method:: set_E(self, E_GeV) .. method:: center(self, s) .. method:: cut_empty_I(self, thresh=0.01) .. method:: start_at_0(self) .. method:: cleanup(self) .. method:: __getitem__(self, index) .. method:: __delitem__(self, index) .. method:: pk(self) .. method:: add_chirp(self, chirp=0, order=1, s0=None) adds energy chirp of given "order" to the beam around "center" position [m] chirp = dE/E0/ds[um]**order = dg/g0/s[um]**order so that g_new = g0 + dg = g0 + g0 (s-s0)**order * chirp .. method:: add_chirp_poly(self, coeff, s0=None) The method adds a polynomial energy chirp to the beam object. coeff --- coefficients for the chirp s0 --- the point with respect to which the chirp will be introduced The expression for the chirp: E = E0((g0 + coeff[0])/g0 + + coeff[1]*(s - s0))**1 / 1! / ((speed_of_light * 1e-15)**1 * g0) + + coeff[2]*(s - s0))**2 / 2! / ((speed_of_light * 1e-15)**2 * g0) + + coeff[3]*(s - s0))**3 / 3! / ((speed_of_light * 1e-15)**3 * g0) + ... ... + coeff[n]*(s - s0))**n / n! / ((speed_of_light * 1e-15)**n * g0)) where coeff[n] is represented in [1/fs**n] The convention for the coeff is introduced for convenient treatment this with respect to a radiation chirp in order to easily satisfy the resonant condition along the whole bunch in the case of linear electron bunch chirp. Here is the expresion: 2*dw/dt = (w0/g0) * dg/dt @author: Andrei Trebushinin .. method:: add_wake(self, tube_radius=0.005, tube_len=1, conductivity=36600000.0, tau=7.1e-15, roughness=6e-07, d_oxid=5e-09) .. method:: to_array(self, *args, **kwargs) :abstractmethod: .. py:class:: Trajectory .. method:: add(self, ct, x, y, xp, yp, z, s) .. method:: last(self) .. py:class:: ParticleArray(n=0) array of particles of fixed size; for optimized performance (x, x' = px/p0),(y, y' = py/p0),(ds = c*tau, p = dE/(p0*c)) p0 - momentum .. py:class:: LostParticleRecorder(n) Stores information about particles that are getting lost. Attributes: lost_particles: List of indices of deleted particle. Notes: The indices of the initial ParticleArray are used. lp_to_pos_hist: Histogram of number of lost particles to position s. [(pos, num of lost particles), ...] .. method:: add(self, inds, position) .. method:: rm_tails(self, xlim, ylim, px_lim, py_lim) Method removes particles outside range [-xlim, +xlim], [-px_lim, +px_lim] ... .. method:: __getitem__(self, idx) .. method:: __setitem__(self, idx, p) .. method:: list2array(self, p_list) .. method:: array2list(self) .. method:: array2ex_list(self, p_list) .. method:: size(self) .. method:: x(self) .. method:: px(self) .. method:: y(self) .. method:: py(self) .. method:: tau(self) .. method:: p(self) .. method:: t(self) :property: .. method:: n(self) :property: .. method:: thin_out(self, nth=10, n0=0) Method to thin out the particle array in n-th times. Means every n-th particle will be saved in new Particle array :param nth: 10, every n-th particle will be taken to new Particle array :param n0: start from n0 particle :return: New ParticleArray .. method:: rm_particle(self, index) Method removes a "bad" particle with particular "index". :param index: :return: .. method:: rescale2energy(self, energy) Method to rescale beam coordinates with new energy :param energy: new energy :return: .. method:: __str__(self) Return str(self). .. method:: delete_particles(self, inds, record=True) Deletes particles from the particle array via index. :param inds: Indices that will be removed from the particle array. :param record: If record is true the deleted particles will be saved in self.lost_particle_recorder. :return: .. function:: recalculate_ref_particle(p_array) .. function:: get_envelope(p_array, tws_i=Twiss(), bounds=None) Function to calculate twiss parameters form the ParticleArray :param p_array: ParticleArray :param tws_i: optional, design Twiss, :param bounds: optional, [left_bound, right_bound] - bounds in units of std(p_array.tau()) :return: Twiss() .. function:: get_current(p_array, num_bins=200, **kwargs) Function calculates beam current from particleArray. :param p_array: particleArray :param charge: - None, OBSOLETE, charge of the one macro-particle. If None, charge of the first macro-particle is used :param num_bins: number of bins :return s, I - (np.array, np.array) - beam positions [m] and currents in [A] .. function:: gauss_from_twiss(emit, beta, alpha) .. function:: waterbag_from_twiss(emit, beta, alpha) .. function:: ellipse_from_twiss(emit, beta, alpha) .. function:: moments(x, y, cut=0) .. function:: m_from_twiss(Tw1, Tw2) .. function:: beam_matching(particles, bounds, x_opt, y_opt, remove_offsets=True) Beam matching function, the beam is centered in the phase space :param particles: ParticleArray :param bounds: [start, stop] in rms of sigmas in longitudinal direction :param x_opt: [alpha, beta, mu (phase advance)] :param y_opt: [alpha, beta, mu (phase advance)] :param remove_offsets: True, remove offsets in transverse planes :return: transform ParticleArray (the same object) .. function:: sortrows(x, col) .. function:: convmode_py(A, B, mode) .. data:: convmode .. function:: s2cur_auxil_py(A, xiA, C, N, I) .. data:: s2cur_auxil .. function:: s_to_cur(A, sigma, q0, v) Function to calculate beam current :param A: s-coordinates of particles :param sigma: smoothing parameter :param q0: bunch charge :param v: mean velocity :return: [s, I] .. function:: slice_analysis_py(z, x, xs, M, to_sort) returns: , , , , , np.sqrt( * - ^2) based on M particles in moving window Sergey, check please .. data:: slice_analysis .. function:: simple_filter(x, p, iter) .. function:: interp1(x, y, xnew, k=1) .. function:: slice_analysis_transverse(parray, Mslice, Mcur, p, iter) .. py:class:: SliceParameters .. function:: global_slice_analysis_extended(parray, Mslice, Mcur, p, iter) Function to calculate slice parameters :param parray: ParticleArray :param Mslice: 5000, nparticles in the slice :param Mcur: 0.01, smoothing parameters to calculate the beam current: smooth_param = m_std * np.std(p_array.tau()) :param p: 2, filter parameter in the func: simple_filter :param iter: 2, filter parameter in the func: simple_filter :return: s, I, ex, ey, me, se, gamma0, emitxn, emityn .. function:: global_slice_analysis(parray, nparts_in_slice=5000, smooth_param=0.01, filter_base=2, filter_iter=2) Function to calculate slice parameters :param parray: ParticleArray :param nparts_in_slice: 5000, nparticles in the slice :param smooth_param: 0.01, smoothing parameters to calculate the beam current: smooth_param = m_std * np.std(p_array.tau()) :param filter_base: 2, filter parameter in the func: simple_filter :param filter_iter: 2, filter parameter in the func: simple_filter :return: SliceParameters, .. function:: parray2beam(parray, step=1e-07) reads ParticleArray() returns BeamArray() step [m] - long. size ob bin to calculate distribution parameters .. function:: generate_parray(sigma_x=0.0001, sigma_px=2e-05, sigma_y=None, sigma_py=None, sigma_tau=0.001, sigma_p=0.0001, chirp=0.01, charge=5e-09, nparticles=200000, energy=0.13, tau_trunc=None, tws=None) Method to generate ParticleArray with gaussian distribution. Note: in ParticleArray, {x, px} and {y, py} are canonical coordinates. {tau, p} is not, to make it canonical the sign of "tau" should be flipped. :param sigma_x: std(x), x is horizontal cartesian coordinate. :param sigma_px: std(px), 'px' is conjugate momentum canonical momentum px/p0. :param sigma_y: std(y), y is vertical cartesian coordinate. :param sigma_py: std(py), 'py' is canonical momentum py/p0. :param sigma_tau: std(tau), "tau" = c*t :param sigma_p: std(p), 'p' is canonical momentum E/(c*p0) :param chirp: energy chirp [unitless], linear correlation - p_i += chirp * tau_i/sigma_tau :param charge: beam charge in [C], 5e-9 by default :param nparticles: namber of particles, 200k by default :param energy: beam energy in [GeV], 0.13 [GeV] :param tau_trunc: None, if not [float] - truncated gauss distribution in "tau" direction. :param tws: None, if Twiss obj - the beam is matched to twiss params. :return: ParticleArray .. function:: generate_beam(E, I=5000, l_beam=3e-06, **kwargs) Generates BeamArray object accepts arguments with the same names as BeamArray().parameters() I - current in Amps E - beam ebergy in GeV dE - rms energy spread in GeV emit_x, emit_n(both normalized), emit_xn, etc. shape - beam shape ('gaussian' of 'flattop') l_beam [m] - beam length in meters l_window [m] - window length in um by default: l_beam * 2 if flattop, l_beam * 6 if gaussian, nslice - number of slices in the beam