% declare document class and geometry
\documentclass[12pt]{article} % use larger type; default would be 10pt
\usepackage[english]{babel} % for hyphenation dictionary
%\setdefaultlanguage{english} % polyglossia command for use with XeTeX / LuaTeX
\usepackage[margin=1in]{geometry} % handle page geometry

% import packages and commands
\input{../header2.tex}

% title information
\title{Phys 221A -- Quantum Mechanics -- Lec16}
\author{UCLA, Fall 2014}
\date{\formatdate{26}{11}{2014}} % Activate to display a given date or no date (if empty),
         % otherwise the current date is printed

\begin{document}
\maketitle

\section{Rotations and Angular Momentum in Quantum Mechanics}

\subsection{Group theory}

Orthogonal transformations are Euclidean transformations which do not change distances, i.e. rotations and reflections. Suppose we have a transformation $R$ taking
\begin{eqn}
\v x \mapsto \v x' = R \cdot \v x.
\end{eqn}
For the transformation to be orthogonal, we must have
\begin{eqn}
\norm{\v x} = \sqrt{x_i x_i} = \norm{\v x'} = \sqrt{R_{ij} x_j R_{ij'} x_{j'}},
\end{eqn}
which implies that
\begin{eqn}
R_{ij} R_{ij'} = \delta_{jj'}.
\end{eqn}
In other words, we have
\begin{eqn}
R^\top R = 1 \qquad
\implies \qquad
R^\top = R\inv,
\end{eqn}
so $R$ is an orthogonal matrix. Thus rotations and reflections are parametrized by orthogonal matrices. The set of all orthogonal matrices in 3 dimensions is a \textit{group} called $O(3)$.

\begin{definition}
A \textit{group} is a set $G = \set{g_\alpha}$ with an operation $*$ with the following properties.
\begin{itemize}
\item (Identity) There is an identity $1 \in G$ such that for all $g_\alpha \in G$ we have $g_\alpha * 1 = 1 * g_\alpha = g_\alpha$.
\item (Closure) For each $g_\alpha, g_\beta \in G$, we have $g_\alpha * g_\beta \in G$.
\item (Invertibility) For each $g_\alpha \in G$ we have an inverse $g_\alpha\inv \in G$ such that $g_\alpha * g_\alpha\inv = g_\alpha\inv * g_\alpha = 1$.
\item (Associativity) For $g_\alpha, g_\beta, g_\gamma \in G$, we have $(g_\alpha * g_\beta) * g_\gamma = g_\alpha * (g_\beta * g_\gamma)$.
\end{itemize}
In general, $g_\alpha * g_\beta \neq g_\beta * g_\alpha$, i.e. group elements must not necessarily commute. If all elements commute, the group is called \textit{Abelian}. A subset of a group $G$ that is itself a group is called a \textit{subgroup} of $G$.
\end{definition}

Notice that for an orthogonal matrix $R$, we have $\det R = \pm 1$. The subgroup of $O(3)$ with determinant 1 is the group of proper rotations $SO(3)$. If $R \in O(3)$ and $\det R = -1$ then we call $R$ an improper rotation. If furthermore $R^2 = 1$, then $R$ is a reflection. Note that in three dimensions, parity is an improper rotation, but in two dimensions, parity is a proper rotation---it's just a rotation by $\pi$. In general, parity is a proper rotation in even dimensions and improper in odd dimensions.

For now we will consider rotations in three dimensions. A rotation $R_z (\phi)$ about the $z$-axis can be written
\begin{eqn}
R_z (\phi) =
\begin{pmatrix}
\cos\phi & -\sin\phi & 0 \\
\sin\phi & \cos\phi & 0 \\
0 & 0 & 1
\end{pmatrix}.
\end{eqn}
For an infinitesimal angle $\epsilon$ we have
\begin{eqn}
R_z (\epsilon) =
\begin{pmatrix}
1 - \epsilon^2 / 2 & -\epsilon & 0 \\
\epsilon & 1 - \epsilon^2 / 2 & 0 \\
0 & 0 & 1
\end{pmatrix}
+ \bigO(\epsilon^2).
\end{eqn}
Similarly for the other axes the infinitesimal rotations are (to quadratic order)
\begin{eqn}
R_x (\epsilon) =
\begin{pmatrix}
1 & 0 & 0 \\
0 & 1 - \epsilon^2 / 2 & -\epsilon \\
0 & \epsilon & 1 - \epsilon^2 / 2 \\
\end{pmatrix}, \qquad
R_y (\epsilon) =
\begin{pmatrix}
1 - \epsilon^2 / 2 & 0 & \epsilon \\
0 & 1 & 0 \\
-\epsilon & 0 & 1 - \epsilon^2 / 2 \\
\end{pmatrix}.
\end{eqn}
If we look at the commutators of the rotations about the axes, we find
\begin{eqn}
[R_x(\epsilon), R_y(\epsilon)] = R_z(\epsilon^2) - 1 =
\begin{pmatrix}
0 & -\epsilon^2 & 0 \\
\epsilon^2 & 0 & 0 \\
0 & 0 & 0
\end{pmatrix}.
\end{eqn}
One can generalize to other permutations of the elementary rotations by cyclic permutation of $(xyz)$. These commutator relations will be useful in our applications to quantum mechanics.

\subsection{Angular momentum in QM}

Recall that the infinitesimal evolution operator can be written
\begin{eqn}
U(\epsilon) = 1 - \frac{i}{\hbar} \epsilon H + \bigO(\epsilon^2),
\end{eqn}
so we call $H$ the \textit{generator of time evolution}. From now on we will assume that $H$ is time-independent. We can recover the full time evolution by repeatedly composing infinitesimal time evolutions
\begin{eqn}
U(t) = \lim_{n \rightarrow \infty} \left[ U(t/n) \right]^n.
\end{eqn}
Now, recall the identity
\begin{eqn}
e^\phi = \lim_{n \rightarrow \infty} \left( 1 + \frac{\phi}{n} \right)^n,
\end{eqn}
which also works for operators so that we have
\begin{eqn}
U(t) = \lim_{n \rightarrow \infty} \left( 1 - \frac{i}{\hbar} \, \frac{t}{n} H \right)^n = e^{i t H / \hbar}.
\end{eqn}
Thus we have
\begin{eqn}
H = i \hbar \partial_t U(t).
\end{eqn}

Similarly, momentum is the generator of translations,
\begin{eqn}
T (\v \epsilon) = 1 - \frac{i}{\hbar} \v \epsilon \cdot \v p = 1 - \v \epsilon \cdot \v \nabla,
\end{eqn}
since $\v p = - i \hbar \v \nabla$. Thus similarly we have
\begin{eqn}
\v p = i \hbar \v \nabla_{\v x} T(\v x).
\end{eqn}
We can now define the angular momentum operator $\v J$ in quantum mechanics in a similar way, as the generator of rotations
\begin{eqn}
\v J = i \hbar \v \nabla_{\v \phi} R(\v \phi)
\end{eqn}
where $R(\v \phi)$ is a rotation about $\uv \phi$ by angle $\abs{\v \phi}$.

Quantum mechanically, the general state of a particle in some rotation state is described by a ket
\begin{eqn}
\ket{\alpha} = \ket{\sigma} \otimes \ket{\psi},
\end{eqn}
where $\ket{\psi}$ is the usual $L_2$ Euclidean wavefunction giving dynamics in real space, while $\ket{\sigma}$ is a spin ket, or spinor, giving us dynamics in ``spin space''. In the absence of the spinor component we just have the Euclidean wavefunction. Furthermore, since $\v L = \v r \times \v p$ and $\v p = -i\hbar \v \nabla$, an infinitesimal rotation can be written
\begin{eqn}
R(\v \epsilon) = 1 - \frac{i}{\hbar} \v \epsilon \cdot \v L = 1 - \v \epsilon \cdot (\v r \times \v \nabla).
\end{eqn}
In general, when we include the spin structure the angular momentum $\v J$ is decomposed
\begin{eqn}
\v J = \v L + \v S,
\end{eqn}
where $\v L$ is the ``orbital'' angular momentum and $\v S$ is the ``spin'' angular momentum.

The only remaining task is to construct the (irreducible) representations of $SO(3)$. We define a \textit{representation} $D(g)$ of a group element $g \in G$ if $D$ is a homomorphism, i.e. given $g, h \in G$ we have
\begin{eqn}
D(g*h) = D(g) * D(h).
\end{eqn}
In the case of spin rotations, given a spin ket $\ket{\sigma}$ we have under rotations
\begin{eqn}
\ket{\sigma} \rightarrow D(R) \ket{\sigma}
\end{eqn}
It turns out that the irreducible representations of $D(R)$ are $N \times N$ matrices with $N = 2s + 1$ where $s = 0, \frac{1}{2}, 1, \frac{3}{2}, \dots$ is the spin of the particle. In terms of elementary particles, bosons have integer-valued spin while fermions have half-integer-valued spin.

\end{document}


% Created 2021-09-02 Thu 17:27
% Intended LaTeX compiler: pdflatex
\documentclass[presentation,aspectratio=169, usenames, dvipsnames]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{khpreamble}
\usepackage{amssymb}
\usepgfplotslibrary{groupplots}
\newcommand*{\shift}{\operatorname{q}}
\definecolor{ppc}{rgb}{0.1,0.1,0.6}
\definecolor{iic}{rgb}{0.6,0.1,0.1}
\definecolor{ddc}{rgb}{0.1,0.6,0.1}
\usetheme{default}
\author{Kjartan Halvorsen}
\date{\today}
\title{Process Automation Laboratory - PID control}
\hypersetup{
 pdfauthor={Kjartan Halvorsen},
 pdftitle={Process Automation Laboratory - PID control},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 26.3 (Org mode 9.4.6)},
 pdflang={English}}
\begin{document}

\maketitle

\section{Repetition - Second-order model critically damped}
\label{sec:orgd8c85bb}
\begin{frame}[label={sec:org8c495f4}]{Second-order models}
\end{frame}
\begin{frame}[label={sec:org4130cf8}]{Two first-order models in series}
\begin{center}
\begin{tikzpicture}
  \node {\includegraphics[width=0.4\linewidth]{../../figures/tank-with-hole-no-variables}};
  \node at (5.3,-2.05) {\includegraphics[width=0.4\linewidth]{../../figures/tank-with-hole-no-variables}};
\end{tikzpicture}
\end{center}

