9.1 Overview of Codes

Along with theoretical developments and polarized beam studies at the weak focusing synchrotron ZGS (polarized proton beams were produced from 1973) and at the strong focusing synchrotron Saturne 2 (proton and light ion beams, from 1981), a number of spin tracking techniques have been devised over the years along with the design and operation of polarized beam facilities.

Early computer codes were based on matrix transport techniques, two early instances were lattice design and spin dynamics studies for polarized ion beams at Saturne 2 and its synchrotron injector Mimas [1], for electron beams accounting for synchrotron radiation at SPEAR [2]. Numerical integration of the equations of motion was later resorted to and allowed solving spin motion in arbitrary fields, and to high order in particle coordinates, so allowing accurate treatment of spin motion in special devices such as snakes and in field maps [3, 4]. With the increased interest in polarized beams and the design and construction of accelerator facilities, a number of analytical methods have been developed and used in spin codes. Indications regarding possible spin dynamics capabilities of existing beam optics codes may be found in accelerator codes repositories [5, 6].

There are several direct spin-orbit tracking codes freely obtainable at the time of this writing. These can be categorized based on their method of numerical integration, order of accuracy, and also their inclusion of radiative effects necessary when considering electron spin tracking.

  • Bmad [7] is a Fortran 2008 platform which can make use of several different spin-orbit tracking algorithms. These include Runge-Kutta style and Symplectic PTC style orbit integrators. It reads lattices written using MAD like syntax and can be run exploiting multi-threading with certain restrictions. It is well documented and maintained. It has recently been used to help model several of the future Electron-Ion Collider lattices including the Electron Storage Ring and the Rapid Cycling Synchrotron.

  • COSY Infinity [8] uses a differential algebraic method to generate transfer maps for both orbit and spin. It accomplishes this by generating derivatives to arbitrary order using automatic differentiation [9]. It includes higher-order nonlinearities, normal form analysis, and symplectic tracking. It has been used for instance to support Electric Dipole Moment lattice simulations at COSY [10].

  • gpuSpinTrack: a symplectic drift-kick, bend-kick and matrix-kick integrator [11] (see Sect. 9.5).

  • SITROS [12] was used at the HERA e-p collider, it was developed in the early 1980s by Jorg Kewisch and updated in the 1990s and early 2000s. It tracks a group of electrons or positrons through the lattice and applies radiative kicks using a Monte-Carlo style algorithm to simulate the radiative effects on longitudinal dynamics and spin. It first performs orbital tracking to generate an equilibrium phase space distribution, later spin tracking is included. To speed up the tracking time transfer maps are developed for whole sections of the ring instead of tracking element by element. It is used today to model aspects of the spin dynamics and compute polarization life-time in the EIC Electron Storage Ring [13].

  • SPINK: a symplectic kick based first order integrator [14] (see Sect. 9.4).

  • SPRINT performs multi-turn spin-orbit tracking for linearized orbital motion, but fully nonlinear spin motion and all orders of resonance [15].

  • Zgoubi: Taylor based integrator, handles E and B fields, includes radiative effects. Degree of non-symplecticity inherent to truncated Taylor series is mostly controlled by the integration step size [16] (see Sect. 9.3).

Then there are several reduced spin tracking codes which integrate a reduced form the T-BMT equation. These include the codes SLIM [2, 17] and T-BMT [18].

In addition to direct spin-orbit tracking codes there are codes which calculate the spin resonances for a given energy range based on the optics for an accelerator lattice. These include DEPOL [19], ASPIRRIN [20] and SPRINT [21].

To illustrate the general approaches for numerical integration, we explore the three codes Zgoubi, SPINK and gpuSpinTrack in more detail in the following sections. DEPOL and T-BMT are also addressed in dedicated sections.

9.2 Integration of the Spin and Orbit

As we learned in previous chapters the dynamics of the spin vector of a charged particle in the laboratory frame is described by the T-BMT equation,

$$\displaystyle \begin{aligned} \frac{ \mathrm{d} \mathbf S }{\mathrm{d } t} = \frac{q}{\gamma m}\mathbf S \times \left( (1+G\gamma)\mathbf B_{\perp}+(1+G)\mathbf B_{\parallel} + \left( \dfrac{1}{\gamma +1} +G \right)\gamma \dfrac{\mathbf E \times \mathbf \beta}{c} \right) {}\end{aligned} $$
(9.1)

S is the spin vector in the rest frame of the particle, E and B are fields in the laboratory, the magnetic field components B and B are defined with respect to the particle’s velocity. \( G = \frac {g-2}{2} \) is the anomalous magnetic moment coefficient which for protons is 1.7928474, and γmc2 is the energy of the particle. We can transform this equation by expanding about a reference orbit described by a Frénet-Serret coordinate system. See Fig. 9.1. Thus we have

$$\displaystyle \begin{aligned} \frac{ \mathrm{d} \hat x } {\mathrm{d} s} = \frac{\hat s}{\rho}, \quad \frac{ \mathrm{d} \hat s} { \mathrm{d} s}=-\frac{\hat x } {\rho}, \quad \text{and} \quad \frac{ \mathrm{d} \hat z} { \mathrm{d} s} =0, {} \end{aligned} $$
(9.2)

Particle motion can be parameterized in this coordinate system as

