\subsection{Quick guide to running \texttt{BeamHNL} in \texttt{GENIE}} \label{appdx: code}
A \textcolor{red}{fork} of \verb|GENIE| with the \verb|BeamHNL| module implementation may be found on GitHub \cite{HNLGENIE}.
The configuration file has been designed with ease-of-use in batch jobs, such as might be submitted to a computing grid, in mind.
For this reason, there exists a single file \verb|config/CommonHNL.xml| which houses all the options that the module's components need to know about in order to simulate the HNL production, propagation, and decay.
A sample file may be found in \verb|src/contrib/beamhnl|, and explanations for the various options are available in \verb|config/NHLPrimaryVtxGenerator.xml|.
In this section, we will briefly outline the main components.
\begin{itemize}
    \item \verb|ParameterSpace| defines $M_{\textrm{N}4}$ in $\text{GeV}/c^{2}$, $\{\left|U_{\alpha 4}\right|^{2}\}$, and Dirac vs. Majorana nature of the HNL.
    \item \verb|InterestingChannels| enumerates the 10 decay channels (the 7 summarised in Table \ref{tab: decayChannels} and $N_{4} \rightarrow \pi^{\pm}\pi^{0}\ell^{\mp}, \pi^{0}\pi^{0}\nu$) kinematically accessible to an HNL below the kaon mass. Entries set to \verb|false| will be inhibited from entering the event record, whereas \verb|true| entries are treated as valid truth signal channels.
    \item \verb|CoordinateXForm| defines the unique translation and rotation vectors $\boldsymbol{T}, \boldsymbol{R}$ from NEAR to BEAM and from NEAR to USER coordinates. $\boldsymbol{T}$ is given in metres, with respect to the NEAR system, and $\boldsymbol{R}$ is a vector of 3 Euler angles, following the ``extrinsic $X-Z-X$" convention; that is, the rotation matrix $R$ is given as
    \begin{equation}
        R(\alpha,\beta,\gamma) = R_{\textrm{X}}(\alpha)R_{\textrm{Z}}(\beta)R_{\textrm{X}}(\gamma),
    \end{equation}
    where $X,Y,Z$ are the fixed NEAR axes.
    \item \verb|FluxCalc| provides switches for the user to enable/disable certain features; namely, the module's polarisation accept/reject weight, and whether the simulation should evaluate Eq. \ref{eq: acceptance_correction} assuming the parent to be perfectly focused (setting $\zeta_{+}$ to one-half the detector's angular opening, and $\zeta_{-} = 0$)
\end{itemize}
For the purposes of running this module, an input \verb|dk2nu|-like flux ROOT flat-tree and a ROOT geometry file describing the detector are required.
Sample inputs that are module-compliant are supplied along with the source code in \verb|src/contrib/beamhnl| for the user to be able to run the module immediately.
\par A folder \verb|flatDk2nus| contains two flat ROOT trees, corresponding to one \verb|dk2nu| flux file from NuMI in neutrino mode, and one in antineutrino mode \cite{NuMIBeamFlux}.
It also contains scripts to produce ROOT flat-trees from \verb|dk2nu| flux files.
These flat-trees can then be used as input of the \verb|BeamHNL| module.
Detailed instructions on how to generate these are written in the \verb|README| file located inside the folder. \\
Three ROOT macros \verb|makeBox.C|, \verb|makeCylinder.C|, and \verb|makeHexagon.C| along with three respective outputs are also inside the \verb|contrib/beamhnl| directory, which allow the user to make three different ROOT geometries of arbitrary dimensions and rotation with respect to the USER coordinate system. \\
To enable the \verb|BeamHNL| module, the user must first configure \verb|GENIE| appropriately by adding the following line to the \verb|configure| script (an example can be seen at the \verb|GENIE| website \cite{GENIEWebsite}):
\begin{center}
\verb|--enable-heavy-neutral-lepton \ |
\end{center}
After running \verb|make|, the \verb|BeamHNL| module is ready.
The archetypal run command is
\begin{center}
\verb|gevgen_hnl -n <nSignalEvents>| \verb|-f <path/to/flux/dir> -g <path/to/geom/file.root>|
\end{center}
Detailed instructions can be referred to by passing the \verb|-h| flag.

\subsection{HNL production and decay rates} \label{appdx: QM}
The available production channels for an HNL with mass $M_{\textrm{N}4} \lesssim m_{\textrm{K}}$ are summarised in Table \ref{tab: prodChannels}.
\footnote{
Throughout this section, we will engage in a mild abuse of notation and write down such expressions as $K^{\pm} \rightarrow N_{4} + \mu^{\pm}$.
The reader will notice that $N_{4}$ has been defined in Eq. \ref{eq: fourth_nu_mixing} as a \emph{mass eigenstate}, rather than a flavour eigenstate.
In order to shorten notation, we will sacrifice formal correctness (i.e. $K^{\pm} \rightarrow \nu_{\mu} + \mu^{\pm},\,\,\nu_{\mu} = \sum_{i}U_{\mu i}\nu_{i} + U_{\mu 4}N_{4}$) and directly concentrate on the mixed-in element $U_{\alpha 4}N_{4}$, hoping that the implied association does not cause confusion.
}
For each channel, the threshold, kinematic scaling $\mathcal{K}$ and SM branching ratio are listed.
The kinematic scaling $\mathcal{K}$ is defined through the decay width as in Eq. \ref{eq: kineScaling}
\begin{equation}
    \Gamma\left(P \rightarrow N_{4} + \ell_{\alpha} + ...\right) = \left|U_{\alpha 4}\right|^{2}\mathcal{K}\cdot\Gamma\left(P \rightarrow \nu + \ell_{\alpha} + ...\right)
\end{equation}
The decay width is then, for a given channel, written as
\begin{equation}
    \Gamma\left(M_{\textrm{N}4},|U_{\alpha 4}|^{2}\right) = \mathcal{K}\left(M_{\textrm{N}4}\right)\cdot|U_{\alpha 4}|^{2},
\end{equation}
For each parent species ($\pi^{\pm}, K^{\pm}, K^{0}_{\textrm{L}}, \mu^{\pm}$) a series of scores $\{s_{i}\}, s_{i+1} = s_{i} + \Delta s$ is constructed, which is then used to determine the production channel for the HNL.
The scores are calculated as
\begin{equation}
    \Delta s = \frac{\mathfrak{B}_{\text{channel}}}{\mathfrak{B}_{\text{tot}}},
\end{equation}
where $\mathfrak{B}_{\text{tot}}$ is the sum of $\mathfrak{B}_{\text{channel}}$ over all kinematically accessible HNL production channels (see \ref{tab: decayChannels}).
The following definitions are used for the case of 2-body HNL production \cite{Shrock1981}:
\begin{subequations}\label{eq: scores}
\begin{eqnarray}
    \delta(m,M) &\equiv& \delta_{M}^{m}:= \frac{m^{2}}{M^{2}},
    \\
    \lambda(x,y,z) &:=& x^{2} + y^{2} + z^{2} - 2(xy + yz + zx), \label{eq: kallen}
    \\
    f_{m}(x,y) &:=& x + y - (x-y)^{2},
    \\
    \rho(x,y) &:=& f_{m}(x,y)\cdot\lambda^{1/2}(x,y,1),
    \\
    \mathcal{P}_{\ell}(x,y) &:=& \frac{\rho(x,y)}{x(1-x)^{2}}.
\end{eqnarray}
\end{subequations}
Calculations of the three-body HNL scaling factor for production have been done in the literature.
We have used the helicity-summed scaling factors reported in \cite{Ballett2020} to construct through interpolation a scaling function $\mathcal{S}_{\textrm{P}\ell}$, with $P = K^{\pm}, K^{0}_{\textrm{L}}$ and $\ell = e,\mu$.
For the special case of muon decay to HNL, we start from the known decay $\mu^{\pm} \rightarrow \nu_{\mu}\nu_{e}e^{\pm}$ and then ``promote" either the $\nu_{\mu}$ or $\nu_{e}$ to HNL, depending on the mixings $|U_{\textrm{e}4}|^{2}, |U_{\upmu 4}|^{2}$.
\begin{figure}
    \centering
    \includegraphics[width=\linewidth]{Images/betterFeynman.pdf}
    \caption{Feynman diagrams for the decay $N_{4} \rightarrow \pi^{\pm}+\pi^{0}+\ell^{\mp}$.}
    \label{fig:pipi0ell}
