\chapter{Yield extraction}
\label{chap:prod:fitting}

Signal charm mesons can be distinguished from combinatorial background in the
invariant mass distribution, as shown in \cref{fig:prod:sel:D0ToKpi:offline}
for example.
However, the contributions from prompt and secondary charm are identical in the
invariant mass, and so another distribution must be used to distinguish between
the two sources of charm decays.

This analysis uses the logarithm of the \chisq\ of the \acl{IP}, \lnipchisq, to
obtain the prompt charm yields.
The momentum vector of prompt charm should point back to the \ac{PV}, and so
the \lnipchisq\ distribution is expected be centred around zero.
For secondary charm the \lnipchisq\ distribution is expected to peak at higher
values.
This separation is exploited to distinguish between prompt and secondary charm,
where the prompt signal yield in each \pTy\ bin is measured by a binned,
extended maximum likelihood fit to the \lnipchisq\ distribution.
The prompt and secondary models in this fit are described analytically as
peaking functions.
The combinatorial background is described by a non-parametric model taken from
the data outside the signal peak in the mass distribution.
This background model is normalised in the \lnipchisq\ fit to the number of
combinatorial background candidates in a signal window defined in the mass
distribution, measured in a fit to the charm hadron mass spectrum.

For all cases but the \PDstarp\ measurement, it is the mass of the charm hadron
that is used to discriminate all signal from combinatorial background.
For the \PDstarp\ measurement, the delta mass distribution is used instead,
defined as the difference \deltam\ between the reconstructed \PDstarp\ mass and
the reconstructed \PDzero mass
\begin{equation}
  \deltam = m(\PKminus\Ppiplus\Ppiplussoft) - m(\PKminus\Ppiplus).
  \label{eqn:prod:fitting:delta_mass}
\end{equation}
This has a nominal value of \SI{145.4}{\MeVcc}~\cite{PDG2014}.
The narrower signal peak allows for a better signal-to-background ratio.

\section{Signal-background discrimination}
\label{chap:prod:fitting:mass}

For each one-dimensional mass and \deltam\ fit, one PDF is defined per
discriminatory species: signal and combinatorial background.
In both the mass and \deltam\ distributions, the prompt and secondary signal
shapes are assumed to be identical, and for the \deltam\ fits the combinatorial
background is assumed to be indistinguishable from random soft pion
backgrounds, where a true \PDzero is combined with a random track in the event.
The total \ac{PDF} is constructed as the sum of the per-species \acp{PDF}, each $f_{s}$,
each weighted by the respective yield $N_{s}$
\begin{align}
  f(m) &= \frac{1}{\sum_{\textnormal{s}} N_{\textnormal{s}}}
          \sum_{\textnormal{s}} N_{\textnormal{s}}
          f_{\textnormal{s}}(m),\\
  f(\deltam) &= \frac{1}{\sum_{\textnormal{s}} N_{\textnormal{s}}}
                \sum_{\textnormal{s}} N_{\textnormal{s}}
                f_{\textnormal{s}}(\deltam).
\end{align}

For every mass fit, the background PDF $f_{\textnormal{Bkg.}}(m)$ is taken to
be a first-order polynomial, and the signal PDF $f_{\textnormal{Sig.}}(m)$ is
dependent on the charm hadron candidate, with details given in
Section~\ref{chap:prod:fitting:details}.
The combinatorial and random soft pion background in the \deltam\ fits are
modelled as a single empirical threshold function of the (un-normalised) form
\begin{equation}
  % (dm - dm0)^A * exp(B*dm)
  % The exponential factor has been omitted, as we just set B = 0
  R(x; \deltam_{0}, A) = {(x - \deltam_{0})}^A,
\end{equation}
where $\deltam_{0}$ is the threshold value, fixed to the charged pion rest mass
$m_{\Ppipm} = \SI{139.57}{\MeVcc}$~\cite{PDG2014}.
The signal PDF in \deltam\ is the sum of three normal distributions, sharing a
common mean but allowed to have different widths.

One mass or \deltam\ PDF, $f(m)$ or $f(\deltam)$, is constructed per \pTy\ bin,
and the likelihood is formed as the product of these such that each PDF is
fitted simultaneously when the \ac{NLL} is minimised.

\section{Prompt-secondary discrimination}
\label{chap:prod:fitting:ipchisq}

The prompt and secondary signal distributions are modelled by continuous,
parametric \acp{PDF}.
Rather than attempting to parameterise the combinatorial background
distribution, a \acf{KDE} \ac{PDF}~\cite{Poluektov:2014rxa}, or `template', is
created from a histogram of the \lnipchisq\ distribution in the lower and upper
sidebands of the reconstructed charm hadron mass.
In the case of the \PDstarp measurements, the data in the upper sideband of the
\deltam\ distribution are used instead.
This approach assumes that the mass and \lnipchisq\ are uncorrelated in the
background sample, such that the \lnipchisq\ shape in the signal region is the
same as that in the sidebands.

The signal region in each long-lived charm hadron mass distribution is defined
as a \SI{40}{\MeVcc}-wide window centred on the nominal rest mass of the given
charm hadron, taken to be \SI{1864.84}{\MeVcc}, \SI{1869.61}{\MeVcc}, and
\SI{1968.30}{\MeVcc} for \PDzero, \PDplus, and \PDsplus~\cite{PDG2014}.
The lower sideband is a \SI{20}{\MeVcc}-wide window centred \SI{50}{\MeVcc}
below the centre of the signal window, and the upper sideband is a
\SI{20}{\MeVcc}-wide window centred \SI{50}{\MeVcc} above the centre of the
signal window.
For the \PDstarp\ measurements, the signal region is defined as a window
\SI{6}{\MeVcc} wide, centred on the nominal \deltam\ value of
\SI{145.43}{\MeVcc}~\cite{PDG2014}.
The upper sideband, or just `sideband' as a lower sideband region is not
defined in \deltam, is defined as the region from \SI{4.5}{\MeVcc} to
\SI{9}{\MeVcc} above the centre of the signal region.
\Cref{fig:prod:fitting:regions_A,fig:prod:fitting:regions_B}
show the signal and sideband regions for each mode.

The integral of the \lnipchisq\ background template \ac{PDF} is
Gaussian-constrained to the number of background candidates in the mass or
\deltam\ signal region.
To avoid any complications due to correlations between the background template
\ac{PDF} and the fitted data, only the data in signal region are used in the
\lnipchisq\ fit.
For the \PDstarp\ measurements, this signal region requirement is made in both
the \PDzero mass and the \deltam\ distributions.

For each one-dimensional \lnipchisq\ fit, one \ac{PDF} $f_{s}$ per
discriminatory species is assigned: prompt signal, secondary signal, and
combinatorial background.
The total \acp{PDF} are constructed as the sum of per-species \acp{PDF},
each weighted by the respective yield $N_{s}$
\begin{equation}
  f(\lnipchisq) = \frac{1}{\sum_{\textnormal{s}} N_{\textnormal{s}}}
                  \sum_{\text{s}} N_{\text{s}}
                  f_{\text{s}}(\lnipchisq).
\end{equation}
The constraint on the background yield \nbkg\ is applied by multiplying the
likelihood by a normal distribution in \nbkg, whose mean is the number of
background candidates measured by the mass fit and whose width is the
uncertainty on that value.
This penalises the likelihood by reducing its value when the fitted \nbkg\
parameter is far away from the value found in the mass fit.

One \lnipchisq\ \ac{PDF} and background constraint is constructed per \pTy\
bin, and the likelihood is formed as the product of these such that each
\ac{PDF} is fitted simultaneously when the negative log-likelihood is
minimised.
The benefit of this construction is that some shape parameters can be shared
across bins, reducing the uncertainty on the fit parameters.
Which parameters are shared across bins and which are fitted independently is
dependent on the type of charm meson.
The shared and independent parameters are enumerated in
\cref{chap:prod:fitting:details}.

The prompt signal model $H$ in the \lnipchisq\ distribution is a modified
normal distribution, where the width is allowed to be asymmetric with respect
to the mean, and the tails are described by exponential functions,
\begin{equation}
  H(x; \mu, \sigma, \epsilon, \rho_{L}, \rho_{R}) =
  \begin{cases}
    \exp\left(\frac{\rho_{L}^{2}}{2} + \rho_{L}\frac{x - \mu}{(1 -
    \epsilon)\sigma}\right) & x < \mu - (\rho_{L}\sigma(1 -
        \epsilon)), \\
    \exp\left(-\left(\frac{x - \mu}{\sqrt{2}\sigma(1 -
    \epsilon)}\right)^{2}\right) & \mu - (\rho_{L}\sigma(1 - \epsilon))
          \leq x < \mu, \\
    \exp\left(-\left(\frac{x - \mu}{\sqrt{2}\sigma(1 +
    \epsilon)}\right)^{2}\right) & \mu \leq x < \mu + (\rho_{R}\sigma(1 +
          \epsilon)), \\
    \exp\left(\frac{\rho_{R}^{2}}{2} - \rho_{R}\frac{x - \mu}{(1 +
    \epsilon)\sigma}\right) & x \geq \mu + (\rho_{R}\sigma(1 +
        \epsilon)),
  \end{cases}
  \label{eqn:prod:fitting:ipchisq:signal_model}
\end{equation}
where the parameter $\mu$ is the mode of the distribution; $\sigma$ is the
average of the left and right widths; $\epsilon$ is the asymmetry between the
left and right widths; and $\rho_{L(R)}$ is the exponent for the left (right)
tail.
The secondary signal distribution is modelled by a normal distribution.
These shapes are motivated by the \lnipchisq\ distributions for prompt and
secondary signal decays observed in the \ac{MC} samples.

Given the large number of parameters to be fitted, some shape parameters in the
prompt and secondary signal \lnipchisq\ \acp{PDF} are fixed to values obtained
from `prefits' to the pure samples of prompt and secondary signal \ac{MC}
described in \cref{chap:prod:data:mc}.
The set of parameters that is fixed is dependent on the charm meson species.

\section{Mode-specific details}
\label{chap:prod:fitting:details}

As different final states exhibit different features in the mass, \deltam, and
\lnipchisq\ distributions, several aspects of the fits are different between
modes.
This \lcnamecref{chap:prod:fitting:details} gives the list of parameters that
are split across \pTy\ bins, and the list of parameters that are allowed to
float after the \ac{MC} prefits, for each mode.

Initially, no knowledge is assumed on which parameters should be independent
(to be `split') across the \pTy\ bins, nor of whether the \lnipchisq\
distribution is well-modelled by the \ac{MC}.
The chosen parameterisation is that which best describes the data.
For the mass fits, all parameters are initially fixed such that they are same
across all \pTy\ bins, and are then split one by one when it is observed that a
feature varies across the bins, such as the width of the signal peak.
All parameters of the \lnipchisq\ fits are first kept fixed to values found
from the fits to the simulated data, and then individual parameters are floated
if the total PDF does not model the data well.
Parameters are then split across \pTy\ bins in the same manner as described
below.

