CMS 3D CMS Logo

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, const GhostTrackState &state);
39 
40  Vector2 residual;
41  Matrix2S measErr, measPredErr;
42  Matrix24 h;
43  };
44 } // namespace
45 
46 KalmanState::KalmanState(const GhostTrackPrediction &pred, const GhostTrackState &state) {
47  using namespace ROOT::Math;
48 
49  GlobalPoint point = state.globalPosition();
50 
51  // precomputed values
52  double x = std::cos(pred.phi());
53  double y = std::sin(pred.phi());
54  double dz = pred.cotTheta();
55  double lip = x * point.x() + y * point.y();
56  double tip = x * point.y() - y * point.x();
57 
58  // jacobian of global -> local
59  Matrix23 measToLocal;
60  measToLocal(0, 0) = -dz * x;
61  measToLocal(0, 1) = -dz * y;
62  measToLocal(0, 2) = 1.;
63  measToLocal(1, 0) = y;
64  measToLocal(1, 1) = -x;
65 
66  // measurement error on the 2d plane projection
67  measErr = Similarity(measToLocal, state.cartesianCovariance());
68 
69  // jacobian of representation to measurement transformation
70  h(0, 0) = 1.;
71  h(0, 2) = lip;
72  h(0, 3) = dz * tip;
73  h(1, 1) = -1.;
74  h(1, 3) = -lip;
75 
76  // error on prediction
77  measPredErr = Similarity(h, pred.covariance());
78 
79  // residual
80  residual[0] = point.z() - pred.z() - dz * lip;
81  residual[1] = pred.ip() - tip;
82 }
83 
85  const GhostTrackState &state,
86  double &ndof,
87  double &chi2) const {
88  using namespace ROOT::Math;
89 
90  KalmanState kalmanState(pred, state);
91 
92  if (state.weight() < 1.0e-3)
93  return pred;
94 
95  // inverted combined error
96  Matrix2S invErr = kalmanState.measPredErr + (1.0 / state.weight()) * kalmanState.measErr;
97  if (!invErr.Invert())
98  return pred;
99 
100  // gain
101  Matrix42 gain = pred.covariance() * Transpose(kalmanState.h) * invErr;
102 
103  // new prediction
104  Vector4 newPred = pred.prediction() + (gain * kalmanState.residual);
105  Matrix44 tmp44 = SMatrixIdentity();
106  tmp44 = (tmp44 - gain * kalmanState.h) * pred.covariance();
107  Matrix4S newError(tmp44.LowerBlock());
108 
109  // filtered residuals
110  Matrix22 tmp22 = SMatrixIdentity();
111  tmp22 = tmp22 - kalmanState.h * gain;
112  Vector2 filtRes = tmp22 * kalmanState.residual;
113  tmp22 *= kalmanState.measErr;
114  Matrix2S filtResErr(tmp22.LowerBlock());
115  if (!filtResErr.Invert())
116  return pred;
117 
118  ndof += state.weight() * 2.;
119  chi2 += state.weight() * Similarity(filtRes, filtResErr);
120 
121  return GhostTrackPrediction(newPred, newError);
122 }
123 
125  const GhostTrackState &state,
126  double &ndof,
127  double &chi2,
128  bool withPredError) const {
129  using namespace ROOT::Math;
130 
131  KalmanState kalmanState(pred, state);
132 
133  // this is called on the full predicted state,
134  // so the residual is already with respect to the filtered state
135 
136  // inverted error
137  Matrix2S invErr = kalmanState.measErr;
138  if (withPredError)
139  invErr += kalmanState.measPredErr;
140  if (!invErr.Invert()) {
141  ndof = 0.;
142  chi2 = 0.;
143  }
144 
145  ndof = 2.;
146  chi2 = Similarity(kalmanState.residual, invErr);
147 }
GhostTrackPrediction.h
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:58
sqr
int sqr(const T &t)
Definition: pfalgo_common_ref.h:9
KalmanGhostTrackUpdater.h
reco::GhostTrackPrediction::phi
double phi() const
Definition: GhostTrackPrediction.h:51
GhostTrackState.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
reco::KalmanGhostTrackUpdater::update
GhostTrackPrediction update(const GhostTrackPrediction &pred, const GhostTrackState &state, double &ndof, double &chi2) const override
Definition: KalmanGhostTrackUpdater.cc:84
reco::GhostTrackState
Definition: GhostTrackState.h:21
qcdUeDQM_cfi.lip
lip
Definition: qcdUeDQM_cfi.py:25
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ndof
Definition: HIMultiTrackSelector.h:49
reco::GhostTrackPrediction::prediction
const Vector & prediction() const
Definition: GhostTrackPrediction.h:59
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
h
reco::GhostTrackPrediction::ip
double ip() const
Definition: GhostTrackPrediction.h:49
reco::GhostTrackPrediction::z
double z() const
Definition: GhostTrackPrediction.h:48
Point3DBase< float, GlobalTag >
ROOT::Math
Definition: Transform3DPJ.h:41
qcdUeDQM_cfi.tip
tip
Definition: qcdUeDQM_cfi.py:23
reco::GhostTrackPrediction::cotTheta
double cotTheta() const
Definition: GhostTrackPrediction.h:50
reco::GhostTrackPrediction::covariance
const Error & covariance() const
Definition: GhostTrackPrediction.h:60
reco::KalmanGhostTrackUpdater::contribution
void contribution(const GhostTrackPrediction &pred, const GhostTrackState &state, double &ndof, double &chi2, bool withPredError=false) const override
Definition: KalmanGhostTrackUpdater.cc:124
GlobalError.h
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
PVValHelper::dz
Definition: PVValidationHelpers.h:51
genVertex_cff.x
x
Definition: genVertex_cff.py:13
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
GlobalVector.h
funct::arg
A arg
Definition: Factorize.h:31
reco::GhostTrackPrediction
Definition: GhostTrackPrediction.h:21
point
*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
GlobalPoint.h