Introduction

Kinematic fitting is a powerful tool widely used in particle and nuclear physics analyses, recognized for its ability to improve the resolution of measured particle track parameters, suppress background, reconstruct undetected particles and to determine the position of vertices. Available information from measurements, such as momenta, angles and energy, combined with physics constraints, such as four-momentum conservation in a production or displaced decay vertex, or the mass of an undetected unstable particle through its decay products, are exploited. With this information, a mathematical minimization problem can be formulated and solved using, e.g., the Lagrange multiplier technique.

Kinematic fitting techniques have been available in particle physics since the 1960s [1] and gained momentum during the bubble chamber days. However, existing packages like RAVE [2] from ILD or the full decay chain fitters from Belle II [3] or PANDA [4] are often embedded in the respective experiment software and specialized for the detector setup. In the measurement of complex decays of heavy particles, it is beneficial to apply kinematic tree fits  [3] to complex decay chains or jets [2, 5]. However, also track- and kinematic fitting packages that are independent of the experiment are available. One such library is ACTS [6], developed at CERN, which performs tracking finding, track fitting and vertexing. The detector geometry is in this case provided by the user. Another library is KFParticle [7] which is part of the CBM first level event trigger and can also be used for other experiments when the geometry is provided. KFParticle can for example perform a missing mass fit to reconstruct neutral particles as has been done in analysis of data from STAR [8].

In many hadron physics experiments like the HADES experiment [9] at GSI, the interaction point is not fixed to a point but can be located within a target volume that covers several centimeters of the path along the beamline. Hence, the interaction vertex position needs to be determined from the measured track parameters of the outgoing particles. In addition, weakly decaying particles such as hyperons produce daughter particles in a secondary vertex, located a measurable distance away from the interaction point. These are crucial to reconstruct since many hyperons, e.g., \(\Lambda\) and \(\Sigma ^0\), are neutral and could otherwise escape detection. Figure 1 illustrates an example where a \(\Lambda\) hyperon is produced in the target volume and subsequently decays in a secondary vertex after travelling some distance. Tracks from secondary particles are more challenging to reconstruct and hence, the reconstructed track parameters have larger measurement uncertainties compared to those from primary particles. All this calls for kinematic fitting. A new package, KinFit, has been developed to facilitate the hyperon program at HADES [10] but is provided in an experiment-agnostic way and is therefore applicable also to other experiments. KinFit performs kinematic fitting of reconstructed tracks with various constraints in contrast to the previously mentioned packages which also performs track fitting. The package has the benefit that the used does not need to integrate a detector geometry in the code in order to use it but can pass already reconstructed quantities direclty to the fitting procedure. Hadron physics experiments at J-PARC [11], JLab [12] or COMPASS [13] and AMBER at CERN, may profit from this package.

In addition to kinematic fitting, tools are provided to construct a particle candidate from its daughter tracks. A functionality for running a kinematic fit for event selection on a ROOT [14] file in an automated way is included as well. The particle tracks are assumed to originate from a region free of magnetic fields, meaning they are propagated as straight tracks.

This paper is outlined as follows: the methodology including the fitting procedure and available constraint equations are described in "Methodology" section. In "Class Descriptions" section, the classes contained in the package are described and in "Performance Study" section, a benchmark study is provided for \(\Lambda\) hyperon reconstruction to demonstrate the performance of the fitter. In addition, a comprehensive user’s guide is provided in Appendix 7.

Fig. 1
figure 1

Illustration of a \(\Lambda\) hyperon produced by a proton beam hitting a proton target. The position of the interaction point (IP, marked in blue) and the \(\Lambda\) decay vertex (marked in green) are determined by the point of closest approach of the \(p_1\) and K and \(p_2\) and \(\pi ^-\) tracks, respectively

Methodology

The goal of a kinematic fitting algorithm is to find an improved set of track parameters as close as possible to the true values, such that they fulfill a set of kinematic and/or geometric constraints. This concept can be translated quantitatively into a \(\chi ^{2}\) minimization expressed as follows:

$$\begin{aligned} \chi ^{2} = (\vec {y} - \vec {\eta })^{T} \, V^{-1}(\vec {y})\, (\vec {y} - \vec {\eta }) = \textrm{minimum} \,, \end{aligned}$$
(1)