\subsection{Fit details for \PDzero}
\label{chap:prod:fitting:details:D0ToKpi}

For the \DzToKpi\ mode, the signal shape in the mass fit is the sum of a normal
and a Crystal Ball distribution~\cite{Skwarnicki:1986xj}, sharing a common mode
but allowed to have different widths.
The Crystal Ball function $C$ is a normal distribution but with a power-law
tail on one side, defined (un-normalised) as
\begin{equation}
  C(x; \mu, \sigma, \alpha, n) = \begin{cases}
    e^{-\frac{{(x - \mu)}^{2}}{2\sigma^{2}}}                          & \frac{x - \mu}{\sigma} > -\alpha, \\
    e^{-\frac{|\alpha|^{2}}{2}}
      {\left(\frac{n}{|\alpha|}\right)}^{n}
      {\left(\frac{n}{|\alpha|} - |\alpha| - \frac{x - \mu}{\sigma}\right)}^{-n} & \frac{x - \mu}{\sigma} \leq -\alpha,
  \end{cases}
  \label{eqn:prod:fitting:crystal_ball}
\end{equation}
where $\alpha$ defines where the power-law tail begins, in units of the width
of the core Gaussian $\sigma$, and $n$ is the power law exponent.
The mode and width of the total signal \ac{PDF} are split across \pTy\ bins, as
is the slope of the background \ac{PDF}.
The mode of the \lnipchisq\ prompt signal \ac{PDF} and the width of the
secondary signal \ac{PDF} are also split across \pTy\ bins.
The mode and width of the prompt signal \lnipchisq\ \ac{PDF} and all parameters
of the secondary signal \lnipchisq\ \ac{PDF} are floated in the fit to data,
and all other \lnipchisq\ shape parameters are fixed to the values from
\ac{MC}.

Prefits to the prompt signal and secondary signal \ac{MC} samples are given in
\cref{fig:prod:fitting:prefits:D0ToKpi}.

\subsubsection*{Fit details for \PDplus}
\label{chap:prod:fitting:details:DpToKpipi}

For the \DpToKpipi\ mode, the signal shape in the mass fit is the sum of a
normal and a Crystal Ball distribution, sharing a common mode but allowed to
have different widths.
The mode of the signal mass \ac{PDF} as well as the width of the Crystal Ball
component in the mass \ac{PDF} are split across \pTy\ bins, as is the slope of
the background mass \ac{PDF}.
The mode of the \lnipchisq\ prompt signal and secondary signal distributions
are split across \pTy\ bins.
The mode and tail parameters of the signal \lnipchisq\ \ac{PDF}, are floated
during the fit to data, with all other shape parameters fixed to the values
from \ac{MC}.

Prefits to the prompt signal and secondary signal data samples in \lnipchisq\
are given in \cref{fig:prod:fitting:prefits:DpToKpipi}.

\subsubsection*{Fit details for \PDsplus}
\label{chap:prod:fitting:details:DsToKKpi}

For the \DspTophipi\ mode, the signal shape in the mass fit is the sum of a two
normal distributions, sharing a common mean but allowed to have different
widths.
The mean and width of the signal mass \ac{PDF} and the slope of the background
mass \ac{PDF}, along with the mode of the \lnipchisq\ prompt signal \ac{PDF},
are split across \pTy\ bins.
The mode of the prompt signal \lnipchisq\ \ac{PDF} and all parameters of the
secondary \ac{PDF} are floated during the fit to data, with all other shape
parameters fixed to the values from \ac{MC}.

Prefits to the prompt signal and secondary signal data samples in \lnipchisq\
are given in \cref{fig:prod:fitting:prefits:DsToKKpi}.

\subsubsection*{Fit details for \PDstarp}
\label{chap:prod:fitting:details:DstToD0pi}

For the \PDstarp-tagged \DzToKpi\ mode, the width of the widest component of
the \deltam\ signal model, described in \cref{chap:prod:fitting:mass}, is split
across \pTy\ bins, along with the mean of the prompt signal \lnipchisq\
\ac{PDF}.
The mean of the prompt signal \lnipchisq\ \ac{PDF} and all parameters of the
secondary \ac{PDF} are floated during the fit to data, with all other shape
parameters fixed to the values from \ac{MC}.

Prefits to the prompt signal and secondary signal data samples in \PDzero
\lnipchisq\ are given in \cref{fig:prod:fitting:prefits:DstToD0pi_D0ToKpi}.

\subsection{Fit results}
\label{chap:prod:fitting:results}

For all fits, the covariance matrix is checked to be positive definite, and the
goodness-of-fit within each \pTy\ bin is checked visually to ensure that the
\ac{NLL} minimisation stopped at a sensible parameter value set.
Mass, \deltam, and \lnipchisq\ fits are given in
\cref{fig:prod:fitting:D0ToKpi,fig:prod:fitting:DpToKpipi,fig:prod:fitting:DsToKKpi,fig:prod:fitting:DstToD0pi_D0ToKpi},
where the data and models shown are the sums of the data and models over all
\pTy\ bins.
Prompt signal yields per \pTy\ bin are given in
\cref{tab:prod:fitting:D0ToKpi,tab:prod:fitting:DpToKpipi,tab:prod:fitting:DsToKKpi,tab:prod:fitting:DstToD0pi_D0ToKpi},
and those integrated across all bins in \cref{tab:prod:fitting:integrated}.

The plots show that the models match the data well, but there are some
significant discrepancies such as in
\cref{fig:prod:fitting:DsToKKpi:ipchisq,fig:prod:fitting:DstToD0pi_D0ToKpi:delta_mass}.
However, the discrepancies in these integrated plots are exaggerations of those
in the individual \pTy\ bin fits: they indicate that there is a consistent bias
in the individual bins, but do not necessarily indicate that these are
statistically significant.
For comparison,
\cref{fig:prod:fitting:D0ToKpi:sig_bkg,fig:prod:fitting:DpToKpipi:sig_bkg,fig:prod:fitting:DsToKKpi:sig_bkg,fig:prod:fitting:DstToD0pi_D0ToKpi:sig_bkg}
show the mass (or \deltam) and \lnipchisq\ fits for each meson in the \pTy\ bin
with the highest prompt signal yield and in the \pTy\ bin with the highest
combinatorial background yield.
These show that, in the individual \pTy\ bins, the fits model the data
significantly better than the integrated plots would suggest, and also that the
fit is flexible enough to model both high prompt signal and high combinatorial
background datasets.
The effect on the cross-section measurements of mis-modelling will be discussed
further in \cref{chap:prod:syst:fitting}.

In some \pTy\ bins, it is not possible to make a prompt signal yield
measurement due to insufficient data in those bins.
At this stage in the analysis, a cross-section measurement in a bin is
considered unfeasible if there is either no data (zero candidates), or if the
prompt signal yield $N_{i} \pm \sigma_{N_{i}}$ in that bin as determined in the
fit does not satisfy $N_{i} > 3\sigma_{N_{i}}$.

\begin{figure}
  \begin{subfigure}{0.5\textwidth}
    \includegraphics[width=\textwidth]{production/fitting/D0ToKpi_mass_offline_selection_regions}
    \caption{\DzToKpi}
    \label{fig:prod:fitting:regions:D0ToKpi}
  \end{subfigure}
  \begin{subfigure}{0.5\textwidth}
    \includegraphics[width=\textwidth]{production/fitting/DpToKpipi_mass_offline_selection_regions}
    \caption{\DpToKpipi}
    \label{fig:prod:fitting:regions:DpToKpipi}
  \end{subfigure}
  \caption{%
    Definition of signal window, in blue, and sidebands, in red, for
    \DzToKpi~(\subref*{fig:prod:fitting:regions:D0ToKpi}) and
    \DpToKpipi~(\subref*{fig:prod:fitting:regions:DpToKpipi}) candidates.
    The boundaries of the different regions are defined in
    \cref{chap:prod:fitting:ipchisq}.
    The full dataset is shown.
  }
  \label{fig:prod:fitting:regions_A}
\end{figure}

