\documentclass[fleqn, final]{../styles/unmphythesis}
\usepackage{../styles/qxd}
\renewcommand{\thechapter}{6}
%\newcommand{\thechapter}{1}

\makeindex
\begin{document}

%<*twocolorprotocol>

\chapter{Canceling the tensor light shift with two-color probes}\label{chap:twocolor}

Following Chapter~\ref{chap:quantumdynamicsrepresentation}, the light-atom interaction Hamiltonian with one atom can be written as
\begin{align}
\hat{h}_\eff &= -\hat{\mathbf{E}}^{(-)}(\br')\cdot\hat{\tensor{\mathbf{\alpha}}}\cdot\hat{\mathbf{E}}^{(+)}(\br')\nn\\
&= -\frac{2\pi\hbar\omega}{v_g}\left[\mathbf{u}_H^*\cdot\hat{\tensor{\mathbf{\alpha}}}\cdot \mathbf{u}_H\hat{a}_H^\dagger\hat{a}_H\right.
+ \mathbf{u}_H^*\cdot\hat{\tensor{\mathbf{\alpha}}}\cdot \mathbf{u}_V\hat{a}_H^\dagger\hat{a}_V\nn\\
&\quad\quad + \mathbf{u}_V^*\cdot\hat{\tensor{\mathbf{\alpha}}}\cdot \mathbf{u}_H\hat{a}_V^\dagger\hat{a}_H
\left. + \mathbf{u}_V^*\cdot\hat{\tensor{\mathbf{\alpha}}}\cdot \mathbf{u}_V\hat{a}_V^\dagger\hat{a}_V\right]\\
&= \hbar\left[(\hat{\chi}_{HH}+\hat{\chi}_{VV})\hat{S}_0 + (\hat{\chi}_{HH}-\hat{\chi}_{VV})\hat{S}_1 \right.\nn\\
&\quad \quad\left. + (\hat{\chi}_{HV}+\hat{\chi}_{VH})\hat{S}_2 + i(\hat{\chi}_{HV}-\hat{\chi}_{VH})\hat{S}_3 \right]\\
%\hbar \left[\left(\chi_{RR\uparrow} + \chi_{RR\downarrow} +\chi_{LL\uparrow}+\chi_{LL\downarrow} \right)\hat{F}_0\hat{S}_0 \right.\nonumber\\
%&\quad+\left(\chi_{RR\uparrow} + \chi_{RR\downarrow} -\chi_{LL\uparrow}-\chi_{LL\downarrow} \right)\hat{F}_0\hat{S}_3\nonumber\\
%&\quad+\left(\chi_{RR\uparrow} + \chi_{LL\uparrow} -\chi_{RR\downarrow}-\chi_{LL\downarrow} \right)\hat{F}_3\hat{S}_0\nonumber\\
%&\quad+\left(\chi_{RR\uparrow} - \chi_{RR\downarrow} +\chi_{LL\downarrow}-\chi_{LL\uparrow} \right)\hat{F}_3\hat{S}_3\nonumber\\
%&\quad+i\left(\chi_{LR\uparrow} - \chi_{RL\uparrow} +\chi_{RL\downarrow}-\chi_{RL\downarrow} \right)\hat{F}_0\hat{S}_1\nonumber\\
%&\quad+\left(\chi_{RL\uparrow} + \chi_{LR\uparrow} +\chi_{RL\downarrow}+\chi_{LR\downarrow} \right)\hat{F}_0\hat{S}_2\nonumber\\
%&\quad+i\left(\chi_{LR\uparrow} - \chi_{RL\uparrow} +\chi_{RL\downarrow}-\chi_{LR\downarrow} \right)\hat{F}_3\hat{S}_1\nonumber\\
%&\quad+\left.\left(\chi_{LR\uparrow} + \chi_{RL\uparrow} -\chi_{LR\downarrow}-\chi_{RL\downarrow} \right)\hat{F}_3\hat{S}_2 \right]\\
&=\hbar\sum_{i=0}^3 \hat{\chi}_{i}\hat{S}_i\\
&=\hbar\sum_{i,j=0} \chi_{ij}\hat{f}_i\hat{S}_j,
\end{align}
where $ \hat{S}_i $ are the Stokes vector operators of the light indicating its polarization, and the mode-atom coupling operator
\begin{align}
\hat{\chi}_{pp'}
&=-\frac{2\pi \omega}{v_g}\mathbf{u}_{p}^*(r'\!_\perp,\phi')\cdot \hat{\tensor{\alpha}}\cdot \mathbf{u}_{p'}(r'\!_\perp,\phi')\\
&= \sum_{f'} \frac{n_g\sigma_0}{4}\frac{\Gamma_{f'}}{\Delta_{ff'}+i\Gamma_{f'}/2}\cdot \left\{ C_{j'ff'}^{(0)}\mathbf{u}_p^*(r'\!_\perp)\cdot \mathbf{u}_{p'}(r'\!_\perp)\hat{\mathbbm{1}}\right.\nn\\
&\quad\quad +iC_{j'ff'}^{(1)}\left(\mathbf{u}_p^*(r'\!_\perp)\times\mathbf{u}_{p'}(r'\!_\perp) \right)\cdot \hat{\mathbf{f}} \nonumber\\
&\quad\quad\left. + C_{j'ff'}^{(2)}\sum_{i,j}\left[u^*_{p,i}u_{p',j}(\frac{\hat{f}_i\hat{f}_j+\hat{f}_j\hat{f}_i}{2}-\frac{\delta_{ij}}{3}\hat{\mathbf{f}}\cdot\hat{\mathbf{f}}) \right]\right\}
%&\left.+C_{jj'ff'}^{(2)}\left[\mathbf{u}_p^*(r'\!_\perp)\cdot \mathbf{u}_{p'}(r'\!_\perp)\left(\frac{f(f+1)}{6}-\frac{m^2}{2} \right)+\mathbf{u}_p^*(r'\!_\perp)\cdot (\hat{e}^*_{\tilde{z}}\hat{e}_{\tilde{z}})\cdot \mathbf{u}_{p'}(r'\!_\perp)\left(\frac{3m^2}{2}-\frac{f(f+1)}{2} \right) \right] \right\}
\label{eq:chippp}
\end{align}
with the horizontally(H)- and vertically(V)-linearly polarized guided modes, $ \mathbf{u}_p(r'\!_\perp) $, at the atom position $ \br'=(r'\!_\perp,\phi',z') $.
$ \chi_{ij}=\tr[\hat{f}_i\hat{\chi}_j]/(2f+1) $ is the coupling strength between spin operator $ \hat{f}_i $ and Stokes operator $ \hat{S}_j $.
For example, $ \chi_{33} $ is the coupling strength between $ \hat{f}_z $ and $ \hat{S}_3 $.
The fundamental guided modes of an optical nanofiber has been defined in the appendix of our previous paper~\cite{Qi2016}.
In general, for a cylindrical waveguide, the H- and V-modes are the guided modes adiabatically transferred from a corresponding linearly polarized input light from one end of the waveguide, where H- and V-directions are orthogonal to each other in the transverse plane.
The coupling operator or Eq.\eqref{eq:chippp} includes three terms corresponding to scalar, vector and tensor interactions between atoms and the probe light which are proportional to $ C_{j'ff'}^{(K)} $ with $ K=0,\,1,\,2 $, respectively.

\qxd{Generalize the above to the two-color case. Some words on finding the correct frequencies.}

We also ignore the tensor coupling strength related to $ C_{jj'ff'}^{(2)} $ terms in Eq.\eqref{eq:chippp} as the tensor interaction strength ($ \sim 1/\Delta^2 $) is relatively small compared to the vector interaction strength ($ \sim 1/\Delta $)~\cite{Deutsch2010a}.
For a nanofiber geometry, the Faraday interaction coupling strength is independent of the azimuthal position of the atoms and can be simplified as
\begin{align}
\chi_{33} &= -\sum_{f'}n_g\sigma_0\frac{\Gamma_0}{\Delta_{ff'}+i\Gamma_0/2}C_{jj'ff'}^{(1)}u_{r\!_\perp}(r'\!_\perp)u_\phi(r'\!_\perp)\\
&=\frac{\sigma_0}{A_F}\frac{\Gamma_0}{\Delta_F},
\end{align}
where the effective Faraday interaction mode area $ A_F=1/2n_g|u_{r\!_\perp}(r'\!_\perp)u_\phi(r\!_\perp)| $, and the effective detuning $ \Delta_F=\sum_{f'}\frac{-C_{j'ff'}^{(1)}}{\Delta_{ff'}} $.
The measurement strength is now defined as
\begin{align}
\kappa\equiv|\chi_{33}|^2\dot{N}_L=\frac{\sigma_0A_{in}}{A_F^2}\gamma_s,
\end{align}
where the characteristic photon scattering rate $ \gamma_s\equiv \frac{\Gamma_0\Omega^2}{4\Delta_F}=\frac{\sigma_0}{A_{in}}\frac{\Gamma_0^2}{4\Delta_F^2}\dot{N}_L $ and the effective mode area $ A_{in}=1/n_g|u_{\mathrm{in}}(\br'\!_\perp)|^2 $.
Now we can define the OD per atom for the Faraday interaction using SCS by
\begin{align}
\frac{\mathrm{OD}}{N_A} \equiv \frac{\kappa}{\gamma_s}=\frac{\sigma_0A_{in}}{A_F^2}.
\end{align}

\qxd{Again, generalize to two-color case.}
\section{A two-color spin squeezing protocol to cancel the tensor light shift}
As illustrated in Enrique Montano's PhD dissertation work, the tensor light shift due to the external field can be canceled in a free-space spin squeezing setup, we will generalize this idea to the nanophotonic waveguide case.

From Eq.~\eqref{eq:Heff_Faraday_C02}, the state-dependent tensor light shift (the term proportional to $ \hat{f}_x^2 $) is proportional to
\begin{align}
\delta E_T &= \sum_{j',f'} \frac{\Gamma_{j'f'}^x\Omega^2}{\Delta_{fj'f'}^2+(\Gamma_{j'f'}^x)^2/4}C_{j'ff'}^{(2)}\\
&\approx \sum_{j'f'}\frac{\Gamma_{j'f'}^x\Omega^2}{\Delta_{fj'f'}^2}C_{j'ff'}^{(2)} = \sum_{j'f'}\frac{\sigma_0}{\Ain}\left(\frac{\Gamma_{j'f'}^x}{\Delta_{fj'f'}} \right)^2 \dot{N}_L C_{j'ff'}^{(2)}
\end{align}
To cancel the tensor light shift, we want to find the two frequencies of the probes so that $ \delta E_T=0 $.

\qxd{To be continue...}

\section{Spin dynamics with two-color probes}

To study the spin squeezing dynamics, we employ a first-principles stochastic master equation for the collective state of $N_A$ atoms,
\begin{align}\label{eq:totaldrhodt_twocolor}
\mathrm{d}\hat{\rho}= \left.\mathrm{d}\hat{\rho}\right|_{QND}+\left.\mathrm{d}\hat{\rho}\right|_{op}.
\end{align}
The first term on the right-hand side of Eq.\eqref{eq:totaldrhodt_twocolor} governs the spin dynamics arising from QND measurement~\cite{Jacobs2006,Baragiola2014},
\begin{align}
\left.\mathrm{d}\hat{\rho}\right|_{QND} &= \sqrt{\frac{\kappa_1}{4}}\mathcal{H}\left[\hat{\rho} \right]\mathrm{d}W_1 + \sqrt{\frac{\kappa_2}{4}}\mathcal{H}\left[\hat{\rho} \right]\mathrm{d}W_2 + \frac{\kappa_1+\kappa_2}{4}\mathcal{L}\left[ \hat{\rho}\right]\mathrm{d}t,
\end{align}
where  $\kappa_1$ and $ \kappa_2 $ are the measurement strengths defined in Eq.~\eqref{eq:kappa} for the two probes in different frequencies, respectively; $\mathrm{d}W_1$ and $ \mathrm{d}W_2 $ are independent stochastic Weiner intervals for the two probes. The conditional dynamics are generated by superoperators that depend on the {\em collective} spin
\begin{subequations}
\begin{align}
\mathcal{H}\left[ \hat{\rho}\right] &= \hat{F}_z \hat{\rho} + \hat{\rho}\hat{F}_z -2\expect{\hat{F}_z}\hat{\rho}, \\
\mathcal{L}\left[ \hat{\rho} \right] &= \hat{F}_z \hat{\rho}\hat{F}_z -\frac{1}{2}\left(\hat{\rho}\hat{F}_z^2+\hat{F}_z^2\hat{\rho} \right)=\frac{1}{2}\left[\hat{F}_z,\left[\hat{\rho},\hat{F}_z \right] \right].
\end{align}
\end{subequations}
The second term governs decoherence arising from optical pumping, which acts {\em locally} on each atom$,\mathrm{d}\hat{\rho}|_{op}=\sum_n^{N_A} \mathcal{D}^{(n)}\left[ \hat{\rho}\right] \mathrm{d}t$, where
\begin{equation}
\mathcal{D}^{(n)}\left[ \hat{\rho}\right] = -\frac{i}{\hbar}\left(\hat{H}^{(n)}_{\rm eff}\hat{\rho} - \hat{\rho} \hat{H}^{(n)\dag}_{\rm eff}\right) + \gamma_{op} \sum_q \hat{W}^{(n)}_q \hat{\rho}\hat{W}^{(n)\dag}_q.
\label{op_superator}
\end{equation}
Here $\hat{H}^{(n)}_{\rm eff}$ is the effective nonHermitian Hamiltonian describing the local light shift and absorption by the $i^{th}$ atom and $\hat{W}^{(n)}_q$ is the jump operator corresponding to optical pumping through spontaneous emission of a photon of polarization $q$~\cite{Deutsch2010a} (see Appendix~\ref{chap:opticalpumpingwithmodifiedrates} \qxd{Need to double check if all modified decay rates are correctly included.}).
The rate of decoherence is characterized by the total optical pumping rate, $\gamma_{op}=\gamma_{op,1}+\gamma_{op,2}$, of the two probes.  Note, the optical pumping superoperator, Eq.\eqref{op_superator},  is not trace preserving when restricted to a given ground-state hyperfine manifold $f$.  In this case, optical pumping of atoms to the other hyperfine manifold in the ground-electronic state is treated as loss.  If the atoms are placed at the optimal position, the local field is linearly polarized.  In that case the vector light shift vanishes, and for detunings large compared to the excited-state hyperfine splitting, the rank-2 tensor light shift is negligible over the time scales of interest.  In that case the light shift is dominated by the scalar component, which has no effect on the spin dynamics.  In that case $\hat{H}_{\rm eff} = -i\hbar \gamma_{op}/2 1$.

%</twocolorprotocol>

\appendix

%<*opticalpumpingwithmodifiedrates>
\chapter{Optical pumping considering the modified emission rates}\label{chap:opticalpumpingwithmodifiedrates}
In this part, we derive the motion of equations for the optical pumping dynamics with one-color probe. To make our notation simple, we implicit include the excited state fine structure quantum number $ j' $ for the one-color probe case. Once the quantum transition rates of individual colors of the probes have been calculated, the total dynamics due to the two-color probes should be determined by the sums of the transition rates associated with the two probes.

The collective spin dynamics in the QND measurement and spin squeezing process is described by the stochastic master equation defined in Eq.~\eqref{eq:totaldrhodt}. The optical pumping dynamics of the $ j $-th atom are governed by
\begin{align}
\left.\dt{\hat{\rho}^{(j)}}\right|_{op} &= \mathcal{D}[\hat{\rho}^{(j)}]=-\frac{i}{\hbar}\left\{\hat{H}_{\rm eff}^{(j)},\hat{\rho}^{(j)} \right\}_+ + \gamma_s\sum_{q}\hat{W}_q(\br'_j)\hat{\rho}^{(j)}\hat{W}_q^\dagger(\br'_j) %\\
%&=-\gamma_s\frac{1}{2}\sum_{a,b}\gamma_{ba}\ket{b}\bra{a}+
%\!\!\!\!\!\!\sum_{q,q',q'',a,b,c,d,f',f'',m',m''}\!\!\!\!\!\! \gamma_sw_{dcq}^{f''m''q''}\left(w_{abq}^{f'm'q'}\right)^*\ket{d}\bra{c}\hat{\rho}^{(i)}\ket{b}\bra{a}.
\end{align}
We have defined a characteristic photon scattering rate, $\gamma_s \equiv \frac{\Gamma_0\Omega^2}{4\Delta_{F}^2}= \frac{\sigma_0}{A_{\rm in}}\frac{\Gamma_0^2}{4 \Delta_{F}^2} \dot{N}_L $ with an effective detuning $ \Delta_F $ defined by $ \frac{1}{\Delta_F}=\sum_{f'}\frac{C_{ff'}^{(1)}}{\Delta_{ff'}} $ and $ \Delta_{ff'}=\omega-\omega_{ff'} $.
We have also defined Rabi frequency $ \Omega=2\bra{j}|d|\ket{j'}\mathcal{E}^{(+)}_{\rm in}/\hbar $ with reduced optical dipole matrix element $\bra{j}|d|\ket{j'}$ and field amplitude $ \mathcal{E}^{(+)}_{\rm in}=|\mathbf{E}_{\rm in}^{(+)}(\br')| $.
The total rate of photon scattering by an atom from the $\ket{a}\equiv \ket{f,f_x=a}$ to $ \ket{b}\equiv\ket{f,f_x=b} $ hyperfine ground state in the $x$-basis is
	\begin{equation}\label{Eq::gammaf}
		\gamma_{ba}=- \frac{2}{\hbar} {\rm Im} \big[ \bra{f,b} \hat{h}_{\rm eff}\ket{f,a} \big] ,
	\end{equation}
The effective nonHermitian light-shift Hamiltonian for one atom (labeled with superscript $ (j) $ for the $ j $th atom) is given by
\begin{align}
\hat{H}_{\rm eff}^{(i)} \equiv \hat{h}_{\rm eff}&= - \hat{\mathbf{E}}^{(-)}_{\rm in}(\mathbf{r}' ; t ) \cdot \poltens \cdot \hat{\mathbf{E}}^{(+)}_{\rm in}(\mathbf{r}' ;t ),
\end{align}
where the polarizability operator $  \poltens=\sum_{f',q}\hat{\tensor{\mathbf{A}}}(f,f',q)$ with elements of $ \hat{\tensor{\mathbf{A}}} $ given by
\begin{align} \label{Eq::PolarizabilityIrrep}
		\hat{A}_{ij}(f,f',q)&\equiv -\frac{\sigma_0}{8\pi k_0\gamma_s}\frac{\Gamma_{f'\!\!,\, i}^q}{\Delta_{ff'}^q+i\Gamma_{f'\!\!,\, i}^q/2}\hat{e}_i^*\cdot\hat{\mathbf{D}}_{ff'}\hat{\mathbf{D}}_{f'f}^\dagger \cdot \hat{e}_j \\
		&=  -\frac{\sigma_0}{8\pi k_0\gamma_s}\frac{\Gamma_{f'\!\!,\, i}^q}{\Delta_{ff'}^q\!+\! i\Gamma_{f'\!\!,\, i}^q/2}\left\{ C_{ff'}^{(0)} \delta_{i,j}\hat{\mathbbm{1}}\!+\! iC_{ff'}^{(1)}\epsilon_{ijk}\hat{f}_k \!+\! C_{ff'}^{(2)} \Big[ \smallfrac{1}{2} ( \hat{f}_i\hat{f}_j \!+\!\hat{f}_j\hat{f}_i )\!-\!\smallfrac{1}{3} \hat{\mathbf{f}}\!\cdot\!\hat{\mathbf{f}} \delta_{i,j} \Big]\right\},
\end{align}
where $\hat{\mathbf{f}}$ is the atomic spin operator in hyperfine multiplet $f$, and $ \epsilon_{ijk} $ is the Levi-Civita symbol.
Definitions of the interaction coefficients $ C_{ff'}^{(n)} $ can be found in Ref.~\cite{Qi2016}, which correspond to scalar, vector and tensor atom-light interactions for $ n=0,1,2 $, respectively.

Given the geometry of the Faraday spin squeezing protocol for optical nanofiber and square waveguides discussed in this paper, the local electric field at the atom positions is linearly polarized.
By denoting the local field's polarization direction as the $ x$-direction and the propagation direction of the guided light as the $ z $-direction, the effective atom-light interaction Hamiltonian in a static reference frame can be written as
\begin{align}
\hat{h}_{\rm eff} &= -\frac{i\hbar}{2}\sum_{f'} \gamma'_s \left[C_{ff'}^{(0)}\hat{\mathbbm{1}}+C_{ff'}^{(2)}(\hat{f}_{x}^2-\frac{\hat{\mathbf{f}}^2}{3} ) \right],\label{eq:Heff_Faraday_C02}
\end{align}
where the intrinsic photon scattering rate $ \gamma'_s\equiv \frac{\Gamma_{f'}^x\Omega^2}{4(\Delta_{ff'}^2+\left(\Gamma_{f'}^x\right)^2/4 )}$ and in the far-detuning regime, $\gamma'_s \approx \frac{\Gamma_{f'}^x\Omega^2}{4\Delta_{\rm eff}^2}=\frac{\sigma_0}{\Ain}\left(\frac{\Gamma_{f'}^x}{2\Delta_{\rm eff}} \right)^2\dot{N}_L $. Note here the vector interaction term vanishes given a linearly polarized light; we have ignored the energy shift, which is valid when the detuning is much larger than the hyperfine level splitting.
In our simulations of spin squeezing in this paper, we have used the decay rate $ \Gamma_{f',q} $ to indicate the decay rates from the hyperfine $ f' $ manifold sublevels of excited states with a photon emission polarized along the $ \mathbf{e}_q $ direction; the effective detuning is also an averaged detuning from the fine structure excited level $ j' $ to the ground fine structure manifold $ j $ with resonant frequency $ \omega_D $ of $ D_1 $ line transitions--that is $ \Delta_{\rm eff}=\omega -\omega_D $ with probe frequency at $ \omega $ in vacuum given a far-detuned $ \sim 1 $nm of detuning from the $ D_1 $ line transition of $ ^{133}Cs $ atoms.
Compared to the normal characteristic photon scattering rate $ \gamma_s $, we can see they are defined in different scales.
In general, they are related given a transition between ground hyperfine structure level $ f $ and excited hyperfine structure level $ f' $ by
\begin{align}
\gamma'_s(f')=\gamma_s \frac{\Delta_F^2}{\Delta_{ff'}^2},
\end{align}
and hence $ \frac{\sqrt{\Gamma_{f'}^x}\Omega/2}{\Delta_{ff'}\pm i\Gamma_{f'}^x/2}\approx \frac{\sqrt{\Gamma_{f'}^x}\Omega/2}{\Delta_{ff'}}=\sqrt{\gamma_s}\frac{\Delta_F}{\Delta_{ff'}} $ in the far-detuning regime.

We define the Lindblad jump operators of optical pumping among ground states by~\cite{Deutsch2010a}
	\begin{align}\label{Eq::Wq_Faraday}
		\hat{W}_q &= \frac{1}{\sqrt{\gamma_s}}\sum_{f'}\frac{\sqrt{\Gamma_{f'}^q}\Omega/2}{\Delta_{f'f}^q+i\Gamma_{f'}^q/2}\mathbf{e}_q^*\cdot(\hat{\mathbf{D}}_{ff'}  \hat{\mathbf{D}}^\dagger_{f'f} )\cdot\mathbf{e}_{\rm in} \\
		&= \frac{1}{\sqrt{\gamma_s}}\!\sum_{f'k}\! \frac{\sqrt{\Gamma_{f'}^q}\Omega/2}{\Delta_{ff'}+i\Gamma_{f'}^q/2} \left[\delta_{qx}C_{ff'}^{(0)}\hat{\mathbbm{1}} + iC_{ff'}^{(1)}\epsilon_{qxk}\hat{f}_k  \phantom{\dfrac{\hat{f}}{f}}\right. \nn\\
		&\qquad\qquad\qquad\qquad\qquad\qquad \left. + C_{ff'}^{(2)} \left(\frac{\hat{f}_q\!\hat{f}_{x}\!+\!\hat{f}_{x}\!\hat{f}_q }{2} \!-\! \frac{\delta_{qx}}{3}\hat{\mathbf{f}}^2 \right) \right].
%		&=\sum_{f',m',q',a,b} w_{baq }^{f'm'q'}\ket{b}\bra{a}.
	\end{align}
Each jump operator $\hat{W}_q$ is associated with absorption of the probe photon polarized along $ \mathbf{e}_{\rm in} $ followed by spontaneous emission of a photon with polarization $ \mathbf{e}_q $, where $q= \{0,\pm 1\}$ labels spherical basis elements for $\pi$ and $ \sigma_\pm$ transitions.
%Here the dimensionless raising operator $ \mathbf{e}_q\cdot\hat{\mathbf{D}}_{f'f}^\dagger= \sum_{m',m} o_{jf}^{j'f'} C_{f',m'}^{f,m;1, q}\ket{f',m'}\bra{f,m} $,
%where $ C_{f',m'}^{f,m;1, q}=0 $ unless $ m'=m+q $ with $ C_{f',m+q}^{f,m;1, q}=\Braket{f',m+q}{f,m;1,q}$ being the Clebsch-Gordan coefficients, and
%\begin{equation}
%\big| o_{jf}^{j'f'} \big|^2=(2j'+1)(2f+2) \bigg\{
%\begin{array}{ccc}
%f' & 7/2 & j' \\
% j & 1 & f
% \end{array}
% \bigg\}
%\end{equation}
%are the relative oscillator strengths determined by the relevant Wigner 6-$J$ symbol.
%In our protocols, we assume the probe light is so far-detuned from any of the atomic resonances that the tilting of the hyperfine structure levels due to an external magnetic field becomes irrelevant and we can set $ \Delta_{ff'}^q=\Delta_{ff'} $ and $ \Delta_{ff'}\gg \Gamma_f'^q $ for arbitrary $ f' $ and $ q $.

Therefore, in the static $ \left\{x,y,z \right\} $ basis, we have
\begin{align}
\hat{W}_{x} &= \frac{1}{\sqrt{\gamma_s}}\!\sum_{f'} \frac{\sqrt{\Gamma_{f'}^x}\Omega/2}{\Delta_{ff'}+i\Gamma_{f'}^x/2} \left[C_{ff'}^{(0)}\hat{\mathbbm{1}} + C_{ff'}^{(2)}\left(\hat{f}_{x}^2-\frac{1}{3}\hat{\mathbf{f}}^2 \right) \right]\\
\hat{W}_{y} &= \frac{1}{\sqrt{\gamma_s}}\!\sum_{f'} \frac{\sqrt{\Gamma_{f'}^y}\Omega/2}{\Delta_{ff'}+i\Gamma_{f'}^y/2} \left(-iC_{ff'}^{(1)}\hat{f}_z + C_{ff'}^{(2)}\frac{\hat{f}_{x}\hat{f}_{y}+\hat{f}_{y}\hat{f}_{x}}{2} \right)\\
\hat{W}_{z} &= \frac{1}{\sqrt{\gamma_s}}\!\sum_{f'} \frac{\sqrt{\Gamma_{f'}^z}\Omega/2}{\Delta_{ff'}+i\Gamma_{f'}^z/2} \left(iC_{ff'}^{(1)}\hat{f}_{y} + C_{ff'}^{(2)}\frac{\hat{f}_z\hat{f}_{x}+\hat{f}_{x}\hat{f}_z}{2}  \right).
\end{align}

The optical pumping dynamics of the $ j $-th atom are governed by
\begin{align}
\left.\dt{\hat{\rho}^{(j)}}\right|_{op} &= \gamma_s\mathcal{D}[\hat{\rho}^{(j)}]=-\frac{i\gamma_s}{\hbar}\left\{\hat{h}^{\rm eff}_{\rm eff},\hat{\rho}^{(j)} \right\}_+ + \gamma_s\sum_{q}\hat{W}_q(\br'_j)\hat{\rho}^{(j)}\hat{W}_q^\dagger(\br'_j)\\
\\
&=-\gamma_s\frac{1}{2}\sum_{a,b}\gamma_{ba}\ket{b}\bra{a} \nn\\
&\quad\quad + \!\!\!\!\!\!\sum_{q,q',q'',a,b,c,d,f',f'',m',m''}\!\!\!\!\!\! \gamma_sw_{dcq}^{f''m''q''}\left(w_{abq}^{f'm'q'}\right)^*\ket{d}\bra{c}\hat{\rho}^{(i)}\ket{b}\bra{a}
\end{align}
Eqs.~\eqref{Eq::gammaf} and~\eqref{Eq::Wq_Faraday} yield,
\begin{subequations}
	\begin{align}
		\gamma_{ba}
		&=\frac{n_g\dot{N}_L}{\gamma_s}  \sum_{f',q} \sigma (\Delta_{ff'} ) \mathbf{u}^*_\inp(\br'_\perp)\cdot \bra{b} \hat{\tensor{\mbf{A}}}(f,f') \ket{a}  \cdot \mathbf{u}_\inp(\br'_\perp)\\
		&\approx  \sum_{f',m'} \frac{\Delta_{F}^2}{\Delta_{ff'}^2}\sum_{q,q'} \big| o_{jf}^{j'f'} \big|^2C_{f',b+q'}^{f,b;1, q'}C_{f',a+q}^{f,a;1, q} \mathbf{e}_{q'}^* \cdot (\mathbf{e}_{\rm in}\mathbf{e}_{\rm in}^* )\cdot \mathbf{e}_q,
	\end{align}
\end{subequations}
	\begin{align}
		w_{baq}^{f'm'q'}
		&\approx  \frac{\Delta_{F}}{\Delta_{ff'}+i\Gamma_{f'}^q/2} \big| o_{jf}^{j'f'}  \big|^2 C_{f'm'}^{f,b;1 q}C_{f',m'}^{f,a;1,q'} (\mathbf{e}_{q'}^* \cdot \mathbf{e}_{\rm in}),
	\end{align}
where $ \sigma (\Delta_{ff'} )  = \sigma_0 \Gamma_0^2/4\Delta^2_{f' f}$ is the the scattering cross section at the probe detuning in free space.

Now, we consider a static magnetic field is applied to the atoms to fix the quantization axis to the $ \mathbf{e}_{z} $ direction pointing along the waveguide axis.
We assume the magnetic field is so strong that the Larmor processing is much faster than the atomic decay and atom-photon interaction processes and the transverse components of the atomic angular momentum operators will be averaged out in the process of spin squeezing dynamics.
In theory, this leads us to transfer the master equations of the collective spin dynamics to the rotating frame determined by the fast-rotating transform operator
\begin{align}
\hat{U}_B(t) &= e^{-i\Omega_Bt\hat{f}_z},
\end{align}
where $ \Omega_B $ is the Larmor processing frequency of the external magnetic field.
In the rotating frame, a quantum operator $ \hat{A} $ is transfered into $ \hat{A}' $ through $ \hat{A}\rightarrow \hat{A}'=\expect{\hat{U}_B^\dagger\hat{A}\hat{U}_B }_T $, where the notation $ \expect{\cdot}_T=\frac{1}{T}\int\cdot dt $ is the time average of observables in a period $ T $.
The density operator preserves its form in the rotating frame.
We can solve the transformed master equations by employing the Baker-Campbell-Hausdorff formula that $ e^{\lambda\hat{A}}\hat{B}e^{-\lambda\hat{A}}=\sum_{n=0}^\infty\frac{\lambda^n}{n!}\hat{C}_n $, where $ \hat{C}_0=\hat{B} $ and $ \hat{C}_n=\left[\hat{A},\hat{C}_{n-1} \right] $ for $ n>1 $, and the commutators of atomic angular momentum operators, $ \left[\hat{f}_m, \hat{f}_n\right]=i\sum_p\epsilon_{mnp}\hat{f}_p $.
The following static-rotating frame transformation relationships can be proved easily:
\begin{subequations}\label{eq:rotationtransf}
	\begin{align}
	\hat{U}_B^\dagger\hat{f}_{x}\hat{U}_B&=\cos(\Omega_Bt)\hat{f}_x-\sin(\Omega_Bt)\hat{f}_y,\\
	\hat{U}_B^\dagger\hat{f}_{y}\hat{U}_B &= \sin(\Omega_Bt)\hat{f}_x+ \cos(\Omega_Bt)\hat{f}_y, \\ \hat{U}_B^\dagger\hat{f}_{z}\hat{U}_B &=\hat{f}_z,\quad \hat{U}_B^\dagger\hat{\mathbbm{1}}\hat{U}_B =\hat{\mathbbm{1}}.
	\end{align}
\end{subequations}
In the rotating frame, operators with a transverse atomic angular momentum will be averaged to vanish. For example,
\begin{subequations}\label{eq:rotationtransf_f}
	\begin{align}
	\hat{f}_{x}&=\hat{f}_{y} \rightarrow 0, \quad \hat{f}_{z}\rightarrow\hat{f}_z, \quad \hat{f}_{z}^ 2\rightarrow\hat{f}_z^2,\\
	\hat{f}^2_{x} &= \hat{f}^ 2_{y} \rightarrow \frac{1}{2}(\hat{\mathbf{f}}^2-\hat{f}_z^2),\\
	\hat{f}_{x}\hat{f}_{y} &\rightarrow\frac{1}{2}\hat{f}_z,\quad \hat{f}_{y}\hat{f}_{x}\rightarrow -\frac{1}{2}\hat{f}_z,\quad \hat{f}_{i=x,y}\hat{f}_{z}\rightarrow 0.
	\end{align}
\end{subequations}

Using the transformation relationships defined in Eqs.\eqref{eq:rotationtransf}, the loss Hamiltonian in the rotating frame becomes
\begin{subequations}\label{eq:rotationtransf_hloss}
\begin{align}
\hat{h}_{\rm eff} =-\frac{i\hbar}{2} \sum_{f'}\gamma'_s \left[C_{ff'}^{(0)}\hat{\mathbbm{1}} + \frac{C_{ff'}^{(2)}}{6}(\hat{\mathbf{f}}^2-3\hat{f}_z^2 ) \right],
\end{align}
\end{subequations}
where $ z $-direction is the waveguide axis direction, and $ \hat{\mathbf{f}}^2=\hat{\mathbf{f}}\cdot\hat{\mathbf{f}} $.

By using the transformation relationships of Eqs.\eqref{eq:rotationtransf}, the jump operators become
\begin{subequations}\label{eq:rotationtransf_Wxyz}
\begin{align}
\hat{W}_{x} &= \frac{1}{\sqrt{\gamma_s}}\!\sum_{f'} \frac{\sqrt{\Gamma_{f'}^x}\Omega/2}{\Delta_{ff'}+i\Gamma_{f'}/2} \left[C_{ff'}^{(0)}\hat{\mathbbm{1}} + \frac{C_{ff'}^{(2)}}{6}\left(\hat{\mathbf{f}}^2-3\hat{f}_{z}^2 \right) \right]\\
\hat{W}_{y} &= \frac{1}{\sqrt{\gamma_s}}\!\sum_{f'} -\frac{i\sqrt{\Gamma_{f'}^y}\Omega/2}{\Delta_{ff'}+i\Gamma_{f'}^y/2} C_{ff'}^{(1)}\hat{f}_z  \\
\hat{W}_{z} &= 0.
\end{align}
\end{subequations}

By using the fact that
\begin{subequations}
\begin{align}
\hat{\mathbf{f}}^2 &=f(f+1)\hat{\mathbbm{1}}\\
\hat{f}_z &=\sum_{m=1}^{2f+1}(f-m+1)\hat{\sigma}_{mm}\\
\hat{f}_z^2 &= \sum_{m=1}^{2f+1}(f-m+1)^2\hat{\sigma}_{mm}
\end{align}
\end{subequations}
in the rotating frame, both $ \hat{h}_{\rm eff} $ and $ \hat{W}_{q} $ become diagonal, and Eqs.\eqref{eq:rotationtransf_hloss} and~\eqref{eq:rotationtransf_Wxyz} can be simplified as
\begin{subequations}
\begin{align}
\hat{h}_{\rm eff} &= -\frac{i\hbar}{2} \sum_{f'} \gamma'_s(f') \sum_{m=-f}^f\left[C_{ff'}^{(0)} + \frac{C_{ff'}^{(2) }}{6}(f(f+1)-3m^2) \right]\hat{\sigma}_{mm}\\
\hat{W}_{x} &= \frac{1}{\sqrt{\gamma_s}}\!\sum_{f'} \frac{\sqrt{\Gamma_{f'}^x }\Omega/2}{\Delta_{ff'}+i\Gamma_{f'}^x/2 } \sum_{m=-f}^f\left[C_{ff'}^{(0)} + \frac{C_{ff'}^{(2) }}{6}(f(f+1)-3m^2) \right]\hat{\sigma}_{mm}\\
\hat{W}_{y} &= -\frac{i}{\sqrt{\gamma_s}}\!\sum_{f'} \frac{\sqrt{\Gamma_{f'}^y }\Omega/2}{\Delta_{ff'}+i\Gamma_{f'}^y/2 } \sum_{m=-f}^f C_{f'ff'}^{(1)}m\hat{\sigma}_{mm}\\
\hat{W}_z &=0.
\end{align}
\end{subequations}
After some algebra, one can obtain the optical pumping master equation in the rotating frame as
\begin{align}
\left. \dt{\hat{\rho}}\right|_{\rm op}
&= - \sum_{f'} \gamma'_s(f') \left[\left(C_{ff'}^{(0)}+\frac{f(f+1)}{12}C_{ff'}^{(2)} \right)\hat{\rho}-\frac{C_{ff'}^{(2)}}{4}(\hat{f}_z^2\hat{\rho}+\hat{\rho}\hat{f}_z^2) \right]\nn\\
&\quad+\sum_{f',f''} \frac{\sqrt{\Gamma_{f'}\Gamma_{f''} }\Omega^2/4 }{\Delta_{ff'}\Delta_{ff''}+\Gamma_{f'}\Gamma_{f''}/4+i(\Delta_{ff''}\Gamma_{f'}-\Delta_{ff'}\Gamma_{f''} ) }\nn\\
&\quad\cdot\left\{C_{ff'}^{(0)}C_{ff''}^{(0)}\hat{\rho}+ C_{ff'}^{(0)}C_{ff''}^{(2)}\frac{\hat{\rho}}{6}(\fo^2-3\hat{f}_z^2) + C_{ff''}^{(0)}C_{ff'}^{(2)}(\fo^2-3\hat{f}_z^2)\frac{\hat{\rho}}{6} \right.\nn\\
&\quad\quad + \frac{1}{2}C_{ff'}^{(1)}C_{ff''}^{(1)}(\hat{f}_x\hat{\rho}\hat{f}_x+\hat{f}_y\hat{\rho}\hat{f}_y+2\hat{f}_z\hat{\rho}\hat{f}_z )\nn\\
&\quad\quad -\frac{1}{4}C_{ff'}^{(1)}C_{ff''}^{(2)}(\fx\rhoo\fx-\fy\rhoo\fy-2i\fx\rhoo\fz\fy+2i\fy\rhoo\fx\fz )\nn\\
&\quad\quad +\frac{1}{4}C_{ff''}^{(1)}C_{ff'}^{(2)}(\fx\rhoo\fx-\fy\rhoo\fy-2i\fz\fy\rhoo\fx+2i\fx\fz\rhoo\fy ) \nn\\
&\quad +C_{ff'}^{(2)}C_{ff''}^{(2)}\left[\frac{1}{4}f^2(f \!+\! 1)^2\rhoo \!-\! \frac{f(f \!+\! 1)}{6}(\fo^2 \!-\! \fz^2)\rhoo \!-\! \frac{f(f \!+\! 1)}{6}\rhoo(\fo^2 \!-\! \fz^2) \right.\nn\\
&\quad\quad\quad+\frac{1}{2}\fx^2\rhoo\fx^2+\frac{1}{2}\fy^2\rhoo\fy^2+\frac{1}{4}(i\fz+2\fy\fx)\rhoo(i\fz+2\fy\fx)\nn\\
&\quad\quad\quad +\frac{1}{8}(i\fy+2\fx\fz)\rhoo(i\fy+2\fx\fz)\nn\\
&\quad \quad\quad \left.\left. +\frac{1}{8}(i\fx+2\fz\fy)\rhoo(i\fx+2\fz\fy) \right]\right\}.
\end{align}
As a sanity check, we consider a far-detuning regime where the detuning on hyperfine sublevels is indistinguishable so that we can denote $ f''=f' $ and ignore all tensor polarizability terms where $ C_{ff'}^{(2)} $ presents, and the optical pumping part of the master equation above becomes
\begin{align}
\left.\dt{\rhoo}\right|_{\rm op} &= \gamma'_s  \left[C_{fj'}^{(0)}(C_{fj'}^{(0)}-1)\rhoo+\frac{1}{2}(C_{fj'}^{(1)})^2(\fx\rhoo\fx+\fy\rhoo\fy+2\fz\rhoo\fz ) \right]\\
&= -\frac{2\gamma'_s}{9}+\frac{\gamma'_s}{18f^2}(\fx\rhoo\fx+\fy\rhoo\fy+2\fz\rhoo\fz )
\end{align}
for the far-detuned $ D_1 $- and $ D_2 $-line transitions of cesium atoms,
which is a well-known result in previous studies~\cite{Deutsch2010a,Baragiola2014}.
Above, we have defined $ C_{fj'}^{(0)}=\sum_{f'}C^{(0)}_{ff'}=1/3  $ for $ j'=1/2 $ or $ 2/3 $ for $ j'=3/2 $; $ C^{(1)}_{fj'}=\sum_{f'}C^{(1)}_{ff'}=\pm g_f/3 $ for $ j'=1/2 $ and $ j'=3/2 $, respectively, and $ g_f=1/f $ for our case.

%</opticalpumpingwithmodifiedrates>

%\bibliography{Nanofiber}
%\bibliographystyle{amsplain}
\bibliographystyle{../styles/abbrv-alpha-letters-links}
%\bibliographystyle{unsrt}
% \nocite{*}
\bibliography{../refs/Archive,../chap5/Nanofiber}

\printindex

\end{document}


\section{Object Reconstruction}
\subsection{Tracks}

Building a track, which represents the three dimensional path of the a charge particle, begins with forming hits in both the SMT and CFT tracking detectors. An SMT hit cluster is formed when a group of adjacent silicon strips register enough charge generated from an ionizing charged particle traversing the detector. The presence of the magnetic field in the SMT causes the electron-hole pairs to drift at an angle, known as the Lorentz angle. This drift angle is corrected for when determining the center of the silicon strip. The center of the hit cluster is formed by the charge weighted average of the centers of each silicon strip. The fine granularity of the SMT silicon strips allows an $x$-$y$-$z$ coordinate measurement for each hit in the detector. The axial resolution of an SMT hit is $10~\mu m$ and the $z$ coordinate resolution is $35~\mu m$. A hit in the CFT is formed when the two fibers in each layer register scintillation light indicating the presence of the charge particle traversing the fibers. The $x$-$y$ position of the hit can be measured because each fiber layers is rotated by $3^{\circ}$~with respect to the beam axis. The $z$ hit position is inferred from the $x$-$y$ coordinate measurement and the fibers which produced the signal.
The axial resolution of a CFT hit is $100~\mu m$ and the $z$ coordinate resolution $2$~cm.

A track formed by pattern recognition software that takes SMT and CFT hit clusters as input to form a path in three dimensions, which represents the path of the charged particle. Because the tracking detectors are immersed in a $2$T magnetic field, the paths of the charged particles with be a three-dimensional helix as opposed to a straight line in absence of the magnetic field. The goal of the track finding algorithms is to combine SMT and CFT hits into possible track candidates and determine the parameters which fully define the track helix. There are two track finding algorithms employed in the $\dzero$~event reconstruction software. The first algorithm uses a histogramming technique to find finds and the second algorithm uses a road method technique. These two techniques are described in more detail below. A global track reconstruction algorithm combines the output of the two algorithms to create a final set of reconstructed tracks.

\subsubsection{Histogramming Tracking Finding Method (HTF)}
\label{htf}
The histogramming method works by taking a list of hits in the SMT and CFT and transforming their coordinates transverse coordinates (x,y) into the ($\rho$,$\phi$) plane, where $\rho$ is the track curvature and $\phi$ is the azimuthal angle. The conversion to the new unit is done by a Hough transformation. Hits resulting from the same charged particle and thus the same track parameters will form a peak in this plane. The height of the peak will be $n(n-1)/2$, where $n$~is the number hits. This new histogram then goes through a cleaning procedure, called a 2D Kalman filter, which for the first time includes material related affects such as multiple scattering and energy loss. The Kalman filter has several tunable parameters such as the maximum $\chi^{2}$ of the track fit and the minimum number is SMT and CFT hits. The result of the filter is to have at most one $r$-$\phi$ hit in each layer and modified track parameters. The $z$~coordinate information is included by creating a new histogram in $(r,z)$ and performing a Hough transformation to the $(z_{0},C)$ plane, where $z_{0}$ is the position of the track along the origin and $C$ is the track inclination defined as $C = \frac{dr}{dz}$. Finally, the tracks are extrapolated either inward toward the SMT if the track finding began in the CFT or outward toward the CFT if the track finding began in the inner SMT detector. The histogramming method has advantages over titional road finding algorithms because it does not need to compute all possible combinations of tracks, which grows exponentially with increasing luminosity. The method is also well suited to detectors without distinct layers such as the SMT detector.

\subsubsection{Alternative Algorithm Tracking (AA)}
\label{aa}
The alternative algorithm tracking method works by building a seed track in one layer and building a track by incrementally including more layers of the SMT and CFT detectors. The algorithm begins by taking SMT clusters in the innermost layers and adding additional layers if the axial angle between the next point and the beam spot is less than a certain tunable value. Additional layers are included if the previous condition is true and also if the resulting ius of curvature of the track hypothesis is greater than $30$~cm, which indicates the track must have $p_{T}>180$~MeV. The new track must also have a track fit $\chi^{2}<16$. All possible combinations that meet these requirements are kept in the tracking algorithm for later filtering. The algorithm also allows for missing hits in the SMT or CFT by re-defining the track if a hit in one of the outer layers is consistent with a previously defined track. The number of such missing hits is a tunable parameter in the algorithm. AA tracking also allows for so-called CFT-only tracks built from seeds in the CFT detector that have less than 3 hits in the SMT detector. Allowing tracks to be built in this manner dramatically increases the overall efficiency of the algorithm. The final step in the algorithm is to remove overlapping tracks by selecting the track with the lowest $\chi^{2}$.

\subsection{Primary Interaction Vertex}
\label{pvreco}
The primary hard scatter interaction vertex is very important to locate in to allow discrimination of physics objects resulting from the $\ppbar$~collision and objects created from noise in the detector or other low energy inelastic $\ppbar$~collisions. The primary vertex is defined as the three-dimensional position of the hard-scatter interaction. These vertices are found using the adaptive primary vertex algorithm. The algorithm begins by attempting to assign all tracks with $p_{T}>0.5$~GeV and at least two SMT hits to a vertex where the track paths intersect. The result of this first pass fit to the primary vertex is a $\chi^{2}$ for each track. The algorithm then attempts a second path fit to the primary vertex except this time each track receives a weight, shown in Eq.~\ref{pvweight}, that is contains to the $\chi^{2}$ of the previous fit.

\begin{equation}
\label{pvweight}
w_{i} = \frac{1}{1+e^{(\chi^{2}_{i} - \chi^{2}_{\rm{cutoff}})/2T}}
\end{equation}

The parameters $\chi^{2}_{\rm{cutoff}}$ and T are input parameters to the algorithm and have similar interpretations to the chemical potential and temperature in Fermi statistics. If the weight of the track is less than $10^{-6}$ the track is not included in the next round of fitting. This procedure is repeated until the difference of weights from the previous iteration for each track is less than $10^{-4}$.

The adaptive vertexing algorithm produces a list of possible vertices of which one might be the hard scatter vertex. To determine the hard scatter vertex a minimum bias~\footnote{A minimum bias vertex is a vertex from an inelastic $\ppbar$~collision.} vertex probability is calculated. The probability, shown in Fig~\ref{minbias} peaks at zero for the hard-scatter vertex and is uniform for inelastic $\ppbar$~collision vertices. The vertex used as hard-scatter vertex in an event is the one that has the lowest minimum bias probability. Finally, the vertex resolution of the algorithm for events with no heavy flavor production is 9.3 $\mu$m and 12.8 $\mu$m for events with heavy flavor.

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.45\textwidth]{eps/Reco/MBP_PV.eps}
\includegraphics[width=0.45\textwidth]{eps/Reco/MBP_MB.eps}
\end{center}
\vspace{-0.1in}
\caption[minbias]{Minimum bias probability for the hard-scatter vertex (left) and inelastic $\ppbar$ vertices (right).}
\label{minbias}
\end{figure}

