

\section{Trigger}

\subsection{Overview}

In order to achieve the roughly 20-1 reduction in event rate, Hall D will use a 
two-stage trigger, combining a hardware-based level 1 trigger with a software (reconstruction) based level 3
trigger.  An essential feature of the \hd\ design is to build pipelining into the entire trigger, digitizer, and
data acquisition systems at the outset.
This has the twin virtues of allowing adequate time for the level 1 trigger to
do its job, while eliminating signal degradation involved in delaying the signals while the trigger operates.  Pipelining in this way also allow us to upgrade from initial photon fluxes of $10^7$ photons/sec to eventual
fluxes of
 $10^8$ photons/sec without any significant changes to the trigger/DAQ architecture. Eliminating conversion deadtimes will allow us to acquire events which occur very close together in time.

Figure \ref{trigger:alexs} shows a schematic of the implementation of the
\hd\ level 1 trigger.  
\begin{figure}[htbp]
  \begin{center}
    \mbox{\epsfig{file=ch8_level1.eps,width=0.85\textwidth,height=0.63\textwidth}}
  \end{center}
  %%\vspace*{-0.45in}
  \caption{A schematic diagram of the \hd\ trigger. \label{trigger:alexs} }
\end{figure}
The level 1 trigger makes a decision based on detector elements
which measure
hadronic multiplicities (track counts) and energies.  In the schematic shown,
the start counter and barrel calorimeter and forward TOF detectors provide the track
count
while the barrel and forward calorimeters determine the energy.  A tight
tagger OR/start counter coincidence  is used as input to the
level 1 trigger
for low photon fluxes of $\approx 10^7$ photons/sec.

For high photon fluxes ($ \approx 10^8$ photons/sec),
the tagger OR/start counter coincidence is not a useful requirement, and the level 1 trigger will probably only be able to cut the rate down from 385 KHz to around 180 KHz.  Most of this background comes from multi-pion events caused by untagged (low energy) photons.  In order to reduce this rate by a factor of 10, a very accurate reconstruction of the photon energy is required. 
 Because of the complexities involved in accurately determining track momenta and then linking information from
the different detectors, we believe the best approach is to use a software level 3 trigger embedded in the DAQ
architecture, rather than to build a series of specialized level 3 trigger processors.  This level 3 trigger
will do a simplified full reconstruction of the event, using all  of the data, in order to throw out events from
low energy photons.

\subsection{Level 1 trigger}
\label{sec:lev1trigger}

The level 1 trigger consists of five subsystems, and a global trigger processor (GTP) 
which combines these five outputs into the global level 1 trigger.  Each of the subsytems continuously (via a
digital pipeline) computes a parameter, then compares it against a number of programmed value/function pairs. A
value function pair might be an energy value and a $<$, =, or $>$ function. When any of the
value/function requirements is satisfied, the subsytem sends a timestamped subsystem event report (SER) to the
GTP.  The GTP is programmed with a number of different level 1 trigger configurations, each combining different
value/function pairs from the subsystems, along with a trigger coincidence window (TCW) specifying the maximum
time window for coincidence of the different trigger requirements.

The five level 1 trigger subsystems are:

\begin{enumerate}
\item {\textbf{A track count} - obtained from the start counter.  The
start counter discriminator
signals are used to create the prompt OR for coincidence with the tagger,
but are also
sent into a \emph{track count pipeline} to determine the number of tracks.
The sample rate
for the pipeline would be 4\nstunit\ (250\mhz). Two different track counts may be programmed, each
 with a $<$, =, or $>$ criterion attached.}

\item {\textbf{A track count} - obtained from the barrel calorimeter.  The discriminator signals from
the central calorimeter are sent into another \emph{track count pipeline} which
determines the number
of tracks.  This pipeline runs synchronously with the start counter track
count pipeline. Two different track counts may be programmed, each 
with a $<$, =, or $>$ criterion attached.}

