{'fraction_non_alphanumeric': 0.03177026893902079, 'fraction_numerical': 0.011772239188257315, 'mean_word_length': 4.422809829059829, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Real-time sextupole tuning for a long in-plane polarization at storage rings

A long in-plane beam polarization can be a desired feature for spin measurement experiments in storage rings. The polarization time of the beam can be extended by orders of magnitude by means of the frozen spin method and beam bunching via RF cavities, up to 10-100 seconds. Previous studies have shown that it can be further improved by sextupoles, which correct the second order effects related to the chromaticity of the beam. However, sextupole tuning is a tedious process and very sensitive to changes in the ring parameters. This work shows that sextupole tuning can be significantly simplified with real-time tuning, which uses a PID (Proportional Integral Derivative) feedback algorithm. Simulation results show that roughly determined feedback coefficients work effectively for a wide range of ring parameters.


Introduction
Storage ring spin physics experiments may require long polarization time for better sensitivities. Previous studies show that the in-plane polarization time can be extended by several methods, such as "frozen spin method" [1,2], beam bunching via RF cavities [3] and use of sextupoles [4,5,6]. The optimization procedure in the latter method can be a tedious process, especially when the experimental conditions vary at different storage times.
This work investigates the feasibility of a real-time sextupole tuning method through beam and spin dynamics simulations. The method relies on periodic monitoring of an error function and a feedback algorithm (namely a PID controller [7]) to reduce it. The PID controller tunes k s to minimize the time average of the left-right asymmetry of the beam polarization: s x . It involves three coefficients: • P: A "proportional feedback" K p multiplies with the error (defined as s x ) and generates a feedback. Typically, a Ponly controller makes the error function oscillate nearby the set value with an offset.
• I: An "integral feedback" K i multiplies with the past error to reduce the offset from the P-component. A large K i value results in unstable oscillations.
• D: The instantaneous change at every s x measurement can be used for the "derivative feedback" K d to damp the oscillations and converge fast.
The algorithm relies on a periodic modification of the sextupole strength k s by k s = K p s x + K i s x tot + K d s x diff (1) * selcuk.haciomeroglu@gmail.com to oppose the changes in the s x -terms. The superscripts "tot" and "diff" refer to the integral and the recent change of s x , respectively. Section 2 introduces the basic concepts and methods regarding in-plane spin polarization. Section 3 shows an application of sextupoles for a long polarization, and tuning requirements. Then, real-time sextupole tuning is introduced and its performance for various beam configurations is discussed in Section 4.

Spin dynamics in a storage ring experiment
The spin precession in a storage ring is determined by the T-BMT equation [8] where c, e and m are the speed of light, the electric charge and the mass of the particle, G = g/2 − 1 is the magnetic anomaly (≈ 1.8 for proton), β and γ are the relativistic velocity and the Lorentz factor correspondingly, B and E are the magnetic and electric fields respectively. Ideally, the average magnetic field on the beam should be zero, while the electric field should be purely radial. η is the EDM coefficient. It would be instructive to explain some concepts by referencing to an experiment. Storage ring electric dipole moment (EDM) experiments rely on measurement of out-of-plane spin precession rate d s y / dt of a longitudinally polarized charged beam [1,9,10]. Asuming a total cancellation of the magnetic field, it precesses as On the other hand, the in-plane (i.e. horizontal, towards the ring center) spin precession rate with respect to the momentum is approximately Comparison of G and η shows that the out-of-plane spin precession tends to be orders of magnitude slower than the in-plane precession. If the latter is not decelerated, then the out-of-plane spin component cannot grow with time because the main signal is proportional to the product of longitudinal spin and radial electric field components as shown in Equation 3. It is possible to work with a fast in-plane spin precession (at a frequency f G ) and measure the oscillation amplitude of the out-of-plane spin component at that specific frequency. This method was applied in the muon EDM measurement [11]. However, the sensitivity drops significantly in this method.
Limiting the in-plane spin precession helps reducing several systematic errors as well. One of them is a false EDM signal, related to the coupling between G and the longitudinal magnetic field, as seen in the first and the second terms of Equation 2. This effect is enhanced proportionally with s x [12]. Another false EDM signal originates from the coupling between G, and the product of the vertical component of β and the radial component of the electric field (3 rd term in Equation 2). Again, it is enhanced by s x [14].
The in-plane spin precession rate can be ideally stopped by the correct choice of γ = √ 1/a + 1, corresponding to the magic momentum p 0 (≈ 0.7 GeV/c for proton). This is the "frozen spin method" [1,2]. However, momentum spread of the beam limits the performance of the frozen spin method because the off-momentum (∆p/p 0 0) particles in the beam have faster in-plane spin precession. This causes their vertical spin components change sign due to the rotation of the spin on the horizontal plane, hence a decoherence among the particles. Following this argument, the spin coherence time (SCT) is defined as the time needed for keeping the off-momentum populations' spin within 1 radian with respect to the longitudinal direction.
The off-momenta particles orbit the storage ring with an average horizontal offset ∆x. An RF cavity can make it oscillate around zero, which eventually prolongs the SCT [3]. To first order, this is equivalent to averaging their momentum to p 0 . However, the second order effect, which originates from (∆p/p 0 ) 2 ∝ ∆x 2 and (∆p/p 0 ) 2 ∝ ∆y 2 , still causes a depolarization.
Regarding this second order effect, it was previously shown for electron/positron beams that the beam polarization could be prolonged by minimizing the chromaticity of the beam by means of sextupoles [4]. Y. Orlov has made first analytical estimations of the sextupole strengths for the deuteron beam to achieve a SCT of order 10 3 seconds [13].
At the COSY magnetic storage ring, the SCT of the deuteron beam could be prolonged by means of beam bunching with an RF cavity and optimizing three sextupole families. At the order of 10 3 seconds of SCT was achieved for various sextupole configurations. Based on an extrapolation, they reported that longer SCT was also achievable [5]. The sextupoles in those tests were first optimized by scanning, then the chromaticity and s x were monitored. They have observed a linear relation between the sextupole strength and the absolute value of the polarization loss. The slope of the line was reproducible at different runs. However, the zero crossing, an indication of the largest SCT, depended on the experimental setup. That means, the sextupole configuration requires a separate tuning for each experimental condition. A detailed analysis of the sextupole optimization and its connection to chromaticity is given in Ref. [6].

Achieving longer spin coherence with sextupoles
The simulations in this work were made with the hybrid storage ring design for the proton EDM experiment [14], which has a simple lattice with the cell structure as shown in Figure  1. However, the method is applicable to other storage rings as well. The term "hybrid" refers to electric deflectors and magnetic quadrupoles.
The sextupole elements in these studies overlapped with the 40 cm quadrupoles, located at the center of every straight section. Similar to the quadupoles, each sextupole had the same absolute strength k s . They also had the same alternating polarity pattern. However, a negative sign in k s means opposite polarity with the overlapping quadrupole. A number of simulations were repeated with different k s values, and then k s was optimized for the smallest change of rate in s x . The RF cavity was enabled at every simulation in this work.
The beam in the simulations had 74 particles with an approximately Gaussian distribution (Figure 2), where, the particles with |∆p/p 0 | > 2 × 10 −4 were excluded.
The particles in the beam were simulated simultaneously. The spin precession of the whole population was estimated by where t is the simulation time, s i x (t) is the horizontal spin component of the i th particle and N = 74 is the number of the simulated particles.  Figure 3 shows the in-plane spin precession rate ds x /dt of the beam as a function of the sextupole strength k s . A linear fit yields k s ≈ −0.00134 T/m 2 for the zero crossing. Figure 4 shows simulation results of ds x /dt as a function of momentum spread. The overall spin coherence was improved significantly with (k s = −0.00134 T/m 2 ) sextupoles. Comparison of Figure 3 and Figure 4 shows that zero crossing corresponds to a full cancellation between positive and negative spin precession rates, rather than an infinite SCT. That is, it happens even with depolarized beams. Nevertheless, the quadratic shape in Figure 4 suggests that the zero crossing for this storage ring happens nearby the zero spin precession rate region. This is a preferred behavior even if not optimal. Therefore, as will be seen below, the real-time sextupole tuning algorithm takes the time average s x of the beam as the reference.
While an optimum sextupole configuration improves spin coherence, it should be tuned extremely well. A single particle with ∆p/p 0 = 10 −4 was simulated again with 1.5% and 3.5% larger k s values. The spin precession rate increased by roughly 25% and 100% respectively.
Perturbations in the ring parameters have a significant impact on the sextupole performance as well. The horizontal betatron tune corresponding to Figures 3 and 4 was Q x = 1.9215. particle for slightly different horizontal tunes. Q x was modified through changing the quadrupole focusing strength, leaving everything else the same. The plot shows that the spin precession gets faster by ≈ 0.7 mrad/s at every 0.1% increase in Q x . It is clear that the sextupoles become inefficient rapidly as the ring configuration deviates from the optimum conditions. The combined effect of the betatron tune shift and the sextupole field shift is particularly critical. The betatron tunes may change due to an unknown effect and be corrected by a feedback at the quadrupoles. However, if the tune shift originates from electrical focusing effects, the magnetic quadrupole correction can cause an extra sextupole field, depending on the geometric design of the quadrupoles, eventually reducing the SCT.
In addition, varying ring parameters at different runs may be a preferred feature in an experiment, as in the hybrid ring design for the proton EDM experiment [15], which requires a sextupole tuning for each experimental configuration. A realtime sextupole tuning provides a one-size-fits-all solution to the sextupole tuning problem, simplifying the sextupole optimization process significantly.

Real-time sextupole tuning
The previous section showed that the SCT could be improved through a precise tuning of the sextupole strength. However, it got worse when the optimization conditions were tuned off.
Tuning the sextupole strength via a feedback mechanism has a number of merits. It only requires tuning several feedback coefficients. Then, the tedious sextupole tuning process is taken over by the simple feedback algorithm. The feedback coefficients do not need to be modified unless the ring parameters are dramatically changed. With this procedure, the sextupole strength changes slightly during the storage, to converge the optimal value.

Adjusting the PID parameters
The simulations in this section were made with a ∆p/p 0 = 10 −4 particle. The time average s x is defined as the error function for the PID controller and measured periodically, at every 0.1 ms. This period is large enough to prevent the PID controller from reacting the betatron oscillations. After each calculation, k s was updated by Equation 1.
The coefficients K p , K i , and K d can be adjusted in a number of ways. In this work, they were determined by manual tests, one by one. Initially, K i and K d were set to zero, and K p was tuned until s x started to make visible oscillations in the desired time scale. At that state, the spin precession oscillated with an offset, while k s oscillated around the optimal value. Then, K p was kept at that value and new simulations were made by increasing K i values, until the offset in s x was corrected. However, some time after damping, s x started oscillations in an unstable way. This seemed to be mostly related to the fact that K i was trying to fix the large synchrotron oscillations. Probably increasing the measurement from 0.1 ms to a second would fix this problem, but it was not feasible for a ms scale simulation. Therefore, K i was set to zero in the rest of the simulations. It is worth noting that the offset is not too critical as long as the spin precession rate is concerned.
Finally, several simulations were made by increasing K d , until the oscillations were seen to decay sufficiently fast. The PID coefficients did not need to be fine-tuned for different experimental conditions, while it might be helpful for a faster convergence. They were kept constant during each simulation. Figure 6 shows s x , as simulated after the coefficients were adjusted. The large oscillation at the beginning of the simulation was partly due to the large synchrotron oscillations and mainly because the initial k s estimations were far away from the optimum value. The seemingly flat oscillations at later times suggests > 10 4 seconds of SCT. Figure 7 shows the corresponding sextupole strength as a function of time. It took only a few iterations for k s to converge to the optimum value.

Simulations with a beam
The sextupole strength was optimized for a ∆p/p 0 = 10 −4 particle. Therefore, it was not supposed to perform as well for other momenta particles. For this section, 74 particles ( Figure  2) were simulated simultaneously, and the average in-plane spin of the beam was periodically calculated from Equation 5. At every period, k s was estimated via Equation 1 and the sextupoles were updated at each simulation. Figure 8 shows the time average of the horizontal spin component in the beam simulation. The quadrupoles were set to |k q | = 0.05 T/m, which corresponds to Q x = 1.92. The drift in the plot could possibly be fixed by a nonzero integral coefficient K i , which was not enabled due to the short simulation time. Nevertheless, d s x /dt = −1.3 × 10 −5 rad/s is negligible compared to the no-sextupole scenario. Figure 9 shows the average spin precession rate as a function of the momentum spread for three different quadrupole configurations: |k q | = 0.04 T/m, |k q | = 0.05 T/m and |k q | = 0.06 T/m, with horizontal tunes of 1.90, 1.92 and 1.95, respectively. While the spin precession tends to spread more for the higher Q x cases, the overall variation in the SCT is acceptable. This is particularly important for the hybrid ring design [15], because it requires a number of runs with different betatron tunes. A comparison with Figure 5 shows that the effect of the betatron tune shift reduces by an order of magnitude with this method.
All of the above simulations were made with the same set of PID coefficients: K i = 0; K p = 300; K d = 300 s. Several one-particle simulations were repeated by varying the latter two, keeping the K d /K p ratio constant. The simulations down to K p ≈ 100 yielded similar s x and k s values at the end, while the convergence time increased with smaller K p -values. Too small values did not converge at all within the short simulation time. On the other hand, too large K i -values caused unstable motion.
In conclusion, the PID controller does not require a precise adjustment. It is worth emphasizing that no initial estimation of sextupole strength was required in the simulations.

Transverse motion
The RF cavity forces every particle to have a fixed average revolution time around the ring. As mentioned above, setting it to the revolution period of the design particle (p 0 = 0.7 GeV/c with zero betatron oscillations), first order effects on the in-plane spin precession can be canceled. However, the betatron oscillations cause a lag at each revolution, which is compensated by the RF cavity by increasing the momentum, hence the in-plane spin precession rate.
The beam in the previous simulations was injected through the design orbit with no transverse offset. Therefore, the horizontal betatron oscillations were coupled to the momentum spread, and their effect on s x was reduced with no extra effort by the sextupoles.
With the additional two degrees of freedom (horizontal and vertical betatron oscillations with random phases), a sextupole strength usually has competing effects on these three terms. Clearly, this performance reduction becomes more significant as the beam size increases. In this section, the particles in the beam were given random offsets following an elliptical distribution. Figure 10 shows a comparison of the in-plane spin precession rate of various beam sizes at the end of 50 ms simulations. The sextupoles performed significantly well with the beams with 2 mm and 5 mm radii, while the performance reduced with the larger beam. Figure 11 shows the spin precession time τ x , the inverse of the fitting curves in Figure 10. Ignoring the peaks, τ x is prolonged by one to two orders of magnitude for the smallest beam (a), and up to ten times for the 5 mm radius beam (b). The slight reduction of τ x at the central region is likely to be tolerable, because of the small ∆p/p 0 coverage and already large τ x value. For the 1 cm radius beam (c), the contribution of τ x becomes less significant. It even becomes unfavorable for the    Figure 10. For the smallest size beam (a), τ x is two orders of magnitude larger for |∆p/p 0 | > 5 × 10 −4 . In the remaining region the sextupoles still increase τ x by more than order of magnitude. In (b), the improvement is roughly an order of magnitude for |∆p/p 0 | > 7 × 10 −4 , and it performs slightly worse than the no sextupole case at the central region. The peaks in the plots are the zero crossings at Figure 10. The sextupoles perform less impressively in (c), with τ x improved by only 4-5 times for the region |∆p/p 0 | > 6 × 10 −4 , and getting worse in the central region.
small ∆p/p 0 region. Therefore, a careful lattice design [13] and/or a more complex real-time tuning algorithm become essential to achieve a long SCT for large beams. A more complex sextupole system could solve the problem as well, but this is beyond the scope of this work. The peaks around ∆p/p 0 = ±10 −4 indicate zero crossing of the curves in Figure 10. The peaks around ∆p/p 0 = 0 imply that the momentum spread has a significant impact on τ x , even for large beams.

Conclusion
Sextupoles can be utilized in storage ring experiments to correct the second order chromaticity-related effects and prolong the SCT to the required level. However, its optimization is a tedious process and slight changes in the ring parameters affect the SCT significantly. Therefore, a real-time sextupole tuning may be inevitable.
The storage ring in this work was perfectly symmetric with one family of quadrupoles and sextupoles, which had alternating polarities at every straight section. A more complex storage ring could provide a better SCT, while requiring a more complex PID controller (with features like adaptivity, limiting the maximum sextupole strength, etc.) for each sextupole family.
The simulation time in this study had to be kept at milliseconds scale because of the limited CPU speed as well as the limitations of the simulation tool. Yet, an optimal sextupole strength could be achieved via PID tuning in such a short time.