\end{figure}
\par We adopt the HNL decay widths in the context of an effective field theory describing interactions of HNL with mesons, as detailed in \cite{ColomaDUNEHNL}.
For the double-pion channels $N_{4} \rightarrow \pi^{\pm}\pi^{0}\ell^{\mp}, \pi^{0}\pi^{0}\nu$, whose thresholds for emission lie below the kaon mass, the decay widths in the literature have been noted to be dominated by the chain involving the emission of an on-shell $\rho$.
Because $m_{\uprho} > m_{\textrm{K}}$, this argument cannot be applied in the case $M_{\textrm{N}4} < m_{\textrm{K}}$, and it is necessary to perform an explicit calculation to estimate the decay width resulting from double-pion channels.
To that effect, we have used the Lagrangian for Dirac particles, made public by the authors of \cite{ColomaDUNEHNL} in the \verb|FeynRules| model database \cite{FeynRulesWebsite}, and extracted the double-differential decay rate over final-state particle energies using \verb|FeynRules| \cite{FeynRulesManual}, \verb|FeynArts| \cite{FeynArts} and \verb|FeynCalc| \cite{FeynCalc1, FeynCalc2, FeynCalc3}.
The resulting expression for the two-dimensional $\textrm{d}^{2}\Gamma/\textrm{d}E_{\uppi}\textrm{d}E_{\ell}$ depends on the energy of the $\pi^{0}$ due to energy conservation in the HNL rest frame.
Therefore, the integrated decay rate is obtained in runtime by numerically integrating the differential decay rate.
\par As can be seen from the relevant tree-level Feynman diagrams in Fig. \ref{fig:pipi0ell}, the decay $N_{4} \rightarrow \pi^{+}\pi^{0}\ell^{-}$ is mediated by both light and heavy neutrinos.
Compared to the left-hand diagrams, the right-hand diagram where $N_{4}$ enters both pion vertices is suppressed by a factor $\left|U_{\alpha 4}\right|^{2}/\left|U_{\alpha i}\right|^{2} \ll 1$, and is safely ignored.
\par For the $\pi^{0}\pi^{0}\nu$ diagrams, the intermediate propagator is always a $N_{4}$, which renders the entire channel's decay width subleading to $\pi^{\pm}\pi^{0}\ell^{\mp}$.
\par Comparing $N_{4} \rightarrow \pi^{\pm}\pi^{0}\ell_{\alpha}^{\pm}$, the $\alpha = e$ case has a larger decay width due to the larger phase space available to the final state.
The result is
\begin{equation}
    \frac{\Gamma\left(N_{4}\rightarrow\pi^{+}\pi^{0}e^{-}\right)}{\sum_{\text{all lighter channels}}\Gamma} \lesssim 10^{-11},
\end{equation}
confirming the argument that the essential process for double-pion production is decays of HNL into on-shell $\rho$.
The calculation proceeds similarly for Majorana HNL.
\par To conserve computing time, we only simulate those channels that the user has explicitly defined in the configuration file as being ``interesting" as a signal.
For each run of the module, a C++ \verb|std::map<HNLDecayMode_t, double>| is constructed which contains the accessible and interesting channels and their decay widths.
These are then used to construct scores similarly to Eq. \ref{eq: scores}, after which a standard Monte Carlo transformation method \cite{NumericalRecipes3rd} maps a uniform random number to a decay channel and fills the appropriate decay product list for use with \verb|GENIE|'s phase-space generator.
\par To calculate the decay rates, we make use of the following definitions found in \cite{ColomaDUNEHNL}:
\begin{subequations}
\begin{eqnarray}
    &B_{1}& := \frac{1}{4}\left(1 - 4\sin^{2}\theta_{\textrm{W}} + 8\sin^{4}\theta_{\textrm{W}}\right),
    \\
    &B_{2}& := \frac{1}{2}\sin^{2}\theta_{\textrm{W}}\left(2\sin^{2}\theta_{\textrm{W}} - 1\right),
    \\
    &\mathcal{C}_{\alpha}\left(M_{\textrm{N}4}\right)& := \sum_{\alpha}|U_{\alpha 4}|^{2}\cdot\big[F_{1}\left(m_{\alpha}/M_{\textrm{N}4}\right)B_{1}
    \\
    \nonumber &&+ F_{2}\left(m_{\alpha}/M_{\textrm{N}4}\right)B_{2}\big],
    \\
    &\mathcal{D}_{\alpha}\left(M_{\textrm{N}4}\right)& := |U_{\alpha 4}|^{2}\sin^{2}\theta_{\textrm{W}}
    \\
    \nonumber &&\times \left[2F_{1}\left(M_{\textrm{N}4}\right) + F_{2}\left(M_{\textrm{N}4}\right)\right],
    \\
    &\mathcal{G}\left(x,y\right)& := \lambda^{1/2}\left(x,y,1\right)
    \\
    \nonumber &&\times \left[1-y^{2} - x^{2}(2-x^{2}+y^{2})\right],
    \\
    &F_{1}(x) =& (1 - 14x^{2} - 2x^{4} - 12x^{6})\sqrt{1 - 4x^{2}}
    \\
    \nonumber &&+ 12x^{4}(x^{4}-1)L(x),
    \\
    &F_{2}(x) =& 4x^{2}(2 + 10x^{2} - 12x^{4})\sqrt{1 - 4x^{2}}
    \\
    \nonumber &&+ 24x^{4}(1 - 2x^{2} + 2x^{4})L(x),
    \\
    &L(x) =& \ln\left[\frac{1 - 3x^{2} - (1-x^{2})\sqrt{1 - 4x^{2}}}{x^{2}\left(1 + \sqrt{1 - 4x^{2}} \right)}\right],
\end{eqnarray}
\end{subequations}
where $\theta_{\textrm{W}}$ is the Weinberg mixing angle, and $\lambda(x,y,z)$ is the K\"{a}ll\'{e}n function defined in Eq. \ref{eq: kallen}.

\subsection{Coordinate systems} \label{appdx: coords}
\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{Images/extrinsicEuler.pdf}
    \caption{Extrinsic Euler rotations. The fixed system $(X,Y,Z)$ is rotated to the new system $(X_{\textrm{U}}, Y_{\textrm{U}}, Z_{\textrm{U}})$ by applying successive rotations first about $X$ (green), then about $Z$ (blue), and finally about $X$ again (red).}
    \label{fig:eulerAngles}
\end{figure}
A general detector can be both displaced and rotated arbitrarily with respect to the NEAR frame.
One can parametrise any such configuration by two vectors: one translation and one rotation.
We have made the choice to use extrinsic Euler angles to write rotations (see Fig. \ref{fig:eulerAngles}): that is, the rotation matrix describing the transition between two coordinate systems $(X, Y, Z), (X_{\textrm{U}}, Y_{\textrm{U}}, Z_{\textrm{U}})$ centred around the same point is written as
\begin{align}
\begin{split}
    &R(\alpha, \beta, \gamma) = \\
    &= R_{\textrm{X}}(\gamma)R_{\textrm{Z}}(\beta)R_{\textrm{X}}(\alpha) \\
    &= \begin{pmatrix} 1 &0 &0 \\ 0 &c_{\gamma} &-s_{\gamma} \\ 0 &s_{\gamma} &c_{\gamma} \end{pmatrix} \begin{pmatrix} c_{\beta} &0 &-s_{\beta} \\ 0 &1 &0 \\ s_{\beta} &0 &c_{\beta} \end{pmatrix} \begin{pmatrix} 1 &0 &0 \\ 0 &c_{\alpha} &-s_{\alpha} \\ 0 &s_{\alpha} &c_{\alpha} \end{pmatrix} \\
    &= \begin{pmatrix} c_{\beta} &-s_{\alpha}s_{\beta} &-c_{\alpha}s_{\beta} \\ -s_{\beta}s_{\gamma} &c_{\alpha}c_{\gamma} - c_{\beta}s_{\alpha}s_{\gamma} &-c_{\gamma}s_{\alpha} -c_{\alpha}c_{\beta}s_{\gamma} \\ c_{\gamma}s_{\beta} &c_{\beta}c_{\gamma}s_{\alpha} + c_{\alpha}s_{\gamma} &c_{\alpha}c_{\beta}c_{\gamma} - s_{\alpha}s_{\gamma} \end{pmatrix},
