\setcounter{MaxMatrixCols}{32}

\section[Kinematic Fitting]{Kinematic Fitting \footnote{ By Kanglin He, Beijiang Liu, Min Xu, Xueyao Zhang}}
\label{sec:kfit}

\subsection{Introduction}
Kinematic fitting is a mathematical procedure in which one
uses the physical law governing a particle interaction or decay to
improve the measurements describing the process. For example,
consider the decay chains, $\psi(3770)\rightarrow D^{0}\overline{D^{0}}$, 
where $\overline{D^{0}}$ decays to the $CP$ eigenstate $K_{S}^{0}\pi^{0}$ 
and $D^{0}$ decays to the hadronic mode $K^{-}\pi^{+}$. 
There are several constraints that can be applied: 
(1) the $\pi^{+}\pi^{-}$ pair from $K^{0}_{S}$ decay must 
come from a common space point($2\times2-3$ = 1 constraint); 
(2) the momentum vector of $\pi^{+}\pi^{-}$ 
pair must be aligned with the position vector of the decay 
vertex relative to the interaction point($3-1$ = 2 constraints); 
(3) the mass of the $\gamma\gamma$ pair has to be equal to the 
$\pi^{0}$ mass(1 constraint); 
(4) energy and momentum are conserved in the  $D\overline{D}$ 
production  (4 constraints); 
and (5) the mass of $K^{0}_{S}\pi^{0}$ has to be 
equal to the mass of $K^{-}\pi^{+}$ (1 constraint). 
When the tracks are refit with these 9 constraints using 
the general algorithm discussed in next section, 
their parameters are forced to satisfy the constraints, thereby 
improving the mass and momentum resolution of the $D^{0}$ and 
the $\overline{D^{0}}$. 
These resolution improvements will translate to a larger signal 
to background ratio and frequently elevate marginal signals to 
statistical significant results.
The importance of kinematic fitting to data analysis
is demonstrated by its use in virtually all
modern high energy  physics experiments.

\subsection{General algorithm}

 The fitting technique is straightforward and is based on the well known
Lagrange multiplier method~\cite{part1:ref:fit1}. It is assumed that the
constraint equations can be linearized and summarized in two
matrices, {\bf{D}} and {\bf{d}}. Let $\alpha$ represent the
parameters for a set of $n$ tracks. It has the form of a column vector
\begin{equation}\label{part1:eq:alpha}
\alpha=\begin{pmatrix}
          \alpha_{1}\\
          \alpha_{2}\\
          \vdots \\
          \alpha_{n}
        \end{pmatrix}.%
\end{equation}
\noindent
Initially the track parameters have the unconstrained values $\alpha_{0}$,
obtained from the reconstruction. The $r$ constraint functions can be written generally as
\begin{equation}\label{eq:constraints}
\begin{matrix}
{\bf{H}}(\alpha)\equiv 0,    &\textrm{where }{\bf{H}}= \begin{pmatrix}
                                                   H_{1} &H_{2}&\cdots&H_{r}
                                                \end{pmatrix}.%
\end{matrix}%
\end{equation}
Expanding \eqref{eq:constraints} around a convenient point
$\alpha_{A}$ yields the linearized equations
\begin{equation}
0=\displaystyle\frac{\partial H(\alpha_{A})}{\partial\alpha}(\alpha-\alpha_{A})+H(\alpha_{A})={\bf{D}}\delta\alpha+{\bf{d}},
\end{equation}
where $\delta\alpha=\alpha-\alpha_{A}$. Thus we have
\begin{equation}
\begin{matrix}
   {\bf{D}}= \begin{pmatrix}
               \displaystyle\frac{\partial H_{1}}{\partial\alpha_{1}}
              &\displaystyle\frac{\partial H_{1}}{\partial\alpha_{2}}
              &\cdots
              &\displaystyle\frac{\partial H_{1}}{\partial\alpha_{n}} \\
              &  &  &  \\
               \displaystyle\frac{\partial H_{2}}{\partial\alpha_{1}}
              &\displaystyle\frac{\partial H_{2}}{\partial\alpha_{2}}
              &\cdots
              &\displaystyle\frac{\partial H_{2}}{\partial\alpha_{n}} \\
               \vdots &\vdots &\ddots &\vdots \\
               \displaystyle\frac{\partial H_{r}}{\partial\alpha_{1}}
              &\displaystyle\frac{\partial H_{r}}{\partial\alpha_{2}}
              &\cdots
              &\displaystyle\frac{\partial H_{r}}{\partial\alpha_{n}}
             \end{pmatrix},\quad
    &{\bf{d}}=\begin{pmatrix}
                H_{1}(\alpha_{A})\\
                H_{2}(\alpha_{A})\\
                \vdots \\
                H_{r}(\alpha_{A})
             \end{pmatrix},%