\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
    \node[block, right of=input, node distance=20mm] (plant1)  {$G_1(s)$};
    \node[block, right of=plant1, node distance=26mm] (plant2)  {$G_2(s)$};
    \node[coordinate, right of=plant2, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$u(t)$} (plant1);
    \draw[->] (plant1) -- node[coordinate, ] (mp) { } (plant2);
    \draw[->] (plant2) -- node[above, near end] {$y(t)$} (output);
    \draw[red] (plant1.south west) ++(-4mm,-10mm) rectangle ++(49mm, 20mm);

    \node[red,below of=mp, node distance=10mm] {$G(s) = G_1(s)G_2(s)$};
  \end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}[label={sec:org51bc4e6}]{Fitting second-order critically-damped model}
\alert{Model with two identical time-constants.}
Assuming model
\[ \textcolor{green!50!black}{Y(s)} = \frac{K}{(s\tau + 1)^2}\textcolor{blue!80!black}{U(s)} \quad \overset{U(s) = \frac{u_f}{s}}{\Longrightarrow} \quad \textcolor{green!50!black}{y(t)} = u_f K\Big( 1 - (1+\frac{t}{\tau}\big)\mathrm{e}^{-\frac{t}{\tau}}\Big)u_H(t)\]
\def\Tcnst{2}
\def\tdelay{0.0}
\def\ggain{2}
\def\uampl{0.8}
\pgfmathsetmacro{\yfinal}{\uampl*\ggain}
\pgfmathsetmacro{\ytwo}{\yfinal*(1-2*exp(-1))}
\pgfmathsetmacro{\ytwofactor}{(1-2*exp(-1))}
\pgfmathsetmacro{\two}{\tdelay + \Tcnst}

\begin{center}
  \begin{tikzpicture}
    \begin{axis}[
    width=14cm,
    height=4.5cm,
    grid = both,
    xtick = {0, \two},
    xticklabels = {0,  $\tau$},
    ytick = {0, \ytwo, \uampl, \yfinal},
    yticklabels = {0, $\ytwofactor y_f$, $u_f$, $y_f$},
    xmin = -0.2,
    clip = false,
    %minor y tick num=9,
    %minor x tick num=9,
    %every major grid/.style={red, opacity=0.5},
    ]
      \addplot [thick, green!50!black, no marks, domain=0:11, samples=100] {\uampl*\ggain*(x>\tdelay)*(1 - (1+x/\Tcnst)*exp(-(x-\tdelay)/\Tcnst)} node [coordinate, pos=0.9, pin=-90:{$y(t)$}] {};
      \addplot [const plot, thick, blue!80!black, no marks, domain=-1:11, samples=100] coordinates {(-1,0) (0,0) (0,\uampl) (11,\uampl)} node [coordinate, pos=0.9, pin=-90:{$u(t)$}] {};
      \node at (axis cs: 11, -0.3) {$t$};
    \end{axis}
  \end{tikzpicture}
\end{center}

\[ y_f = \lim_{t\to\infty} y(t) = u_f K \quad \Rightarrow \quad K = \frac{y_f}{u_f}. \]
\end{frame}

\section{PID parameter intuition}
\label{sec:org9124c70}
\begin{frame}[label={sec:org21ee677}]{Feedback control}
   \begin{center}
   \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]
  {
  \node[coordinate] (input) {};
  \node[sumnode, right of=input] (sum) {\tiny $\sum$};
  \node[block, right of=sum, node distance=2.6cm] (reg) {$F(s)$};
  \node[block, right of=reg, node distance=2.6cm] (plant) {$G(s)$};
  \node[coordinate, right of=plant, node distance=2cm] (output) {};
  \node[coordinate, below of=plant, node distance=12mm] (feedback) {};

  \draw[->] (plant) -- node[coordinate, inner sep=0pt] (meas) {} node[near end, above] {$y(t)$} (output);
  \draw[->] (meas) |- (feedback) -| node[very near end, left] {$-$} (sum);
  \draw[->] (input) -- node[very near start, above] {$r(t)$} (sum);
  \draw[->] (sum) -- node[above] {$e(t)$} (reg);
  \draw[->] (reg) -- node[above] {$u(t)$}(plant);
}
\end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}[label={sec:org2fb2529}]{The PID controller}
\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt},scale=0.8, every node/.style={scale=0.8}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[block, right of=sum, node distance=20mm] (pid)  {$F(s)$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=pid, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above] {$e(t)$} (pid);
    \draw[->] (pid) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
  \end{tikzpicture}
\end{center}

\alert{Parallel form (ISA)}
\[   F(s) &= k_c\left( 1 + \frac{1}{\tau_i s} + \tau_d s\right) \]

\alert{Series form}
\[F(s) = K_c \left( \frac{ \tau_I s + 1}{\tau_I s} \right) (\tau_D s + 1)
= \underbrace{\frac{K_c(\tau_I + \tau_D)}{\tau_I}}_{k_c} \left(1 + \frac{1}{\underbrace{(\tau_I + \tau_D)}_{\tau_i} s} + \underbrace{\frac{\tau_I\tau_D}{\tau_I + \tau_D}}_{\tau_d}s \right) \]
\end{frame}

\begin{frame}[label={sec:orgae39394}]{The PID - Parallel form}
\definecolor{ppc}{rgb}{0.1,0.1,0.6}
\definecolor{iic}{rgb}{0.6,0.1,0.1}
\definecolor{ddc}{rgb}{0.1,0.6,0.1}

\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[color=iic,block, right of=sum, node distance=28mm] (ii)  {$\frac{1}{\tau_is}$};
    \node[color=ppc, coordinate, above of=ii, node distance=10mm] (pp)  {};
    \node[color=ddc,block, below of=ii, node distance=10mm] (dd)  {$\tau_ds$};
    \node[sumnode, right of=ii, node distance=20mm] (sum2) {\tiny $\Sigma$};
    \node[block, right of=sum2, node distance=20mm] (gain)  {$k_c$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=gain, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above, pos=0.2] {$e(t)$} node[coordinate] (mm) {}  (ii);
    \draw[->] (gain) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
    \draw[->, color=ppc] (mm) |- (pp) -| node[right,] {$u_P(t)$} (sum2);
    \draw[->, color=ddc] (mm) |- (dd) -| node[right,] {$u_D(t)$} (sum2);
    \draw[->, color=iic] (ii)  -- node[above,] {$u_I(t)$} (sum2);
    \draw[->] (sum2) -- node[above, near end] {} (gain);

  \end{tikzpicture}
\end{center}

\begin{align*}
u(t) &= k_c\Big( \textcolor{ppc}{e(t)} + \textcolor{iic}{\frac{1}{\tau_i} \int_0^{t} e(\xi) d\xi} + \textcolor{ddc}{\tau_d \frac{d}{dt} e(t)} \Big)
\end{align*}
\end{frame}

\begin{frame}[label={sec:orga5afc99}]{The PID - Parallel form, modified D-part}
\definecolor{ppc}{rgb}{0.1,0.1,0.6}
\definecolor{iic}{rgb}{0.6,0.1,0.1}
\definecolor{ddc}{rgb}{0.1,0.6,0.1}

\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[color=iic,block, right of=sum, node distance=28mm] (ii)  {$\frac{1}{\tau_is}$};
    \node[color=ppc, coordinate, above of=ii, node distance=10mm] (pp)  {};
    \node[color=ddc,block, below of=ii, node distance=10mm] (dd)  {$\tau_ds$};
    \node[sumnode, right of=ii, node distance=20mm] (sum2) {\tiny $\Sigma$};
    \node[block, right of=sum2, node distance=20mm] (gain)  {$k_c$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=gain, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above, pos=0.2] {$e(t)$} node[coordinate] (mm) {}  (ii);
    \draw[->] (gain) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
    \draw[->, color=ppc] (mm) |- (pp) -| node[right,] {$u_P(t)$} (sum2);
    \draw[->, color=ddc] (feedback |- dd) -- node[above, pos=0.95] {-} (dd);
    \draw[->, color=ddc] (dd) -| node[right,] {$u_D(t)$} (sum2)  ;
    \draw[->, color=iic] (ii)  -- node[above,] {$u_I(t)$} (sum2);
    \draw[->] (sum2) -- node[above, near end] {} (gain);

  \end{tikzpicture}
\end{center}

\[    u(t) = k_c\Big( \textcolor{ppc}{e(t)} + \textcolor{iic}{\overbrace{\frac{1}{\tau_i} \int_0^{t} e(\xi) d\xi}^{u_I(t)}} + \textcolor{ddc}{ \underbrace{\tau_d \frac{d}{dt} \big(-y(t)\big)}_{u_D(t)}} \Big) \]
\end{frame}

\begin{frame}[label={sec:org320807c}]{The PID - Parallel form}
\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}, scale=0.6, every node/.style={scale=0.6}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[color=iic,block, right of=sum, node distance=28mm] (ii)  {$\frac{1}{\tau_is}$};
    \node[color=ppc, coordinate, above of=ii, node distance=10mm] (pp)  {};
    \node[color=ddc,block, below of=ii, node distance=10mm] (dd)  {$\tau_ds$};
    \node[sumnode, right of=ii, node distance=20mm] (sum2) {\tiny $\Sigma$};
    \node[block, right of=sum2, node distance=20mm] (gain)  {$k_c$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=gain, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above, pos=0.2] {$e(t)$} node[coordinate] (mm) {}  (ii);
    \draw[->] (gain) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
    \draw[->, color=ppc] (mm) |- (pp) -| node[right,] {$u_P(t)$} (sum2);
    \draw[->, color=ddc] (feedback |- dd) -- node[above, pos=0.95] {-} (dd) -| node[right,] {$u_D(t)$}   (sum2);
    \draw[->, color=iic] (ii)  -- node[above,] {$u_I(t)$} (sum2);
    \draw[->] (sum2) -- node[above, near end] {} (gain);

  \end{tikzpicture}
  \small
  \(  u(t) = k_c\Big( \textcolor{ppc}{e(t)} + \textcolor{iic}{\overbrace{\frac{1}{\tau_i} \int_0^{t} e(\xi) d\xi}^{u_I(t)}} + \textcolor{ddc}{ \underbrace{\tau_d \frac{d}{dt} \big(-y(t)\big)}_{u_D(t)}} \Big)\)
