\section*{Efield and pitch and Quadrupole Nonlinearity}
In smulation $\omega_a$ is most directly determined by spin tracking. The trajectory of the muon is established by numerically integrating
the equations of motion, and the spin by integration of the BMT equation along that trajectory. We would like to explore the contribution 
to $\omega_a$ numerically, due the
electric field of the quads and the vertical pitching (vertical betatron motion), so that we can incorporate nonlinearity that arises from the quadrupole geometry, and alignment errors. 
Spin tracking includes both effects. 
But spin tracking is inconvenient for at least 3 reasons
\begin{enumerate}
\item Integration of the BMT equation is computationally intensive (and slow).
\item The change in $\omega_a$ due to the electric field and the pitch is of order 1 part in $10^7$. Extracting their contribution depends
on the difference of large numbers, and is subject to error.
\item There is no simple way to distinguish contributions from electric field, and pitch, and whatever else. 
\end{enumerate}
As an alternative to spin tracking, we revisit the expressions for the contributions from electric field and pitch and proceed as follows.
\subsection*{Electric field contribution}
Recall that electric field appears as
\begin{equation}
\vec{\omega_a}=-\frac{q}{m}\left[a_\mu \vec B\left(a_\mu-\frac{m^2}{p^2}\right)\frac{\vec\beta\times\vec E}{c}\right]\label{eq:intb}
\end{equation} 
Define
$\phi_a = \int_0^T\omega_a dt$. In the absence of $\vec E$, we compute $\phi_a$ by integrating $\vec B_\perp$ along the muon trajectory.
Evidently, the contribution from the the electric field to $\phi_a$ is given by
\begin{equation}
\frac{\Delta \phi_E}{\phi_a} = \left(a_\mu-\frac{m^2}{p^2}\right)\frac{1}{c}\int_0^T\vec\beta\times\vec E dt
\approx -2\frac{\Delta p}{p}\frac{1}{c}\int_0^T\vec\beta\times\vec E dt\label{eq:inte}
\end{equation}
where $\Delta p = p-p_{magic}$.
In the tracking code it is straightforward to compute the sums in Equations ~\ref{eq:intb} and ~\ref{eq:inte}.
Then the electric field correction for the trajectory is
\begin{equation}
C_e(T) = -2\frac{\Delta p}{p}\frac{1}{T}\int^T\frac{\vec\beta\times\vec E}{Bc} dt \label{eq:efield_int}
\end{equation}
(We assume that $\vec B$ is parallel to $\vec\beta\times \vec E$.)
\subsection*{Pitch}
Consider the trajectory shown in ~\ref{fg:pitchpicture} of a muon executing betatron oscillations in the vertical plane. The pitching angle
is $\psi_0$. The magnetic field is in the vertical direction and $y_0$ is the associated vertical displacement. We are interested in the 
precession of the spin with respect to the muon momentum and therefore its projection onto the plane that contains the velocity 
and $\vec \beta\times \vec B$. The component of the magnetic field along the perpendicular to the plane is $B_\perp=B\cos\psi$.
The spin tune, that is the advance of the spin phase per turn is then
\begin{equation}
\nu_{spin}=\oint B_\perp dl = \oint B\cos\psi dl
\end{equation}
where the integration is through a single turn.
The path length of the pitching trajectory is 
\begin{equation}
\oint \sqrt{dx^2 + dy^2} =\oint \sqrt{1+\left(\frac{dy}{dx}\right)^2}dx \sim\oint 1+\frac{1}{2}\psi_0^2\sin\left(\frac{2\pi\nu_y}{L}\right)^2) = L(1+\frac{1}{4}\psi_0^2)
\end{equation}
The pathlength increases with the square of the pitching angle. Therefore the spin tune is independent of the pitching angle.
On the other hand, the cyclotron frequency decreases with pitching angle according to  $\omega_c(\psi_0) \sim \omega_c(0)(1-\frac{1}{4}\psi^2)$ and
then $$\omega_a (\psi_0)=\omega_a(0)(1-\frac{1}{4}\psi_0^2)$$
\begin{figure}[tb]
 \begin{center}
    \includegraphics*[width=0.8\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/pitchpicture.pdf}
