CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KFUpdator.cc
Go to the documentation of this file.
9 
11  const TrackingRecHit& aRecHit) const {
12  switch (aRecHit.dimension()) {
13  case 1: return update<1>(tsos,aRecHit);
14  case 2: return update<2>(tsos,aRecHit);
15  case 3: return update<3>(tsos,aRecHit);
16  case 4: return update<4>(tsos,aRecHit);
17  case 5: return update<5>(tsos,aRecHit);
18  }
19  throw cms::Exception("Rec hit of invalid dimension (not 1,2,3,4,5)") <<
20  "The value was " << aRecHit.dimension() <<
21  ", type is " << typeid(aRecHit).name() << "\n";
22 }
23 
24 #define NEW
25 #ifdef NEW
26 template <unsigned int D>
28  const TrackingRecHit& aRecHit) const {
29 
30  typedef typename AlgebraicROOTObject<D,5>::Matrix MatD5;
31  typedef typename AlgebraicROOTObject<5,D>::Matrix Mat5D;
32  typedef typename AlgebraicROOTObject<D,D>::SymMatrix SMatDD;
33  typedef typename AlgebraicROOTObject<D>::Vector VecD;
34  double pzSign = tsos.localParameters().pzSign();
35 
36  //MeasurementExtractor me(tsos);
37 
38  auto && x = tsos.localParameters().vector();
39  auto && C = tsos.localError().matrix();
40  // Measurement matrix
42  MatD5 H;
43  VecD r, rMeas;
44  SMatDD V, VMeas;
45 
46  KfComponentsHolder holder;
47  holder.template setup<D>(&r, &V, &H, &pf, &rMeas, &VMeas, x, C);
48  aRecHit.getKfComponents(holder);
49 
50  //MatD5 H = asSMatrix<D,5>(aRecHit.projectionMatrix());
51 
52  // Residuals of aPredictedState w.r.t. aRecHit,
53  //VecD r = asSVector<D>(aRecHit.parameters()) - me.measuredParameters<D>(aRecHit);
54  //r -= me.measuredParameters<D>(aRecHit);
55  r -= rMeas;
56 
57  // and covariance matrix of residuals
58  //SMatDD V = asSMatrix<D>(aRecHit.parametersError());
59  //SMatDD R = V + me.measuredError<D>(aRecHit);
60  SMatDD R = V + VMeas;
61  bool ok = invertPosDefMatrix(R);
62  // error check moved at the end
63  //R.Invert();
64 
65  // Compute Kalman gain matrix
66  Mat5D K;
68  if (holder.useProjFunc() ) {
69  K = C*pf.project(R);
70  pf.projectAndSubtractFrom(M,K);
71  }
72  else {
73  K = (C * ROOT::Math::Transpose(H)) * R;
74  M -= K * H;
75  }
76 
77  // Compute local filtered state vector
78  AlgebraicVector5 fsv = x + K * r;
79  // Compute covariance matrix of local filtered state vector
80  AlgebraicSymMatrix55 fse = ROOT::Math::Similarity(M, C) + ROOT::Math::Similarity(K, V);
81 
82 
83  /*
84  // expanded similariy
85  AlgebraicSymMatrix55 fse;
86  ROOT::Math::AssignSym::Evaluate(fse, (M* C) * ( ROOT::Math::Transpose(M)));
87  AlgebraicSymMatrix55 tmp;
88  ROOT::Math::AssignSym::Evaluate(tmp, (K*V) * (ROOT::Math::Transpose(K)));
89  fse += tmp;
90  */
91 
92  if (ok) {
94  LocalTrajectoryError(fse), tsos.surface(),&(tsos.globalParameters().magneticField()), tsos.surfaceSide() );
95  }else {
96  edm::LogError("KFUpdator")<<" could not invert martix:\n"<< (V+VMeas);
97  return TrajectoryStateOnSurface();
98  }
99 
100 }
101 #endif
102 
103 #ifndef NEW
104 template <unsigned int D>
106  const TransientTrackingRecHit& aRecHit) const {
107 
108  typedef typename AlgebraicROOTObject<D,5>::Matrix MatD5;
109  typedef typename AlgebraicROOTObject<5,D>::Matrix Mat5D;
110  typedef typename AlgebraicROOTObject<D,D>::SymMatrix SMatDD;
111  typedef typename AlgebraicROOTObject<D>::Vector VecD;
112  double pzSign = tsos.localParameters().pzSign();
113 
114  MeasurementExtractor me(tsos);
115 
117  const AlgebraicSymMatrix55 &C = (tsos.localError().matrix());
118  // Measurement matrix
119  MatD5 H = asSMatrix<D,5>(aRecHit.projectionMatrix());
120 
121  // Residuals of aPredictedState w.r.t. aRecHit,
122  VecD r = asSVector<D>(aRecHit.parameters()) - me.measuredParameters<D>(aRecHit);
123 
124  // and covariance matrix of residuals
125  SMatDD V = asSMatrix<D>(aRecHit.parametersError());
126  SMatDD R = V + me.measuredError<D>(aRecHit);
127  int ierr = ! invertPosDefMatrix(R);; // if (ierr != 0) throw exception;
128  //R.Invert();
129 
130  // Compute Kalman gain matrix
131  Mat5D K = C * ROOT::Math::Transpose(H) * R;
132 
133  // Compute local filtered state vector
134  AlgebraicVector5 fsv = x + K * r;
135 
136  // Compute covariance matrix of local filtered state vector
138  AlgebraicMatrix55 M = I - K * H;
139  AlgebraicSymMatrix55 fse = ROOT::Math::Similarity(M, C) + ROOT::Math::Similarity(K, V);
140 
142  LocalTrajectoryError(fse), tsos.surface(),&(tsos.globalParameters().magneticField()), tsos.surfaceSide() );
143 }
144 #endif
virtual int dimension() const =0
virtual void getKfComponents(KfComponentsHolder &holder) const
double pzSign() const
Sign of the z-component of the momentum in the local frame.
ROOT::Math::SMatrix< double, D1, D1, ROOT::Math::MatRepSym< double, D1 > > SymMatrix
bool useProjFunc() const
const LocalTrajectoryParameters & localParameters() const
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
virtual AlgebraicVector parameters() const =0
AlgebraicVector5 vector() const
ROOT::Math::SMatrix< double, D1, D2, ROOT::Math::MatRepStd< double, D1, D2 > > Matrix
const SurfaceType & surface() const
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
bool invertPosDefMatrix(ROOT::Math::SMatrix< T, N, N, ROOT::Math::MatRepSym< T, N > > &m)
const std::complex< double > I
Definition: I.h:8
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
ROOT::Math::SVector< double, D1 > Vector
ROOT::Math::SVector< double, 5 > AlgebraicVector5
const GlobalTrajectoryParameters & globalParameters() const
virtual AlgebraicMatrix projectionMatrix() const =0
#define update(a, b)
const MagneticField & magneticField() const
Definition: DDAxes.h:10
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
virtual AlgebraicSymMatrix parametersError() const =0