A total of 5120 Montecarlo-generated background events and 1536 signal events from different samples were fed to the test framework. The number of times the algorithm successfully identified and rejected a background event is shown in \tablename~\ref{tab:gpu-trig-eff}. The efficiency for the signal was also computed and it is shown in the same table. The errors shown represent pure statistical uncertainties.\\
%1280 Montecarlo-generated $K^+ \rightarrow \pi^+ \pi^0$ decay that passed the standard L0 selection were fed to the test framework. Of these, 826 were successfully identified and rejected, reaching a rejection level of (64.5 $\pm$ 1.3)\% (where the error represents the statistical uncertainty). A $K^+ \rightarrow \pi^+\pi^+\pi^-$ sample of \\

\begin{table}
\centering
\begin{tabular}{lcccc}
\hline
\hline
Data type & & Sample & Discarded & Trigger efficiency (\%)\T\B\\
\hline
$\pi^+\pi^0$ & L0 selected & 1280 & 800 & 62.5 $\pm$ 1.4\T\\
$\pi^+\pi^+\pi^-$ & L0 selected & 1536 & 920 & 59.9 $\pm$ 1.3\\
$\pi^+\pi^0$ & $5\leq n_{hit}\leq 64$ & 1024 & 618 & 60.4 $\pm$ 1.5\\
$\pi^+\pi^+\pi^-$ & $5\leq n_{hit}\leq 64$ & 1280 & 936 & 73.1 $\pm$ 1.2\B\\
\hline
$\pi^+\nu\bar{\nu}$ & L0 + Signal cuts & 768 & 38 & 95.1 $\pm$ 0.8\T\\
$\pi^+\nu\bar{\nu}$ & Signal cuts & 768 & 38 & 95.1 $\pm$ 0.8\B\\
\hline
\hline
\end{tabular}
\caption{GPU trigger performance. The first four rows show the achieved rejection level for four different background samples. The last two rows show the $K^+ \rightarrow \pi^+ \nu \bar{\nu}$ efficiency achieved before and after a standard L0 selection is performed (the rejected events differ in the two cases, even if the result is the same).}\label{tab:gpu-trig-eff}
\end{table}

The trigger was run on two series of Montecarlo-generated data sets. One series consisted of events that had passed the standard L0 selection (see \chaptername~\ref{ch:na62-tdaq}). This means that the multiplicity of hit PMTs was constrained between 5 and 32. The other series was not filtered through the L0 trigger requirements, but it was requested that each event had a number of hits comprised between 5 and 64. The latter events were analysed in order to explore the possibility of running a GPU-based trigger in parallel to a less biased hardware trigger, where the RICH hit multiplicity cut is relaxed or completely dropped. This way it would be possible to design special triggers to explore additional Physics channels. \\

The data sets were further divided into subsets according to the number of hits in each event, to analyse the behaviour of the algorithm with respect to this variable. The performance of the trigger on the various subsets is shown in Figures~\ref{img:binned-eff-pipi0-32} to~\ref{img:binned-eff-pinunu-32}.\\

\begin{figure}
\centering
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/pipi0_32}\label{img:binned-eff-pipi0-32}}
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/pipi0_64}\label{img:binned-eff-pipi0-64}}
\vfill
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/pipipi_32}\label{img:binned-eff-pipipi-32}}
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/pipipi_64}\label{img:binned-eff-pipipi-64}}
\vfill
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/pinunu_32}\label{img:binned-eff-pinunu-32}}
%\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/pinunu_32}\label{img:binned-eff-pinunu-64}}
\caption{Trigger rejection for $\pi^+\pi^0$ \textbf{(a, b)} and $\pi^+\pi^+\pi^-$ \textbf{(c, d)} backgrounds, and signal efficiency \textbf{(e)}. The distributions on the right differ from the ones on the left for the data set used: on the left \textbf{(a, c)}, the trigger was run on Montecarlo-simulated events that passed the standard L0 selection. On the right \textbf{(b, d)}, only a relaxed $5 \leq n_{hit} \leq 64$ cut was applied to the input data set. Standard L0 selection and signal cuts (see \tablename~\ref{tb:sigdef}) were applied for the $\pi\nu\bar{\nu}$ data set shown in the bottom panel \textbf{(e)}.}
\end{figure}

