%\subsubsection{plan}
%\begin{itemize}
%\item two stage: alcapana then rootana
%\item alcapana is online analysis as well as primary midas -> root conversion
%\item rootana is the main offline analysis
%\item Waveform Analysis
%\begin{itemize}
%\item Pulse Candidate Finder
%\item Amplitude: MaxBin
%\item Timing: Constant Fraction
%\item Calibration: Timing offsets, Pedestals, Energy scales
%\end{itemize}
%\item Event Correlating:  Fast and Slow coincidence
%\item Event Correlating:  Muon events
%\end{itemize}

\begin{figure}[htbp]
  \centering
    \includegraphics[width=0.7\textwidth]{figs/WaveformAnalysis.png}
    \caption{Illustration of the waveform analysis techniques used in Rootana.}
  \label{fig:waveform_reco_demo}
\end{figure}


%The analaysis of the Alcap data is split between two main stages, known as
%Alcapana and Rootana.  
The AlCap DAQ delivers data as compressed MIDAS files. These are then
handled in two stages.  In the first stage (Alcapana), 
some preliminary analysis is
performed and the MIDAS files unpacked into a ROOT format.  These are then
passed through the second stage (Rootana) for physics analysis.

\subsubsection{Alcapana}
The MIDAS files produced by the DAQ contain both the digitised
waveform outputs
and the run-time DAQ configuration.  Alcapana is the first point in the
processing chain to look at this data and performs two roles: 1) it 
provides some preliminary, semi-online analysis, 2) it converts the 
MIDAS data into a ROOT format.  

The analysis produces simple histograms of quantities such as amplitude,
timing, and pulse island length.  It also creates persistency-style 
overlays of each
waveform in the event.  These histograms are placed in an output file which can
then be loaded into a simple ROOT-based GUI where results can be displayed
rapidly and help to understand the data quality.
%Much of this was implemented during the run and by the end the alcapana
%analysis and displays formed a strong and user-friendly tool-kit.

Since each digitiser is run in a self-trigger mode within a MIDAS block, the
output waveforms contain, in principle, a single pulse stored as a vector of
ADC samples. The waveform digitisers stamp each pulse with a trigger time-stamp relative to the
start of the MIDAS block.  Each of these time-stamped ADC vectors is referred
to as a Pulse Island.  Occasionally a
real pulse may be split over two Pulse Islands. Therefore, during the
unpacking in Alcapana Pulse Islands are with adjacent time-stamps are
checked to concatenated into a single pulse when necessary.
The treatment of the $\mu$PC detector is slightly different as it is readout using a discriminator and TDC, and so does not use the same waveform format for raw data.

\subsubsection{Rootana}
Most of the physics analysis is performed in Rootana.  The framework is
designed to be easily configured by dividing the analysis into
modules which can be called and reconfigured at run-time through a
configuration file.  Most processing chains begin with waveform analysis so
the module for this delegates the work to runtime selectable `generators' which
implement the actual waveform analysis.  Then the program searches for
correlations or coincidences between different detectors in order 
to produce the final physics results.

\subsubsection*{Waveform Analysis}
The general approach to waveform analysis
uses the following methodology:
\begin{description} 
\item [1. Find Pulse Candidates:] Remove pulse islands which are just noise and
divide pile-up pulses into two separate pulse islands.
%
%\item [2. Subtract Pedestal] 
%
\item [2. Amplitude and Time reconstruction:] Use the Max Bin method (sometimes
Peak Sample method) to extract the amplitude followed by a Constant Fraction Timing
process using a linear interpolation between the two bins closest to the
peak-sample which crosses a given fraction of the pulse's amplitude.  See Fig.
\ref{fig:waveform_reco_demo} for an illustration of these techniques.
%
\item [3. Apply Calibration Constants:] Account for cable delays and 
similar effects in
the timing and convert the amplitude to energy.  The constants 
are obtained from a prior data pass which calculates the timing and
pedestal data, or from a dedicated calibration datasets in the case of energy
constants.
\end{description}

We are investigating alternative methods of waveform analysis using
pulse-averaging in order to produce a template followed by fitting or 
convolution of the
original waveform.  Since the analysis shown below has not used these
methods, 
they will not be described here.

\subsubsection*{Pulse Correlation}
There are two types of pulse correlation used in the analysis: 
1) correlation of
pulses between the fast and slow filtered read-out channels of a
single detector, 
and 2) correlation of pulses between all detectors.  The first method 
provides a
cross check on the data quality, but results in a reduction of the overall
dynamic range of the detector since the correlation is only meaningful for
pulses with energies within the intersection of the individual 
dynamic ranges of each channel.
The second method is used when pulses are correlated between
detectors. It 
is implemented
by restructuring the dataset into what are known as ``Muon Events''.  Individual
pulses on the $\mu$Sc are used as a reference point and all pulses which occur
within a certain time window (typically 15~\textmu s) are collected together into
a single muon event.  Should two or more $\mu$Sc pulses occur within this window,
the event is marked as a muon pile-up event.  It is then trivial to scan
over each muon event, applying various cuts, in order to build a
spectrum of interest.

Since the bulk of the correlation work is done by inspecting the timing of
pulses on different channels, the accuracy of the time offsets due to
 cable delays is particularly important.
