In order to be used as lowest-level trigger, a ring-fitting algorithm needs to be:
\begin{itemize}
\item \textbf{seedless}: it will be fed with raw RICH data, with no previous information on the ring position from other detectors;
\item \textbf{fast}: it will run concurrently with the hardware L0 trigger, with a maximum latency (\textit{decision making} time) of 1~\si{\milli\second} and an event rate of about 10~\si{\mega\hertz};
\item \textbf{accurate}: while the aim of this project is to reduce the background events rate to as low as possible, we still need to maintain the signal acceptance close to 100\%. Our constraints therefore will be defined by the finite combined resolution of the RICH detector and of the ring finding algorithm;
\item \textbf{``multi-ring friendly''}, to account for inelastic hadron scattering and $\pi^0$ Dalitz decays, for the $\pi^+\pi^-\pi^+$ background, and to allow positive identification of rare di-lepton decay modes.
\end{itemize}

When I started working on this thesis, there were no multi-ring parallel fitting algorithms in literature ready to be adapted to RICH applications. For this reason, I tried to figure out how to discard events with more than one ring, i.e. with more than one charged track, that would be rejected during the final $K^+ \rightarrow \pi^+ \nu \bar{\nu}$ analysis.\\

If there are only single-ring algorithms available, the easiest way to check whether the data points really belong to a single circle is to compute a $\chi^2$ variable on the ring candidate. Except in the rare case when two rings are concentric and similar in radius, a \textit{least squares} analysis will return a higher $\chi^2$ when the points do not belong to the same ring.\\

However, as reported in \chaptername~\ref{ch:mc}, a background rejection algorithm is more effective if it is designed to provide at least basic kinematical information. The background process $K^+ \rightarrow \pi^+ \pi^0$ analysed in this work may create multiple rings in the cases reported in \chaptername~\ref{ch:2body}. 
The presence of more rings (or parts of rings), and possibly of noise hits on the photomultipliers, would make it difficult to evaluate the radius and position of a ``real'' $\pi^+$ \v{C}erenkov ring.\\

In addition, NA62 is a promising experiment for the study of other $K$ decay channels, besides $\pi^+\nu\bar{\nu}$: the large statistics it will collect will make it possible to probe other ultra-rare or forbidden decay channels with unprecedented precision.
Most current BSM theories predict some degree of Lepton Flavour Violation (LFV). A non-exhaustive list of such theories includes Supersymmetry (SUSY), Technicolor, Little Higgs models, extra dimensions and even the introduction of heavy neutrinos.\\

SM-forbidden decays such as $K^+ \rightarrow \pi^+ \mu^\pm e^\mp$ and $K^+ \rightarrow \pi^- \ell^+ {\ell'}^+$ (with $\ell ,\ell' = \mu,e$) would feature a very clean experimental signature.
The high statistics of NA62 -- of the order of $10^{13}$ kaon decays -- would allow the current limits to be improved by a factor of about 10: the existing limits for these processes are listed in \tablename~\ref{tab-lfv}.\\

Current limits from \tablename~\ref{tab-lfv} date back to 2005 (1996 data) for BNL experiments, and to 2011 for NA48/2 \cite{Sher:2005sp,Ambrose:1998us,Batley:2011zz}.
The sensitivity in NA62 is expected to be of the order of $10^{-12}$, and it should be possible to improve the current branching ratio limits by at least one order of magnitude.
Moreover, NA62 will be equipped with better spectrometers compared to the previous generation kaon experiments, providing a better mass resolution and allowing cleaner separation between background events such as $K^+\to\pi^+\pi^+\pi^-$ and the signal region. This will allow direct searches in regions with low expected Physics background.\\