\subsection{Electrons}
Electrons are characterized by narrow electromagnetic showers produced in the electromagnetic calorimeter. Electrons are first identified by searching for a cluster of EM calorimeter towers with energies above a given threshold value. Once a tower is found above threshold the electron candidate is defined as the towers surrounded the highest $E_{T}$ tower in a cone of ius 0.4. Since electrons are light they will deposit almost all of their energy in the first few layers of the electromagnetic calorimeter. Once the electron candidate is found it is required to have at least $90\%$ of it's energy deposited in this region. The shape of the electromagnetic shower induced by the depleted uranium should also be consistent with an electron or photon. The shower shape is fit to the expected shower shape determined from simulation and the resulting $\chi^{2}$ must be less than 50. To remove photons, which will produce similar deposits of energy and shower shapes, the electromagnetic cluster is required to be matched to a track found by the global track reconstruction algorithm. The matched track is then required to have $p_{T}>5$~GeV. To ensure that the electron is well measured it is also required to be narrow and isolated from other electromagnetic clusters. The isolation, defined in Eq.~\ref{fiso}, is required to be less than 0.15

\begin{equation}
\label{fiso}
\rm{f_{iso}} = \frac{E_{tot}(\Delta R <  0.4) - E_{EM}(\Delta R <  0.2)}{E_{EM}(\Delta R <  0.2)}
\end{equation}