\begin{figure}
  \begin{subfigure}{0.5\textwidth}
    \includegraphics[width=\textwidth]{production/fitting/DsToKKpi_mass_offline_selection_regions}
    \caption{\DspTophipi}
    \label{fig:prod:fitting:regions:DsTophipi}
  \end{subfigure}
  \begin{subfigure}{0.5\textwidth}
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_delta_mass_offline_selection_regions}
    \caption{\DstToDzpi}
    \label{fig:prod:fitting:regions:DstToD0pi_D0ToKpi}
  \end{subfigure}
  \caption{%
    Definition of signal window, in blue, and sidebands, in red, for
    \DspTophipi~(\subref*{fig:prod:fitting:regions:DsTophipi}) and
    \DstToDzpi~(\subref*{fig:prod:fitting:regions:DstToD0pi_D0ToKpi})
    candidates.
    The boundaries of the different regions are defined in
    \cref{chap:prod:fitting:ipchisq}.
    The full dataset is shown.
  }
  \label{fig:prod:fitting:regions_B}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/D0ToKpi_ipchisq_fit_pT_integrated_y_integrated_sig}
    \caption{Prompt}
    \label{fig:prod:fitting:prefits:D0ToKpi:prompt}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/D0ToKpi_ipchisq_fit_pT_integrated_y_integrated_sec}
    \caption{Secondary}
    \label{fig:prod:fitting:prefits:D0ToKpi:secondary}
  \end{subfigure}
  \caption{%
    Distributions of \lnipchisq\ for simulated \DzToKpi\ decays: prompt signal
    \PDzero (\subref*{fig:prod:fitting:prefits:D0ToKpi:prompt}) and secondary
    signal \PDzero (\subref*{fig:prod:fitting:prefits:D0ToKpi:secondary}).
    The sum of the simultaneous likelihood fits in each \pTy\ bin is overlaid.
  }
  \label{fig:prod:fitting:prefits:D0ToKpi}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DpToKpipi_ipchisq_fit_pT_integrated_y_integrated_sig}
    \caption{Prompt}
    \label{fig:prod:fitting:prefits:DpToKpipi:prompt}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DpToKpipi_ipchisq_fit_pT_integrated_y_integrated_sec}
    \caption{Secondary}
    \label{fig:prod:fitting:prefits:DpToKpipi:secondary}
  \end{subfigure}
  \caption{%
    Distributions of \lnipchisq\ for simulated \DpToKpipi\ decays: prompt
    signal \PDplus (\subref*{fig:prod:fitting:prefits:DpToKpipi:prompt}) and
    secondary signal \PDplus
    (\subref*{fig:prod:fitting:prefits:DpToKpipi:secondary}).
    The sum of the simultaneous likelihood fits in each \pTy\ bin is overlaid.
  }
  \label{fig:prod:fitting:prefits:DpToKpipi}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DsToKKpi_ipchisq_fit_pT_integrated_y_integrated_sig}
    \caption{Prompt}
    \label{fig:prod:fitting:prefits:DsToKKpi:prompt}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DsToKKpi_ipchisq_fit_pT_integrated_y_integrated_sec}
    \caption{Secondary}
    \label{fig:prod:fitting:prefits:DsToKKpi:secondary}
  \end{subfigure}
  \caption{%
    Distributions of \lnipchisq\ for simulated \DspTophipi\ decays: prompt
    signal \PDsplus (\subref*{fig:prod:fitting:prefits:DsToKKpi:prompt}) and
    secondary signal \PDsplus
    (\subref*{fig:prod:fitting:prefits:DsToKKpi:secondary}).
    The sum of the simultaneous likelihood fits in each \pTy\ bin is overlaid.
  }
  \label{fig:prod:fitting:prefits:DsToKKpi}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_ipchisq_fit_pT_integrated_y_integrated_sig}
    \caption{Prompt}
    \label{fig:prod:fitting:prefits:DstToD0pi_D0ToKpi:prompt}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_ipchisq_fit_pT_integrated_y_integrated_sec}
    \caption{Secondary}
    \label{fig:prod:fitting:prefits:DstToD0pi_D0ToKpi:secondary}
  \end{subfigure}
  \caption{%
    Distributions of \PDzero \lnipchisq\ for simulated \DstToDzpi, with
    \DzToKpi, decays: prompt signal \PDstarp\
    (\subref*{fig:prod:fitting:prefits:DstToD0pi_D0ToKpi:prompt}) and secondary
    signal \PDstarp\
    (\subref*{fig:prod:fitting:prefits:DstToD0pi_D0ToKpi:secondary}).
    The sum of the simultaneous likelihood fits in each \pTy\ bin is overlaid.
  }
  \label{fig:prod:fitting:prefits:DstToD0pi_D0ToKpi}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/D0ToKpi_mass_fit_pT_integrated_y_integrated}
    \caption{Mass}
    \label{fig:prod:fitting:D0ToKpi:mass}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/D0ToKpi_ipchisq_fit_pT_integrated_y_integrated}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:D0ToKpi:ipchisq}
  \end{subfigure}
  \caption{%
    Distributions for fully selected \DzToKpi\ candidates: \PDzero\ invariant
    mass (\subref*{fig:prod:fitting:D0ToKpi:mass}) and \PDzero\ \lnipchisq\
    (\subref*{fig:prod:fitting:D0ToKpi:ipchisq}) for a mass window of
    $\pm\SI{20}{\MeVcc}$ around the nominal \PDzero mass.
    The sum of the simultaneous likelihood fits in each \pTy\ bin is shown,
    with components as indicated in the legends.
  }
  \label{fig:prod:fitting:D0ToKpi}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DpToKpipi_mass_fit_pT_integrated_y_integrated}
    \caption{Mass}
    \label{fig:prod:fitting:DpToKpipi:mass}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DpToKpipi_ipchisq_fit_pT_integrated_y_integrated}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:DpToKpipi:ipchisq}
  \end{subfigure}
  \caption{%
    Distributions for fully selected \DpToKpipi\ candidates: \PDplus\ invariant
    mass (\subref*{fig:prod:fitting:DpToKpipi:mass}) and \PDplus\ \lnipchisq\
    (\subref*{fig:prod:fitting:DpToKpipi:ipchisq}) for a mass window of
    $\pm\SI{20}{\MeVcc}$ around the nominal \PDplus mass.
    The sum of the simultaneous likelihood fits in each \pTy\ bin is shown,
    with components as indicated in the legends.
  }
  \label{fig:prod:fitting:DpToKpipi}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DsToKKpi_mass_fit_pT_integrated_y_integrated}
    \caption{Mass}
    \label{fig:prod:fitting:DsToKKpi:mass}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DsToKKpi_ipchisq_fit_pT_integrated_y_integrated}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:DsToKKpi:ipchisq}
  \end{subfigure}
  \caption{%
    Distributions for fully selected \DspTophipi\ candidates: \PDsplus\
    invariant mass (\subref*{fig:prod:fitting:DpToKpipi:mass}) and \PDsplus\
    \lnipchisq\ (\subref*{fig:prod:fitting:DpToKpipi:ipchisq}) for a mass
    window of $\pm\SI{20}{\MeVcc}$ around the nominal \PDsplus mass.
    The sum of the simultaneous likelihood fits in each \pTy\ bin is shown,
    with components as indicated in the legends.
  }
  \label{fig:prod:fitting:DsToKKpi}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_mass_fit_pT_integrated_y_integrated}
    \caption{\PDzero mass}
    \label{fig:prod:fitting:DstToD0pi_D0ToKpi:mass}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_delta_mass_fit_pT_integrated_y_integrated}
    \caption{Delta mass}
    \label{fig:prod:fitting:DstToD0pi_D0ToKpi:delta_mass}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_ipchisq_fit_pT_integrated_y_integrated}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:DstToD0pi_D0ToKpi:ipchisq}
  \end{subfigure}
  \caption{%
    Distributions for fully selected \PDstarp\ candidates, with \DzToKpi:
    \PDzero\ invariant mass
    (\subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:mass}); $\deltam = m(\PDstarp)
    - m(\PDzero)$ (\subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:delta_mass}) for
    a mass window of $\pm\SI{20}{\MeVcc}$ around the nominal \PDzero mass; and
    \PDzero\ \lnipchisq\ (\subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:ipchisq})
    with an additional mass window of $\pm\SI{3}{\MeVcc}$ around the nominal
    \deltam\ value.
    The sum of the simultaneous likelihood fits in each \pTy\ bin is shown,
    with components as indicated in the legends.
  }
  \label{fig:prod:fitting:DstToD0pi_D0ToKpi}
\end{figure}

\begin{table}
  \caption{%
    Prompt signal yields in the fully selected dataset, summed over all
    \pTy\ bins in which a measurement is made.
  }
  \label{tab:prod:fitting:integrated}
  \centering
  \input{tables/production/fitting/integrated_signal_yields}
\end{table}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/D0ToKpi_mass_fit_pT_3_y_2}
    \caption{Mass}
    \label{fig:prod:fitting:D0ToKpi:mass_high_sig}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/D0ToKpi_ipchisq_fit_pT_3_y_2}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:D0ToKpi:ipchisq_high_sig}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/D0ToKpi_mass_fit_pT_0_y_3}
    \caption{Mass}
    \label{fig:prod:fitting:D0ToKpi:mass_high_bkg}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/D0ToKpi_ipchisq_fit_pT_0_y_3}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:D0ToKpi:ipchisq_high_bkg}
  \end{subfigure}
  \caption{%
    Distributions for fully selected \DzToKpi\ candidates: \PDzero\ invariant
    mass (\subref*{fig:prod:fitting:D0ToKpi:mass_high_sig} and
    \subref*{fig:prod:fitting:D0ToKpi:mass_high_bkg}); and \PDzero\ \lnipchisq\
    (\subref*{fig:prod:fitting:D0ToKpi:ipchisq_high_sig} and
    \subref*{fig:prod:fitting:D0ToKpi:ipchisq_high_bkg}) for a mass window of
    $\pm\SI{20}{\MeVcc}$ around the nominal \PDzero mass.
    The top Figures (\subref*{fig:prod:fitting:D0ToKpi:mass_high_sig} and
    \subref*{fig:prod:fitting:D0ToKpi:ipchisq_high_sig}) show the data and fits
    in the region \pTyrange{2}{2.5}{3}{3.5}, whilst the bottom Figures
    (\subref*{fig:prod:fitting:D0ToKpi:mass_high_bkg} and
    \subref*{fig:prod:fitting:D0ToKpi:ipchisq_high_bkg}) show the data and fits
    in the \pTyrange{0}{1}{3.5}{4} region.
  }
  \label{fig:prod:fitting:D0ToKpi:sig_bkg}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DpToKpipi_mass_fit_pT_4_y_2}
    \caption{Mass}
    \label{fig:prod:fitting:DpToKpipi:mass_high_sig}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DpToKpipi_ipchisq_fit_pT_4_y_2}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:DpToKpipi:ipchisq_high_sig}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DpToKpipi_mass_fit_pT_3_y_3}
    \caption{Mass}
    \label{fig:prod:fitting:DpToKpipi:mass_high_bkg}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DpToKpipi_ipchisq_fit_pT_3_y_3}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:DpToKpipi:ipchisq_high_bkg}
  \end{subfigure}
  \caption{%
    Distributions for fully selected \DpToKpipi\ candidates: \PDplus\ invariant
    mass (\subref*{fig:prod:fitting:DpToKpipi:mass_high_sig} and
    \subref*{fig:prod:fitting:DpToKpipi:mass_high_bkg}); and \PDplus\
    \lnipchisq\ (\subref*{fig:prod:fitting:DpToKpipi:ipchisq_high_sig} and
    \subref*{fig:prod:fitting:DpToKpipi:ipchisq_high_bkg}) for a mass window of
    $\pm\SI{20}{\MeVcc}$ around the nominal \PDplus mass.
    The top Figures (\subref*{fig:prod:fitting:DpToKpipi:mass_high_sig} and
    \subref*{fig:prod:fitting:DpToKpipi:ipchisq_high_sig}) show the data and
    fits in the region \pTyrange{2.5}{3}{3}{3.5}, whilst the bottom Figures
    (\subref*{fig:prod:fitting:DpToKpipi:mass_high_bkg} and
    \subref*{fig:prod:fitting:DpToKpipi:ipchisq_high_bkg}) show the data and
    fits in the \pTyrange{2}{2.5}{3.5}{4} region.
  }
  \label{fig:prod:fitting:DpToKpipi:sig_bkg}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DsToKKpi_mass_fit_pT_6_y_1}
    \caption{Mass}
    \label{fig:prod:fitting:DsToKKpi:mass_high_sig}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DsToKKpi_ipchisq_fit_pT_6_y_1}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:DsToKKpi:ipchisq_high_sig}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DsToKKpi_mass_fit_pT_2_y_3}
    \caption{Mass}
    \label{fig:prod:fitting:DsToKKpi:mass_high_bkg}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DsToKKpi_ipchisq_fit_pT_2_y_3}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:DsToKKpi:ipchisq_high_bkg}
  \end{subfigure}
  \caption{%
    Distributions for fully selected \DspTophipi\ candidates: \PDsplus\
    invariant mass (\subref*{fig:prod:fitting:DsToKKpi:mass_high_sig} and
    \subref*{fig:prod:fitting:DsToKKpi:mass_high_bkg}); and \PDsplus\
    \lnipchisq\ (\subref*{fig:prod:fitting:DsToKKpi:ipchisq_high_sig} and
    \subref*{fig:prod:fitting:DsToKKpi:ipchisq_high_bkg}) for a mass window of
    $\pm\SI{20}{\MeVcc}$ around the nominal \PDsplus mass.
    The top Figures (\subref*{fig:prod:fitting:DsToKKpi:mass_high_sig} and
    \subref*{fig:prod:fitting:DsToKKpi:ipchisq_high_sig}) show the data and
    fits in the region \pTyrange{4}{5}{2.5}{3}, whilst the bottom Figures
    (\subref*{fig:prod:fitting:DsToKKpi:mass_high_bkg} and
    \subref*{fig:prod:fitting:DsToKKpi:ipchisq_high_bkg}) show the data and
    fits in the \pTyrange{2}{2.5}{3.5}{4} region.
  }
  \label{fig:prod:fitting:DsToKKpi:sig_bkg}
