FEDRA emulsion software from the OPERA Collaboration
VtKalman.hh
Go to the documentation of this file.
1#ifndef __VTKALMAN_HH
2#define __VTKALMAN_HH
3// *****************************************************************************
4//
5// source:
6//
7// type: source code
8//
9// created: 21. Aug 2000
10//
11// author: Thorsten Glebe
12// HERA-B Collaboration
13// Max-Planck-Institut fuer Kernphysik
14// Saupfercheckweg 1
15// 69117 Heidelberg
16// Germany
17// E-mail: T.Glebe@mpi-hd.mpg.de
18//
19// Description: Kalman filter class
20//
21// changes:
22// 21 Aug 2000 (TG) creation
23// 12 Sep 2000 (TG) member functions ex(), ey(), ez(), E() added
24// 12 Sep 2000 (TG) declared some member functions inline
25// 13 Sep 2000 (TG) added evec(), tvec(), pvec() member functions
26// 04 Okt 2000 (TG) renamed set_use_momentum(const bool use) to
27// use_momentum(const bool use)
28// 04 Okt 2000 (TG) moved use_momentum() member function from class Vertex to
29// class Kalman - now momentum usage can be set for tracks individually
30// 10 Okt 2000 (TG) member G is not a reference to inv. track cov matrix any
31// more but a full copy. Modified use_momentum member function.
32// This fixes the bug that even with k_use_momentum = false
33// the momentum correlated cov. matrix elements influenced the
34// vertex fit.
35// 11 Okt 2000 (TG) init() member function added
36// 18 Okt 2000 (TG) k_alpc member added
37// 18 Okt 2000 (TG) alpc(), alp(), alpc_init(), alp_init(), xn(), yn(), zn(),
38// erg(), calc_ealpc() added
39// 23 Okt 2000 (TG) k_erg member added, renamed k_ealpc to k_nalpc, nalpc(),
40// qvs_nc() added
41// 05 Okt 2001 (TG) bug fix: added CINTOBJECT to get cintdict compilation right
42// 16 Jan 2002 (TG) moved inlines to VtKalman.icc
43//
44// *****************************************************************************
45
46#include <cmath>
47#include "CMatrix.hh"
48#include "VtVector.hh"
49
50#ifdef WIN32
51# include "Rtypes.h"
52#endif
53
54#if defined USE_ROOT && !defined __CINT__
55#include "smatrix/SMatrix.hh"
56#include "smatrix/SVector.hh"
57#endif
58
59namespace VERTEX {
60
61 class Relation;
62
67 //============================================================================
68 // Class Kalman - data structure for Kalman filtering
69 //============================================================================
70 class Kalman {
71 public:
74 Kalman(const Relation* const relation);
76 ~Kalman();
77
80 double chi2() const;
82 double chi2s() const;
84 double tx() const;
86 double ty() const;
88 double p() const;
90 double px() const;
92 double py() const;
94 double pz() const;
96 double ex() const;
98 double ey() const;
100 double ez() const;
102 double E(double rm = 0.) const;
103
104#if defined USE_ROOT && !defined CINTOBJECT
106 SVector<double,3> tvec() const;
108 SVector<double,3> evec() const;
110 SVector<double,3> pvec() const;
111#else
118#endif
119
122 const MATRIX::VtSymMatrix& W() const;
124 const MATRIX::VtSymMatrix& C() const;
126 const MATRIX::VtSymMatrix& CINV() const;
128 const MATRIX::VtSqMatrix& F() const;
130 const MATRIX::VtSqMatrix& ES() const;
132 const MATRIX::VtSymMatrix& DS() const;
134 const MATRIX::VtVector& xv() const;
136 const MATRIX::VtVector& xnk() const;
138 const MATRIX::VtVector& qvs() const;
139
142 void use_momentum(const bool use);
144 bool use_momentum() const;
146 double set_chi2(const double chi2);
147
148
150 void init();
152 std::ostream& print( std::ostream& os ) const;
153
155 bool filter(double z,
156 const MATRIX::VtSymMatrix& prCINV,
157 const MATRIX::VtVector& prkal_xv);
159 double filter_chi2(double z,
160 double prChi2,
161 const MATRIX::VtSymMatrix& prCINV,
162 const MATRIX::VtVector& prkal_xv);
164 bool inverse_filter(double z,
165 const MATRIX::VtSymMatrix& CINVn,
166 const MATRIX::VtSymMatrix& prCINV,
167 const MATRIX::VtVector& kal_xvn);
169 void smooth(double z,
170 const MATRIX::VtVector& xvs,
171 const MATRIX::VtSymMatrix& Cn);
173 const MATRIX::VtVector calc_dp(double z,
174 const MATRIX::VtVector& xk,
175 const MATRIX::VtVector& qk) const;
177 const MATRIX::VtVector calc_pcAx(const MATRIX::VtVector& xk) const;
179 const MATRIX::VtVector calc_AGpc(void) const;
181 const MATRIX::VtVector calc_qk(const MATRIX::VtVector& xk) const;
183 void calc_qvs(const MATRIX::VtVector& xvs);
185 double calc_dchi2(double z,
186 const MATRIX::VtSymMatrix& prCINV,
187 const MATRIX::VtVector& xk,
188 const MATRIX::VtVector& prxk,
189 const MATRIX::VtVector& qk) const;
191 void calc_pc(double z);
192
195 void alpc_init(void);
197 void alp_init(void);
199 void calc_ealpc(void);
201 const MATRIX::VtVector& alpc() const;
203 const MATRIX::VtVector& alp() const;
205 double xn() const;
207 double yn() const;
209 double zn() const;
211 double erg() const;
213 const MATRIX::VtVector& nalpc() const;
216
217 private:
218 const Relation* rel; // relation to Track & Vertex
219 MATRIX::CMatrix G; // copy of inverse track cov. Matrix
221 double k_tx; // in Vt: Ak33(iv,k) = -qvs(1,..) before filter step
222 double k_ty; // in Vt: Ak34(iv,k) = -qvs(2,..) before filter step
223 MATRIX::VtVector k_qvs; // smoothed tx,ty,p (in Vt: qvs(1..3,..))
224 MATRIX::VtVector k_xv; // in Vt: xv(..)
225 // xv(1,..) = kal_xv[0] = kalman vertex x - pos
226 // xv(2,..) = kal_xv[1] = kalman vertex y - pos
227 // xv(3,..) = kal_xv[2] = kalman vertex z - pos
228 MATRIX::VtVector k_qv; // filtered tx,ty,p (in Vt: qv(1..3,..))
229 MATRIX::VtVector k_pc; // vector p_k-c_k^(0) (in Vt: pc)
230 MATRIX::VtVector k_xnk; // inverse kalman vertex position (in Vt: xnk)
231 MATRIX::VtSymMatrix k_W; // 3x3 matrix of filtered (tx,ty,p) cov. values
232 MATRIX::VtMatrix k_GB; // 5x3 matrix GB = G_k*B_k (in Vt: AGB)
233 MATRIX::VtMatrix k_WBG; // 3x5 matrix WBG = W_k*B_k^T*G_k (in Vt: WBG)
234 MATRIX::CMatrix k_Gb; // 5x5 Gb = G - GBWBG (in Vt: GB, G^B)
235 MATRIX::VtSymMatrix k_C; // 3x3 C_k: contribution to vertex covariance matrix
236 MATRIX::VtSymMatrix k_CINV; // 3x3 inverse C_k = (C_k-1^-1 + A^T_kG^B_kA_k)^-1
238 MATRIX::VtSqMatrix k_ES; // track-vertex correlation matrix
239 MATRIX::VtSymMatrix k_DS; // track param. covariance matrix
240 MATRIX::VtVector k_alpc; // (in Vt: alpc): (tx,ty,p) for mass constraint fit
241 MATRIX::VtVector k_alp; // (in Vt: alp)
242 MATRIX::VtVector k_nalpc;// (in Vt: xn,yn,zn)
243 double k_erg; // (in Vt: erg)
244 double k_chi2; // (in Vt: chi^2_k) chi2 contrib. to vertex
245 double k_chi2s;// (in Vt: chi^2_k,S) smoothed chi2 contrib. to vertex
246
247#ifdef WIN32
248 ClassDef(Kalman,0)
249#endif
250 };
251
252 //==============================================================================
253 // operator <<
254 //==============================================================================
255 std::ostream& operator<< ( std::ostream& os, const Kalman& k );
256
257} // end of namespace VERTEX
258
259#include "VtKalman.icc"
260#endif
Definition: CMatrix.hh:63
Definition: VtMatrix.hh:49
Definition: VtSqMatrix.hh:50
Definition: VtSymMatrix.hh:49
Definition: VtVector.hh:45
Definition: VtKalman.hh:70
const MATRIX::VtVector calc_AGpc(void) const
Definition: VtKalman.C:111
const Relation * rel
Definition: VtKalman.hh:218
double xn() const
$n_x = t_x * e_z$
MATRIX::VtMatrix k_GB
Definition: VtKalman.hh:232
const MATRIX::VtVector & nalpc() const
$\vec{n} = (n_x,n_y,n_z)$
Kalman(const Relation *const relation)
Definition: VtKalman.C:40
MATRIX::CMatrix G
Definition: VtKalman.hh:219
void smooth(double z, const MATRIX::VtVector &xvs, const MATRIX::VtSymMatrix &Cn)
Definition: VtKalman.C:450
double chi2s() const
smoothed $\chi^2$
MATRIX::VtVector k_alpc
Definition: VtKalman.hh:240
MATRIX::VtVector k_xv
Definition: VtKalman.hh:224
MATRIX::VtVector pvec() const
$\vec{v} = (p_x,p_y,p_z)$ refitted mom. vector
MATRIX::VtVector k_nalpc
Definition: VtKalman.hh:242
void alp_init(void)
fill $\vec{\alpha}^{(0)}$
void init()
initialize the kalman structure
Definition: VtKalman.C:80
const MATRIX::VtSymMatrix & CINV() const
bool filter(double z, const MATRIX::VtSymMatrix &prCINV, const MATRIX::VtVector &prkal_xv)
Definition: VtKalman.C:278
double erg() const
$E_i=\sqrt{m^2 + p^2}$, $m$ = track rest-mass
double tx() const
refitted $t_x$
void alpc_init(void)
fill $\vec{\alpha}_c^{(0)}$
double k_chi2s
Definition: VtKalman.hh:245
void calc_qvs(const MATRIX::VtVector &xvs)
Definition: VtKalman.C:203
MATRIX::VtVector k_alp
Definition: VtKalman.hh:241
double ex() const
refitted $e_x$
MATRIX::VtVector tvec() const
$\vec{v} = (t_x,t_y,1.)$ refitted slope vector
double k_erg
Definition: VtKalman.hh:243
std::ostream & print(std::ostream &os) const
called by operator<<()
Definition: VtKalman.C:72
double p() const
refitted $p$
const MATRIX::VtSymMatrix & W() const
double zn() const
$n_z = 1/\sqrt{1 + t_x^2 + t_y^2}$
double k_chi2
Definition: VtKalman.hh:244
const MATRIX::VtSymMatrix & DS() const
const MATRIX::VtVector & xnk() const
MATRIX::VtVector k_pc
Definition: VtKalman.hh:229
double E(double rm=0.) const
refitted Energy $E = \sqrt{p^2 + m^2}$
const MATRIX::VtSqMatrix & F() const
double ty() const
refitted $t_y$
const MATRIX::VtVector & xv() const
const MATRIX::VtVector calc_pcAx(const MATRIX::VtVector &xk) const
Definition: VtKalman.C:158
double py() const
refitted $p_y$
bool use_momentum() const
double chi2() const
$\chi^2$ contribution of track
void calc_ealpc(void)
calculate unit vector $\vec{\alpha}_c/|\vec{\alpha}_c|$, energy from alpc
Definition: VtKalman.C:574
double ey() const
refitted $e_y$
MATRIX::VtSymMatrix k_DS
Definition: VtKalman.hh:239
double set_chi2(const double chi2)
double ez() const
refitted $e_z$
const MATRIX::VtVector & qvs() const
$\vec{v} = (t_x,t_y,p)$
double pz() const
refitted $p_z$
MATRIX::VtVector & qvs_nc()
return non-const reference to qvs
~Kalman()
Definition: VtKalman.C:67
double px() const
refitted $p_x$
double k_tx
Definition: VtKalman.hh:221
MATRIX::VtMatrix k_WBG
Definition: VtKalman.hh:233
MATRIX::VtVector k_qv
Definition: VtKalman.hh:228
double yn() const
$n_y = t_y * e_z$
const MATRIX::VtVector calc_dp(double z, const MATRIX::VtVector &xk, const MATRIX::VtVector &qk) const
Definition: VtKalman.C:131
bool inverse_filter(double z, const MATRIX::VtSymMatrix &CINVn, const MATRIX::VtSymMatrix &prCINV, const MATRIX::VtVector &kal_xvn)
Definition: VtKalman.C:509
MATRIX::VtSqMatrix k_ES
Definition: VtKalman.hh:238
MATRIX::VtVector k_xnk
Definition: VtKalman.hh:230
double k_ty
Definition: VtKalman.hh:222
double calc_dchi2(double z, const MATRIX::VtSymMatrix &prCINV, const MATRIX::VtVector &xk, const MATRIX::VtVector &prxk, const MATRIX::VtVector &qk) const
Definition: VtKalman.C:236
MATRIX::VtVector k_qvs
Definition: VtKalman.hh:223
const MATRIX::VtSymMatrix & C() const
const MATRIX::VtVector & alpc() const
state vector $\vec{\alpha_c}=(t_x,t_y,p)$
const MATRIX::VtSqMatrix & ES() const
const MATRIX::VtVector & alp() const
state vector $\vec{\alpha}=(t_x,t_y,p)$
MATRIX::VtSqMatrix k_F
Definition: VtKalman.hh:237
MATRIX::VtSymMatrix k_CINV
Definition: VtKalman.hh:236
MATRIX::VtVector evec() const
$\vec{v} = (e_x,e_y,e_z)$ unit vector along refitted track
MATRIX::VtSymMatrix k_W
Definition: VtKalman.hh:231
bool k_use_momentum
Definition: VtKalman.hh:220
MATRIX::VtSymMatrix k_C
Definition: VtKalman.hh:235
void calc_pc(double z)
Definition: VtKalman.C:213
const MATRIX::VtVector calc_qk(const MATRIX::VtVector &xk) const
Definition: VtKalman.C:185
double filter_chi2(double z, double prChi2, const MATRIX::VtSymMatrix &prCINV, const MATRIX::VtVector &prkal_xv)
Definition: VtKalman.C:434
MATRIX::CMatrix k_Gb
Definition: VtKalman.hh:234
Definition: VtRelation.hh:51
Definition: VtDistance.hh:30
std::ostream & operator<<(std::ostream &os, const VtIni &t)
Definition: VtIni.hh:83