Finally to ensure high quality electrons, likelihood discriminant is created using seven variables that will separate electrons from W/Z boson decays from jets with large electromagnetic fractions (fake electrons). Electrons with a likelihood discriminant greater than 0.85 are considered true electrons from a W/Z decay.

\subsection{Muons}
\label{muonreco}
Muon are reconstructed by requiring hits in the layers of the muon system from both the scintillators and the wire chambers. Muons are required to register at least two wire hits and at least one scintillator hit in the A layer. If this condition is met, the muon is required to have at least two wire hits in the B and C layers as well as at least one scintillator hit in this region. By requiring hits in all three layers it is possible to construct a local momentum measurement due to the curvature induced by the toroid magnet; however, typically the resolution of this measurement is quite poor. To improve the resolution, the local muon track is required to be matched to a track found by the global track reconstruction algorithm. The track is required to be $\Delta R<0.5$~from the local muon track. To remove muons produced by cosmic rays the muon is required to arrive at the three muon layers less than $10$~ns after the bunch crossing. To further reduce the cosmic ray background the muon track is required to originate from the primary vertex. The ensure this requirement the muon track must have a transverse distance of closest approach (DCA) less than 0.2 cm if there are no SMT hits and less than 0.02 cm if there is at least one SMT hit for the track. The track is also required to be within 1 cm of the primary vertex in the $z$ direction. The final background contamination to remove are muons from heavy flavor decays (e.g. $B \rightarrow \mu\nu_{\mu} D$). These muons tend to be embedded inside or nearby a jet since they are decay product of the boosted mesons that makeup the jet. To remove this background muons are required to be isolated ($\Delta R(\mu,\rm{jet}) > 0.5$)~from nearby jets. Also, a muon track isolation variable, defined in Eq.~\ref{trackiso}, is required to be less than 0.2.

