\documentclass[a4paper,11pt]{article}
\parskip=1.5ex
\usepackage{a4margins,hyperref}

\newcommand{\dd}[2]{\frac{\mathrm d #1}{\mathrm d #2}}
\newcommand{\dds}[2]{\frac{\mathrm d^2 #1}{{\mathrm d #2}^2}}
\newcommand{\pdd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\pdds}[2]{\frac{\partial^2 #1}{\partial{#2}^2}}
\newcommand{\pddd}[3]{\frac{\partial^2 #1}{\partial #2\partial #3}}

\newcommand{\sq}[1]{\left(#1\right)^2}

\newcommand{\dx}{\delta x}
\newcommand{\dy}{\delta y}

\newcommand{\mtwo}[4]{\left[\begin{array}{cc}#1&#2\\#3&#4\end{array}\right]}
\newcommand{\vectwo}[2]{\left[\begin{array}{c}#1\\#2\end{array}\right]}
\newcommand{\detmtwo}[4]{\left|\begin{array}{cc}#1&#2\\#3&#4\end{array}\right|}

\newcommand{\ang}[1]{\langle#1\rangle}

\begin{document}

\title{Optical Function Evolution in Generalised FFAG Transfer Lines (in the Thin Lens Paraxial Approximation)}
\author{Stephen Brooks}
\maketitle

\section{Dynamics}\label{-dynamics}

This note uses some of the same notation as \cite{tunefix}, which is defined again in this section.  However, the goal here is to derive the optical functions $\beta_{x,y}$ and $\alpha_{x,y}$ in a transfer line, rather than determining or fixing the tunes of a periodic system.

The beamline consists of drifts of length $d_n$ for $1\le n\le N$, each followed by magnetic kicks defined by $b_n(x)$.  The horizontal phase space position before the first drift is $(x_0,x'_0)$, with later positions given by
\begin{eqnarray*}
x_n &=& x_{n-1} + d_n x'_{n-1}\\
x'_n &=& x'_{n-1} + p^{-1} b_n(x_n).
\end{eqnarray*}

In physical quantities, $b_n(x) = -B_{yn}(x,0)\ell q$ or alternatively $-B_{yn}(x,0)\ell q/p_0$ if using normalised $p$ with $p=1$ meaning the reference momentum $p_0$.

Considering a nearby particle that is at $(x_n+\dx_n,x'_n+\dx'_n)$ when the original is at  $(x_n,x'_n)$ gives the evolution of small variations:
\begin{eqnarray*}
\dx_n &=& \dx_{n-1} + d_n \dx'_{n-1} \\
\dx'_n &=& \dx'_{n-1} + p^{-1} b'_n(x_n) \dx_n.
\end{eqnarray*}

Vertical dynamics can be analysed as small perturbations $\dy$ from the midplane, incorporating the consequence of $\nabla \cdot \mathbf B=0$:
\begin{eqnarray*}
\dy_n &=& \dy_{n-1} + d_n \dy'_{n-1} \\
\dy'_n &=& \dy'_{n-1} - p^{-1} b'_n(x_n) \dy_n.
\end{eqnarray*}

\section{Beam Optical Functions}\label{-beam}
\newcommand{\s}{\mathbf s}
Define the phase space displacement from the centre of the beam $\s=(\dx,\dx')$ and consider the covariance matrix $C=\ang{\s\s^T}$, where angle brackets indicate averaging over all particles in the beam.  Under a linear mapping $\s \mapsto A\s$, the covariance matrix changes as $C \mapsto ACA^T$.  The RMS emittance is defined as $\epsilon=\sqrt{\det C}$ and the optical functions are defined as scaled elements of $C$:
\[ C = \epsilon\mtwo{\beta}{-\alpha}{-\alpha}{\gamma}. \]
The definition of $\epsilon$ ensures that the matrix on the right has a determinant of 1, so that $\beta\gamma-\alpha^2=1$, or $\gamma=(1+\alpha^2)/\beta$.  Thus the beam covariance matrix is entirely determined by $\epsilon$, $\alpha$ and $\beta$, with the emittance being the only thing that is affected by uniform scaling of the beam in phase space.  This discussion has considered the $(x,x')$ plane but optical functions also exist for the $(y,y')$ plane by defining $\s=(\dy,\dy')$ at the start.  The beta functions for the two planes are distinguished as $\beta_x$ and $\beta_y$ for example.

\subsection{Drift}
The phase space displacement after drift $d_n$ (but before the magnetic kick $b_n$) is 
\[ \vectwo{\dx_n}{\dx'_{n-1}} = \vectwo{\dx_{n-1} + d_n \dx'_{n-1}}{\dx'_{n-1}} = 
\mtwo{1}{d_n}{0}{1} \vectwo{\dx_{n-1}}{\dx'_{n-1}}, \]
so the drift has transfer matrix $A=\mtwo{1}{d_n}{0}{1}$.  The covariance matrix after the drift will be
\begin{eqnarray*}
ACA^T &=& \mtwo{1}{d_n}{0}{1} \epsilon\mtwo{\beta}{-\alpha}{-\alpha}{\gamma} \mtwo{1}{0}{d_n}{1} \\
&=& \epsilon\mtwo{\beta-d_n\alpha}{-\alpha+d_n\gamma}{-\alpha}{\gamma} \mtwo{1}{0}{d_n}{1} \\
&=& \epsilon\mtwo{\beta-2d_n\alpha+d_n^2\gamma}{-\alpha+d_n\gamma}{-\alpha+d_n\gamma}{\gamma}.
\end{eqnarray*}
The drift matrix $A$ (or any transfer matrix) does not change $\det C$ or $\epsilon$, so the new values of the optical functions can be found by equating entries:
\begin{eqnarray*}
\beta_\mathrm{drift}(d_n,\alpha,\beta) &=& \beta-2d_n\alpha+d_n^2\gamma = \beta-2d_n\alpha+d_n^2(1+\alpha^2)/\beta \\
\alpha_\mathrm{drift}(d_n,\alpha,\beta) &=& \alpha-d_n\gamma = \alpha-d_n(1+\alpha^2)/\beta.
\end{eqnarray*}

\subsection{Kick}
The phase space displacement after kick $b_n$ is 
\[ \vectwo{\dx_n}{\dx'_n} = \vectwo{\dx_n}{\dx'_{n-1} + p^{-1} b'_n(x_n) \dx_n} = 
\mtwo{1}{0}{p^{-1} b'_n(x_n)}{1} \vectwo{\dx_n}{\dx'_{n-1}}, \]
so the kick has transfer matrix $A=\mtwo{1}{0}{k}{1}$, where we define $k=p^{-1} b'_n(x_n)$.  The covariance matrix after the kick will be
\begin{eqnarray*}
ACA^T &=& \mtwo{1}{0}{k}{1} \epsilon\mtwo{\beta}{-\alpha}{-\alpha}{\gamma} \mtwo{1}{k}{0}{1} \\
&=& \epsilon\mtwo{\beta}{-\alpha}{k\beta-\alpha}{-k\alpha+\gamma} \mtwo{1}{k}{0}{1} \\
&=& \epsilon\mtwo{\beta}{k\beta-\alpha}{k\beta-\alpha}{k^2\beta-2k\alpha+\gamma}.
\end{eqnarray*}
Equating entries gives the new values of the optical functions:
\begin{eqnarray*}
\beta_\mathrm{kick}(k,\alpha,\beta) &=& \beta \\
\alpha_\mathrm{kick}(k,\alpha,\beta) &=& \alpha-k\beta.
\end{eqnarray*}
In terms of physical quantites, $k=-p^{-1}B'_{yn}(x_n,0)\ell q$ for the $(x,x')$ phase space plane and the negative of this for the $(y,y')$ plane.

\section{Optimisation}
\newcommand{\uu}{\mathbf u}
The problem is having multiple beams of different momenta going through multiple generalised magnets and trying to match both the beam trajectory and optical functions to a goal at the exit for each beam.  At a given point in the lattice, each beam is described to first order by the variables $\uu=(x,x',\beta_x,\alpha_x,\beta_y,\alpha_y,p)$, assuming that the beam centres do not leave the $y=0$ plane and emittance is an external constant (it does not affect the optics).  These groups of variables can be evolved through drifts and kicks in the lattice using the formulae in the previous two sections.  The momentum $p$ can be different per beam but does not change in value when going through magnetic lattice elements.

The initial conditions are a list of beams $\uu_{0i}$ at the start of the lattice, where $i$ ranges over all beams.  The goal is to achieve $\uu_{Ni}\simeq\hat\uu_i$ at the end of the lattice, where $N$ is the index of the final point in the transfer line and $\hat\uu_i$ is a list of ideal output beams.

\subsection{Figure of Merit}
This optimisation has multiple objectives: matching 6 parameters per beam.  Some optimisers work better when given a vector of all the objectives rather than a single figure of merit to minimise.  A suitable vector can be made out of difference vectors $\mathbf\Delta(\uu_{Ni},\hat\uu_i)$ between the output beams and the goals, where
\[ \mathbf\Delta(\uu,\hat\uu) = \left(\frac{x-\hat x}{X},\frac{x'-\hat x'}{\Theta},\ln\beta_x-\ln\hat\beta_x,\alpha_x-\hat\alpha_x,\ln\beta_y-\ln\hat\beta_y,\alpha_y-\hat\alpha_y\right). \]

Here, $X$ is a scale length (e.g. 1cm) and $\Theta$ a scale angle (e.g. 0.01rad) chosen to be about as `bad' as a unit mismatch in $\alpha$ or a factor of $e$ in $\beta$.  This is needed because some algorithms, such as those using SVD \cite{SVDnote}, do care about the relative size of the vector entries and try to minimise $\sum_i|\mathbf\Delta(\uu_{Ni},\hat\uu_i)|^2$. 

\begin{thebibliography}{9}   % Use for  1-9  references
%\begin{thebibliography}{99} % Use for 10-99 references

\bibitem{tunefix} \emph{Fixing the Tune of Nonscaling FFAGs in the Thin Lens Paraxial Approximation}, S.J.~Brooks, available from \url{http://stephenbrooks.org/ap/report/2010-5/tunefix.pdf} (2010).
\bibitem{SVDnote} \emph{Bounded Approximate Solutions of Linear Systems using SVD}, S.J.~Brooks, available from \url{http://stephenbrooks.org/ap/report/2015-3/svdboundedsolve.pdf} (2015).

\end{thebibliography}

\end{document}