$$\displaystyle \begin{aligned} \mathbf r= \mathbf r_{0}(s)+x \hat x + z \hat z, {} \end{aligned} $$
(9.3)

where r0(s) is the reference orbit, and \(\hat s = \mathrm {d} \mathbf r_{0}/ \mathrm {d} s \).

Fig. 9.1
A diagram of the curvilinear coordinate system in a circular accelerator. The circle represents the reference orbit. From the origin, the line r o directs toward the vertical line Z. From the edge of a circle, the line represents x, and the dashed line forms an irregular rectangle shape. An arrow towards the left represents V.

The curvilinear coordinate system for particle motion in a circular accelerator. The unit vectors \(\hat x\), \(\hat s\) and \(\hat z\) are the transverse radial, longitudinal, and transverse vertical basis vectors; and r0(s) is the reference orbit

The integration of the T-BMT equation requires the knowledge of the spatial dependence of the fields, which in turn depend on the trajectory of the charged particle in the optical elements. A particle traversing a quadrupole magnet off axis will experience a different magnetic field than one going through the center. We calculate this trajectory by integrating the Lorentz force equation.

$$\displaystyle \begin{aligned} \frac{ \mathrm{d} \mathbf p}{ \mathrm{d} t} = q \left(\mathbf E + \mathbf v \times \mathbf B \right) \end{aligned} $$
(9.4)

This is the job which all accelerator codes need to accomplish and to do this they use several standard approaches:

  • Non-symplectic approaches. They typically use a Runge-Kutta type algorithm or a ray tracing method which use the mechanics of a Taylor expansion of the equations of motion.

  • Symplectic Methods. These include both thin lens-kick and thick lens integrators.

9.3 Zgoubi

Step-wise ray-tracing has accompanied accelerator design concurrently with the emergence of computers and magnetic field simulations in the early 1950s, with Runge-Kutta being one of the early methods [22]. Step-wise integration of the orbital motion allows the necessary accuracy for solving the Thomas-BMT differential equation. This is especially important in small rings where lattice optics field perturbations matter, and in beam transport lines which may include special magnets and fancy spin manipulations; these were the main reasons why step-wise spin tracking were developed in the late 1980s in Zgoubi (originally a spectrometer code) in the context of partial snake plans at Saturne [3], and in Raytrace [23] (a spectrometer code as well) at the AGS for polarized beam transport in AGS and RHIC facility transfer lines [4]. A serendipity of step-wise integration is its yielding 6D motion ab initio as it handles the three components of the position and velocity vectors, independently.

Zgoubi has been in use since the early 2000s at RHIC [24] and its injectors [25, 26], and at present for spin simulations in the EIC electron machines [27, 28]. Preservation of motion invariants, in relation with the truncated Taylor series integration method, is controlled over millions of turns in RHIC size EIC rings, via step size mostly.

In order to integrate the Lorentz equation (m is the particle mass, q its charge, v the velocity, e and b the local electric and magnetic fields)

$$\displaystyle \begin{aligned} \dfrac{ \mathrm{d}(\gamma m\mathbf v)}{ \mathrm{d} t} = q\, (\mathbf e + \mathbf v \times \mathbf b) {} \end{aligned} $$
(9.5)