\end{matrix}%
\end{equation}
or $\displaystyle D_{ij}=\frac{\partial H_{i}}{\partial \alpha_{j}}$ and
$d_{i}=H_{i}(\alpha_{A})$. The constraints are incorporated using the method
of Lagrange multipliers in which the $\chi^{2}$ is written as a
sum of two term
\begin{equation}
\displaystyle \chi^{2}=(\alpha-\alpha_{0})^{T}V_{\alpha_{0}}^{-1}(\alpha-\alpha_{0})+2\lambda^{T}({\bf{D}}\delta\alpha+{\bf{d}}),
\end{equation}
where $\lambda$ is a vector of $r$ unknown Lagrange multipliers.
Minimizing the $\chi^{2}$ with respect to $\alpha$ and $\lambda$ yields two
vector equations that can be solved for parameters $\alpha$ and their 
covariance matrix:
\begin{equation}
     \begin{matrix}
        \displaystyle V^{-1}_{\alpha_{0}}(\alpha-\alpha_{0})+{\bf{D}}^{T}\lambda = 0, \\
        \displaystyle {\bf{D}}\delta\alpha+{\bf{d}}=0.
     \end{matrix}%
\end{equation}
The solution can be written as:
\begin{equation}
   \begin{matrix}
      \displaystyle \alpha = \alpha_{0}-V_{\alpha_{0}}{\bf{D}}^{T}\lambda, \\
      \displaystyle \lambda = V_{D}({\bf{D}}\delta\alpha_{0}+{\bf{d}}), \\
      \displaystyle V_{\alpha}=V_{\alpha_{0}}-V_{\alpha_{0}}{\bf{D}}^{T}V_{D}{\bf{D}}V_{\alpha_{0}},
   \end{matrix}%
   \label{eq:kf:sol}
\end{equation}
where $\displaystyle V_{D}=\left({\bf{D}}V_{\alpha_{0}}{\bf{D}}^{T}\right)^{-1}$ is the $r\times r$ constraint covariance matrix and
\begin{equation}
      \displaystyle \chi^{2}=\lambda^{T}V^{-1}_{D}\lambda=\lambda^{T}({\bf{D}}\delta\alpha_{0}+{\bf{d}}).
    \label{eq:kf:sol_chi2}
\end{equation}
Note that the $\chi^{2}$  can be written as a sum of $r$ distinct terms, one for each constraint. 
It can be shown that the new covariance matrix $V_{\alpha}$ has diagonal elements
that are smaller than the initial 
covariance matrix $V_{\alpha_0}$. In general, the nonlinearities of 
the constraint equations requires that the 
kinematic fitting procedure be applied iteratively until satisfactory convergence is achieved. 
Track parameters and their errors, covariance matrices, fit information and other quantities can be obtained after fitting.

The constraints ``pull'' the tracks away from  
their unconstrained values. 
The ``pull'' of the $i^{\rm th}-$track parameter is defined as:
\begin{equation}
\displaystyle \textrm{(pull)}_{i}=\frac{\alpha_{i}-\alpha_{0i}}{\sqrt{(V_{\alpha_{0}})_{ii}-(V_{\alpha})_{ii}}}.
\end{equation}
This is an important variable to test the track parameter and its error.
The resulting $\chi^{2}$ that is
obtained with $r$ constraints is distributed like a standard $\chi^{2}$ 
with $r$ degrees of freedom, 
if Gaussian errors apply. Of course, since track errors are only 
approximately Gaussian, the actual distribution will 
have more events in the tail than predicted by theory.  Still, knowledge 
of the distribution allows one to define reasonable $\chi^{2}$ cuts.


