\subsection{TrackCalib package}\label{sec:trackEff-TrackCalib}

The ultimate goal of the track reconstruction efficiency measurement is to measure the ratio $R$ defined in \refEq{trackEff-R}. The ratio obtained directly from the trigger selection can be used by a wide range of \lhcb analyses to correct the track reconstruction efficiencies obtained from the simulation. However, many analyses require a dedicated approach: tighter selection than the one presented here, different detector occupancy measure to weight their simulation sample, special binning in momentum $p$ and pseudorapidity $\eta$ or estimating the track reconstruction efficiency or the ratio $R$ in some other variable. In order to simplify the dedicated measurement of the track reconstruction efficiency tailored to the needs of any analysis, a dedicated tool \TrackCalib has been created and made available to the collaboration in 2017. This \python tool allows to evaluate the track reconstruction efficiency using command line options. In \runI, such customization has not been possible. However, exploiting the stripping lines described in \refSec{trackEff-strip}, these options have been recently extended also to the \runI sample. The tool documentation is available online at~\cite{Twiki-TrackCalib}.

The \TrackCalib package works in three main steps: data preparation, the fit of the data and the plotting of the efficiencies. It is possible to run each step or run all three steps together. The user can decide
\begin{itemize}\setlength{\parskip}{0\baselineskip} 
	\item what method is used
	\item which simulation version is used
	\item whether data, simulation or both are used
	\item whether only one magnet polarity or both are used
\end{itemize}
for the track reconstruction efficiencies or $R$ evaluation. Moreover, the user can decide in dependence on what variables should the efficiency or the ratio $R$ be evaluated. In each of the three steps, additional options can be set.\vspace{\baselineskip}

\subsubsection{Data preparation}\label{sec:trackEff-TrackCalib-prepare}

In the first step of \TrackCalib tool, the dataset used for the tracking efficiency calculation is selected. The full datasample obtained from the trigger lines is rather large (especially in real data) not just due to the large amount of saved events, but also because of many variables being saved. Therefore, a smaller datafile consisting only of relevant variables is created. Additional selection criteria, typically ghost track probability cut, can be set by the user. This criteria can be applied only on the \Probe track, \Tag track or both. The default requirements used by the \TrackCalib are listed in \refTab{trEff-calib}.

\begin{table}
	\begin{center}
		\begin{tabular}[htbp]{c|r|r|r}
			{Variable}		&{\velo method} 	&{\Tstation method}	&{Long method}	\\ \hline  \hline
				\multicolumn{4}{c}{\emph{Tag} selection criteria} \\ \hline
			\dllmupi		&$--$ 			&$--$				&$--$		\\
			\ptot			&$>5\gevc$		&$>7\gevc$			&$>10\gevc$	\\
			\pt				&$>0.7\gevc$	&$>0.5\gevc$		&$>1.3\gevc$	\\ 
	{\rm track}\;\chisqndf	&$<5$			&$<5$				&$<2$		\\ 
			IP				&$--$			&$>0.2\mm$			&$--$		\\ \hline
				\multicolumn{4}{c}{\emph{Probe} selection criteria}   \\ \hline
			\ptot			&$>5\gevc$		&$>5\gevc$			&$>5\gevc$	\\
			\pt				&$>0.7\gevc$	&$>0.1\gevc$		&$>0.1\gevc$	\\ 
	{\rm track}\;\chisqndf	&$--$			&$--$				&$-$		\\ 	 \hline 
				\multicolumn{4}{c}{\jpsi candidates selection criteria}   \\ \hline
 $|m_{\mup\mun}-m_{\jpsi}|$	&$<200\mevcc$	&$<500\mevcc$		&$<500\mevcc$	\\
			\pt				&$--$			&$--$				&$>0\gevc$	\\ 
	{\rm vertex}\;\chisq	&$<5$			&$<5$				&$<5$		\\ 
			Track DOCA		&$--$			&$--$				&$--$		\\ 
			IP				&$-$			&$--$				&$<0.8\mm$	\\ 
		\end{tabular}
		
		\captionof{table}[\TrackCalib selection criteria.]{Selection cuts applied applied to the \Tag track, \Probe track and the reconstructed \jpsi candidate by the default \TrackCalib selection.}
		\label{tab:trEff-calib}
	\end{center}