\begin{table}
\begin{tabular}{p{2cm}p{1.5cm}p{3.5cm}c}
\hline
%\parbox[c][][c]{2cm}{\centering\T $K^+$ decay\\mode\B} & \parbox[c][][c]{1.5cm}{\centering\T SM\\violation\B} & \parbox[c][][c]{3.5cm}{\centering\T Branching ratio\\$\Gamma_i/\Gamma$ at 90\% C.L.\B} & Experiment\\
\parbox[c][][c]{2cm}{\centering\T $K^+$ decay\\mode\B} & \parbox[c][][c]{1.5cm}{\centering\T SM\\violation\B} & \parbox[c][][c]{3.5cm}{\centering\T Branching ratio\\at 90\% C.L.\B} & Experiment\\
\hline
\centering $\pi^+ \mu^+ e^-$ & \centering LF & \centering$< 1.3 \times 10^{-11}$ & BNL E777 -- E865\T\\
\centering $\pi^+ \mu^- e^+$ & \centering LF & \centering$< 5.2 \times 10^{-10}$ & BNL E865 -- CERN NA48/2\\
\centering $\pi^- \mu^+ e^+$ & \centering L & \centering$< 5.0 \times 10^{-10}$ & BNL E865 -- CERN NA48/2\\
\centering $\pi^- e^+ e^+$ & \centering L & \centering$< 6.4 \times 10^{-10}$ & BNL E865 -- CERN NA48/2\\
\centering $\pi^- \mu^+ \mu^+$ & \centering L & \centering$< 1.1 \times 10^{-9}$ & CERN NA48/2\B\\
\hline
\end{tabular}
\caption{Lepton Number (\textit{L}) and Lepton Flavour Number (\textit{LF}) violating $K^+$ decay modes}\label{tab-lfv}
\end{table}

LF violating decays may be pursued by NA62 to sensitivities corresponding to possible tree-level contribution of new particles, where the decay mode suppression arises from the mass of the exchanged field. A precise measurement would rule out a fraction of theories providing LFV.\\

The detection of a lepton pair would result in a trigger opportunity for such forbidden decay modes: allowed decays with more than one lepton in the final state are highly suppressed, and always imply the presence of a neutrino. As a consequence, they can be identified and discarded by the analysis of the missing energy. The probability of misidentifying a pion as a lepton is low, due to the presence of several P.ID.\footnote{Particle Identification.} detectors. The high-resolution NA62 spectrometer makes it possible to apply stringent cuts on the decay vertex, and to remove the background due to the pile-up of different decay events.\\

For all these reasons, a real-time algorithm capable of fitting multiple rings would be valuable.\\%seems most advisable.\\

Since no seedless multiple-ring-fitting algorithm exists, we chose to split the problem in a preliminary ``\textbf{pattern recognition}'' step, needed to divide the data set into single-ring candidates, and a subsequent \textbf{single-ring fitting} stage.\\



\section{Ptolemy's theorem}

For the pattern recognition step we chose to exploit Ptolemy's trigonometric theorem \cite{geometry} about quadrilaterals inscribed in a circle, as first proposed by G. Lamanna \cite{gianluca-tipp}:

\begin{pttheo}
For a cyclic quadrilateral, the sum of the products of the two pairs of opposite sides equals the product of the diagonals.
\end{pttheo}

\begin{figure}
\centering
\includegraphics[width=0.4\textwidth]{Images/pdf/gpu_algo/Ptolemy_Theorem_nolabels}
\caption{Ptolemy's theorem is a relation among the lengths of the sides and those of the diagonals in a cyclic quadrilateral.}\label{img:ptolemy}
\end{figure}

For our application this theorem translates to the subsequent formula (refer to \figurename~\vref{img:ptolemy} for vertices and segments naming):
\begin{align}
&\overline{AB}\cdot \overline{CD} + \overline{AD}\cdot \overline{BC} - \overline{AC}\cdot \overline{BD} = 0
\end{align}

Given the coordinates of three points on a circle, we use this theorem to check whether a fourth point belongs to the same circle or not. If it belongs to the same circle, it is added into an array that contains the set of points belonging to the given ring candidate.\\

Ideally, this process would be repeated until there are no points left, and then the ring candidates would be fed to a ring-fitting algorithm that would find the best centre and radius.\\

Unfortunately, our algorithm needs to be seedless, meaning that we do not know a priori how many rings the current event contains, and we are unable to identify three starting points belonging to the same ring. We must therefore find an approximate way to define adequate starting ``triplets'' of hits %on which the Ptolemy algorithm will be run.
that will be fed to the Ptolemy algorithm.\\

In this chapter I will examine the building blocks of the trigger algorithm developed for this project. In Section~\ref{sect:triplets} I will examine the procedure devised for the definition of four initial suitable triplets in detail. However, we first need to go through a short description of the data fed to the procedure (Section~\ref{sect:data-format}). \chaptername~\ref{app:algo-implementation} will describe the GPU implementation of the whole trigger program more thoroughly.\\