It is useful to compute how far the parameters have to move to
satisfy a particular constraint $j$. The initial ``distance from
satisfaction'' can be characterized by the quantity
$({\bf{D}}\delta\alpha_{0}+{\bf{d}})_{j}$ and the number of standard
deviations away from the satisfying the constraint is easily
calculated to be
\begin{equation}
  \displaystyle \sigma_{j}=\frac{D_{ji}\delta\alpha_{0i}+d_{j}}{\sqrt{(V^{-1}_{D})_{jj}}}.
\end{equation}
This information can be used to provide criteria for rejecting
background in addition to the overall $\chi^{2}$.


For kinematic fitting, it is important to choose a track representation 
that uses physically meaningful 
quantities and is complete. We adopt the 7-parameter $W$ format, 
defined as $\alpha_{W}=(p_{x},p_{y},p_{z},E,x,y,z)$,
a 4-momentum and a point where the 4-momentum is evaluated,
in the \bes3 kinematic fitting software package. It is 
straight-forward  to transfer the parameters of neutral tracks
and their covariance to the $W$ representation.
The $W$ format is conveient for transporting
particles in a magnetic field, and well suited for vertex
fitting. It has been noted that the $W$ format also have enough
information to represent the general decays of particles.

\subsection{Common Kinematic Constraints}
In this section, the constraints that are commonly encountered in high
energy physics are described. If multiple constraints are desired,  
one just extends the matrices by adding additional rows, one row per 
constraint.
This allows many constraints to be used simultaneously in the fit.

\subsubsection{Invariant mass and energy-momentum constraints}
The invariant mass constraint equation that forces a track to have an 
invariant mass $m_{c}$ is
\begin{equation}
E^{2}-p^{2}_{x}-p^{2}_{y}-p^{2}_{z}-m^{2}_{c}=0.
\end{equation}
Processes where invariant mass constraints 
are frequently applied in high energy physics analyses are 
$\pi^{0}/\eta\rightarrow \gamma\gamma$, $\eta\rightarrow 
\pi^{+}\pi^{-}\pi^{0}$, $K_{S}^{0}\rightarrow \pi^{+}\pi^{-}$, and
$\Lambda\rightarrow p \pi^{-}$, etc. All of these involve decays into 
several specific daughter particles. 
Since the detector resolutions for neutral particles are poorer
than those for charged particles, the 
invariant mass constraints 
for $\pi^{0}/\eta\rightarrow\gamma\gamma$ are 
almost always applied in data analyses.

In most $J/\psi$ and $\psi(2S)$ analyses, 
the final state daughter particles are 
fully reconstructed and are required 
to  satisfy energy-momentum conservation:
\begin{equation}
\begin{matrix}
             p_{x}-p_{cx}=0,\\
             p_{y}-p_{cy}=0 ,\\
             p_{z}-p_{cz}=0, \\
             E-E_{c}=0.
\end{matrix}
\end{equation}
Energy-momentum constraints are the most commonly
used  analysis tool. It is 
helpful for improving the momentum, 
energy and mass resolution, and for suppressing combinatorial 
backgrounds.

