\subsection{Trigger selection}\label{sec:sel-TriggerSelection}

The selection of events begins at the hardware level, as described in \refSec{det_trig}. %The \BuToKstmm candidate events have to pass both stages of the trigger. %While the trigger selection is very similar in \runI and \runII, there are small differences at the high-level trigger level. 
As a first step, the \BuToKstmm candidate event has to be triggered by the L0 trigger by identifying a single muon. In \hltone, the event has to be triggered either by a single detached high \pt track~\cite{ANA-SingleTrackTrig} or a muon~\cite{ANA-MuonTrig}.  In \hlttwo, the events have to pass several topological criteria~\cite{ANA-HLT2Topo} or pass a tighter muon track cut.  In \runII, the requirement on a single detached high \pt muon in \hltone is replaced by a more efficient kinematic cut applied on all tracks. Moreover, topological trigger selection algorithms, or lines, using two muons as input are exploited. The full list of \lhcb trigger lines used for this analysis is presented in \refTab{presel_trigList}. For detailed description of \runI trigger lines see~Ref.\,\cite{ANA-TrigAll}.

\begin{table}[hbt!]
    \centering
    \begin{tabular}{l|l}
        \lone 	& L0Muon \\ \hline
        \hltone & Hlt1TrackAllL0 (\runI) \\
                & Hlt1TrackMVA (\runII)\\
                & Hlt1TrackMuon\\ \hline
        \hlttwo & Hlt2TopoMu2BodyBBDT\\
                & Hlt2TopoMu3BodyBBDT\\
                & Hlt2Topo2BodyBBDT\\
                & Hlt2Topo3BodyBBDT\\
                & Hlt2DiMuonDetached\\
                & Hlt2TopoMuMu3BodyBBDT (\runII)\\
                & Hlt2TopoMuMu2BodyBBDT (\runII)
        
        
    \end{tabular}
\captionof{table}[List of applied trigger selection requirements.]{List of applied trigger requirements. For a detailed definitions of the applied trigger selection algorithms see~Ref.\,\cite{ANA-TrigAll}. \label{tab:presel_trigList}}
\end{table}

The trigger decision can be either \emph{triggered on signal} (TOS) or \emph{triggered independent of signal} (TIS). That means that if the event is TOS, the signal candidate directly affected the trigger decision, while TIS means that the trigger decision is driven by a different element of the event. The simulation of TIS events is rather complicated. As the contribution of the \Bu meson TIS decisions to the signal candidates is negligible, only the \Bu meson TOS decisions are used in this analysis.

\subsection{Central selection (stripping)}\label{sec:sel-StrippingSelection}

As the trigger requires events to pass only basic topological and kinematical constrains, it is necessary to filter the events selected by the trigger lines further. Due to the size of the dataset and due to computational constraints, an additional central selection is applied. This process is called \emph{stripping} and one set of selection algorithms within stripping is called a \emph{line}. Typically, a stripping line is used by several analyses, hence the selection is still rather loose at this step.

