\begin{center} {\bfseries By \par
 Benno List, University of Hamburg, \par
 and\par
 Jenny List, D\-E\-S\-Y} \end{center} \section{Introduction}\label{kinfit_intro}
The purpose of this package is to provide an object-\/oriented framework for kinematic fits. It provides a set of general base classes that are not dependent on the experiment or the event hypothesis under consideration. Although a growing set of concrete cases is implemented, the actual parametrisation of the particles' four-\/momenta and the formulation of different constraints can easily be done by the user according to the desired physics process.

Also the actual fitting algorithm is exchangable. At the moment, two fitters are available, both based on (Zitat!) and its fortran implementation in the O\-P\-A\-L software.\subsection{Basic Concepts}\label{kinfit_introconcepts}
This fitting package is based on three concepts\-:
\begin{DoxyItemize}
\item A fitting engine
\item Constraints
\item Fit objects. These concepts are reprensented by different classes, with abstract base classes that define the interfaces and concrete subclasses for the implementation.
\end{DoxyItemize}

{\bfseries Fit objects}, which correspond tio entities like jets, muons, or neutrinos, store information on their parameters and encapsulate the details of the parametrization. If parameters have been measured, two parameter sets are stored, the measured and the fitted ones, together with their respective covariance matrices.

The fit objects provide information on the number of their internal parameters, whether they are measured or unmeasured, and information on their physical quantities, in particular four vector components, and values of derivatives of the four vector components with respect to the various parameters.

{\bfseries Constraints} between fit objects are formulated in terms of the physical quantities, in particular four vector components, of the fit objects. A constraint is a function of the physical quantities of several fit objects, which has to be zero if the constraint is fulfilled. A constraint object is associated with several fit objects, and communicates with them so that it can evaluate the value of the constraint function and its derivatives with respect to the internal parameters of the fit objects. These derivatives are evaulated according to the chain rule, so that the constraint object contains only derivatives with respect to the physical quantities, which are then multiplied by the derivatives with respact to the parameters that are provided by the fit objects.

{\bfseries The fit engine} sets up and solves the system of equations of the fitting problem. It maintains lists of constraints and fitting objects.\subsection{How the Fitting Works}\label{kinfit_introhowto}
To set up a fitting problem, first the fit objects have to be created\-: 
\begin{DoxyCode}
JetFitObject j1 (47., 0.84 , 0.64,  5.0, 0.1, 0.1, 0.);
JetFitObject j2 (45., 2.30 , 2.50,  5.0, 0.1, 0.1, 0.);
JetFitObject j3 (46., 0.996, 3.83,  5.0, 0.1, 0.1, 0.);
JetFitObject j4 (42., 2.21 , 5.82,  5.0, 0.1, 0.1, 0.);
\end{DoxyCode}
 Then, constraint objects that express constraints such as
\begin{DoxyItemize}
\item sum of p\-\_\-x = 0
\item sum of E = sqrt(s)
\item invariant mass of two jet pairs is equal
\end{DoxyItemize}

are created 
\begin{DoxyCode}
PxConstraint pxc;     \textcolor{comment}{// sum(px)=0}
PyConstraint pyc;     \textcolor{comment}{// sum(py)=0}
MassConstraint w(0.); \textcolor{comment}{// mass(particle set 1)-mass (particle set 2)=0}
\end{DoxyCode}
 and the fit objects are associated with them\-: 
\begin{DoxyCode}
pxc.addToFOList (j1);
pxc.addToFOList (j2);
pxc.addToFOList (j3);
pxc.addToFOList (j4);

w.addToFOList (j1, 1);
w.addToFOList (j2, 1);
w.addToFOList (j3, 2);
w.addToFOList (j4, 2);
\end{DoxyCode}
 Finally, the fit engine is created, and the fit and constraint objects are passed to the engine, which finally performs the fit. 
\begin{DoxyCode}
WWFitter fitter;

fitter.addFitObject (j1);
fitter.addFitObject (j2);
fitter.addFitObject (j3);
fitter.addFitObject (j4);

fitter.addConstraint (pxc);
fitter.addConstraint (pyc);
fitter.addConstraint (w);

\textcolor{keywordtype}{double} prob = fitter.fit();
\end{DoxyCode}


After the fit, the fit objects have their fitted parameters set to the fit result.\subsection{How the Fitting Works}\label{kinfit_introhowto}
The kinematic fit minimizes a global chi square, which is given by the differences between fitted and measured parameters of the involved fit objects, weighted by their covariance matrices. This minimization is subject to constraints, expressed as functions of the physical quantities of the fit objects which have to be zero. The constrained fit is solved by the method of Lagrange multipliers, where one term for each constraint is added to the global chi square, and one new parameter, the Lagrange multiplier, enters for each constraint into the minimization problem.

The fit engine has a list of fit objects. First it sets up a global list of measured and unmeasured quantities, and each of the internal parameters of the fit objects gets, in addition to its internal or local number, a global number. These global parameter numbers are stored, for efficiency reason, within the fit objects. Similarly, the constraints are numbered by the fit engine, and tehse global constraint numbers are also stored in the constraint objects. Remember that to each constraint there belongs a new parameter, its Lagrange multiplier. Measured parameters, unmeasured poarameters, and Lagrange multipliers are globally numbered in consequitive order, starting at 0. 