We consider the analysis of  
$J/\psi\rightarrow\rho\pi\rightarrow\pi^{+}\pi^{-}\pi^{0}\rightarrow\pi^{+}\pi^{-}\gamma\gamma$
as an example to illustrate the kinematic fitting procedure for 
energy-momentum constraints:
\begin{equation*}
\begin{matrix}
p_{x1}+p_{x2}+p_{x3}+p_{x4}=0,\\
p_{y1}+p_{y2}+p_{y3}+p_{y4}=0,\\
p_{z1}+p_{z2}+p_{z3}+p_{z4}=0,\\
E_{1}+E_{2}+E_{3}+E_{4}=M_{J/\psi},
\end{matrix}
\end{equation*}
where the $J/\psi$ is assumed to be at rest in the laboratory frame. 
Initially, the track parameters have the 
values $\displaystyle \alpha_{0}=\begin{pmatrix} \alpha^{0}_{1}\\ \alpha^{0}_{2}\\\alpha^{0}_{3}\\\alpha^{0}_{4}\end{pmatrix}$, where
$\alpha^{0}_{i}=\begin{pmatrix}
                 p^{0}_{x_{i}}\\
                 p^{0}_{y_{i}}\\
                 p^{0}_{z_{i}}\\
                 E^{0}_{i}
                 \end{pmatrix}$,
$i$=1, 2, 3, 4,                 
%$\alpha^{0}_{2}=\begin{pmatrix}
%                 p^{0}_{x2}\\
%                 p^{0}_{y2}\\
%                 p^{0}_{z2}\\
%                 E^{0}_{2}
%                 \end{pmatrix}$,
%$\alpha^{0}_{3}=\begin{pmatrix}
%                 p^{0}_{x3}\\
%                 p^{0}_{y3}\\
%                 p^{0}_{z3}\\
%                 E^{0}_{3}
%                 \end{pmatrix}$ and
%$\alpha^{0}_{4}=\begin{pmatrix}
%                 p^{0}_{x4}\\
%                 p^{0}_{y4}\\
%                 p^{0}_{z4}\\
%                 E^{0}_{4}
%                 \end{pmatrix}$
represent the four momentum vectors of $\pi^{+}$, $\pi^{-}$ and two photons. 
 The initial track covariance matrices are denoted as $V_{i0}$, $i$=1,2,3,4. 
%$V_{20}$, $V_{30}$ and $V_{40}$. \
The track parameters $\alpha_{i}$ can be expanded about these values (i.e., $\alpha_{iA}=\alpha_{i}^{0}$) giving for {\bf D} and {\bf d}:
\begin{equation*}
\begin{matrix}
{\bf D}=\begin{pmatrix}
        1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 \\
        0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 \\
        0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 \\
        0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1
        \end{pmatrix},\quad
%\end{equation*}
%and
%\begin{equation*}
&{\bf d} = \begin{pmatrix}
    p^{0}_{x1}+p^{0}_{x2}+p^{0}_{x3}+p^{0}_{x4}\\
    p^{0}_{y1}+p^{0}_{y2}+p^{0}_{y3}+p^{0}_{y4}\\
    p^{0}_{z1}+p^{0}_{z2}+p^{0}_{z3}+p^{0}_{z4}\\
    E^{0}_{1}+E^{0}_{2}+E^{0}_{3}+E^{0}_{4}-M_{J/\psi}
    \end{pmatrix}.
\end{matrix}
\end{equation*}
The updated track parameters, covariance matrices and $\chi^{2}$ can be 
obtained by applying Eqs.~\eqref{eq:kf:sol} and~\eqref{eq:kf:sol_chi2}.
If one wants to apply the additional 
$\pi^{0}\rightarrow\gamma\gamma$ mass constraint:
\begin{equation*}
(E_{3}+E_{4})^{2}-(p_{x3}+p_{x4})^{2}-(p_{y3}+p_{y4})^{2}-(p_{z3}+p_{z4})^{2}=M^{2}_{\pi^{0}} ,
\end{equation*}
the derivative matrices {\bf D} and {\bf d} will take the forms:
\begin{equation*}
%\begin{matrix}
{\bf D}=\begin{pmatrix}
        1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 \\
        0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 \\
        0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 \\
        0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 &0 &0 &0 &1 \\
        0 &0 &0 &0 &0 &0 &0 &0
        &-2p^{0}_{x}
        &-2p^{0}_{y}
        &-2p^{0}_{z}
        &2E^{0}
        &-2p^{0}_{x}
        &-2p^{0}_{y}
        &-2p^{0}_{z}
        &2E^{0}
        \end{pmatrix},