%\url{http://lhcbdoc.web.cern.ch/lhcbdoc/stripping/config/stripping34r0p1/leptonic/strippingb2xmumu_line.html}

The cuts applied in the stripping line used in this analysis are summarized in \refTab{stripping_cuts}. Most of the requirements are kinematical, however several more specific properties of the candidates are exploited:

\begin{itemize}
	\item \texttt{IsMuon} requires a track to penetrate through the detector up to the muon stations. This reduces the probability of misidentifying a hadron as a muon to 1\% while maintaining high efficiency of muon reconstruction~\cite{ANA-IsMuon}. Depending on the momentum of the track, hits in different muon stations are required. The summary of the required hits based on the track momentum is in \refTab{IsMuon}.
	%	
	\stepcounter{table}
	\begin{table}[hbt!]
		\centering
		\begin{tabular}{r|c}%In order to reference it after the stripping cuts table
			track momentum 			    & muon stations hit requirement\\\hline
			$3\gev < p_\mu < 6\gev$ 	& M2 and M3 \\
			$6\gev < p_\mu < 10\gev$ 	& M2 and M3 and (M4 or M5)\\
			$ p_\mu > 10\gev$ 			& M2 and M3 and M4 and M5 \\
		\end{tabular}
		
		\captionof{table}[Muon stations required to trigger the IsMuon decision.]{Muon stations required to trigger the IsMuon decision as a function of momentum range. Taken from~Ref.\,\cite{ANA-IsMuon}. \label{tab:IsMuon}}
	\end{table} \vspace{15pt}
	
	\begin{figure}[hbt!]
		\centering
		\includegraphics[width=0.7\textwidth]{./AnalysisSelection/IP_definition3.png}
		\captionof{figure}[The impact parameter definition.]{The impact parameter definition in the specific case of \BuToKstmm. For readers convenience, the \emph{DIRA} angle of the \Bu meson is also shown.} \label{fig:ANA-IP-def}
	\end{figure}
	
	\item Using the established \lhcb convention in notation, impact parameter (IP) is the transverse distance of closest approach between a particle trajectory and a vertex.  A naive sketch of this quantity is shown in \refFig{ANA-IP-def}.
	
	\item \emph{DIRA} angle (direction angle) is the angle between the reconstructed momentum of the particle and the line joining the primary vertex and the \Bu decay vertex. The \Bu meson DIRA angle is shown in \refFig{ANA-IP-def}.
	
	\item Despite \lhcb convention in notation, $\chisq_{FD}$ is not exactly the $\chisq$ of the flight distance, but the \chisq of separation of two vertices. It is calculated as the $\chisq$ of the common vertex of all tracks minus the sum of $\chisq$ for two distinct vertices.
	

	\item At \lhcb, the particles fly through the dipole magnet. Tracks are reconstructed from hits downstream and upstream of the magnet. Due to this 'gap' in the detector, the algorithm matching the tracks from subdetectors downstream and upstream of the magnet might reconstruct a track, which is not induced by a real particle flying through \lhcb. These fits have typically low track fit quality. Such tracks are called \emph{ghosts}. A dedicated variable related to the track fit quality with values between 0 and 1, \emph{ghost probability}, is assigned to each track and represents the possibility of the track being a \emph{ghost} track.
	
\end{itemize}

\addtocounter{table}{-2} %In order to reference it before the muon stations table
\begin{table}[hbt!]    \centering
	\begin{tabular}{c|c}
		candidate			&selection\\ 
		\hline\hline
		\Bpm 		&4700\mev $<$ m(\Bpm) $<$ 7000\mev\\
		& $\sum_{i\in daughters}\text{daughter charge} < 3$\\ %Sum of charge of particles <3
		&\chisqvtxndf $<$ 8 \\
		&\chisqip $<$ 16 (best PV) \\
		&DIRA angle $<$ 14\mrad\\
		&$\chisq_{FD}>$ 64\footnotemark[1]\\ 
		&min(\chisqip)$>$ 9.0\\
		\hline
		\mupm		&\pt$>$250\mev\\
		&track \textit{ghost prob} $<$ 0.5\\
		&min(\chisqip)$>$ 6.0\footnotemark[2]\\
		&\dllmupi $>$-3\footnotemark[3]\\
		\hline	
		\mup\mun		& $m(\mup\mun)<$ 7100\mev\footnotemark[4]\\
		& \chisqvtxndf $<$ 12\\
		& DIRA angle $\in (2.69\rad,3.59\rad)$ \\
		&min(\chisqip)$>$ 6.0\footnotemark[5]\\
		& flight distance $\chisq> 9.0$\\                    
		&\texttt{isMuon} \\
		\hline
		\Kstarpm		& 592\mev $<$ m(\Kstarpm) $<$ 1192\mev \\
		\hline
		$K^+$   		& track \textit{ghost prob} $<$ 0.5\\ %check 
		& min(\chisqip)$>$ 6.0\\
		&\texttt{hasRich}\footnotemark[6]\\
		\hline
		$\pi^0$ 		&105\mev $<$ m(\piz) $<$ 165\mev \\
		&$\pt(\piz)>800\mev$\footnotemark[7]\\
		\hline     
		$\gamma$		& $\pt(\g)>$200\mev\\
		% & CL(\g)$>$-99.0\\
		\hline                    
		GEC     		& nSPDHits$<$600  \\		
		& at least one PV \\
		
	\end{tabular}
	\begin{multicols}{2}
		\begin{itemize} \footnotesize\setlength{\parskip}{-2pt} 
			\item [$^1$] In S21r0p1 and S29r2 \chisq $>$ 121.
			\item [$^2$] In S21r0p1 and S29r2 min(\chisqip)$>$ 9.0.
			\item [$^3$] For definition see \refSec{det_RICH}.
			\item [$^4$] Only in S24r2, S28r2 and S34r0p1.
			\item [$^5$] In S21r0p1 and S29r2 min(\chisqip)$>$ 9.0.
			\item [$^6$] RICH subsystem registered a track in the candidate event.
			\item [$^7$] In S21r0p1, $\pt(\piz)>700\mev$.	
		\end{itemize}
	\end{multicols}
	
	\captionof{table}[Central selection (stripping) cuts.]{Central selection (stripping) cuts for the \texttt{B2XMuMu} line. For each data-taking year, there is a dedicated version of the software. The stripping cuts slightly differ between different version of the software: S21r1p2\,(2011), S21r0p1\,(2012), S24r2\,(2015), S28r2\,(2016), S29r2\,(2017) and S34r0p1\,(2018). \label{tab:stripping_cuts}}
\end{table}


