GeneralBrokenLines  trunk_rev46
 All Classes Files Functions Variables Typedefs Pages
GblPoint.cpp
Go to the documentation of this file.
1 /*
2  * GblPoint.cpp
3  *
4  * Created on: Aug 18, 2011
5  * Author: kleinwrt
6  */
7 
8 #include "GblPoint.h"
9 
11 
15 GblPoint::GblPoint(const TMatrixD &aJacobian) :
16  theLabel(0), theOffset(0), measDim(0), transFlag(false), measTransformation(), scatFlag(
17  false), localDerivatives(), globalLabels(), globalDerivatives() {
18 
19  for (unsigned int i = 0; i < 5; ++i) {
20  for (unsigned int j = 0; j < 5; ++j) {
21  p2pJacobian(i, j) = aJacobian(i, j);
22  }
23  }
24 }
25 
26 GblPoint::GblPoint(const SMatrix55 &aJacobian) :
27  theLabel(0), theOffset(0), p2pJacobian(aJacobian), measDim(0), transFlag(
28  false), measTransformation(), scatFlag(false), localDerivatives(), globalLabels(), globalDerivatives() {
29 
30 }
31 
33 }
34 
36 
44 void GblPoint::addMeasurement(const TMatrixD &aProjection,
45  const TVectorD &aResiduals, const TVectorD &aPrecision,
46  double minPrecision) {
47  measDim = aResiduals.GetNrows();
48  unsigned int iOff = 5 - measDim;
49  for (unsigned int i = 0; i < measDim; ++i) {
50  measResiduals(iOff + i) = aResiduals[i];
51  measPrecision(iOff + i) = (
52  aPrecision[i] >= minPrecision ? aPrecision[i] : 0.);
53  for (unsigned int j = 0; j < measDim; ++j) {
54  measProjection(iOff + i, iOff + j) = aProjection(i, j);
55  }
56  }
57 }
58 
60 
69 void GblPoint::addMeasurement(const TMatrixD &aProjection,
70  const TVectorD &aResiduals, const TMatrixDSym &aPrecision,
71  double minPrecision) {
72  measDim = aResiduals.GetNrows();
73  TMatrixDSymEigen measEigen(aPrecision);
75  measTransformation = measEigen.GetEigenVectors();
77  transFlag = true;
78  TVectorD transResiduals = measTransformation * aResiduals;
79  TVectorD transPrecision = measEigen.GetEigenValues();
80  TMatrixD transProjection = measTransformation * aProjection;
81  unsigned int iOff = 5 - measDim;
82  for (unsigned int i = 0; i < measDim; ++i) {
83  measResiduals(iOff + i) = transResiduals[i];
84  measPrecision(iOff + i) = (
85  transPrecision[i] >= minPrecision ? transPrecision[i] : 0.);
86  for (unsigned int j = 0; j < measDim; ++j) {
87  measProjection(iOff + i, iOff + j) = transProjection(i, j);
88  }
89  }
90 }
91 
93 
101 void GblPoint::addMeasurement(const TVectorD &aResiduals,
102  const TMatrixDSym &aPrecision, double minPrecision) {
103  measDim = aResiduals.GetNrows();
104  TMatrixDSymEigen measEigen(aPrecision);
106  measTransformation = measEigen.GetEigenVectors();
107  measTransformation.T();
108  transFlag = true;
109  TVectorD transResiduals = measTransformation * aResiduals;
110  TVectorD transPrecision = measEigen.GetEigenValues();
111  unsigned int iOff = 5 - measDim;
112  for (unsigned int i = 0; i < measDim; ++i) {
113  measResiduals(iOff + i) = transResiduals[i];
114  measPrecision(iOff + i) = (
115  transPrecision[i] >= minPrecision ? transPrecision[i] : 0.);
116  for (unsigned int j = 0; j < measDim; ++j) {
117  measProjection(iOff + i, iOff + j) = measTransformation(i, j);
118  }
119  }
120 }
121 
123 
127 unsigned int GblPoint::hasMeasurement() const {
128  return measDim;
129 }
130 
132 
137 void GblPoint::getMeasurement(SMatrix55 &aProjection, SVector5 &aResiduals,
138  SVector5 &aPrecision) const {
139  aProjection = measProjection;
140  aResiduals = measResiduals;
141  aPrecision = measPrecision;
142 }
143 
145 
149 void GblPoint::addScatterer(const TVectorD &aResiduals,
150  const TVectorD &aPrecision) {
151  scatFlag = true;
152  scatResiduals(0) = aResiduals[0];
153  scatResiduals(1) = aResiduals[1];
154  scatPrecision(0) = aPrecision[0];
155  scatPrecision(1) = aPrecision[1];
156 }
157 
160  return scatFlag;
161 }
162 
164 
168 void GblPoint::getScatterer(SVector2 &aResiduals, SVector2 &aPrecision) const {
169  aResiduals = scatResiduals;
170  aPrecision = scatPrecision;
171 }
172 
174 
178 void GblPoint::addLocals(const TMatrixD &aDerivatives) {
179  if (measDim) {
180  localDerivatives.ResizeTo(aDerivatives);
181  if (transFlag) {
182  localDerivatives = measTransformation * aDerivatives;
183  } else {
184  localDerivatives = aDerivatives;
185  }
186  }
187 }
188 
190 unsigned int GblPoint::getNumLocals() const {
191  return localDerivatives.GetNcols();
192 }
193 
195 const TMatrixD& GblPoint::getLocalDerivatives() const {
196  return localDerivatives;
197 }
198 
200 
205 void GblPoint::addGlobals(const std::vector<int> &aLabels,
206  const TMatrixD &aDerivatives) {
207  if (measDim) {
208  globalLabels = aLabels;
209  globalDerivatives.ResizeTo(aDerivatives);
210  if (transFlag) {
211  globalDerivatives = measTransformation * aDerivatives;
212  } else {
213  globalDerivatives = aDerivatives;
214  }
215 
216  }
217 }
218 
220 unsigned int GblPoint::getNumGlobals() const {
221  return globalDerivatives.GetNcols();
222 }
223 
225 std::vector<int> GblPoint::getGlobalLabels() const {
226  return globalLabels;
227 }
228 
230 const TMatrixD& GblPoint::getGlobalDerivatives() const {
231  return globalDerivatives;
232 }
233 
235 
238 void GblPoint::setLabel(unsigned int aLabel) {
239  theLabel = aLabel;
240 }
241 
243 unsigned int GblPoint::getLabel() const {
244  return theLabel;
245 }
246 
248 
251 void GblPoint::setOffset(int anOffset) {
252  theOffset = anOffset;
253 }
254 
256 int GblPoint::getOffset() const {
257  return theOffset;
258 }
259 
262  return p2pJacobian;
263 }
264 
266 
270  int ifail = 0;
271 // to optimize: need only two last rows of inverse
272 // prevJacobian = aJac.InverseFast(ifail);
273 // block matrix algebra
274  SMatrix23 CA = aJac.Sub<SMatrix23>(3, 0)
275  * aJac.Sub<SMatrix33>(0, 0).InverseFast(ifail); // C*A^-1
276  SMatrix22 DCAB = aJac.Sub<SMatrix22>(3, 3) - CA * aJac.Sub<SMatrix32>(0, 3); // D - C*A^-1 *B
277  DCAB.InvertFast();
278  prevJacobian.Place_at(DCAB, 3, 3);
279  prevJacobian.Place_at(-DCAB * CA, 3, 0);
280 }
281 
283 
287  nextJacobian = aJac;
288 }
289 
291 
299 void GblPoint::getDerivatives(int aDirection, SMatrix22 &matW, SMatrix22 &matWJ,
300  SVector2 &vecWd) const {
301 
302  SMatrix22 matJ;
303  SVector2 vecd;
304  if (aDirection < 1) {
305  matJ = prevJacobian.Sub<SMatrix22>(3, 3);
306  matW = -prevJacobian.Sub<SMatrix22>(3, 1);
307  vecd = prevJacobian.SubCol<SVector2>(0, 3);
308  } else {
309  matJ = nextJacobian.Sub<SMatrix22>(3, 3);
310  matW = nextJacobian.Sub<SMatrix22>(3, 1);
311  vecd = nextJacobian.SubCol<SVector2>(0, 3);
312  }
313 
314  matW.InvertFast();
315  matWJ = matW * matJ;
316  vecWd = matW * vecd;
317 
318 }