\section{Res\_monitor: The monitor for resolution calculation}
\label{s:res_monitor}
\index{Monitors!Resolution monitor|see{Samples/Resolution function}}

%\component{Res\_monitor}{(System); Alan Tennant, HMI}{$x_\textrm{min}$, $x_\textrm{max}$, $y_\textrm{min}$, $y_\textrm{max}$, filename, res\_sample, buffer size}{$x_w$, $y_h$, $z_t$, options}{}
\mcdoccomp{misc/Res_monitor.parms}

The component \textbf{Res\_monitor} is used for calculating the
resolution function of a particular instrument with detector of the
given shape, size, and position.
The shape of \textbf{Res\_monitor} is by default rectangular,
but can be a box, a sphere, a disk, or a cylinder,
depending on the parameter ``options''.
The component works like a normal monitor, but
also records all scattering events and stores
them to a file that can later be read by 
the \MCS frontend tool \verb+mcresplot+.

For time-of-flight (TOF) instruments, {Res\_monitor} should be understood 
as giving the resolution of one time bin of the TOF-detector only; 
the bin properties being specified in the preceding \textbf{TOF\_Res\_sample}.

As described in section~\ref{s:res_sample},
the \textbf{Res\_monitor} should be used in connection with one of the
components \textbf{Res\_sample} or \textbf{TOF\_Res\_sample}, 
the name of which should be passed as an
input parameter to \textbf{Res\_monitor}. For example
\begin{lstlisting}
    COMPONENT mysample = Res_sample( ... )
    ...
    COMPONENT det = Res_monitor(res_sample_comp = mysample, ...)
    ...
\end{lstlisting}

The output file is in ASCII format, one line per scattering event, with
the following columns:
\begin{itemize}
\item $\textbf{k}_\textrm{i}$, the three components of the initial wave vector.
\item $\textbf{k}_\textrm{f}$, the three components of the final wave vector.
\item $\textbf{r}$, the three components of the position of the scattering
  event in the sample.
\item $p_\textrm{i}$, the neutron weight just after the scattering event.
\item $p_\textrm{f}$, the relative neutron weight adjustment from sample to
  detector (so the total weight in the detector is $p_\textrm{i}p_\textrm{f}$).
\end{itemize}
From $\textbf{k}_\textrm{i}$ and $\textbf{k}_\textrm{f}$, we may compute 
the scattering parameters 
$\kappa = \textbf{k}_\textrm{i} - \textbf{k}_\textrm{f}$ and 
$\hbar \omega = \hbar^2/(2 m_\textrm{n})(\textbf{k}_\textrm{i}^2 - \textbf{k}_\textrm{f}^2)$.
The vectors are given in the local coordinate system of the resolution
sample component. The wave vectors are in units of $\mbox{\AA}^{-1}$, the
energy transfer in meV.

The output parameters from \textbf{Res\_monitor}
are the three count numbers, \textit{Nsum}, \textit{psum},
and \textit{p2sum}, and the handle \textit{file} of the output file.
