\chapter{Simulation} The ratios of positrons to the electrons impinging the tungsten production target, T1, was substantially smaller after they traversed the beam line than what was produced at the target (10$^{-15}$ instead of 10$^{-3}$). Simulations were performed using G4beamline to better understand the losses from the transportation of positrons to the experimental cell. ``G4beamline is a particle tracking and simulation program based on the GEANT4~\cite{geant4} toolkit that is specifically designed to easily simulate beamlines and other systems using single-particle tracking~\cite{muonsinc}.'' A sample G4beamline script for positron generation using the new HRRL beamline is given in the appendix F. The simulation predicts that at least one positron per 1000 incident 10~MeV electrons is produced using a 2~mm thick tungsten target. The simulation revealed that the number of electrons decreased by orders of magnitude as they were transported through some of the beamline magnets. As a result of this beam loss, the simulation was divided into three steps to increase the beam line simulation efficiency. Each step generates particles at different locations along the beamline where the beam loss was found to be substantial. While the first simulation step used the measured electron energy profile, subsequent steps would generate particles based on the particle phase space observed at the end of previous step. The method decreased the simulation time so a sample of more than one million events could be produced within a single day. The first step in the simulation generated an electron beam with the energy distribution observed in the experiment, see Figure~\ref{fig:En-Scan}. The electrons were focused by three quadrupoles onto the positron production target T1 (see Figure~\ref{fig:app-hrrl-line}). Electrons traversing T1 produced bremsstrahlung photons of sufficient energy to produce $e^+e^-$ pairs that would escape the downstream side of the target and be collected by a second quadrupole triplet. The second step simulated the collection and transportation of positrons exiting T1 to the entrance of the first dipole D1. The last step transported positrons from the entrance of D1 all the way to the annihilation target T2, the interactions of positrons with T2, and the detection of the resulting 511~keV photon pairs. The two targets (T1 and T2) were positioned at different angles with respect to the incident beam momentum vector. The beamline coordinate system aligns the z-axis to point along the incident electrons momentum vector and the x-axis along the horizontal plane. The positron production target, T1, was placed such that the upstream side of T1 was facing vertically down at a 45$^{\circ}$ angle with respect to the vertical(rotated 45$^{\circ}$ counter clockwise about x-axis). The positron conversion target, T2, was rotated about two different axes. The first rotation positioned the upstream side of the target so it was facing down by 45$^{\circ}$ (rotated 45$^{\circ}$ clockwise about x-axis like T1). The second rotation was 45$^{\circ}$ about y-axis. As a result, target T2's upstream face was directed towards the beam right NaI detector. \section{Step 1 - The Electron Beam Generation and Transportation to T1} In the first simulation step, an electron beam was generated with an energy distribution that was observed in the experiment. The emittance, the Twiss parameters, and the energy distribution of the electron beam were measured experimentally. The energy distribution of the electron beam is shown in Figure~\ref{fig:En-Scan}. The distribution was fit using two skewed Gaussian distributions. The fit parameters given in Table~\ref{tab:En-Scan_resluts} were used by the simulation to generated electrons. A series of virtual detectors were placed along the beamline to sample the beam. As an example, three virtual circular detectors and T1 are shown in Figure~\ref{fig:T1_UpD_DwD2}. The electron beam was detected by a virtual detector DUPT1 (Detector UPstream of T1) placed 25.52~mm upstream of T1. Positrons, electrons, and photons generated during the interaction of the electron beam with T1 were observed by virtual detectors DT1 (Detector of T1) and DDNT1 (Detector DowNstream of T1) placed 25.52~mm downstream of T1. \begin{figure}[htbp] \centering \includegraphics[scale=0.55]{3-Simulation/Figures/sim_setup_T1_UpD_DwD2.png} \caption{The T1 positron target and virtual detectors used in the simulation. DUPT1 is a virtual detector located upstream of T1 to detect the incoming electron beam. DDNT1 is a virtual detector downstream of T1. DT1 is a virtual detector that is placed right after T1 and parallel to it.} \label{fig:T1_UpD_DwD2} \end{figure} \subsection{The Positron Beam on DDNT1} In the first step, $1.38 \times 10^{10}$ electrons were generated with the energy distribution shown by the dotted-dashed line in Figure~\ref{fig:SimS1_T1UPDN}. These electrons were transported to T1 where they produced photons that produced the positron distribution shown by the solid the line in Figure~\ref{fig:SimS1_T1UPDN} by pair-production. The dashed line is the electron energy distribution observed by DDNT1. The simulation result using $1.38 \times 10^{7}$ electrons incident on T1 is drawn in Figure~\ref{fig:SimS1_T1UPDN}. The incident electrons were detected by the virtual detector DUPT1 and downstream positrons and electrons were detected by DDNT1. As shown in Figure~\ref{fig:SimS1_T1UPDN}, the electrons pass through T1 loosing approximately 4~MeV while the positrons escape the downstream side of T1 with a mean energy of about 3~MeV. The beam line was set to transport positrons with this mean energy as a result of this prediction. \begin{figure}[htbp] \centering \includegraphics[scale=0.75]{3-Simulation/Figures/s/s1/overlay9.eps} \caption{The incident electron energy distribution (dotted dashed line), the distribution of electrons after T1 (dashed line), and the distribution of positrons produced (solid line). The incident electron distribution counts were weighted by 0.001.} \label{fig:SimS1_T1UPDN} \end{figure} \begin{figure}[htbp] \begin{tabular}{cc} {\scalebox{0.364} [0.364]{\includegraphics{3-Simulation/Figures/X_e+_DDNT1.eps}}} & {\scalebox{0.364} [0.364]{\includegraphics{3-Simulation/Figures/Y_e+_DDNT1.eps}}} \\ (a) $x$ projection. & (b) $y$ projection. \\ {\scalebox{0.364} [0.364]{\includegraphics{3-Simulation/Figures/XP_e+_DDNT1.eps}}} & {\scalebox{0.364} [0.364]{\includegraphics{3-Simulation/Figures/YP_e+_DDNT1.eps}}} \\ (c) $x$ projection of the divergence. & (d) $y$ projection of the divergence.\\ {\scalebox{0.364} [0.364]{\includegraphics{3-Simulation/Figures/XY_e+_DDNT1.png}}} & {\scalebox{0.364} [0.364]{\includegraphics{3-Simulation/Figures/XY_e+_DDNT1_zoom.png}}} \\ (e) The transverse beam profile. & (f) Zoom in of (e). \\ \end{tabular} \caption{The transverse beam projections and angular distributions of positrons detected. The virtual detector diameter is 30~mm while the beam pipe is only 24~mm.} \label{fig:DDNT1_results} \end{figure} The positron spatial and angular distribution detected by DDNT1 is shown in Figure~\ref{fig:DDNT1_results}. The $y$ vs. $x$ spatial distribution of the beam is shown in Figure~\ref{fig:DDNT1_results}~(e) and Figure~\ref{fig:DDNT1_results} (f). As can be seen from Figure~\ref{fig:DDNT1_results} (b) and (d), the $y$ spatial distribution and divergence, defined in equation~\ref{eq:divergence}, of the positron beam have a sharp drop in counts in the region between $-25.8$~mm and $-27.2$~mm from the beam center. Figure~\ref{fig:sim-DDNT1-T1-geo} shows the geometry and location of T1 and DDNT1. If the size of T1 were to be increased, it would eventually intersect with DDNT1 at a distance between $25.8$~mm and $27.2$~mm from the beam center, $i.e.$ the edge of the T1 is facing this $1.4$~mm wide low count area. \begin{figure}[htbp] \centering \includegraphics[scale=1]{3-Simulation/Figures/sharp_drop2.eps} \caption{The geometry of the target T1 and the virtual detector DDNT1.} \label{fig:sim-DDNT1-T1-geo} \end{figure} As shown in Figure~\ref{fig:DDNT1_YpY}, the $y$ distribution count decreases at $\theta$ = 45$^{\circ}$. Positrons were emitted from both the downstream and upstream side of T1. Positrons from the downstream side of T1 intersected the detector at angles below 45$^{\circ}$ while positrons from the upstream side of T1 begin to hit the detector at angles beyond 45$^{\circ}$. Neither positrons upstream nor downstream of T1 traveled to the 1.4~mm wide low count area. Only positrons created on the edge of T1 reached the low count area between 25.8~mm~$