where \(\vec {y}\) is a vector of the \(N\in \mathbb {N}\) measured track parameters provided by the tracking algorithm, \(V(\vec {y})\) is the corresponding covariance matrix and \(\vec {\eta }\) are the estimated track parameters.

In addition, the kinematic and geometric constraints are implemented in the procedure by constraint equations \(\vec {f}\). These are in general represented by a set of \(K\in \mathbb {N}\) continuously differentiable functions of the estimated parameters \(\vec {\eta }\) and a set of \(J\in \mathbb {N}_0\) unmeasured parameters combined in \(\vec {\xi }\):

$$\begin{aligned} \vec {f} = \vec {f}(\vec {\eta },\,\vec {\xi }) = 0. \end{aligned}$$

The objective is to minimize the \(\chi ^2\) from equation 1 subject to these constraints.

The Iterative Lagrange Multiplier Method

The method of Lagrange multipliers [15] is well-suited for addressing such problems. This technique enables the transformation of the constrained minimization into the minimization of a single Lagrange function, \(\mathcal {L}\):

$$\begin{aligned} \mathcal {L}&= (\vec {y} - \vec {\eta })^{T}V^{-1}(\vec {y} - \vec {\eta }) + 2 \vec {\lambda }^{T}f(\vec {\eta }, \vec {\xi }) \,, \end{aligned}$$
(2)

where the K additional variables summarized in \(\vec {\lambda }\) are introduced, referred to as Lagrange multipliers.

Minimizing the Lagrange function (equation 2) involves finding the derivatives of \(\mathcal {L}\) with respect to all unknowns \(\vec {\eta }\), \(\vec {\xi }\), \(\vec {\lambda }\). By setting these derivatives to zero and subsequently solving for \(\vec {\eta }\) and \(\vec {\xi }\), the minimization can be achieved. As this problem is generally non-linear, an iterative procedure is employed, with each iteration yielding improved approximations for \(\vec {\eta }\) and \(\vec {\xi }\). Assuming the values of all quantities of the iteration \(\nu\) have already been extracted, we want to express the quantities of the subsequent iteration \(\nu + 1\) in terms of the values of iteration \(\nu\). We then proceed as follows [15]:

  1. 1.

    First, the following notations are introduced:

    $$\begin{aligned} \vec {r}&= \vec {f}^{\nu } + F^{\nu }_{\eta } (\vec {y} - \vec {\eta }^{\nu }), \\ S&= F^{\nu }_{\eta }V(F^{\nu }_{\eta })^{T} \,, \end{aligned}$$

    where \(F_{\eta }\) is a \(K \times N\) Jacobian matrix (\(F_{\eta }=D_\eta \vec {f}\)), i.e., the derivative of the constraint equations with respect to \(\vec {\eta }\).

  2. 2.

    The updated, unmeasured variables, \(\vec {\xi }^{\nu + 1}\), are obtained by

    $$\begin{aligned} \vec {\xi }^{\nu + 1} = \vec {\xi }^{\nu } - (F_{\xi }^{T}S^{-1}F_{\xi })^{-1}F_{\xi }^{T}S^{-1}\vec {r} \,, \end{aligned}$$

    where \(F_{\xi }\) is a \(K \times J\) Jacobian matrix (\(F_{\xi } = D_\xi \vec {f}\)), i.e., the derivative of the constraint equations with respect to \(\vec {\xi }\).

  3. 3.

    The updated Lagrange multipliers, \(\vec {\lambda }^{\nu + 1}\), are obtained from

    $$\begin{aligned} \vec {\lambda }^{\nu +1} = S^{-1} \Big ( \vec {r} + F_{\xi }(\vec {\xi }^{\nu +1}-\vec {\xi }^{\nu }) \Big ) \,. \end{aligned}$$
  4. 4.

    The updated measured parameters, \(\vec {\eta }^{\nu + 1}\), are calculated as

    $$\begin{aligned} \vec {\eta }^{\nu +1} = \vec {y} - VF_{\eta }^{T}\vec {\lambda }^{\nu +1} \,. \end{aligned}$$
  5. 5.

    Finally, the new \(\mathcal {L}\) is calculated and the results compared with the previous iteration. To decide when the solution is sufficiently close to the minimum, convergence criteria are defined, see "Convergence" section.

