A Monte Carlo simulation of the experiment has been developed using the GEANT4 toolkit. A visualisation of the implemented geometry is shown in Figure~\ref{fig:geant-vis}.

\begin{figure}[htbp]
  \centering
  \subfigure{
    \includegraphics[scale=0.4,trim=100 50 100 100,clip]{figs/geant-vis}
    \label{g4}
  }
  ~%
  \subfigure{
	  \mbox{
    \includegraphics[scale=0.20,trim=200 0 200 0,clip]{figs/geant-vis_eventDisplay}
    }
    \label{g4_ed}
  }
  \caption{Visualisations from the AlCap Monte Carlo simulation.  Left: The implemented geometry for an aluminium target. Right: An event display where a muon stops in the target, emitting a proton which is stopped in the right silicon detector package.}
  \label{fig:geant-vis}
\end{figure}

The simulation is written in such a way that most aspects of it can be easily modified by editing various text files that exist for the geometry, the initial particle distribution and the output variables.

%The geometry configure files define and place all volumes. Some of these are placed within each other but ultimately they all placed within the ``world'' volume. By editing this file, properties of each volume can be changed to suit the simulation study being done. For example, the thickness and material of the target can be changed to simulate the experimental set-up of a different dataset. In addition, it is in this file that the volumes that are designated the ``sensitive'' volumes are defined. It is in these volumes where the properties of particles are read out.

The initial particle distribution configure files (also called the generator configure files) are used to define the particles that are created at the beginning of the experiment. These files contain the particle type, starting position, and initial momentum. The distributions of these latter two can be defined as a simple random uniform or Gaussian distributions or a distribution stored in a ROOT histogram can be used. This is especially useful if a previous simulation has generated a more realistic distribution that should be used. For example, after running a simulation where muons are fired at the target, a 3D histogram of the muon stopping positions can be created and used in future simulations.

%Finally, the output configure file defines the variables that are read out of the simulation. This includes, for example, each particle's momentum and energy deposited in the sensitive volumes as defined in the geometry configure file. Also, certain condition can be specified in this configure file so that only particles passing a certain cut will be recorded which can aid in reducing the output file size and allowing more statistics for a specific result.