\end{equation*}
and
\begin{equation*}
{\bf d} = \begin{pmatrix}
    p^{0}_{x1}+p^{0}_{x2}+p^{0}_{x3}+p^{0}_{x4}\\
    p^{0}_{y1}+p^{0}_{y2}+p^{0}_{y3}+p^{0}_{y4}\\
    p^{0}_{z1}+p^{0}_{z2}+p^{0}_{z3}+p^{0}_{z4}\\
    E^{0}_{1}+E^{0}_{2}+E^{0}_{3}+E^{0}_{4}-M_{J/\psi} \\
    (E^{0})^{2}-(p^{0}_{x})^{2}-(p^{0}_{y})^{2}-(p^{0}_{z})^{2}-M^{2}_{\pi^{0}}
    \end{pmatrix},
\end{equation*}
where $p^{0}_{x}=p^{0}_{x3}+p^{0}_{x4}$, $p^{0}_{y}=p^{0}_{y3}+p^{0}_{y4}$, $p^{0}_{z}=p^{0}_{z3}+p^{0}_{z4}$ and $E^{0}=E^{0}_{3}+E^{0}_{4}$.

\subsubsection{Reconstruction of $K^{0}_{S}$ and $\Lambda$ decay vertex}

\begin{figure}\centering
\includegraphics[width=8.0cm]{./Part1/figures/ks_decay.eps}
\caption{ \label{fig::ksdecay}A $K^{0}_{S}$ travels a certain
distance (``the flight distance'') before decaying into its
daughters. These daughters are subsequently measured by the tracking
system.}
\end{figure}

To introduce the subject of decay vertex reconstruction, consider 
\figurename~\ref{fig::ksdecay},  which shows
a $K^{0}_{S}$ that decays to $\pi^{+}\pi^{-}$ at a secondary vertex 
after being produced in the beam interaction
region. An accurate determination of the lifetime requires that both
the beginning and endpoint of the $K^{0}_{S}$ flight vector be
determined accurately. The endpoint is determined by vertex fitting,
and its measurement accuracy is controlled purely by the tracking
error of the daughter particles. The beginning point is determined
by the beam spot size augmented, perhaps, 
as shown in \figurename~\ref{fig::ksdecay}, 
by other tracks produced in interaction point (IP), or by the
average of preliminary vertex for lot of events.


The motion of a neutral track before its decay is a simple linear
equation. We convert the  flight distance ($s$) measured from 
the production point $(x_{p}, y_{p}, z_{p})$ to 
the decay point $(x_{d}, y_{d}, z_{d})$, to the
proper decay time $c\tau$ using 
$s=\beta ct=\gamma\beta c\tau =(p/m)c\tau$, yielding the new
equations
\begin{equation}\label{eq:ctau}
      \begin{pmatrix}
           x_{p} \\
           y_{p} \\
           z_{p}
        \end{pmatrix} =
        \begin{pmatrix}
           \displaystyle x_{d}-\frac{p_{x}}{m}c\tau \\
            ~\\
           \displaystyle y_{d}-\frac{p_{y}}{m}c\tau \\
            ~\\
           \displaystyle z_{d}-\frac{p_{z}}{m}c\tau
        \end{pmatrix}.
\end{equation}
\noindent
The lifetime $c\tau$ is determined with Eq.~\eqref{eq:ctau} representing  
constraint conditions. We can apply
\begin{equation}
   \chi^{2}=(\alpha-\alpha_{0})^{T}V^{-1}_{\alpha_{0}}(\alpha-\alpha_{0})+2\lambda^{T}({\bf{D}}\delta\alpha+{\bf{E}}\delta c\tau +{\bf{d}})
\end{equation}
to solve for $c\tau$ and its error, while at the same time improving the track parameters and the start point~\cite{part1:ref:ctau}. 
Cascade decay vertices, such as, $\Xi^{-}\rightarrow\Lambda\pi^{-}$, then 
$\Lambda\rightarrow p\pi^{-}$ can also 
be reconstructed by applying a similar technique~\cite{part1:ref:xi_rec}.

