CMS 3D CMS Logo

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 
30 #ifndef GBLPOINT_H_
31 #define GBLPOINT_H_
32 
33 #include<iostream>
34 #include<vector>
35 #include<math.h>
36 #include <stdexcept>
37 #ifdef GBL_EIGEN_SUPPORT_ROOT
38 #include "TVectorD.h"
39 #include "TMatrixD.h"
40 #include "TMatrixDSym.h"
41 #include "TMatrixDSymEigen.h"
42 #endif
43 
44 #include "Eigen/Dense"
45 
46 namespace gbl {
47  typedef Eigen::Matrix<double, 5, 1> Vector5d;
48  typedef Eigen::Matrix<double, 2, 3> Matrix23d;
49  typedef Eigen::Matrix<double, 2, 5> Matrix25d;
50  typedef Eigen::Matrix<double, 2, 7> Matrix27d;
51  typedef Eigen::Matrix<double, 3, 2> Matrix32d;
52  typedef Eigen::Matrix<double, 5, 5> Matrix5d;
53 
55 
66  class GblPoint {
67  public:
68  GblPoint(const Matrix5d &aJacobian);
69  GblPoint(const GblPoint&) = default;
70  GblPoint& operator=(const GblPoint&) = default;
71  GblPoint(GblPoint&&) = default;
72  GblPoint& operator=(GblPoint&&) = default;
73  virtual ~GblPoint();
74 #ifdef GBL_EIGEN_SUPPORT_ROOT
75  // input via ROOT
76  GblPoint(const TMatrixD &aJacobian);
77  void addMeasurement(const TMatrixD &aProjection, const TVectorD &aResiduals,
78  const TVectorD &aPrecision, double minPrecision = 0.);
79  void addMeasurement(const TMatrixD &aProjection, const TVectorD &aResiduals,
80  const TMatrixDSym &aPrecision, double minPrecision = 0.);
81  void addMeasurement(const TVectorD &aResiduals, const TVectorD &aPrecision,
82  double minPrecision = 0.);
83  void addMeasurement(const TVectorD &aResiduals,
84  const TMatrixDSym &aPrecision, double minPrecision = 0.);
85  void addScatterer(const TVectorD &aResiduals, const TVectorD &aPrecision);
86  void addScatterer(const TVectorD &aResiduals,
87  const TMatrixDSym &aPrecision);
88  void addLocals(const TMatrixD &aDerivatives);
89  void addGlobals(const std::vector<int> &aLabels,
90  const TMatrixD &aDerivatives);
91 #endif
92  // input via Eigen
93  template <typename Projection, typename Residuals, typename Precision,
96  void addMeasurement(const Eigen::MatrixBase<Projection>& aProjection,
97  const Eigen::MatrixBase<Residuals>& aResiduals,
98  const Eigen::MatrixBase<Precision>& aPrecision,
99  double minPrecision = 0.);
100  template <typename Projection, typename Residuals, typename Precision,
101  typename std::enable_if<(Residuals::ColsAtCompileTime == 1)>::type* = nullptr,
103  void addMeasurement(const Eigen::MatrixBase<Projection>& aProjection,
104  const Eigen::MatrixBase<Residuals>& aResiduals,
105  const Eigen::MatrixBase<Precision>& aPrecision,
106  double minPrecision = 0.);
107  template <typename Residuals, typename Precision,
108  typename std::enable_if<(Residuals::ColsAtCompileTime == 1)>::type* = nullptr,
110  void addMeasurement(const Eigen::MatrixBase<Residuals>& aResiduals,
111  const Eigen::MatrixBase<Precision>& aPrecision,
112  double minPrecision = 0.);
113  template <typename Residuals, typename Precision,
114  typename std::enable_if<(Residuals::ColsAtCompileTime == 1)>::type* = nullptr,
116  void addMeasurement(const Eigen::MatrixBase<Residuals>& aResiduals,
117  const Eigen::MatrixBase<Precision>& aPrecision,
118  double minPrecision = 0.);
119  template <typename Precision>
120  void addScatterer(const Eigen::Vector2d &aResiduals,
121  const Eigen::MatrixBase<Precision>& aPrecision);
122  void addScatterer(const Eigen::Vector2d &aResiduals,
123  const Eigen::Vector2d& aPrecision);
124  //
125  unsigned int hasMeasurement() const;
126  double getMeasPrecMin() const;
127  void getMeasurement(Matrix5d &aProjection, Vector5d &aResiduals,
128  Vector5d &aPrecision) const;
129  void getMeasTransformation(Eigen::MatrixXd &aTransformation) const;
130  bool hasScatterer() const;
131  void getScatterer(Eigen::Matrix2d &aTransformation, Eigen::Vector2d &aResiduals,
132  Eigen::Vector2d &aPrecision) const;
133  void getScatTransformation(Eigen::Matrix2d &aTransformation) const;
134  template <typename Derivative>
135  void addLocals(const Eigen::MatrixBase<Derivative>& aDerivatives);
136  unsigned int getNumLocals() const;
137  const Eigen::MatrixXd& getLocalDerivatives() const;
138  template <typename Derivative>
139  void addGlobals(const std::vector<int> &aLabels,
140  const Eigen::MatrixBase<Derivative>& aDerivatives);
141  unsigned int getNumGlobals() const;
142  void getGlobalLabels(std::vector<int> &aLabels) const;
143  void getGlobalDerivatives(Eigen::MatrixXd &aDerivatives) const;
144  void getGlobalLabelsAndDerivatives(unsigned int aRow,
145  std::vector<int> &aLabels, std::vector<double> &aDerivatives) const;
146  void setLabel(unsigned int aLabel);
147  unsigned int getLabel() const;
148  void setOffset(int anOffset);
149  int getOffset() const;
150  const Matrix5d& getP2pJacobian() const;
151  void addPrevJacobian(const Matrix5d &aJac);
152  void addNextJacobian(const Matrix5d &aJac);
153  void getDerivatives(int aDirection, Eigen::Matrix2d &matW, Eigen::Matrix2d &matWJ,
154  Eigen::Vector2d &vecWd) const;
155  void printPoint(unsigned int level = 0) const;
156 
157  private:
158  unsigned int theLabel;
159  int theOffset;
160  Matrix5d p2pJacobian;
161  Matrix5d prevJacobian;
162  Matrix5d nextJacobian;
163  unsigned int measDim;
164  double measPrecMin;
165  Matrix5d measProjection;
166  Vector5d measResiduals;
167  Vector5d measPrecision;
168  bool transFlag;
169  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic,
170  Eigen::ColMajor /* default */, 5, 5> measTransformation;
171  bool scatFlag;
172  Eigen::Matrix2d scatTransformation;
173  Eigen::Vector2d scatResiduals;
174  Eigen::Vector2d scatPrecision;
175  Eigen::MatrixXd localDerivatives;
176  std::vector<int> globalLabels;
177  Eigen::MatrixXd globalDerivatives;
178  };
179 
180 
182 
191  template <typename Projection, typename Residuals, typename Precision,
194  void GblPoint::addMeasurement(const Eigen::MatrixBase<Projection>& aProjection,
195  const Eigen::MatrixBase<Residuals>& aResiduals,
196  const Eigen::MatrixBase<Precision>& aPrecision,
197  double minPrecision)
198  {
199  measDim = aResiduals.rows();
200  measPrecMin = minPrecision;
201  // arbitrary precision matrix
202  Eigen::SelfAdjointEigenSolver<typename Precision::PlainObject> measEigen{aPrecision};
203  measTransformation = measEigen.eigenvectors().transpose();
204  transFlag = true;
205  measResiduals.tail(measDim) = measTransformation * aResiduals;
206  measPrecision.tail(measDim) = measEigen.eigenvalues();
207  measProjection.bottomRightCorner(measDim, measDim) =
208  measTransformation * aProjection;
209  }
210 
212 
221  template <typename Projection, typename Residuals, typename Precision,
222  typename std::enable_if<(Residuals::ColsAtCompileTime == 1)>::type*,
224  void GblPoint::addMeasurement(const Eigen::MatrixBase<Projection>& aProjection,
225  const Eigen::MatrixBase<Residuals>& aResiduals,
226  const Eigen::MatrixBase<Precision>& aPrecision,
227  double minPrecision)
228  {
229  measDim = aResiduals.rows();
230  measPrecMin = minPrecision;
231  // diagonal precision matrix
232  measResiduals.tail(measDim) = aResiduals;
233  measPrecision.tail(measDim) = aPrecision;
234  measProjection.bottomRightCorner(measDim, measDim) = aProjection;
235  }
236 
238 
246  template <typename Residuals, typename Precision,
247  typename std::enable_if<(Residuals::ColsAtCompileTime == 1)>::type*,
249  void GblPoint::addMeasurement(const Eigen::MatrixBase<Residuals>& aResiduals,
250  const Eigen::MatrixBase<Precision>& aPrecision,
251  double minPrecision)
252  {
253  measDim = aResiduals.rows();
254  measPrecMin = minPrecision;
255  // arbitrary precision matrix
256  Eigen::SelfAdjointEigenSolver<typename Precision::PlainObject> measEigen{aPrecision};
257  measTransformation = measEigen.eigenvectors().transpose();
258  transFlag = true;
259  measResiduals.tail(measDim) = measTransformation * aResiduals;
260  measPrecision.tail(measDim) = measEigen.eigenvalues();
261  measProjection.bottomRightCorner(measDim, measDim) = measTransformation;
262  }
263 
265 
273  template <typename Residuals, typename Precision,
274  typename std::enable_if<(Residuals::ColsAtCompileTime == 1)>::type*,
276  void GblPoint::addMeasurement(const Eigen::MatrixBase<Residuals>& aResiduals,
277  const Eigen::MatrixBase<Precision>& aPrecision,
278  double minPrecision)
279  {
280  measDim = aResiduals.rows();
281  measPrecMin = minPrecision;
282  // diagonal precision matrix
283  measResiduals.tail(measDim) = aResiduals;
284  measPrecision.tail(measDim) = aPrecision;
285  measProjection.setIdentity();
286  }
287 
289 
304  template <typename Precision>
305  void GblPoint::addScatterer(const Eigen::Vector2d &aResiduals,
306  const Eigen::MatrixBase<Precision>& aPrecision)
307  {
308  scatFlag = true;
309  // arbitrary precision matrix
310  Eigen::SelfAdjointEigenSolver<typename Precision::PlainObject> scatEigen{aPrecision};
311  scatTransformation = scatEigen.eigenvectors();
312  scatTransformation.transposeInPlace();
313  scatResiduals = scatTransformation * aResiduals;
314  scatPrecision = scatEigen.eigenvalues();
315  }
316 
318 
322  template <typename Derivative>
323  void GblPoint::addLocals(const Eigen::MatrixBase<Derivative>& aDerivatives)
324  {
325  if (measDim) {
326  localDerivatives.resize(aDerivatives.rows(), aDerivatives.cols());
327  if (transFlag) {
328  localDerivatives = measTransformation * aDerivatives;
329  } else {
330  localDerivatives = aDerivatives;
331  }
332  }
333  }
334 
336 
341  template <typename Derivative>
342  void GblPoint::addGlobals(const std::vector<int> &aLabels,
343  const Eigen::MatrixBase<Derivative>& aDerivatives)
344  {
345  if (measDim) {
346  globalLabels = aLabels;
347  globalDerivatives.resize(aDerivatives.rows(), aDerivatives.cols());
348  if (transFlag) {
349  globalDerivatives = measTransformation * aDerivatives;
350  } else {
351  globalDerivatives = aDerivatives;
352  }
353 
354  }
355  }
356 
357 }
358 #endif /* GBLPOINT_H_ */
const Eigen::MatrixXd & getLocalDerivatives() const
Retrieve local derivatives from a point.
Definition: GblPoint.cc:367
type
Definition: HCALResponse.h:21
void addNextJacobian(const Matrix5d &aJac)
Define jacobian to next scatterer (by GBLTrajectory constructor)
Definition: GblPoint.cc:487
void getGlobalDerivatives(Eigen::MatrixXd &aDerivatives) const
Retrieve global derivatives from a point.
Definition: GblPoint.cc:417
Eigen::Matrix< double, 2, 5 > Matrix25d
Definition: GblPoint.h:49
Vector5d measResiduals
Measurement residuals.
Definition: GblPoint.h:166
void setLabel(unsigned int aLabel)
Define label of point (by GBLTrajectory constructor)
Definition: GblPoint.cc:441
bool transFlag
Transformation exists?
Definition: GblPoint.h:168
bool scatFlag
Scatterer present?
Definition: GblPoint.h:171
void setOffset(int anOffset)
Define offset for point (by GBLTrajectory constructor)
Definition: GblPoint.cc:454
int theOffset
Offset number at point if not negative (else interpolation needed)
Definition: GblPoint.h:159
GblPoint(const Matrix5d &aJacobian)
Create a point.
Definition: GblPoint.cc:41
Eigen::Vector2d scatPrecision
Scattering precision (diagonal of inverse covariance matrix)
Definition: GblPoint.h:174
bool hasScatterer() const
Check for scatterer at a point.
Definition: GblPoint.cc:307
unsigned int getLabel() const
Retrieve label of point.
Definition: GblPoint.cc:446
GblPoint & operator=(const GblPoint &)=default
double measPrecMin
Minimal measurement precision (for usage)
Definition: GblPoint.h:164
void addGlobals(const std::vector< int > &aLabels, const Eigen::MatrixBase< Derivative > &aDerivatives)
Add global derivatives to a point.
Definition: GblPoint.h:342
void addLocals(const Eigen::MatrixBase< Derivative > &aDerivatives)
Add local derivatives to a point.
Definition: GblPoint.h:323
double getMeasPrecMin() const
get precision cutoff.
Definition: GblPoint.cc:197
Eigen::Matrix< double, 3, 2 > Matrix32d
Definition: GblPoint.h:51
unsigned int measDim
Dimension of measurement (1-5), 0 indicates absence of measurement.
Definition: GblPoint.h:163
void getMeasurement(Matrix5d &aProjection, Vector5d &aResiduals, Vector5d &aPrecision) const
Retrieve measurement of a point.
Definition: GblPoint.cc:207
int getOffset() const
Retrieve offset for point.
Definition: GblPoint.cc:459
unsigned int hasMeasurement() const
Check for measurement at a point.
Definition: GblPoint.cc:189
Eigen::MatrixXd globalDerivatives
Derivatives of measurement vs additional global (MP-II) parameters.
Definition: GblPoint.h:177
CLHEP::HepMatrix Matrix
Definition: matutil.h:65
Eigen::MatrixXd localDerivatives
Derivatives of measurement vs additional local (fit) parameters.
Definition: GblPoint.h:175
void getGlobalLabels(std::vector< int > &aLabels) const
Retrieve global derivatives labels from a point.
Definition: GblPoint.cc:409
void getGlobalLabelsAndDerivatives(unsigned int aRow, std::vector< int > &aLabels, std::vector< double > &aDerivatives) const
Retrieve global derivatives from a point for a single row.
Definition: GblPoint.cc:427
void printPoint(unsigned int level=0) const
Print GblPoint.
Definition: GblPoint.cc:533
std::vector< int > globalLabels
Labels of global (MP-II) derivatives.
Definition: GblPoint.h:176
void addScatterer(const Eigen::Vector2d &aResiduals, const Eigen::MatrixBase< Precision > &aPrecision)
Add a (thin) scatterer to a point.
Definition: GblPoint.h:305
Namespace for the general broken lines package.
unsigned int getNumLocals() const
Retrieve number of local derivatives from a point.
Definition: GblPoint.cc:362
Matrix5d nextJacobian
Jacobian to next scatterer (or last measurement)
Definition: GblPoint.h:162
void getMeasTransformation(Eigen::MatrixXd &aTransformation) const
Get measurement transformation (from diagonalization).
Definition: GblPoint.cc:219
Eigen::Matrix2d scatTransformation
Transformation of diagonalization (of scat. precision matrix)
Definition: GblPoint.h:172
Eigen::Matrix< double, 5, 1 > Vector5d
Definition: GblPoint.h:47
Eigen::Matrix< double, 2, 7 > Matrix27d
Definition: GblData.h:44
Eigen::Matrix< double, 2, 3 > Matrix23d
Definition: GblPoint.h:48
Vector5d measPrecision
Measurement precision (diagonal of inverse covariance matrix)
Definition: GblPoint.h:167
void getDerivatives(int aDirection, Eigen::Matrix2d &matW, Eigen::Matrix2d &matWJ, Eigen::Vector2d &vecWd) const
Retrieve derivatives of local track model.
Definition: GblPoint.cc:501
Eigen::Vector2d scatResiduals
Scattering residuals (initial kinks if iterating)
Definition: GblPoint.h:173
Matrix5d measProjection
Projection from measurement to local system.
Definition: GblPoint.h:165
void getScatTransformation(Eigen::Matrix2d &aTransformation) const
Get scatterer transformation (from diagonalization).
Definition: GblPoint.cc:328
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:194
Matrix5d prevJacobian
Jacobian to previous scatterer (or first measurement)
Definition: GblPoint.h:161
unsigned int theLabel
Label identifying point.
Definition: GblPoint.h:158
void addPrevJacobian(const Matrix5d &aJac)
Define jacobian to previous scatterer (by GBLTrajectory constructor)
Definition: GblPoint.cc:472
void getScatterer(Eigen::Matrix2d &aTransformation, Eigen::Vector2d &aResiduals, Eigen::Vector2d &aPrecision) const
Retrieve scatterer of a point.
Definition: GblPoint.cc:317
virtual ~GblPoint()
Definition: GblPoint.cc:68
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor, 5, 5 > measTransformation
Transformation of diagonalization (of meas. precision matrix)
Definition: GblPoint.h:170
const Matrix5d & getP2pJacobian() const
Retrieve point-to-(previous)point jacobian.
Definition: GblPoint.cc:464
unsigned int getNumGlobals() const
Retrieve number of global derivatives from a point.
Definition: GblPoint.cc:401
Matrix5d p2pJacobian
Point-to-point jacobian from previous point.
Definition: GblPoint.h:160
Point on trajectory.
Definition: GblPoint.h:66
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: GblData.h:43