GeneralBrokenLines V03-01-03
using EIGEN
GblPoint.h
Go to the documentation of this file.
1/*
2 * GblPoint.h
3 *
4 * Created on: Aug 18, 2011
5 * Author: kleinwrt
6 */
7
32#ifndef GBLPOINT_H_
33#define GBLPOINT_H_
34
35#include "GblMeasurement.h"
36
37#include<iostream>
38#include<vector>
39#include<math.h>
40#include <stdexcept>
41
42#include "Eigen/Dense"
43
44namespace gbl {
45
46typedef Eigen::Matrix<double, 5, 1> Vector5d;
47typedef Eigen::Matrix<double, 2, 3> Matrix23d;
48typedef Eigen::Matrix<double, 2, 5> Matrix25d;
49typedef Eigen::Matrix<double, 3, 2> Matrix32d;
50typedef Eigen::Matrix<double, 5, 5> Matrix5d;
51typedef Eigen::Matrix<double, 4, 9> Matrix49d;
52
54
62class GblPoint {
63public:
64 GblPoint(const Matrix5d &aJacobian, unsigned int numMeasReserve = 0);
65 GblPoint(const GblPoint&) = default;
66 GblPoint& operator=(const GblPoint&) = default;
67 GblPoint(GblPoint&&) = default;
69 virtual ~GblPoint();
70#ifdef GBL_EIGEN_SUPPORT_ROOT
71 // input via ROOT
72 GblPoint(const TMatrixD &aJacobian);
73 void addMeasurement(const TMatrixD &aProjection, const TVectorD &aResiduals,
74 const TVectorD &aPrecision, double minPrecision = 0.);
75 void addMeasurement(const TMatrixD &aProjection, const TVectorD &aResiduals,
76 const TMatrixDSym &aPrecision, double minPrecision = 0.);
77 void addMeasurement(const TVectorD &aResiduals, const TVectorD &aPrecision,
78 double minPrecision = 0.);
79 void addMeasurement(const TVectorD &aResiduals,
80 const TMatrixDSym &aPrecision, double minPrecision = 0.);
81 void addScatterer(const TVectorD &aResiduals, const TVectorD &aPrecision);
82 void addScatterer(const TVectorD &aResiduals,
83 const TMatrixDSym &aPrecision);
84 void addThickScatterer(const TVectorD &aResiduals,
85 const TMatrixDSym &aPrecision);
86 void addLocals(const TMatrixD &aDerivatives);
87 void addGlobals(const std::vector<int> &aLabels,
88 const TMatrixD &aDerivatives);
89#endif
90 // input via Eigen
91
93
105 template<typename Projection, typename Residuals, typename Precision,
106 typename std::enable_if<(Precision::ColsAtCompileTime != 1)>::type* =
107 nullptr>
108 void addMeasurement(const Eigen::MatrixBase<Projection> &aProjection,
109 const Eigen::MatrixBase<Residuals> &aResiduals,
110 const Eigen::MatrixBase<Precision> &aPrecision,
111 double minPrecision = 0.);
112
114
125 template<typename Projection, typename Residuals, typename Precision,
126 typename std::enable_if<(Precision::ColsAtCompileTime == 1)>::type* =
127 nullptr>
128 void addMeasurement(const Eigen::MatrixBase<Projection> &aProjection,
129 const Eigen::MatrixBase<Residuals> &aResiduals,
130 const Eigen::MatrixBase<Precision> &aPrecision,
131 double minPrecision = 0.);
132
134
144 template<typename Residuals, typename Precision, typename std::enable_if<
145 (Precision::ColsAtCompileTime != 1)>::type* = nullptr>
146 void addMeasurement(const Eigen::MatrixBase<Residuals> &aResiduals,
147 const Eigen::MatrixBase<Precision> &aPrecision,
148 double minPrecision = 0.);
149
151
160 template<typename Residuals, typename Precision, typename std::enable_if<
161 (Precision::ColsAtCompileTime == 1)>::type* = nullptr>
162 void addMeasurement(const Eigen::MatrixBase<Residuals> &aResiduals,
163 const Eigen::MatrixBase<Precision> &aPrecision,
164 double minPrecision = 0.);
165
166 void addScatterer(const Eigen::Vector2d &aResiduals,
167 const Eigen::Matrix2d &aPrecision);
168 void addScatterer(const Eigen::Vector2d &aResiduals,
169 const Eigen::Vector2d &aPrecision);
170 void addThickScatterer(const Eigen::Vector4d &aResiduals,
171 const Eigen::Matrix4d &aPrecision);
172
174
179 template<typename Derivative>
180 void addLocals(const Eigen::MatrixBase<Derivative> &aDerivatives);
181 template<typename Derivative>
182
184
190 void addGlobals(const std::vector<int> &aLabels,
191 const Eigen::MatrixBase<Derivative> &aDerivatives);
192 //
193 unsigned int numMeasurements() const;
194 unsigned int getScatDim() const;
195 void getScatterer(Eigen::Matrix4d &aTransformation,
196 Eigen::Vector4d &aResiduals, Eigen::Vector4d &aPrecision) const;
197 void getReducedScatterer(Eigen::Matrix4d &aTransformation,
198 Eigen::Vector4d &aResiduals, Eigen::Vector4d &aPrecision) const;
199 void getScatTransformation(Eigen::MatrixXd &aTransformation) const;
200 unsigned int getLabel() const;
201 int getOffset() const;
202 const Matrix5d& getP2pJacobian() const;
203 void getDerivatives(int aDirection, Eigen::Matrix2d &matW,
204 Eigen::Matrix2d &matWJ, Eigen::Vector2d &vecWd) const;
205 void printPoint(unsigned int level = 0) const;
206 std::vector<GblMeasurement>::iterator getMeasBegin();
207 std::vector<GblMeasurement>::iterator getMeasEnd();
208 void getGlobalLabelsAndDerivatives(unsigned int aMeas, unsigned int aRow,
209 std::vector<int> &aLabels, std::vector<double> &aDerivatives) const;
210 bool isFirst() const;
211 bool isLast() const;
212
213private:
214 friend class GblTrajectory; // to have the following setters private
215 void setLabel(unsigned int aLabel);
216 void setOffset(int anOffset);
217 void setType(int aType);
218 void addPrevJacobian(const Matrix5d &aJac);
219 void addNextJacobian(const Matrix5d &aJac);
220
221 unsigned int theLabel;
224 Matrix5d p2pJacobian = Matrix5d::Zero(5,5);
225 Matrix5d prevJacobian = Matrix5d::Zero(5,5);
226 Matrix5d nextJacobian = Matrix5d::Zero(5,5);
227 unsigned int scatDim;
228 //Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic,
229 // Eigen::ColMajor /* default */, 4, 4> scatTransformation; ///< Transformation of diagonalization (of scat. precision matrix)
230 Eigen::Matrix4d scatTransformation;
231 Eigen::Vector4d scatResiduals;
232 Eigen::Vector4d scatPrecision;
233 std::vector<GblMeasurement> theMeasurements;
234};
235
236template<typename Projection, typename Residuals, typename Precision,
237 typename std::enable_if<(Precision::ColsAtCompileTime != 1)>::type*>
238void GblPoint::addMeasurement(const Eigen::MatrixBase<Projection> &aProjection,
239 const Eigen::MatrixBase<Residuals> &aResiduals,
240 const Eigen::MatrixBase<Precision> &aPrecision, double minPrecision) {
241 static_assert(static_cast<int>(Residuals::ColsAtCompileTime) == 1, "addMeasurement: cols(Residuals) must be 1 (vector)");
242 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) <= 5 or static_cast<int>(Residuals::RowsAtCompileTime) == Eigen::Dynamic, "addMeasurement: rows(Residuals) must be 1-5 or dynamic");
243 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) == static_cast<int>(Precision::RowsAtCompileTime), "addMeasurement: rows(Residuals) and rows(Precision) must be equal");
244 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) == static_cast<int>(Projection::RowsAtCompileTime), "addMeasurement: rows(Residuals) and rows(Projection) must be equal");
245 static_assert(static_cast<int>(Precision::RowsAtCompileTime) == static_cast<int>(Precision::ColsAtCompileTime), "addMeasurement: rows(Precision) and cols(Precision) must be equal");
246 static_assert(static_cast<int>(Projection::RowsAtCompileTime) == static_cast<int>(Projection::ColsAtCompileTime), "addMeasurement: rows(Projection) and cols(Projection) must be equal");
247 theMeasurements.emplace_back(aProjection, aResiduals, aPrecision,
248 minPrecision);
249}
250
251template<typename Projection, typename Residuals, typename Precision,
252 typename std::enable_if<(Precision::ColsAtCompileTime == 1)>::type*>
253void GblPoint::addMeasurement(const Eigen::MatrixBase<Projection> &aProjection,
254 const Eigen::MatrixBase<Residuals> &aResiduals,
255 const Eigen::MatrixBase<Precision> &aPrecision, double minPrecision) {
256 static_assert(static_cast<int>(Residuals::ColsAtCompileTime) == 1, "addMeasurement: cols(Residuals) must be 1 (vector)");
257 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) <= 5 or static_cast<int>(Residuals::RowsAtCompileTime) == Eigen::Dynamic, "addMeasurement: rows(Residuals) must be 1-5 or dynamic");
258 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) == static_cast<int>(Precision::RowsAtCompileTime), "addMeasurement: rows(Residuals) and rows(Precision) must be equal");
259 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) == static_cast<int>(Projection::RowsAtCompileTime), "addMeasurement: rows(Residuals) and rows(Projection) must be equal");
260 static_assert(static_cast<int>(Projection::RowsAtCompileTime) == static_cast<int>(Projection::ColsAtCompileTime), "addMeasurement: rows(Projection) and cols(Projection) must be equal");
261 //theMeasurements.push_back(GblMeasurement(aProjection, aResiduals, aPrecision, minPrecision));
262 theMeasurements.emplace_back(aProjection, aResiduals, aPrecision,
263 minPrecision);
264}
265
266template<typename Residuals, typename Precision, typename std::enable_if<
267 (Precision::ColsAtCompileTime != 1)>::type*>
268void GblPoint::addMeasurement(const Eigen::MatrixBase<Residuals> &aResiduals,
269 const Eigen::MatrixBase<Precision> &aPrecision, double minPrecision) {
270 static_assert(static_cast<int>(Residuals::ColsAtCompileTime) == 1, "addMeasurement: cols(Residuals) must be 1 (vector)");
271 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) <= 5 or static_cast<int>(Residuals::RowsAtCompileTime) == Eigen::Dynamic, "addMeasurement: rows(Residuals) must be 1-5 or dynamic");
272 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) == static_cast<int>(Precision::RowsAtCompileTime), "addMeasurement: rows(Residuals) and rows(Precision) must be equal");
273 theMeasurements.emplace_back(aResiduals, aPrecision, minPrecision);
274}
275
276template<typename Residuals, typename Precision, typename std::enable_if<
277 (Precision::ColsAtCompileTime == 1)>::type*>
278void GblPoint::addMeasurement(const Eigen::MatrixBase<Residuals> &aResiduals,
279 const Eigen::MatrixBase<Precision> &aPrecision, double minPrecision) {
280 static_assert(static_cast<int>(Residuals::ColsAtCompileTime) == 1, "addMeasurement: cols(Residuals) must be 1 (vector)");
281 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) <= 5 or static_cast<int>(Residuals::RowsAtCompileTime) == Eigen::Dynamic, "addMeasurement: rows(Residuals) must be 1-5 or dynamic");
282 static_assert(static_cast<int>(Residuals::RowsAtCompileTime) == static_cast<int>(Precision::RowsAtCompileTime), "addMeasurement: rows(Residuals) and rows(Precision) must be equal");
283 theMeasurements.emplace_back(aResiduals, aPrecision, minPrecision);
284}
285
286template<typename Derivative>
287void GblPoint::addLocals(const Eigen::MatrixBase<Derivative> &aDerivatives) {
288 if (theMeasurements.size())
289 theMeasurements.back().addLocals(aDerivatives);
290}
291
292template<typename Derivative>
293void GblPoint::addGlobals(const std::vector<int> &aLabels,
294 const Eigen::MatrixBase<Derivative> &aDerivatives) {
295 if (theMeasurements.size())
296 theMeasurements.back().addGlobals(aLabels, aDerivatives);
297}
298
299}
300#endif /* GBLPOINT_H_ */
GblMeasurement (with optional derivatives) definition.
Point on trajectory.
Definition: GblPoint.h:62
Matrix5d nextJacobian
Jacobian to next scatterer (or last measurement)
Definition: GblPoint.h:226
void getScatterer(Eigen::Matrix4d &aTransformation, Eigen::Vector4d &aResiduals, Eigen::Vector4d &aPrecision) const
Retrieve scatterer of a point.
Definition: GblPoint.cpp:375
GblPoint & operator=(GblPoint &&)=default
Eigen::Matrix4d scatTransformation
Transformation of diagonalization (of scat. precision matrix)
Definition: GblPoint.h:230
void addMeasurement(const Eigen::MatrixBase< Residuals > &aResiduals, const Eigen::MatrixBase< Precision > &aPrecision, double minPrecision=0.)
Add a measurement to a point.
void addThickScatterer(const Eigen::Vector4d &aResiduals, const Eigen::Matrix4d &aPrecision)
Add a thick scatterer to a point.
Definition: GblPoint.cpp:232
void getScatTransformation(Eigen::MatrixXd &aTransformation) const
Get scatterer transformation (from diagonalization).
Definition: GblPoint.cpp:417
void getDerivatives(int aDirection, Eigen::Matrix2d &matW, Eigen::Matrix2d &matWJ, Eigen::Vector2d &vecWd) const
Retrieve derivatives of local track model.
Definition: GblPoint.cpp:522
void addMeasurement(const Eigen::MatrixBase< Projection > &aProjection, const Eigen::MatrixBase< Residuals > &aResiduals, const Eigen::MatrixBase< Precision > &aPrecision, double minPrecision=0.)
Add a measurement to a point.
Definition: GblPoint.h:238
void getGlobalLabelsAndDerivatives(unsigned int aMeas, unsigned int aRow, std::vector< int > &aLabels, std::vector< double > &aDerivatives) const
Retrieve global derivatives from a measurement at a point for a single row.
Definition: GblPoint.cpp:625
GblPoint(GblPoint &&)=default
void setType(int aType)
Define type for point (by GBLTrajectory constructor)
Definition: GblPoint.cpp:480
void printPoint(unsigned int level=0) const
Print GblPoint.
Definition: GblPoint.cpp:554
void addPrevJacobian(const Matrix5d &aJac)
Define jacobian to previous scatterer (by GBLTrajectory constructor)
Definition: GblPoint.cpp:493
int theType
Type (-1: first, 0: inner, 1: last)
Definition: GblPoint.h:223
GblPoint & operator=(const GblPoint &)=default
std::vector< GblMeasurement > theMeasurements
List of measurements at point.
Definition: GblPoint.h:233
Eigen::Vector4d scatPrecision
Scattering precision (diagonal of inverse covariance matrix)
Definition: GblPoint.h:232
unsigned int numMeasurements() const
Check for measurements at a point.
Definition: GblPoint.cpp:135
void getReducedScatterer(Eigen::Matrix4d &aTransformation, Eigen::Vector4d &aResiduals, Eigen::Vector4d &aPrecision) const
Retrieve (reduced) scatterer of a point.
Definition: GblPoint.cpp:391
unsigned int theLabel
Label identifying point.
Definition: GblPoint.h:221
std::vector< GblMeasurement >::iterator getMeasBegin()
Get GblMeasurement iterator for begin.
Definition: GblPoint.cpp:609
unsigned int scatDim
Dimension of scatterer (0: none, 2: thin, 4:thick)
Definition: GblPoint.h:227
int theOffset
Offset number at point if not negative (else interpolation needed)
Definition: GblPoint.h:222
bool isLast() const
Is last point on (sub)trajectory?
Definition: GblPoint.cpp:638
void setLabel(unsigned int aLabel)
Define label of point (by GBLTrajectory constructor)
Definition: GblPoint.cpp:454
void addLocals(const Eigen::MatrixBase< Derivative > &aDerivatives)
Add local derivatives to a point.
Definition: GblPoint.h:287
void addGlobals(const std::vector< int > &aLabels, const Eigen::MatrixBase< Derivative > &aDerivatives)
Add global derivatives to a point.
Definition: GblPoint.h:293
friend class GblTrajectory
Definition: GblPoint.h:214
void addNextJacobian(const Matrix5d &aJac)
Define jacobian to next scatterer (by GBLTrajectory constructor)
Definition: GblPoint.cpp:508
unsigned int getScatDim() const
Get scatterer dimension.
Definition: GblPoint.cpp:365
unsigned int getLabel() const
Retrieve label of point.
Definition: GblPoint.cpp:459
GblPoint(const Matrix5d &aJacobian, unsigned int numMeasReserve=0)
Create a point.
Definition: GblPoint.cpp:42
Eigen::Vector4d scatResiduals
Scattering residuals (initial kinks if iterating)
Definition: GblPoint.h:231
virtual ~GblPoint()
Definition: GblPoint.cpp:65
Matrix5d prevJacobian
Jacobian to previous scatterer (or first measurement)
Definition: GblPoint.h:225
std::vector< GblMeasurement >::iterator getMeasEnd()
Get GblMeasurement iterator for end.
Definition: GblPoint.cpp:614
GblPoint(const GblPoint &)=default
const Matrix5d & getP2pJacobian() const
Retrieve point-to-(previous)point jacobian.
Definition: GblPoint.cpp:485
void addScatterer(const Eigen::Vector2d &aResiduals, const Eigen::Matrix2d &aPrecision)
Add a thin scatterer to a point.
Definition: GblPoint.cpp:159
void setOffset(int anOffset)
Define offset for point (by GBLTrajectory constructor)
Definition: GblPoint.cpp:467
bool isFirst() const
Is first point on (sub)trajectory?
Definition: GblPoint.cpp:633
Matrix5d p2pJacobian
Point-to-point jacobian from previous point.
Definition: GblPoint.h:224
int getOffset() const
Retrieve offset for point.
Definition: GblPoint.cpp:472
Namespace for the general broken lines package.
Eigen::Matrix< double, 3, 2 > Matrix32d
Eigen::Matrix< double, 2, 5 > Matrix25d
Eigen::Matrix< double, 2, 3 > Matrix23d
Eigen::Matrix< double, 5, 1 > Vector5d
Eigen::Matrix< double, 4, 9 > Matrix49d
Definition: GblData.h:47
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: GblData.h:46