\begin{figure}\centering
\includegraphics[width=7.5cm]{./Part1/figures/m_Ks.eps}\quad
\includegraphics[width=7.5cm]{./Part1/figures/m_Lambda.eps}
\caption{The mass distribution of reconstructed $K^{0}_{S}$'s and
$\Lambda$'s from a MC simulation. The $K^{0}_{S}$ and 
$\Lambda$ mass resolutions are obtained from the weighted 
widths from  double Gaussian fits to the histograms.} 
\label{fig::ks_lam}
\end{figure}

A cut on the ratio of decay length to its error, $s/\sigma_{s}$, 
is useful to suppress  combinatorial backgrounds. 
\figurename~\ref{fig::ks_lam} 
shows the mass distribution of $K^{0}_{S}$ ($s/\sigma_{s}>2$) 
and $\Lambda$ ($s/\sigma_{s}>1$) after the secondary vertex 
reconstruction. 
The mass resolutions are $\sim3$~MeV for $K_{S}$, and 
$\sim1.2$~MeV for $\Lambda$.

%%%%SLO%%

\subsubsection{Kinematic constraints for charm tag reconstructions}

The general technique used in charm physics studies is referred to as tagging. 
At the peak of the $\psi(3770)$, 
charmed $D$ mesons are pair produced with no accompanying particles. 
Fully reconstructing one $D$ from a 
subset of tracks in an event
guarantees the remaining tracks must 
originate from the recoiling $\overline{D}$.

The total energy constraints $E=E_{c}(E_{\textrm{beam}})$ can be applied to improve the mass resolution 
of charm tags by the fact that each $D$ carries 
one-half the total cms energy, 
if the cms is at rest in the laboratory frame. In this case,
the reconstructed $D$ mass  is the famous,  so-called 
``beam constrained mass.''  At \bes3, The produced $\psi(3770)$ 
is  not at rest since 
the electron and positron beam collides with a finite 
crossing angle (22 mrad). 
The beam energy constraint can still be applied by simply 
boosting the tracks to the rest frame of the $\psi(3770)$.

The charmed partcle tags can be reconstructed in an alternative way that 
requires the mass of the reconstructed 
$D$ tag to be equal to the mass of recoiling $\overline{D}$. 
In this case we have
\begin{equation}
E^{2}_{D}-p^{2}_{Dx}-p^{2}_{Dy}-p^{2}_{Dz}=(E_{\psi}-E_{D})^{2}-(p_{\psi x}-p_{Dx})^{2}-(p_{\psi y}-p_{Dy})^{2}-(p_{\psi z}-p_{Dz})^{2},
\end{equation}
where $(p_{Dx}, p_{Dy}, p_{Dz}, E_{D})$ and $(p_{\psi x}, p_{\psi y}, p_{\psi z}, E_{\psi})$ denote the energy-momentum 
vectors of reconstructed $D$ tag and produced $\psi(3770)$. In the
$\psi(3770)$ rest frame, the equal mass 
constraint is totally equivalent to the beam energy constraint.

In Dalitz-plot or partial-wave analyses, an effective recoil mass can be 
calculated 
using $E_{\textrm{recoil}}=E_{\psi(3770)}-E_{\textrm{tag}}$  and 
$\vec{p}_{\textrm{recoil}}=\vec{p}_{\psi(3770)}-\vec{p}_{\textrm{tag}}$. 
One can perform a kinematic fit in which the mass of the charm  tag is 
constrained to the $D$ mass and the recoil mass is allowed to vary. 
The signal can then be seen in the recoil mass plot as a peak  near the 
$D$ mass. With this type of constraint, each event has the
same amount of phase space for its decay throughout the recoil  mass plot. 
This has the advantage that the kinematic boundaries 
of phase space are the same for 
the signal and sideband regions of the recoil mass plot.



