test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KalmanGhostTrackUpdater.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <cmath>
3 
4 #include <Math/SVector.h>
5 #include <Math/SMatrix.h>
6 #include <Math/MatrixFunctions.h>
7 
11 
14 
16 
17 using namespace reco;
18 
19 namespace {
20 #ifndef __clang__
21  static inline double sqr(double arg) { return arg * arg; }
22 #endif
23  using namespace ROOT::Math;
24 
25  typedef SVector<double, 4> Vector4;
26  typedef SVector<double, 2> Vector2;
27 
28  typedef SMatrix<double, 4, 4, MatRepSym<double, 4> > Matrix4S;
29  typedef SMatrix<double, 3, 3, MatRepSym<double, 3> > Matrix3S;
30  typedef SMatrix<double, 2, 2, MatRepSym<double, 2> > Matrix2S;
31  typedef SMatrix<double, 4, 4> Matrix44;
32  typedef SMatrix<double, 4, 2> Matrix42;
33  typedef SMatrix<double, 2, 4> Matrix24;
34  typedef SMatrix<double, 2, 3> Matrix23;
35  typedef SMatrix<double, 2, 2> Matrix22;
36 
37  struct KalmanState {
38  KalmanState(const GhostTrackPrediction &pred,
39  const GhostTrackState &state);
40 
41  Vector2 residual;
42  Matrix2S measErr, measPredErr;
43  Matrix24 h;
44  };
45 }
46 
47 KalmanState::KalmanState(const GhostTrackPrediction &pred,
48  const GhostTrackState &state)
49 {
50  using namespace ROOT::Math;
51 
53 
54  // precomputed values
55  double x = std::cos(pred.phi());
56  double y = std::sin(pred.phi());
57  double dz = pred.cotTheta();
58  double lip = x * point.x() + y * point.y();
59  double tip = x * point.y() - y * point.x();
60 
61  // jacobian of global -> local
62  Matrix23 measToLocal;
63  measToLocal(0, 0) = - dz * x;
64  measToLocal(0, 1) = - dz * y;
65  measToLocal(0, 2) = 1.;
66  measToLocal(1, 0) = y;
67  measToLocal(1, 1) = -x;
68 
69  // measurement error on the 2d plane projection
70  measErr = Similarity(measToLocal, state.cartesianCovariance());
71 
72  // jacobian of representation to measurement transformation
73  h(0, 0) = 1.;
74  h(0, 2) = lip;
75  h(0, 3) = dz * tip;
76  h(1, 1) = -1.;
77  h(1, 3) = -lip;
78 
79  // error on prediction
80  measPredErr = Similarity(h, pred.covariance());
81 
82  // residual
83  residual[0] = point.z() - pred.z() - dz * lip;
84  residual[1] = pred.ip() - tip;
85 }
86 
88  const GhostTrackPrediction &pred,
89  const GhostTrackState &state,
90  double &ndof, double &chi2) const
91 {
92  using namespace ROOT::Math;
93 
94  KalmanState kalmanState(pred, state);
95 
96  if (state.weight() < 1.0e-3)
97  return pred;
98 
99  // inverted combined error
100  Matrix2S invErr = kalmanState.measPredErr +
101  (1.0 / state.weight()) * kalmanState.measErr;
102  if (!invErr.Invert())
103  return pred;
104 
105  // gain
106  Matrix42 gain = pred.covariance() * Transpose(kalmanState.h) * invErr;
107 
108  // new prediction
109  Vector4 newPred = pred.prediction() + (gain * kalmanState.residual);
110  Matrix44 tmp44 = SMatrixIdentity();
111  tmp44 = (tmp44 - gain * kalmanState.h) * pred.covariance();
112  Matrix4S newError(tmp44.LowerBlock());
113 
114  // filtered residuals
115  Matrix22 tmp22 = SMatrixIdentity();
116  tmp22 = tmp22 - kalmanState.h * gain;
117  Vector2 filtRes = tmp22 * kalmanState.residual;
118  tmp22 *= kalmanState.measErr;
119  Matrix2S filtResErr(tmp22.LowerBlock());
120  if (!filtResErr.Invert())
121  return pred;
122 
123  ndof += state.weight() * 2.;
124  chi2 += state.weight() * Similarity(filtRes, filtResErr);
125 
126  return GhostTrackPrediction(newPred, newError);
127 }
128 
130  const GhostTrackPrediction &pred,
131  const GhostTrackState &state,
132  double &ndof, double &chi2,
133  bool withPredError) const
134 {
135  using namespace ROOT::Math;
136 
137  KalmanState kalmanState(pred, state);
138 
139  // this is called on the full predicted state,
140  // so the residual is already with respect to the filtered state
141 
142  // inverted error
143  Matrix2S invErr = kalmanState.measErr;
144  if (withPredError)
145  invErr += kalmanState.measPredErr;
146  if (!invErr.Invert()) {
147  ndof = 0.;
148  chi2 = 0.;
149  }
150 
151  ndof = 2.;
152  chi2 = Similarity(kalmanState.residual, invErr);
153 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
double weight() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
GhostTrackPrediction update(const GhostTrackPrediction &pred, const GhostTrackState &state, double &ndof, double &chi2) const
A arg
Definition: Factorize.h:36
T x() const
Cartesian x coordinate.
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void contribution(const GhostTrackPrediction &pred, const GhostTrackState &state, double &ndof, double &chi2, bool withPredError=false) const
const Vector & prediction() const
const Error & covariance() const
if(dp >Float(M_PI)) dp-
Square< F >::type sqr(const F &f)
Definition: Square.h:13
CovarianceMatrix cartesianCovariance() const
GlobalPoint globalPosition() const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5