\begin{equation}
\label{trackiso}
\frac{1}{p_{T}(\mu)} \times \sum_{\rm{tracks \neq muon~ \Delta R < 0.5 }}p_{T}(\rm{track})
\end{equation}

A similar variable for calorimeter tower energies, shown in Eq.~\ref{caliso}, is also required to be less than 0.2.

\begin{equation}
\label{caliso}
\frac{1}{p_{T}(\mu)} \times \sum_{\rm{cal~tower~0.1 < \Delta R < 0.4 }}E_{T}(\rm{cal~tower})
\end{equation}

Muons that satisfy all of these criteria are considered true muons from a W/Z decay.

\subsection{Jets}
\label{jetreco}
A jet is the result of an strong interaction particle, such as a quark or gluon, that hadronizes producing a collection of collimated hadrons traveling in the same direction as the origination parton~\footnote{A parton is a fundamental particle such as a quark or a gluon that is a constituent of a hadron.}. The Run II improved legacy cone algorithm~\cite{Blazey:2000qt} is used to reconstruct jets in the $\dzero$~calorimeter. This algorithm starts with calorimeter towers with transverse energies~\footnote{The transverse energy is the energy of the calorimeter tower weighted by the sine of the polar angle $\theta$ of the tower. $E_{T} = E \times \sin(\theta)$.} greater than $0.5$~GeV and uses them as seeds around which the jet is built. If there is greater than $1$~GeV is total transverse energy in a cone ius if $0.5$ in $y-\phi$~space~\footnote{$y$~is the rapidity of the jet.}, then the collection of towers is considered a jet. The center of the jet is defined by the $E_{T}$ weighted midpoint of each calorimeter tower. If the cone axis of the jet is different from the previous iteration, a new jet is formed and the total $E_{T}$ is again calculated. This process is repeated until a stable jet is found. The result of this process is a list of stable jets with well-defined transverse energy $E_{T}$, rapidity $y$, and, azimuthal angle $\phi$. The final step of the jet finding algorithm is to remove overlapping (duplicate) jets and either split large jets or merge nearby jets. Two overlapping jets are merged if they contain more than half of each others energy in their own jets. If the overlapping jets are not merged, then they are split into two distinct jets whose total $E_{T}$ and cone axis are then recomputed.