\subsection{Applying Kalman filter techniques to kinematic fitting}

In 1960, R.~E.~Kalman published his famous paper describing a recursive 
solution to the discrete-data linear filtering problem~\cite{part1:ref:kalman}. 
It was introduced to the high energy physics world  in a paper by 
Fr\"{u}hwirth~\cite{part1:ref:fruhwirth_kalman}. The Kalman filter is a
set of mathematical equations that provides an efficient
computational (recursive) means to estimate the state of a process,
in a way that minimizes the mean of the square error. 
It is interesting to derive the kinematic fit formalism in the 
Kalman filter framework~\cite{part1:ref:kalman_kine}. 
This derivation is also relevant to the addition of exact constraints to 
a fit. At \bes3, there are two typical kinematic fitting problems:
\begin{itemize}
\item[1)] constraints with a covariance matrix;
\item[2)] constraints with virtual particles.
\end{itemize}
that have to be processed by applying the Kalman filter technique.

\subsubsection{Constraint with a covariance matrix}
The exact constraints can be regarded as a measurement equation with
infinite precision. Most kinematic constraints are of the exact type.
But at \bes3, the contribution from beam energy spread should be 
considered if
the data are taken off the peak of narrow resonance like the $J/\psi$
and $\psi(2S)$. In general, we call the ``measurement
equation'' the constraint with a covariance matrix.

Synchrotron radiation and the replacement of the radiated energy by
the accelerating cavities generate an energy spread for each beam
that results in an essentially Gaussian distribution in  beam
energies $E_{b}^{\prime}$ centered on the
nominal value ($E_{b}$)
\begin{equation}
\displaystyle G(E_{b},E_{b}^{\prime})=\frac{1}{\sqrt{2\pi}\Delta}
\exp\left[-\frac{(E_{b}-E_{b}^{\prime})^{2}}{2\Delta^{2}}\right],
\end{equation}
where $\Delta$ represents the beam energy spread.

Suppose that the electron and positron beams collide with a crossing
angle $2\theta$ in the $x$-$z$ plane (at \bes3, 
$\theta=11~\textrm{mrad}$).  In tha case
we have the measurement equation:
\begin{equation}
\begin{pmatrix} p_{x}&p_{y}&p_{z}&E\end{pmatrix} =
\begin{pmatrix}\displaystyle \sqrt{s}\tan\theta &0 &0
&\displaystyle \frac{\sqrt{s}}{\cos\theta}\end{pmatrix}
\end{equation}
where $E=2E_{b}$, $\delta E = \sqrt{2}\Delta$ and
$\delta\sqrt{s}=\displaystyle \sqrt{2}\Delta\cos\theta$. The corresponding
covariance matrix is given by
$2\cdot\Delta^{2}\cdot
\begin{pmatrix}\sin^{2}\theta &0 &0 &\sin\theta \\
0 &0 &0 &0 \\ 0 &0 &0 &0\\ \sin\theta &0 &0 &1
\end{pmatrix}$.
Clearly, the correlation between $p_{x}$ and $E$ are included.

\subsubsection{Constraint with virtual particles}

At \bes3, three kinds of constraints with virtual particles will commonly 
be encountered in data analysis. 
(In the following discussion, we suppose that a virtual particle is 
represented by a 4-momentum vector 
$q=(q_{x}, q_{y}, q_{z}, W)$ and all  detected particles are represented 
by a 4-momentum vector $p=(p_{x}, p_{y}, p_{z}, E)$.)

\begin{itemize}
\item No detection information available; the virtual particle is 
connected to kinematic fitting with some mass constraints. 
Energy-momentum conservation gives:
    \begin{equation*}
    \begin{matrix}
    p_{x}+q_{x}=p_{cx},\\
    p_{y}+q_{y}=p_{cy},\\
    p_{z}+q_{z}=p_{cz},\\
    E+W=E_{c}.
    \end{matrix}
    \end{equation*}
    In the analysis of $J/\psi\rightarrow \bar{p}n\pi^{+}$, where the $n$ 