\caption{pitching trajectory}
 \label{fg:pitchpicture}
 \end{center}
 \end{figure}

Then
%\frac{\Delta \phi_p}{\phi_a} = \frac{1}{T} \int^T(\vec \beta\cdot\vec B)\vec\beta dt\\
\begin{equation}
C_p(T)=\frac{\Delta \phi_a}{\phi_a} = \frac{1}{T} \int^T(|B|-|\hat\beta\times B|) dt \label{eq:pitch_int}
\end{equation}

To test the equivalence of the shift in precession frequency based Equations \ref{eq:efield_int} and~\ref{eq:pitch_int} we compute
both simultaneously along a single trajectory. The muon is propagated for 1000 $2\pi/\omega_a$ in order to determine the spin tune with sufficient accuracy. $\vec\beta\times\vec E$ is summed 
along that same trajectory. 
The trajectories chosen to test Equation~\ref{eq:efield_int} have momentum offset but no vertical motion. Similarly, to test Equation~\ref{eq:pitch_int}
the tracked muon has magic momentum and zero radial betatron oscillation. As shown in Figures~\ref{fg''spintrackintlin} the agreement is excellent.
The model of the quadrupole field is based on field maps and includes nonlinearity associated with the geometry of the plates. 
Note that at large amplitudes (see Figure~\ref{fg:spintrackingintlin} the formulas that assume linearity of the electric field overestimate the contributions of electric field and pitch 
to $\omega_a$ at large amplitudes, where the field gradient rolls over. 
%\subsection{Efield - Equivalence of spin tracking and integration of $\phi_a$.}
%\begin{figure}[h]
% \begin{center}
%    \includegraphics*[width=0.8\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/efield-spin_track_vs_int.pdf}
%\caption{Spin tracking and integration}
% \label{fg:spintrackint}
% \end{center}
% \end{figure}
\begin{figure}[h]
 \begin{center}
%    \includegraphics*[width=0.45\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/efield-spintrack-int-lin.pdf}
   \includegraphics*[width=0.45\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/efield-convolve.pdf}
    \includegraphics*[width=0.45\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/pitch-spintrack-int-lin.pdf}
\caption{(left) Contribution to $\omega_a$ due to electric field as computed by spin tracking and integration along trajectories for closed orbits at varying radial offset. Vertical closed orbit is zero and there is no vertical betatron motion. (The measured distribution
of radial offsets is superimposed for reference.)
Contribution to $\omega_a$ due to vertical oscillation is computed with spin tracking and integration along 
the trajectory for muons with magic momentum and zero radial betatron amplitude. The formula that assumes linearity overestimates the contribution at large amplitudes.}
 \label{fg:spintrackintlin}
 \end{center}
 \end{figure}


%\subsection{Pitch - Equivalence of spin tracking and integration of $\phi_a$.}
%\begin{figure}[tb]
% \begin{center}
%    \includegraphics*[width=0.8\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/pitch-spin_track_vs_int.pdf}
%    \includegraphics*[width=0.8\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/pitch-spintrack-int-lin.pdf}
%\caption{Contribution to $\omega_a$ due to vertical oscillation is computed with spin tracking and integration along 
%the trajectory for muons with magic momentum and zero radial betatron amplitude. The formula that assumes linearity overestimates the contribution at large amplitudes.}
% \label{fg:spintrackint}
% \end{center}
% \end{figure}
%\begin{figure}[tb]
 %\begin{center}


%\subsection{Misalignment and Voltage errors}
%\begin{figure}[tb]
% \begin{center}
%    \includegraphics*[width=0.45\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/efield-4mmerror.pdf}
%    \includegraphics*[width=0.45\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/efield-4mmerror-closedorbit.pdf}
%\caption{E-field alignment error}
% \label{fg:efield-4mmerror}
% \end{center}
% \end{figure}

%\begin{figure}[tb]
% \begin{center}
%    \includegraphics*[width=0.45\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/pitch-quadplatevoltageerror.pdf}
%    \includegraphics*[width=0.45\textwidth,angle=0, trim= 0 0 0 0, clip=.true.]{figures/pitch_quadplatevoltageerror_closed_orbit.pdf}
%\caption{pitch alignment error}
% \label{fg:pitchvoltageerror}
% \end{center}
% \end{figure}