Cone jets have several advantages both experimentally and theoretically. Since the jets are defined by rapidity and $\phi$, they are invariant under boosts along the longitudinal direction (beam axis). This is important because the longitudinal boost of the event will typically be large with resepect to the $\ppbar$~rest frame. The other advantage of cone jets is they are infrared safe meaning that one can calculate jet properties in the low energy regime of a theory without incurring singularities.

Once the final list of jets has been created, the final step is to impose a set of quality criteria that will help remove fake jets created out of calorimeter noise and remove electromagnetic particles such as electrons and photons. To remove jets created by electromagnetic particles a jet is require to have between 5 and 95$\%$ of it's energy deposited in the hadronic calorimeter because electrons and photons tend to deposit almost all of their energy in the electromagnetic calorimeter. Also, a jet is required to be isolated ($\Delta R>0.5$) from all electromagnetic clusters in the detector. To remove fake jets created by calorimeter noise, the jet is required to have at least 60$\%$ of it's energy deposited in the fine hadronic calorimeter since this detector gives significantly better energy measurements compared to the coarse hadronic calorimeter. To remove jets created by a single noisy tower all jets are required to have at least two or more calorimeter cells containing at least $90\%$ if the jet energy. Also, the ratio of the most energetic tower to the second most energetic tower must be less than 10.

\subsection{Missing $E_{T}$}
Missing transverse energy, $\met$, is a useful quantity to calculate because it is highly correlated with the energy an undetected neutrino carries away from the events. The missing energy is only calculated in the transverse plane (x-y) because there is no net momentum in this plane since the collision only occurs along the beam axis. The total missing energy of the event can not be calculated however because of the unknown boost along the longitudinal direction from the hard scatter process.  The $\met$~is formed by summing all calorimeter cells in the electromagnetic and fine hadronic calorimeters and then balanced so there is no net transverse momentum in the event. The $\met$ is further corrected for high $p_{T}$ leptons in the event. The total $\met$ is defined in Eq.~\ref{met}.

\begin{equation}
\label{met}
\left[~\sum_{\rm{cells}} E_{T}~\right]+ p_{T}(\ell) + \rm{ME}_{T} = 0
\end{equation}

\subsection{$B$-Jets}
\label{bidreco}
Events with heavy flavor jets (jets formed from initial $b$ or $c$ quarks) are important to measure because many fundamental particles, such as the top quark, will decay into a $b$ quark leaving it as one of the few signatures of it's existence. Jets formed from $b$ quarks are unique from other jets produced from light quarks because the $B$~meson (a combination of a $b$ quark and a light quark) has a much longer lifetime than lighter mesons. The result of this long lifetime is a displaced decay vertex from the primary interaction vertex. The typical decay length, which is the distance from the decay vertex from the primary vertex, is $\sim$few mm. The goal of the $B$-jet finding algorithm is to use this information and more to identify heavy flavor jets from ordinary light flavor jets.

The $B$-jet selection algorithm at $\dzero$~uses a neural network (NN) to separate events with heavy flavor (B,D mesons) from light flavor events. The neural network is trained on seven variables that show discrimination between heavy and light flavor events. The seven variables are shown in Table~\ref{nnvars}. The neural network takes as input good quality jets and the tracks which point towards those jets. All jets must have at least two associated tracks with $p_{T}>1$~GeV. Jets that fail these criteria are considered light jets. The network was trained with $Z\rightarrow b\bar{b}$ and direct QCD $b\bar{b}$ production as heavy flavor signal-like events and $Z\rightarrow q\bar{q}$ and QCD $q\bar{q}$ production as light flavor background-like events. The output of the neural network is new probabilistic variable which peaks at 1 for jets with heavy flavor and 0 for light flavor jets. A jet is considered a $B$-jet if the NN value is greater than 0.775. For this choice of NN cut, the average $b$-tagging efficiency for central jets is $47\%$ and a light jet mis-tag rate of $0.47\%$.