\end{center}

   \begin{center}
   \def\TT{1}
   \begin{tikzpicture}
   \begin{axis}[
    clip=false,
    width=14cm,
    height=4.5cm,
    ylabel={},
    xlabel={$t$},
    ymax = 2,
    ymin = -0.5,
    ]
      \addplot[black, no marks, domain=-0.1:8, samples=200] {(x>0)*(1 - (1+x/\TT)*exp(-x/\TT)} node[coordinate, pin=-20:{$y(t)$}, pos=0.4] {};
      \addplot[magenta!70!black, no marks, domain=-0.1:8, samples=200] coordinates {(-0.1, 0) (0,0) (0,1) (8,1)} node[coordinate, pin=90:{$r(t)$}, pos=0.4] {};
    \end{axis}

 \end{tikzpicture}
\end{center}
\alert{Activity} Sketch the error signal \(e(t)\), the derivative signal \(u_D(t)\) and the integral signal \(u_I(t)\) (use \(\tau_i=\tau_d=1\))
\end{frame}

\begin{frame}[label={sec:org0429488}]{The PID - Parallel form, solution}
\end{frame}
\begin{frame}[label={sec:orgb2e7e1a}]{The PID - Parallel form, solution}
\(u(t) = k_c\Big( \textcolor{ppc}{e(t)} + \textcolor{iic}{\overbrace{\frac{1}{\tau_i} \int_0^{t} e(\xi) d\xi}^{u_I(t)}} + \textcolor{ddc}{ \underbrace{\tau_d \frac{d}{dt} \big(-y(t)\big)}_{u_D(t)}} \Big)\)
   \begin{center}
   \def\TT{1}
   \begin{tikzpicture}
   \begin{axis}[
    clip=false,
    width=14cm,
    height=5cm,
    ylabel={},
    xlabel={$t$},
    ymax = 2,
    ]
      \addplot[black, no marks, domain=-0.1:8, samples=200] {(x>0)*(1 - (1+x/\TT)*exp(-x/\TT)} node[coordinate, pin=-20:{$y(t)$}, pos=0.4] {};
      \addplot[magenta!70!black, no marks, domain=-0.1:8, samples=200] coordinates {(-0.1, 0) (0,0) (0,1) (8,1)} node[coordinate, pin=90:{$r(t)$}, pos=0.21] {};
      \addplot[color=ppc, no marks, domain=0:8, samples=200] {(x>=0)*( (1+x/\TT)*exp(-x/\TT)} node[coordinate, pin=20:{$e(t)$}, pos=0.7] {};
      \addplot[color=iic, no marks, domain=-0.1:8, samples=200] {(x>0)*(2*(1-exp(-x/\TT)) - \x/\TT*exp(-x/\TT))} node[coordinate, pin=-20:{$u_I(t)$}, pos=0.6] {};
      \addplot[color=ddc, no marks, domain=-0.1:8, samples=200] {(x>0)*(-\x/\TT*exp(-x/\TT))} node[coordinate, pin=-20:{$u_D(t)$}, pos=0.4] {};
    \end{axis}

 \end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}[label={sec:org586fa5e}]{The PID - practical form}
\definecolor{ppc}{rgb}{0.1,0.1,0.6}
\definecolor{iic}{rgb}{0.6,0.1,0.1}
\definecolor{ddc}{rgb}{0.1,0.5,0.1}

\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[color=iic,block, right of=sum, node distance=28mm] (ii)  {$\frac{1}{\tau_is}$};
    \node[color=ppc, coordinate, above of=ii, node distance=10mm] (pp)  {};
    \node[color=ddc,block, below of=ii, node distance=13mm] (dd)  {$\frac{\tau_ds}{\frac{\tau_d}{N}s + 1}$};
    \node[sumnode, right of=ii, node distance=20mm] (sum2) {\tiny $\Sigma$};
    \node[block, right of=sum2, node distance=20mm] (gain)  {$k_c$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=gain, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above, pos=0.2] {$e(t)$} node[coordinate] (mm) {}  (ii);
    \draw[->] (gain) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
    \draw[->, color=ppc] (mm) |- (pp) -| node[right,] {$u_P(t)$} (sum2);
    \draw[->, color=ddc] (feedback |- dd) -- node[above, pos=0.95] {-} (dd);
    \draw[->, color=ddc] (dd) -| node[right,] {$u_D(t)$} (sum2)  ;
    \draw[->, color=iic] (ii)  -- node[above,] {$u_I(t)$} (sum2);
    \draw[->] (sum2) -- node[above, near end] {} (gain);

  \end{tikzpicture}
\end{center}

The parameter \(N\) is chosen to limit the influence of noisy measurements. Typically,
\[  3 < N < 10 \]
\end{frame}

\section{PID tuning - (Smith and Corripio) Ziegler Nichols}
\label{sec:orga158d8d}
\begin{frame}[label={sec:orgd1f6a5d}]{PID tuning}
\end{frame}
\begin{frame}[label={sec:org71a4d7d}]{Method by Smith \& Corripio using table by Ziegler-Nichols}
\small

Given process model (fitted to response of the system) \[ G(s) = K \frac{\mathrm{e}^{-s\theta}}{\tau s + 1} \] and PID controller
   \[ F(s) = k_c\left( 1 + \frac{1}{\tau_i s} + \tau_d s\right) \]
   Choose the PID parameters according to the following table (Ziegler-Nichols, 1943)
   \begin{center}
   \setlength{\tabcolsep}{20pt}
   \renewcommand{\arraystretch}{1.5}
   \begin{tabular}{llll}
   Controller & \(k_c\) & \(\tau_i\) & \(\tau_d\)\\
  \hline\hline
  P & \(\frac{\tau}{\theta K}\) &  & \\
  PI & \(\frac{0.9\tau}{\theta K}\) & \(\frac{\theta}{0.3}\) & \\
  PID & \(\frac{1.2\tau}{\theta K}\) & \(2\theta\) & \(\frac{\theta}{2}\)\\
  \hline
\end{tabular}
\end{center}

Gives good control for \[0.1 < \frac{\theta}{\tau} < 0.6.\]
\end{frame}

\section{SIMC}
\label{sec:org627d95f}

\begin{frame}[label={sec:org62fb5a1}]{SIMC-PID tuning rule}
[ SIMC stands for \emph{SIMple Control} or \emph{Skogestad Internal Model Control} ]
   \begin{center}
   \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}scale=0.5, every node/.style={scale=0.5}]
  {
  \node[coordinate] (input) {};
  \node[sumnode, right of=input] (sum) {\tiny $\sum$};
  \node[block, right of=sum, node distance=2.6cm] (reg) {$F(s)$};
  \node[block, right of=reg, node distance=2.6cm] (plant) {$G(s)$};
  \node[coordinate, right of=plant, node distance=2cm] (output) {};
  \node[coordinate, below of=plant, node distance=12mm] (feedback) {};

  \draw[->] (plant) -- node[coordinate, inner sep=0pt] (meas) {} node[near end, above] {$y(t)$} (output);
  \draw[->] (meas) |- (feedback) -| node[very near end, left] {$-$} (sum);
  \draw[->] (input) -- node[very near start, above] {$r(t)$} (sum);
  \draw[->] (sum) -- node[above] {$e(t)$} (reg);
  \draw[->] (reg) -- node[above] {$u(t)$}(plant);
}
\end{tikzpicture}
\end{center}

Given model of the process and desired closed-loop system \[G(s) = K \frac{\mathrm{e}^{-s\theta}}{(\tau_1 s + 1)(\tau_2 s + 1)}, \quad \tau_1 \ge \tau_2; \qquad G_c(s) = \frac{\mathrm{e}^{-s\theta}}{\tau_c s + 1} \] Good robustness is obtained with PID controller

\[F(s) = K_c \left( \frac{ \tau_I s + 1}{\tau_I s} \right) (\tau_d s + 1)
= \frac{K_c(\tau_I + \tau_d)}{\tau_I} \left(1 + \frac{1}{(\tau_I + \tau_D) s} + \frac{\tau_I\tau_D}{\tau_I + \tau_D}s \right) \]
with
\[ K_c = \frac{\tau_1}{K(\tau_c + \theta)}, \qquad \tau_I = \min\{\tau_1, 4(\tau_c + \theta)\}, \qquad \tau_d = \tau_2 \]
\end{frame}
\end{document}


\documentclass[12pt]{article}
    \usepackage{mathtools}
    \usepackage[hidelinks]{hyperref}
    \usepackage{color}
    \usepackage{fancyref}
    \usepackage{lastpage}
    \usepackage{fancyhdr}

    \usepackage{pagecolor}
    % \pagecolor{black}
    % \color{white}

    \pagestyle{fancy}
    \fancyhf{}
    \fancyhead[LO]{TMA4140: Homework set 8}
    \fancyhead[RO]{Henry S. Sjøen \& Toralf Tokheim}
    \fancyfoot[CO]{\thepage\ of \pageref{LastPage}}

    \definecolor{darkred}{RGB}{200, 0, 0}

  \author{Henry S. Sjøen \& Toralf Tokheim}
  \title{
  \textbf{TMA4140 - Homework Exercise Set 8}}