is onot detected, 
the mass of the virtual particle $n$ provides an additional constraint. 
In  the analysis of $\psi(3770)\rightarrow D\bar{D}$, 
where one $D$ is reconstructed in one of its decay modes $X$ and 
$\bar{D}$ is not required to be reconstructed,
an equal mass constraint $m_{X}=m_{\textrm{missing}}$ can be employed to 
improve the $D$ tag mass resolution.
\item Only position information is available; the virtual particle is 
connected to the kinematic fitting with a set of 
measurement equations. Some particles, e.g., $K^{0}_{L}$, will register 
reliable position information when it interacts in the detector. 
In this situation, we may construct ``measurement equations'' as 
additional constraints to the energy-momentum conservation:
    \begin{equation*}
    \begin{matrix}
    x_{v}+\lambda q_{x}=x_{\textrm{clus}},\\
    y_{v}+\lambda q_{y}=y_{\textrm{clus}},\\
    z_{v}+\lambda q_{z}=z_{\textrm{clus}},
    \end{matrix}
    \end{equation*}
    where $(x_{v},y_{v},z_{v})$ is the position of interaction or decay 
vertex, $(x_{\textrm{clus}},y_{\textrm{clus}},z_{\textrm{clus}})$ is 
the position vector of the neutral cluster with the covariance matrix 
$V_{\textrm{clus}}$, and $\lambda$ is the flight path. 
The value of the
parameter $\lambda$ is not very interesting, it can be easily substituted 
with 
%(by its minimum $\chi^{2}$)
    \begin{equation*}
    \displaystyle \lambda=\frac{q^{T}V^{-1}_{\textrm{clus}}\Delta x}{q^{T}V^{-1}_{\textrm{clus}}q},
    \end{equation*}
    where $\Delta x=(x_{v}-x_{\textrm{clus}},
y_{v}-y_{\textrm{clus}},z_{v}-z_{\textrm{clus}})$.
\item The virtual particle is built by merging a set of tracks. 
Frequently, one wants to build virtual particles 
with a vertex constraint(e.g. $K^{0}_{S}\rightarrow \pi^{+}\pi^{-}$), or 
with a mass constraint (e.g., $\pi^{0}\rightarrow\gamma\gamma$). 
The pre-fitted $K^{0}_{S}$'s and $\pi^{0}$'s can be directly applied in 
physics analyses.
\end{itemize}


\subsection{Limitations of Kinematic Fitting}

%I'll discuss more about track error matrix.

The precision of kinematic fitting is governed by the model of 
constraint/measurement equations and the model of track parameters and 
their covariance matrices. 
To understand the power and limitations of the kinematic fitting, one has 
to understand these models well.

Since the natural widths of the narrow resonance  such as the $J/\psi$ and 
$\psi(2S)$ are much smaller than the detector resolution, 
the imperfection of energy-momentum constraints could be ignored. For 
broad resonances above charm threshold or for data-taking off of 
resonance peaks,  effects due to beam energy spread and initial state 
radiation must be taken into account.

Unlike the real world, the errors of track parameters are assumed to be 
Gaussian in the kinematic fitting procedure. In some experiments,
the track errors are poorly understood, making kinematic fittng
be of little use.   On the other hand, 
Kalman fitted tracks at \bes3 have better-understood tracking errors
and are well suited for kinematic fitting. 
As is known, it is quite difficult to obtain ``ideal'' track error in an 
experiment since there are many approximations in the 
Kalman track fitting error models, 
such as the wire resolution, fluctuations of energy losses and 
multiple scattering.  Tight $\chi^{2}$ cuts can cause large systematic 
uncertainties into an  analysis because of a long tail in the $\chi^{2}$ 
distribution.

For neutral tracks, the energy deposited in the crystal calorimeter 
is distributed asymmetrically.  If one is 
to avoid large inefficiencies in kinematic fits, the Gaussian error model 
for neutrals has to be modified. 
A solution may be carried out in the near future by application of the 
method of dynamic noise adjustment~\cite{part1:ref:dna}.

