We have 7 h scheduled this week (https://cas.web.cern.ch/sites/cas.web.cern.ch/files/programmes/vysoke-tatry-2019-programme_5.pdf).
from IPython.display import Image
fig = Image(filename=('/Users/sterbini/CERNBox/2019/CAS/Vysoke_Tatry/Python/Wednesday/programme_5.png'))
fig
The goal is to complement with hand-on numerical exercises the lectures of Transverse Linear Beam Dynamics:
On Wednesday 11.09 we will cover the following topics
On Friday 13.09 we will cover
On Saturday 14.09 we will generalize the code including
We will fine tune the pace depending on the needs.
The format is quite simple: we are going to solve the exercises presented in https://indico.cern.ch/event/808940/contributions/3553546/attachments/1904762/3145489/CAS_Optics_Primer.pdf
You will try first on your own for few minutes and after we will solve and comment together.
The installation procedure for Python3 (it will be used also next week for the longitudinal hands-on) can be found at https://codimd.web.cern.ch/s/HkfQy3YbB
Do not hesitate to ask Werner, Volker, Andrea or Guido if you have questions, doubts or problems!
Just to get familiar with a bit of syntax
# Import the modules
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
import sympy as sy
# Matrix definition
Omega=np.array([[0, 1],[-1,0]])
M=np.array([[1, 0],[1,1]])
M
# Sum and multiplication of matrices
Omega - M.T @ Omega @ M
# M.T means the "traspose of M".
# Function definition
def Q(f=1):
return np.array([[1, 0],[-1/f,1]])
np.linalg.det(Q(10))
np.linalg.det?
# check a simple plot
plt.plot([0,10],[0,10],'ob-')
plt.xlabel('My x-label [arb. units]')
plt.ylabel('My y-label [arb. units]')
plt.title('My title')
# an sns plot
sns.set(style="ticks")
rs = np.random.RandomState(10)
x = rs.normal(size=10000)
y = rs.normal(size=10000)
sns.jointplot(x, y, kind="hex");
# from Wolfgang's pag.26
fig = Image(filename=('/Users/sterbini/CERNBox/2019/CAS/Vysoke_Tatry/Python/Wednesday/pag26.png'))
fig
Show that multiplying two drift matrices, one with $L_1$ and the other with $L_2$ in the upper right corner, produces a matrix with the sum of the distances in the upper right corner.
Even if we can prove it by hand, we take the opportunity to show some symbolic computation in python.
# we introduce the symbols
L_1=sy.Symbol('L_1');
L_2=sy.Symbol('L_2');
# we define the matrices
DRIFT_1=sy.Matrix([[1,L_1],[0,1]])
DRIFT_2=sy.Matrix([[1,L_2],[0,1]])
# we multiply the matrices.
# NOTA BENE: the @ operator is the "multiplication between matrix" in py3
DRIFT_2 @ DRIFT_1
A similar analysis can be done for two thin quadrupoles.
# we introduce the symbols
f_1=sy.Symbol('f_1');
f_2=sy.Symbol('f_2');
# we define the matrices
Q_1=sy.Matrix([[1,0],[1/f_1,1]])
Q_2=sy.Matrix([[1,0],[1/f_2,1]])
# we multiply the matrices.
# NOTA BENE: the @ operator is the "multiplication between matrix" in py3
Q_2 @ Q_1
How do you describe a ray that is on the optical axis?
The phase space vector of a particle sitting on the optical axis can be represented by \begin{equation} X=\left( \begin{array}{c} 0 \\ x' \end{array} \right). \end{equation} We assumed that "on the optical axis" referred only to the position and not to the particle angle, x'.
Show by multiplying the respective matrices that a parallel ray, which first passes through a lens with focal length $f$ and then moves on a straight line, actually crosses the optical axis at a distance $L=f$ downstream of the lens. Hint: think a little extra about ordering of the matrices!
Set f=3 and numerically verify what you found in Exercise 4, namely that parallel rays cross the axis after a distance $L=f.$
Recall that the imaging equation for a lens is $1/b+1/g=1/f,$ which corresponds to a system of one focusing lens with focal length $f,$ sandwiched between drift spaces with length $g$ and $b,$ respectively. Write a beamline description that corresponds to this system. We will later return to it and analyze it.
Define a FODO beamline and prepare initial coordinates that describe a particle that is on the optical axis, but has an initial angle $x'$ and plot the position $x$ along the beam line.
Plot the position $x$ through 100 cells, play with different values of the focal length F and explore whether you can make the oscillations grow.
Use the beam line for the imaging system you prepared in Exercise 6 and launch a particle with $x_0=0$ and an angle of $x'_0=1\,$mrad at one end. Verify that this particle crosses the center of the beam pipe at the exit of the beam line, provided that $b,g,$ and $f$ satisfy the imaging equation that is shown in Exercise 6.
Define an ensemble of 1000 particles with an arbitrary first order ($x0$, $xpo$) and second order momenta( $x_{rms}$ and $x'_{rms}$) Verify the angular divergence of the beam is the one set.
Trasport the beam distribution of Exercise 12 in a drift of length 1 m. Compare the initial and final distribution.
Test of linearity. Scale the input vector by 17 times the month of your birthday (85 if you are born in May) and verify that the output vector from the matrix multiplication has changed by the same factor.
Now launch 3 particles such that they define a trianle of surface A. Verify that this linear trasport preserve the area of the tiangle.