\end{table}

Moreover, the required overlap fraction needed to associate the tracks can be modified. The variable used for the weighting of the simulation sample can be chosen. Lastly, maximum number of event candidates per method and charge settings\footnote{Simirarly to what is done in the trigger selection, the \TrackCalib tool either uses a \mup track as a \Probe and \mun as a \Tag or the opposite charge configuration.} can be used. The selected dataset is locally stored in order to be readily available for the next two steps.\vspace{\baselineskip}


\subsubsection{Fit execution}\label{sec:trackEff-TrackCalib-fit}

In this part of the \TrackCalib tool, the previously created dataset is divided based on the selected variables. The user can decide what binning in the desired variables is used\footnote{This can be done both by requiring a certain number of bins with the same width or by specifying the bin edges.}. In the case of low statistics sample, instead of performing a simultaneous fit to the matched and failed \jpsi candidates, as explained in \refSec{trackMeas-tag-and-probe}, a fit to the matched and \emph{all} \jpsi candidates is performed. Due to very high track reconstruction efficiency, the failed sample has very little signal component (see \refFig{trEff-mass}): by avoiding the fit to the failed sample, the fit stability improves. To further improve the fit stability, the Crystal Ball function used to describe the signal component can be replaced by a sum of two Gaussian distributions. Lastly, the user can also execute an ubinned fit to the \jpsi mass.

For each method and each variable bin, a dedicated file containing the calculated efficiency as well as the fitted distribution is saved. Moreover, an output file is created, where the fit status and the fitted parameter values are saved. For user's convenience, another warning file is created, where only failed fit statuses and variables with large or zero uncertainty are saved. This allows for quick recongnition of failed fits.

\subsubsection{Plotting}\label{sec:trackEff-TrackCalib-plot}

Last part of the \TrackCalib tool is the plotting of the track reconstruction efficiency dependency plots and the creation of correction tables: the \root files (the correction tables), where the ratio $R$ is saved in bins of the desired variables (the default is pseudorapidity and momentum). In this step, the three methods are also combined into the Combined and Final methods. 


\subsubsection{Simulation samples}\label{sec:trackEff-centralProd}

In order to apply the tag-and-probe method on the simulated sample, several sets of the decay \decay{\Bu}{\jpsi(\to\mumu)X}, where $X$ is any particle, are created. These simulated samples are then treated the same way as the record data. In order to correct the difference between the simulation and the data in the occupancy, weights based on the number of hits in the \spd are applied.

The \lhcb software is constantly evolving and improving. Therefore, it is important to evaluate the track reconstruction efficiency correctly for each version of the software. The available simulation samples used in \TrackCalib for each data taking year are listed in \refTab{trEff-sim}. 

\begin{table}
	\begin{center}
		\begin{tabular}[htbp]{l|l}
			{year}		&{Simulation versions}	\\ \hline 
			2015\,(EM)    & Sim08h,  Sim09b    \\
			2015	 	  & Sim09a,  Sim09b    \\
			2016	  	  & Sim09a,  Sim09b,  Sim09d    \\
			2016\,(strip) & Sim09h    \\
			2017		  & Sim09h    \\
			2017\,(strip) & Sim09h    \\
			2018	      & Sim09h \\  
			2018\,(strip) & Sim09h    \\			
		\end{tabular}
		
		\captionof{table}[Available simulation samples for the track reconstruction efficiency measurements.]{Available simulation samples for the track reconstruction efficiency measurements. In the first months of data taking in 2015, the settings of the machine were different to the rest of the year. This sample is denoted \emph{early measurements} (EM). Samples produced using the stripping selection instead of the trigger selection are denoted as (strip).  }
		\label{tab:trEff-sim}
	\end{center}
\end{table}