%In Figures~\ref{img:binned-eff-pipi0-32} and~\ref{img:binned-eff-pipipi-32} the efficiency of the trigger is shown for the rejection of $\pi^+\pi^0$ and $\pi^+\pi^+\pi^-$ backgrounds, respectively.\\
%
%The trigger was run on Montecarlo-generated data sets, where each event had passed the standard L0 selection (see \chaptername~\ref{ch:na62-tdaq}). This means that the multiplicity of hit PMTs was constrained between 5 and 32. The data sets were divided into subsets according to the number of hits in each event, to analyse to behaviour of the algorithm with respect to this variable.\\

We can infer from \figurename~\ref{img:binned-eff-pipi0-32} that the rejection for L0 filtered $\pi^+\pi^0$ events increases with the number of hits. In particular, the low rejection $\varepsilon_{\leqslant10} = (40.5 \pm 3.4)\%$ shown for events with $5 \leq n_{hit} \leq 10$ arises from the difficulty of fitting a ring with so few points. The three following bins yield increasing rejection levels of $\varepsilon_{\leqslant16} = (58.5 \pm 2.6)\%$, $\varepsilon_{\leqslant23} = (69.4 \pm 2.0)\%$ and $\varepsilon_{\leqslant32} = (76.0 \pm 3.1)\%$, respectively: as the number of hits per event increases, chances are that the fraction of spurious hits due to the presence of other partial rings decreases. The identification of rings is therefore easier, with the effect of increasing the rejection capability of the trigger (as discussed in Section~\ref{sect:trigger-impl}, events are rejected only if the quality of the identified rings exceeds a threshold defined by a few parameters).\\

On the other hand, the initial low-multiplicity rejection capability achieved for $3\pi$ events with few hits is higher (plot~\ref{img:binned-eff-pipipi-32}): in this case, $\varepsilon_{\leqslant10} = (49.3 \pm 3.1)\%$. In fact, in this case it is more probable that at least one \v{C}erenkov ring is present in the RICH detector. 
%Moreover, if two or more different rings are detected, the event is discarded. 
However, \figurename~\ref{img:binned-eff-pipipi-32} highlights that for $3\pi$ events there is no steep increase of rejection power with the number of hits, as there is for the 2-body background. This is probably due to the fact that the trigger is not optimized for the $\pi^+\pi^+\pi^-$ background. As the number of hits increases, it is easier to detect a single ring, but it becomes more difficult to separate an increasing number of rings. In principle, this difficulty might be overcome by 
%introducing additional triplets for 
using more triplets in the pattern recognition procedure. The trigger rejection computed in the other three bins reads: $\varepsilon_{\leqslant16} = (60.4 \pm 3.0)\%$, $\varepsilon_{\leqslant23} = (60.7 \pm 2.7)\%$ and $\varepsilon_{\leqslant32} = (63.6 \pm 1.9)\%$.\\

%It is interesting to explore the possibility of running a GPU-based trigger in parallel to a standard hardware trigger where the RICH hit multiplicity cut is dropped. This could be useful in order to design special triggers to explore more Physics channels. With this aim, three more data sets were prepared, where the L0 selection was completely dropped in favour of a more relaxed multiplicity cut $5 \leq n_{hit} \leq 64$. 
Plots~\ref{img:binned-eff-pipi0-64} and~\ref{img:binned-eff-pipipi-64} display the level of background rejection achieved on the second series of input data, that was selected with a relaxed multiplicity cut only ($5\leq n_{hit}\leq 64$).\\

In particular, from \figurename~\ref{img:binned-eff-pipi0-64} we learn that most $\pi^+\pi^0$ events can be correctly identified, and therefore rejected, when the number of hits found is greater than 32:
\begin{align}
&\varepsilon_{\leqslant16} = (44.0 \pm 2.5)\%\\
&\varepsilon_{\leqslant32} = (64.3 \pm 2.1)\%\\
&\varepsilon_{\leqslant48} = (89.4 \pm 3.0)\%\\
&\varepsilon_{\leqslant64} = (92.3 \pm 4.3)\%
\end{align}
%From another point of view, this is in fact another validation of the standard RICH multiplicity L0 cut. 
%The efficiency achieved is very high indeed for high-multiplicity events: it is therefore feasible, in principle, to drop the RICH multiplicity L0 cut, and to rely only on GPU-based alternatives.\\
The level of event rate suppression achieved for the set of $\pi^+\pi^+\pi^-$ events can be read from plot~\ref{img:binned-eff-pipipi-64}:
\begin{align}
&\varepsilon_{\leqslant16} = (53.2 \pm 3.8)\%\\
&\varepsilon_{\leqslant32} = (68.6 \pm 2.0)\%\\
&\varepsilon_{\leqslant48} = (82.8 \pm 1.6)\%\\
&\varepsilon_{\leqslant64} = (93.8 \pm 6.1)\%
\end{align}

