\chapter{Monitors and detectors}
\index{Library!Components!monitors}
\index{Monitors|textbf}

In real scattering experiments, detectors and monitors play quite
different roles. One wants the detectors to be as efficient as
possible, counting all photons (absorbing them in the process),
while the monitors measure the intensity of the incoming beam, and must
as such be almost transparent, interacting only with (roughly) 0.1-1\%
of the photons passing by. In computer simulations, it is
of course possible to detect every xray without
absorbing it or disturbing any of its parameters. Hence, the two components
have very similar functions in the simulations, and we do
not distinguish between them. For simplicity, they are from here on
just called \textbf{monitors}.

Another important difference between computer simulations
and real experiments is
that one may allow the monitor to be sensitive to any xray property,
as {\em e.g.} direction, energy, and divergence, in addition to what
is found in real-world detectors (space and time). One may, in
fact, let the monitor    record correlations between these properties.

When a monitor detects a xray,
a number counting variable is incremented: $n_i = n_{i-1}+1$.
In addition, the photon
weight $p_i$ is added to the weight counting variable:
$I_i = I_{i-1} + p_i$,
and the second moment of the weight is
updated: $M_{2,i} = M_{2,i-1} + p_i^2$.
As also discussed chapter \ref{c:MCtechniques}, after a simulation of $N$ rays
the detected intensity (in units of photonts/sec.) is $I_N$,
while the estimated errorbar is $\sqrt{M_{2,N}^2}$.

Several different monitor components have been developed for
\MCX , but we have decided to support only the most important ones.
One example of the monitors we have omitted is the single monitor,
\textbf{Monitor},
that measures just one number (with errorbars) per simulation.
This effect is mirrored by any of the 1- or 2-dimensional components
we support, e.g. the \texttt{PSD\_monitor}.
In case additional functionality of monitors is required,
a few lines of code in existing monitors can easily be modified.

Another solution is the ``Swiss army knife'' of monitors, \textbf{Monitor\_nD}, that can handle
almost any simulation requirement, but may prove challenging for inexperienced users or users who like to make their own modifications.

\newpage

\input{monitors/Monitor}

\input{monitors/E_monitor}

\input{monitors/L_monitor}

\input{monitors/PSD_monitor}
\input{monitors/PSD_monitor_coh}

\input{monitors/PSD_monitor_4PI}

\input{monitors/EPSD_monitor}
\input{monitors/W_psd_monitor}

\newpage
\input{monitors/Monitor_nD}
\input{monitors/PreMonitor_nD}