\end{figure}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_delta_mass_fit_pT_7_y_2}
    \caption{Delta mass}
    \label{fig:prod:fitting:DstToD0pi_D0ToKpi:delta_mass_high_sig}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_ipchisq_fit_pT_7_y_2}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:DstToD0pi_D0ToKpi:ipchisq_high_sig}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_delta_mass_fit_pT_2_y_3}
    \caption{Delta mass}
    \label{fig:prod:fitting:DstToD0pi_D0ToKpi:delta_mass_high_bkg}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\textwidth]{production/fitting/DstToD0pi_D0ToKpi_ipchisq_fit_pT_2_y_3}
    \caption{\lnipchisq}
    \label{fig:prod:fitting:DstToD0pi_D0ToKpi:ipchisq_high_bkg}
  \end{subfigure}
  \caption{%
    Distributions for fully selected \DstToDzpi, with \DzToKpi, candidates:
    $\deltam = m(\PDstarp) - m(\PDzero)$
    (\subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:delta_mass_high_sig} and
    \subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:delta_mass_high_bkg}) for a
    mass window of $\pm\SI{20}{\MeVcc}$ around the nominal \PDzero mass; and
    \PDzero\ \lnipchisq\
    (\subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:ipchisq_high_sig} and
    \subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:ipchisq_high_bkg}) with an
    additional mass window of $\pm\SI{3}{\MeVcc}$ around the nominal
    \PDstarp-\PDzero\ mass difference.
    The top Figures
    (\subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:delta_mass_high_sig} and
    \subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:ipchisq_high_sig}) show the
    data and fits in the region \pTyrange{4}{5}{3}{3.5}, whilst the bottom
    Figures (\subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:delta_mass_high_bkg}
    and \subref*{fig:prod:fitting:DstToD0pi_D0ToKpi:ipchisq_high_bkg}) show the
    data and fits in the \pTyrange{1.5}{2}{3.5}{4} region.
  }
  \label{fig:prod:fitting:DstToD0pi_D0ToKpi:sig_bkg}
\end{figure}


\chapter{Dimensionality reduction with Principal Component Analysis (PCA)}


\section{Hyperchains}

\textbf{todo: reorganize, mention commitments earlier, images!}

The previous approaches had a lot to offer, but considering they cons it is hard
to scale them in a reasonable way. PoW seems to work well only with big
computational effort being burned and PoS suffers from huge amount of security
holes that require very complicated algorithms that usually either don't solve
the problem at all or just move it further to another layer of abstraction.

