Track & Vertex fit formulae

  Let we have Track and Vertex(hit), and we want to update track by vertex(hit). How to do it?

 Track T has 5 parameters and vertex V has 3 ones.

 Find the point on track nearest to vertex (DCA point). Set coordinate system where zero in DCA point,
Zaxis along the track, Yaxis coming thru vertex V and Xaxis orthogonal to them.

In this system Track has parameters T(x,y,Pt,Theta,Phi), vertex (x0,y0,z0=0)
Or T = (X , P) where X = (x,y) and P = (Pt,Theta,Phi)

vertex  V(x0,y0) == V(X0)
T0 = (0,P0)
V0 =( X0)

TF = (XF, PF)
VF = (XF)

                                          | gxx    gxp |
Error matrix Gxp for track =   |               |
                                          | gxp   gpp |

                          | gixx  gixp |
 ( GIxp)-1 = GI =   |              |                             
                          | gixp gipp |

Error matrix  for V is qxx 
( qxx)-1  = qi

Case 1: V is a hit, i.e. measurement of point on the track. We want to estimate new track parameters T1
             closest to both T0 and V in the sense of Xi2

a)  Xi2   = (TF-T0) * (GI) * (TF-T0) +  (V - V0) * qi * (V - V0)

                               | qixx  0 |
Let introduce: QI =   |           | 
                               |  0    0 |
and Tv = T(X0 ,0)

Then we can rewrite expression a) as
b)  Xi2   = (TF-T0) * GI * (TF-T0) +  (T - Tv) * QI * (T - Tv )

Assigning all derivatives to zero we got:

c)  
GI * (TF-T0) +   QI * (T - Tv ) = 0
     ( GI +QI)*TF = GI * T0 +   QI *Tv
 
d)     TF = ( GI +QI) -1 * ( GI * T0 +   QI *Tv)

     and ( GI +QI) -1 == error matrix for   TF

Case 2: Vertex is not a hit but real  vertex. That means TF must pass thru vertex.
            Then TF = T(X0,PF)

e)  Xi2   = (TF-T0) * (GI) * (TF-T0)

    (TF-T0) == T(X0,PF) - T( 0,P0 ) == T(X0,DF)                          where DF = PF -P0
f)  Xi2   = (   gixx*X0 +  gixp * DF  )   * X0 + (   gixp*X0 +  gipp * DF  ) * DF

Assigning all derivatives to zero we got:
g)                  gixp  * X0 +  gipp * DF  = 0
h)                 DF  = -  (gipp)-1   * gixp  * X0
    and (gipp)-1  the error matrix of DF

You see the re is no dependency from Q or QI
Also from h) DF  linearly depends of  X0
Then at the end error matrix of DF = (gipp)-1   * gixp ) * qxx * (gipp)-1   * gixp )