\end{split}
\end{align}
using $c_{\theta}, s_{\theta} \equiv \cos\theta, \sin\theta$.

\subsection{Bookkeeping} \label{appdx: book}
There are a certain number of quantities that must be kept track of during the simulation in order to correctly estimate the number of signal events, given a detector volume and number of protons on target \footnote{By ``protons on target" we will account for the mean number of POT for a single HNL decay to \emph{signal} event. This information is calculated taking the input detector volume and beamline simulation; different inputs will yield different outputs.}.
These can be summarised in Fig. \ref{fig:POT_map}; we shall explain the steps taken forthwith.
\par Suppose that the user has selected a channel $C$ as the channel of interest for a particular detector; for example, $N_{4} \rightarrow \mu^{-} \pi^{+}$.
We work our way backwards in order to obtain, \textit{for each signal event}, an estimate of the number of POT $N_{\text{POT}}$ that would result in one signal event occurring in the detector, and return this estimate as a weight attached to the \verb|EventRecord| describing the signal event, which makes POT counting a straightforward loop on the analysis side.
\par First to be obtained is the expected number of \emph{total} HNL decays occurring in the detector, signal or not (for example, invisible decays $N_{4} \rightarrow \nu\nu\nu$ are almost never going to be considered signal events due to the inability to detect neutrinos in the final state directly), as
\begin{equation}
    N_{H} = \frac{\sum_{i \in\text{all channels}}\Gamma_{i}}{\Gamma_{C}} \equiv \frac{\Gamma_{\text{tot}}}{\Gamma_{C}}.
\end{equation}
One then takes the detector geometry into account, by considering the HNL's lifetime $\tau = \hbar/\Gamma_{\text{tot}}$ and requiring that the HNL decays inside the detector volume.
Suppose a beam of HNL of rest-frame lifetime $\tau$ and velocity $\beta c$ propagates along the $z$ axis, and the detector volume is in between the planes $z = z_{1}$ and $z = z_{2}$.
The probability distribution for the HNL decay location is
\begin{equation}
    p(z) = \frac{1}{\widetilde{N}}\exp\left(-\frac{z}{\beta c \gamma\tau}\right),
\end{equation}
where $\widetilde{N}$ is some normalisation constant.
The probability of decay inside the detector is then
\begin{equation}
    P\left(z_{1} \leq z_{\text{decay}} \leq z_{2}\right) = \int_{z_{1}}^{z_{2}}\textrm{d}u\,p(u)
\end{equation}
which yields
\begin{align} \label{eq: survival}
\begin{split}
    P &= \frac{\beta\gamma c\tau}{\widetilde{N}}\exp\left(-\frac{z_{1}}{\beta\gamma c\tau}\right)\left[1 - \exp\left(-\frac{z_{2}-z_{1}}{\beta\gamma c\tau}\right)\right] \\
    &= P(\text{arrival}) \cdot P(\text{decay} | \text{arrival}).
\end{split}
\end{align}

\begin{widetext}
\begin{figure*}
    \setlength{\belowcaptionskip}{-5pt}
    \centering
    \includegraphics[width=\textwidth]{Images/POT_map.pdf}
    \caption{Sequence for estimating number of POT for each event, working backwards. See text for definitions.}
    \label{fig:POT_map}
\end{figure*}
\end{widetext}

\begin{figure}
    \setlength{\belowcaptionskip}{-1pt}
    \centering
    \includegraphics[width=0.48\textwidth]{Images/genie_angdeviation.pdf}
    \caption{Calculation of deviation angles $\zeta_{\mp}$. The parent's momentum $\boldsymbol{p}_{\textrm{P}}$ is projected to the point $\textrm{V}_{0}$ such that $z_{\textrm{V}0} = z_{\textrm{C}}$, with $\textrm{C}$ the centre of the detector. The entry and exit points $\textrm{V}_{\mp}$ lie on the line $\epsilon: \boldsymbol{r}(u) = \boldsymbol{r}_{\textrm{V}0} + u\cdot\boldsymbol{\delta}$, where $\boldsymbol{\delta}$ is a sweep direction: $\boldsymbol{\delta} := \boldsymbol{r}_{\textrm{C}} - \boldsymbol{r}_{\textrm{V}0}$. The angles $\zeta_{\mp}$ are $\langle\boldsymbol{r}_{\mp}, \boldsymbol{p}_{\textrm{P}}\rangle$.}
    \label{fig:deviation}
\end{figure}
Equation \ref{eq: survival} states that the HNL must first survive long enough to reach the detector, and then decay promptly while inside it.
\par We can generalise this to the full 3D picture.
Let D, E, and X be the HNL production point, and the intersections of its trajectory with the detector at entry and exit, respectively.
Then for every $N_{\textrm{P}}$ HNL emitted that could be accepted, $N_{\textrm{A}}$ will survive until the detector, and $N_{\textrm{H}}$ will decay without exiting the detector.
These quantities are straightforwardly obtained :
\begin{equation}\label{eq: lifetimeWeight}
    N_{\textrm{A}} = N_{\textrm{H}}\cdot\exp\left(\frac{\ell}{\beta c \gamma \tau}\right),
\end{equation}
\begin{equation}
    N_{\textrm{P}} = N_{\textrm{A}}\cdot\exp\left(\frac{L}{\beta c \gamma \tau}\right)
\end{equation}
where $\ell, L$ are the distances $|\boldsymbol{r}_{\textrm{X}} - \boldsymbol{r}_{\textrm{E}}|, |\boldsymbol{r}_{\textrm{D}} - \boldsymbol{r}_{\textrm{E}}|$.
\par Next, we factor in those HNL that decayed before reaching the detector volume to get the total number $N_{\textrm{P}}$ of HNL produced in the accepted region, using once again Eq. \ref{eq: lifetimeWeight} but substituting $\ell = |\boldsymbol{r}_{\textrm{X}} - \boldsymbol{r}_{\textrm{E}}|$ for $L = |\boldsymbol{r}_{\textrm{E}} - \boldsymbol{r}_{\textrm{D}}|$.
\par Further backward, we have the estimate of acceptance; only those HNL emitted in the correct angular region would intersect the detector.
It is assumed that the decays of parents are isotropic in the parents' rest frame, which is correct for pseudoscalar mesons ($\pi^{\pm}, K^{\pm}, K^{0}$).
Furthermore, the detector is assumed to be sufficiently far away that the small angle approximation $\sin\theta \simeq \theta$ is valid.
The size and position of the detector defines a window in the observer's frame, which is then transformed into a rest-frame window using the collimation-effect function $f:[0,\pi]\rightarrow[0,\pi]$ described in Fig. \ref{fig:collimation}.
The lab-frame emission angle can be interpreted as an angular deviation of the HNL's trajectory from the parent's momentum.
The angular size of the detector is given by $\zeta_{+} - \zeta_{-}$, where the angles $\zeta_{\mp}$ are the minimum and maximum deviation angles for which the HNL's trajectory can intersect the detector.
Figure \ref{fig:deviation} shows how these deviation angles are calculated.
A ``sweep direction" $\boldsymbol{\delta}$ is constructed from the parent's momentum $\boldsymbol{p}_{\textrm{P}}$ and the detector centre C, and the points of entry $\textrm{V}_{-}$ and exit $\textrm{V}_{+}$ along this sweep are obtained, giving the deviation angles as the angles between the parent momentum and the vectors $\boldsymbol{r}_{-}, \boldsymbol{r}_{+}$.
\par We thus estimate the acceptance correction $\mathcal{A}$ induced by the collimation effect of HNL becoming dominated by their parent's Lorentz boost, as
\begin{equation}\label{eq: acceptance_correction}
    \mathcal{A} = \frac{|\mathcal{I}_{\textrm{N}4}|}{|\mathcal{I}_{\nu}|},
\end{equation}
where $\mathcal{I}$ is the pre-image under $f$ of the angular opening $[\zeta_{-},\zeta_{+}]$.
Especially for large HNL masses, it is often $\mathcal{I}_{\textrm{N}4} = \mathcal{I}_{\textrm{F}} \sqcup \mathcal{I}_{\textrm{B}}$ where $\mathcal{I}_{\textrm{F},\textrm{B}}$ are the forward and backward angular regions where HNL can be accepted.
One can contrast this with the case of light neutrinos, where $f$ increases monotonously and only forward emitted neutrinos can reach the detector.
In the end, the number of total HNL emitted (``ancestry events") is given by
\begin{equation}
    N_{\textrm{C}} = \frac{N_{\textrm{P}}}{\sum_{\alpha=\textrm{e},\upmu,\uptau}\left|U_{\alpha 4}\right|^{2}}\cdot \frac{1}{\omega_{\text{det}}\mathcal{B}^{2}\mathcal{A}},
\end{equation}
where $\mathcal{B}, \mathcal{A}$ were defined in Eqs. \ref{eq: boostFactor}, \ref{eq: acceptance_correction} and $\omega_{\text{det}}$ is the angular size of the detector in the lab frame, with $D$ at the origin.
The angular size of the detector in the parent's rest frame is then $\omega_{\text{det}}\mathcal{B}^{2}$, assuming its face is roughly perpendicular to the parent momentum; the acceptance correction $\mathcal{A}$ parametrises the intrinsic increase of the probability that a randomly chosen direction for HNL emission will be boosted such that the HNL gets accepted.
The prefactor $(\sum |U_{\alpha 4}|^{2})^{-1}$ is inserted to correct for the fact that, to conserve computing resources, we assume all parent decays result in an HNL. \\
Finally, we estimate $N_{\text{POT}} = N_{\textrm{C}}\cdot\widetilde{N}(P)$, $\widetilde{N}(P) = n(\text{all particles})/n(P)$, where $n$ is the number of particles produced in a $p$+target interaction.
For example, if in $n(\pi^{+}) = 0.4, n(K^{+}) = 0.1, n(K^{0}) \simeq n(K^{0}_{L}) = 0.05, n(p) = 0.15, n(\mu^{+}+\text{other}) \simeq 0.05$, then the relevant factors are
\begin{equation}
    \widetilde{N}\left\{\pi^{+}, K^{+}, K^{0}_{\textrm{L}}, \mu^{+}, p\right\} = \left\{1.875, 7.5, 15, 5, 15\right\}.
\end{equation}
For practical purposes, the code expects the values $\widetilde{N}(P)$ as inputs from the user in the configuration file.

\end{document}

\subsection{HNL production in beamline}
The starting off point for deriving a neutrino flux is a precalculated spectrum of particles, such as is typically produced from proton interactions on a target in a neutrino beamline.
These particles (such as $\pi^{\pm}, K^{\pm}, K^{0}_{\textrm{L}}, \mu^{\pm}$) are then usually focused by a series of magnets to perform some charge selection.
The particles then propagate downstream, decaying in some suitably long decay volume to neutrinos (or particles that eventually decay to neutrinos).
They are referred to as ``parents" if they decay directly to neutrinos, or more generally ``ancestors" if one of their decay products is a parent.
One or more particle absorbers are normally placed in between the decay volume and the detector, so that the only particles that survive to reach the detector are neutrinos.
This same production philosophy applies to HNL, which by Eq. \ref{eq: fourth_nu_mixing} have a probability $\propto \left| U_{\alpha 4}\right|^{2}$ to be the mass state that corresponds to the $\nu_{\alpha}$ flavour state made during neutrino production.
\par Experiments simulate the spectrum for each parent species using a description of their beamlines and suitable external experimental data (\cite{NA49, NA61}) to constrain the simulation uncertainty \cite{NuMIBeamFlux}.
There are various formats the output of this simulation can be stored in; we have chosen to adapt the \verb|dk2nu| format \cite{Dk2NuProposal} developed for the Fermilab Intensity Frontier experiments to a ``flat dk2nu" format which mirrors the \verb|dk2nu| tree structure, without containing any complex classes.
This was done to minimise the build complexity for \verb|GENIE|.
However, other flux formats can readily be converted into the format required for this simulation, and an example input flux with the necessary structure has been provided in the \verb|$GENIE/src/contrib/beamhnl| directory accompanying our module.
\par One application of this general format is the ability to use this module not only for accelerator neutrino experiments such as \cite{DUNEBSMOverview, SBNReview, DarkQuestHNL}, but also in the context of higher-energy collider neutrino experiments with detectors lying downstream of the neutrino production point \cite{SHiPSensitivity, FASERHNL}.
This is particularly interesting, because at higher energies heavy mesons (such as $D, D_{s}$), which can decay to HNL heavier than the kaon mass, are produced copiously enough to have a strong sensitivity to HNL with $M_{\textrm{N}4} > m_{\textrm{K}}$.
\par We have used the production branching ratios from \cite{Shrock1981, Ballett2020} for the evaluation of HNL production probabilities, for the most commonly produced parent types: $\pi^{\pm}, K^{\pm}, K^{0}_{L}$ (directly from the beamline), and $\mu^{\pm}$ (from hadron decay themselves).
Further hadron types are not yet a part of our simulation, but are compelling targets to include in light of the above fact.
\par To conserve computing resources, we force every parent in the simulation to decay to HNL; that is equivalent to using the uncorrected branching ratios from Fig. \ref{fig:prodBR}.
This is corrected in the simulation bookkeeping by applying Eq. \ref{eq: pseudounitarity} on the production probability of the HNL.
\par A salient feature of the HNL production is that, depending on the mass of the HNL, the acceptance of the detector as seen by the HNL at its production point can change significantly, owing to the fact that HNL travel with $\beta_{\textrm{N}4} < 1$.
A more detailed review of massive-particle kinematics can be found in \cite{rubbia_2022}. \\
\par Consider a parent $P$ of energy $E_{\textrm{P}}$, decaying leptonically to a neutral lepton $L$ which can either be light ($\nu$) or heavy ($N_{4}$) and a charged lepton $\ell$.
The energy of $L$ in the rest frame of $P$ is then
\begin{equation}
    E_{\textrm{L}}^{*} = \frac{m_{\textrm{P}}^{2} - m_{\ell}^{2} + m_{\textrm{L}}^{2}}{2m_{\textrm{P}}},
\end{equation}
Suppose, without loss of generality, that an observer sees $P$ propagate along the $z$ axis, $\boldsymbol{p}_{\textrm{P}} = (0, 0, p_{\textrm{P}})$.
Then the angle $\Theta$ at which $L$ is emitted with respect to the $z'$ axis in the rest frame can be related to the emission angle $\theta$ in the observer's frame, as
\begin{equation}\label{eq: collimation_effect}
    \tan\theta = \frac{q_{\textrm{L}}\sin\Theta}{\gamma_{\textrm{P}}\left(\beta_{\textrm{P}}E_{\textrm{L}}^{*} + q_{\textrm{L}}\cos\Theta\right)},
\end{equation}
where $q_{\textrm{L}}$ is the rest-frame momentum of $L$, and $\beta,\gamma$ are the relativistic parameters of $P$ in the lab frame.
Figure \ref{fig:collimation} shows $\theta$ as a function of $\Theta$ for a kaon parent, with $E_{\textrm{K}} = 1\,\,\text{GeV}$, for various HNL masses produced in the decay $K^{\pm} \rightarrow N_{4} + \mu^{\pm}$.
\par The cases of massless neutrinos and HNL are quite different; for massless Standard Model neutrinos, $q_{\textrm{L}} = E_{\textrm{L}}^{*}$ and the resulting function $\tan^{-1}\left[\gamma_{\textrm{P}}^{-1}\sin\Theta\left(\beta_{\textrm{P}}+\cos\Theta\right)^{-1}\right]$ is monotonically increasing.
This means that, for any arbitrary emission angle $\theta_{0}$ in the lab frame, there exists some suitable pre-image $\Theta_{0}$ in the rest frame, for any parent velocity.
In a Standard Model calculation, \emph{any} parent can produce a neutrino that is accepted by a detector, \emph{for any} parent momentum and relative position of the neutrino production vertex to the detector.
\par In contrast, for HNL with masses large enough, it is not generically true that any $\theta_{0}$ can be achieved; this places increased importance on the kinematics of the parent $P$.
The greater the angle between $P$'s momentum $\boldsymbol{p}_{\textrm{P}}$ and the relative separation $\boldsymbol{\mathcal{O}}$ between neutrino production vertex and detector, and the greater the HNL mass, the smaller the acceptance becomes, generally speaking; for large enough angles and masses, the HNL could not be accepted at all, regardless of its rest-frame emission angle.
This same collimation effect can, at the same time, account for \emph{increased} acceptance of HNL with respect to a Standard Model neutrino, if $P$ is well-collimated enough.
This happens because Eq. \ref{eq: collimation_effect} now reaches a maximum and tends towards $0$ for large $\Theta$: in other words, backwards-emitted HNL are swept forwards by the Lorentz boost into the lab frame, and end up accepted by the detector.
In general, this \emph{acceptance correction} respective to a Standard Model neutrino is calculated on an event-by-event basis, and applied as an additional weight to each HNL.
\begin{figure}
    \centering
    \includegraphics[width=0.4\textwidth]{Images/largegoodkaon.pdf}
    \caption{Collimation effect for in $K^{\pm} \rightarrow N_{4}\mu^{\pm}$, $E_{\textrm{K}^{\pm}} = 1\,\,\text{GeV}$. For $M_{\textrm{N}4}$ heavy enough, backwards emission in the rest frame is equivalent to forwards emission in the lab frame.}
    \label{fig:collimation}
\end{figure}
One can also obtain an estimate for the neutrino energy at the detector, again setting $p_{\textrm{L}}^{x} = 0$ without loss of generality
\begin{align}\label{eq: boostFactor}
\begin{split}
    &\Rightarrow E_{\textrm{L}}^{*} = \gamma_{\textrm{P}}E_{\textrm{L}} - \gamma_{\textrm{P}}\beta_{\textrm{P}}p_{\textrm{L}}\cos\theta_{\textrm{D}}, \\
    &\Rightarrow E_{\textrm{L}} = \frac{E_{\textrm{L}}^{*}}{\gamma_{\textrm{P}}\left(1 - \beta_{\textrm{P}}\beta_{\textrm{L}}\cos\theta_{\textrm{D}}\right)} \equiv \mathcal{B}E_{\textrm{L}}^{*},
\end{split}
\end{align}
where $\mathcal{B}$ is termed the \emph{boost factor}, and $\theta_{\textrm{D}}$ is the viewing angle between $\boldsymbol{p}_{\textrm{P}}$ and $\boldsymbol{\mathcal{O}}$.
From a Standard Model simulation standpoint, this equation simplifies to
\begin{equation}
    \mathcal{B}_{\nu} = \frac{1}{\gamma_{\text{P}}\left(1 - \beta_{\textrm{P}}\cos\theta_{\textrm{D}}\right)},
\end{equation}
which uniquely determines the lab-frame energy for the massless neutrino.
For a massive neutrino, there is a complication: Eq. \ref{eq: boostFactor} depends on knowledge of the lab-frame velocity through $\beta_{\textrm{L}}$.
We estimate $\beta_{\textrm{L}}$ by imposing a geometric constraint; using the worldline $(T, \boldsymbol{\mathcal{O}})$ with $T = |\boldsymbol{\mathcal{O}}|/(\beta_{\textrm{L}}c)$, we construct a candidate lab-frame momentum by boosting $(T, \boldsymbol{\mathcal{O}})$ into $P$'s rest frame and forcing the HNL momentum to point to that direction, then boosting the result back into the lab frame.
We check the distance between the point of closest approach and the detector centre; if this is too large, we decrement $\beta_{\textrm{L}}$ and repeat the procedure.
\par In Fig. \ref{fig:NuMI_acceptance}, we plot the differential geometrical acceptance, defined as the probability a HNL emitted isotropically in the parent's rest frame will be accepted by the detector, for the case of the MINER$\nu$A detector \cite{TheMINERvADetector} in the NuMI Medium-Energy beam \cite{NuMIBeamFlux}.
We have plotted the acceptance for the processes $K^{\pm} \rightarrow N_{4} + \mu^{\pm}$ (left-hand side plots) and $K^{\pm} \rightarrow N_{4} + \pi^{0} + e^{\pm}$ (right-hand side plots).
Panels (a), (b) show the differential acceptance under the assumption the parent kaons are perfectly focused, which is to say an HNL emitted with momentum collinear to the kaon momentum would definitely be accepted.
Generally, the acceptance remains about the same as for Standard Model neutrinos, though the peak shifts first to higher and then to lower energies.
This is caused by the Lorentz boost becoming more efficient for all HNL as the mass initially increases, followed by the decrease associated with the drop in boost factor $\mathcal{B}$ as the HNL's velocity drops significantly.
In panels (c), (d), we have used the kaon spectrum from the NuMI beamline simulation including realistic focusing, but not applied acceptance correction.
The shape of the acceptance remains roughly similar, but the normalisation and integrated acceptance change dramatically.
This is caused by the suppression of the boost factor $\mathcal{B}$ at both high angles and low velocities.
Finally, panels (e), (f) show the full simulation accounting for both realistic focusing and the change in suitable emission regions in the parent rest frame due to acceptance correction.
Peaks of these distributions shift decidedly to lower energy, as the higher energy HNL are more collimated with their parents and, unlike Standard Model neutrinos, are not necessarily able to reach the detector.
This effect becomes increasingly prominent as $M_{\textrm{N}4}$ goes up and the kinematic constraints become more severe.
\begin{figure*}
    \centering
    \includegraphics[width=\textwidth]{Images/allCOption.pdf}
    \caption{Acceptance for a $K^{\pm}$ decaying to HNL and either $\mu^{\pm}$ or $e^{\pm} + \pi^{0}$, for the MINER$\nu$A detector \cite{TheMINERvADetector}. Top row: Parents perfectly focused: momentum of parent always points towards detector. Middle row: parents not perfectly focused, but no acceptance correction $\mathcal{A}$ applied. Bottom row: full focusing and acceptance correction applied. \newline
    The normalisation of these curves drops considerably when focusing is not perfect; this happens because the boost factor $\mathcal{B}$ drops with opening angle between parent momentum and detector location. The effect of $\mathcal{A}$ is mainly to suppress the high-$E_{\textrm{N}4}$ tails, as hard HNL cannot deviate from their parents enough to reach the detector; also, at low enough HNL mass, $\mathcal{A}$ increases normalisation as backward-emitted HNL are accepted by the detector.}
    \label{fig:NuMI_acceptance}
\end{figure*}
\begin{figure}
    \centering
    \includegraphics[width=0.45\textwidth]{Images/ratioAcc.pdf}
    \caption{Effect of focusing on acceptance; flux at MINER$\nu$A (realistic focusing) / flux (perfect focusing). Note the dramatic reduction in acceptance from pion parents at $M_{\textrm{N}4} = 100\,\,\text{MeV}/c^{2}$. Error bands are purely statistical (note for $M_{\textrm{N}4} > 0$ they are scaled up by a factor $5$).}
    \label{fig:ratioAcceptance}
\end{figure}
\par We further demonstrate the effect of parent focusing on the acceptance in Fig. \ref{fig:ratioAcceptance}, by simulating the flux under the assumption of perfect parent focusing or using realistic parent focusing as provided from the NuMI beamline simulation.
We show the ratios of realistic over perfect acceptance, as a function of HNL energy, for masses $0, 100, ..., 400\,\,\text{MeV}/c^{2}$.
The effect is striking at $100$ and $400\,\,\text{MeV}/c^{2}$, where the thresholds of HNL production by pions and kaons are almost reached; at these masses, the collimation effect becomes most severe, and proportionally more parents can not produce HNL that are accepted by the detector, unless the parent happens to be travelling in a direction which would intersect the detector.
The effect is more pronounced at high HNL energy $E_{\textrm{N}4}$, because more energetic HNL have a stronger collimation effect due to the larger Lorentz boost.
\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{Images/OA_pions_emission.pdf}
    \caption{Boost factor $\mathcal{B}$ as function of pion energy, for different values of $\theta$. (a): $\beta_{\textrm{L}} = 1$ (Standard Model); (b): $\beta_{\textrm{L}} = 0.9999$; (c): $\beta_{\textrm{L}} = 0.999$; (d): $\beta_{\textrm{L}} = 0.99$.}
    \label{fig:pion_OA_emission}
\end{figure}
\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{Images/kineAnalysisMultiAxis.pdf}
    \caption{Pion energy at which $\mathcal{B}$ is highest, for different values of $\theta$.}
    \label{fig:pion_OA_peaks}
\end{figure}
\par Another profound impact can be seen on off-axis neutrino spectra, relevant for PRISM-like searches.
Varying Eq. \ref{eq: boostFactor} over $\cos\theta$ for $\beta_{\textrm{L}} = 1$ yields the celebrated \emph{off-axis effect} for the Standard Model.
In the general case $\beta_{\textrm{L}} \neq 1$, however, the off-axis effect becomes progressively less pronounced.
In Fig. \ref{fig:pion_OA_emission}, we have chosen a pion parent, and four different values of $\beta_{\textrm{L}}$; the Standard Model case is retrieved in (a), and progressively smaller $\beta_{\textrm{L}}$ are shown in (b), (c), (d).
The various curves representing different values of $\theta_{\textrm{D}}$ collapse to a single curve.
Writing out the derivative $\partial E_{\textrm{L}}/\partial E_{\textrm{P}} = E_{\textrm{L}}^{*}\partial\mathcal{B}/\partial E_{\textrm{P}}$, one can find the peak $\mathcal{B}$ to be at
\begin{equation}
    E_{P}\big|_{\mathcal{B}\,\,\text{max}} = \frac{m_{P}}{(1 - \beta_{\textrm{L}}^{2}\cos^{2}\theta)^{1/2}}.
\end{equation}
In Fig. \ref{fig:pion_OA_peaks} we have plotted, for different values of $\theta_{\textrm{D}}$ and for pion parent, $E_{\textrm{P}}\big|_{\mathcal{B}\,\,\text{max}}$ (x axis) as a parametric plot of $\log_{10}\left(1-\beta_{\textrm{L}}\right)$ (y axis).
Standard Model neutrinos are the limit $y \rightarrow \infty$; additionally, we have drawn two axes for visualisation: red is the mass of a $1\,\,\text{GeV}$ HNL for the given $\beta$, and blue is the energy a $100\,\,\text{MeV}/c^{2}$ HNL would have at that $\beta$.
For very high $\beta$, the position of the peaks varies greatly with $E_{\uppi}$, meaning the off-axis effect is visible; this motivates the PRISM concept \cite{DUNE_ND_CDR} of utilising a narrower neutrino spectrum at high off-axis angles to constrain the neutrino flux.
However, as $\beta$ decreases, so does the variation of the neutrino spectrum (as one can also see in Fig. \ref{fig:pion_OA_emission} with curves converging into one for $\beta = 0.99$): since $\beta$ scales inversely to $M_{N4}$, the HNL flux is expected to be \emph{less} sensitive to the off-axis effect than Standard Model neutrinos.
In principle, the spectrum of HNL is still expected to become softer \cite{DuneNDBSM}, but the effect seen would be much smaller than predicted previously.
In Fig. \ref{fig:prism}, one can see our calculation of the flux shapes at the DUNE PRISM with $|U_{\textrm{e}4}|^{2}:|U_{\upmu 4}|^{2}:|U_{\uptau 4}|^{2} = 1:1:0$, for masses $M_{\textrm{N}4} = 0, 100, ..., 400\,\,\text{MeV}/c^{2}$.
Notice how as the off axis angle $\theta_{\textrm{OA}}$ changes, the massless neutrino flux shifts in accordance with the SM prediction, whereas the $M_{N4} = 100, ..., 400\,\,\text{MeV}/c^{2}$ HNL have a far smaller (but still present) dependence on the off axis angle.
The baseline for the detector is 575 m, which means the reference off axis transverse displacements of $5, 10, 20,$ and $30$ m are equivalent to $\theta_{\textrm{OA}} \simeq 0.5, 1.0, 2.0, 3.0^{\circ}$.
\par Our HNL simulation produces the flux calculation based on minimal information from the beamline simulation, which is passed as an input.
There are two fundamentally important inputs:
\begin{enumerate}
    \item Parent momentum and decay vertex position in NEAR coordinates;
    \item ``Importance weight" \cite{Dk2NuProposal, Goodwin2022} - a multiplicity factor for hadrons with very similar kinematics.
\end{enumerate}
Based on this information, the module assigns the appropriate decay channel, calculates the boost factor to obtain the energy of the HNL at the detector under the constraint that the HNL can reach it, and constructs the first particle in \verb|GENIE|'s particle stack that corresponds to an HNL that decays in the detector.
We provide details of the bookkeeping in Appendix \ref{appdx: book}.
\subsection{Decay to Standard Model particles}
Unlike Standard Model neutrinos, HNL are unstable and can decay directly (semi-)leptonically to SM particles.
\begin{widetext}
\begin{figure*}
    \centering
    \includegraphics[width=\textwidth]{Images/combinedPlots.pdf}
    \caption{HNL fluxes at DUNE PRISM, as function of HNL energy and off-axis displacement.}
    \label{fig:prism}
\end{figure*}
\end{widetext}
\par The lifetime of an HNL is generally inversely proportional to the mixing with the SM leptons $\sum_{\alpha} |U_{\alpha 4}|^{2}$ and to the HNL mass $M$.
Depending on the parameter space point being searched, the branching ratios for HNL decays vary as thresholds for various channels open; a few possibilities can be seen in Fig. \ref{fig:BR}.
Details of how we keep track of the decay channels and selects the correct one are in Appendix \ref{appdx: QM}.
\par An HNL has angular momentum same as a Standard Model neutrino; however, its mass implies that it is \emph{partially}, rather than completely, polarised \cite{Levy}.
Equivalently, the HNL and the other particle(s) which were produced in the decay of $P$ form a pure $J = 0$ state, but the HNL itself is not a pure state.
Considering the leptonic production mode $P \rightarrow N_{4} + \ell'$, one can write down a polarisation vector $\mathbb{P}$ for the HNL.
$\mathbb{P}$ has magnitude $|\mathbb{P}| < 1$ (partial polarisation) and direction collinear to the momentum $\boldsymbol{q}_{\ell'}$ where $\boldsymbol{q}$ is written in the HNL's rest frame.
Because in $P$'s rest frame the momenta $\boldsymbol{p}_{\textrm{N}4}$ and $\boldsymbol{p}_{\ell'}$ are collinear, this direction is the same as the momentum $\boldsymbol{q}_{\textrm{P}}$ of $P$ in the HNL rest frame.
\par It is important, moreover, to keep track of where the polarisation vector $\mathbb{P}$ of the HNL is pointing, since it defines the only ``privileged direction" in the HNL rest frame, and thus the axis with which an angular dependence of the decay products $N_{4} \rightarrow X$ manifests.
This direction can be tracked at the moment of HNL production, if its parent $P$ is a particle with no angular momentum.
\par The partial polarisation of $N_{4}$ also means that its differential decay rate into the generic final state $X$ is multiplied, again, by the appropriate coefficient determined by $|\mathbb{P}|$.
Essentially, instead of the well-known $1\mp\cos\theta$ dependence expected from fully polarised spin-$1/2$ particles, the angular dependence is modulated by a suitable polarisation modulus $H$ which is \textit{a priori} dependent on both the production and decay modes of the HNL and produces an angular dependence $1 \pm H\cos\theta$.
The reader will notice that $-1 < H < 1$ - the polarisation modulus is not (semi-)definite.
Its sign is the same as that of the helicity expectation value, $s_{\textrm{N}4}$.
\begin{widetext}
In the simple case of two-body production and two-body decay $P \rightarrow N_{4} + \ell', N_{4} \rightarrow D + \ell$, $H$ is explicitly given as \cite{Levy}
\begin{equation}
    H = - \frac{\left(m_{\ell'}^{2} - M_{\textrm{N}4}^{2}\right)\lambda^{1/2}\left(m_{\textrm{P}}^{2},M_{\textrm{N}4}^{2},m_{\ell'}^{2}\right)}{m_{\textrm{P}}^{2}\left(M_{\textrm{N}4}^{2} + m_{\ell'}^{2}\right)\left(m_{\ell'}^{2}-M_{\textrm{N}4}^{2}\right)^{2}}\cdot\frac{\left(M_{\textrm{N}4}^{2} - m_{\ell}^{2}\right)\lambda^{1/2}\left(M_{\textrm{N}4}^{2},m_{\ell'}^{2},m_{\textrm{D}}^{2}\right)}{m_{\textrm{D}}^{2}\left(M_{\textrm{N}4}^{2}-m_{\ell}^{2}\right)^{2}\left(M_{\textrm{N}4}^{2} + m_{\ell}^{2}\right)} = - \left(s_{\textrm{N}4}\cdot|\mathbb{P}|\right)\cdot|\mathbb{D}|,
\end{equation}
where $\lambda(x,y,z)$ is the K\"{a}ll\'{e}n function defined in Appendix \ref{appdx: QM}, $s_{\textrm{N}4} = +1(-1)$ if $M_{\textrm{N}4}$ is greater(smaller) than $m_{\ell'}$, and $\mathbb{D}$ is the factor resulting from the decay $N_{4} \rightarrow D + \ell$.
The factorisation of the polarisation modulus from HNL production and decay is thus made apparent.
\par For HNL below the kaon mass, the most prevalent production channels are the two-body production channels $\pi \rightarrow N_{4} + \ell$ and, above the pion threshold, $K \rightarrow N_{4} + \ell$; for HNL above about $100\,\,\text{MeV}/c^{2}$, the main decay channels are the two-body channels $N_{4} \rightarrow \pi + \ell, N_{4} \rightarrow \pi^{0} + \nu$.
\end{widetext}

\begin{figure}[t]
    \centering
    \begin{subfigure}[b]{0.23\textwidth}
        \centering
        \includegraphics[width=\textwidth]{Images/allLab.pdf}
        \caption{Lab frame}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.23\textwidth}
        \centering
        \includegraphics[width=\textwidth]{Images/allCm.pdf}
        \caption{HNL rest frame}
    \end{subfigure}
    \caption{Angular distributions of final-state muons in $K^{+} \rightarrow N_{4}+e^{+}\,\,N_{4} \rightarrow \pi^{+}+\mu^{-}$ for Dirac HNL with $M_{\textrm{N}4} = 400\,\,\text{MeV}/c^{2}$, using NuMI flux and for a detector located at MINER$\nu$A's coordinates. See text for details.}
    \setlength{\belowcaptionskip}{-5pt}
    \label{fig:polarisation}
\end{figure}
\begin{figure}
    \centering
    \includegraphics[width=0.4\textwidth]{Images/polz.pdf}
    \caption{Polarisation modulus $H$ for the chain $K^{\pm} \rightarrow N_{4} + e^{\pm}, N_{4} \rightarrow \mu^{\mp} + \pi^{\pm}$.}
    \setlength{\belowcaptionskip}{-5pt}
    \label{fig:polModulus}
\end{figure}
Since the SM weak force couples to left-chiral particles and right-chiral antiparticles, the decays of $N_{4}$ and $\overline{N}_{4}$ have opposite angular dependencies \cite{TastetPol}; the well-known corollary is that in two-body decays only Dirac HNL have a $\cos\theta$ dependence in their decay spectra, whereas Majorana HNL do not (as has been shown explicitly in the case of neutral-mediated decays in \cite{BahaDiracVsMajPol}).
In practical terms, charge-blind detectors that cannot distinguish between leptons and antileptons cannot search for forward-backward asymmetries in the decay distributions of HNL \cite{uBooNEMuPiHNL}.
\par In this work, we have implemented the simple, yet analytically calculable ``two-body-production, two-body-decay" polarisation prescription for all (Dirac) HNL decays, assigning an angular distribution $1 \pm H\cos\theta$ to the spectrum of decay products.
However, we have implemented a switch that allows the user to switch this simple scheme off if it is desirable to do so, reverting to pure phase-space decays instead.
Because the user has access to the truth-level four-momentum of each of the decay particles, it is in principle possible to reweight the spectra of the final state products with any desired polarisation scheme.
The implementation of a fuller description of polarisation effects, including in the three-body decays of Majorana HNL (see for example \cite{MajoranaPol, Ballett2020} for discussions on Majorana HNL polarisations), remains an appealing avenue for future work.
We comment on this in Section \ref{SECT_discussion}.
\par We have simulated in Fig. \ref{fig:polarisation} the effect of three different polarisation prescriptions for $400\,\,\text{MeV}/c^{2}$ HNL from the kaon decay $K^{+} \rightarrow N_{4} + e^{+}$, decaying as $N_{4} \rightarrow \pi^{+} + \mu^{-}$ at the MINER$\nu$A detector in the NuMI beam \cite{TheMINERvADetector}.
The modulus $H$ is plotted as a function of $M_{\textrm{N}4}$ in Fig. \ref{fig:polModulus}, with the red curve corresponding to the production mode $K^{+} \rightarrow N_{4} + e^{+}$ and the blue curve to $K^{+} \rightarrow N_{4} + \mu^{+}$; for $M_{\textrm{N}4} = 400\,\,\text{MeV}/c^{2}$ and $K^{+} \rightarrow N_{4} + e^{+}$, it is $H \simeq 0.9961$.
The simplest prescription (blue curve) is the absence of any polarisation effect, i.e. the switch set to false; the angular distribution of final-state products is isotropic, as expected.
In the red curve, a ``maximal scenario" of polarisation is implemented.
The \emph{direction} of $\mathbb{P}$ is kept fixed to $\widehat{z}$, which shows up as a distribution $1 + H\cos\theta_{\mathbb{P}}$, where $\theta_{\mathbb{P}}$ is the angle between the muon and $\widehat{z}$.
This shows that, for suitable HNL mass, there could be a significant polarisation effect if one did not account for the variation of the direction of $\mathbb{P}$.
Finally, the magenta curve implements the realistic scenario where the direction of $\mathbb{P}$ is evaluated event-by-event according to the procedure outlined above.
It is immediately apparent that the polarisation is almost completely washed out; this occurs as a consequence of backwards-emitted HNL being accepted by the detector.
For such a heavy mass, there is almost the same chance of a backwards-emitted HNL being accepted as a forwards-emitted one; this ``averages out" the polarisation effect.
\par The proper implementation of polarisation effects is doubtlessly going to be crucially important for lower-energy beamlines, or decays at rest, where the Lorentz transformations into the lab frame are small or identity; for the case of the $120\,\,\text{GeV}$ NuMI beam, for example, the transformation into the lab frame makes polarisation effects matter very little for the correct description of final-state kinematics, affecting the opening angle $\Theta_{\mathbb{P}}$ between the muon momentum and beam direction in the region $\Theta_{\mathbb{P}} \lesssim 0.1^{\circ}$.
\begin{widetext}
\begin{figure*}
    \centering
    \begin{subfigure}[b]{0.38\textwidth}
        \centering
        \subfloat[$25\,\,\text{MeV}/c^{2}$, unweighted]{%
            \includegraphics[clip,width=\textwidth]{Images/offAxis_25MeV_unweighted.pdf}
        }

        \subfloat[$100\,\,\text{MeV}/c^{2}$, unweighted]{%
            \includegraphics[clip,width=\textwidth]{Images/offAxis_100MeV_unweighted.pdf}
        }

        \subfloat[$250\,\,\text{MeV}/c^{2}$, unweighted]{%
            \includegraphics[clip,width=\textwidth]{Images/offAxis_250MeV_unweighted.pdf}
        }
    \end{subfigure}
    %
    \begin{subfigure}[b]{0.38\textwidth}
        \centering
        \subfloat[$25\,\,\text{MeV}/c^{2}$, weighted]{%
            \includegraphics[clip,width=\textwidth]{Images/offAxis_25MeV.pdf}
        }

        \subfloat[$100\,\,\text{MeV}/c^{2}$, weighted]{%
            \includegraphics[clip,width=\textwidth]{Images/offAxis_100MeV.pdf}
        }

        \subfloat[$250\,\,\text{MeV}/c^{2}$, weighted]{%
            \includegraphics[clip,width=\textwidth]{Images/offAxis_250MeV.pdf}
        }
    \end{subfigure}
    \caption{Delays of HNL with respect to a SM neutrino produced by the same parent, for the MINER$\nu$A detector. Each circular slice represents one timing bin. The final timing bin is $[1.48,\,1.6]\,\upmu\text{s}$. Panels (a), (b), (c): HNL decay events as a proportion of all simulated events. Panels (d), (e), (f): HNL decay events, weighted for the probability of production, propagation, and decay, as a proportion of the sum of weights of all events. Note the logarithmic scale on the radial axis.}
    \label{fig:delays}
\end{figure*}
\end{widetext}
\subsection{Determination of decay vertex}
\par The final task for the description of a single HNL decay event is its location in spacetime, given some origin; frequently, the user will input their own coordinate system, which is just the USER frame defined earlier.
Knowledge of the position in space where the decay happens is important, because coupled with the knowledge of the HNL's velocity it can give information about the spatial distribution and the timing of HNL signal events.
This is particularly interesting for heavier HNL which tend to ``lag behind" Standard Model neutrinos, and which could for long enough baselines and small enough velocities decay during a timing window with little to no Standard Model expected background such as the period in between beam spills.
This lends itself primarily to the development of special HNL triggers \cite{Porzio2019, Ballett2017}, and underlines the importance of the accurate determination of the position of the HNL decay, as well as the HNL energy and position relative to the USER frame.
\par Given the HNL three-momentum $\boldsymbol{p}_{\textrm{N}4}$ and its production vertex D, it is possible to construct a line $\epsilon(u) = \boldsymbol{r}_{\textrm{D}} + u \cdot \boldsymbol{p}_{\textrm{N}4}$.
Combining that with a description of the detector geometry and a description of where the detector centre is located allows one to calculate two points E, X where $\epsilon$ intersects the detector, using standard methods.
Another straightforward task, given the velocity $\beta$ and lifetime $\tau$ of the HNL, is the calculation of where in the detector the decay occurs, which is of unique interest to segmented detectors such as the DUNE near detector \cite{DUNE_ND_CDR}, whose different submodules may have different tracking capability, thresholds, geometries and fiducial volumes, etc. \\
Since the HNL is unstable, the probability that it can traverse a length $z$ is given by
\begin{equation}
    \mathcal{P}(z) \propto \exp\left(-\frac{z}{\beta c}\cdot\frac{1}{\gamma\tau}\right).
\end{equation}
\par Parametrising the appropriate region of $\epsilon$ as $\epsilon(u) = \boldsymbol{r}_{\textrm{E}} + u\cdot(\boldsymbol{r}_{\textrm{X}} - \boldsymbol{r}_{\textrm{E}})$, where $u = z / |\boldsymbol{r}_{\textrm{X}} - \boldsymbol{r}_{\textrm{E}}|$, one gets the position of the vertex V. \\
Apart from the spatial information, the timing information that can be gained is useful as well, with detectors in the appropriate baseline potentially able to see HNL events in between proton-beam buckets \cite{Ballett2017}, or after the beam spill.
In both cases, backgrounds from neutrino interactions would drop off significantly, leading to far easier HNL signal identification.
\par In Fig. \ref{fig:delays}, we show the distribution of the delay for HNL arrival at the MINER$\nu$A detector, compared to the arrival time of Standard Model neutrinos.
Each slice of a circular plot corresponds to one bin of delay, i.e. the first bin signifies delay $\Delta t \in [0, 10]\,\,\text{ns}$, and so on.
The span of the timing bins covers the range $\Delta t \in [0, 1.6]\,\,\upmu\text{s}$, which is roughly the length of one beam batch in NuMI.
The left panels (a), (b), (c) are filled with the proportion of HNL events in each bin over all HNL events, whereas the right panels (d), (e), (f) are filled with the HNL events, weighted for the overall probability that each HNL would be produced, propagated, and decayed inside the detector, normalised to all HNL.
Note that the radial direction is on a logarithmic scale, and that bins are only drawn if their content is greater than $10^{-3.5}$.
The mass $M_{\textrm{N}4}$ increases from $25\,\,\text{MeV}/c^{2}$ on the top row to $250\,\,\text{MeV}/c^{2}$ on the bottom row.
\par As expected, heavier HNL travel slower than lighter ones, and end up arriving at the detector appreciably later.
Though there exist a small handful of HNL events with great delays which could end up delayed by about the length of one NuMI beam batch, they are less likely to survive long enough to reach the detector.
This explains why the largest bins seem to ``drop off" in the weighted right column of plots.
\par We also see that a significant proportion (about $10\%$) of HNL have a delay within the small delay bins $\sim \ord{10\,\,\text{ns}}$.
This implies that, for detectors which support sufficient triggering capability to distinguish beam-spill timing from beam-off timing, it is possible in principle to obtain a trigger for delayed HNL which arrive after the Standard Model neutrinos from the beam have traversed the detector.
Work utilising such a trigger has already been done by the MicroBooNE collaboration \cite{uBooNEMuPiHNL}, and studied for the SBN programme \cite{Ballett2017}.
\par The simulation, much like Standard Model \verb|GENIE| output, returns \verb|EventRecord|s that summarise the HNL decay.
The defining features of the event record are:
\begin{itemize}
    \item The particle stack, containing each particle's PDG code and four-momentum;
    \item The event vertex, in USER coordinates, with the time component measuring the delay $\Delta t := t\left(\text{HNL reaches}\,\text{V}\right) - t\left(\text{SM}\,\nu\,\text{reaches}\,\text{V}\right)$;
    \item The weight, containing the calculated $N_{\text{POT}}$ for this signal event.
\end{itemize}
We present more information about configuration and running of the module in Appendix \ref{appdx: code}.

\end{document}

\section{Introduction} \label{SECT_Introduction}
\subfile{Sections/Introduction}
\section{The HNL model} \label{SECT_model}
\subfile{Sections/Model}
\onecolumngrid
\section{Previous implementations of HNL simulation} \label{SECT_overview}
\twocolumngrid
\subfile{Sections/MC}
\begin{widetext}
\end{widetext}
\section{Implementation in \small{GENIE} v3} \label{SECT_simulation}
\subfile{Sections/Simulation}
\section{Discussion} \label{SECT_discussion}
\subfile{Sections/Discussion}
\section{Summary} \label{SECT_conclusion}
\subfile{Sections/Conclusion}
\section*{Acknowledgments} \label{SECT_acknowledgments}
\subfile{Sections/Acknowledgments}