\begin{document}
    \maketitle
    \thispagestyle{empty}
    \pagebreak
    \tableofcontents
    \pagebreak

    \section{Section 5.2}
    %  Obligatoriske: 4, 14; Anbefalte: 7, 19, 23
    \subsection{Exercise 4}
    Let $P(n)$ be the statement that a postage of $n$ cents can be formed using just 4-cent stamps and 7-cent stamps. The parts of this exercise outline a strong induction proof that $P(n)$ is $true$ for $n\geq 18$.\\

    \textbf{a)} Show statements $P(18),P(19),P(20)$ and $P(21)$ are $true$, completing the basis step of the proof.

    \begin{equation}
        \begin{split}
            P(n)=4a+7b=n\\
            P(18)=(4\times 1)+(7\times 2)=18\\
            P(19)=(4\times 3)+(7\times 1)=19\\
            P(20)=(4\times 5)+(7\times 0)=20\\
            P(21)=(4\times 0)+(7\times 3)=21\\
        \end{split}
    \end{equation}

    \textbf{b)} What is the inductive hypothesis of the proof?\\
    If for every i in $18 \leq i \leq k $, where $k \leq 21$, there is an "a" and "b" so that $i= 4a+7b$. Then there is an  "c" and "b" so that $k+1 = 4c+7d$ is \textit{true}.\\

    \textbf{c)} What do you need to prove in the inductive step?\\
    In the inductive step, we assume that the inductive hypothesis holds, and use that to prove $k+1$. \\

    \textbf{d)} Complete the inductive step for $k \geq 21$.\\
    For $k = 21$ then $P(k+1)$ should still be \textit{true}.
    \begin{equation}
        \begin{split}
                    P(k)=(4\times 0)+(7\times 3)=21\\
                    P(k+1)=4+(k-3)=(4\times 2)+(7\times 2)=22\\
        \end{split}
    \end{equation}
    \textit{True} for base step $P(21)$ and the first inductive step $P(22)$.\\

    \textbf{e)} Explain why these steps show that this statement is $true$ whenever $n\geq 18$.\\
    Since the base step and the inductive step are true, by the principle of strong induction all amount of postage where $n \geq 18$ can be obtained using only 4- and 7-cent stamps.

    % \subsection{Todo: Exercise 14}
    % Suppose you begin with a pile of $n$ stones and split this pile into $n$ piles of one stone each by successively splitting a pile of stones into two smaller piles.\\
    % Each time you split a pile you multiply the number of stones in each of the two smaller piles you form, so that if these piles have $r$ and $s$ stones in them, respectively, you compute $rs$. Show that no matter how you split the piles, the sum of the products computed at each step equals $n(n-1)/2$.

    \section{Section 5.3}
    %  Obligatoriske: 12, 18; Anbefalte: 13, 14, 15
    \subsection{Exercise 12}
    Prove that $f_1^2 +f_2^2 +\cdots+f_n^2 =f_nf_{n+1}$ when $n$ is a positive integer.
    \begin{equation}
        \begin{split}
                    f_{0} = 0\\
                    f_{1} = 1\\
                    \\
                    f_{2} = f_{1}+f_{0}=1+0=1 \\
                    f_{3} = f_{2}+f_{1}=1+1=2 \\
                    f_{4} = f_{3}+f_{1}=2+1=3 \\
        \end{split}
    \end{equation}

    \textbf{Base step:} \\
    $P(1)$ is true because $f_{1}^2 = f_{1}f_{1}$\\
    $= 1.1$\\
    $= 1$\\
    $= f_1*f_2$\\
    \\

    \textbf{Inductive step:}\\
    Assume that $P(k)$  is true.\\
    Show that $P(k+1)$ is true:
    \begin{equation}
        \begin{split}
              f_{1}^2 + f_{2}^2 + \cdots + f_k^2 + f_{k+1}^2 = f_k * f_{k+1} + f_{k+1}^2\\
            = f_k * f_{k+1} + f_{k+1} * f_{k+1}\\
            = f_{k+1} (f_k+f_{k+1})
            =f_{k+1} * f_{k+2}
        \end{split}
    \end{equation}
    Therefore, $P(k+1)$ is true. \\
    Hence by the principle of strong induction, we conclude that the statement is true. \\
    And therefor $f_1^2 +f_2^2 +\cdots+f_n^2 =f_nf_{n+1}$ is true.

    \subsection{Exercise 18}
    Let
    $ A =
    \begin{bmatrix}
        1 & 1 \\
        1 & 0
    \end{bmatrix}
    $,
    Show that
    $ A^n = \begin{bmatrix}
                    f_{n+1} & f_n\\
                    f_n & f_{n-1}
                    \end{bmatrix}
    $   when $n$ is a positive integer.

    Let $A=\begin{bmatrix}
    1&1\\
    1&0
    \end{bmatrix}$
    Let $P(n)$ be a statement that $A^n=\begin{bmatrix}
        f_{n+1}&f_{n}\\
        f_{1}&f_{1-1}
    \end{bmatrix}$

    \begin{equation}
        A^1= \begin{bmatrix}
            f_{2}&f_{1}\\
            f_{1}&f_{0}
        \end{bmatrix}\\
        =\begin{bmatrix}
            1&1\\
            1&0
        \end{bmatrix}
        = A
    \end{equation}
    A is true.\\
    Inductive step...
    Assume that $P(k)$ is true.
    i.e., $A^k=\begin{bmatrix}
    f_{k+1}&f_k\\
    f_k & f_k-1
    \end{bmatrix}$\\
    We have to prove that $P(k+1)$ is true.
    \begin{equation}
        \begin{split}
            A^{k+1}&=A.A^k\\
            &=\begin{bmatrix}
            1&1\\
            1&0
            \end{bmatrix}
            \begin{bmatrix}
            f_{k+1}& f_k\\
            f_k&f_{k-1}
            \end{bmatrix}\\
            &=\begin{bmatrix}
            1.f_{k+1}+1.f_k &1.f_{k}+1.f_{k-1}\\
            1.f_{k+1}+ 0.f_k & 1.f_k+0.f_{k-1}
            \end{bmatrix}\\
            &=\begin{bmatrix}
            f_{k+1}+f_k & f_{k-1}+f_k\\
            f_{k+1}+0 & f_{k}+0
            \end{bmatrix}\\
            &=\begin{bmatrix}
            f_{k+2} & f_{k+1}\\
            f_{k+1} & f_{k}
            \end{bmatrix}
        \end{split}
    \end{equation}
    Therefore $P(k+1)$ is \textbf{true}.\\
    And from the principle of mathematical induction we can conclude that the given statement is true.

    \section{Section 5.4}
    %  Obligatoriske: 3
    \subsection{Exercise 3}
    Trace Algorithm 3 when it finds $\gcd(8,13)$. That is, show all the steps used by Algorithm 3 to find $\gcd(8,13)$.

            \textbf{Input:} $\gcd(8, 13)$ \\
            \begin{equation}
                \begin{split}
                   since(8 < 13) &\\
                        \gcd(8, 13) &= \gcd(13 \textbf{mod} 8,8)\\
                        \gcd(8, 13) &= \gcd(5, 8) \\
                        \\
                   since(5 < 8) &\\
                        \gcd(5, 8) &= \gcd(8 \textbf{mod} 5,5)\\
                        \gcd(5, 8) &= \gcd(3, 5) \\
                        \\
                   since(3 < 5) &\\
                        \gcd(3, 5) &= \gcd(5 \textbf{mod} 3,3)\\
                        \gcd(3, 5) &= \gcd(2, 3) \\
                        \\
                   since(2 < 3) &\\
                        \gcd(2, 3) &= \gcd(3 \textbf{mod} 2,2)\\
                        \gcd(2, 3) &= \gcd(1, 2) \\
                        \\
                   since(1 < 2) &\\
                        \gcd(1, 2) &= \gcd(2 \textbf{mod} 1,1)\\
                        \gcd(1, 2) &= \gcd(0, 1) \\
                        \\
                   since(a = 0) &\\
                        \gcd(0, 1) &= 1\\
                        \gcd(8, 13) &= \textbf{1}
                \end{split}
            \end{equation}

    \section{Section 9.1}
    %  7, 40a, 40c (4, 28a, 28c); Anbefalte: 4, 25, 32
    \subsection{Exercise 7}
    Determine whether the relation $R$ on the set of all integers is \textit{reflexive}, \textit{symmetric}, \textit{antisymmetric}, and/or \textit{transitive}, where $(x,y) \in R$ if and only if\\
    \textbf{a)} $ x \neq y$.\\
        $R$ is \textbf{Not reflective}. $x \neq x$ can never be true\\
        $R$ is \textbf{symetric}, since if $x, y$ are integers and $ x \neq y$; then $ y \neq x$. \\
        $R$ is \textbf{not antisymetric}, as $1\neq 5$, $5 \neq 1$ while $1$ and $5$ are not the same.
        $R$ is \textbf{not transitive}, as $1\neq 5$, $5 \neq 1$ while $1 = 1$\\
        \\
    \textbf{b)} $ xy \geq 1$.\\
        $R$ is \textbf{not reflexive} \\
        $R$ is \textbf{symetric} \\
        $R$ is \textbf{not antisymetric} \\
        $R$ is \textbf{transitive} \\
        \\
    \textbf{c)} $ x=y + 1$ or $ x=y-1$.\\
        $R$ is \textbf{not reflexive} \\
        $R$ is \textbf{symetric} \\
        $R$ is \textbf{not asymetric} \\
        $R$ is \textbf{not transitive} \\
        \\
    \textbf{d)} $ x \equiv y (mod 7) $.\\
        $R$ is \textbf{reflexive} \\
        $R$ is \textbf{symetric} \\
        $R$ is \textbf{not asymetric} \\
        $R$ is \textbf{transitive} \\
        \\
    \textbf{e)} $ x $ is a multiple of $y$.\\
        $R$ is \textbf{reflective} \\
        $R$ is \textbf{not symmetric} \\
        $R$ is \textbf{not antisymetric} \\
        $R$ is \textbf{transitive} \\
        \\
    \textbf{f)} $ x $ and $y$ are both negative or both nonnegative.\\
        $R$ is \textbf{reflexitive} \\
        $R$ is \textbf{symmetric} \\
        $R$ is \textbf{not asymmetric} \\
        $R$ is \textbf{transitive} \\
        \\
    \textbf{g)} $ x=y^2 $.\\
        $R$ is \textbf{not reflexive} \\
        $R$ is \textbf{not symmetric} \\
        $R$ is \textbf{asymmetric} \\
        $R$ is \textbf{not transitive} \\
        \\
    \textbf{h)} $ x \geq y^2 $.
        $R$ is \textbf{not reflexive} \\
        $R$ is \textbf{not symmetric} \\
        $R$ is \textbf{asymmetric} \\
        $R$ is \textbf{transitive} \\
        \\

    \subsection{Exercise 40}
    Let $R_1$ and $R_2$ be the "divides" and "is a multiple of" relations on the set of all positive integers, respectively.\\
    That is, $R_1 = \{(a,b)|a $ divides $ b\}$ and $R_2=\{(a,b)|a$ is a multiple of $b\}$. Find...

    \subsubsection{Exercise 40.a}
    $R_1 \cup R_2$.\\
    An ordered pair $(a,b)\in R_1\cup R_2 $ if and only if $(a,b)\in R_1$ or $(a,b)\in R_2$.\\
    If $a$ divides $b$ for some integer $k$, $b=ka$.\\
    If $a$ is an multiple of $b$, then for some integer k,
    $b=\frac{1}{k}a $\\
    Therefore, $R_1 \cup R_2=\{(a,b)|b=ka$ or $ b=\frac{1}{k}a$, where $k$ is an integer.$\}$

    \subsubsection{Exercise 40.c}
    $R_1 - R_2$.\\
    An ordered pair $(a,b)\in R_1-R_2$ if and only if $(a,b)\in R_1$ and $(a,b)\notin R_2$.\\
    That is, if and only if \textit{a divides b} and \textit{a} is not a multiple of \textit{b}.\\
    Therefore,
    $R_1-R_2 = \{(a,b) | a$ is a proper divisor of $b \}$.

    \section{Section 9.3}
    %  10, 14a, 14b, 14c (6, 10a, 10b, 10c); Anbefalte: 15
    \subsection{Exercise 10}
    How many nonzero entries does the matrix representing the relation $R$ on $A=\{1,2,3,...,1000\}$ consisting of the first 1000 positive integers have if $R$ is...\\
    \textbf{a)} $\{(a,b) | A \leq b \}$?
    \begin{equation}
        \begin{split}
            \{(a,b) | A \leq b \}&=1000+999+998+\cdots + 2 + 1\\
            &=\frac{(1000)(1000+1)}{2}\\
            &=(500)(1001)\\
            &=500,500
        \end{split}
    \end{equation}

    \textbf{b)} $\{(a,b) | a=b \pm 1 \}$?
    \begin{equation}
        \begin{split}
            \{(a,b) | a=b \pm 1 \}&=1+2(998)+1\\
            &=1+1996+1\\
            &=1998
        \end{split}
    \end{equation}

    \textbf{c)} $\{(a,b) | a+b = 1000 \}$?
    \begin{equation}
        \begin{split}
            \{(a,b) | a+b = 1000 \}&=1+1+1+\cdots + 1(999)\\
            &=999
        \end{split}
    \end{equation}

    \textbf{d)} $\{(a,b) | a+b \leq 1001 \}$?
        \begin{equation}
            \begin{split}
            \{(a,b) | a+b \leq 1001 \} &=1000+999+998+\cdots+2+1\\
            &=\frac{(1000)(1000+1)}{2}\\
            &=(500)(1001)\\
            &=500,500
            \end{split}
        \end{equation}

    \textbf{e)} $\{(a,b) | a \neq 0 \}$?
        \begin{equation}
            \begin{split}
            \{(a,b) | a \neq 0 \}&=1000+1000+1000+\cdots + 1000+1000 (1000 times)\\
            &=(1000)(1000)\\
            &= 1,000,000
            \end{split}
    \end{equation}

    \subsection{Exercise 14}

    Let $R_1$ and $R_2$ be the relations represented by the matrices... \\
    $M_{R_1}=\begin{bmatrix}
        0 & 1 & 0\\
        1 & 1 & 1\\
        1 & 0 & 0
    \end{bmatrix}$ and $M_{R_2} = \begin{bmatrix}
        0 & 1 & 0 \\
        0 & 1 & 1 \\
        1 & 1 & 1
    \end{bmatrix}
    $\\
    Find the matrices that represent...
    \subsubsection{Exercise 14.a}
    $R_1 \cup R_2$
    \begin{equation}
        M_{R_1 \cup R_2} = \begin{bmatrix}
            0 & 1 & 0 \\
            1 & 1 & 1 \\
            1 & 1 & 1
        \end{bmatrix}
    \end{equation}

    \subsubsection{Exercise 14.b}
    $ R_1 \cap R_2 $.
    \begin{equation}
        M_{ R_1 \cap R_2}=
        \begin{bmatrix}
            0 & 1 & 0\\
            0 & 1 & 1\\
            1 & 0 & 0
        \end{bmatrix}
    \end{equation}

    \subsubsection{Exercise 14.c}
    $ R_2 \circ R_1$.
    \begin{equation}
       M_{R_2 \circ R_1}=
        \begin{bmatrix}
        0&1&1\\
        1&1&1\\
        0&1&0
        \end{bmatrix}
    \end{equation}
