GeneralBrokenLines V03-01-03
using EIGEN
GblMeasurement.cpp
Go to the documentation of this file.
1/*
2 * GBLMeasurement.cpp
3 *
4 * Created on: 31 Mar 2021
5 * Author: kleinwrt
6 */
7
30#include "GblMeasurement.h"
31using namespace Eigen;
32
34namespace gbl {
35
37
46GblMeasurement::GblMeasurement(const Eigen::MatrixXd &aProjection,
47 const Eigen::VectorXd &aResiduals, const Eigen::MatrixXd &aPrecision,
48 double minPrecision) {
49 enabled = true;
50 measDim = aResiduals.rows();
51 measPrecMin = minPrecision;
52 if (aPrecision.cols() > 1) {
53 // arbitrary precision matrix
54 SelfAdjointEigenSolver<MatrixXd> measEigen(aPrecision);
55 measTransformation = measEigen.eigenvectors();
56 measTransformation.transposeInPlace();
57 transFlag = true;
58 measResiduals.tail(measDim) = measTransformation * aResiduals;
59 measPrecision.tail(measDim) = measEigen.eigenvalues();
61 * aProjection;
62 } else {
63 // diagonal precision matrix
64 transFlag = false;
65 measResiduals.tail(measDim) = aResiduals;
66 measPrecision.tail(measDim) = aPrecision;
67 measProjection.bottomRightCorner(measDim, measDim) = aProjection;
68 }
69}
70
72
80GblMeasurement::GblMeasurement(const Eigen::VectorXd &aResiduals,
81 const Eigen::MatrixXd &aPrecision, double minPrecision) {
82 enabled = true;
83 measDim = aResiduals.rows();
84 measPrecMin = minPrecision;
85 if (aPrecision.cols() > 1) {
86 // arbitrary precision matrix
87 SelfAdjointEigenSolver<MatrixXd> measEigen(aPrecision);
88 measTransformation = measEigen.eigenvectors();
89 measTransformation.transposeInPlace();
90 transFlag = true;
91 measResiduals.tail(measDim) = measTransformation * aResiduals;
92 measPrecision.tail(measDim) = measEigen.eigenvalues();
94 } else {
95 // diagonal precision matrix
96 transFlag = false;
97 measResiduals.tail(measDim) = aResiduals;
98 measPrecision.tail(measDim) = aPrecision;
99 measProjection.setIdentity();
100 }
101}
102
104}
105
106#ifdef GBL_EIGEN_SUPPORT_ROOT
108
116GblMeasurement::GblMeasurement(const TMatrixD &aProjection,
117 const TVectorD &aResiduals, const TVectorD &aPrecision,
118 double minPrecision) {
119 enabled = true;
120 measDim = aResiduals.GetNrows();
121 measPrecMin = minPrecision;
122 transFlag = false;
123 unsigned int iOff = 5 - measDim;
124 for (unsigned int i = 0; i < measDim; ++i) {
125 measResiduals(iOff + i) = aResiduals[i];
126 measPrecision(iOff + i) = aPrecision[i];
127 for (unsigned int j = 0; j < measDim; ++j) {
128 measProjection(iOff + i, iOff + j) = aProjection(i, j);
129 }
130 }
131}
132
134
143GblMeasurement::GblMeasurement(const TMatrixD &aProjection,
144 const TVectorD &aResiduals, const TMatrixDSym &aPrecision,
145 double minPrecision) {
146 enabled = true;
147 measDim = aResiduals.GetNrows();
148 measPrecMin = minPrecision;
149 TMatrixDSymEigen measEigen(aPrecision);
150 TMatrixD tmpTransformation(measDim, measDim);
151 tmpTransformation = measEigen.GetEigenVectors();
152 tmpTransformation.T();
153 transFlag = true;
154 TVectorD transResiduals = tmpTransformation * aResiduals;
155 TVectorD transPrecision = measEigen.GetEigenValues();
156 TMatrixD transProjection = tmpTransformation * aProjection;
158 unsigned int iOff = 5 - measDim;
159 for (unsigned int i = 0; i < measDim; ++i) {
160 measResiduals(iOff + i) = transResiduals[i];
161 measPrecision(iOff + i) = transPrecision[i];
162 for (unsigned int j = 0; j < measDim; ++j) {
163 measTransformation(i, j) = tmpTransformation(i, j);
164 measProjection(iOff + i, iOff + j) = transProjection(i, j);
165 }
166 }
167}
168
170
177GblMeasurement::GblMeasurement(const TVectorD &aResiduals,
178 const TVectorD &aPrecision, double minPrecision) {
179 enabled = true;
180 measDim = aResiduals.GetNrows();
181 measPrecMin = minPrecision;
182 transFlag = false;
183 unsigned int iOff = 5 - measDim;
184 for (unsigned int i = 0; i < measDim; ++i) {
185 measResiduals(iOff + i) = aResiduals[i];
186 measPrecision(iOff + i) = aPrecision[i];
187 }
188 measProjection.setIdentity();
189}
190
192
200GblMeasurement::GblMeasurement(const TVectorD &aResiduals,
201 const TMatrixDSym &aPrecision, double minPrecision) {
202 enabled = true;
203 measDim = aResiduals.GetNrows();
204 measPrecMin = minPrecision;
205 TMatrixDSymEigen measEigen(aPrecision);
206 TMatrixD tmpTransformation(measDim, measDim);
207 tmpTransformation = measEigen.GetEigenVectors();
208 tmpTransformation.T();
209 transFlag = true;
210 TVectorD transResiduals = tmpTransformation * aResiduals;
211 TVectorD transPrecision = measEigen.GetEigenValues();
213 unsigned int iOff = 5 - measDim;
214 for (unsigned int i = 0; i < measDim; ++i) {
215 measResiduals(iOff + i) = transResiduals[i];
216 measPrecision(iOff + i) = transPrecision[i];
217 for (unsigned int j = 0; j < measDim; ++j) {
218 measTransformation(i, j) = tmpTransformation(i, j);
219 measProjection(iOff + i, iOff + j) = measTransformation(i, j);
220 }
221 }
222}
223#endif
224
226
230void GblMeasurement::addLocals(const Eigen::MatrixXd &aDerivatives) {
231 if (measDim) {
232 localDerivatives.resize(aDerivatives.rows(), aDerivatives.cols());
233 if (transFlag) {
234 localDerivatives = measTransformation * aDerivatives;
235 } else {
236 localDerivatives = aDerivatives;
237 }
238 }
239}
240
242
247void GblMeasurement::addGlobals(const std::vector<int> &aLabels,
248 const Eigen::MatrixXd &aDerivatives) {
249 if (measDim) {
250 globalLabels = aLabels;
251 globalDerivatives.resize(aDerivatives.rows(), aDerivatives.cols());
252 if (transFlag) {
253 globalDerivatives = measTransformation * aDerivatives;
254 } else {
255 globalDerivatives = aDerivatives;
256 }
257
258 }
259}
260
261#ifdef GBL_EIGEN_SUPPORT_ROOT
263
267void GblMeasurement::addLocals(const TMatrixD &aDerivatives) {
268 if (measDim) {
269 unsigned int numDer = aDerivatives.GetNcols();
270 localDerivatives.resize(measDim, numDer);
271 // convert from ROOT
272 MatrixXd tmpDerivatives(measDim, numDer);
273 for (unsigned int i = 0; i < measDim; ++i) {
274 for (unsigned int j = 0; j < numDer; ++j)
275 tmpDerivatives(i, j) = aDerivatives(i, j);
276 }
277 if (transFlag) {
278 localDerivatives = measTransformation * tmpDerivatives;
279 } else {
280 localDerivatives = tmpDerivatives;
281 }
282 }
283}
284
286
291void GblMeasurement::addGlobals(const std::vector<int> &aLabels,
292 const TMatrixD &aDerivatives) {
293 if (measDim) {
294 globalLabels = aLabels;
295 unsigned int numDer = aDerivatives.GetNcols();
296 globalDerivatives.resize(measDim, numDer);
297 // convert from ROOT
298 MatrixXd tmpDerivatives(measDim, numDer);
299 for (unsigned int i = 0; i < measDim; ++i) {
300 for (unsigned int j = 0; j < numDer; ++j)
301 tmpDerivatives(i, j) = aDerivatives(i, j);
302 }
303 if (transFlag) {
304 globalDerivatives = measTransformation * tmpDerivatives;
305 } else {
306 globalDerivatives = tmpDerivatives;
307 }
308 }
309}
310#endif
311
313
320 enabled = flag;
321}
322
324
328 return enabled;
329}
330
332
336unsigned int GblMeasurement::getMeasDim() const {
337 return measDim;
338}
339
341
345 return measPrecMin;
346}
347
349
354void GblMeasurement::getMeasurement(Matrix5d &aProjection, Vector5d &aResiduals,
355 Vector5d &aPrecision) const {
356 aProjection.bottomRightCorner(measDim, measDim) =
357 measProjection.bottomRightCorner(measDim, measDim);
358 aResiduals.tail(measDim) = measResiduals.tail(measDim);
359 aPrecision.tail(measDim) = measPrecision.tail(measDim);
360}
361
363
366void GblMeasurement::getMeasTransformation(MatrixXd &aTransformation) const {
367 aTransformation.resize(measDim, measDim);
368 if (transFlag) {
369 aTransformation = measTransformation;
370 } else {
371 aTransformation.setIdentity();
372 }
373}
374
376unsigned int GblMeasurement::getNumLocals() const {
377 return localDerivatives.cols();
378}
379
381const MatrixXd& GblMeasurement::getLocalDerivatives() const {
382 return localDerivatives;
383}
384
386unsigned int GblMeasurement::getNumGlobals() const {
387 return globalDerivatives.cols();
388}
389
391
394void GblMeasurement::getGlobalLabels(std::vector<int> &aLabels) const {
395 aLabels = globalLabels;
396}
397
399
402void GblMeasurement::getGlobalDerivatives(MatrixXd &aDerivatives) const {
403 aDerivatives = globalDerivatives;
404}
405
407
413 std::vector<int> &aLabels, std::vector<double> &aDerivatives) const {
414 aLabels.resize(globalDerivatives.cols());
415 aDerivatives.resize(globalDerivatives.cols());
416 for (unsigned int i = 0; i < globalDerivatives.cols(); ++i) {
417 aLabels[i] = globalLabels[i];
418 aDerivatives[i] = globalDerivatives(aRow, i);
419 }
420}
421
423
426void GblMeasurement::printMeasurement(unsigned int level) const {
427 if (level > 0)
428 std::cout << " GblMeasurement";
429
430 if (measDim) {
431 std::cout << ", " << measDim << " dimensions";
432 }
433 if (!enabled) {
434 std::cout << ", disabled";
435 }
436 if (transFlag) {
437 std::cout << ", diagonalized";
438 }
439 if (localDerivatives.cols()) {
440 std::cout << ", " << localDerivatives.cols() << " local derivatives";
441 }
442 if (globalDerivatives.cols()) {
443 std::cout << ", " << globalDerivatives.cols() << " global derivatives";
444 }
445 if (level > 0) {
446 std::cout << std::endl;
447 IOFormat CleanFmt(4, 0, ", ", "\n", "[", "]");
448 if (measDim) {
449 std::cout << " Projection: " << std::endl
450 << measProjection.bottomRightCorner(measDim, measDim).format(
451 CleanFmt) << std::endl;
452 std::cout << " Residuals: "
453 << measResiduals.tail(measDim).transpose().format(CleanFmt)
454 << std::endl;
455 std::cout << " Precision (min.: " << measPrecMin << "): "
456 << measPrecision.tail(measDim).transpose().format(CleanFmt)
457 << std::endl;
458 }
459 if (localDerivatives.cols()) {
460 std::cout << " Local Derivatives:" << std::endl
461 << localDerivatives.format(CleanFmt) << std::endl;
462 }
463 if (globalDerivatives.cols()) {
464 std::cout << " Global Labels:";
465 for (unsigned int i = 0; i < globalLabels.size(); ++i) {
466 std::cout << " " << globalLabels[i];
467 }
468 std::cout << std::endl;
469 std::cout << " Global Derivatives:"
470 << globalDerivatives.format(CleanFmt) << std::endl;
471 }
472 }
473}
474
475}
GblMeasurement (with optional derivatives) definition.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor, 5, 5 > measTransformation
Transformation of diagonalization (of meas. precision matrix)
double getMeasPrecMin() const
get precision cutoff.
unsigned int getNumGlobals() const
Retrieve number of global derivatives from a point.
Vector5d measPrecision
Measurement precision (diagonal of inverse covariance matrix)
void addLocals(const Eigen::MatrixXd &aDerivatives)
Add local derivatives.
void getGlobalLabelsAndDerivatives(unsigned int aRow, std::vector< int > &aLabels, std::vector< double > &aDerivatives) const
Retrieve global derivatives from a point for a single row.
GblMeasurement(const Eigen::MatrixXd &aProjection, const Eigen::VectorXd &aResiduals, const Eigen::MatrixXd &aPrecision, double minPrecision=0.)
Create a measurement.
void getGlobalDerivatives(Eigen::MatrixXd &aDerivatives) const
Retrieve global derivatives from a point.
Eigen::MatrixXd globalDerivatives
Derivatives of measurement vs additional global (MP-II) parameters.
bool transFlag
Transformation exists?
double measPrecMin
Minimal measurement precision (for usage)
bool enabled
Enabled flag (to be used)
void getMeasTransformation(Eigen::MatrixXd &aTransformation) const
Get measurement transformation (from diagonalization).
void getGlobalLabels(std::vector< int > &aLabels) const
Retrieve global derivatives labels from a point.
Matrix5d measProjection
Projection from measurement to local system.
bool isEnabled() const
Get enabled flag.
void getMeasurement(Matrix5d &aProjection, Vector5d &aResiduals, Vector5d &aPrecision) const
Retrieve measurement of a point.
void printMeasurement(unsigned int level=0) const
Print GblMeasurement.
Eigen::MatrixXd localDerivatives
Derivatives of measurement vs additional local (fit) parameters.
unsigned int getNumLocals() const
Retrieve number of local derivatives from a point.
Vector5d measResiduals
Measurement residuals.
std::vector< int > globalLabels
Labels of global (MP-II) derivatives.
unsigned int getMeasDim() const
Get measurement dimension.
unsigned int measDim
Dimension of measurement (1-5), 0 indicates absence of measurement.
void setEnabled(bool flag)
Set enabled flag.
const Eigen::MatrixXd & getLocalDerivatives() const
Retrieve local derivatives from a point.
void addGlobals(const std::vector< int > &aLabels, const Eigen::MatrixXd &aDerivatives)
Add global derivatives.
Namespace for the general broken lines package.
Eigen::Matrix< double, 5, 1 > Vector5d
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: GblData.h:46