we rewrite it by nothing that \(()' = \dfrac {d()}{ds} \), \(\mathbf u = \dfrac {\mathbf v }{v}\), ds = v dt, γmv = γmvu = q B ρ u, and B ρ the rigidity of the particle,

$$\displaystyle \begin{aligned} ({B\!\rho} )^\prime \, \mathbf u +{B\!\rho} \,\mathbf u^{\,\prime} = \dfrac{\mathbf e }{v} + \mathbf u \times \mathbf b, {} \end{aligned} $$
(9.6)

Zgoubi uses truncated Taylor developments of the position R and normalized velocity u vectors, namely,

$$\displaystyle \begin{aligned} \mathbf R(M_1) & \approx \mathbf R(M_0) + \mathbf u(M_0)\, \Delta s+ \mathbf u^{\,\prime} (M_0)\, \dfrac{\Delta s^2 }{2!} + ...+ \mathbf u^{\,\prime\prime\prime\prime\prime} (M_0)\, \dfrac{\Delta s^6 }{6!} \\ \mathbf u(M_1) & \approx \mathbf u(M_0) + \mathbf u^{\,\prime} (M_0)\,\Delta s + \mathbf u^{\,\prime\prime} (M_0)\, \dfrac{\Delta s^2 }{2!} + ...+ \mathbf u^{\,\prime\prime\prime\prime\prime} (M_0)\, \dfrac{\Delta s^5 }{5!} \end{aligned} $$
(9.7)

In these series R(M0) and u(M0) are the initial conditions, at point M0, R(M1) and u(M1) are one integration step Δs ahead, at point M1 (Fig. 9.2). The rigidity varies in the presence of electric field, it is calculated the same way using

$$\displaystyle \begin{aligned} ({B\!\rho} )(M_1) \approx ({B\!\rho} )(M_0)+({B\!\rho} )^\prime (M_0)\Delta s+...+ ({B\!\rho})^{\,\prime\prime\prime\prime\prime} (M_0) \dfrac{\Delta s^5 }{5!} {}\end{aligned} $$
(9.8)

The time of flight is expanded in a similar manner

$$\displaystyle \begin{aligned} T(M_1) \approx T(M_0) + T' (M_0)\, \Delta s+ T'' (M_0)\,\dfrac{\Delta s^2}{2} + ~ ... ~ + T^{\,\prime\prime\prime\prime\prime} (M_0)\,\dfrac{\Delta s^5}{5!} {}\end{aligned} $$
(9.9)

which simplifies to T(M1) = T(M0) +  Δsv in the absence of electric field.

Fig. 9.2
A diagram of Zgoubi reference frame illustrates the position and velocity of a particle position. A right-angle triangle of Z versus X at the bottom has three straight lines passing from the origin, such as R vector M 0, R vector M 1, and Y. The right-angle triangle at the top has lines of u vector M 0 and y, respectively from the origin. From the origin of the top right-angle triangle delta s curve passes through the M 1 line and an arrow at the top represents the u vector M 1.

Position and velocity of a particle in Zgoubi reference frame

The derivatives \(\mathbf u^{(n)} = \dfrac {d^n\mathbf u}{ds^n}\) and \( ({B\!\rho } )^{(n)} = \dfrac {d^n({B\!\rho } )}{ds^n} \) involved in these expressions are calculated by recursive differentiation of Eq. 9.6, details can be found in the Users’ Guide [16].

Spin in Zgoubi is evaluated in the same manner as the particle, with the three spin vector components treated independently. The T-BMT equation is recast as,

$$\displaystyle \begin{gathered} \dfrac{d\mathbf S }{ dt} = \dfrac{q }{ m \gamma } \, \mathbf S\times\mathbf \omega {} \end{gathered} $$
(9.10)

with, in the laboratory frame,

$$\displaystyle \begin{gathered} \mathbf \omega = (1+\gamma G)\mathbf b - G(\gamma -1 )\mathbf b_{\parallel } + \gamma(G + \dfrac{1}{1+\gamma}) \dfrac{\mathbf e \times \mathbf v}{c2} {} \end{gathered} $$
(9.11)

wherein b and e are the fields in the laboratory, b is the component of b parallel to the velocity v of the particle. Equation (9.10) is normalized by introducing again v = ||v||, v = vu, ds = vdt the differential path, \( \dfrac {\gamma mv }{ q} = {B\!\rho } \) the rigidity of the particle, whereas b =∥b ∥, \( \mathbf S^{\,\prime } = \dfrac {d\mathbf S }{ ds} = \dfrac {1 }{ v}\dfrac {d\mathbf S }{ dt} \) is the derivative of the spin with respect to the path. This yields

$$\displaystyle \begin{aligned} (B\rho) \, \mathbf S^{\,\prime} = \mathbf S \times \mathbf \omega ~ ~ ~ ~ ~ \mathrm{or} ~ ~ ~ ~ \mathbf S^{\,\prime} = \mathbf S \times \mathbf \Omega {} \end{aligned} $$
(9.12)

where, noting B = bB ρ, E = eB ρ,

$$\displaystyle \begin{aligned} \mathbf \Omega = \dfrac{\mathbf \omega }{ {B\!\rho}} = (1+\gamma G)\mathbf B + G(1-\gamma )\mathbf B_{\parallel } + \dfrac{\beta \gamma}{c} \left( G + \dfrac{1}{1+\gamma} \right) \mathbf E \times \mathbf u {} \end{aligned} $$
(9.13)

From the initial conditions Ω(M0) and S(M0) of the particle at position M0, the spin S(M1) at position M1, following a displacement Δs (Fig. 9.2), is obtained from the truncated Taylor expansion

$$\displaystyle \begin{aligned} \mathbf S(M_1) \approx \mathbf S(M_0)+ \mathbf S' (M_0)\, \Delta s + \mathbf S'' \,(M_0) \dfrac{\Delta s^2 }{ 2!} + \ ... \ + \mathbf S'''''\, (M_0) \dfrac{\Delta s^5 }{ 5!} {} \end{aligned} $$
(9.14)

The spin vector S and its derivatives S(n) = dnSdsn are obtained by recursive differentiation of Eq. 9.12, details in the Users’ Guide [16].

9.4 SPINK

SPINK code was developed in the 1990s by Alfredo Luccio and used to extensively model the RHIC machine which was being built at the time. It employed the linear transport matrices from the MAD8 code to track the orbit, estimating the position of the charged particles inside each magnet and thus deducing the field. Beginning from the T-BMT equation:

$$\displaystyle \begin{aligned} \frac{ \mathrm{d} \mathbf S}{ \mathrm{d} t} = \frac{e}{\gamma m} \mathbf S \times \mathbf F \end{aligned} $$
(9.15)

now with F defined as (we now assume no electric field)

$$\displaystyle \begin{aligned} \mathbf F = (1+G\gamma) \mathbf B_{\perp} + (1+G)\mathbf B_{\parallel} \end{aligned} $$
(9.16)

and with the perpendicular and parallel components of the magnet field expressed as,

$$\displaystyle \begin{aligned} \mathbf B_\perp = \frac{1}{v^2} (\mathbf v\times\mathbf B) \times \mathbf v, \quad \mathbf B_\parallel = \frac{1}{v^2} (\mathbf v\cdot\mathbf B) \mathbf v, {} \end{aligned} $$
(9.17)

F can be expressed as,

$$\displaystyle \begin{aligned} \mathbf F = (1+G\gamma)\mathbf B - G(\gamma - 1)\frac{1}{v^2} (\mathbf \cdot \mathbf B)\mathbf v \end{aligned} $$
(9.18)

As discussed in previous sections the velocity vector can be expressed in terms of the derivative of the spatial coordinates with respect to the longitudinal coordinate s to obtain:

$$\displaystyle \begin{aligned} \mathbf v = \frac{ \mathrm{d} \mathbf r}{ \mathrm{d} t} = \left [ x^{\prime} \hat {\mathbf x }+ y^{\prime} \hat{\mathbf y} + ( 1 + \frac{x}{\rho} \hat {\mathbf z} \right ] \frac{ \mathrm{d} s}{ \mathrm{d} t} \end{aligned} $$
(9.19)

One can now rewrite the T-BMT equation as an s derivative,

$$\displaystyle \begin{aligned} \frac{ \mathrm{d} \mathbf S}{ \mathrm{d} s} = \mathbf S \times \mathbf \Omega {} \end{aligned} $$
(9.20)

with,

$$\displaystyle \begin{aligned} \mathbf \Omega = \frac{ h}{B\rho} \left [ (1 + G\gamma)\mathbf B - G(\gamma -1)(\mathbf r^{\prime} \cdot \mathbf B)\mathbf r^{\prime} \right ] \end{aligned} $$
(9.21)

and,

$$\displaystyle \begin{aligned} \begin{array}{rcl} \frac{e}{\gamma m} & =&\displaystyle \frac{v}{B\rho} \\ h & =&\displaystyle \sqrt{x^{\prime 2}+ y^{\prime 2} + (1 + x/\rho)^2} \\ \mathbf r^{\prime} & = &\displaystyle \frac{\mathbf v}{v}. \end{array} \end{aligned} $$
(9.22)

Using this the T-BMT equation can be reduced to a third order differential equation,

$$\displaystyle \begin{aligned} \mathbf S^{\prime \prime \prime} + \omega(s)^2 \mathbf S^{\prime} = 0 \end{aligned} $$
(9.23)

where,

$$\displaystyle \begin{aligned} \omega(s)^2 = \Omega_x(s)^2 + (\Omega_y(s)-\frac{1}{\rho(s)})^2 + \Omega_z(s)^2 \end{aligned} $$
(9.24)

In the case that both the fields and orbits are constant across a given portion of the magnet then ω(s) would likewise be constant and solutions in the form of transport matrices can be developed yielding,

$$\displaystyle \begin{aligned} \begin{array}{rcl} \left ( {\begin{array}{ccc} 1 - (B^2 + C^2)c & ABc + Cs & ACc-Bs \\ ABc-Cc & 1-(A^2+C^2)c & BCc+As \\ ACc + Bs & BCc-As & 1 - (A^2+B^2)c\\ \end{array}} \right ) \end{array} \end{aligned} $$
(9.25)

with

$$\displaystyle \begin{aligned} \begin{array}{rcl} c = 1 - \cos{\omega \delta s}\,\, ,s=\sin{\omega \delta s} \\ A=\frac{\Omega_x}{\omega} \ , B = \frac{\Omega_y - 1/\rho}{\omega} \,\,, C=\frac{\Omega_z}{\omega} \end{array} \end{aligned} $$
(9.26)

9.4.1 Bends

Applied to the case of the rectangular bend magnet with Bx = Bz = 0 and By = ρ one obtains the matrix,

$$\displaystyle \begin{aligned} \begin{array}{rcl} \left ( {\begin{array}{ccc} \cos{\delta \psi} & 0 & \sin{\delta \psi} \\ 0 & 1 & 0 \\ -\sin{\delta \psi} & 0 & \cos{\delta \psi}\\ \end{array}} \right ). \end{array} \end{aligned} $$
(9.27)

This represents a rotation about the vertical axis through an angle of,

$$\displaystyle \begin{aligned} \delta \psi = \omega \delta s = \left [ G\gamma - (1+G\gamma)\frac{x}{\rho}) \right ]\delta \theta \end{aligned} $$
(9.28)

with δθ = δsρ the bend angle.

9.4.2 Quadrupoles

For the quadrupole with a gradient of k1 the fields become Bx = k1Bρy, By = k1Bρx and Bz = 0 with \(\frac {1}{\rho } = 0\). In this case the transport matrix becomes,

$$\displaystyle \begin{aligned} \begin{array}{rcl} \frac{1}{r^2} \left ( {\begin{array}{ccc} y^2+x^2 \cos{\delta \psi} & xy(1-\cos{\delta \psi}) & -xr\sin{\delta \psi} \\ xy(1-\cos{\delta \psi}) & y^2+x^2 \cos{\delta \psi} & yr\sin{\delta \psi} \\ xr\sin{\delta \psi} & -yr\sin{\delta \psi} & \cos{\delta \psi}\\ \end{array}} \right ) \end{array} \end{aligned} $$
(9.29)

with ω = k1(1 + )r and \(r=\sqrt {x^2+y^2}\)

SPINK made use of the MAD8 generated Twiss functions to calculate the transport matrices and thus coordinates at the beginning and exit of each element. It takes the average of the position between the beginning and end of each sliced transport element to estimate the field that acts on the spin. The accuracy of the solution is controlled by increasing the number of slices in MAD8.

9.5 gpuSpinTrack

gpuSpinTrack was developed from a version of SPINK which uses a native teapot integrator called UAL-SPINK. It reads lattices formatted in the SXF style. The development of gpuSpinTrack was motivated by problems with convergence using the drift and thin kick style teapot orbit integrator. As a result a new orbit integrator was developed which is detailed in [11]. It was observed that when crossing strong spin resonance in the presence of snakes, the highly accurate rendering of the orbital trajectory through the quadrupoles was essential to achieve convergence with a reasonable number of slices.

9.5.1 How to Integrate the Quadrupole?

The Hamiltonian for quadrupole is given by,

$$\displaystyle \begin{aligned} \begin{array}{rcl} H_Q & =&\displaystyle H_D(P_t,P_x,P_y) + H_K(X,Y) \\ H_D(P_t,P) & = &\displaystyle - \sqrt{1+\frac{2}{\beta_0}P_t + P_t^2 - P_x^2 - P_y^2} + \frac{1}{\beta_0} P_t \\ H_K(X,Y) & =&\displaystyle \frac{k_1}{2} \left ( X^2-Y^2 \right ). \end{array} \end{aligned} $$
(9.30)

Here \(P_t=\frac {\gamma -\gamma _0}{\beta _0 \gamma _0}\) with subscript 0 indicating on-momentum values for the relativistic gamma and beta and k1 the quadrupole gradient. The usual teapot approach is to split this Hamiltonian into HD for the drift and HK for the kick. The effect of each of these pieces can be exactly evaluated yielding a drift transport matrix and a thin kick part. The drifts are then split in half and sandwiched around the thin kick. An improved approach which yields higher accuracy is to split the Hamiltonian in a different way, by adding and subtracting as follows,

$$\displaystyle \begin{aligned} \begin{array}{rcl} H_M & = &\displaystyle \frac{1}{2} \left ( P_x^2+P_y^2 \right ) + \frac{k_1}{2} \left ( X^2-Y^2 \right ) \\ H_K & = &\displaystyle - \sqrt{1+\frac{2}{\beta_0}P_t + P_t^2 - P_x^2 - P_y^2} + \frac{1}{\beta_0} P_t -\frac{1}{2} \left ( P_x^2+P_y^2 \right ) \end{array} \end{aligned} $$
(9.31)

Here we add and subtract \(\frac {1}{2} \left ( P_x^2+P_y^2 \right )\) from each term to create a matrix transport HM. gpuSpinTrack additionally divides the momentum term by the energy contribution to momentum to get the correct tunes for the off energy particles yielding,

$$\displaystyle \begin{aligned} \begin{array}{rcl} H_M & = &\displaystyle \frac{1}{2} \frac{ P_x^2+P_y^2 }{\sqrt{1+\frac{2}{\beta_0}P_t + P_t^2}} + \frac{k_1}{2} \left ( X^2-Y^2 \right ) \\ H_K & = &\displaystyle - \sqrt{1+\frac{2}{\beta_0}P_t + P_t^2 - P_x^2 - P_y^2} + \frac{1}{\beta_0} P_t -\frac{1}{2} \frac{ P_x^2+P_y^2 }{\sqrt{1+\frac{2}{\beta_0}P_t + P_t^2}} \end{array} \end{aligned} $$
(9.32)

9.5.2 Spin Precession Calculation

With the orbit the spin transport can be calculated across a given element slice as was done in the original SPINK code. However gpuSpinTrack accelerates computation and the spin convergence by making use of Romberg quadrature with quaternions to represent the spin transport using SPINK Ω. The approach is to calculate the quaternions for q(h Ω) for different relative step sizes h across a given magnetic element as follows,

$$\displaystyle \begin{aligned} \begin{array}{rcl} R_{0,2}=Q(h) & = &\displaystyle q(\frac{1}{2}h \mathbf \Omega_4)q(h \mathbf \Omega_3)q(h \mathbf \Omega_2) q(h \mathbf \Omega_1) q(\frac{1}{2} \mathbf \Omega_0) \\ R_{0,1}= Q(2h) & = &\displaystyle q(h \mathbf \Omega_4) q(2 h \mathbf \Omega_2) q(h \mathbf \Omega_0) \\ R_{0,0}= Q(4h) & = &\displaystyle q(2 h \mathbf \Omega_4) q(2 h \mathbf \Omega_0). \end{array} \end{aligned} $$
(9.33)

Here Ωi represents the calculated spin precession vector at a given slice across the magnetic element (see Fig. 9.3). With this, one can construct a ‘bootstrapped’ quaternion across the whole element to arbitrary order using,

$$\displaystyle \begin{aligned} R_{j+1,k} = \frac{4^{j+1}R_{j,k}-R_{j,k-1}}{4^{j+1}-1} \end{aligned} $$
(9.34)
Fig. 9.3
A diagram consists of four square-shaped blocks. Each vertical line has an arrow pointing upwards attached to it representing the spin precession vector. They are labeled vector omega subscript 0, vector omega subscript 1, vector omega subscript 2, vector omega subscript 3, and vector omega subscript 4 from left to right, respectively. Vector omega subscript 0 and vector omega subscript 1 point towards the inside, and the distance h represents the orbital slice. Vector omega sub 2 and vector omega subscript 3 point towards the inside.

Slicing up magnetic element for Romberg integration

9.6 How to Integrate the T-BMT Equation by Hand

Aside from numerical integration, it is possible to integrate certain forms of it analytically. Beginning with Eq. 9.20 in the absence of solenoid magnets and vertical bends, the T-BMT equation can, to first order in the coordinates (x, s, z), be rewritten as (see Exercise 9.10).

$$\displaystyle \begin{aligned} \begin{array}{rcl} \frac{ \mathrm{d} \mathbf S}{ \mathrm{d} s} & \approx &\displaystyle v \left ( \frac{ \mathrm{d} t}{ \mathrm{d} s} \right ) \mathbf S \times \mathbf \Omega \approx \mathbf S \times \mathbf \Omega \\ \Omega_x & =&\displaystyle -(1+ G\gamma) z^{\prime\prime} \\ \Omega_s & =&\displaystyle (1+G\gamma) z^{\prime}/\rho - (1+G) \left ( \frac{z}{\rho} \right )^{\prime} \\ \Omega_z & = &\displaystyle x^{\prime \prime}(1+G\gamma) - \frac{1+G\gamma}{\rho} \end{array} \end{aligned} $$

Further, Accounting for the derivatives of the x, s, z basis vectors of S we can obtain,

$$\displaystyle \begin{aligned} \begin{array}{rcl} \frac{ \mathrm{d} S_x}{ \mathrm{d} s } & =&\displaystyle S_s ( \Omega_z + 1/\rho) - \Omega_s S_z \\ \frac{ \mathrm{d} S_s}{ \mathrm{d} s } & =&\displaystyle -S_x ( \Omega_z + 1/\rho) + \Omega_x S_z \\ \frac{ \mathrm{d} S_z}{ \mathrm{d} s } & =&\displaystyle S_x \Omega_s - \Omega_x S_s \end{array} \end{aligned} $$

If we change to a basis vector which rotates with the beam \( ( \hat e_1, \hat e_2 , \hat e_3 )\) we obtain,

$$\displaystyle \begin{aligned} \frac{ \mathrm{d} \mathbf S}{ \mathrm{d} s} &= \mathbf \omega \times \mathbf S, \\ \omega_1 &= (1+ G\gamma) z^{\prime\prime}, \\ \omega_2 &= - (1 + G\gamma) z^{\prime}/\rho + (1 + G) \left(\frac{z}{\rho}\right)^{\prime}, \\ \omega_3 &= - (1 + G\gamma) x^{\prime\prime} + \frac{G\gamma}{\rho}. \end{aligned} $$
(9.35)

This can be further transformed by defining a two-component spinor Ψ such that the j-th component of the spin vector is given by

(9.36)

Here Ψ denotes a classical vector with components u and d, which are related to the three components of S by

(9.37)

Using σ = (σx, σs, σz), the vector of the Pauli spin matrices, and ζ(s) = −ω1 + iω2, it is possible to show (see Exercise 9.10) that Eq. 9.35 can be transformed into,

(9.38)

where we have dropped the first term in ω3, − (1 + )x′′, since it is small compared to .

Using the differential relation , one may transform (9.38) so as to make θ the independent variable. Then, considering the effects of a single resonance, wherein ζ(θ) becomes 𝜖Ke−i, the T-BMT equation becomes

$$\displaystyle \begin{aligned} \frac{\mathrm{d}\Psi}{\mathrm{d}\theta} = -\frac{\mathrm{i}}{2} \begin{pmatrix} G\gamma & -\epsilon_K e^{-\mathrm{i} K\theta} \\ -\epsilon_K^{*} e^{\mathrm{i} K\theta} & -G\gamma \end{pmatrix} \Psi. {}\end{aligned} $$
(9.39)

If we assume  = constant, and transform the spinor equation (9.39) into the resonance precessing frame by defining

$$\displaystyle \begin{aligned} \Psi_K(\theta) = e^{\frac{i}{2}K \theta \sigma_z} \Psi(\theta).\end{aligned} $$
(9.40)

one can obtain (see Exercise 9.10),

$$\displaystyle \begin{aligned} \frac{\mathrm{d}\Psi_K}{\mathrm{d}\theta} = \frac{\mathrm{i}}{2} \begin{pmatrix} K - G\gamma & \epsilon_K \\ \epsilon_K^{\ast} & G\gamma - K \end{pmatrix} \Psi_K. {} \end{aligned} $$
(9.41)

Since all the elements of the matrix are constant one can simply exponentiate the matrix directly to obtain an exact solution to the differential equation. In the case when is not constant, but linearly accelerating, a solution is still possible and ultimately yields the famous Froissart-Stora formula.

In the case when  = 0 + αθ we can transform the spinor equation into the spin precessing frame by defining,

$$\displaystyle \begin{aligned} \Psi(\theta) = e^{-\frac{i}{2} \int_o^{\theta} G\gamma(x) dx \sigma_3 }\Psi_I(\theta) \end{aligned} $$
(9.42)

to obtain,

$$\displaystyle \begin{aligned} \frac{\mathrm{d}\Psi_I}{\mathrm{d}\theta} = \frac{\mathrm{i}}{2} \begin{pmatrix} 0 & \epsilon_K e^{i[(G\gamma_0-K)\theta + \frac{1}{2}\alpha \theta^2]} \\ \epsilon_K^{\ast}e^{-i[(G\gamma_0-K)\theta + \frac{1}{2}\alpha \theta^2]} & 0 \end{pmatrix} \Psi_I. {} \end{aligned} $$
(9.43)

which can be transformed into an ordinary second order homogeneous differential equation,

$$\displaystyle \begin{aligned} \frac{\mathrm{d^2}\Psi_I^{\pm}}{\mathrm{d}\theta^2} \mp i \alpha \theta \frac{\mathrm{d}\Psi_I^{\pm}}{\mathrm{d}\theta}+ \frac{|\epsilon_K|{}^2}{4} \Psi_I^{\pm} = 0 \end{aligned} $$
(9.44)

which has confluent hyper-geometric functions as solutions. Using the asymptotic expressions of these functions it is possible to show that, in the limit of large |θ|,

$$\displaystyle \begin{aligned} S_z = 2 e^{-\frac{\pi |\epsilon_K|{}^2}{2 \alpha}} -1 \end{aligned} $$
(9.45)

which is the famous Froissart-Stora formula.

9.7 Calculating Spin Resonances

One of the first codes to calculate the strength of the intrinsic and imperfection spin resonance strength was developed by Ruth and Courant in 1980 and is known as DEPOL [19]. This code calculates the expansion of ζ(s) by making use of the linear transport matrix to derive an exact solution to the elements of the quasi Fourier integral,

$$\displaystyle \begin{aligned} \epsilon_K = -\frac{1}{2 \pi N_T} \int_0^{C N_T} \left [(1+G\gamma)(z^{\prime \prime} + \frac{i z^{\prime}}{\rho}) - i \rho (1 + G)(\frac{z}{\rho})^{\prime} \right ] e^{iK\theta(s)} \mathrm{d} s \end{aligned} $$
(9.46)

Here C is the circumference of the ring. The number of turns NT depends on the rationality of K. If K is an integer then NT = 1; however if K is an irrational number then we normally would need an infinite number of turns to approximate the resonance strength. Decomposing the integral into a sum of integrals over each element we obtain,

$$\displaystyle \begin{aligned} \begin{array}{rcl} \epsilon_K & = &\displaystyle \sum_{lattice} \frac{\epsilon_{K_m}}{N_T} \\ \epsilon_{K_m} & = &\displaystyle -\frac{1}{2 \pi } \int_{s_1}^{s_2} \left [(1+G\gamma)(z^{\prime \prime} + \frac{i z^{\prime}}{\rho}) - i \rho (1 + G)(\frac{z}{\rho})^{\prime} \right ] e^{iK\theta(s)} \mathrm{d} s \end{array} \end{aligned} $$
(9.47)

Assuming that 1∕ρ is a step function, constant in the element and zero just outside of the element, partial integration leads to an intermediate form,

$$\displaystyle \begin{aligned} \begin{array}{rcl} \epsilon_{K_m} & = &\displaystyle \frac{1}{2 \pi} \left [ \frac{(1+K)(\chi_1 + i)}{\rho} z_1 e^{i K \theta_1} + \frac{(1+K)(\chi_2 - i)}{\rho} z_2 e^{i K \theta_2} - \right . \\ & &\displaystyle \left . (1+K)\int_{s_1}^{s_2} z^{\prime \prime} e^{iK\theta} \mathrm{d} s - \frac{K}{\rho^2}(K-G)\int_{s_1}^{s_2}ze^{iK\theta}ds \right ] \end{array} \end{aligned} $$
(9.48)

Here χi is the contribution due to edge focusing of the magnet and zi = z(si). Applying partial integration to the last two terms yields,

$$\displaystyle \begin{aligned} \begin{array}{rcl} \epsilon_{K_m} & = &\displaystyle \frac{1}{2 \pi} \left [ \frac{(1+K)(\chi_1 + i)}{\rho} z_1 e^{i K \theta_1} + \frac{(1+K)(\chi_2 - i)}{\rho} z_2 e^{i K \theta_2} - \right . \\ & &\displaystyle \left . -(1+K)\left [ (z_2^{\prime} - \frac{iK}{\rho}z_2)e^{iK\theta_2} - (z_1^{\prime} - \frac{iK}{\rho}z_1)e^{iK\theta_1} \right ] + (\frac{K(K^2+G)}{\rho^2})\int_{s_1}^{s_2}ze^{iK\theta} \mathrm{d} s \right ] \end{array} \end{aligned} $$
(9.49)

In the uncoupled case the last term can be evaluated exactly using the homogeneous equation z′′ = −Kzz, where Kz(s) is the focusing function of the guide field. Substitution and integration by parts yields,

$$\displaystyle \begin{aligned} \int_{s_1}^{s_2} z e^{i K \theta} \mathrm{d} s = \frac{(z^{\prime}_2 - \frac{i K}{\rho} z_2)e^{iK\theta_2} - (z^{\prime}_1 - \frac{iK}{\rho}z_1)e^{i K \theta_1}}{K_z -K^2/\rho^2}. \end{aligned} $$
(9.50)

DEPOL uses Courant-Snyder parameters from the MAD output files to construct the z1,2 and \(z_{1,2}^{\prime }\) values. In calculating the resonance integral, one can factor out the phases which change with each period around the lattice. The remaining elements in the sum remain constant for each pass. This permits the evaluation of the integral over just one pass.

Later other more general algorithms have been developed to calculate spin resonances for arbitrary spin orientation [29]. Currently there exists the SPRINT [21] code which also can perform these calculations. As well an extension to the DEPOL algorithm was developed to handle resonance calculations in the case of linear betatron coupling. More recently the code ASPIRRIN [20] was developed to calculate spin resonances in the presence of snakes.

9.8 Integration of the Spinor T-BMT Equation for Many Resonances

In the case that one wants to include the effects of two resonances an analytical approximation has been derived [30], which makes use of the fact that the spinor form of the T-BMT equation can be expressed as a parametric oscillator. However these expressions are long and unwieldy. They do however permit the identification of regions in θ where the system can be approximated using only the single dominant resonance outside of the parametric resonance tongues.

In the case that one has more than two resonances, then numerical methods should be used. The T-BMT c++ method performs this integration using a 4th order Magnus Gaussian quadrature. With the spinor T-BMT equation expressed compactly as,

$$\displaystyle \begin{aligned} \begin{array}{rcl} \mathbf \Psi^{\prime} = \mathbf A(\theta) \mathbf \Psi , \, \, \, \mathbf \Psi(\theta_0) = \mathbf \Psi_0 \end{array} \end{aligned} $$
(9.51)

it evaluates A(θ) at two orbital locations \(\theta + (\frac {1}{2} \pm \frac {\sqrt {3}}{6})h\) with step size h:

$$\displaystyle \begin{aligned} \begin{array}{rcl} A_1 & =&\displaystyle A \left [ \theta_n + \left (\frac{1}{2} - \frac{\sqrt{3}}{6} \right ) h \right ] \\ A_2 & =&\displaystyle A \left [ \theta_n + \left (\frac{1}{2} + \frac{\sqrt{3}}{6} \right ) h \right ]. \end{array} \end{aligned} $$
(9.52)

These are then used to calculate the Ω used to propagate the spinor:

$$\displaystyle \begin{aligned} \begin{array}{rcl} \mathbf \Omega^{[4]}(h) & = &\displaystyle \frac{h}{2}(A_1 + A_2) - h^2 \frac{\sqrt{3}}{12}[A_1,A_2] \\ \mathbf \Psi_{n+1} & = &\displaystyle e^{\mathbf \Omega^{[4]}(h)} \mathbf \Psi_n \end{array} \end{aligned} $$
(9.53)

Here we use the identity,

$$\displaystyle \begin{aligned} e^{i \mathbf a \cdot \mathbf \sigma} = \cos{|a|}I + i \sin{|a|} \frac{\mathbf a \cdot \mathbf \sigma}{|a|} \end{aligned} $$
(9.54)

to generate the two-by-two complex matrix to transport the spinors. To reduce the number of integration steps necessary, the T-BMT code transforms first to the interaction frame before performing the 4th order Magnus Gaussian quadrature.

9.9 Initialization of Spinors

For any realistic spin tracking it is necessary to initialize the spinors to the invariant spin field (ISF) before tracking. For most lower energy machines the ISF trivially points vertically along the dominant dipole guide field. In these cases initialization involves setting the spinor to point vertically up or down. However at higher energies or with machines having more complex guide fields the ISF can assume a very complex and spread-out structure as shown in Fig. 9.4. If the spinors are not initially aligned with the ISF then they will execute a precession around the local ISF. This will make it appear that there is a spin resonance or depolarization mechanism when in fact no polarization would be lost if the spins had be initially aligned with the ISF. Several approaches using stroboscopic averaging were developed by K. Heinemann and G.H.Hoffstatter [21]. T-BMT code and gpuSpinTrack code employs one of the forward tracking methods detailed in this paper. Here three spin vectors each of which points along the \(\hat x\) (= (1, 0, 0)), \(\hat z\)(= (0, 1, 0)), and \(\hat s\) (= (0, 0, 1)) directions are tracked for each orbital phase space point. These are then tracked through one turn to establish the one turn spin transport matrix (R0), the eigenvector of which is calculated to give the spin closed orbit vector \(\hat n_0\). This is then dotted into subsequent transport matrices Rn each turn and accumulated in a total vector b,

$$\displaystyle \begin{aligned} \mathbf b_{n+1} = \mathbf b_n + \mathbf R_n \cdot \hat n_0. \end{aligned} $$
(9.55)

which is then averaged and normalized to yield the ISF for each phase space point which we want to track. One then needs to select an appropriate number of turns to achieve convergence to the ISF. The number of turns depends on ones proximity to a resonance and the overall nature of the ISF. Evidence that one has not converged can be seen in the turn-by-turn precession of the spin vector for a particle which is not aligned with the ISF.

Fig. 9.4
A schematic drawing of an invariant spin field. Many small upward arrows are arranged evenly at the bottom and fan out at the top. On the left and right two thick arrows indicate vector S 1, z 1 and vector S 2, z 2, respectively. The distance between them is labeled as a one-turn map.

Structure of the Invariant Spin Field