\item {\textbf{An energy sum} - obtained from the barrel calorimeter.
The barrel calorimeter will be digitized by 8
bit, 250\mhz\ flash \adc s (\fadc ).
All channels are then digitally added together (in a pipeline tree) to form the barrel calorimeter energy sum.
These adders are pipelined at the same 250\mhz\ rate, giving an energy
measurement every 4\nstunit\ for use in the \emph{Level 1 Trigger}.
The energy sum then passes through a shift register thus making available a
time window.
Successive samples within this time window are added together.
This is analogous to the gate width in a conventional charge sensitive \adc.
Two different energy values may be programmed, each with a $<$, =, or $>$ criterion attached.}

\item {\textbf{A track count} - obtained from the forward TOF.
Discriminator signals from the
forward TOF are sent into a \emph{track count pipeline} which determines
the number of
tracks.  This pipeline runs synchronously with all the other level 1
pipelines. Two different track counts may be programmed, each 
with a $<$, =, or $>$ criterion attached.}

\item {\textbf{An energy sum} - obtained from the forward calorimeter.
This sum is constructed in the same manner as for the central calorimeter, except that the selection of which digitized analog sums
are added together to form the forward energy sum, is programmable.  Two different energy values may be
programmed,  each with a $<$, =, or $>$
criterion attached.}
\end{enumerate}

As mentioned above, the GTP may be programmed with several different triggers.  Programming a single trigger means selection of

\begin{enumerate}
\item {Either a minimum, maximum, or exact number of tracks in the start
counter.}
\item {A minimum, maximum, or exact number of tracks in the barrel calorimeter.}
\item {A minimum, maximum, or exact number of tracks in the forward TOF.}
\item {A minimum or maximum for the global energy in the barrel calorimeter.}
\item {A minimum or maximum for the global energy in the forward
calorimeter.
Certain areas might be programmed out of this sum.}
\item {The appropriate boolean combination of elements 1-5.}
\end{enumerate}

The
trigger will
have the capability to have at least eight simultaneously defined triggers.
This trigger is very flexible and can be programmed to be very loose (say
one track in
the start counter) or very tight (specific track counts and energy
thresholds in each
detector). Examples of triggers which can be programmed in this model
include:

\begin{enumerate}
\item {At least two tracks in the start counter AND at least one track in
the downstream TOF.}
\item {At least one track in the start counter AND a minimum energy in the
downstream
calorimeter.}
\item {At least two tracks in the start counter AND at least one track in
the barrel calorimeter
AND a minimum requirement of  energy in the barrel calorimeter AND a
minimum requirement
in the forward calorimeter.}
\end{enumerate}


All subsystems will run synchronously and will be timed so that the
time stamps from average momentum tracks ($\sim$ Ebeam/3) will match at the GTP. Higher and lower momentum
tracks will be slightly out of time, but this effect should be less
than 20\nstunit, and this is compenstated for by programming the TCW value.
The synchronous output of the level 1 trigger
will then be ANDed with the coincidence of the tagger OR and the start
counter OR.  This allows the timing to be determined by the tagger and
start counter, and removes the synchronous nature of the trigger.


The rate of the global level 1 trigger, $f_{L1}\times R_0$, is taken to
be the total hadronic rate\footnote{The cosmic-ray rate is small and has
been neglected.} reduced by the rate for single pion production for
E$_\gamma~ \leq$ 0.5 \eunit\ ($f_{L1}=0.5$). 
A loose trigger which uses a
charged particle track count in the start counter and requires neutral
energy in the barrel and/or forward calorimeter 
% (see Section \ref{sec:lev1trigger} below) 
% Section 7.2.2 in current version
should easily be able to eliminate these low energy events. 
The resultant level 1 trigger rate is about 180 \khz.
We note, however,
that 80\% of the hadronic rate comes from photons with energies below
2 \eunit.  This energy cut, which would require a more sophisticated trigger,
would reduce the level 1 rate to 70 \khz.


\subsection{Trigger simulation}
\label{sec:triggersim}

As mentioned above, background events are typically due to low energy
photons, resulting in low energy events.  Not only are these
background events lower in energy, but they are also less forward, due
to reduced Lorentz boost. Thus, good events typically deposit a
larger fraction of their energy in the forward calorimeter, and have
more tracks and hits in the forward time-of-flight. The goal of the
Level 1 trigger is to use these differences to cut as large a fraction
as possible of the background events, while minimizing the number of
good events lost. The goal for the data reduction in the level 1
trigger is to remove at least 50\% of the background events, without
losing more than 0.5\% of the good events.