\begin{table}[!h!tbp]
\begin{center}
\begin{tabular}{c|c}
\multicolumn{2}{c}
{\underline{Variables Used in $B$-jet Neural Network}} \\
Rank	&	Variable Description	\\
\hline
1		&	Decay length significance ($\frac{L_{T}}{\delta L_{T}}$) of the displaced vertex	\\
2		&	Weighed combination of the input tracks' impact parameter significance ($\frac{IP}{\delta IP}$)	\\
3		&	Probability that the jet originates from the primary interaction vertex	\\
4		&	$\chi^{2}$/N$_{dof}$ of the displaced vertex fit	\\
5		&	Number of tracks used to reconstruct the displaced vertex	\\
6		&	Mass of the tracks used to reconstruct the displaced vertex	\\
7		&	Number of displaced vertices found inside the input jets		\\
\end{tabular}
\vspace{-0.1 in}
\caption[nnvars]{Variables used in the neural networks training. The variables are listed in order of relative importance as determined in the training.}
\label{nnvars}
\end{center}
\end{table}


\subsection{Memory Resistor}

In 2008, a group of researchers from HP labs published a paper entitled \textit{``The missing memristor found''} \cite{hp_memristor_found}. What, then, is a memristor, and how did we know it was missing? A memristor (short for memory resistor) is a resistor with memory whose resistance depends on the past flows of current passed through the circuit. The resistance of a memristor is increased by current travelling through it in one direction, and decreased by current travelling through it in the other direction. A memristor is a passive circuit which remembers its resistance even when inactive and without power for long periods of time. These properties make memristors interesting candidates for non-volatile storage and memory units, as they retain their state when unpowered, and specifically as they enable storage of continuous ranges of values (i.e. low \textit{through} high resistance) in contrast to discrete binary values (i.e. 0 \textit{or} 1) \cite{memristors_a_new_frontier}.

Back in 1971, Leon Chua, often referred to as the father of non-linear circuit theory, laid the mathematical foundation detailing the relations between the four fundamental circuit elements. Interestingly, at that time only three fundamental circuit elements had physical counterparts, namely resistors, capacitors and inductors. The fourth fundamental circuit element, the memristor, was only conceptualized in theory by Chua for the sake of symmetry (see figure \ref{fig:circuit_elements}). As outlined in Chua's seminal paper \textit{``Memristor-the missing circuit element''} \cite{chua_memristor}, the current-$I$ voltage-$V$ curve of a memristor has a unique shape, an IV-fingerprint if you will, in the form of a pinched hysteresis loop (see figure \ref{fig:pinched_hysteresis}). A hysteresis loop indicates that a system has an internal state (i.e. memory) which affects the output of the system and which depends on past inputs to the system \cite{memristor_hayes}. As famously state by Chua, \textit{``If it's pinched it's a memristor''} indicates that the hysteresis loop of a memristor passes through the origin.

\begin{figure}[htbp]
	\begin{center}
		\includegraphics[width=0.5\textwidth]{inc/circuit_elements.png}
		\caption{Fundamental circuit elements.\protect\footnotemark}
		\label{fig:circuit_elements}
	\end{center}