\end{document}


\documentclass[epsfig,10pt,fullpage]{article}

\newcommand{\LabNum}{2}
\newcommand{\CommonDocsPath}{../../../../common/docs}
\input{\CommonDocsPath/preamble.tex}

\begin{document}

\centerline{\huge Computer Organization}
~\\
\centerline{\huge Laboratory Exercise \LabNum}
~\\
\centerline{\large Using Logic Instructions with the Nios\textsuperscript{\textregistered} II Processor}
~\\

Logic instructions are needed in many embedded applications.  Logic instructions are useful
for manipulation of bit strings and for dealing with data at the bit level where only a
few bits may be of special interest.  They are essential in dealing with input/output tasks.
In this exercise we will consider some typical uses.
We will use the Nios\textsuperscript{\textregistered} II processor in one of the pre-built computer systems that come with the Monitor Program.

\section*{Part I}
\addcontentsline{toc}{1}{Part I}
In this part you will implement a Nios II assembly language program that counts the longest
string of 1's in a word of data. For example, if the word of data is {\sf 0x103fe00f}, then
the required result is 9.

\begin{figure}[H]
\begin{center}
\begin{minipage}[t]{16.5 cm}
\lstinputlisting[style=defaultNiosStyle]{../design_files/part1.s}
\end{minipage}
\end{center}
\caption{Assembly-language program that counts consecutive ones.}
\label{fig:code}
\end{figure}

~\\
Perform the following:

\begin{enumerate}
\item Create a new folder to hold your Monitor Program project for this part. Create a
file called {\it part1.s}, and type the assembly language code shown in
Figure~\ref{fig:code} into this file.
This code uses an algorithm involving shift and AND operations to find the required
result---make sure that you understand how this works.

\item
Make a new Monitor Program project in the folder where you stored the {\it part1.s}
file. Depending on your DE-series board, use the corresponding computer system
listed in Table~\ref{tab:computer_systems}.

\begin{table}[H]
	\begin{center}
	\begin{tabular}{ l | l }
	\bf{Board} & \bf{Computer System} \\
	\hline
	\rule{0pt}{3ex}DE0-Nano & DE0-Nano Computer \\
	DE0-Nano-SoC & DE0-Nano-SoC Computer \\
	DE10-Nano & DE10-Nano Computer \\
	\end{tabular}
	\caption{DE-series board computer systems}
	\label{tab:computer_systems}
	\end{center}
\end{table}

\item
Compile and load the program. Fix any errors that you encounter (if you mistyped some of
the code). Once the program is loaded into memory in the computer, single step
through the code to see how the program works.
\end{enumerate}

\section*{Part II}
\addcontentsline{toc}{2}{Part II}
Perform the following:
\begin{enumerate}
\item Make a new folder and make a copy of the file {\it part1.s} in that new folder. Give
the new file a name such as {\it part2.s}.
\item In the new file {\it part2.s}, take the code which calculates the
number of consecutive 1's and make it into a subroutine called ONES. Have the subroutine use
register r4 to receive the input data and register r2 for returning the result.
\item Add more words in memory starting from the label TEST\_NUM. You can add as many
words as you like, but include at least 10 words. To terminate the list include the word 0
at the end---check for this 0 entry in your main program to determine when all of the
items in the list have been processed.
\item In your main program, call the newly-created subroutine in a loop for every word of
data that you placed in memory. Keep track of the longest string of 1's in any of the words,
and have this result in register r10 when your program completes execution.
\item Make sure to use breakpoints or single-stepping in the Monitor Program to observe what
happens each time the ONES subroutine is called.
\end{enumerate}

\section*{Part III}
\addcontentsline{toc}{3}{Part III}
One might be interested in the longest string of 0's, or even the longest string of
alternating 1's and 0's. For example, the binary number {\sf 101101010001} has a string of
6 alternating 1's and 0's.

~\\
 Write a new assembly language program that determines the following:
\begin{itemize}
\item Longest string of 1's in a word of data---put the result into register r10
\item Longest string of 0's in a word of data---put the result into register r11
\item Longest string of alternating 1's and 0's in a word of data---put the result into
register r12
(Hint: What happens when an n-bit number is XORed with an n-bit string of alternating 0's and 1's?)
\end{itemize}
Make each calculation in a separate subroutine called ONES, ZEROS, and ALTERNATE. Call
each of these subroutines in the loop that you wrote in Part III, and keep track of the
largest result for each calculation, from your list of data.

\section*{Part IV}
\addcontentsline{toc}{4}{Part IV}
In this part you are to extend your code from Part III so that the results produced are
shown on the Terminal window of the \productNameMedTM{}.
Each result should be displayed as a two-digit decimal number preceded by the name of the register
the number corresponds to. You may want to use the approach discussed in Part IV of Exercise 1 to
convert the numbers in registers r10, r11, and r12 from binary to decimal.

~\\
The computer systems can communicate with the \productNameMed{}'s Terminal through the
JTAG* UART.  The programming interface of the JTAG UART consists of two 32-bit registers, as
shown in Figure~\ref{fig:UART}. The register mapped to address 0xFF201000 is called the
{\it Data} register and the register mapped to address 0xFF201004 is called the {\it
Control} register.

~\\
The JTAG UART includes a 64-character FIFO that stores data waiting to be transmitted to the
host computer.  ASCII character data is loaded into this FIFO by performing a write to
bits 7-0 of the Data register in Figure~\ref{fig:UART}. Note that writing into this register
has no effect on received data. The amount of space, WSPACE, currently available in
the transmit FIFO is provided in bits 31-16 of the Control register. If the transmit FIFO
is full, then any characters written to the Data register will be lost. A subroutine that
transmits a character to the host computer is shown in Figure~\ref{fig:ascii}.

\begin{figure}[htb]
	\begin{center}
	\includegraphics[scale=1]{figures/figureJTAGUART.pdf}
	\end{center}
	\caption{The JTAG UART Programming Interface.}
\label{fig:UART}
\end{figure}

\noindent
An example of code that shows the contents of registers on the Terminal window
is illustrated in Figure~\ref{fig:codefrag}. The code in the figure shows only the steps needed
to display the contents of register r15 on the Terminal. Extend the code to display the contents of
all three registers.

\begin{figure}[H]
\lstinputlisting[style=defaultNiosStyle]{./figures/ascii.s}
\caption{A subroutine that sends an ASCII character to the Monitor Program Terminal.}
\label{fig:ascii}
\end{figure}

\begin{figure}[H]
\begin{center}
\begin{minipage}[t]{16.5 cm}
\lstinputlisting[style=defaultNiosStyle]{../design_files/part4.s}
\end{minipage}
\end{center}
\caption{A code fragment that sends an ASCII character to the Monitor Program Terminal and shows registers in decimal on the Terminal window.}
\label{fig:codefrag}
\end{figure}

\newpage
\noindent
For your Monitor Program project for this part, in the screen shown in Figure
\ref{fig:terminal}, make sure to select {\sf JTAG\_UART} as the {\it Terminal
device}. Without this setting no character output will appear on the Terminal window when
your code writes to the JTAG UART.

~\\
\begin{figure}[htb]
	\begin{center}
	\includegraphics[scale=0.58]{figures/terminal.png}
	\end{center}
	\vspace{-0.25cm}\caption{Specifying the {\it Terminal device}.}
\label{fig:terminal}
\end{figure}

\input{\CommonDocsPath/copyright.tex}
\end{document}


