\chapter{Samples}
\index{Library!Components!samples}
\index{Samples|textbf}
\label{c:samples}

This class of components models the sample of the experiment.
This is by far the most challenging part of an xray scattering
instrument to model. However, for purpose of simulating
instrument performance, details of the samples are rather unimportant,
allowing for simple approximations. On the contrary, for full
virtual experiments it is of importance to have realistic and
detailed sample descriptions. \MCX\ contains both simple and detailed
samples.

An important component class is elastic Bragg scattering from an ideal powder.
The component \textbf{PowderN} models a powder scatterer with reflections
given in an input file. 
The component includes absorption, incoherent scattering, direct beam
transmission and can assume \emph{concentric} shape, i.e. can be used
for modelling sample enviroments.

Next type is Bragg scattering from single crystals. Two types of single crystal exist in \MCX
at present: The \textbf{Perfect\_crystal} and \textbf{Single\_crystal} components.
\textbf{Perfect\_crystal} is in fact most often used as a monchromator crystal. It models a 
crystal where peak broadening is dominated by the Darwin width. Currently it only handles a
single defined reflection. If more than one is wanted this could be
accomplished by using two instances in a \texttt{GROUP} and dynamically choose between
them with a \texttt{WHEN}-statement. For details on the \texttt{GROUP} and \texttt{WHEN} constructs see the
main \MCX user manual~\cite{mcxtracemanual}

Much more general, the component \textbf{Single\_crystal}
is a single crystal sample (with multiple scattering) that allows
the input of an arbitrary unit cell and a list of structure factors, read
from a LAZY / Crystallographica file.
This component also allows anisotropic mosaicity
and $\Delta d/d$ lattice space variation.

Isotropic small-angle scattering is simulated in \textbf{Saxs\_Spheres},
which models scattering from a collection of hard spheres (dilute colloids).
Furthermore, a whole series of sample components modelling various SAXS standard 
sample types are available in the  \texttt{contrib} component library section.

\subsection{Scattering notation}
In sample components, we use a notation common for scattering experiments,
where the wave vector transfer is denoted the {\em scattering vector}
\begin{equation} \label{eq:q-transfer}
\boldsymbol{q} \equiv \boldsymbol{k}_\mathrm{i} - \boldsymbol{k}_\mathrm{f} .
\end{equation}
In analygo, the {\em energy transfer} is given by
\begin{equation} \label{eq:w-transfer}
\hbar \omega \equiv E_\mathrm{i} - E_\mathrm{f} =
\frac{\hbar^2}{2 m_\mathrm{n}} \left( k_\mathrm{i}^2 - k_\mathrm{f}^2 \right) .
\end{equation}

\subsection{Weight transformation in samples; focusing}

Within many samples,
the incident beam is attenuated by scattering and absorption,
so that the illumination varies considerably throughout the sample.
For single crystals, this phenomenon is known as
{\em secondary extinction} \cite{bacon}, but the effect is
important for all samples.
In analytical treatments, attenuation is difficult to deal with,
and is thus often ignored, making a {\em thin sample approximation}.
In Monte Carlo simulations, the beam attenuation
is easily taken care of, as will be shown below.
In the description, we ignore multiple scattering, which is however
 implemented in some sample components.

The sample has an absorption cross section per unit cell of
$\sigma_c^a$ and a scattering cross section per unit cell
of $\sigma_c^s$. The x-ray path length
in the sample before the scattering event is denoted by $l_1$, and
the path length within the sample after the scattering
is denoted by $l_2$, see figure \ref{powderFig}.
We then define the inverse penetration lengths as
$\mu^s = \sigma_c^s / V_c$ and $\mu^a = \sigma_c^a / V_c$, where
$V_c$ is the volume of a unit cell. Physically, the attenuation
along this path follows
\begin{equation}
f_\mathrm{att}(l) = \exp(- l (\mu^s + \mu^a)) ,
\end{equation}
where the normalization $f_\mathrm{att}(0)=1$.

\begin{figure}
  \begin{center}
    \psfrag{l1}{$l_1$}
    \psfrag{l2}{$l_2$}
    \psfrag{lfull}{$l_\mathrm{full}$}
    \includegraphics[width=0.6\textwidth]{figures/scatter.eps}
  \end{center}
\caption{The geometry of a scattering event within a powder sample.}
\label{powderFig}
\end{figure}

The probability for a given x-ray to be scattered from within the interval
$[ l_1 ; l_1+dl ]$ will be
\begin{equation}
P(l_1) dl = \mu^s f_\mathrm{att}(l_1) dl ,
\end{equation}
while the probability for a x-ray to be scattered from within
this interval into the solid angle $\Omega$ {\em and}
not being scattered further
or absorbed on the way out of the sample is
\begin{equation}
P(l_1,\Omega) dl d\Omega =
  \mu^s f_\mathrm{att}(l_1) f_\mathrm{att}(l_2) \gamma(\Omega) d\Omega dl ,
\end{equation}
where $\gamma(\Omega)$ is the directional distribution
of the scattered x-rays, and $l_2$ is determined by
Monte Carlo chocies of $l_1$, $\Omega$,
and from the sample geometry, see e.g. figure \ref{powderFig}.

In our Monte-Carlo simulations, we may choose the scattering
parameters by making a Monte-Carlo choice of $l_1$ and $\Omega$
from a distribution different from $P(l_1,\Omega)$.
By doing this, we must adjust $\pi_i$ according to
the probability transformation rule (\ref{probrule}).
If we {\em e.g.}\ choose the scattering depth, $l_1$,
from a flat distribution in $[ 0 ; l_\mathrm{full} ]$,
and choose the directional dependence from $g(\Omega)$,
we have a Monte Carlo probability
\begin{equation}
f(l_1,\Omega) = g(\Omega) / l_\mathrm{full} ,
\end{equation}
$l_\mathrm{full}$ is here the path length through the sample
as taken by a non-scattered x-ray (although we here
assume that all simulated x-rays are being scattered).
According to (\ref{probrule}), the x-ray weight factor
is now adjusted by the amount
\begin{equation}     \label{sampleprob}
\pi_i(l_1,\Omega) =
 \mu^s l_\mathrm{full} \exp \left[ - (l_1+l_2) (\mu^a + \mu^s) \right]
  \frac{\gamma(\Omega)}{g(\Omega)} .
\end{equation}

In analogy with the source components, it is possible to define
"interesting" directions for the scattering.
One will then try to focus the scattered x-rays,
choosing a $g(\Omega)$, which peaks around these directions.
To do this, one uses (\ref{sampleprob}), where the
fraction $\gamma(\Omega)/g(\Omega)$ corrects for the focusing.
One must choose a proper distribution so that
$g(\Omega) > 0$ in every interesting direction. If this is not the
case, the Monte Carlo simulation gives incorrect results.
All samples have been constructed with a focusing
and a non-focusing option.


\subsection{Future development of sample components}
There is still room for much more development of functionality in
\MCX\ samples.

%\input{vanadium.tex}         \newpage
%\input{tunneling.tex}        \newpage
\input{samples/Absorption_sample.tex}\newpage
\input{samples/Saxs_spheres.tex} \newpage
\input{samples/PowderN.tex}          \newpage
\input{samples/Perfect_crystal.tex}\newpage
\input{samples/Single_crystal.tex}   \newpage
\input{samples/Molecule_2state.tex} \newpage
%\input{samples/saxs.tex}             \newpage
%\input{samples/absorption_phantom.tex} \newpage
%\input{phonon.tex}           \newpage
%\input{LSCO.tex}            \newpage
%\input{isotropic_sqw.tex}