Here we present a hybrid strategy which will benefit from stability of PoW
solutions but will offer the scalability of PoS systems. A Hyperchain is a
special kind of blockchain that sticks to an already existing chain. They are
going to be called respectively child- and parent-chain
\footnote{https://medium.com/@yanislav/hyperchains-secure-cheap-scalable-blockchain-technology-for-everyone-3ddec96a4152}.

The parent chain can be almost any blockchain in the world. In general, we want
to use some big existing PoW based chains (at the time of writing, preferably
Bitcoin or Ethereum, but not limited to) to reuse their burned work to maintain
the stability of the childchain. We would also like to have
PoS-like election system to choose the leaders on the hyperchain. In this case
however we have a really reliable – and most important, unpredictable – source
of randomness – the keyblock hash of the parent chain. The idea is not very new
though – there is already some research made in this direction
\footnote{https://eprint.iacr.org/2015/1015.pdf}.
The critics say that it is still possible to exploit it to mine blocks in such a
manner that the outcome would be beneficial, but in reality that reduces to
compound PoW – most likely the difficulty of mining such a block will go
squared, so in order to have actual control over the entropy one needs to
control the parent chain anyway.

Having this machinery it seems natural to start a new election each time a
keyblock was mined on the parent chain. The next leader shall be chosen
depending on the hash of that block and selected with proportional chances to
their stake. The selection algorithm is going to be straightforward – we take
the hash (let's say, MD5) and consider a whole MD5 counterdomain as a closed
line segment divided into intervals of lengths proportional to the stakes of the
delegates. The intervals are going to be sorted by the order of the respective
commitments that appeared on the parent chain. The generated hash will then
point into some subsection which will determine the winner.

$$Insert\ some\ nice\ image\ here$$

One of the important concepts of the commitment idea is to be able to rely on
the parent chain's stability. Therefore we want to treat it as a rigid skeleton
of the hyperchain which can be achieved by proper blockhash linking. Each
commitment must declare over which block is the delegating going to compete.
Therefore the commitment must consist of:
\begin{itemize}
\item The subject of delegation on the child chain
\item The block over the delegate is going to build
\item Singature of the delegate from the child chain
\end{itemize}

One dillema that rises at this point is whether should the commitment reference
the latest keyblock or the microblock of the child chain. Referencing microblock
on the first sight looks more consistent, but we believe that in reality would
lead to massive forking (especially when some peers wouldn't receive all of the
blocks). The problem with referencing keyblock is that the next leader could
steal the transactions and post them in their microblocks. This however can be
faced with the smarter feeing strategy: instead of giving the full fee to the
miner we can split it up and give the bigger part to the next leader that did
include the previous leader's microblocks in their continuation of the history.

$$Insert\ some\ nice\ image\ here$$


\chapter{AWP model set of equations}
\label[secinapp]{chap:awp-eqn}
\resetallacronyms

This appendix presents the set of equations for the model presented in
\cpref{sec:awp-model} with \cpref{fig:awp-exp-analysis-model}. The
known variables are:

\begin{multicols}{5}
  \begin{itemize}
    \item $\dotE{el}{14}$
    \item $\dotM{02}{26}$
    \item $\dotM{03}{07}$
    \item $\dotM{17}{15}$
    \item $\text{\textit{Cp}}_{15,in}$
    \item $\text{\textit{Cp}}_{15,out}$
    \item $h_{02,out}$
    \item $h_{03,in}$
    \item $h_{03,out}$
    \item $h_{04,in}$
    \item $h_{04,out}$
    \item $h_{18,out}$
    \item $h_{20,out}$
    \item $h_{21,out}$
    \item $h_{25,out}$
    \item $h_{26,out}$
    \item $h_{28,out}$
    \item $\eta_{in}$
    \item $\eta_{rad}$
    \item $\eta_{axi}$
  \end{itemize}
\end{multicols}

$\eta_{mot}$ is set directly by the solver. $\eta_{rad}$ and
$\eta_{axi}$ are determined with the gas bearings losses model
implemented by \citet{schiffmann-2008a}.

\begin{flalign}
  & \dotQ{03}{15} = \dotM{17}{15} \left( \text{\textit{Cp}}_{15,out} \, T_{15,out} - \text{\textit{Cp}}_{15,in} \, T_{15,in} \right) \label{eq:cd-eb-01} \\
  & \dotM{20}{03} = \dfrac{\dotQ{03}{15}}{h_{03,in} - h_{03,out}} \label{eq:cd-eb-02} \\
  & \dotM{03}{05} = \dotM{20}{03} - \dotM{03}{07} \label{eq:cd-eb-03} \\
  & \dotM{05}{08} = \dotM{03}{05} \nonumber \\
  & \dotM{02}{20} = \dotM{03}{05} \nonumber \\
  & \dotM{07}{09} = \dotM{03}{07} \nonumber \\
  & \dotM{26}{21} = f_{01} \dotM{02}{26} & 0 < f_{01} < 1 \hspace{2.1cm} \nonumber \\
  & \dotQ{21}{at} = \dotM{26}{21} \left( h_{26,out} - h_{21,out} \right) \nonumber \\
  & \dotQ{26}{at} = \dotM{02}{26} \left( h_{02,out} - h_{26,out} \right) \nonumber \\
  & \dotQ{20}{at} = \dotM{20}{03} \left( h_{02,out} - h_{20,out} \right) \nonumber \\
  & \dotQ{14}{at} = \left( 1 - \eta_{in} \right) \dotE{el}{14} \nonumber \\
  & \dotQ{16}{at} = \dotQ{03}{15} - \dotE{el}{14} - \dotQ{21}{at} - \dotQ{26}{at} - \dotQ{20}{at} - \dotQ{14}{at} \label{eq:ev-eb-01} \\
  & \dotM{09}{04} = \dfrac{\dotQ{16}{04}}{h_{04,out} - h_{04,in}} \label{eq:ev-eb-02} \\
  & \dotM{06}{09} = \dotM{09}{04} - \dotM{07}{09} \label{eq:sc-mf} \\
  & \dotM{19}{06} = \dotM{06}{09} \nonumber \\
  & \dotM{08}{19} = \dotM{06}{09} \nonumber \\
  & \dotM{04}{18} = \dotM{09}{04} \nonumber \\
  & \dotM{18}{22} = \dotM{04}{18} \nonumber
\end{flalign}

\begin{flalign}
  & \dotM{26}{13} = \left( 1 - f_{01} \right) \dotM{02}{26} \nonumber \\
  & \dotM{21}{12} = \dotM{26}{21} \nonumber \\
  & \dotM{13}{12} = \dotM{26}{13} \nonumber \\
  & \dotM{12}{24} = \dotM{13}{12} + \dotM{21}{12} \nonumber \\
  & \dotM{24}{11} = \dotM{12}{24} \nonumber \\
  & \dotM{11}{23} = f_{02} \dotM{24}{11} & 0 < f_{02} < 1 \hspace{2.1cm} \nonumber \\
  & \dotM{11}{22} = \left( 1 - f_{02} \right) \dotM{24}{11} \nonumber \\
  & \dotM{23}{29} = \dotM{11}{22} + \dotM{18}{22} \nonumber \\
  & \dotM{29}{01} = \dotM{23}{29} + \dotM{22}{29} \nonumber \\
  & \dotM{01}{25} = \dotM{29}{01} \nonumber \\
  & \dot{M}_{cp1} = \dotM{01}{25} \nonumber
\end{flalign}

The mass flow rate in the second stage impeller $\dot{M}_{cp2}$ is
equal to $\dotM{02}{26} + \dotM{02}{20} + \dotM{02}{10}$.
$\dotM{02}{10}$, the leakage flow rate through the labyrinth
seal, needs to be determined.

\begin{flalign}
  & \dotM{02}{10} = f_{03} \dot{M}_{cp2} & 0 < f_{03} < 1 \hspace{1cm} \label{eq:awp-f03}
\end{flalign}

With the introduction of the parameter $f_{03}$ in \cref{eq:awp-f03},
the equation of the mass flow rate in the second stage impeller
$\dot{M}_{cp2}$ is equal to
$f_{03} \dot{M}_{cp2} + \dotM{02}{26} + \dotM{02}{20}$. Which implies
the \cref{eq:awp-dotM_cp2}.

\begin{flalign}
  & \dot{M}_{cp2} = \dfrac{\dotM{02}{20} + \dotM{02}{26}}{1 - f_{03}} \label{eq:awp-dotM_cp2} \\
  & \dotM{10}{25} = \dotM{02}{10} \nonumber \\
  & \dotM{25}{27} = f_{04} \left( \dotM{10}{25} + \dotM{01}{25} \right) & 0 < f_{04} < 1 \hspace{2.1cm} \nonumber \\
  & \dotM{25}{08} = \left( 1 - f_{04} \right) \left( \dotM{10}{25} + \dotM{01}{25} \right) \nonumber \\
  & \dotM{27}{28} = \dotM{25}{27} \nonumber \\
  & \dotM{08}{28} = \dotM{25}{08} + \dotM{05}{08} - \dotM{08}{19} \nonumber \\
  & \dotM{28}{02} = \dotM{27}{28} + \dotM{08}{28} \nonumber \\
  & \dotE{14}{13} = \eta_{in} \dotE{el}{14} \nonumber
\end{flalign}

If we consider the energy balance on component \#13, we get
$\dotE{14}{13} - \dotE{13}{12} - \dotQ{13}{12} - \dotQ{13}{07} +
\dotMh{26}{13} - \dotMh{13}{12} = 0$.
$h_{13,out}$ is unknown and needs to be determined. In order to do
this, $\dotE{13}{12}$, $\dotQ{13}{12}$ and $\dotQ{13}{07}$ are
required.

\begin{flalign}
  & \dotE{13}{12} = \eta_{mot} \dotE{14}{13} & 0 < \eta_{mot} < 1 \hspace{1.9cm} \nonumber \\
  & \dotQ{13}{12} = f_{05} \left( 1 - \eta_{mot} \right) \dotE{14}{13} & 0 < f_{05} < 1 \hspace{2.1cm} \nonumber \\
  & \dotQ{13}{07} = f_{06} \left( 1 - \eta_{mot} \right) \dotE{14}{13} & 0 < f_{06} < 1 \hspace{2.1cm} \nonumber \\
  & h_{13,out} = \dfrac{\dotE{14}{13} - \dotE{13}{12} - \dotQ{13}{12} - \dotQ{13}{07} + \dotMh{26}{13}}{\dotM{13}{12}}
\end{flalign}

According to their definitions, we observe that $f_{05}$ and $f_{06}$
have to respect the relation $0 < f_{05} + f_{06} < 1$.

If we consider the energy balance on component \#12, we get
$\dotE{13}{12} + \dotQ{13}{12} + \dotMh{13}{12} +
\dotMh{21}{12} - \dotMh{12}{24} - \dotE{12}{11} -
\dotQ{12}{11} = 0$.
$\dotE{12}{11}$ and $h_{12,out}$ need to be determined to get
$\dotQ{12}{11}$.

\begin{flalign}
  & \dotE{12}{11} = \eta_{ra} \dotE{13}{12} \nonumber \\
  & T_{12,out} = \left( 1 + f_{07} \right) T_{13,out} & \Rightarrow h_{12,out} \hspace{2.1cm} \nonumber \\
  & \dotQ{12}{11} = \dotE{13}{12} + \dotQ{13}{12} + \dotMh{13}{12} \nonumber \\
  &  \text{\hspace{1.25cm}} + \dotMh{21}{12} - \dotMh{12}{24} - \dotE{12}{11}
\end{flalign}

If we consider the energy balance on component \#11, we get
$\dotQ{12}{11} + \dotE{12}{11} - \dotE{11}{01} - \dotQ{11}{01} -
\dotQ{11}{23} - \dotQ{11}{24} - \dotMh{11}{23} +
\dotMh{24}{11} - \dotMh{11}{22} = 0$.
In order to determine $h_{11,out}$, the variables $\dotE{11}{01}$, $h_{24,out}$,
$\dotQ{11}{24}$, $\dotQ{11}{01}$ and $\dotQ{11}{23}$ need to be
determined.

\begin{flalign}
  & \dotE{11}{01} = \eta_{axi} \dotE{12}{11} \nonumber \\
  & T_{24,out} = \left( 1 + f_{08} \right) T_{12,out} & \Rightarrow h_{24,out} \hspace{2.1cm} \nonumber
\end{flalign}

The energy balance on component \#24 gives us the equation
$\dotMh{12}{24} - \dotMh{24}{11} + \dotQ{11}{24} =
0$, which gives \cref{eq:awp-dotQ_11_24}.

\begin{flalign}
  & \dotQ{11}{24} = \dotMh{24}{11} - \dotMh{12}{24} \label{eq:awp-dotQ_11_24} \\
  & \dotQ{11}{01} = f_{09} \dotQ{12}{11} & 0 < f_{09} < 1 \hspace{2.1cm} \nonumber \\
  & \dotQ{11}{23} = f_{10} \dotQ{12}{11} & 0 < f_{10} < 1 \hspace{2.1cm} \nonumber \\
\end{flalign}

\begin{flalign}
  & h_{11,out} = \dfrac{\dotQ{12}{11} + \dotE{12}{11} - \dotE{11}{01} - \dotQ{11}{01} - \dotQ{11}{23} - \dotQ{11}{24} + \dotMh{24}{11}}{\dotM{11}{23} + \dotM{11}{22}} & \nonumber
\end{flalign}

The energy balance on component \#22 gives the equation $\dotMh{18}{22} + \dotMh{11}{22} - \dotMh{22}{29} = 0$, which gives \cref{eq:awp-hout22}.

\begin{flalign}
  & h_{22,out} = \dfrac{\dotMh{18}{22} + \dotMh{11}{22}}{\dotM{22}{29}} & \label{eq:awp-hout22}
\end{flalign}

The energy balance on components \#29 and \#23 give the balance equations
$\dotMh{22}{29} + \dotMh{23}{29} - \dotMh{29}{01} = 0$ and
$\dotMh{11}{23} + \dotQ{11}{23} - \dotMh{23}{29} = 0$
which give \cref{eq:awp-hout29}.

\begin{flalign}
  & h_{29,out} = \dfrac{\dotMh{22}{29} + \dotMh{23}{29}}{\dotM{29}{01}} & \label{eq:awp-hout29}
\end{flalign}

The energy balance on component \#1 gives the equation
$\dotE{11}{01} - \dotMh{01}{25}  + \dotMh{29}{01} + \dotQ{11}{01} - \dotQ{01}{02} - \dotE{01}{02} = 0$.

We need a relationship between $T_{01,out}$ and $T_{25,out}$, in order
to go further. This results in the equation
\cref{eq:awp-T01out}. Knowing $T_{01, out}$ gives access to
$h_{01,out}$ through a computation with REFPROP.

\begin{flalign}
  & T_{01,out} = \dfrac{T_{25,out}}{1 + f_{11}} & 0 < f_{11} < 1 \hspace{1cm} \label{eq:awp-T01out}
\end{flalign}

\Cref{eq:awp-T01out} allows to write the equation
$\dotE{11}{01} - \dotE{01}{02} = \dot{M}_{cp1} \, \left( h_{01,out} -
  h_{29,out} \right)$, which gives \cref{eq:awp-E0102}.

\begin{flalign}
  & \dotE{01}{02} = \dotE{11}{01} - \dot{M}_{cp1} \, \left( h_{01,out} -
  h_{29,out} \right) & \label{eq:awp-E0102} \\
  & \dotQ{01}{02} = \dotE{11}{01} - \dotMh{01}{25} + \dotMh{29}{01} + \dotQ{11}{01} - \dotE{01}{02} \nonumber
\end{flalign}

The energy balance on component \#02 gives the equation
$- \dotMh{02}{10} - \dotMh{02}{26} - \dotMh{02}{20} + \dotMh{28}{02} - \dotQ{02}{10} + \dotQ{01}{02} + \dotE{01}{02} = 0$,
which gives \cref{eq:awp-Q0210}.

\begin{flalign}
  & \dotQ{02}{10} = \dotQ{01}{02} + \dotE{01}{02} - \dotMh{02}{10} - \dotMh{02}{26} - \dotMh{02}{20} + \dotMh{28}{02} & \label{eq:awp-Q0210} \\
  & \dotQ{19}{18} = \dotM{18}{22} \left( h_{18,out} - h_{04,out} \right) \nonumber
\end{flalign}

\FloatBarrier
\bibliographystyle{plainnat}
\bibliography{main}
\label[secinapp]{sec:awp-eqn-refs}


\section{Conclusions and future work}
\label{sec:conclusions}

This paper presents a novel framework for predicting the \gls{rul} of mechanical components. While the method was tested on the jet-engine specific dataset \gls{cmaps}, the method is general enough so that it can be applied to other kind of similar systems. The framework makes use of a strided moving time window to generate the training and test sets, a shallow \gls{mlp} to make the predictions of the \gls{rul} and an evolutionary algorithm (\gls{de}) which needs to be run just once in order to find the best data-related parameters that optimize the scoring functions used in this study.  The results presented in this paper demonstrate that the proposed framework is accurate and computationally efficient, which makes this framework suitable for applications that have limited computational resources such as embedded systems. Furthermore, a comparison with other state-of-the-art methods shown that the proposed method is the best overall performer.

Two major features of the proposed framework are its generality and scalability. While for this paper very specific regressors and evolutionary algorithms were chosen, many other combinations are possible and may be more suitable for different applications. Furthermore, the framework here presented can, in principle, be used for model-construction, i.e. generating the best possible neural network architecture tailored to a specific application. Both issues are to be addressed in future work.


%% ESyS-Particle Reference Manual

\documentclass{report}

\begin{document}
\title{ESyS-Particle Scripting Reference Manual}
\author{Steffen Abe}
\date{\today}
\maketitle
\tableofcontents

\chapter{Introduction}
\chapter{Functions}

\section{Initialization and Setup}

\subsection{makeLattice}

\textsf{makeLattice(ParticleType, $\mathsf{dt}$, nrange, $\mathsf{\alpha}$ )}
\par \medskip

Set the basic parameters of the Model. The parameters are:
\begin{itemize}
\item \textbf{ParticleType} : The type of particle used in the model. Currently supported are :
\begin{itemize}
\item ``Basic'' a spherical, non-rotational particle with 3 (translational) degrees of freedom
\item \textit{planned} ``Rotational'' a spherical particle with 6 (translational + rotational) degrees of freedom.
\end{itemize}
\item $\mathbf{dt}$ : The time step used in the time integration scheme.
\item \textbf{nrange}  and $\mathbf{\alpha}$ : The parameters determining the search range of the neighbor table. nrange is the cut-off for individual particle pairs to be added to a dynamic interaction group. The neighbour table is rebuilt if any particle moves further than $\alpha / 2 $ since the last rebuild.
\end{itemize}

%% --- setProcessDims ----
\subsection{setProcessDims}

\textsf{setProcessDim(nx,ny,nz)}
\par \medskip

Set the process dimensions.

%% --- setSpatialDomain ---
\subsection{setSpatialDomain}

\textsf{setSpatialDomain($x_{min}$,$y_{min}$,$z_{min}$,$x_{max}$,$y_{max}$,$z_{max}$)}
\par \medskip

%% --- readGeometryFile ----
\subsection{readGeometryFile}

\textsf{readGeometryFile(FileName)}
\par \medskip
Read in a geometry description file and initialize the model accordingly. The parameter is:
\begin{itemize}
\item \textbf{FileName} The name of the geometry file. It has to be either relative to the directory from which the program is run or an absolute pathname.
\end{itemize}
For a description the format of the geometry file see \textit{Doc/FileFormat.tex} in the source distribution.

\subsection{readMeshFile}
\label{sec:readMeshFile}
\textsf{resdMeshFile(MeshName,FileName)}
\par \medskip
Read a mesh file in Finley format and setup a triangle mesh.
\begin{itemize}
\item \textbf{MeshName} The name under which the mesh made accessible.
\item \textbf{FileName} The name of the mesh file. It has to be either relative to the directory from which the program is run or an absolute pathname.
\end{itemize}

\subsection{tagParticleNearestTo}

\textsf{tagParticleNearestTo(tag,mask,x,y,z)}
\par \medskip
Tag the particle closest to a given position.
\begin{itemize}
\item \textbf{tag}
\item \textbf{mask}
\item \textbf{x,y,z}
\end{itemize}

\section{Interactions}

\subsection{AddPairInteractions}

\textsf{AddPairInteractions(InteractionType, InteractionName, InteractionParameters)}
\par \medskip

Add a group of interactions between pairs of particles to the model. The InteractionType determines the number and format of the InteractionParameters. The parameters are:
\begin{itemize}
\item \textbf{InteractionType} : The type of interaction. \par
\begin{tabular}{|l|l|}
\hline
Type of interaction & Supported Particle Type \\
\hline
\hline
Elastic & Basic \\
\hline
Friction & Basic \\
\hline
FractalFriction & Basic \\
\hline
AdhesiveFriction & Basic \\
\hline
\end{tabular}

\item \textbf{InteractionName}
\item \textbf{InteractionParameters} The parameters for the interaction. The number and format of the parameters depends on the type of interaction.
\begin{itemize}

\item Elastic : k
\begin{itemize}
\item k : The spring constant for the elastic interaction
\end{itemize}

\item Friction : k, $\mu$, $k_s$,dt \\
Constant Coulomb friction. Implementation follow standard Cundall \& Strack DEM approach
\begin{itemize}
\item k - elastic spring constant
\item $\mu$ - coefficient of friction
\item $k_s$ - shear stiffness (Cundall)
\item dt - time step
\end{itemize}

\item FractalFriction : k, $\mu$, $k_s$, dt \\
\textit{there are some problems with fractal friction currently (hardcoded filename)}
\begin{itemize}
\item k - elastic spring constant
\item $\mu$
\item $k_s$
\item dt
\end{itemize}

\item AdhesiveFriction : k, $\mu$, $k_s$, dt, $r_{cut}$ \\
Coulomb friction with some adhesion added in. For $r_{ij} < r_0$ it is identical to normal friction, for $r_0 \le r_{ij} \le r_{cut}$ there is no friction but an attractive elastic force.
\begin{itemize}
\item k - elastic spring constant
\item $\mu$ - coefficient of friction
\item $k_s$ - shear stiffness (Cundall)
\item dt - time step
\item $r_{cut}$ - cutoff distance for adhesive elastic interactions
\end{itemize}

\end{itemize}
\end{itemize}

\subsection{AddBondedInteractions}

\textsf{AddBondedInteractions(Tag, InteractionName, $k$, $r_{break}$)}
\par \medskip
Generate a group of bonded interactions from the interaction list read from the geometry file. Only interactions with a given tag will be added to the group.
\begin{itemize}
\item \textbf{Tag} : The tag of the interactions which should be in this group
\item \textbf{InteractionName} : The name of the generated interaction group
\item \textbf{$k$} : the elastic spring constant
\item \textbf{$r_{break}$} : the relative extension at which a bond breaks
\end{itemize}

\subsection{AddRotPairInteractions}

\textsf{AddRotPairInteractions(InteractionType, InteractionName, InteractionParameters)}
\par \medskip

Add a group of interactions between pairs of particles to the model.
The InteractionType determines the number and format of the InteractionParameters.
The parameters are:
\begin{itemize}
  \item \textbf{InteractionType} : The type of interaction. \par
  \begin{tabular}{|l|l|}
  \hline
  Type of interaction & Supported Particle Type \\
  \hline
  \hline
  RotElastic & Rot \\
  \hline
  RotFriction & Rot \\
  \hline
  \end{tabular}

  \item \textbf{InteractionName} Name of the interaction.
  \item \textbf{InteractionParameters} The parameters for the interaction.
    The number and format of the parameters depends on the type of interaction.
    \begin{itemize}
      \item Elastic : k
      \begin{itemize}
        \item k : The spring constant for the elastic interaction
      \end{itemize}

      \item RotFriction : $k$, $\mu_s$, $\mu_d$, $k_s$, $\delta t$ \\
      Constant Coulomb friction. Implementation follow standard Cundall \& Strack DEM approach
      \begin{itemize}
        \item $k$ - elastic spring constant
        \item $\mu_s$ - static coefficient of friction
        \item $\mu_d$ - dynamic coefficient of friction
        \item $k_s$ - shear stiffness (Cundall)
        \item $\delta t$ - time step
      \end{itemize}
    \end{itemize}
\end{itemize}

\subsection{AddRotBondedInteractions}
\label{sec::AddRotBondedInteractions}

\newcommand{\brkForce}[1]{f^{\rm max}_{#1}}
\newcommand{\brkTorque}[1]{t^{\rm max}_{#1}}
\textsf{AddRotBondedInteractions(Tag, InteractionName, $k_r$, $k_s$, $k_t$, $k_b$, $\brkForce{r}$, $\brkForce{s}$, $\brkForce{t}$, $\brkForce{b}$)}
Generate a group of rotational bonded interactions from the interaction
list read from the geometry file. Only interactions with a given tag
will be added to the group.
\begin{itemize}
\item{\textbf Tag}
\item{\textbf InterationName}
\item{$k_r$} : radial (normal) spring constant,
\item{$k_s$} : shearing (tangent) spring constant,
\item{$k_t$} : torsional spring constant,
\item{$k_b$} : bending spring constant,
\item{$\brkForce{r}$} : maximum normal force for bond breakage,
\item{$\brkForce{s}$} : maximum shear force for bond breakage,
\item{$\brkTorque{t}$} : maximum torsion torque for bond breakage,
\item{$\brkTorque{b}$} : maximum bending torque for bond breakage.
\end{itemize}

\subsection{AddExclusion}
\label{sec::AddExclusion}

\textsf{AddExclusion(InteractionName1, InteractionName2)}
\par \medskip
Prevent particle pair which are in one interaction group to be also in another interaction group. An common example would be that two particles which are linked together, i.e. the pair is in a bonded interaction group, can not also be in elastic or frictional interaction.
The parameters are:
\begin{itemize}
\item \textbf{InteractionName1} : The name of the interaction group the pair is excluded from.
\item \textbf{InteractionName2} : The name of the interaction group in which the pair has to be to be excluded from InteractionGroup1
\end{itemize}

\subsection{AddDamping}

\textsf{AddDamping(InteractionName, $\nu$, $dt$, $N_{max}$)}
\par \medskip

%%=== addTriMeshInteraction ===
\subsection{addTriMeshInteraction}

\textsf{addTriMeshInteactions(InteractionType,InteractionName,MeshName,Parameters)}
\par\medskip
Add a group of interactions between a triangle mesh and the particles. The mesh needs to be read in with a call to \textbf{readMeshFile}(see section \ref{sec:readMeshFile}) before.

\begin{itemize}
\item \textbf{InteractionType} : The type of interaction. \par
\begin{tabular}{|l|l|}
\hline
Type of interaction & Supported Particle Type \\
\hline
\hline
Elastic & Basic \\
\hline
\end{tabular}

\item \textbf{InteractionName} The name of the new interaction group
\item \textbf{MeshName} The name of the mesh (see \ref{sec:readMeshFile}) with wh ich the particles interact
\item \textbf{InteractionParameters} The parameters for the interaction. The number and format of the parameters depends on the type of interaction.
\begin{itemize}
\item Elastic : k
\begin{itemize}
\item k : The spring constant for the elastic interaction
\end{itemize} %% Elastic

\end{itemize} %% parameters

\end{itemize}

%%=== addBondedTriMeshInteractions ===
\subsection{addBondedTriMeshInteractions}

\textsf{addBondedTriMeshInteractions(InteractionName,MeshName,k,$r_{break}$,BuildType,BuildParams)}
\par\medskip
Add a group of bonded interactions between a triangle mesh and the particles. The mesh needs to be read in with a call to \textbf{readMeshFile}(see section \ref{sec:readMeshFile}) before.

\begin{itemize}
\item BuildByTag : tag,mask
\item BuildByGap : gap
\end{itemize}
%%=== SetParticleNonDynamic ===
\subsection{SetParticleNonDynamic}

\textsf{SetParticleNonDynamic(Tag)}
\par \medskip
Make all particles with the given tag non-dynamic, i.e. interactions involving those particles will still generate forces, but the particles will not move in response to this forces. This is achieved by setting $1/mass=0$, i.e. have infinite mass in the calculation of particle acceleration but also have $mass=0$ for the calculation of kinetic energy.
The parameter is:
\begin{itemize}
\item \textbf{Tag} : The tag which the particles need to have.
\end{itemize}

%%=== SetParticleNonRot ===
\subsection{SetParticleNonRot}

\textsf{SetParticleNonRot(Tag)}
\par \medskip
Make all particles with the given tag non-rotational, i.e. interactions involving those particles will still generate forces, but the particles will not rotate in response to this forces. This is achieved by setting the inverse moment of inertia to 0;
The parameter is:
\begin{itemize}
\item \textbf{Tag} : The tag which the particles need to have.
\end{itemize}

\section{Walls}

``Walls'' in the Lattice Solid Model are used to represent the boundary conditions of the models .They behave as rigid, planar objects which interact with the particles, but aren't dynamically moving in response to the resulting forces themselves. They could, in a sense be considered to be of infinite mass.  \par
All the walls generated by initWall and related functions, i.e. initWall (\ref{sec::initWall}), initBondedWall (\ref{sec::initBondedWall}) and initSoftBondedWall(\ref{sec::initSBWall}) will have ids assigned in order of their construction, beginning with 0, i.e. the first call generates the wall with id 0, the second call generates the wall with id 1 and so on.

\subsection{initWall}
\label{sec::initWall}

\textsf{initWall($P_x$, $P_y$, $P_z$, $N_x$, $N_y$, $N_z$,k)}
\par \medskip
Add a infinite, planar, elastic wall with a defined position. The geometry of the wall is described by a point on the plane and the normal vector. Any particles which are in contact with the wall, i.e. the separation between the particle position and the plane is smaller than the particle radius interact with the wall by a repulsive linear elastic interaction, $F=k(r-r_0)\mathbf{n}$ where $F$ is the force applied to the particle, $k$ the spring constant, $r$ the distance between the plane and the particle position, $r_0$ the particle radius and $\mathbf{n}$ the normal vector of the plane. \par
The parameters are:
\begin{itemize}
\item $\mathbf{P_x}$, $\mathbf{P_y}$, $\mathbf{P_z}$ : A point on the plane (x, y and z component).
\item $\mathbf{N_x}$, $\mathbf{N_y}$, $\mathbf{N_z}$ : The normal vector (x, y and z component).
\item \textbf{k} : The spring constant for the elastic interactions between the wall and the particles.
\end{itemize}

\subsection{initBondedWall}
\label{sec::initBondedWall}
Add a infinite, planar wall bonded to some particles. The geometry of the wall is described by a point on the plane and the normal vector.

\textsf{initBondedWall($P_x$, $P_y$, $P_z$, $N_x$, $N_y$, $N_z$,k,Tag)}
\par\medskip
The parameters are:
\begin{itemize}
\item $\mathbf{P_x}$, $\mathbf{P_y}$, $\mathbf{P_z}$ : A point on the plane (x, y and z component).
\item $\mathbf{N_x}$, $\mathbf{N_y}$, $\mathbf{N_z}$ : The normal vector (x, y and z component).
\item \textbf{k} : The spring constant for the elastic interactions between the wall and the particles.
\item \textbf{Tag}
\end{itemize}

\subsection{initViscWall}
\label{sec::initViscWall}
Add a infinite, planar wall exerting viscous drag to the tagged particles if moved. The geometry of the wall is described by a point on the plane and the normal vector.

\textsf{initViscWall($P_x$, $P_y$, $P_z$, $N_x$, $N_y$, $N_z$,k,$\nu$,Tag)}
\par\medskip
The parameters are:
\begin{itemize}
\item $\mathbf{P_x}$, $\mathbf{P_y}$, $\mathbf{P_z}$ : A point on the plane (x, y and z component).
\item $\mathbf{N_x}$, $\mathbf{N_y}$, $\mathbf{N_z}$ : The normal vector (x, y and z component).
\item \textbf{k} : The spring constant for the elastic interactions between the wall and the particles.
\item $\mathbf{\nu}$
\item \textbf{Tag}
\end{itemize}

\subsection{initSoftBondedWall}
\label{sec::initSBWall}
Add a infinite, planar wall bonded to some particles. The geometry of the wall is described by a point on the plane and the normal vector. The spring coefficients for the interaction between particles and the wall are dependent on the direction.

\textsf{initSoftBondedWall($P_x$, $P_y$, $P_z$, $N_x$, $N_y$, $N_z$,$k_x$,$k_y$,$k_z$,Tag)}
\par\medskip
The parameters are:
\begin{itemize}
\item $\mathbf{P_x}$, $\mathbf{P_y}$, $\mathbf{P_z}$ : A point on the plane (x, y and z component).
\item $\mathbf{N_x}$, $\mathbf{N_y}$, $\mathbf{N_z}$ : The normal vector (x, y and z component).
\item $\mathbf{k_x}$, $\mathbf{k_y}$, $\mathbf{k_z}$ : The spring constants for the bonded elastic interactions between the wall and the particles in x-, y- and z-directions.
\item \textbf{Tag}
\end{itemize}

\section{Moving things around and applying forces}

\subsection{MoveParticleTo}

\subsection{SetParticleVelocity}

\textsf{SetParticleVelocity(Id,$v_x$,$v_y$,$v_z$)}
\par\medskip

Set the velocity of a particle to a given value.
The parameters are:
\begin{itemize}
\item \textbf{Id} : the id of the particle
\item $\mathbf{v_x}$,$mathbf{v_y}$,$mathbf{v_z}$ : the velocity
\end{itemize}

\subsection{moveWall}

\textsf{moveWall(Id,$D_x$, $D_y$, $D_z$)}
\par\medskip

The parameters are:

\begin{itemize}
\item \textbf{Id} :
\item $D_x$, $D_y$, $D_z$ :
\end{itemize}

\subsection{applyForceToWall}
Apply a given force to a wall. The force is only applied during the current timestep, i.e. the function needs to be called within the Loading function in the script.
\textit{Not implemented for SoftBonded (\ref{sec::initSBWall}) walls.}

\textsf{applyForceToWall(Id,$F_x$, $F_y$, $F_z$)}
\par\medskip

The parameters are:

\begin{itemize}
\item \textbf{Id} : The Id of the wall.
\item $F_x$, $F_y$, $F_z$ : The force to be applied (x, y and z component).
\end{itemize}

\subsection{setVelocityOfWall}

\section{Saving Stuff}

\subsection{Fields Overview}

The fields which can be saved are distinguished by two properties: the objects they are defined on, i.e. particles or interactions and the data type of the field, i.e. scalar or vector (tensor to come).

\subsection{Available Fields}

\subsubsection{Fields available on Particles}
\par \medskip

\begin{tabular}{|l|p{3.5cm}|l|p{2.5cm}|}
\hline
Name & Field & Data type & Supported Particle Types \\
\hline \hline
\verb{e_kin{ & kinetic energy & scalar & Basic \\
\hline
\verb{displacement{ & total displacement & vector & Basic \\
\hline
\verb{velocity{ & linear velocity & vector & Basic \\
\hline
\verb{v_abs{ & absolute value of linear velocity & scalar & Basic \\
\hline
\verb{force{ & force applied to the particle & vector & Basic \\
\hline
\end{tabular}

\subsubsection{Fields available on Interactions}
\par \medskip

\begin{tabular}{|l|p{2.6cm}|l|p{2.5cm}|c|}
\hline
Name & Field & Data type & Supported Interaction Types & checked\\
\hline \hline
\verb{potential_energy{ & potential energy & scalar & Bonded, Friction, FractalFriction &\\
\hline
\verb{slipping{ & number of frictional interactions in a dynamic state & scalar & Friction, FractalFriction &\\
\hline
\verb{F_fric{ & current frictional force & scalar & Friction & x \\
\hline
\verb{muF_n{ & product of coefficient of friction and normal force & scalar & Friction & x \\
\verb{F_fric{ & current frictional force & scalar & Friction & x \\
\hline
\verb{strain{ & relative strain on interaction, compression positive & scalar & Bonded & \\
\hline
\end{tabular}

\subsubsection{Fields available on Triangles}
\par \medskip

\begin{tabular}{|l|p{3.5cm}|l|}
\hline
Name & Field & Data type \\
\hline \hline
\verb{force{ & total force & vector \\
\hline
\verb{pressure{ & pressure & scalar \\
\hline
\end{tabular}

\subsection{Output Formats}
\label{sec::OutputFormats}

All field can be saved in different formats. The following formats are currently supported:

\begin{itemize}
\item \textbf{DX} : The complete field is saved in one OpenDX compatible file for each timestep. For particle based fields  the position of the particle and the value of the field at that particle are saved. For interaction based fields the position of the centre of the interaction, i.e. in case of a 2-particle interaction the middle point between the particles, and the value of the field for this interaction is saved.
\item \textbf{SUM} : The sum over all data in the field is saved into one continuous file, one value per timestep.
\item \textbf{MAX} : The maximum over all data in the field is saved into one continuous file, one value per timestep.
\item \textbf{RAW\_SERIES} : The complete field is saved in one file, one row of values per time step. \textit{not yet implemented for interaction fields}
\end{itemize}

\section{Fields Defined on Interactions}

\subsection{addScalarInteractionFieldSaver}
\textsf{addScalarInteractionFieldSaver(FileName, FieldName, InteractionType, InteractionName, SaveType, $T_0$, $T_{max}$, $dT$)}
\par \medskip
Add a saver for a scalar field defined on an interaction. The parameters are:

\begin{itemize}
\item \textbf{FileName} : The name of the file into which the field is saved. If the  \textbf{SaveType} is such that the field is saved into a separate file for each time step, for example ``DX'', the \textbf{FileName} is used as the base for forming the individual filenames as FileName.N.Ext, were N is the number of the file (0....$(T_{max}-T_0)/dT$) and Ext the file extension for the SaveType, such as dx for ``DX''.
\item \textbf{FieldName} : The name of the field to be saved. The name has to be of the fields supported by the Interaction for which it is saved, otherwise an error message will result.
\item \textbf{InteractionType} The type of the interaction for which the field is saved.
\item \textbf{InteractionName} The name of the interaction group for which the field is saved.
\item \textbf{SaveType} The way the field is saved. Currently supported are ``DX'', ``SUM'' and ``MAX''. See section \ref{sec::OutputFormats}.
\item \textbf{$T_0$} The first timestep for which the field is saved.
\item \textbf{$T_{max}$} The last timestep for which the field is saved.
\item \textbf{$dT$} The number of timesteps between savings. For example if $T_0$=1, $T_{max}$=31 and $dT$=5 the field would be saved for the timesteps 1,6,11,16,21,26,31.
\end{itemize}

\subsection{addTaggedScalarInteractionFieldSaver}
\label{sec::TaggedSIFSaver}
\textsf{addTaggedScalarInteractionFieldSaver(FileName, FieldName, InteractionType, InteractionName, SaveType, $T_0$, $T_{max}$, $dT$,Tag,Mask)}
\par \medskip

Add a saver for a scalar field defined on an interaction. The field is only saved for interaction involving at least one particle with a tag fulfilling the given criteria. The parameters are:

\begin{itemize}
\item \textbf{FileName} : The name of the file into which the field is saved. If the  \textbf{SaveType} is such that the field is saved into a separate file for each time step, for example ``DX'', the \textbf{FileName} is used as the base for forming the individual filenames as FileName.N.Ext, were N is the number of the file (0....$(T_{max}-T_0)/dT$) and Ext the file extension for the SaveType, such as dx for ``DX''.
\item \textbf{FieldName} : The name of the field to be saved. The name has to be of the fields supported by the Interaction for which it is saved, otherwise an error message will result.
\item \textbf{InteractionType} The type of the interaction for which the field is saved.
\item \textbf{InteractionName} The name of the interaction group for which the field is saved.
\item \textbf{SaveType} The way the field is saved. Currently defined are ``DX'', ``SUM'' and ``MAX''. See section \ref{sec::OutputFormats}.
\item \textbf{$T_0$} The first timestep for which the field is saved.
\item \textbf{$T_{max}$} The last timestep for which the field is saved.
\item \textbf{$dT$} The number of timesteps between savings.
\item \textbf{Tag} The particle tag.
\item \textbf{Mask} The mask used in the tag comparison, i.e. a interaction is included if for at least one of the particles involved the following is true: $(particle->getTag() | Mask ) == (Tag | Mask)$, i.e. the mask is used to determine which bits in the tag are compared. For example if Tag=5 (binary 101) and Mask=4 (binary 100), particles with a tag in which bit 3 is 1 would be used, i.e. 5 (101) or 6 (110), but not 8 (1000). A Mask of -1 (binary all 1) will lead to an exact comparison of the tags.
\end{itemize}

\subsection{addCheckedScalarInteractionFieldSaver}

\textsf{addCheckedScalarInteractionFieldSaver(FileName, FieldName, InteractionType, InteractionName, SaveType, $T_0$, $T_{max}$, $dT$)}
\par \medskip

Add a saver for a checked scalar field defined on an interaction, i.e. the field is only saved for interactions where the field access function returns ``true''.  The parameters are:

\begin{itemize}
\item \textbf{FileName} : The name of the file into which the field is saved. If the  \textbf{SaveType} is such that the field is saved into a separate file for each time step, for example ``DX'', the \textbf{FileName} is used as the base for forming the individual filenames as FileName.N.Ext, were N is the number of the file (0....$(T_{max}-T_0)/dT$) and Ext the file extension for the SaveType, such as dx for ``DX''.
\item \textbf{FieldName} : The name of the field to be saved. The name has to be of the fields supported by the Interaction for which it is saved, otherwise an error message will result.
\item \textbf{InteractionType} The type of the interaction for which the field is saved.
\item \textbf{InteractionName} The name of the interaction group for which the field is saved.
\item \textbf{SaveType} The way the field is saved. Currently supported are ``DX'', ``SUM'' and ``MAX''. See section \ref{sec::OutputFormats}.
\item \textbf{$T_0$} The first timestep for which the field is saved.
\item \textbf{$T_{max}$} The last timestep for which the field is saved.
\item \textbf{$dT$} The number of timesteps between savings.
\end{itemize}

\subsection{addTaggedCheckedScalarInteractionFieldSaver}

\textsf{addTaggedCheckedScalarInteractionFieldSaver(FileName, FieldName, InteractionType, InteractionName, SaveType, $T_0$, $T_{max}$, $dT$,Tag,Mask)}
\par \medskip

Checked version of \textsf{addTaggedScalarInteractionFieldSaver} (see \ref{sec::TaggedSIFSaver}). The parameters are:

\begin{itemize}
\item \textbf{FileName} : The name of the file into which the field is saved. If the  \textbf{SaveType} is such that the field is saved into a separate file for each time step, for example ``DX'', the \textbf{FileName} is used as the base for forming the individual filenames as FileName.N.Ext, were N is the number of the file (0....$(T_{max}-T_0)/dT$) and Ext the file extension for the SaveType, such as dx for ``DX''.
\item \textbf{FieldName} : The name of the field to be saved. The name has to be of the fields supported by the Interaction for which it is saved, otherwise an error message will result.
\item \textbf{InteractionType} The type of the interaction for which the field is saved.
\item \textbf{InteractionName} The name of the interaction group for which the field is saved.
\item \textbf{SaveType} The way the field is saved. Currently defined are ``DX'', ``SUM'' and ``MAX''. See section \ref{sec::OutputFormats}.
\item \textbf{$T_0$} The first timestep for which the field is saved.
\item \textbf{$T_{max}$} The last timestep for which the field is saved.
\item \textbf{$dT$} The number of timesteps between savings.
\item \textbf{Tag} The particle tag.
\item \textbf{Mask} The mask used in the tag comparison.
\end{itemize}
\subsection{addVectorInteractionFieldSaver}

\textsf{addVectorInteractionFieldSaver(FileName,FieldName,IGType,IGName,SaveType,$t_0$,$t_{end}$,$dt$)}

\subsection{addTaggedVectorInteractionFieldSaver}

\textsf{NOT IMPLEMENTED}

\section{Fields Defined on Particles}

\subsection{addScalarParticleFieldSaver}

\textsf{addScalarParticleFieldSaver(FileName, FileName, SaveType, $T_0$, $T_{max}$, $dt$)}
\par \medskip

Add a saver for a scalar field defined on the particles. The parameters are:

\begin{itemize}
\item \textbf{FileName} : The name of the file into which the field is saved. If the  \textbf{SaveType} is such that the field is saved into a separate file for each time step, for example ``DX'', the \textbf{FileName} is used as the base for forming the individual filenames as FileName.N.Ext, were N is the number of the file (0....$(T_{max}-T_0)/dT$) and Ext the file extension for the SaveType, such as dx for ``DX''.
\item \textbf{FieldName} : The name of the field to be saved. The name has to be of the fields supported by the Interaction for which it is saved, otherwise an error message will result.
\item \textbf{SaveType} The way the field is saved. Currently supported are ``DX'' and ``SUM''. See section \ref{sec::OutputFormats}.
\item \textbf{$T_0$} The first timestep for which the field is saved.
\item \textbf{$T_{max}$} The last timestep for which the field is saved.
\item \textbf{$dT$} The number of timesteps between savings. For example if $T_0$=1, $T_{max}$=31 and $dT$=5 the field would be saved for the timesteps 1,6,11,16,21,26,31.
\end{itemize}

\subsection{addTaggedScalarParticleFieldSaver}

\textsf{addTaggedScalarParticleFieldSaver(FileName, FieldName, FileFormat, $T_0$, $T_{max}$, $dt$, Tag, Mask)}
\par \medskip

Add a saver for a scalar field defined on the particles. The field is only saved for particles with a tag fulfilling the given criteria. The parameters are:

\begin{itemize}
\item \textbf{FileName} : The name of the file into which the field is saved. If the  \textbf{SaveType} is such that the field is saved into a separate file for each time step, for example ``DX'', the \textbf{FileName} is used as the base for forming the individual filenames as FileName.N.Ext, were N is the number of the file (0....$(T_{max}-T_0)/dT$) and Ext the file extension for the SaveType, such as dx for ``DX''.
\item \textbf{FieldName} : The name of the field to be saved. The name has to be of the fields supported by the Interaction for which it is saved, otherwise an error message will result.
\item \textbf{SaveType} The way the field is saved. Currently defined are ``DX'' and ``SUM''. See section \ref{sec::OutputFormats}.
\item \textbf{$T_0$} The first timestep for which the field is saved.
\item \textbf{$T_{max}$} The last timestep for which the field is saved.
\item \textbf{$dT$} The number of timesteps between savings.
\item \textbf{Tag} The particle tag.
\item \textbf{Mask} The mask used in the tag comparison, i.e. the field is saved for particles for which the following is true: $(particle->getTag() | Mask ) == (Tag | Mask)$, i.e. the mask is used to determine which bits in the tag are compared. For example if Tag=5 (binary 101) and Mask=4 (binary 100), particles with a tag in which bit 3 is 1 would be used, i.e. 5 (101) or 6 (110), but not 8 (1000). A Mask of -1 (binary all 1) will lead to an exact comparison of the tags.
\end{itemize}

\subsection{addVectorParticleFieldSaver}

\textsf{addVectorParticleFieldSaver(FileName, FieldName, FileFormat, $T_0$, $T_{max}$, $dt$)}
\par \medskip

Add a saver for a vector field defined on the particles. The parameters are:

\begin{itemize}
\item \textbf{FileName} : The name of the file into which the field is saved. If the  \textbf{SaveType} is such that the field is saved into a separate file for each time step, for example ``DX'', the \textbf{FileName} is used as the base for forming the individual filenames as FileName.N.Ext, were N is the number of the file (0....$(T_{max}-T_0)/dT$) and Ext the file extension for the SaveType, such as dx for ``DX''.
\item \textbf{FieldName} : The name of the field to be saved. The name has to be of the fields supported by the Interaction for which it is saved, otherwise an error message will result.
\item \textbf{SaveType} The way the field is saved. Currently supported are ``DX'' and ``SUM''. See section \ref{sec::OutputFormats}.
\item \textbf{$T_0$} The first timestep for which the field is saved.
\item \textbf{$T_{max}$} The last timestep for which the field is saved.
\item \textbf{$dT$} The number of timesteps between savings. For example if $T_0$=1, $T_{max}$=31 and $dT$=5 the field would be saved for the timesteps 1,6,11,16,21,26,31.
\end{itemize}

\subsection{addTaggedVectorParticleFieldSaver}

\textsf{addTaggedVectorParticleFieldSaver(FileName, FieldName, FileFormat, $T_0$, $T_{max}$, $dt$, Tag, Mask)}
\par \medskip

Add a saver for a vector field defined on the particles. The field is only saved for particles with a tag fulfilling the given criteria. The parameters are:

\begin{itemize}
\item \textbf{FileName} : The name of the file into which the field is saved. If the  \textbf{SaveType} is such that the field is saved into a separate file for each time step, for example ``DX'', the \textbf{FileName} is used as the base for forming the individual filenames as FileName.N.Ext, were N is the number of the file (0....$(T_{max}-T_0)/dT$) and Ext the file extension for the SaveType, such as dx for ``DX''.
\item \textbf{FieldName} : The name of the field to be saved. The name has to be of the fields supported by the Interaction for which it is saved, otherwise an error message will result.
\item \textbf{SaveType} The way the field is saved. Currently defined are ``DX'' and ``SUM''. See section \ref{sec::OutputFormats}.
\item \textbf{$T_0$} The first timestep for which the field is saved.
\item \textbf{$T_{max}$} The last timestep for which the field is saved.
\item \textbf{$dT$} The number of timesteps between savings.
\item \textbf{Tag} The particle tag.
\item \textbf{Mask} The mask used in the tag comparison, i.e. the field is saved for particles for which the following is true: $(particle->getTag() | Mask ) == (Tag | Mask)$, i.e. the mask is used to determine which bits in the tag are compared. For example if Tag=5 (binary 101) and Mask=4 (binary 100), particles with a tag in which bit 3 is 1 would be used, i.e. 5 (101) or 6 (110), but not 8 (1000). A Mask of -1 (binary all 1) will lead to an exact comparison of the tags.
\end{itemize}

\section{Other fields}

\subsection{addVectorTriangleFieldSaver}
\textsf{addVectorTriangleFieldSaver(FileName,FieldName,MeshName,SaveType,$t_0$,$t_{end}$,$dt$)}
\par \medskip

Add a saver for a vector field defined on the triangles of a given mesh. The parameters are:
\begin{itemize}
\item \textbf{FileName}
\item \textbf{FieldName}
\item \textbf{MeshName}
\item \textbf{SaveType}
\item \textbf{$t_0$} The first timestep for which the field is saved.
\item \textbf{$t_{max}$} The last timestep for which the field is saved.
\item \textbf{$dt$} The number of timesteps between savings.

\end{itemize}

\subsection{addScalarrTriangleFieldSaver}
\textsf{addScalarTriangleFieldSaver(FileName,FieldName,MeshName,SaveType,$t_0$,$t_{end}$,$dt$)}
\par \medskip

Add a saver for a scalar field defined on the triangles of a given mesh. The parameters are:
\begin{itemize}
\item \textbf{FileName}
\item \textbf{FieldName}
\item \textbf{MeshName}
\item \textbf{SaveType}
\item \textbf{$t_0$} The first timestep for which the field is saved.
\item \textbf{$t_{max}$} The last timestep for which the field is saved.
\item \textbf{$dt$} The number of timesteps between savings.

\end{itemize}

\chapter{Examples}

\end{document}