\subsection{Task 7: Triangle Counting}
According to the algorithms in \cite{tsourakakis2008fast}, we know that the number of triangles in a network is proportional to the sum of eigenvalue of its adjacency matrix, which is $\frac{\sum_{i}\lambda_{i}^{3}}{6}$. Figure \ref{t7:timedata} shows the running time of global triangle counting with regards to the size of graph. We can see that as the size of graph increases, the running time also grows nearly linearly with the size. For the largest graph, which is Roadnet-PA, it runs nearly for an hour to complete. However, the predicted result for Roadnet-PA is unsatisfactory. We conduct both global and local triangle counting, all the data is listed as follows.

\subsubsection{Detailed Plots}
{\bf Proof of Correctness: } In this experiment, we run our algorithm on the dataset, and verify that the predicted number of triangles is a good approximate of the true count. The full result is in Table \ref{t7:globalpredict}. As we can see, most of the result is near to each other. So we are aure about the correctness of the implementation.

Table \ref{t7:timedata} lists run time of global triangle counting. Figure \ref{t7:globaltime} plots the run time of global triangle counting on each dataset.

\begin{table}
\begin{center}
\begin{tabular}{ | c | c | }
    \hline
    graph size & run time(seconds) \\ \hline
    7115 & 45.199s \\ \hline
    36692 & 72.76 \\ \hline
    82168 & 596.046 \\ \hline
    334863 & 1288.703 \\ \hline
    1088092 & 2980.985 \\ \hline
\end{tabular}
\end{center}
\caption{Task 7 run time(global)}
\label{t7:timedata}
\end{table}

\begin{table}
\begin{center}
\begin{tabular} {| c | c | c | c | }
    \hline
    dataset & size & predict & truth \\ \hline
    wiki-Vite & 7115 & 661282 & 608389 \\ \hline
    Enron-email & 36692 & 756757 & 727044 \\ \hline
    slash-dot & 82168 & 635792 & 602592 \\ \hline
    Amazon-com & 334863 & 675778 & 667129 \\ \hline
    Roadnet-PA & 1088092 & 72134 & 67150 \\ \hline
\end{tabular}
\end{center}
\caption{Predicted triangle count(global)}
\label{t7:globalpredict}
\end{table}

% \begin{table}
% \begin{center}
% \begin{tabular} {| c | c | c | c | }
%     \hline
%     dataset & predict & truth \\ \hline
%     wiki-Vote & 661282 & 608389 \\ \hline
%     youtube & 3122234 & 3056386 \\ \hline
%     slashdot0922 & 631667 & 602592\\ \hline
%     com-DBLP & 2451225 & 2224385 \\ \hline
%     wiki-Talk & 9778534 & 9203519\\ \hline
% \end{tabular}
% \end{center}
% \caption{Predicted triangle count(global)}
% \label{t7:globalpredict}
% \end{table}

\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.6\textwidth]{FIG/t7_time.png}
\end{tabular}
\caption{Task 7: Run time VS graph size(global)}
\label{t7:globaltime}
\end{center}
\end{figure}

\subsubsection{Local triangle counting}
We plot the rank-frequency plot of local triangle counting, that x-axis represent the rank of the count of local triangle, y-axis represents the number of local triangles at that rank.

\paragraph{Amazon}
Figure \ref{t7:amazon} plots the rank-frequency of Amazon. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_amazon.png}
\end{tabular}
\caption{Local triangle counting for Amazon}
\label{t7:amazon}
\end{center}
\end{figure}

\paragraph{Enron mail}
Figure \ref{t7:enron} plots the rank-frequency of Enron Mail. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_enron.png}
\end{tabular}
\caption{Local triangle counting for Enron mail}
\label{t7:enron}
\end{center}
\end{figure}

\paragraph{Slashdot}
Figure \ref{t7:slashdot} plots the rank-frequency of Slashdot. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_slashdot.png}
\end{tabular}
\caption{Local triangle counting for Slashdot}
\label{t7:slashdot}
\end{center}
\end{figure}

\paragraph{wiki-Vote}
Figure \ref{t7:wikivote} plots the rank-frequency of wiki-Vote. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_wikivote.png}
\end{tabular}
\caption{Local triangle counting for wiki-Vote}
\label{t7:wikivote}
\end{center}
\end{figure}

\paragraph{Youtube}
Figure \ref{t7:youtube} plots the rank-frequency of Youtube. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_youtube.png}
\end{tabular}
\caption{Local triangle counting for youtube}
\label{t7:youtube}
\end{center}
\end{figure}

% \begin{figure}[!htbf]
% \begin{center}
% \begin{tabular}{cc}
%      \includegraphics[width=0.4\textwidth]{FIG/t7_amazon.png} &
%      \includegraphics[width=0.4\textwidth]{FIG/t7_enron.png} \\
%      (a) & (b) \\
%      \includegraphics[width=0.4\textwidth]{FIG/t7_slashdot.png} &
%      \includegraphics[width=0.4\textwidth]{FIG/t7_wikivote.png} \\
%      (c) & (d) \\
%      \includegraphics[width=0.4\textwidth]{FIG/t7_youtube.png} & \\
%      (e)
% \end{tabular}
% \caption{Local triangle counting. (a) Amazon (b) Enron Mail (c) Slashdot (d) Wiki Vote (e) Youtube}
% \label{t7:local}
% \end{center}
% \end{figure}

\subsubsection{Observation}
We can see that the rank-frequency plot of local triangle count also follows {\bf power law}, it just matches our intuition. And we can observe that the run time grows nearly linearly with the graph size.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% -*- Mode:TeX -*-

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% You need to build this file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Try not to edit this file much, only input pacakges and the
% sub-files you write so that if you make a mistke you dont break
% everything in the code.

\documentclass[fleqn,titlepage]{book}

% add packages here if needed
\usepackage[T1]{fontenc}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{mathtools}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{geometry}
\usepackage{tikz}
\usepackage{float}
\usepackage{graphicx}
\usepackage{lmodern}
% Equation numbering
\numberwithin{equation}{section}

% Used in cover page
\usepackage{xcolor}
\hypersetup{
    colorlinks,
    linkcolor={blue!50!black},
    citecolor={blue!50!black},
    urlcolor={blue!80!black}
}
\providecommand{\HUGE}{\Huge}% if not using memoir
\newlength{\drop}% for my convenience
\usepackage{epstopdf}
\usepackage{epsfig}

% Draft
\usepackage{draftwatermark}
\SetWatermarkScale{1}\usepackage{epsfig}

% Set up format for definitions and axioms etc.
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{law}[thm]{Law}
\newtheorem{prop}[thm]{Proposition}
\newtheorem*{cor}{Corollary}
\newtheorem*{axiom}{Axiom}

\theoremstyle{definition}
\newtheorem{defn}{Definition}[section]
\newtheorem{conj}{Conjecture}[section]
\newtheorem{exmp}{Example}[section]
\newtheorem{note}{Note}[section]

\theoremstyle{remark}
\newtheorem*{rem}{Remark}

%Set up the format for the listing structure
\renewcommand{\theenumi}{\Roman{enumi}}
\renewcommand{\labelenumi}{(\theenumi)}
\renewcommand{\theenumii}{\alph{enumii}}
\renewcommand{\labelenumii}{\theenumi.~\theenumii}

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% \input{../include/Cover/cover}

\pagestyle{plain}

%========================================================================
\frontmatter
%========================================================================

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Disclaimer}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{../include/Disclaimer/disclaimer}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Acknowledgements}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{../include/Acknowledgements/acknowledgements}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{About the Authors}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{../include/Authors/authors}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Preface}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{../include/Preface/preface}

%========================================================================
\mainmatter
%========================================================================
\tableofcontents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%------------------------------------------------------------------------
\part{Introduction}
%------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{../include/Introduction/intro}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%------------------------------------------------------------------------
\part{Notes and Definitions}
%------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Module 1: Discrete Mathematics}
\input{../include/Notes/mod1}
\chapter{Module 2: Probability and Distributions}
\input{../include/Notes/mod2}
\chapter{Module 3: Particle Mechanics}
\input{../include/Notes/mod3}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%------------------------------------------------------------------------
\part{Solutions}
%------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%------------------------------------------------------------------------
\chapter{20XX}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/20XX/q1}
\item \input{../include/Solutions/20XX/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/20XX/q3}
% \item % \input{../include/Solutions/20XX/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item % \input{../include/Solutions/20XX/q5}
\item % \input{../include/Solutions/20XX/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2005}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2005/q1}
\item \input{../include/Solutions/2005/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2005/q3}
\item \input{../include/Solutions/2005/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2005/q5}
\item \input{../include/Solutions/2005/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2006}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2006/q1}
\item \input{../include/Solutions/2006/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2006/q3}
\item \input{../include/Solutions/2006/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2006/q5}
\item \input{../include/Solutions/2006/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2007}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2007/q1}
\item \input{../include/Solutions/2007/q2}
\end{enumerate}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\section{Module 2: Probability and Distributions}
\item \input{../include/Solutions/2007/q3}
\item \input{../include/Solutions/2007/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2007/q5}
\item \input{../include/Solutions/2007/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2008}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2008/q1}
\item \input{../include/Solutions/2008/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2008/q3}
\item \input{../include/Solutions/2008/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2008/q5}
\item \input{../include/Solutions/2008/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2009}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2009/q1}
\item \input{../include/Solutions/2009/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2009/q3}
\item \input{../include/Solutions/2009/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2009/q5}
\item \input{../include/Solutions/2009/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2010}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2010/q1}
\item \input{../include/Solutions/2010/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2010/q3}
\item \input{../include/Solutions/2010/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2010/q5}
\item \input{../include/Solutions/2010/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2011}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2011/q1}
\item \input{../include/Solutions/2011/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2011/q3}
\item \input{../include/Solutions/2011/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2011/q5}
\item \input{../include/Solutions/2011/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2012}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2012/q1}
\item \input{../include/Solutions/2012/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2012/q3}
\item \input{../include/Solutions/2012/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2012/q5}
\item \input{../include/Solutions/2012/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2013}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2013/q1}
\item \input{../include/Solutions/2013/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2013/q3}
\item \input{../include/Solutions/2013/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2013/q5}
\item \input{../include/Solutions/2013/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2014}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2014/q1}
\item \input{../include/Solutions/2014/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2014/q3}
\item \input{../include/Solutions/2014/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2014/q5}
\item \input{../include/Solutions/2014/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2015}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2015/q1}
\item \input{../include/Solutions/2015/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2015/q3}
\item \input{../include/Solutions/2015/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2015/q5}
\item \input{../include/Solutions/2015/q6}
\end{enumerate}