In the end, the new covariance matrix, \(V^{\nu + 1}\), is calculated:

$$\begin{aligned} {V^{\nu +1}}\,=\,V - V [ F^{T}_{\eta }S^{-1}F_{\eta } \nonumber \\ \,-\,(F^{T}_{\eta }S^{-1}F_{\xi })(F^{T}_{\xi }S^{-1}F_{\xi })^{-1}(F^{T}_{\eta }S^{-1}F_{\xi })^{T} ] V \,. \end{aligned}$$
(3)

This ansatz assumes a quadratic minimum of the \(\chi ^2\) function. The function will look different if it deviates too much from its minimum. Currently there is no guard against this, but the user should be mindful of potential deviations and assess the validity of the results accordingly.

Track Parametrization

The input objects for KinFit include track parameters such as momentum and angles, defined in polar coordinates, as well as the point of closest approach to the beam axis. Functions for converting from Cartesian coordinates are provided to ensure compatibility with other experiments (see the User’s Guide in Appendix 7). In addition, the covariance matrix is required as input. The parameters employed here to uniquely describe a track that is parametrized as a straight line include:

  • Inverse momentum 1/p [MeV\(^{-1}\)c].

  • Polar angle \(\theta\) [radians] defined from 0 to \(\pi\).

  • Azimuthal angle \(\phi\) [radians] defined from \(-\pi\) to \(\pi\) relative to the beam (z) axis.

  • R [mm], the distance between the beam axis and the point of closest approach of the track to the beam axis.

  • Z [mm], the z coordinate of the point of closest approach of the track to the beam axis, and

  • Covariance matrix, where the diagonal entries correspond to the uncertainties in the parameters 1/p, \(\theta\), \(\phi\), R and Z.

For the purely kinematic fits, only the track parameters 1/p, \(\theta\) and \(\phi\) are required.

Constraints

KinFit offers a variety of constraints that can be selected for kinematic fitting.

1C: Vertex Constraint

This purely geometrical vertex constraint minimizes the distance between two tracks, ensuring they originate from the same vertex. A straight line in 3D is uniquely defined by a base vector that points from the origin of a chosen coordinate system to a coordinate on the line and the direction of the line. The components of these vectors are:

$$\begin{aligned} {\left\{ \begin{array}{ll} b_x=R\cdot \cos (\phi +\pi /2), \\ b_y=R\cdot \sin (\phi +\pi /2), \\ b_z=Z, \end{array}\right. } \end{aligned}$$
(4)

and

$$\begin{aligned} {\left\{ \begin{array}{ll} d_x=\sin (\theta )\cdot \cos (\phi ), \\ d_y=\sin (\theta )\cdot \sin (\phi ), \\ d_z=\cos (\theta ). \end{array}\right. } \end{aligned}$$
(5)

In the base vector, \(\pi /2\) is added to \(\phi\) to ensure the base vector is constructed in the HADES coordinate system. A suitable constraint equation can then be formulated as follows:

$$\begin{aligned} f=(\vec {d_1}\times \vec {d_2})\cdot (\vec {b_1}-\vec {b_2}) = 0. \end{aligned}$$
(6)

This expression is proportional to the minimum distance between the straight lines parameterized by the respective base and direction vectors \(\vec {b_1}\), \(\vec {b_2}\), \(\vec {d_1}\) and \(\vec {d_2}\).

The vertex fit can be performed either separately or as part of a series of consecutive fitting procedures. In addition, there is the possibility to perform a mass and a geometrical vertex fit simultaneously.

4C: Four-Momentum Conservation in the Beam–Target Interaction

The 4C constraint demands that the sum of the four-momenta of the final state particles equals that of the initial beam–target system (in the following denoted with the suffix ini). Since all parameters are treated as measured parameters with uncertainties, there are four over-constraints. For N particles, the constraint equations are

$$\begin{aligned} f = {\left\{ \begin{array}{ll} \sum \limits ^N_{i=1} p_{i}\sin \theta _{i}\cos \phi _{i}-p_{\textrm{ini}, x}=0 \text { }\text { } (p_x), \\ \sum \limits ^N_{i=1} p_{i}\sin \theta _{i}\sin \phi _{i}-p_{\textrm{ini}, y}=0 \text { }\text { } (p_y), \\ \sum \limits ^N_{i=1} p_{i}\cos \theta _{i}-p_{\textrm{ini}, z}=0 \text { }\text { } (p_z), \\ \sum \limits ^N_{i=1} \sqrt{p_{i}^2+m_{i}^2}-E_{\textrm{ini}}=0 \text { }\text { } (E). \end{array}\right. } \end{aligned}$$
(7)

3C: Four-Momentum Conservation in a Displaced Vertex

The 3C constraint utilizes four-momentum conservation at a given decay vertex, where a mother particle (M) decays weakly into N particles. This procedure relies on measured information about the primary vertex and the decay vertex, and on a mass hypothesis of the mother particle as, e.g., \(\Lambda\) or \(K_s\). The angles of the mother particle, \(\theta _M\) and \(\phi _M\), are determined by the direction of the vector pointing from the primary to the decay vertex and are therefore treated as measured parameters, whereas the momentum \(p_M\) is unmeasured and hence obtained from the fit. This results in three over-constraints (3C). The initial value is estimated from energy conservation of the decay products using

$$\begin{aligned} p_{M}=\sqrt{\left( \sum _i\sqrt{p_{i}^2+m_{i}^2}\right) ^2-m^2_{M}}\; . \end{aligned}$$
(8)

In this expression, the subscript M represents the mother particle, while i refers to the decay products. The user must provide the mass of the mother particle as a mass hypothesis. The uncertainties in the vertex positions must estimated in the previous step and are propagated to the uncertainties in the parameters. Since the momentum of the mother particle \(p_M\) is an unmeasured quantity, its uncertainties are not known a priori but are, as the momentum itself, obtained from the fit. The constraint equations ensure four-momentum conservation in the decay of the mother:

$$\begin{aligned} f = {\left\{ \begin{array}{ll} \sum \limits ^N_{i=1} p_{i}\sin \theta _{i}\cos \phi _{i}-p_{M}\sin \theta _{M}\cos \phi _{M}=0 \text { }\text { } (p_x), \\ \sum \limits \limits ^N_{i=1} p_{i}\sin \theta _{i}\sin \phi _{i}-p_{M}\sin \theta _{M}\sin \varphi _{M}=0 \text { }\text { } (p_y), \\ \sum \limits ^N_{i=1} p_{i}\cos \theta _{i}-p_{M}\cos \theta _{M}=0 \text { }\text { } (p_z), \\ \sum \limits ^N_{i=1} \sqrt{p_{i}^2+m_{i}^2}-\sqrt{p_{M}^2+m_{M}^2}=0 \text { }\text { } (E). \end{array}\right. } \end{aligned}$$
(9)

1C: Four-Momentum Conservation with a Missing Particle

Four-momentum conservation at the interaction point enables the reconstruction of one undetected or missing (indicated by the suffix miss) particle with a mass hypothesis \(m_\textrm{miss}\). I all other inital and final state particles are known or measured, the four-momentum conservation results in the following constraint equations:

$$\begin{aligned} f = {\left\{ \begin{array}{ll} \sum \limits ^N_{i=1} p_{i}\sin \theta _{i}\cos \phi _{i} + p_{\textrm{miss},x}-p_{\textrm{ini}, x}=0 \text { }\text { } (p_x), \\ \sum \limits ^N_{i=1} p_{i}\sin \theta _{i}\sin \phi _{i} + p_{\textrm{miss},y}-p_{\textrm{ini}, y}=0 \text { }\text { } (p_y), \\ \sum \limits ^N_{i=1} p_{i}\cos \theta _{i} + p_{\textrm{miss},z}-p_{\textrm{ini}, z}=0 \text { }\text { } (p_z), \\ \sum \limits ^N_{i=1} \sqrt{p_{i}^2+m_{i}^2} + \sqrt{p_\textrm{miss}^2+m_\textrm{miss}^2}-E_{\textrm{ini}} \\ \hspace{20pt}=0 \text { }\text { } (E). \end{array}\right. } \end{aligned}$$
(10)

Here, one has measured particles with indices i, a missing particle with mass \(m_\textrm{miss}\) and the initial beam–target four vector \(p^\mu _\textrm{ini}\). The mass, \(m_\textrm{miss}\) needs to be provided by the user as a hypothesis as well as \(p^\mu _\textrm{ini}\).

The four-momentum of the missing particle can be extracted after the fit. Since there are three unmeasured variables, i.e., the three-momentum of the missing particle, only one over-constraint (1C) remains.

1C: Missing Mass Constraint

The missing mass constraint is suitable in the case when there is one undetected final state particle whose momentum is not of interest. Instead, a missing mass constraint can be formulated from the mass hypothesis of the missing particle:

$$\begin{aligned} {f}\,= & {} \, \sqrt{\left( E_\textrm{ini}-\sum ^N_{i=1}{E_{i}}\right) ^2 - \left( \vec {p}_\textrm{ini}-\sum ^N_{i=1}{\vec {p}_{i}}\right) ^2}\nonumber \\{} & {} - m_\textrm{miss} = 0. \end{aligned}$$
(11)

1C: Invariant Mass Constraint

The mass constraint can be used to constrain a set of particles to originate from a common mother particle, whose mass is known. The invariant mass of this set of particles is then constrained to the mass of the hypothetical mother particle:

$$\begin{aligned} f = \sqrt{\left( \sum ^N_{i=1}{E_{i}}\right) ^2 - \left( \sum ^N_{i=1}{\vec {p}_{i}}\right) ^2} - m_\textrm{mother} = 0 \; . \end{aligned}$$
(12)

Convergence

The iterative fitting procedure is terminated when convergence is achieved. There are three different convergence criteria: the difference in \(\chi ^2\) of the Lagrange function between consecutive iterations, the Euclidean norm of the sum of all constraint equations and the Euclidean norm of the difference of all track parameters, normalized to the initial measurement, between two consecutive iterations. The default value for the convergence criteria is \(10^{-4}\) but can be customized. If convergence is not reached before a specified number of iterations (default 20), the fitting procedure is exited.

Goodness of Fit

The performance of the fit is assessed by the final \(\chi ^2_{final}\) of the fit and the so-called pull distributions for all fitted variables. The value of \(\chi ^2_{final}\) should be small, on the order of the number of over-constraints, \(N_C\). For an ensemble of events, \(N_C\) defines the shape of the \(\chi ^2_{final}\) distribution. There is a one-to-one relation between \(\chi ^2_{final}\) for a given \(N_C\) and the corresponding probability, as defined by the probability density function [16]. Ideally, the probability distribution should be uniform if the correct particle hypotheses have been used in the fit and if the covariance matrices accurately describe the measurement precision. However, if the particle hypotheses are incorrect, then a peak towards zero probability should be discernible. If elements of the covariance matrix are over- or underestimated, the distribution will decrease or increase towards larger values of probability.

The pull distributions are defined as:

$$\begin{aligned} pull=\frac{\eta -y}{\sqrt{\sigma ^2(y)-\sigma ^2(\eta )}} \; , \end{aligned}$$
(13)

for each variable, where \(\eta\)/y are the fitted/measured variables, respectively, and \(\sigma (\eta )\)/\(\sigma (y)\) are the corresponding uncertainties. The pull distribution should follow a normal distribution with a mean value of 0 and a standard deviation of 1.

Class Descriptions

The KinFit package is written in C++ and based on ROOT [14] (version 6) and uses CMake [17] (version 3.0 or newer) for the installation. It is available online at:

figure a

Documentation about the usage of the provided tools can be found in the README of the git repository and in the User’s Guide in Appendix 7.

The properties of the particle candidates needed as input are the particle’s track parameters, mass, and covariance matrix. Functions are provided to transform Cartesian track parameters to the RZ track parameters.

KFitParticle

The track parameters of particle candidates are organized in KFitParticle objects that provide all information needed by the fitter class. It inherits from the ROOT class TLorentzVector. For each candidate, the values for the track parameters described in "Track Parametrization" section have to be set. Optionally, an arbitrary particle ID and track ID can be chosen by the user for later reference.

KFitDecayCandFinder

KFitDecayCandFinder calculates properties of an unmeasured candidate that decays in a displaced vertex to be used later in the fit. The angles, \(\theta\) and \(\phi\) are calculated from the line segment connecting the primary to the displaced decay vertex. The uncertainties for these angles are propagated from the uncertainties in the vertex positions in X, Y and Z using the matrix formalism for error propagation. The user needs to provide the uncertainties for the vertex positions.

KFitVertexFinder

KFitVertexFinder finds the vertex by calculating the point of closest approach between at least two tracks by a matrix formalism. For more than two tracks, the vertex is taken as the center of gravity, i.e., the point that is simultaneously closest to all tracks.. This is calculated from a least square method. The vertex finding code is based on a procedure in HYDRA Footnote 1, the HADES software.

KinFitter

KinFitter is the main class containing the fitting functions. It can perform a vertex, 4C, 3C, missing particle, missing mass, mass and a combined vertex+mass fit (see "Constraints" section). The constraint equations and Jacobi matrices are implemented here. This is where the iterative fitting procedure is carried out. The maximum number of iterations or convergence criteria can be changed to custom values.

KFitAnalyzer

KFitAnalyzer is a user interface class. It contains user settings and performs the event loop with a fit of choice. The input particles need to be stored as KFitParticles in a TClonesArray. For each event, particles are selected based on their particle ID (PID), which is also provided to the KFitAnalyzer. A KFitDecayBuilder object is created which takes the selected particles and the desired constraint as input. In the end, the fitted particles are retrieved from the KFitDecayBuilder and stored in an output file together with the fit probability. The KFitAnalyzer currently performs all fits except the 3C fit.

KFitDecayBuilder

This class is responsible for building all possible combinations of the particles within one event. Each combination is passed to the KinFitter which performs the selected fit. The KFitDecayBuilder selects the combination with the best fit probability.

Performance Study

The performance of KinFit is benchmarked using Monte Carlo (MC) simulations. These represent an ideal scenario where a finite detector resolution is added by smearing, and thus known, whereas in real data, it might be difficult to estimate the covariance matrix exactly. This approach allows for a focused investigation of the quality of the KinFit tools. The reaction investigated is \(pp\rightarrow pK^+\Lambda\), \(\Lambda \rightarrow p\pi ^-\), as illustrated in Fig. 1. This reaction provides an opportunity to examine all tools contained in the package. All fits performed in this section use the default settings of KinFitter, described in "Convergence" section.

The event generator Pluto [18] was used to generate \(100\,000\) events of the \(pp\rightarrow pK^+\Lambda\) \(\Lambda \rightarrow p\pi ^-\) reaction at a beam kinetic energy of T=\(4.5\,\textrm{GeV}\). In our simulations, the produced particles and their decay products are distributed isotropically across the available phase space. The primary vertex is generated at the origin, i.e., (0,0,0). A full 4\(\pi\) acceptance is assumed and no material effects are included. The \(\Lambda\) hyperons decay at a displaced decay vertex according to the mean \(\Lambda\) hyperon life time \(c_\tau (\Lambda ) = 7.98\,\textrm{cm}\) [16]. The track parameters of the final state particles are smeared according to a Gaussian distribution, simulating uncertainties from, e.g., detector resolution in a controlled way. The uncertainty for each track parameter is listed in Table 1. Since the results presented here do not depend on a specific experiment, the uncertainties are set to be constant, except the momentum uncertainty, which is momentum dependent.

Table 1 Gaussian standard deviations of the track parameters in the MC sample after smearing

Mass Fit Using KFitAnalyzer

In each event, there are four measured particles: a proton (\(p_1\)) and a kaon from the interaction point and a pion and a proton (\(p_2\)) from the \(\Lambda\) hyperon decay. This means there are two possibilities to combine a pion with a proton, either \(p_1\pi ^-\) and \(p_2\pi ^-\), of which the latter is the correct \(\Lambda\) decay candidate. The KFitAnalyzer is used to find the pion–proton combination that comes from the \(\Lambda\) hyperon decay through the application of a mass fit.

The pion–proton pair giving the largest mass fit probability (see Fig. 2) are selected as \(\Lambda\) daughters. In \(99\,\%\) of the events, the correct proton \(p_2\) is chosen. The probability distribution is uniform, as expected.

Fig. 2
figure 2

Probability distribution of a \(\Lambda\) hyperon mass fit in the reaction \(pp\rightarrow pK^+\Lambda\) \(\Lambda \rightarrow p\pi ^-\) using KFitAnalyzer (top) and the proton selected to originate from the \(\Lambda\) hyperon decay (bottom)

Reconstruction of \(\Lambda\) Hyperon from Vertex Positions and a 3C Fit

The \(\Lambda\) hyperon reconstruction procedure includes three steps:

Fig. 3
figure 3

Reconstructed production vertex from proton and \(K^+\) (top) and location of reconstructed decay vertices of the \(\Lambda\) hyperon from the secondary proton and \(\pi ^-\) (bottom) as reconstructed by the KFitVertexFinder. The positions are projected onto the x–z plane

  1. 1.

    Vertex finding As a first step the position of the primary vertex, where the \(\Lambda\) hyperon was produced is determined from the point of closest approach between the other tracks coming from the production vertex. In this case, these are the proton (\(p_1\)) and kaon tracks. This task is performed by KFitVertexFinder. In a similar way, the \(\Lambda\) hyperon decay vertex is obtained from the point of closest approach between the proton (\(p_2\)) and pion tracks originating from the \(\Lambda\) hyperon decay. The vertex positions are shown in Fig. 3. All primary particles are produced at the origin which means that the distribution in the top panel reflects the finite resolution of the vertex estimation. The dominating effect in the \(\Lambda\) decay vertex distribution is the distance travelled by \(\Lambda\) before decaying.

  2. 2.

    Reconstruction of the neutral candidate The direction of the \(\Lambda\) candidate is given by the vector pointing from the primary to the decay vertex. The magnitude of the \(\Lambda\) hyperon momentum is estimated by the of the sum of the three-momenta of its daughter particles, see equation . The KFitDecayCandFinder carries out this task and calculates the uncertainties of the track parameters of the \(\Lambda\) candidate. The latter requires information on the vertex uncertainties which were estimated by Gaussian fits to the vertex resolution in x, y and z for each vertex.

  3. 3.

    3C fit A kinematic fit ensuring four-momentum conservation at the \(\Lambda\) hyperon decay vertex is the final step and is executed by KinFitter. This improves the resolution of the \(\Lambda\) hyperon track parameters significantly (Fig. 4) and can be used to reject false combinations of protons in the vertices.

Fig. 4
figure 4

Resolution of the \(\Lambda\) hyperon track parameters before and after the 3C fit

Only the correct combination of particles was used in this example, i.e., correct assignment of the protons to the vertices. The pull distributions for the pion track are shown as an example in Fig. 5. These nearly follow a normal distribution, as expected. Figure 6 shows the probability distribution of the 3C fit. The probability deviates slightly from a uniform distribution and there are some events for which the fit converged, but gives a low probability. This effect and the slightly larger deviation of the pull distributions from a normal distribution are only seen in the 3C fit and originate from the estimation of the vertex resolutions, which are not exactly described by a Gaussian.

Fig. 5
figure 5

Pull distributions for the \(\pi ^-\) track parameters after the 3C fit with respective mean and standard deviation

Fig. 6
figure 6

Probability distribution from the 3C fit

4C Fit of the Reaction \(pp\rightarrow pK^+\Lambda\)

The 4C fit is used to constrain the four-momenta of all final state particles to that of the initial beam–target system. In this example, the final state particles are a proton and a kaon from the primary vertex and a proton and a pion from the \(\Lambda\) hyperon decay vertex. Figure 7 shows the momentum resolution for the kaon and the pion before and after the fit. The maximum improvement in resolution is achieved for the kaon momentum, with \(\frac{\sigma _\mathrm {pre-fit}-\sigma _\mathrm {post-fit}}{\sigma _\mathrm {pre-fit}} = 89\,\%\). This improvement is more substantial for the kaon momentum resolution compared to the other particles. This is due to the larger uncertainty of the kaon associated with its larger total momentum. The probability distribution is uniform and the pull distributions follow a normal distribution, as shown in Fig. 8.

Fig. 7
figure 7

Momentum resolution for the \(K^+\) (top) and \(\pi ^-\) (bottom) before and after the 4C fit

Fig. 8
figure 8

4C fit. Probability distribution (top) and example pull distribution of the \(\pi ^-\) momentum with mean and standard deviation (bottom)

Missing Particle Fit of \(K^+\) in the Reaction \(pp\rightarrow pK^+\Lambda\).

In this scenario, it is assumed that the kaon is not detected. The missing particle fit is employed to constrain the four-momenta of the detected particles along with the undetected particle to match the beam–target system, as well as to estimate the momentum of the missing particle. Figure 9 presents the probability distribution of the fit and compares the kaon momentum resolution from the initial guess and after the fit. The initial guess for the kaon momentum is calculated from three-momentum conservation in the interaction point. The momentum resolution before the fit is worse than in the example in "4C Fit of the Reaction pp → pK+Λ" section, where the momentum was measured directly. A noticeable improvement in the momentum resolution can be observed after the fit. However, the resolution is still worse than in the case of the 4C fit, as the missing particle fit has fewer over-constraints. The resolutions of the other track parameters and the pull distributions appear quite similar to those of the 4C fit.

Fig. 9
figure 9

Missing particle fit. Probability distribution (top) and resolution of the estimated and fitted \(K^+\) momentum (bottom)

Vertex Fit

The vertex fit aims to constrain the track parameters of final state particles that originate from the same single point in space. To perform the vertex fit, at least two outgoing particles from the same vertex must be measured. In this example, these particles are the kaon and proton (\(p_1\)) produced at the beam–target interaction point. Figure 10 illustrates the resolution of the estimated R-parameter, defined in "Track Parametrization" section, for the proton. The probability distribution for this vertex fit, along with an example pull distribution of the R-parameter of \(p_1\), is depicted in Fig. 11. As anticipated, the probability is uniformly distributed across its range, while the pull follows a normal distribution. The KinFitAnalyzer was used to choose the proton track that has the largest probability to come from the same vertex as the kaon track. The correct proton (\(p_1\)) is chosen in \(85\,\%\) of the events, which is lower than the fraction of correctly identified combinations by the mass fit presented in "Mass Fit using KFitAnalyzer" section. This shows that the mass constraint is more powerful than the vertex fit.

Fig. 10
figure 10

Vertex fit. Resolution of the R-parameter of the primary proton (\(p_1\)) before and after the fit

Fig. 11
figure 11

Vertex fit. Probability distribution (top) and example pull distribution of the R-parameter for the primary proton (p1) (bottom)

Runtime Performance

KinFit currently runs sequentially on CPU architectures. The runtime performance of various components of KinFit was evaluated on a laptop with the following hardware specifications:

  • Processor: Intel Core i7-1185G7, 3.00 GHz

  • Memory: 32 GB RAM

The results are displayed in Table 2. The average runtime per 1000 events for the 3C constraint (see "3C: Four-momentum conservation in a displaced vertex" section) was calculated for the cases in which the fit converged. There are two tracks per event used in each fit. An overhead on the order of a microsecond for initialization, vertex finding and mother candidate finding each. The runtime for the iterative fitting depends on the number of iterations and the time for each event is shown in Fig. 12. Peaks are visible that correspond to the number of iterations. There is roughly a linear increase in runtime with an increase of about 4 \(\mu\)s per additional iteration.

Table 2 Runtime per event for different parts of KinFit
Fig. 12
figure 12

The runtime for all converged events after the 3C fit. The peaks correspond to different number of iterations before the fit converges and the first four iterations are highlighted with different colors

Conclusions

The KinFit package is a versatile kinematic fitting package that has been developed to provide tools for reconstruction of vertices, momenta and masses of particles in a generic hadron physics experiment. In particular, it is capable of fitting an unknown production vertex from an extended beam–target interaction volume, and of combining kinematic and geometric constraints.

The tools provided by KinFit have been evaluated using toy MC simulations, showing significant improvements in track parameter resolutions and the capability to accurately select the correct particle hypotheses and combinations. It’s essential to note that while our results are promising, a comparison with other kinematic fitting packages will further validate the efficacy of KinFit in a broader context.

While the focus has been on providing suitable tools for hadronic interactions and specifically hyperon decays, the package can be applied for other types of reactions as well. Though KinFit uses the same track parametrization as HADES, but it is generally considered experiment-independent.

The minimal overhead introduced by adding KinFit to an analysis suggests that the package is suitable for running on a local machine.

Outlook

Although the majority of particle physics analyses are based on C++, the demand for similar Python tools is currently growing due to the rapid expansion of the Python ecosystem. Therefore, the KinFit package is planned to be integrated into the SciKit-HEP project [19], which is a community-driven Python ecosystem for data analysis.