The trigger proves most powerful for high-multiplicity events: it could be therefore feasible, in principle, to drop the RICH multiplicity cut from the standard trigger, and to rely only on the GPU-based alternative.\\

The results plotted in \figurename~\ref{img:binned-eff-pinunu-32}, finally, ensure that the design of this algorithm is optimized to minimize unwanted suppression of the signal. The plot shows the efficiency for $K^+ \rightarrow \pi^+ \nu \bar{\nu}$ decays that passed the standard L0 selections, for different intervals of hit multiplicity:
\begin{align}
&1-\varepsilon_{\leqslant10} = (98.4 \pm 1.1)\%\\
&1-\varepsilon_{\leqslant16} = (94.7 \pm 1.2)\%\\
&1-\varepsilon_{\leqslant23} = (93.6 \pm 1.5)\%\\
&1-\varepsilon_{\leqslant32} = (97.2 \pm 2.7)\%
\end{align}
A study of the signal efficiency carried out on a set of $\pi^+\nu\bar{\nu}$ data not preliminarily filtered by the standard L0 selections yielded the same global results (\tablename~\ref{tab:gpu-trig-eff}). However, no $\pi^+\nu\bar{\nu}$ events with hit multiplicity higher than 32 could be found after performing the signal selection described in \tablename~\ref{tb:sigdef}.\\

It must be pointed out that none of the selections implemented in the trigger (see Section~\ref{sect:trigger-impl}) were designed specifically to cope with the $3\pi$ background. The algorithm should be further optimized in order to suppress the rate of these events. The tests reported in plots~\ref{img:binned-eff-pipi0-64} and~\ref{img:binned-eff-pipipi-64} were only intended to verify, on events that may feature more than one \v{C}erenkov ring, the efficiency of the `multi-ring' algorithm I developed.\\

\begin{figure}
\centering
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/nhit_pipi0_32}\label{img:nhit-pipi0-32}}
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/nhit_pipi0_64}\label{img:nhit-pipi0-64}}
\vfill
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/nhit_pipipi_32}\label{img:nhit-pipipi-32}}
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/nhit_pipipi_64}\label{img:nhit-pipipi-64}}
\vfill
\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/nhit_pinunu_32}\label{img:nhit-pinunu-32}}
%\subfigure[]{\includegraphics[width=0.49\textwidth]{Images/pdf/gpu_algo/tests/pinunu_32}\label{img:nhit-pinunu-64}}
\caption{Hit multiplicity in the triggered data sets.}
\end{figure}

Plots~\ref{img:nhit-pipi0-32} to~\ref{img:nhit-pinunu-32} analyse the data sets used for the tests described in this section. The multiplicity of hits in the events is shown as a function of the number of different rings detected, for the data sets described above. We can observe that:
\begin{itemize}
\item The number of times no rings could be identified approaches zero, for $\pi^+\pi^0$ events, as the number of hits in the event grows, and in particular for $n_{hit} > 32$. This explains why the trigger is more powerful for high-multiplicity primitives.
\item While $\pi^+\pi^0$ events mostly exhibit a single \v{C}erenkov ring, in a significant fraction of the $3\pi$ events analysed two rings were detected. This fraction increases with the hit multiplicity up to approximately $n_{hit} \simeq 35$, and then it decreases. This is a hint that the 4-triplets approach used for this work cannot efficiently handle events with a very large hit multiplicity.
\item The number of times three different rings were detected is very small. However, it is not possible to state that this is due to a problem in the algorithm discussed here. The current NA62 analysis software does not provide any straightforward way to know the actual number of \v{C}erenkov rings formed, or the actual number of charged particles that crossed the RICH volume. Besides, in order to verify the real ring detection efficiency, the format of data fed to the GPU should be modified to include ``Montecarlo-truth'' information. A ``toy'' simulation with a custom ring generating tool might be designed to perform these tests.
\end{itemize}

The algorithm I designed represents only a starting point for a real-time application of GPUs in High Energy Physics. The results achieved with this work can still be improved by devoting further effort to the development of a parallelized trigger algorithm, and to the study of its performance.\\