\section{\label{mc:sec4}

The physics simulation for \hd\ is provided by a program called
\emph{HDGeant}.  The simulator requires four data interfaces:
an event source, detector geometry data, simulation control
information, and event output.  HDGeant is capable of simulating
events from any one of three sources.

\begin{list}
\item events from a Monte Carlo generator
\item coherent bremsstrahlung source generator
\item automatic single-track generator (for testing)
\end{list}

The first of the three is an external event source described in
section \ref{mc:sec2}.  Events from the generator are distributed
uniformly along the length of the beam-target interaction volume
and final-state particles followed out into the detector from there.
The other two sources are internal to the simulator, and are used
for special purposes.  The coherent bremsstrahlung source generates
uncollimated photons with the energy, angle and
polarization characteristics of bremsstrahlung
from an oriented diamond radiator.  These photons enter the
setup upstream of the primary collimator and are followed through
the collimator region into the experimental hall, where
interactions in the detector are allowed to take place.  This
simulation mode is useful for estimating detector backgrounds,
and for studing the systematics of the collimated photon beam.
The single-track generator is used for development of various
parts of the simulation, and will be useful later in debugging
the event reconstruction package.

The choice of the source for input events is specified in an input
file known as the \emph{control} file.  Also in the control file are
a number of switches that control the simulation mode, such as
the number of events to simulate, cutoffs for a variety of physics
processes, and debug options.  HDGeant obtains the detector geometry
directly from the standard geometry interface.  Input events from
the Monte Carlo generator are accessed through the the standard event
interface implemented in the hddm library.  Output events are likewise
written out using the hddm library.

The output from the simulation is a list of \emph{hits}, which are
time and energy data from each detector element that received a signal
during the propagation of the event through the detector.  The hit
data are stored in physical units appropriate to the signal
(eg. ns, MeV) which is what the simulation directly produces.
No provision is made in the simulator to convert these data back into
ADC or TDC data in the form produced by the data acquisition hardware;
that would require couple the simulation to the the detector calibration
database, and introduces an unnecessary complication to the simulation.
If events in that form were desired at some point, a separate
converter could be written to generate simulated raw events from the
simulator output.

The major effort in the ongoing development of the simulation is to
have a reasonably accurate model of the detector response in each
of the detector elements.  A basic model presently exists in the code
for each of the detector components.  These must be improved by the
incorporation of intrinsic resolutions for each of the detectors.
For example, the impact parameter of tracks in a straw tube of the
central drift chamber is converted to a hit time value using a simple
linear model for the time {\it vs} radius.  For another, for the
response of the lead-glass calorimeter, the total energy loss of
charged particles is reported as the hit energy, without taking into
account the difference in the \v{C}erenkov response between different
kinds of particles.  Nevertheless, in its present form the simulator
is useful for estimating many aspects of detector performance.

In addition to the detector hits, the simulation is also capable
of writing out certain kinds of auxilliary information about the
simulated event, for example the actual 3-d points of track impacts
on the planes of the forward tracker or the true energy of a photon
creating a cluster in the barrel calorimeter.  Such information is
called \emph{cheat} data because it is not available for real events.
However it is invaluable for Monte Carlo studies prior to the
development of event reconstruction code, and will be useful in
that development for checking the fidelity of the reconstruction.

In Table~\ref{table:g3speed} is shown the average time required to
simulate a single event on a cpu that is available today, for a
few sample reactions.  The beam simulation uses the simulator's
internal coherent bremsstrahlung generator, and exercises mainly
the electromagnetic shower simulation in the collimator region
upstream of the detector.  The single-track case is included to show
the cost of tracking charged particles through the the magnetic
field.  The gammas show the corresponding cost for photons.  The
two are put together in the reactions which follow.

\begin{table}
\begin{center}
\begin{tabular}{lc}
\hline\hline
    uncollimated beam	    			& 	\\
    1GeV $\pi^+$ at 15$^{\mbox{\rm o}}$ 	&	\\
    3GeV $\gamma$ at 15$^{\mbox{\rm o}}$ 	&	\\
    1GeV $\gamma$ at 45$^{\mbox{\rm o}}$ 	&	\\
    $\gamma p \rightarrow \pi^+\pi^ p$		&	\\
    $\gamma p \rightarrow \pi^+\pi^-\pi^0 p$	&	\\
    $\gamma p \rightarrow \eta\pi^0\pi^0 p$	&	\\
\hline\hline
\end{tabular}
\end{center}
\caption[Average event simulation times for HDGeant]
{Average time required by HDGeant to simulate a single event of
various kinds.  The tests were carried out on a single Pentium III
1GHz processor.}
\label{table:g3speed}
\end{table}

In order to obtain a reliable simulation of backgrounds from the
collimator region, two enhancements to the standard Geant simulation
library were incorporated into HDGeant.  The first of these is
the addition of hadronic interactions by photons in materials, and
the second was Bethe-Heitler muon pair production.  The standard
Geant electromagnetic shower simulation does not include hadronic
photoproduction processes or muon pair production because their cross
sections are several orders of magnitude less than the dominant
electromagnetic processes and their presence is generally not
important to simulating calorimeter response.  For the purposes of
\hd\ however, the high intensities of showers in the collimator
enclosure and the heavy shielding against electromagnetic backgrounds
makes them important.  In particular there are two kinds of penetrating
radiation that must be considered: neutrons and high-energy muons.

The incorporation of muon Bethe-Heitler production into Geant was
straight-forward to do, simply by replicating the code for electron
pair production with a changed mass, and the cross section reduced
by the factor $m_e^2/m_{\mu}^2$.  The inclusion of photonuclear
processes is more daunting.  Rather than launch a development of
our own, it was decided to incorporate a package that was developed
earlier for use by the BaBar experiment known as \emph{Gelhad}
\cite{Gelhad}.  This package breaks provides four models of hadronic
photoproduction that are applicable at different scales: single
nucleon knockout, two-nucleon knockout via the quasi-deuteron process, 
single pion photoproduction in the delta-resonance region, and
diffractive vector production in the diffractive region.  From the
point of view of photonuclear physics, this model is far from
complete.  It will not be used by \hd\ to generate photoproduction
events in the target.  What it does provide is a starting point for
estimating neutron fluxes in the hall from the collimator region.

The present HDGeant package is based on the widely-used version 3
of the CERN Geant library.  Discussion has started regarding moving
the development for \hd\ over to the c++ simulation package known
as Geant4 that is being used by some of the LHC experiments.  Given
that the Geant-3 library is written almost entirely in Fortran and
is no longer being actively supported by the CERN computer division,
its long-term viability depends upon support by the user community.
The LHC Alice experiment has taken the major components of Geant-3
and wrapped them for use in a c++ environment known as \emph{AliRoot}.
The choice of a long-term solution for a physics simulation for \hd\
has not yet been finalized.  