\end{figure}
\footnotetext{Original image (CC BY-SA): \url{https://en.wikipedia.org/wiki/File:Two-terminal_non-linear_circuit_elements.svg}}

\begin{figure}[htbp]
	\begin{center}
		\includegraphics[width=0.5\textwidth]{inc/pinched_hysteresis.png}
		\caption{IV-curve of a memristor circuit, arrow indicates time.\protect\footnotemark}
		\label{fig:pinched_hysteresis}
	\end{center}
\end{figure}
\footnotetext{Original image (© Brian Hayes): \url{https://www.americanscientist.org/libraries/documents/201128120228377-2011-03CompScienceHayes.pdf}}

Ever since 2008, there has been an exponential increase in research related to memristors, where the number of search results for ``memristor'' on Google Scholar has doubled every 18-24 months \cite{memristors_a_new_frontier}. Why are so many researchers attracted to this new field of research? To answer this question, lets first evaluate the suitability of using current computer architectures in highly adaptive systems, such as brain-like learning systems with neural and synaptic placticity (i.e. adaptivity).

Machine learning research has managed to achieve some truly remarkable milestones in recent years (e.g. AlphaGo beating the human world champion in Go \cite{alphago}), both reaching and surpassing human potential on a number of tasks for which the brain is tailored towards, such as face recognition \cite{facenet}, classification, and abnormality detection. Given this resent development, it may be tempting to imagine that it is only a matter of time until these machines achieve general problem solving skills through highly adaptive learning, which is fundamental for general artificial intelligence.

However, the very nature of adaptivity introduces a significant challenge for today's computer architectures as it is inherently dependent on mutable states to reflect changes in the environment. To model these changes in state, data has to be shuffled back and forth between the processor and memory. The separation of processing and memory access is the underlying cause of two significant problems with current computer architectures. Firstly, it restricts the potential for parallel computation \cite{net_doing_all_the_work} and introduces a set of complex workarounds (e.g. mutual exclusion, cache line invalidation). Secondly, and perhaps more importantly, a substantial amount of energy is required just to shuffle data back and forth between the processor and memory \cite{ahah}.

There exist a huge discrepancy between the energy requirements of adaptive learning systems implemented in nature by biological brains and those implemented in silicon by machine learning algorithms running on von-Neumann computers. The difference in energy efficiency for adaptive learning tasks is estimated to be around 9 orders of magnitude. To put this into perspective, the brain would be able to travel around the entire earth on the same amount of energy that current computers would require to travel one and a half inches \cite{memristors_a_new_frontier}. This is one compelling reason why researchers are interested in understanding the inner workings of the brain, so that fundamental principles for energy efficient adaptive learning may be derived and modelled.

%Current computer architectures are designed around major bottlenecks, huge amounts of data has to be shuffled back and forth to perform computations. Reaching its limits; transistors now so small that they only allow a single electron to pass through (similar in size to the ion channels). At this scale, problems arise when transistors may allow electrons to pass through, when they shouldn't and wise versa; which leads to unpredictable behaviour (small bursts of ones when should be be all zero, and wise versa.)

% NOTE:
% * Discripancy
%    - Discripancy between computers and biology in terms of energy efficiency when used for highly adaptive systems, such as a synaptic network.
% * Root cause
%    - the adaptive power problem, von-Neumann bottleneck.
% * Why are they interesting?

% ref: Tim Molter HiPeac Prague 2016 Memristor Keynote
%
% Denser memory, faster read and write, lower energy use, non-volatile, and may represent continuous (i.e. not 0 and 1).

% ref: Tim Molter HiPeac Prague 2016 Memristor Keynote
%
% 1 billion fold discrepancy between current machine learning platforms and biological brains.
%
% We can operate on very low voltages because of the read and write phases that constantly repair relevant state.

% === [ Subsections ] ==========================================================

\input{sections/2_models_of_associative_memory/3_memory_resistor/1_artificial_synapses}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{microtype}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{commath}
\usepackage{mathrsfs}

\usepackage[backend=biber, style=alphabetic]{biblatex}
\addbibresource{documentation.bib}

\usepackage{graphicx}

\usepackage{hyperref}
\usepackage[noabbrev]{cleveref}
\usepackage{tabularx}
\usepackage{threeparttable}
\usepackage{enumitem}

\usepackage{siunitx}

\usepackage{listings}
\lstset{language=Matlab}

\usepackage{keystroke}

\usepackage{algorithm}
\usepackage{algpseudocode}

\newcommand{\C}{\mathbb{C}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\scrS}{\mathscr{S}}
\newcommand{\scrH}{\mathscr{H}}
\newcommand{\SD}{\mathsf{SD}}
\DeclareMathOperator{\FP}{FP}
\DeclarePairedDelimiter{\inp}{\langle}{\rangle}

% russian integral
\usepackage{scalerel}
\DeclareMathOperator*{\rint}{\scalerel*{\rotatebox{17}{$\!\int\!$}}{\int}}

\newcommand{\df}{\textit}

\theoremstyle{definition}
\newtheorem{ex}{Example}

\title{Documentation}
\author{Alex Elzenaar}
\date{\today}

\begin{document}
  \maketitle

  \tableofcontents

  \section{Overview}
  The purpose of this MATLAB software package is to generate putatively optimal
  spherical $(t,t)$-designs \autocite{waldron2018}.

  The package itself will only work on newer versions of MATLAB (it has been tested
  on R2018b and above); it depends on the following packages beyond those that are
  part of the `standard' MATLAB release:-
  \begin{itemize}
    \item Statistics and Machine Learning Toolbox
  \end{itemize}

  In addition, should the user wish to use the \texttt{generate.py} Python script to create
  a nice index for their generated designs, they will require:
  \begin{itemize}
    \item The MATLAB Engine API for Python\footnote{This is included by default with MATLAB but must be specifically installed. Documentation may be found at the
          following URL: \url{https://au.mathworks.com/help/matlab/matlab-engine-for-python.html}}
  \end{itemize}

  \section{Software usage}
  In this section, we describe how the user can use the algorithm implementation to generate
  putatively optimal spherical designs.

  MATLAB files are located in the \texttt{matlab/} subdirectory; all the scripts and procedures
  are implemented in MATLAB unless otherwise stated.

  \subsection{The \textproc{tightframe} method}
  The main method available is \textproc{tightframe}; this method takes the parameters
  listed in \cref{tab:tightframe_params} and produces the tuple of return values listed
  in \cref{tab:tightframe_returns}. Broadly speaking, the purpose of this method is to
  produce a putatively optimal spherical $(t,t)$-design of $ n $ vectors in $ \C^d $; the
  three parameters here ($ d $, $ n $, and $ t $) are the most likely ones to be changed.
  The fourth parameter, $ k $ (the number of iterations) is also one that most users might
  wish to manipulate. The final parameters listed in the table allow the caller
  to modify and fine-tune specific parts of the algorithm, and will be described in a later section.

  \begin{ex}\label{ex:dnt_2_4_2}
    The following command computes a putatively optimal $ (2,2)$-design consisting of four vectors in $ \C^2 $:-
    \begin{lstlisting}
[result, errors, totalBadness] =...
  tightframe(2, 4, 2, 5000, 100, 10, 5000, 1, 1);
    \end{lstlisting}
  \end{ex}

  The errors obtained over time may be plotted by MATLAB using the following commands:
  \begin{lstlisting}
t = 1:length(errors);
plot(t,errors);
hold on;
set(gca, 'YScale', 'log');
  \end{lstlisting}
  An example plot corresponding to \cref{ex:dnt_2_4_2} is included as \cref{fig:example_error_plot}.
  The plot produced should resemble an exponential decay curve, because as the number of iterations increases
  the step size of the algorithm towards the variety of designs decreases proportionally.

  The only return value of \textproc{tightframe} which is obscure to understand is $ totalBadness $; when
  this value is large compared to the total number of iterations, it means that the algorithm had trouble
  finding a design (in the sense that it took many tries to get a single step closer to the variety of
  designs). We shall make this more precise in a later section.

  \begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{example_error_plot}
    \caption{The error plot of a run with low badness.\label{fig:example_error_plot}}
  \end{figure}

  \begin{ex}
    \Cref{fig:example_error_plot_2} shows a error plot of an example with extremely high badness (0.913); and
    \cref{fig:example_error_plot_3} shows an example with medium badness (0.706).\footnote{Badness numbers will
    usually be quoted as proportions:- $ totalBadness/k $ where $ k $ is the number of iterations completed.}

    Note that in general a high badness corresponds to two characteristics of the error curve:
    \begin{itemize}
      \item A very long, shallow tail (i.e. for large $ x$-ordinates on the graph, $ \od{y}{x} \approx 0 $). This
            is particularly noticable in \cref{fig:example_error_plot_2}.
      \item A very `blocky' curve shape consisting of stretches of zero gradient interspersed with periods of
            extreme decline. This can be seen in \cref{fig:example_error_plot_3}.
    \end{itemize}
    The shallow tail corresponds to the fact that the algorithm decreases its step size according to the total
    badness (we shall discuss this in detail in a later section); the blockiness occurs because if it is `hard'
    for the algorithm to find a better candidate for the design then the error will remain constant over long
    stretches.

    Both of the graphs in this example were generated with $ (d,n,t) = (3,5,3) $, and it
    is known that there is no such design (see, e.g. the list given in \autocite[\S 6.16]{waldron2018});
    this explains why the asymptote of the error graph is non-zero (in this case, it
    appears to be $ \approx 26 $).
  \end{ex}

  \begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{example_error_plot_2}
    \caption{The error plot of a run with high badness.\label{fig:example_error_plot_2}}
  \end{figure}

  \begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{example_error_plot_3}
    \caption{The error plot of a run with medium badness.\label{fig:example_error_plot_3}}
  \end{figure}

  \begin{table}
    \begin{threeparttable}
    \begin{tabularx}{\linewidth}{r|X|l}
      \textbf{Parameter} & \textbf{Description} & \textbf{Sane value}\\\hline
      $d$ & Dimension of the space to embed the design into.\\
      $n$ & Number of vectors in the design.\\
      $t$ & Parameter of the $ (t,t)$-design.\\
      $k$ & Number of iterations of the algorithm to run before returning.\\
      $s$ & Number of inital seed matrices to check. & \num{1e6}\\
      $b$ & Number of attempts at walking down the line of the gradient before falling back to looking at a ball. & \num{10}\\
      $ap$ & Number of times to run alternating projection on each iteration. & \num{10}\thinspace\tnote{a}\\
      $errorMultiplier$ & Scale factor for the walking distance at each iteration. & $1\times 10^{-4}$\thinspace\tnote{b}\\
      $fd$ & MATLAB file descriptor for progress output. & 1\thinspace\tnote{c}
    \end{tabularx}
    \begin{tablenotes}\footnotesize
      \item[a] According to \autocite[\S7.2.7]{tropp2004}, increasing $ ap $ beyond around \num{5000} does not significantly
               change the results obtained. However, note that in that thesis the projection algorithm itself is the convergence
               procedure (as opposed to the current project, in which a separate convergence step is performed). Thus we only
               need to run the projection a small number of times (and in fact larger numbers here will cause the Gram matrix
               to drift away from the line of descent towards a low value of $ \FP $).
      \item[b] If $ n $ is large, $ errorMultiplier $ should be made very small. For $ n \leq 4 $,
               $ errorMultiplier \approx \num{1e0} $ is OK; then decrease by powers of 10 from there. If
               the number is too large, it is more likely that the algorithm will go too far past the
               variety of $ (t,t)$-designs. If in doubt, set this small (especially if the badness proportion
               ends up high on test runs) and increase $ k $.
      \item[c] Set to `1' for console output; for file output set to \texttt{fopen('<filename>', 'w')}.
    \end{tablenotes}
    \end{threeparttable}
    \caption{Parameters for the \textproc{tightframe} method.\label{tab:tightframe_params}}
  \end{table}

  \begin{table}
    \begin{threeparttable}
    \begin{tabularx}{\linewidth}{r|X}
      \textbf{Return value} & \textbf{Description} \\\hline
      $result$ & A $ d \times n $ matrix consisting of $ n $ column vectors in $ \C^d $ which is putatively optimal
                 according to the error function.\\
      $errors$ & A $ k \times 1 $ matrix where the $ i$th value is the minimum error of the best design found by
                 iteration $ i $.\\
      $totalBadness$ & The total number of times that the algorithm failed to improve the estimate by walking
                       down the gradient. A more `efficient' run minimises $ totalBadness/k $ (where $ k $ is the
                       number of iterations).
    \end{tabularx}
    \end{threeparttable}
    \caption{Return values for the \textproc{tightframe} method.\label{tab:tightframe_returns}}
  \end{table}

  \subsection{The \texttt{runtf} script}
  The \textproc{tightframe} method is useful if the user wants to script the algorithm (e.g. try to run it for
  lots of values of $ n $ to find the minimal $ n $ such that a $ (t,t)$--design in $ \C^d $ exists). However,
  if the user does not need this power they will probably want to use the wrapper script in \texttt{runtf.m}.

  In order to change the design parameters (the same as those listed in \cref{tab:tightframe_params}, the user
  should change the first few lines of \texttt{runtf.m}; then the script (when run) will produce the following:
  \begin{itemize}
    \item The console output from \textproc{tightframe} in the console verbatim.
    \item A printout (to the default number of decimal places) of the returned $ d \times n $ matrix $ result $.
    \item A printout of the final error of that design (i.e. $ \FP_{\C^d,n,t}(result) $).
    \item A printout of the overall badness proportion $ totalBadness/k $.
    \item The parameters used for the generation of the design, together with the $ result $ matrix, the $ totalBadness $, and the list of $ errors $
          in the file \verb|tf_run_YYYY-MM-DD-HH-MM-SS.mat| (in the current directory).
    \item A plot of the best error over time (displayed on screen as a MATLAB figure).
  \end{itemize}

  \subsection{The \textproc{compute3Products} method}
  This method takes a single argument --- a $ d \times n $ matrix $ A $ --- and computes the set of all $ n^3 $ 3--products of the vectors of $ A $,
  sorted according to the MATLAB \textproc{sort} method.

  \subsection{The \texttt{generate.py} script}
  The purpose of this script, located in the top-level directory, is to take a directory of \texttt{.mat} files generated
  by the \texttt{runtf} method and produce a folder containing a nice HTML index of the generated designs.

  The script takes one required argument --- the directory in which to look for the \texttt{.mat} files. If the \texttt{-R}
  flag is specified, then the script will search recursively; otherwise it will search only the directory given and no subdirectories.
  For each \texttt{.mat} file it finds, the script will check whether it contains a variable called \texttt{result}. If it does,
  then it is copied to the output directory (default is \texttt{html/}, but this may be changed using the \texttt{-o} flag). An
  \texttt{index.html} file is also generated in the output directory containing a list of all the found designs, along with some
  parameters ($d$, $n$, $t$, and $k $ from \cref{tab:tightframe_params}, along with the error of the design found).

  If the flag \texttt{-e} is set, the script will attempt to connect to a running MATLAB instance; otherwise it will try to start
  MATLAB itself. If connection to an existing MATLAB instance is needed, the user should note that some user interaction is required:
  a command needs to be run in the MATLAB console and then the \Enter key needs to be pressed to make the script continue. The command
  needs only be run once for a given MATLAB instance, and to avoid the prompt one can give the flag twice (\texttt{-ee}).

  The up-to-date usage information for the script may be viewed by running \texttt{python generate.py -h}.

  \section{Mathematical background}
  Let $ \scrH $ be a finite-dimensional Hilbert space of dimension $ d $ (so, as a vector space,
  $ \scrH \simeq K^d $ for some field $ K $), and let $ \scrS_\scrH(n) $ be the set of finite
  sequences of $ n $ elements of $ V $ with unit norm:
  \begin{displaymath}
    \scrS_\scrH(n) := \{ (v_i)_{i = 1}^n : \forall_i (v_i \in V \text{ and } \norm{v_i} = 1) \}.
  \end{displaymath}

  Suppose $ S $ is the unit sphere in $ \scrH $, let $ \sigma $ be a normalised measure
  on $ S $, and suppose we have picked an orthonormal basis $ (w_i)_{i = 1}^d $ on $ \scrH $.
  Let $ \pi $ be the projection map from $ \scrH $ onto the subspace spanned by $ w_1 $,
  and for each $ t \in \N $ define the \df{bound weighting} $ c_t(\scrH) $ to be the (real) quantity
  \begin{displaymath}
    c_t(\scrH) = \left(\rint_S \norm{\pi v}^{2t} \dif{\sigma(v)}\right)^{-1}.
  \end{displaymath}
  (Remark: the quantity $ c_t(\scrH) $ is independent of the choice of basis.)

  Finally, define the functions $ \FP_{\scrH,n,t} : \scrS_\scrH(n) \to \R $ by the rule
  \begin{equation}\label{eqn:fp}
    \FP_{\scrH,n,t} : (v_i)_{i = 1}^n \mapsto
          c_t(\scrH) \sum_{i = 1}^n \sum_{j = 1}^n \abs{\inp{v_i, v_j}}^{2t}
            - n^2.
  \end{equation}
  The value of $ \FP $ for a given design is called the \textit{error} of that design.

  Define the set $ \SD_\scrH(n,t) := \FP_{\scrH,n,t}^{-1}(0) $; the elements of this set
  are called \df{spherical $ (t,t)$-designs} of order $ n $, embedded in $ \scrH $. (These
  designs obviously also depend on $ \sigma $, the spherical measure --- but usually this
  comes naturally with $ \scrH $.)

  If $ \scrH = \R^d $ or $ \scrH = \C^d $ (with the usual inner product and with $ \sigma $
  the normalised surface area measure of the sphere) then one can precalculate the following
  values \autocite[122]{waldron2018}:-
  \begin{displaymath}
    c_t(\R^d) = \frac{d(d+2)\cdots(d+ 2(t-1))}{1\cdot3\cdot5\cdots(2t-1)},
    \qquad
    c_t(\C^d) = \binom{d+t-1}{t}.
  \end{displaymath}

  The data of a design may be summarised by a $ d \times n $ matrix $ V $ whose columns form
  the $ n $ column vectors of the design with respect to the basis $ (w_i) $. A frequently
  more useful representation, however, is the $ n \times n $ \df{Gram matrix} of the design:
  \begin{displaymath}
    \Gamma((v_i)_{i=1}^d) = [V^* V] = [\inp{v_j,v_i}_{i,j}].
  \end{displaymath}

  It can be shown that the Gram matrix $ \Gamma $ has the following properties:
  \begin{enumerate}[label=(G\arabic*)]\label{pg:gram_properties}
    \item $ \Gamma $ is Hermitian;
    \item $ \Gamma $ has unit diagonal;
    \item $ \Gamma $ is positive definite;
    \item $ \Gamma $ has rank $ d $;
    \item $ \Gamma $ has trace $ n $.
  \end{enumerate}
  Note that (1) and (2) are conditions on the \emph{entries} of $ \Gamma $, while (3), (4), and (5) are conditions
  on the \emph{spectrum} of $ \Gamma $.

  We may also find the gradient of $ \FP_{\scrH,n,t} $ with respect to the entries of the Gram
  matrix: we may rewrite $ \FP $ in terms of $ \Gamma $ as
  \begin{displaymath}
    \FP_(\scrH,n,t) : \Gamma \mapsto c_t(\scrH) \sum_{i = 1}^n \sum_{j = 1}^n \abs{\Gamma_{j,i}}^{2t} - n^2
  \end{displaymath}
  and taking the partial derivatives of this, we obtain
  \begin{displaymath}
    \pd{\FP}{\Gamma_{i,j}} = t\thinspace c_t(\scrH)\thinspace \abs{\Gamma_{i,j}}^{2(t-1)} \thinspace \overline{\Gamma_{i,j}};
  \end{displaymath}
  thus to decrease the frame potential we must perturb the Gram matrix in the direction $ -\nabla \FP $
  where $ (\nabla \FP)_{i,j} = \pd{\FP}{\Gamma_{i,j}} $.

  \section{Algorithms implemented}
  In this section we will give pseudocode for the operations that are implemented by this
  package, along with explaining various design choices and limitations of the approach.

  \subsection{The high-level method}
  The high-level method is implemented in \textproc{tightframe}, listed in \cref{alg:high_level}.
  The algorithm as described here does not take the $ fd $ parameter listed in \cref{tab:tightframe_params},
  as this is only used to print status updates.

  We begin by choosing a good starting Gram matrix (line \ref{line:seed}). We generate $ s $ different matrices
  with the properties (G1)--(G5) (the `seed' matrices), and pick the one which minimises the potential function
  to begin the iteration with.

  The actual iteration begins on line \ref{line:tf_iter}; the variable $ badCount $ holds the number of iterations
  since the current best matrix $ A $ was found, and if $ badCount < b $ we attempt to walk down the gradient
  a small random amount. The mean distance to walk, $ \frac{error \times errorMultiplier}{totalBadness + 1} $,
  is proportional to $ error $ (so when we are `close' the distance we walk decreases), and inversely proportional
  to $ totalBadness $ (so if we keep failing to find a good choice the step size decreases).

  If $ badCount $ exceeds the parameter $ b $, we stop trying to walk down the gradient and instead we pick
  random matrices from the `ball' $ B $ around $ A $ of mean distance $ error\times errorMultiplier$. The idea here
  is that if the badCount is high then we keep trying and failing to walk along the line of steepest descent
  towards the variety of $ (t,t)$--designs, and so the path of steepest descent must be twisting sharply away
  from the path it has been taking (\cref{fig:badness_illustration}). The amount we try to walk along the path
  of steepest descent keeps decreasing as the badness (i.e. failure rate) increases, but if the path is very
  twisty then this permanently makes the walk distance tiny and so the convergence rate will become very slow.
  Instead, if the $badCount$ becomes large, we instead look at the ball $ B $ (dotted blue) of (relatively) large radius, in
  the hope that we will hit upon the path of steepest descent again after it has rounded the corner, we will tend
  to skip part of the path and rejoin it on a straighter section (the dotted arrow on the figure) without having to
  drop our rate of walking too far. This can be seen in the console output: long runs of \texttt{*** Better found, ...} tend to
  accompany very small decreases of the error, while occasional blocks of \texttt{Nothing better}  tend to be followed by a sharp decrease
  in the error. In order to take advantage of this, a healthy \texttt{badnessProportion} should be around 0.7.

  \begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{badness_illustration}
    \caption{An intuitive depiction of the way counting `badness' allows the algorithm to skip twists in the path of steepest descent.\label{fig:badness_illustration}}
  \end{figure}

  In either case we have picked a new random candidate for Gram matrix near $ A $; we call it $ A_\mathrm{new} $.
  Since the randomisation process does not guarantee that $ A_\mathrm{new} $ is Hermitian, we project it onto
  the space of Hermitian matrices (line \ref{line:make_hermitian}); then we attempt to project it onto the space
  of matrices satisfying the properties (G1)--(G5). This is done by the method \textproc{alternatingProjection}
  described below; \textproc{tightframe} passes into this method the parameter $ ap $ to modify the accuracy
  of the alternating projection algorithm, as well as the matrix $ A_\mathrm{new} $ and the desired rank $ d $.

  Finally, we compute the error of the resulting matrix; if it is lower than the current best we set the $ badCount $
  back to zero; otherwise we increase both $ totalBadness $ and $ badCount $.

  When the loop is done, we are left with a Gram matrix $ A $ satisfying (G1)--(G5). The final diagonalisation process
  undoes the map $ V \mapsto \Gamma = V*V $ which produces the Gram matrix from the initial vectors. The resulting
  $ n \times n $ matrix will have $ n - d $ zero rows (by consideration of the rank of $ A $) and so we project down
  to $ \C^d $ in the natural way to produce the final matrix $ result $ which is returned.

  \begin{algorithm}
    \caption{The high-level method}\label{alg:high_level}
    \begin{algorithmic}[1]
      \Procedure{tightframe}{$d,n,t,k,s,b,ap,errorMultiplier$}
        \State Find a good starting matrix $ A $ which satisfies properties (G1)--(G5) by checking $ s $ different
               matrices, $ A_1,...,A_s $ and calculating $\FP_{\C^d,n,t}(A_i)$ for each. \label{line:seed}
        \State $ error \gets \FP_{\C^d,n,t}(A) $
        \State $ errors \gets [] $
        \State $ badCount \gets 0 $
        \State $ totalBadness \gets 0 $
        \State $ h \gets 1 $
        \While{$ h \leq k $} \label{line:tf_iter}
          \State Append $ error $ to $ errors $.
          \If{$badCount < b $}
            \State $ \delta \gets $ a random positive value near $ \frac{error \times errorMultiplier}{totalBadness + 1} $
            \State $ A_{\mathrm{new}} \gets A - \delta \nabla\FP_{\C^d,n,t}(A) $
          \Else
            \State $ \Delta \gets $ an $ n \times n $ matrix of random values near $ (error \times errorMultiplier) $
            \State $ A_{\mathrm{new}} \gets A + \Delta $
          \EndIf
          \State $ A_{\mathrm{new}} \gets \frac{A_{\mathrm{new}} + A_{\mathrm{new}}^*}{2} $\label{line:make_hermitian}
          \State Project $ A_{\mathrm{new}} $ onto the space of matrices satisfying (G1)-(G5).
          \State $ error_\mathrm{new} \gets \FP_{\C^d,n,t}(A_{\mathrm{new}}) $

          \If{$error_\mathrm{new} < error$}
            \State $ A \gets A_\mathrm{new} $
            \State $ error \gets error_\mathrm{new} $
            \State $ badCount \gets 0 $
          \Else
            \State $ badCount \gets badCount + 1 $
            \State $ totalBadness \gets totalBadness + 1 $
          \EndIf
        \EndWhile

        \State $ U \gets $ the $ n \times n $ matrix of eigenvectors of $ A $
        \State $ D \gets $ the diagonal matrix of corresponding eigenvalues
        \State $ result \gets D^{1/2}U $
        \State Delete the zero rows of $ result $, producing a $ d \times n $ matrix (by rank of $ A $).
        \State Return $ (result, errors, totalBadness) $.
      \EndProcedure
    \end{algorithmic}
  \end{algorithm}

  \section{Further work to be done}
  \begin{itemize}
    \item Allow users to pass in an error function to be minimised.
    \item Add support for real designs.
    \item Save all generated designs in a database.
    \item Implement an algorithm to partition generated designs into unitary equivalence classes.
  \end{itemize}

  \printbibliography
\end{document}


\subsection{BRKGA implementation}

\subsubsection{Chromosome structure}

Since in this problem all the nurses are equal in terms of schedule, to exploit the diversification of the chromosoem we have chosen between two approaches. The firsts is to assign each gene of the chromosome in order to each hour of the schedule (chromosome length $hours$). This ways we can sort the hours of the schedule and assign nurses to hours in that order. The other choice is instead to define an excess of working nurses for each hours, that is, to increase the demand of each hour randomly by the chromosome. We choose the second approach as it appears to diversify more in the initial tests that we have performed (around 20\% of different fitness between individuals in each breed versus only around 5\% for the first approach).

\begin{algorithm}[H]
\KwIn{chromosome, hours, demand, nNurses}
%\Parameter{Some parameter}
\KwOut{demand}

\SetKwData{Left}{left}
\SetKwData{This}{this}
\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}
\SetKwFunction{FindCompress}{FindCompress}

i = 0 \\
\ForEach{$gene$ $\in$ $chromosome$}{

	\If{$gene < 0.2$}{
		$new\_hourly\_demand = ceil(demand_{i} \cdot 0.8 \cdot nNurses)  $ \\
		$demand_{i} = new\_hourly\_demand$ \\
	}
	$ i += 1$\\

}

$\textbf{return}$ demand
\caption{BRKGA Decoding algorithm}\label{brkga.decoding}
\end{algorithm}

\subsubsection{Decoder}

\begin{algorithm}[H]
\KwIn{population, nNurses, hours, demand, constraints}
%\Parameter{Some parameter}
\KwOut{population}

\SetKwData{Left}{left}
\SetKwData{This}{this}
\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}
\SetKwFunction{FindCompress}{FindCompress}

\ForEach{$individual$ $\in$ $population$}{
new\_demand $\leftarrow decoding(individual, hours, demand, nNurses, constraints)$ \\
population $\leftarrow assignNurses(solution, nNurses, hours, new\_demand)$ \\
}
$\textbf{return}$ population
\caption{BRKGA Decoder algorithm}\label{BRKGA.decoder.mainLoop}
\end{algorithm}

As illustrated in $Algorithm$ \ref{BRKGA.decoder.mainLoop}, the decoder simply decodes each individual chromosome with $Algorithm$ \ref{brkga.decoding}, and calls $assignNurses$ to assign the nurses according to the newly computed $new\_demand$. Each solution is stored in the population with its corresponding fitness already computed in the $assignNurses$ function ($Algorithm$ \ref{BRKGA.assignNurses}).

\begin{algorithm}[H]
\KwIn{solution, nNurses, hours, new\_demand, constraints}
%\Parameter{Some parameter}
\KwOut{solution}

\SetKwData{Left}{left}
\SetKwData{This}{this}
\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}
\SetKwFunction{FindCompress}{FindCompress}

\ForEach{$h \in hours$}{
	$mustWorkList, canWorkList = computeCandidateAssignments(solution, h, constraints)$\\
	\ForEach{$n \in mustWorkList$}{
		$ assignWorkingHour(solution, n, h)$\\
		$ demand_{h} \leftarrow updateRemainingDemand(solution,h)$\\
	}
	\ForEach{$n \in canWorkList$}{
		\If{$demand_{h} > 0$}{
			$ assignWorkingHour(solution, n, h)$\\
			$ demand_{h} \leftarrow updateRemainingDemand(solution,h)$\\
		}
	}
}

\If{$Feasible(solution)$}{
	$solution(fitness) \leftarrow computeFitness(solution)$ \\
}
\Else{
	$solution(fitness) \leftarrow \infty $
}

$\textbf{return}$ solution
\caption{assignNurses}\label{BRKGA.assignNurses}
\end{algorithm}

As shown in $Algorithm$ \ref{BRKGA.assignNurses}, this algorithm assigns nurses to the schedule according to the demand and the constraints. For each possible hour in the schedule, in order, the algorithm selects the nurses that should work at this specific hour according to the constraints, and the nurses that could work at this specific hour according to the constraints (line 2). The function $computeCandidateAssignments$ walks through all the nurses, assigning the current hour and verifying if the nurse schedule is valid according to the constraints. From that "canWorkList", it walks through all the nurses from that list, removing the assignment in the specific hour and verifying if the schedule would be valid or not. That way it creates the second "mustWorkList" with nurses that must work to have valid schedules, removing them from the first list in order to have two disjoint sets. Once the two lists are set, it first assigns all the nurses that must work to have a valid schedule (lines 3 to 5). Each time, the remaining demand is updated (line 5). Then it walks throught the list of nurses that can work and assign the hour if and only if the remaining demand in that specific hour is positive (line 8). The final solution is then updated with its fitness, which is the same as the cost or number of nurses that work any hour during the schedule. If the solution is not feasible, that means that the demand is not fulfilled in each hour, then the fitness is set to be infinite or big enough.