Bunching¶
Bunching at some wavelength $\lambda$ for a list of particles $z$ is given by the weighted sum of complex phasors:
$$B(z, \lambda) \equiv \frac{\sum_j w_j e^{i k z_j}}{\sum w_j} $$
where $k = 2\pi/\lambda$ and $w_j$ are the weights of the particles.
See for example D. Ratner's disseratation.
Add bunching to particles¶
This uses a simple method to add perfect bunching at 0.1 µm
In [1]:
Copied!
from pmd_beamphysics import ParticleGroup
%config InlineBackend.figure_format = 'retina'
from pmd_beamphysics import ParticleGroup
%config InlineBackend.figure_format = 'retina'
In [2]:
Copied!
P = ParticleGroup("data/bmad_particles2.h5")
P.drift_to_t()
wavelength = 0.1e-6
dz = (P.z / wavelength % 1) * wavelength
P.z -= dz
P = ParticleGroup("data/bmad_particles2.h5")
P.drift_to_t()
wavelength = 0.1e-6
dz = (P.z / wavelength % 1) * wavelength
P.z -= dz
In [3]:
Copied!
P.plot("z")
P.plot("z")
Calculate bunching¶
All of these methods will calculate the bunching. The first returns a complex number bunching
The string attributes return real numbers, magnitude and argument (phase):
'bunching_
returnsnp.abs(bunching)
'bunching_phase_
returnsnp.angle(bunching)
In [4]:
Copied!
b = P.bunching(wavelength)
b
b = P.bunching(wavelength)
b
Out[4]:
np.complex128(1-3.2133096564432656e-16j)
In [5]:
Copied!
P["bunching_0.1e-6"]
P["bunching_0.1e-6"]
Out[5]:
np.float64(1.0)
In [6]:
Copied!
P["bunching_phase_0.1e-6"]
P["bunching_phase_0.1e-6"]
Out[6]:
np.float64(-3.2133096564432656e-16)
In [7]:
Copied!
P["bunching_0.1_um"]
P["bunching_0.1_um"]
Out[7]:
np.float64(1.0)
Simple plot¶
In [8]:
Copied!
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
In [9]:
Copied!
wavelengths = wavelength * np.linspace(0.9, 1.1, 200)
wavelengths = wavelength * np.linspace(0.9, 1.1, 200)
In [10]:
Copied!
plt.plot(wavelengths * 1e6, np.abs(list(map(P.bunching, wavelengths))))
plt.xlabel("wavelength (µm)")
plt.ylabel("bunching")
plt.plot(wavelengths * 1e6, np.abs(list(map(P.bunching, wavelengths))))
plt.xlabel("wavelength (µm)")
plt.ylabel("bunching")
Out[10]:
Text(0, 0.5, 'bunching')
In [11]:
Copied!
P.slice_plot("bunching_0.1_um")
P.slice_plot("bunching_0.1_um")
In [12]:
Copied!
P.slice_plot("bunching_phase_0.1_um")
P.slice_plot("bunching_phase_0.1_um")
In [13]:
Copied!
P.in_z_coordinates
P.in_z_coordinates
Out[13]:
False
Units¶
Bunching is dimensionless
In [14]:
Copied!
P.units("bunching_0.1_um")
P.units("bunching_0.1_um")
Out[14]:
pmd_unit('', 1, (0, 0, 0, 0, 0, 0, 0))
In [15]:
Copied!
P.units("bunching_phase_0.1_um")
P.units("bunching_phase_0.1_um")
Out[15]:
pmd_unit('rad', 1, (0, 0, 0, 0, 0, 0, 0))
Bunching function¶
This is the function that is used.
In [ ]:
Copied!
In [16]:
Copied!
?bunching
?bunching
Object `bunching` not found.