Ramping through a spin-orbit resonance with SciBmad

BNL’s Relativistic Heavy Ion Collider (RHIC) and its successor the Hadron Storage Ring (HSR) of the Electron-Ion Collider (EIC) are characterized by their high degree of polarization. The lack of a significant self-polarization mechanism for protons and ions means that these species have to be polarized at the source and accelerated without a significant loss of polarization. However, without special care, the electromagnetic fields used to accelerate the particles will destroy their polarization. This is often discussed in the context of the Alternating Gradient Synchrotron (AGS), as if particles cannot maintain their polarization through the AGS, there will be no polarization left to maintain once the particles reach RHIC/HSR.

The equation of motion for the rest-frame spin of relativistic particles is the Thomas-Bargmann-Michel-Telegdi (T-BMT) equation. As the length of the spin is constant (usually taken to be unity for simplicity), the T-BMT equation is a precession equation: $\( \dot{\vec{S}}(t)=\vec{\Omega}(t)\times\vec{S}(t). \)\( If there is only a magnetic field \)\vec{B}\( in the lab frame, the precession vector takes the form \)\( \vec{\Omega}=-\frac{q}{m\gamma}\left[(1+G\gamma)\vec{B}_\perp+(1+G)\vec{B}_\parallel \right], \)\( where \)\perp\( and \)\parallel\( indicate components perpendicular to and parallel to the particle's velocity. Comparing this equation to the Lorentz force, one sees that spins precess \)G\gamma\( times faster than the orbit in a transverse field. Therefore, in a ring where a particle on the closed orbit has no vertical momentum in the bending magnets and sees no other fields, the closed-orbit spin tune \)\nu_0\( is exactly equal to \)G\gamma$. In rings without egregious misalignments or spin rotators, we often hope that this is approximately true.

In general, the precession vector \(\vec{\Omega}\) is a quasiperiodic function of the position in the accelerator given by the azimuth \(\theta\). As a function of phase space and the lattice, it must be periodic in the orbital angles and \(\theta\). Hence, a Fourier decomposition in \(\theta\) alone would contain frequencies of the form $\(\kappa=k_0+\vec{k}\cdot\vec{Q} \quad \mathrm{with}\,\left(k_0,\vec{k}\right)\in\mathbb{Z}^4, \)\( where \)\vec{Q}\( contains the orbital tunes. During the acceleration process, \)\nu_0\(, being approximately equal to \)G\gamma\(, usually increases, and we can reach the condition \)\nu_0=\kappa\(. We then speak of a "spin-orbit resonance", and the spin motion usually becomes wild in the vicinity of these resonances, as in the image below for \)\kappa=0\(. In the approximation of an isolated resonance, the effect of a linear crossing depends only on the resonance strength \)\epsilon\( and the crossing speed \)\alpha=(\nu_0-\kappa)/\theta\(. However, the resonance strength \)\epsilon$ depends on the orbital amplitude, and thus every particle’s spin is changed differently. This can lead to a loss of polarization.

crossing.png

The desired polarization outside the interaction region is often vertical, because vertical spins are mostly unaffected by the vertical fields of the bending magnets. Resonances containing \(Q_y\) then become extremely important because vertical motion in the quadrupoles leads to horizontal magnetic fields. It is therefore of interest to see what happens to a vertical spin when it passes through an isolated resonance at constant speed. Froissart and Stora (1963) found that, if the spin is vertical infinitely far before the resonance, then infinitely far after the resonance, the vertical component of the spin will become $\( S_y=2\exp\left(-\frac{\pi\epsilon^2}{2\alpha}\right)-1. \)\( As can be seen below, this formula is often quite accurate even when crossing from a finite distance, as long as the resonances are isolated. In the AGS, the isolated vertical resonances used to be very important. Even now, with the partial snakes, the isolated horizontal resonances are the most important and the Froissart-Stora theory still applies. Note, however, that in the general case, instead of the component of \)\vec{S}\( along the vertical direction, we must consider the component along \)\vec{n}_0$, the periodic spin direction on the closed orbit. FS.png

Now, onto the simulation. We will only need SciBmad, with Plots and LaTeXStrings included for plotting purposes:

using SciBmad, Plots, LaTeXStrings

We will use a simple FODO lattice based on the AGS with superperiod \(P=60\):

include("../../lattices/ags.jl");

To know where to look for spin-orbit resonances, we have to know the tunes:

tw = twiss(ring)
Qy = tw.q2
8.98499999999973

Because the lattice has an exact superperiod of 60, we only expect first-order resonances at \(\nu_0=60N \pm Q_y\) with \(N\in\mathbb{Z}\). The ring is flat, so \(\nu_0=G\gamma\) and we will track through the \(\nu_0=60 + Q_y\) resonance. Let’s start at \(G\gamma=59 + Q_y\) and end at \(G\gamma=61+Q_y\):

Gγ_start = 59 + Qy 
Gγ_end =   61 + Qy
69.98499999999973

We can convert to \(E=\gamma mc^2\) using our physical constants package:

p = Species("proton")
E_start = Gγ_start / gyromagnetic_anomaly(p) * massof(p)
E_end   = Gγ_end   / gyromagnetic_anomaly(p) * massof(p)
3.662608106301288e10

For applying the Froissart-Stora formula, the useful quantity is \(\alpha = (\text{Change in \)G\gamma\( per turn})/(2\pi)\). But for a tracking code (and in the control room), we use the rate of change in terms of time. So we need the (approximate) revolution time, using the fact that we are ultrarelativistic:

approx_rev_time = ring.line[end].s_downstream/C_LIGHT
2.6686347026566107e-6

Let’s set it up so that the ramping takes place over 1,000 turns:

dE_dt = (E_end - E_start) / (1000 * approx_rev_time)
3.9221694422091406e11

In SciBmad, ramping is extremely simple because almost everything (magnet strengths, cavity voltages, cavity frequencies, the reference energy, etc.) can be made a time-dependent function. This is done using the function Time(), which creates an object that will, when the particle reaches an element during tracking, evaluate to the current time. So, to ramp, we simply make the reference energy of the ring a time-dependent function.

Note that there are other ways to go through a resonance, e.g., to vary the tune by changing quadrupole strengths or to drive the resonance with an AC dipole. Using Time(), both of these are easily simulated in SciBmad.

ring.E_ref = E_start + dE_dt*Time(); 
# This is saying E_ref(t) = E_start + dE_dt*t, but it could also be more complicated like sin(Time()), etc.

Let’s start with a vertical offset \((y=0.25\,\text{mm},\,p_y=0)\) and vertical spin. We will initialize a bunch, and then because this lattice doesn’t have RF cavities in it, we will use the simple ramping model which ramps the particle energy uniformly.

To do this, we will use track with the keyword arguments spin=true, ramp_particle_energy_without_rf=true, and n_turns=1000:

v0 = [0.0 0.0 2.5e-4 0.0 0.0 0.0] # Initial phase space coordinate
res = track(ring, v0=v0, spin=true, ramp_particle_energy_without_rf=true, n_turns=1000)
TrackResult of 1 particle:
config:
 n_turns                         = 1000
 save_every_n_turns              = 1
 in_body_coordinates             = false
 save_reference                  = false
 scalar_params                   = false
 rf_on                           = true
 ramp_particle_energy_without_rf = true
 ramp_update_each_particle       = false
 batch_start                     = 1
 verbose                         = false
 groupsize                       = 0
 use_cpu_multithreading          = false
 use_KA                          = false
 use_explicit_SIMD               = true

elapsed_time = 3.567974625 seconds

start = 1
turns = 0:1:1000

s, index, name, kind      the saved locations: the end of the beamline (s = 800.037)
state                     particle state codes, e.g. state[turn=n, particle=i]
x, px, y, py, z, pz       the coordinates, e.g. x[turn=n, particle=i]
v                         all six coordinates, e.g. v[turn=n, particle=i]
q                         spin quaternions (track_spin turns them into spin 3-vectors)
data                      the internal, low-level data arrays:
 state[1:1, 1:1, 1:1001]  [particle, location, saved turn]
 v[1:1, 1:6, 1:1, 1:1001] [particle, coordinate, location, saved turn]
 q[1:1, 1:4, 1:1, 1:1001] [particle, quaternion, location, saved turn]
bunch                     the Bunch at the end of tracking

Also store \(G\gamma\) for plotting:

T = approx_rev_time .* (0:1000);
Gγ = gyromagnetic_anomaly(p) * ring.E_ref.(T) / massof(p);

Because SciBmad tracks quaternions instead of spin 3-vectors, we can use the per-particle quaternions to track any initial spin, using the track_spin function. In this case, we just assume initial vertical spin:

s = track_spin(res.q, [0,1,0]) # [0,1,0] = vertical
s_y = s[particle=1][2,:]; # Vertical (2) component of the spin of particle 1, all turns (:)

Let’s plot the vertical spin component now, as a function of \(G\gamma_0\)

plot(Gγ, s_y, xlabel = L"G\gamma_0", ylabel = L"$S_y$", legend=false)

This indeed looks like a Froissart-Stora crossing. We can compute the resonance strength by looking at \(S_y\) at the end and inverting the Froissart-Stora formula:

epsilon = sqrt(2*(2/1000)/pi*log(2/(1+s_y[end])))
0.05227747866521151

Now, we can write a function which (in the isolated-resonance approximation) gives us the final \(S_y\) for any ramping rate \(\alpha\):

f(alpha) = 2*exp(-pi*epsilon^2/(2*alpha)) - 1
f (generic function with 1 method)

Let’s try some other ramping rates and see how the final \(S_y\) varies with \(\alpha\) (or equivalently the number of turns over which the ramping takes place):

turns = [1, 2, 5, 7, 10, 20, 50, 70, 100, 200, 500, 700, 1000, 2000, 5000, 7000]
final_s_y = zeros(length(turns))

for i in 1:length(turns)
    N = turns[i]
    ring.E_ref = E_start + 1000/N*dE_dt*Time()
    v0 = [0.0 0.0 2.5e-4 0.0 0.0 0.0]
    # save_every_n_turns=N because we only need final spin
    res = track(ring, v0=v0, spin=true, save_every_n_turns=N, ramp_particle_energy_without_rf=true, n_turns=N)
    final_s_y[i] = track_spin(res.q, [0,1,0])[turn=N, particle=1][2]
end

Now we can plot these results against the Froissart-Stora function we wrote:

plot(range(2/turns[1], 2/turns[end], 10000), f.(range(2/turns[1], 2/turns[end], 10000)), xscale=:log10, xlabel = L"$\alpha$", ylabel = L"Final $S_y$", legend=false)
scatter!(2 ./ turns, final_s_y)