%------------------------------------------------------------------------
\chapter{2016}
%------------------------------------------------------------------------
\section{Module 1: Managing Uncertainty}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{0}
\item \input{../include/Solutions/2016/q1}
\item \input{../include/Solutions/2016/q2}
\end{enumerate}
\section{Module 2: Probability and Distributions}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{2}
\item \input{../include/Solutions/2016/q3}
\item \input{../include/Solutions/2016/q4}
\end{enumerate}
\section{Module 3: Particle Mechanics}
\begin{enumerate}[label=\bfseries  \arabic*.]\setcounter{enumi}{4}
\item \input{../include/Solutions/2016/q5}
\item \input{../include/Solutions/2016/q6}
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%------------------------------------------------------------------------
\part{Appendix}
%------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}


%!TEX root = ../../common/main.tex

\section{Decay time resolution and acceptance}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance}

In the following sections the parametrisation of the decay time resolution and
the model to describe the decay time acceptance are studied.

% ------------------------------------------------------------------------------
\subsection{Resolution}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:resolution}

In this section the applicability of the \dtfpv output variable $\obsTimeError$ as
the per-event decay time error resolution estimate is checked and a model to
calibrate the estimate is developed. The model is determined in a two step
procedure. At first, different calibration models are tested using a binned fit
on the decay time resolution determined on data as a function of the resolution
estimate $\obsTimeError$. Then the found resolution model is used in an unbinned
likelihood fit to determine the calibration parameter values.

The study is performed on $\BdToJpsiKS$ candidates passing the pre-scaled
stripping line and the unbiased trigger lines only. The nominal selection is
applied, except the decay time cut at $\obsTime < \SI{0.3}{\pico\second}$, all
remaining candidates are considered irrespective of their tagging information.
Without cuts restricting the reconstructed decay time of the \Bd candidates, the
sample consists mainly of combinatorial background candidates promptly produced
at the \PV. As these candidates quasi decay instantaneously at $t = 0$ their
decay time distribution should give a proper handle on the decay time
resolution. A fit to the $\Jpsi$ candidate's reconstructed mass is applied to
get signal \sweights that are subsequently used in a weighted likelihood fit to
the reconstructed \Bd candidates' decay time distribution.

The $\Jpsi$ mass distribution is described by a \Ipatia \PDF (\cf
\cref{sec:measurement_of_sin2beta:likelihood_fit:pdfs:ipatia}) for the signal
component and an exponential \PDF for the background candidates. The fit is
performed on the reconstructed invariant dimuon mass $m_{\mumu}$ in a range from
$\num{3040}$ to $\SI{3155}{\MeVcc}$. The fitted distribution and the \PDF
projections split into the \catDD and \catLL categories are shown in
\cref{fig:measurement_of_sin2beta:resolution_and_acceptance:resolution:jpsi_mass}.
Although, the pion track types have no influence on the mass distribution of the
$\Jpsi$ candidates, the separation is justified by the different decay time
resolutions expected in these categories.
%
\begin{figure}[h]
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_mass_jpsi_dd.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_mass_jpsi_ll.pdf}
\caption{Invariant $\Jpsi$ candidates' mass distribution in the (left) \catDD
and (right) \catLL subsample. Data are shown in black, the projection of the
total \acs{PDF} as solid black line, the signal component described by a \Ipatia
\acs{PDF} as dashed blue line, and the exponential background component as
dotted green line.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:resolution:jpsi_mass}
\end{figure}
%
Using a simultaneous fit in $\num{20}$ equally filled bins of the decay time
error prediction $\obsTimeError$ the width of the prompt peak in the decay time
distribution is fitted. This choice is based on the assumption that the decay
time resolution behaves alike for all candidates combined into one bin. As the
last bin is too wide, this assumption does not hold not any more, thus the last
bin is left out from then on. The fit model consists of two Gaussian \acp{PDF}
sharing a common mean parameter to model the prompt peak and two additional
decay \acp{PDF} as parametrisation of the non-prompt components. The decay \PDF
is convoluted with the same double-Gaussian \PDF used to model the prompt peak.
The two widths---one narrow and one wider---are then both employed in the
calibration.

For both widths a binned $\chisq$-fit of the $\num{19}$ per-bin parameter values
against the per-bin $\obsTimeError$ averages is performed. One linear and two
parabolic calibration models (with and without offset) are tested. For both
widths ($i = \{1,2\}$) as well as for both the \catDD and \catLL candidates the linear model
$\sigma^\prime(\obsTimeError) = c_i + b_i \obsTimeError$ describes the data at
least equally well \wrt the other parametrisations, such that the simpler model
is chosen in case of comparable results.
\Cref{fig:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration}
shows the calibration function for both track types and both Gaussian width
parameters.
%
\begin{figure}[h]
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_calibration_dd_narrow.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_calibration_dd_wide.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_calibration_ll_narrow.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_calibration_ll_wide.pdf}
\caption{Decay time error estimate calibration for (top) \catDD and (bottom)
\catLL candidates. Different calibration functions are fitted to the (left)
narrow and the (right) wide Gaussian width parameters. In green the linear
function $\sigma^\prime(\obsTimeError) = c_i + b_i \obsTimeError$ is shown, blue
and yellow describe the parabolic function with and without offset.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration}
\end{figure}
%
Results of the depicted fits are given in
\cref{tab:app:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration:dd,tab:app:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration:ll}
in \cref{sec:app:measurement_of_sin2beta:resolution_and_acceptance:resolution}.

Using the determined calibration model, the nominal decay time resolution model
is developed. An unbinned maximum likelihood fit to the \Bd decay time is
performed on the same $\Jpsi$ signal \sweighted dataset as described before
using the resolution model
%
\begin{equation}\label{eq:measurement_of_sin2beta:resolution_and_acceptance:resolution}
\begin{split}
  \Resolution{}{}\!\left(\obsTime;\obsTimeError\right)
  &= \sum_{i=1}^{2}{g_i\,\cdot\,\frac{1}{\sqrt{2\pi}(c_i + b_i \cdot \obsTimeError)}\exp\left(-\frac{(\obsTime - \mu_t)^2}{2(c_i + b_i \cdot \obsTimeError)^2}\right)}\\
  &+ f_{\text{PV}} \frac{1}{\sqrt{2\pi} \sigma_{\text{PV}}} \exp\left(-\frac{(\obsTime - \mu_t)^2}{2 \sigma_{\text{PV}}^2}\right) \eqpd
\end{split}
\end{equation}
%
The first two Gaussian components describe the prompt peak resolution, the third
component models the distribution of candidates associated to the wrong \PV.
Different calibration parameters $c_i$ and $b_i$ are chosen for the width of the
narrow ($i=1$) and the wide ($i=2$) Gaussian \PDF. The fractions $g_i$ add up to
unity together with the fraction $f_\text{\acs*{PV}}$ of candidates associated
to the wrong \PV. The offset $\mu_{\obsTime}$ of the Gaussian central value is
shared between all three Gaussian \acp{PDF}. Finally,
$\sigma_{\text{\acs*{PV}}}$ describes the width of the wrong \PV component. The
decay time distribution is modelled using two decay \acp{PDF} that are
convoluted with the resolution model
$\Resolution{}{}\!\left(\obsTime;\obsTimeError\right)$ and with pseudo-lifetimes
$\tau_{1,2}$.
\Cref{tab:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration:results}
lists the results that are used from now on in the decay time resolution model.
It is tested how the choice of the calibration model influences the measurement
using a \ToyMC study
(\cref{sec:measurement_of_sin2beta:systematics:systematics:resolution}).
%
\begin{table}[h]
  \centering
  \caption{Results of the fit of the parameters described in the decay time
  resolution model.}
  \label{tab:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration:results}
  \sisetup{
    table-number-alignment    = center,
    table-figures-integer     = 1,
    table-figures-decimal     = 5,
    table-figures-uncertainty = 5,
    table-sign-mantissa,
  }
  \begin{tabular}{llSS}
    \toprule
    \multicolumn{2}{c}{Parameter}       &   {\catDD sample}     &   {\catLL sample}   \\
    \midrule
    $\mu_t$             &   (\si{\ps})  &   -0.00291 +- 0.00026 & -0.00169 +- 0.00026 \\
    $b_{1}$             &               &    0.88    +- 0.09    &  1.04    +- 0.14    \\
    $c_{1}$             &   (\si{\ps})  &    0.0077  +- 0.0028  &  0.0045  +- 0.0028  \\
    $b_{2}$             &               &    1.33    +- 0.33    &  1.8     +- 0.4     \\
    $c_{2}$             &   (\si{\ps})  &    0.019   +- 0.008   &  0.007   +- 0.005   \\
    $g_{2}$             &               &    0.251   +- 0.020   &  0.24    +- 0.023   \\
    $\sigma_\text{PV}$  &   (\si{\ps})  &    1.6     +- 0.7     &  1.40    +- 0.14    \\
    $f_\text{PV}$       &               &    0.048   +- 0.004   &  0.0488  +- 0.0024  \\
    \midrule
    $\tau_1$            &   (\si{\ps})  &   0.7      +- 0.5     &  0.29    +- 0.06    \\
    $\tau_2$            &   (\si{\ps})  &   2.1      +- 1.3     &  1.82    +- 0.12    \\
    $f_1$               &               &   0.08     +- 0.10    &  0.046   +- 0.006   \\
    $f_2$               &               &   0.08     +- 0.11    &  0.079   +- 0.009   \\
    \bottomrule
  \end{tabular}
\end{table}

% ------------------------------------------------------------------------------
\subsection{Decay time acceptance}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:acceptance}

Acceptance effects that alter the distribution of the decay time might result
from selection requirements or inefficiencies in the event reconstruction. This
section summarises acceptance effects stemming from lifetime biasing selection
cuts of trigger requirements (\cf
\cref{sec:measurement_of_sin2beta:data_preparation:trigger}) and reconstruction
inefficiencies mainly caused by the \VELO track reconstruction algorithms (\cf
\cref{sec:lhcb_experiment:tracking}).

% ..............................................................................
\subsubsection{Trigger induced decay time acceptance}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower}

The biased trigger lines (\cf
\cref{sec:measurement_of_sin2beta:data_preparation:trigger}) and the stripping
cut on the reconstructed decay time of the $\Bd$ candidates result in a non-flat
decay time acceptance.

In order to correctly describe these effects, the data sample is split into two
disjoint categories of candidates that show a substantially different behaviour
regarding their decay time acceptance. All candidates passing the \emph{almost
unbiased} (\textbf{\catAU}) trigger requirements show nearly no decay time
acceptance effects, in contrast to the sample of candidates passing the
\emph{exclusively biased} (\textbf{\catEB}) trigger requirements. The addressed
requirements are:
%
\begin{description}
  \item[\catAU] \TriggerReqAU
  \item[\catEB] \TriggerReqEB
