The project described in this thesis was partly carried out by means of the NA62 software. ``NA62FW'', i.e. the NA62 software suite, is still being actively developed. It includes a Montecarlo event generator, featuring Geant4\footnote{Geant4 is a toolkit to simulate the passage of particles through matter. \url{http://geant4.cern.ch/}} modelling and event reconstruction routines for most NA62 detectors. 
%, that includes a detailed Montecarlo simulation tool, devised upon the current design of the detector system, and provides data reconstruction routines for some sub-detectors. 
This framework makes use of many Physics utility libraries: detector geometry and particle propagation are implemented through Geant4 \textit{physics lists}, while some ROOT classes handle input/output and data processing, and define hit and event structures.
While this thesis was being developed, hardly any Physics analysis algorithm was implemented in NA62FW. The author designed the reconstruction and track propagation methods described in this Chapter.\\

In order to consider all the material in which particles could interact, I simulated $K^+ \rightarrow \pi^+ \nu \bar{\nu}$ and $K^+ \rightarrow\pi^+ \pi^0$ decays enabling all the sub-detectors upstream of the RICH, that was also included.
% including at least the RICH and the sub-detectors located upstream of it, in order to take all the material into account, in which the simulated particles can interact. 
I then used the reconstruction routines supplied with the NA62 software to examine the events detected by the RICH.
\figurename~\ref{img:l0algo:flange} shows a typical output of the RICH reconstruction routine: a \v{C}erenkov cone emitted by a charged particle results in a ring of photomultipliers firing.\\

\begin{figure}
	\centering
    \includegraphics[width=0.8\textwidth]{Images/pdf/L0algo/flange}
    \caption{\v{C}erenkov ring produced by a simulated $\pi^+$ with momentum $15 \leq P_z \leq 35$ \si{\giga\electronvolt/\textit{c}} on one of the two PM spots of the RICH. Each circle represents a photomultiplier.}\label{img:l0algo:flange}
\end{figure}

The RICH reconstruction algorithm that was provided by the NA62 software at the time of my work may be summarized as follows:\\

\begin{algorithm}[H]
\caption{RICH event reconstruction}
\SetAlgoLined
\SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
%\Input{ a set of \v{C}erenkov photons hitting the RICH flanges (\emph{event})}
\Input{ coordinates of a set of firing photomultipliers (RICH \emph{event})}
\Output{ \v{C}erenkov ring parameters $(\vec{C},R)$ and timestamp $T$}
\BlankLine
%\For{$i=0$ \KwTo $n_\gamma$}{
%	\For{$j=0$ \KwTo $n_{\rm PMTs}$}{
%		$d_j$ = distance between $\gamma_i$ and PMT$_j$\;
%	}
%	$d_k$ = minimum $d_j$\;
%	hit$_i$ $\leftarrow$ coordinates PMT$_k$\;
%}
%\BlankLine
$\bar{x}$, $\bar{y}$ $\leftarrow$ compute centre of gravity of the hits\;
\BlankLine
\SetKwInOut{InitialGuess}{initial guess}
\InitialGuess{ $\vec{C}$ $\leftarrow$ $\bar{x}$, $\bar{y}$}
\InitialGuess{ R $\leftarrow$ 18.8 cm}
fit circle$(\vec{C},R)$ to ${\left\lbrace \mbox{hit}\right\rbrace}_{i=0\dots n_\gamma}$
\BlankLine
%\tcc{compute timestamp}
$T$ $\leftarrow$ compute average time of the hits
\end{algorithm}\B\B

\T\T\T\T Here, $\bar{x}$ and $\bar{y}$ are the coordinates of the centre of gravity of the hits, $\vec{C}$ is the center of the fitted ring and $R$ is its radius. This procedure shows some clear limitations. In fact, it only tries to adapt a single ring to the whole set of photon hits in input.
% Both Montecarlo simulated data, and the physics data we expect when the experiment will be running, 
RICH events often feature more than one charged particle producing \v{C}erenkov rings. Moreover, the geometry of the detector is not completely taken into account. Finally, the whole framework lacks simulation and reconstruction of piled-up events.\\

Therefore, I modified the code provided, and took the geometry features that were missing into consideration. I will briefly explain how I achieved this in Section~\ref{app:geometry}.\\

Events pile-up and the possibility of detecting more than one ring were not included at this time. The strategy the experiment will adopt in order to manage the time superposition of events is still evolving, and anyway it does not represent a critical aspect of this project.
%this is not an essential point for this project anyway. 
Regarding the possible multiplicity of \v{C}erenkov rings, a big effort has been put into the design of a GPU-based `multiple rings' fitting algorithm. However, during the previous Montecarlo characterization step that allowed me to study the rejection efficiency of such trigger algorithm, the presence of more than one ring was represented simply as a high $\chi^2$ in a single-ring fit.\\

My trigger algorithm requires some level of physics reconstruction on top of the detection of a \v{C}erenkov ring. In fact, the kinematic quantities involved in the decay process are modified by the MNP-33 magnet of the \textit{STRAW} spectrometer.
%(and possibly by contingent interaction in the upstream material). 
In addition, the original direction of the decaying kaon has to be taken into account when computing the laboratory-frame decay angle $\theta_{K\pi}$.
In Section~\ref{app:magnets} I will describe the procedure I used in order to reconstruct physical information about the process responsible for a detected RICH event.
% go through the process of extracting information about the physical process responsible for a given RICH event.

%The RICH detector will be indeed rotated with respect to the beam line, in order to minimize the possibility that beam particles spill into the detection volume.
%-----------------------------------