Kinematic fitting is a powerful tool used in the field of particle physics to improve the precision of measured quantities and to reduce background noise. It is particularly useful in the exclusive analysis of particle reactions. The algorithm aims to estimate the true values of track parameters as close as possible to the measured values while fulfilling a set of constraints given by the kinematics of the reaction under study.
The core of the kinematic fitting algorithm is the minimization of the
Here,
The algorithm employs Lagrange multipliers to handle constraints. The Lagrange function
Here,
The Jacobian matrices
The algorithm iteratively updates the parameters
-
PyTorch Integration: This implementation utilizes PyTorch's automatic differentiation tool to find the Jacobian matrices
$F_{\eta}$ and$F_{\xi}$ . -
Generic Implementation: The algorithm is designed to be generic. Users can provide "measured" parameters and "unmeasured" parameters (if needed) in any representation (track parameterization) along with the covariance matrix of the measured parameters and the constraint equation(s).
-
Input Parameters: The user provides the measured and unmeasured parameters, the covariance matrix of the measured parameters, and the constraint equations.
-
Iterative Minimization: The algorithm minimizes the
$\chi^{2}$ function iteratively to find the best estimates of the true observables. -
Output: The algorithm outputs an improved set of parameters that fulfill the kinematic constraints.
To be able to use the kinematic fitting algorithm, you need to clone the repository and install some dependencies.
To install the dependencies using conda, you can create a new environment and install the packages listed in the environment.yml file:
# Create a new conda environment and install PyTorch
conda env create -f environment.yml
# Activate the enviroment
conda activate kinematic_fitter_envThis tutorial demonstrates the application of kinematic fitting to
The tutorial employs ROOT's TGenPhaseSpace to generate KinematicFitter class to perform the fitting.
- ROOT
- PyTorch
- tqdm
Execute the script using Python:
python tutorial_1.py -n 10000Where -n specifies the number of events.
The core of the fitting process relies on defining appropriate constraint equations. In the case of
The invariant mass
In this tutorial, the constraint equation is defined as:
Here, torch tensor as an argument, which represents the measured parameters (in this case te enrgies of the photons, in addition to the angle between the two photons) and return a torch tensor that represents the constraint eqaution(s). All the 'constant' parameters sould be included into this constraint function. In the mass of
def constraint_equations(params: torch.Tensor) -> torch.Tensor:
m = torch.tensor(0.1349766).double()
y = torch.zeros(1, dtype=torch.float64)
y[0] = 2 * params[0] * params[1] * (1 - torch.cos(params[2])) - m * m
return y-
Data Generation: Generate
$\pi^0$ decay events usingTGenPhaseSpace. -
Smearing: Add Gaussian noise to the energy measurements to simulate a 'simpliefied' detector resolution.
-
Measured Parameters: Define the initial parameters for the fit using the smeared energies and the angle between the photon momenta.
-
Constraint Fitting: Utilize the
KinematicFitterclass to perform the constrained fit.
Before performing the kinematic fit, you need to specify the initial values of the parameters that the fit will adjust.These parameters are typically derived from the measurements you have. In this tutorial, the parameters we're interested in fitting are:
$E_1$ : The energy of the first photon, which is smeared.$E_2$ : The energy of the second photon, also smeared.$\theta$ : The angle between the two photons. These parameters are packed into a PyTorch tensor, like so:parameters = torch.tensor([E_1, E_2, g1.Angle(g2.Vect())], dtype=torch.float64)
After defining your initial fitting parameters, the next step is to perform the constrained fit using the `KinematicFitter`` class. Here's how you can initialize and use the fit method in this class:
fitter = KinematicFitter(n_constraints=1, n_parameters=n_params, n_iterations=10)
Here, the
n_constraintsis te number of constraints, which is also the size of theytensor defined inconstraint_equationsfunction. Then_parametersis the number of the measured parameters (in this case 3, 2 energies and 1 angle). Finally,n_iterationsis obobviously the number of iterations. Before performing the fit, you also need to set the covariance matrix that represents the uncertainties in the measured parameters:fitter.set_covariance_matrix(cov_matrix=covariance_matrix)
Call the
fitmethod on thefitterobject. You pass in the initial parameters and the constraint equation function to this method:ok = fitter.fit(measured_params=parameters, constraints=lambda parameters: constraint_equations(parameters))
The
lambdafunction acts like a wrapper around your actualconstraint_equationsfunction. It takes the parameters as an argument and simply forwards them toconstraint_equations. -
Results and Plots: Generate histograms for various observables before and after the kinematic fit.
The tutorial produces the following histograms:
hDiPhotonIMPreFit: Di-Photon invariant mass before the kinematic fit.hEnergyResolutionPreFit: Energy resolution of the 1st photon before the kinematic fit.hChi2: Chi-squared values from the fit.hProb: Probability values associated with the chi-squared values.hEnergyResolutionPostFit: Energy resolution of the 1st photon after the kinematic fit.hDiPhotonIMPostFit: Di-Photon invariant mass after the kinematic fit.
To view the histograms, open the generated plots.root file using ROOT.
In this second tutorial, we delve into a more advanced use case of the `KinematicFitter`` class. We generate an event where a beam proton
- ROOT
- PyTorch
- tqdm
Execute the script using Python:
python tutorial_2.py -n 10000Where -n specifies the number of events.
The tutorial starts by importing required Python and ROOT libraries, then initializes key parameters such as smearing and the covariance matrix. The function get_track_parameters is responsible for simulating smeared track parameters for the decay products. Momentum
The constraint is defined in the function constraint_equations_1C. The constraint equation equates the invariant mass of the proton and pion to the known mass of the Lambda baryon:
y[0] = E**2 - Px**2 - Py**2 - Pz**2 - mass_lambda**2Please note that the constraint equation is written in Spherical coordinates:
The tutorial produces the following histograms:
hIMPreFit: the proton and pion invariant mass before the kinematic fit.hMomentumResolutionPreFit: Momentum resolution of the proton before the kinematic fit.hChi2: Chi-squared values from the fit.hProb: Probability values associated with the chi-squared values.hMomentumResolutionPostFit: Momentum resolution of the proton after the kinematic fit.hIMPostFit: the proton and pion invariant mass after the kinematic fit.
"KinFit -- A Kinematic Fitting Package for Hadron Physics Experiments." arXiv:2308.09575 [physics.data-an], August 2023.
@article{Esmail:2023yjg,
author = {Esmail, Waleed and Rieger, Jana and Taylor, Jenny and Bohman, Malin and Sch\"onning, Karin},
title = "{KinFit -- A Kinematic Fitting Package for Hadron Physics Experiments}",
eprint = "2308.09575",
archivePrefix = "arXiv",
primaryClass = "physics.data-an",
month = "8",
year = "2023"
}