%\documentclass[pdflatex,a4paper,12pt,titlepage,oneside,openany,fleqn,final]{book}
\documentclass[pdflatex,a4paper,12pt,titlepage,twoside,openright,fleqn,final]{book} % FOR FINAL VERSION

\input{headers}

\begin{document}
\frontmatter
\selectlanguage{italian}

\begin{frontespizio}
	\Universita{Pisa}
	\Logo[3,5cm]{Images/pdf/Unipi-notext-bg}
%	\Facolta{Scienze Matematiche, Fisiche e Naturali}
%	\Dipartimento{ }
	\Divisione{\textsc{Dipartimento di Fisica `E. Fermi'}}
%	\Corso[Laurea Magistrale]{Scienze Fisiche}
%	\Scuola{Curriculum ``Fisica delle Interazioni Fondamentali''}
	\Scuola{ }
	\Annoaccademico{2012--2013}
	\Titoletto{Tesi di Laurea Magistrale in Scienze Fisiche\\Curriculum `Fisica delle Interazioni Fondamentali'\\Ottobre 2013}
%	\Titoletto{\textsc{Tesi di Laurea}\\ \today}
%	\Titolo{A GPU-based level 0 trigger\\for background rejection\\in rare kaon decays experiments}
	\Titolo{A GPU-based real time trigger\\for rare kaon decays at NA62}
%	\Sottotitolo{Test-beam results and analysis}
	\Candidato{Elena Graverini}
	\Relatore{Prof. Marco Sozzi}
	\Rientro{3cm}
%	\NCorrelatore{ Tutor aziendale }{ Tutor aziendali }
	\Preambolo{\usepackage{charter}}
	\Preambolo{\usepackage{microtype}}
	\Preambolo{\renewcommand{\frontlogosep}{2pt}}
	\Preambolo{\renewcommand{\frontinstitutionfont}{\fontsize{20}{36}\scshape}}
	\Preambolo{\renewcommand{\frontpretitlefont}{\fontsize{16}{22}\selectfont}}
	\Preambolo{\renewcommand{\frontdivisionfont}{\fontsize{16}{22}\scshape}}
	\Preambolo{\renewcommand{\fronttitlefont}{\fontsize{24}{28}\bfseries}}
	\Preambolo{\renewcommand{\frontsubtitlefont}{\fontsize{20}{24}\bfseries}}
	\Preambolo{\renewcommand{\frontfixednamesfont}{\fontsize{16}{18}\itshape}}
	\Preambolo{\renewcommand{\frontnamesfont}{\fontsize{16}{18}\selectfont}}
	\Preambolo{\renewcommand{\frontfootfont}{\fontsize{16}{18}\selectfont}}

\end{frontespizio}

%\pagestyle{plain}
\selectlanguage{british}

\dominitoc
%\addcontentsline{toc}{chapter}{\numberline{}\contentsname}
\tableofcontents
%\addcontentsline{toc}{chapter}{\numberline{}\listfigurename}
%\listoffigures
%\addcontentsline{toc}{chapter}{\numberline{}\listtablename}
%\listoftables


\selectlanguage{british}

\input{Parts/abstracts}
%\input{Parts/aknowledgements}

\selectlanguage{british}

\chapter{Introduction}\input{Parts/intro}
%\chapter*{Introduction}\addcontentsline{toc}{chapter}{Introduction}\input{Parts/intro}

\mainmatter
\part{The NA62 experiment}\label{part1}

\chapter{The NA62 experiment}\label{ch:na62}\minitoc\input{Parts/NA62}
	\section{Physics objectives}\input{Parts/NA62physics}
	\section{Theoretical framework}\label{sect:na62:phys}\input{Parts/na62/theory}
	\section{Previous searches for $\boldsymbol{ K^+ \rightarrow \pi^+ \nu \bar{\nu} }$}\input{Parts/na62/exp_status}
	\section{Experimental strategy}\label{ch:na62-strategy}\input{Parts/na62/exp_strategy}

\chapter{Experimental setup}\label{ch:exp-setup}\minitoc\input{Parts/na62/exp_setup}
	\section{Beam}\input{Parts/na62/beam}
	\section{Beam detectors}
		\subsection{The differential \v{C}erenkov counter (CEDAR)}\label{sect:cedar}\input{Parts/na62/detector/cedar}
		\subsection{The GigaTracker spectrometer}\label{sect:gtk}\input{Parts/na62/detector/gtk}
		\subsection{The charged anti-counter}\input{Parts/na62/detector/chanti}
	\section{Detectors downstream of the decay region}\input{Parts/na62/detector/downstream}
		\subsection{A hermetic setup for photon vetoing}\label{sect:gammaveto}\input{Parts/na62/detector/photon_veto}
		\subsection{The STRAW magnetic spectrometer}\label{sect:straw}\input{Parts/na62/detector/straw}
		\subsection{The RICH detector}\label{sect:rich}\input{Parts/na62/detector/RICHintro}
			\subsubsection{Principles of a RICH detector}\input{Parts/na62/detector/RICH}
			\subsubsection{The NA62 RICH detector}\input{Parts/na62/detector/RICHsetup}
		\subsection{The charged hodoscope}\input{Parts/na62/detector/chod}
		\subsection{The muon veto detectors}\input{Parts/na62/detector/muv}

\part{A RICH-based online trigger for $\boldsymbol{ K^+ \rightarrow \pi^+ \pi^0 }$ rejection: simulation and design}\label{part2}
	
\chapter{An online trigger using the RICH detector}\label{ch:purpose}\minitoc
	\section{Purpose}\input{Parts/trigIntro/purpose}
	\section{Trigger and Data Acquisition in NA62}\label{ch:na62-tdaq}\input{Parts/na62/tdaq}
	\section{The standard L0 trigger in NA62}\label{sect:na62l0}\input{Parts/trigIntro/existing}
%	\section{Use of GPUs as low level trigger}\input{Parts/GPU/motivation}
	\section{Use of GPUs in triggers}\input{Parts/GPU/motivation}
	\section{The $\boldsymbol{ K^+ \rightarrow \pi^+ \pi^0 }$ background}\label{ch:2body}\input{Parts/trigIntro/pipi0}
	\section{Feasibility study}\input{Parts/MC/feasibility}
	
\chapter{RICH reconstruction}\label{ch:reco}\minitoc\input{Parts/MC/RICHreco}
	\section{Geometric corrections}\label{app:geometry}\input{Parts/MC/geometry}
	\section{Track propagation: upstream magnets}\label{app:magnets}\input{Parts/MC/magnets}
	\section{Reconstruction accuracy}\label{app:rich_res}\input{Parts/MC/resolution}%qui mettere i plot!	
	
\chapter{Trigger characterization}\label{ch:mc}\minitoc
	\label{ch:rejection}\input{Parts/MC/rejection}
	\section{Performance together with the standard L0 trigger}\input{Parts/MC/rich_plus_L0}

\part{Algorithm development and test}\label{part3}

\chapter{``Ptolemy'', a two-step algorithm}\label{ch:tolomeo}\minitoc
	\section{The necessity for a multi-ring algorithm}\label{whymulti}\input{Parts/GPU/ptolemy}
	\section{Reparametrization of the photomultipliers lattice}\label{sect:data-format}\input{Parts/GPU/data_format}
	\section{Pattern recognition}\label{sect:triplets}\input{Parts/GPU/triplets}
	\section{Single-ring fit}\input{Parts/GPU/1ringAlgo}

\chapter{Implementation on GPUs}\label{app:algo-implementation}\minitoc
	\section{GPU architecture and CUDA framework}\label{sect:cuda}\input{Parts/Appendices/cuda_framework}
	\section{Multi-ring algorithm implementation}\label{sect:mr-impl}\input{Parts/Appendices/MR_implementation}
%		\subsection{Implementation of the pattern recognition procedure}\input{Parts/Appendices/triplets_implementation}
%		\subsection{Implementation of the ring fit}\label{app:fit-implementation}\input{Parts/Appendices/fit_implementation}
		\subsection{Implementation of the trigger}\label{sect:trigger-impl}\input{Parts/Appendices/trigger_implementation}
		
\chapter{Tests and conclusions}\label{ch:tests}\minitoc
	\section{Trigger efficiency}\label{ch:results}\input{Parts/GPU/trigger_efficiency}
	\section{Timing tests}\input{Parts/GPU/timing}
	\section{Possible improvements and outlook}\label{sect:improve}\input{Parts/GPU/improvements}
	\section{Conclusions}\input{Parts/GPU/conclu}
	
\bookmarksetup{startatroot}% this is it

%	APPENDIX
\begin{appendices}

\chapter{Ring fitting algorithms}\label{app:fits}\minitoc
	\section{Problem definition}\input{Parts/Appendices/circparam}
	\section{The ``math'' algorithm}\input{Parts/Appendices/math}
	\section{The Taubin algorithm}\label{sect:taubin}\input{Parts/Appendices/taubin}\label{app:taubin-algo}
	
\chapter{CUDA code for the Taubin algorithm}\label{app:taub-code}\input{Parts/Appendices/taubincode}

\chapter{Specifications of the NVIDIA Tesla K20 GPU}\label{app:devicequery}\input{Parts/Appendices/deviceQuery}

\end{appendices}
\selectlanguage{british}

%%	INDICI TABELLE E FIGURE
%\cleardoublepage
%%\newpage
%\addcontentsline{toc}{chapter}{\listfigurename}
%\listoffigures
%
%\cleardoublepage
%%\newpage
%\addcontentsline{toc}{chapter}{\listtablename}
%\listoftables
%
%\cleardoublepage
%%\newpage
%\addcontentsline{toc}{chapter}{\lstlistlistingname}
%\lstlistoflistings

\backmatter

%	BIBLIOGRAPHY
%\input{Parts/biblio}
\cleardoublepage
\bookmarksetup{startatroot}% this is it
\nocite{*}
\phantomsection
\addcontentsline{toc}{chapter}{Bibliography}
%\bibliographystyle{numeric-comp}

% prints author names as small caps
\renewcommand{\mkbibnamefirst}[1]{\textsc{#1}}
\renewcommand{\mkbibnamelast}[1]{\textsc{#1}}
\renewcommand{\mkbibnameprefix}[1]{\textsc{#1}}
\renewcommand{\mkbibnameaffix}[1]{\textsc{#1}}
\printbibliography
%\bibliography{Parts/bibliog}

\cleardoublepage
\phantomsection
%\addcontentsline{toc}{chapter}{Thanks}
%\thispagestyle{plain}
\chapter{Acknowledgements}
I would like to express my gratitude to my supervisor, who has always been available and attentive, and has patiently guided and encouraged me through the steps of my work with many enlightening advices and a maddening attention to spelling and punctuation.

I thank Gianluca Lamanna, whose <<Would it be easy to try this?...>> suggestions I learned to expect and to treasure (and they will probably never stop until the very day of my graduation!).

Thanks to Felice, for his valuable help and company during the long afternoons we spent writing and erasing code in front of the lab PCs.

Thanks to Roberto, Bruno and Jacopo for having always been willing to help me during these long months. My deepest gratitude goes to all of them.

I cannot keep myself from thanking all of my friends. I know that every one of them will bring to themselves and to the people around them the same enjoyable happiness that they have often brought to me.

Thanks to Martina, Alberto, Luigi, Daniele, Leslie, Massimo, Elena, Paola, Marco, Sara, Andrea, Giovanni, Paola, Francesco, and to my dear flatmates Cinzia, Eliana and Irene. I hope my fellow students did not mind that I haunted our department as a thesis-writing ghost all the time. A special mention to Francesco and Luca, my fellow coffee-seeking ghosts!

A heartfelt thought goes to Arianna: our paths split as we left Siena for new adventures, but I know my friend will always be there when I need her.

I take this opportunity to express my profound gratitude to my family, and especially to my parents, that have been a constant source of support during my university years. It is to them that this thesis is dedicated.

Last but not least, my deepest gratitude goes to Salvo. Without his loving support, it would have been much more difficult for me to go through these challenging and sometimes stressful times.
\thispagestyle{empty}
\end{document}