\end{description}
%
To construct the acceptance in terms of ratios, a sample of candidates that pass
a set of unbiased trigger requirements is needed:
%
\begin{description}
  \item[Unbiased] \TriggerReqUB
\end{description}
%
The acceptance of the \catAU subsample can be computed using the overlap of
events which pass the biased and the unbiased \HLTTwo di-muon lines. Both
lines are using the same trigger cuts except for an additional cut on the flight
distance significance (see
\cref{tab:measurement_of_sin2beta:data_preparation:trigger:hlt2:cuts}) in the
case of the biased line. The acceptance can then be written as a time-dependent
efficiency $\varepsilon_\text{\catAU}$, with
%
\begin{align}
    \varepsilon_\text{\catAU} &= \frac{\text{\VerbAU\VerbAnd \HLTTwoDiMuonJpsi}}{\text{\VerbUB}}\\
                              &= \frac{\text{\TriggerReqAUEnumerator}}{\text{\TriggerReqUB}}\eqpd \nonumber
\end{align}
%
For the \catEB subsample, there is no corresponding reference sample available,
so strictly speaking only a relative efficiency can be computed. Nonetheless,
the ratio of the \catEB subsample and the unbiased subsample can be computed as
$\varepsilon_\text{\catEB}$.
%
\begin{align}
    \varepsilon_\text{\catEB} &= \frac{\text{\VerbEB}}{\text{\VerbUB}}\\
                              &= \frac{\text{\TriggerReqEB}}{\text{\TriggerReqUB}}\eqpd \nonumber
\end{align}
%
In other words $\varepsilon_\text{\catAU}$ quantifies the efficiency due to the
requirements by the biased \HLTTwo line for events that pass the unbiased
\HLTOne line, whereas $\varepsilon_\text{\catEB}$ effectively quantifies the
relative efficiency introduced by both, the \HLTOne and \HLTTwo, biased trigger
lines.

\subsubsection{Methodology}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:methodology}

The data set for studying the trigger acceptance effects consists of all events
that are selected by the \StrippingDetached stripping line and pass the
offline selection. As the tagged and untagged candidates are expected to behave
equally concerning the studied effect all available candidates are used.
On the remaining multiple candidates, a random candidate selection is applied.
All candidates are selected by either one of the four considered trigger lines.

The efficiencies are time-dependent and, since the focus lies on the acceptance
of the signal component's decay time distribution, have to be determined through
a fit to separate signal from background. To do so, a simultaneous fit for the
signal yield is performed in ten bins of decay time. The bin boundaries are
chosen in a way that each bin contains the same number of events (before
splitting the data into the different fit categories). The fit is also performed
simultaneously in categories of track type, tagger, and both trigger sets given
by the numerators and the denominator of $\varepsilon_\text{\catAU}$ and
$\varepsilon_\text{\catEB}$. The yields for the different tagger and track type
categories are summed up (including error propagation). Then the efficiency per
time bin is calculated. For $\varepsilon_{\catAU}$ a binomial error is
estimated, while a Gaussian error propagation is used for
$\varepsilon_{\catEB}$.

In the mass fit, the signal peak is described by a \Ipatia \PDF, while a single
exponential is used to describe the combinatorial background.
\Cref{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:mass_fits}
shows both mass distributions and fit projections for the biased and unbiased
sample, respectively. In both plots the sum over all categories is displayed.
%
\begin{figure}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/mass_trigger_efficiency_biased.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/mass_trigger_efficiency_unbiased.pdf}
\caption{Mass distribution and fit projection summed over all categories for
the (left) biased (\catAU and \catEB) and the (right) unbiased sample.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:mass_fits}
\end{figure}
%
\Cref{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:splines}
shows the acceptance histograms for the \catAU and the \catEB sample. In the
nominal fit cubic splines \cite{Karbach:2014qba} are used instead of the
histograms themselves. Each bin centre is used as a knot for the splines. The
bin contents determine the shape of the splines. However, the bin contents
aren't fixed but constrained with a Gaussian function where the width is given
by the uncertainty on the bin content. As there is no information about the
acceptance at the decay time limits, the efficiency is assumed to be flat
between the lower decay time limit at \SI{0.3}{\ps} and the first bin
centre/knot and the last bin centre/knot and the upper decay time limit at
\SI{18.3}{\ps}, respectively.
%
\begin{figure}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/trigger_acceptance_spline_AU.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/trigger_acceptance_spline_EB.pdf}
\caption{Histograms of the trigger acceptance for the (left) almost unbiased and
the (right) exclusively biased sample. The blue curve shows the fitted
acceptance using cubic splines.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:splines}
\end{figure}

% ..............................................................................
\subsubsection{Upper decay time acceptance}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}

Due to a decrease in the \VELO reconstruction efficiency for tracks with a
larger offset to the beam line, a second decay time acceptance effect has to be
modelled. To account for this a correction factor $\beta_\tau$ is included into
the fit model by implementing the modified lifetime
%
\begin{equation}\label{eq:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}
  \widetilde{\tau} = \frac{\tau}{1 + \beta_\tau \tau} \eqpd
\end{equation}
%
The value of $\beta_\tau$ is determined using an unbinned fit to simulated data
while fixing the lifetime $\tau$ to its generation value. Based on the
\BdToJpsiKS signal \MC data set, only candidates passing the
\StrippingPrescaled stripping line and the unbiased trigger lines
\HLTOneDiMuonHighMass and \HLTTwoDiMuonJpsi are chosen to avoid any
additional lifetime bias for events with short decay times. Only candidates
being matched on \MC as true signal events are considered. The nominal offline
selection is applied and from the remaining multiple (\acs{PV},\,\Bd) candidate
pairs, one is chosen randomly. To avoid wrong-\acs{PV} associations of the
reconstructed \BdToJpsiKS candidate the true \MC decay time is used in the fit.
To reduce the statistical uncertainties, and as no deviations of the decay time
distributions are expected, all untagged events are included. The number of
remaining \MC candidates available for this study is roughly \num{60000}. Due to
differences in the reconstruction efficiency the factor $\beta_\tau$ is
determined separately for \catOO/\catOT and \catDD/\catLL events. The results
are collected in
\cref{tab:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}.
%
\begin{table}
  \centering
  \caption{Decay time correction factor $\beta_\tau$ in \si{\per\pico\second}.}
  \label{tab:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}
  \sisetup{
    table-number-alignment    = center,
    table-figures-integer     = 1,
    table-figures-decimal     = 4,
    table-figures-uncertainty = 4,
  }
  \begin{tabular}{cSS}
    \toprule
           & {2011}           & {2012} \\
    \midrule
    \catDD & 0.0036 +- 0.0029 & 0.0084 +- 0.0032 \\
    \catLL & 0.018  +- 0.004  & 0.035  +- 0.005  \\
    \bottomrule
  \end{tabular}
\end{table}

\subsubsection*{Influence of higher order effects}

\cref{eq:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}
expands to
%
\begin{equation}\label{eq:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper:linear}
\begin{split}
  \Prob{}{}\left(t\right) &= \exponential{-\frac{t}{\tau}\left(1+\beta_{\tau}\tau\right)} \\
                          &= \exponential{-\frac{t}{\tau}-\beta_{\tau}t} = \exponential{-\frac{t}{\tau}} \exponential{-\beta_{\tau}t} \\
                          &= \exponential{-\frac{t}{\tau}}\left(1-\beta_{\tau} t+\frac{\beta_{\tau}^2 t^2}{2}+\order{(\beta_{\tau} t)^3}\right).
\end{split}
\end{equation}
%
To check the influence of higher order terms, a quadratic correction function is
tested where the second order term has an own degree of freedom given by
$\gamma_\tau^\prime$,
%
\begin{equation}\label{eq:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper:quadratic}
  \Prob{}{}\left(t\right) = \exponential{-\frac{t}{\tau}}\left(1-\beta_\tau^\prime t+ \gamma_\tau^\prime t^2\right).
\end{equation}
%
Again the parameters $\beta_\tau^\prime$ and $\gamma_\tau^\prime$ are fitted
while fixing the lifetime $\tau$. In \cref{tab:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper:quadratic}
the results are listed for \catOO/\catOT and \catDD/\catLL events. To visualise
the effect, the per-bin ratio of the decay time distributions of signal \MC
events to events generated from \ToyMC is calculated and shown in
\cref{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}.
The \ToyMC decay time distribution follows an exponential function with the same
lifetime as used in the generation of the signal \MC. As the uncertainties on
$\beta_\tau^\prime$ and $\gamma_\tau^\prime$ are large and the parameters are
strongly correlated ($\rho>\SI{90}{\percent}$), the linear model is selected. A
possible bias due to this choice is investigated in
\cref{sec:measurement_of_sin2beta:systematics:systematics:acceptance}.
%
\begin{table}
  \centering
  \caption{Decay time correction factors $\beta_\tau^\prime$ (in
  \si{\per\pico\second}) and $\gamma_\tau^\prime$ (in
  \si{\per\square\pico\second}).}
  \label{tab:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper:quadratic}
  \sisetup{
    table-number-alignment    = center,
    table-figures-integer     = 1,
    table-figures-decimal     = 3,
    table-figures-uncertainty = 3,
    table-sign-mantissa,
  }
  \begin{tabular}{
    c
    S
    S[
    table-figures-decimal     = 4,
    table-figures-uncertainty = 4,
    ]
    S
    S[
    table-figures-decimal     = 4,
    table-figures-uncertainty = 4,
    ]
  }
    \toprule
           & \multicolumn{2}{c}{2011}                          & \multicolumn{2}{c}{2012}                        \\
           & {$\beta_\tau^\prime$}  & {$\gamma_\tau^\prime$}   & {$\beta_\tau^\prime$}  & {$\gamma_\tau^\prime$} \\
    \midrule
    \catDD & -0.016 +- 0.007        & -0.0030 +- 0.0008        & -0.001 +- 0.007        & -0.0014 +- 0.0009      \\
    \catLL & -0.001 +- 0.009        & -0.0028 +- 0.0012        &  0.01  +- 0.06         & -0.0027 +- 0.0008      \\
    \bottomrule
  \end{tabular}
\end{table}
%
\begin{figure}
  \includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/velo_acceptance_11_DD.pdf}\hfill
  \includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/velo_acceptance_11_LL.pdf}
  \includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/velo_acceptance_12_DD.pdf}\hfill
  \includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/velo_acceptance_12_LL.pdf}
\caption{
Decay time ratio in bins of decay time for (left/right) \catDD/\catLL and
(top/bottom) \catOO/\catOT. The blue (red) curve shows a linear (quadratic) fit
to the data points.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}
\end{figure}