GENFIT Rev: NoNumberAvailable
Loading...
Searching...
No Matches
GblPoint.cc
Go to the documentation of this file.
1/*
2 * GblPoint.cpp
3 *
4 * Created on: Aug 18, 2011
5 * Author: kleinwrt
6 */
7
29
30#include "GblPoint.h"
31
33namespace gbl {
34
36
40GblPoint::GblPoint(const TMatrixD &aJacobian) :
43
44 for (unsigned int i = 0; i < 5; ++i) {
45 for (unsigned int j = 0; j < 5; ++j) {
46 p2pJacobian(i, j) = aJacobian(i, j);
47 }
48 }
49}
50
51GblPoint::GblPoint(const SMatrix55 &aJacobian) :
52 theLabel(0), theOffset(0), p2pJacobian(aJacobian), measDim(0), transFlag(
54
55}
56
59
61
69void GblPoint::addMeasurement(const TMatrixD &aProjection,
70 const TVectorD &aResiduals, const TVectorD &aPrecision,
71 double minPrecision) {
72 measDim = aResiduals.GetNrows();
73 unsigned int iOff = 5 - measDim;
74 for (unsigned int i = 0; i < measDim; ++i) {
75 measResiduals(iOff + i) = aResiduals[i];
76 measPrecision(iOff + i) = (
77 aPrecision[i] >= minPrecision ? aPrecision[i] : 0.);
78 for (unsigned int j = 0; j < measDim; ++j) {
79 measProjection(iOff + i, iOff + j) = aProjection(i, j);
80 }
81 }
82}
83
85
94void GblPoint::addMeasurement(const TMatrixD &aProjection,
95 const TVectorD &aResiduals, const TMatrixDSym &aPrecision,
96 double minPrecision) {
97 measDim = aResiduals.GetNrows();
98 TMatrixDSymEigen measEigen(aPrecision);
100 measTransformation = measEigen.GetEigenVectors();
102 transFlag = true;
103 TVectorD transResiduals = measTransformation * aResiduals;
104 TVectorD transPrecision = measEigen.GetEigenValues();
105 TMatrixD transProjection = measTransformation * aProjection;
106 unsigned int iOff = 5 - measDim;
107 for (unsigned int i = 0; i < measDim; ++i) {
108 measResiduals(iOff + i) = transResiduals[i];
109 measPrecision(iOff + i) = (
110 transPrecision[i] >= minPrecision ? transPrecision[i] : 0.);
111 for (unsigned int j = 0; j < measDim; ++j) {
112 measProjection(iOff + i, iOff + j) = transProjection(i, j);
113 }
114 }
115}
116
118
125void GblPoint::addMeasurement(const TVectorD &aResiduals,
126 const TVectorD &aPrecision, double minPrecision) {
127 measDim = aResiduals.GetNrows();
128 unsigned int iOff = 5 - measDim;
129 for (unsigned int i = 0; i < measDim; ++i) {
130 measResiduals(iOff + i) = aResiduals[i];
131 measPrecision(iOff + i) = (
132 aPrecision[i] >= minPrecision ? aPrecision[i] : 0.);
133 }
134 measProjection = ROOT::Math::SMatrixIdentity();
135}
136
138
146void GblPoint::addMeasurement(const TVectorD &aResiduals,
147 const TMatrixDSym &aPrecision, double minPrecision) {
148 measDim = aResiduals.GetNrows();
149 TMatrixDSymEigen measEigen(aPrecision);
151 measTransformation = measEigen.GetEigenVectors();
153 transFlag = true;
154 TVectorD transResiduals = measTransformation * aResiduals;
155 TVectorD transPrecision = measEigen.GetEigenValues();
156 unsigned int iOff = 5 - measDim;
157 for (unsigned int i = 0; i < measDim; ++i) {
158 measResiduals(iOff + i) = transResiduals[i];
159 measPrecision(iOff + i) = (
160 transPrecision[i] >= minPrecision ? transPrecision[i] : 0.);
161 for (unsigned int j = 0; j < measDim; ++j) {
162 measProjection(iOff + i, iOff + j) = measTransformation(i, j);
163 }
164 }
165}
166
168
172unsigned int GblPoint::hasMeasurement() const {
173 return measDim;
174}
175
177
182void GblPoint::getMeasurement(SMatrix55 &aProjection, SVector5 &aResiduals,
183 SVector5 &aPrecision) const {
184 aProjection = measProjection;
185 aResiduals = measResiduals;
186 aPrecision = measPrecision;
187}
188
190
193void GblPoint::getMeasTransformation(TMatrixD &aTransformation) const {
194 aTransformation.ResizeTo(measDim, measDim);
195 if (transFlag) {
196 aTransformation = measTransformation;
197 } else {
198 aTransformation.UnitMatrix();
199 }
200}
201
203
210void GblPoint::addScatterer(const TVectorD &aResiduals,
211 const TVectorD &aPrecision) {
212 scatFlag = true;
213 scatResiduals(0) = aResiduals[0];
214 scatResiduals(1) = aResiduals[1];
215 scatPrecision(0) = aPrecision[0];
216 scatPrecision(1) = aPrecision[1];
217 scatTransformation = ROOT::Math::SMatrixIdentity();
218}
219
221
236void GblPoint::addScatterer(const TVectorD &aResiduals,
237 const TMatrixDSym &aPrecision) {
238 scatFlag = true;
239 TMatrixDSymEigen scatEigen(aPrecision);
240 TMatrixD aTransformation = scatEigen.GetEigenVectors();
241 aTransformation.T();
242 TVectorD transResiduals = aTransformation * aResiduals;
243 TVectorD transPrecision = scatEigen.GetEigenValues();
244 for (unsigned int i = 0; i < 2; ++i) {
245 scatResiduals(i) = transResiduals[i];
246 scatPrecision(i) = transPrecision[i];
247 for (unsigned int j = 0; j < 2; ++j) {
248 scatTransformation(i, j) = aTransformation(i, j);
249 }
250 }
251}
252
255 return scatFlag;
256}
257
259
264void GblPoint::getScatterer(SMatrix22 &aTransformation, SVector2 &aResiduals,
265 SVector2 &aPrecision) const {
266 aTransformation = scatTransformation;
267 aResiduals = scatResiduals;
268 aPrecision = scatPrecision;
269}
270
272
275void GblPoint::getScatTransformation(TMatrixD &aTransformation) const {
276 aTransformation.ResizeTo(2, 2);
277 if (scatFlag) {
278 for (unsigned int i = 0; i < 2; ++i) {
279 for (unsigned int j = 0; j < 2; ++j) {
280 aTransformation(i, j) = scatTransformation(i, j);
281 }
282 }
283 } else {
284 aTransformation.UnitMatrix();
285 }
286}
287
289
293void GblPoint::addLocals(const TMatrixD &aDerivatives) {
294 if (measDim) {
295 localDerivatives.ResizeTo(aDerivatives);
296 if (transFlag) {
297 localDerivatives = measTransformation * aDerivatives;
298 } else {
299 localDerivatives = aDerivatives;
300 }
301 }
302}
303
305unsigned int GblPoint::getNumLocals() const {
306 return localDerivatives.GetNcols();
307}
308
310const TMatrixD& GblPoint::getLocalDerivatives() const {
311 return localDerivatives;
312}
313
315
320void GblPoint::addGlobals(const std::vector<int> &aLabels,
321 const TMatrixD &aDerivatives) {
322 if (measDim) {
323 globalLabels = aLabels;
324 globalDerivatives.ResizeTo(aDerivatives);
325 if (transFlag) {
326 globalDerivatives = measTransformation * aDerivatives;
327 } else {
328 globalDerivatives = aDerivatives;
329 }
330
331 }
332}
333
335unsigned int GblPoint::getNumGlobals() const {
336 return globalDerivatives.GetNcols();
337}
338
340std::vector<int> GblPoint::getGlobalLabels() const {
341 return globalLabels;
342}
343
345const TMatrixD& GblPoint::getGlobalDerivatives() const {
346 return globalDerivatives;
347}
348
350
353void GblPoint::setLabel(unsigned int aLabel) {
354 theLabel = aLabel;
355}
356
358unsigned int GblPoint::getLabel() const {
359 return theLabel;
360}
361
363
366void GblPoint::setOffset(int anOffset) {
367 theOffset = anOffset;
368}
369
372 return theOffset;
373}
374
377 return p2pJacobian;
378}
379
381
385 int ifail = 0;
386// to optimize: need only two last rows of inverse
387// prevJacobian = aJac.InverseFast(ifail);
388// block matrix algebra
389 SMatrix23 CA = aJac.Sub<SMatrix23>(3, 0)
390 * aJac.Sub<SMatrix33>(0, 0).InverseFast(ifail); // C*A^-1
391 SMatrix22 DCAB = aJac.Sub<SMatrix22>(3, 3) - CA * aJac.Sub<SMatrix32>(0, 3); // D - C*A^-1 *B
392 DCAB.InvertFast();
393 prevJacobian.Place_at(DCAB, 3, 3);
394 prevJacobian.Place_at(-DCAB * CA, 3, 0);
395}
396
398
402 nextJacobian = aJac;
403}
404
406
415void GblPoint::getDerivatives(int aDirection, SMatrix22 &matW, SMatrix22 &matWJ,
416 SVector2 &vecWd) const {
417
418 SMatrix22 matJ;
419 SVector2 vecd;
420 if (aDirection < 1) {
421 matJ = prevJacobian.Sub<SMatrix22>(3, 3);
422 matW = -prevJacobian.Sub<SMatrix22>(3, 1);
423 vecd = prevJacobian.SubCol<SVector2>(0, 3);
424 } else {
425 matJ = nextJacobian.Sub<SMatrix22>(3, 3);
426 matW = nextJacobian.Sub<SMatrix22>(3, 1);
427 vecd = nextJacobian.SubCol<SVector2>(0, 3);
428 }
429
430 if (!matW.InvertFast()) {
431 std::cout << " GblPoint::getDerivatives failed to invert matrix: "
432 << matW << std::endl;
433 std::cout
434 << " Possible reason for singular matrix: multiple GblPoints at same arc-length"
435 << std::endl;
436 throw std::overflow_error("Singular matrix inversion exception");
437 }
438 matWJ = matW * matJ;
439 vecWd = matW * vecd;
440
441}
442
444
447void GblPoint::printPoint(unsigned int level) const {
448 std::cout << " GblPoint";
449 if (theLabel) {
450 std::cout << ", label " << theLabel;
451 if (theOffset >= 0) {
452 std::cout << ", offset " << theOffset;
453 }
454 }
455 if (measDim) {
456 std::cout << ", " << measDim << " measurements";
457 }
458 if (scatFlag) {
459 std::cout << ", scatterer";
460 }
461 if (transFlag) {
462 std::cout << ", diagonalized";
463 }
464 if (localDerivatives.GetNcols()) {
465 std::cout << ", " << localDerivatives.GetNcols()
466 << " local derivatives";
467 }
468 if (globalDerivatives.GetNcols()) {
469 std::cout << ", " << globalDerivatives.GetNcols()
470 << " global derivatives";
471 }
472 std::cout << std::endl;
473 if (level > 0) {
474 if (measDim) {
475 std::cout << " Measurement" << std::endl;
476 std::cout << " Projection: " << std::endl << measProjection
477 << std::endl;
478 std::cout << " Residuals: " << measResiduals << std::endl;
479 std::cout << " Precision: " << measPrecision << std::endl;
480 }
481 if (scatFlag) {
482 std::cout << " Scatterer" << std::endl;
483 std::cout << " Residuals: " << scatResiduals << std::endl;
484 std::cout << " Precision: " << scatPrecision << std::endl;
485 }
486 if (localDerivatives.GetNcols()) {
487 std::cout << " Local Derivatives:" << std::endl;
488 localDerivatives.Print();
489 }
490 if (globalDerivatives.GetNcols()) {
491 std::cout << " Global Labels:";
492 for (unsigned int i = 0; i < globalLabels.size(); ++i) {
493 std::cout << " " << globalLabels[i];
494 }
495 std::cout << std::endl;
496 std::cout << " Global Derivatives:" << std::endl;
497 globalDerivatives.Print();
498 }
499 std::cout << " Jacobian " << std::endl;
500 std::cout << " Point-to-point " << std::endl << p2pJacobian
501 << std::endl;
502 if (theLabel) {
503 std::cout << " To previous offset " << std::endl << prevJacobian
504 << std::endl;
505 std::cout << " To next offset " << std::endl << nextJacobian
506 << std::endl;
507 }
508 }
509}
510
511}
ROOT::Math::SMatrix< double, 5, 5 > SMatrix55
Definition GblData.h:45
ROOT::Math::SMatrix< double, 3 > SMatrix33
Definition GblPoint.h:49
ROOT::Math::SVector< double, 5 > SVector5
Definition GblPoint.h:52
ROOT::Math::SVector< double, 2 > SVector2
Definition GblPoint.h:51
ROOT::Math::SMatrix< double, 3, 2 > SMatrix32
Definition GblPoint.h:48
ROOT::Math::SMatrix< double, 2 > SMatrix22
Definition GblPoint.h:44
ROOT::Math::SMatrix< double, 2, 3 > SMatrix23
Definition GblPoint.h:45
GblPoint(const TMatrixD &aJacobian)
Create a point.
Definition GblPoint.cc:40
std::vector< int > getGlobalLabels() const
Retrieve global derivatives labels from a point.
Definition GblPoint.cc:340
TMatrixD localDerivatives
Derivatives of measurement vs additional local (fit) parameters.
Definition GblPoint.h:127
std::vector< int > globalLabels
Labels of global (MP-II) derivatives.
Definition GblPoint.h:128
void addMeasurement(const TMatrixD &aProjection, const TVectorD &aResiduals, const TVectorD &aPrecision, double minPrecision=0.)
Add a measurement to a point.
Definition GblPoint.cc:69
SMatrix55 nextJacobian
Jacobian to next scatterer (or last measurement)
Definition GblPoint.h:116
void getScatterer(SMatrix22 &aTransformation, SVector2 &aResiduals, SVector2 &aPrecision) const
Retrieve scatterer of a point.
Definition GblPoint.cc:264
TMatrixD measTransformation
Transformation of diagonalization (of meas. precision matrix)
Definition GblPoint.h:122
void printPoint(unsigned int level=0) const
Print GblPoint.
Definition GblPoint.cc:447
void getDerivatives(int aDirection, SMatrix22 &matW, SMatrix22 &matWJ, SVector2 &vecWd) const
Retrieve derivatives of local track model.
Definition GblPoint.cc:415
bool scatFlag
Scatterer present?
Definition GblPoint.h:123
void addScatterer(const TVectorD &aResiduals, const TVectorD &aPrecision)
Add a (thin) scatterer to a point.
Definition GblPoint.cc:210
unsigned int hasMeasurement() const
Check for measurement at a point.
Definition GblPoint.cc:172
unsigned int measDim
Dimension of measurement (1-5), 0 indicates absence of measurement.
Definition GblPoint.h:117
const SMatrix55 & getP2pJacobian() const
Retrieve point-to-(previous)point jacobian.
Definition GblPoint.cc:376
bool transFlag
Transformation exists?
Definition GblPoint.h:121
bool hasScatterer() const
Check for scatterer at a point.
Definition GblPoint.cc:254
void getMeasTransformation(TMatrixD &aTransformation) const
Get measurement transformation (from diagonalization).
Definition GblPoint.cc:193
const TMatrixD & getGlobalDerivatives() const
Retrieve global derivatives from a point.
Definition GblPoint.cc:345
void getMeasurement(SMatrix55 &aProjection, SVector5 &aResiduals, SVector5 &aPrecision) const
Retrieve measurement of a point.
Definition GblPoint.cc:182
void addLocals(const TMatrixD &aDerivatives)
Add local derivatives to a point.
Definition GblPoint.cc:293
SVector2 scatResiduals
Scattering residuals (initial kinks if iterating)
Definition GblPoint.h:125
unsigned int theLabel
Label identifying point.
Definition GblPoint.h:112
unsigned int getNumLocals() const
Retrieve number of local derivatives from a point.
Definition GblPoint.cc:305
int theOffset
Offset number at point if not negative (else interpolation needed)
Definition GblPoint.h:113
void addGlobals(const std::vector< int > &aLabels, const TMatrixD &aDerivatives)
Add global derivatives to a point.
Definition GblPoint.cc:320
void addNextJacobian(const SMatrix55 &aJac)
Define jacobian to next scatterer (by GBLTrajectory constructor)
Definition GblPoint.cc:401
void setLabel(unsigned int aLabel)
Define label of point (by GBLTrajectory constructor)
Definition GblPoint.cc:353
TMatrixD globalDerivatives
Derivatives of measurement vs additional global (MP-II) parameters.
Definition GblPoint.h:129
void addPrevJacobian(const SMatrix55 &aJac)
Define jacobian to previous scatterer (by GBLTrajectory constructor)
Definition GblPoint.cc:384
unsigned int getLabel() const
Retrieve label of point.
Definition GblPoint.cc:358
SMatrix22 scatTransformation
Transformation of diagonalization (of scat. precision matrix)
Definition GblPoint.h:124
SVector2 scatPrecision
Scattering precision (diagonal of inverse covariance matrix)
Definition GblPoint.h:126
const TMatrixD & getLocalDerivatives() const
Retrieve local derivatives from a point.
Definition GblPoint.cc:310
virtual ~GblPoint()
Definition GblPoint.cc:57
SVector5 measPrecision
Measurement precision (diagonal of inverse covariance matrix)
Definition GblPoint.h:120
SMatrix55 measProjection
Projection from measurement to local system.
Definition GblPoint.h:118
SMatrix55 p2pJacobian
Point-to-point jacobian from previous point.
Definition GblPoint.h:114
void setOffset(int anOffset)
Define offset for point (by GBLTrajectory constructor)
Definition GblPoint.cc:366
unsigned int getNumGlobals() const
Retrieve number of global derivatives from a point.
Definition GblPoint.cc:335
SVector5 measResiduals
Measurement residuals.
Definition GblPoint.h:119
SMatrix55 prevJacobian
Jacobian to previous scatterer (or first measurement)
Definition GblPoint.h:115
void getScatTransformation(TMatrixD &aTransformation) const
Get scatterer transformation (from diagonalization).
Definition GblPoint.cc:275
int getOffset() const
Retrieve offset for point.
Definition GblPoint.cc:371
Namespace for the general broken lines package.