In order to test the the trigger, the six reactions listed in Table
\ref{table:triggercuts} were simulated and studied.  The simulated 
events include two low energy delta production channels, and four
interesting physics channels at low (background) and high energies.

Reaction events were generated using \emph{Genr8}~\cite{Genr8}.  After
generation the events were then run through \emph{HDGeant}
~\cite{hdgeant} for simulation. This provided the necessary data needed.
For each reaction 10,000 events were generated giving 120,000
events. Using \emph{Java Analysis Studio (JAS)}~\cite{Jas}, graphs
were generated that provided insight as to what was happening. 

\begin{eqnarray}\label{eqn:cutfunc}
Z & >= & A*[Number Tracks Forward TOF] \\
  & + & B*[Energy Forward Cal] \nonumber \\
  & + & C*\frac{[Energy Forward Cal + 1]} {[Energy Barrel Cal + 1]} \nonumber
\end{eqnarray}

On the basis of preliminary investigations, it was decided to use a
function of the form given in Eq. \ref{eqn:cutfunc}.
A genetic algorithm was used to optimize the coefficients of the
function.  As shown in Table \ref{table:triggercuts} the best set 
of coefficents cut nearly all of
the delta's and most of the low energy background events.  On average
72\% of the background events are cut, while no single good event
channel lost more than 0.5\%.

One problem with using a genetic alogrithm is deciding how to score the
individual solutions so that an optimal solution is found.  The
approach taken was to weight the scoring function such that keeping
good events was given a higher score than cutting background events.
If good events were cut then it would be penalized and if it cut too
many then the score received was zero.  

\begin{table}[htb]
  \caption{\label{table:triggercuts}Trigger cut rates for reactions
  and their energies.}
\begin{center}
  \begin{tabular}{|l|c|c|}
\hline
 \multicolumn{1}{|c|}{Reaction} & Energy(GeV) & Percent Cut \\
\hline
\hline

$\label{reaction:1}\gamma p \rightarrow  {{\rho}^{0}} {{\pi}^{{+}}} n  \rightarrow n {{\pi}^{{+}}} {{\pi}^{{-}}} {{\pi}^{{+}}}$ 
  & $1$ & $67.99\%$\\
\cline{2-3}
 ~ & $2$ & $41.68\%$ \\
\cline{2-3}
 ~ & $9$ & $0.05$\% \\
\hline
\hline
$\label{reaction:2}\gamma p\rightarrow {\rho} p \rightarrow p {{\pi}^{{+}}} {{\pi}^{{-}}}$ 
  & $1$ & $70.48\%$\\
\cline{2-3}
 ~ & $2$ & $54.82\%$ \\
\cline{2-3}
 ~ & $9$ & $0.50\%$ \\
\hline
\hline
$\label{reaction:3} \gamma p\rightarrow X^{*}(1600) n \rightarrow (\eta^{0} {{\pi}^{{+}}}) n  \rightarrow n {{\pi}^{{+}}} {\gamma} {\gamma}$ 
& $1$ & $90.10$\% \\
\cline{2-3}
 ~ & $2$ & $56.24\%$ \\
\cline{2-3}
 ~ & $9$ & $0.11\%$ \\
\hline
\hline
$\label{reaction:4} \gamma p \rightarrow X^{+}(1600) {\Delta}^{0} \rightarrow ({{\pi}^{{+}}} {{\pi}^{{+}}} {{\pi}^{{-}}}) (n \pi^{0}) \rightarrow {{\pi}^{{+}}} {{\pi}^{{+}}} {{\pi}^{{-}}} n {\gamma} {\gamma}$ 
& $9$ & $0.23\%$\\
\hline
\hline
$\label{reaction:5}\gamma p\rightarrow {\Delta}\rightarrow n {{\pi}^{{+}}}$ 
& $0.337$ & $99.99\%$\\
\hline
\hline
$\label{reaction:6}\gamma p\rightarrow {\Delta}\rightarrow p {{\pi}^0}$ 
& $0.337$ & $98.75\%$\\
\hline
\end{tabular}
\end{center}
\end{table}

