GeneralBrokenLines V03-01-03
using EIGEN
GblTrajectory.h
Go to the documentation of this file.
1/*
2 * GblTrajectory.h
3 *
4 * Created on: Aug 18, 2011
5 * Author: kleinwrt
6 */
7
32#ifndef GBLTRAJECTORY_H_
33#define GBLTRAJECTORY_H_
34
35#include <array>
36#include "GblPoint.h"
37#include "GblData.h"
38#include "GblPoint.h"
39#include "BorderedBandMatrix.h"
40#include "MilleBinary.h"
41
43namespace gbl {
44
46
51public:
52 GblTrajectory(const std::vector<GblPoint> &aPointList, bool flagCurv = true,
53 bool flagU1dir = true, bool flagU2dir = true);
55 const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> > &aPointsAndTransList);
56
58
70 template<typename Seed>
71 GblTrajectory(const std::vector<GblPoint> &aPointList, unsigned int aLabel,
72 const Eigen::MatrixBase<Seed> &aSeed, bool flagCurv = true,
73 bool flagU1dir = true, bool flagU2dir = true);
74
76
87 template<typename Derivatives, typename Measurements, typename Precision,
88 typename std::enable_if<(Precision::ColsAtCompileTime != 1)>::type* =
89 nullptr>
91 const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> > &aPointsAndTransList,
92 const Eigen::MatrixBase<Derivatives> &extDerivatives,
93 const Eigen::MatrixBase<Measurements> &extMeasurements,
94 const Eigen::MatrixBase<Precision> &extPrecisions);
95
97
109 template<typename Derivatives, typename Measurements, typename Precision,
110 typename std::enable_if<(Precision::ColsAtCompileTime == 1)>::type* =
111 nullptr>
113 const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> > &aPointsAndTransList,
114 const Eigen::MatrixBase<Derivatives> &extDerivatives,
115 const Eigen::MatrixBase<Measurements> &extMeasurements,
116 const Eigen::MatrixBase<Precision> &extPrecisions);
117
118#ifdef GBL_EIGEN_SUPPORT_ROOT
119 // input from ROOT
120 GblTrajectory(const std::vector<GblPoint> &aPointList, unsigned int aLabel,
121 const TMatrixDSym &aSeed, bool flagCurv = true, bool flagU1dir =
122 true, bool flagU2dir = true);
124 const std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > &aPointsAndTransList);
126 const std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > &aPointsAndTransList,
127 const TMatrixD &extDerivatives, const TVectorD &extMeasurements,
128 const TVectorD &extPrecisions);
130 const std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > &aPointsAndTransList,
131 const TMatrixD &extDerivatives, const TVectorD &extMeasurements,
132 const TMatrixDSym &extPrecisions);
133#endif
134 virtual ~GblTrajectory();
135 bool isValid() const;
136 unsigned int getNumPoints() const;
137 unsigned int getExtResults(Eigen::VectorXd &extPar,
138 Eigen::MatrixXd &extCov) const;
139 unsigned int getResults(int aSignedLabel, Eigen::VectorXd &localPar,
140 Eigen::MatrixXd &localCov) const;
141 unsigned int getMeasResults(unsigned int aLabel, unsigned int &numData,
142 Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors,
143 Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights);
144 unsigned int getMeasResults(unsigned int aLabel, unsigned int &numData,
145 Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors);
146 unsigned int getScatResults(unsigned int aLabel, unsigned int &numData,
147 Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors,
148 Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights);
149#ifdef GBL_EIGEN_SUPPORT_ROOT
150 // input from ROOT
151 unsigned int getExtResults(TVectorD &extPar,
152 TMatrixDSym &extCov) const;
153 unsigned int getResults(int aSignedLabel, TVectorD &localPar,
154 TMatrixDSym &localCov) const;
155 unsigned int getMeasResults(unsigned int aLabel, unsigned int &numData,
156 TVectorD &aResiduals, TVectorD &aMeasErrors, TVectorD &aResErrors,
157 TVectorD &aDownWeights);
158 unsigned int getScatResults(unsigned int aLabel, unsigned int &numData,
159 TVectorD &aResiduals, TVectorD &aMeasErrors, TVectorD &aResErrors,
160 TVectorD &aDownWeights);
161#endif
162 unsigned int getLabels(std::vector<unsigned int> &aLabelList) const;
163 unsigned int getLabels(
164 std::vector<std::vector<unsigned int> > &aLabelList) const;
165 unsigned int fit(double &Chi2, int &Ndf, double &lostWeight,
166 const std::string &optionList = "", unsigned int aLabel = 0);
167 void milleOut(MilleBinary &aMille);
168 void printTrajectory(unsigned int level = 0) const;
169 void printPoints(unsigned int level = 0) const;
170 void printData() const;
171 double getBandCondition() const;
172
173private:
174 unsigned int numAllPoints;
175 std::vector<unsigned int> numPoints;
176 unsigned int numTrajectories;
177 unsigned int numOffsetPoints;
178 unsigned int numOffsets;
180 unsigned int numInnerTransOffsets;
181 unsigned int numCurvature;
182 unsigned int numParameters;
183 unsigned int numLocals;
184 unsigned int numMeasurements;
185 unsigned int externalPoint;
186 unsigned int skippedMeasLabel;
187 unsigned int maxNumGlobals;
189 bool fitOK;
190 std::vector<unsigned int> theDimension;
191 std::vector<std::vector<GblPoint> > thePoints;
192 std::vector<GblData> theData;
193 std::vector<unsigned int> measDataIndex;
194 std::vector<unsigned int> scatDataIndex;
195 Eigen::MatrixXd externalSeed;
196 // composed trajectory
197 std::vector<Eigen::MatrixXd> innerTransformations;
198 std::vector<Eigen::MatrixXd> innerTransDer;
199 std::vector<std::array<unsigned int, 5> > innerTransLab;
200 Eigen::MatrixXd externalDerivatives;
201 Eigen::VectorXd externalMeasurements;
202 Eigen::VectorXd externalPrecisions;
203 // linear equation system
206
207 std::pair<std::vector<unsigned int>, Eigen::MatrixXd> getJacobian(
208 int aSignedLabel) const;
209 void getFitToLocalJacobian(std::array<unsigned int, 5> &anIndex,
210 Matrix5d &aJacobian, const GblPoint &aPoint, unsigned int measDim,
211 unsigned int nJacobian = 1) const;
212 unsigned int getFitToKinkJacobian(std::array<unsigned int, 9> &anIndex,
213 Matrix49d &aJacobian, const GblPoint &aPoint) const;
214 unsigned int getFitToStepJacobian(std::array<unsigned int, 9> &anIndex,
215 Matrix49d &aJacobian, const GblPoint &aPoint) const;
216 unsigned int getFitToKinkAndStepJacobian(
217 std::array<unsigned int, 9> &anIndex, Matrix49d &aJacobian,
218 const GblPoint &aPoint) const;
219 void construct();
220 void defineOffsets();
221 void calcJacobians();
222 void prepare();
224 void predict();
225 double downWeight(unsigned int aMethod);
226 void getResAndErr(unsigned int aData, bool used, double &aResidual,
227 double &aMeasError, double &aResError, double &aDownWeight);
228 void getResAndErr(unsigned int aData, double &aResidual,
229 double &aMeasError);
230};
231
232template<typename Seed>
233GblTrajectory::GblTrajectory(const std::vector<GblPoint> &aPointList,
234 unsigned int aLabel, const Eigen::MatrixBase<Seed> &aSeed,
235 bool flagCurv, bool flagU1dir, bool flagU2dir) :
236 numAllPoints(aPointList.size()), numPoints(), numOffsetPoints(0), numOffsets(
237 0), numInnerTransformations(0), numInnerTransOffsets(0), numCurvature(
238 flagCurv ? 1 : 0), numParameters(0), numLocals(0), numMeasurements(
239 0), externalPoint(aLabel), skippedMeasLabel(0), maxNumGlobals(
240 0), theDimension(0), thePoints(), theData(), measDataIndex(), scatDataIndex(), externalSeed(
241 aSeed), innerTransformations(), externalDerivatives(), externalMeasurements(), externalPrecisions() {
242
243 if (flagU1dir)
244 theDimension.push_back(0);
245 if (flagU2dir)
246 theDimension.push_back(1);
247 // simple (single) trajectory
248 thePoints.push_back(aPointList);
249 numPoints.push_back(numAllPoints);
250 construct(); // construct trajectory
251}
252
253template<typename Derivatives, typename Measurements, typename Precision,
254 typename std::enable_if<(Precision::ColsAtCompileTime != 1)>::type*>
256 const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> > &aPointsAndTransList,
257 const Eigen::MatrixBase<Derivatives> &extDerivatives,
258 const Eigen::MatrixBase<Measurements> &extMeasurements,
259 const Eigen::MatrixBase<Precision> &extPrecisions) :
260 numAllPoints(), numPoints(), numOffsetPoints(0), numOffsets(0), numInnerTransformations(
261 aPointsAndTransList.size()), numParameters(0), numLocals(0), numMeasurements(
262 0), externalPoint(0), skippedMeasLabel(0), maxNumGlobals(0), theDimension(
263 0), thePoints(), theData(), measDataIndex(), scatDataIndex(), externalSeed(), innerTransformations() {
264
265 static_assert(static_cast<int>(Measurements::ColsAtCompileTime) == 1, "GblTrajectory: cols(Measurements) must be 1 (vector)");
266 static_assert(static_cast<int>(Measurements::RowsAtCompileTime) == static_cast<int>(Derivatives::RowsAtCompileTime), "GblTrajectory: rows(Measurements) and rows(Derivatives) must be equal");
267 static_assert(static_cast<int>(Measurements::RowsAtCompileTime) == static_cast<int>(Precision::RowsAtCompileTime), "GblTrajectory: rows(Measurements) and rows(Precision) must be equal");
268 static_assert(static_cast<int>(Precision::RowsAtCompileTime) == static_cast<int>(Precision::ColsAtCompileTime), "GblTrajectory: rows(Precision) and cols(Precision) must be equal");
269 // diagonalize external measurement
270 Eigen::SelfAdjointEigenSolver<typename Precision::PlainObject> extEigen {
271 extPrecisions };
272 // @TODO if (extEigen.info() != Success) abort();
273 auto extTransformation = extEigen.eigenvectors().transpose();
274 externalDerivatives.resize(extDerivatives.rows(), extDerivatives.cols());
275 externalDerivatives = extTransformation * extDerivatives;
276 externalMeasurements.resize(extMeasurements.size());
277 externalMeasurements = extTransformation * extMeasurements;
278 externalPrecisions.resize(extMeasurements.size());
279 externalPrecisions = extEigen.eigenvalues();
280
281 for (unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
282 thePoints.push_back(aPointsAndTransList[iTraj].first);
283 numPoints.push_back(thePoints.back().size());
284 numAllPoints += numPoints.back();
285 innerTransformations.push_back(aPointsAndTransList[iTraj].second);
286 }
287 theDimension.push_back(0);
288 theDimension.push_back(1);
289 // kinematic (2) or geometric (1) constraint
290 numInnerTransOffsets = innerTransformations[0].rows() == 5 ? 2 : 1;
291 numCurvature =
292 innerTransformations[0].rows() == 5 ?
293 innerTransformations[0].cols() :
294 innerTransformations[0].cols() + numInnerTransformations;
295 construct(); // construct (composed) trajectory
296}
297
298template<typename Derivatives, typename Measurements, typename Precision,
299 typename std::enable_if<(Precision::ColsAtCompileTime == 1)>::type*>
301 const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> > &aPointsAndTransList,
302 const Eigen::MatrixBase<Derivatives> &extDerivatives,
303 const Eigen::MatrixBase<Measurements> &extMeasurements,
304 const Eigen::MatrixBase<Precision> &extPrecisions) :
305 numAllPoints(), numPoints(), numOffsetPoints(0), numOffsets(0), numInnerTransformations(
306 aPointsAndTransList.size()), numParameters(0), numLocals(0), numMeasurements(
307 0), externalPoint(0), skippedMeasLabel(0), maxNumGlobals(0), theDimension(
308 0), thePoints(), theData(), measDataIndex(), scatDataIndex(), externalSeed(), innerTransformations() {
309 static_assert(static_cast<int>(Measurements::ColsAtCompileTime) == 1, "GblTrajectory: cols(Measurements) must be 1 (vector)");
310 static_assert(static_cast<int>(Measurements::RowsAtCompileTime) == static_cast<int>(Derivatives::RowsAtCompileTime), "GblTrajectory: rows(Measurements) and rows(Derivatives) must be equal");
311 static_assert(static_cast<int>(Measurements::RowsAtCompileTime) == static_cast<int>(Precision::RowsAtCompileTime), "GblTrajectory: rows(Measurements) and rows(Precision) must be equal");
312
313 externalDerivatives = extDerivatives;
314 externalMeasurements = extMeasurements;
315 externalPrecisions = extPrecisions;
316
317 for (unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
318 thePoints.push_back(aPointsAndTransList[iTraj].first);
319 numPoints.push_back(thePoints.back().size());
320 numAllPoints += numPoints.back();
321 innerTransformations.push_back(aPointsAndTransList[iTraj].second);
322 }
323 theDimension.push_back(0);
324 theDimension.push_back(1);
325 // kinematic (2) or geometric (1) constraint
326 numInnerTransOffsets = innerTransformations[0].rows() == 5 ? 2 : 1;
328 innerTransformations[0].rows() == 5 ?
329 innerTransformations[0].cols() :
331 construct(); // construct (composed) trajectory
332}
333
334}
335#endif /* GBLTRAJECTORY_H_ */
BorderedBandMatrix definition.
GblData definition.
GblPoint definition.
MilleBinary definition.
(Symmetric) Bordered Band Matrix.
Point on trajectory.
Definition: GblPoint.h:62
GBL trajectory.
Definition: GblTrajectory.h:50
std::vector< unsigned int > numPoints
Number of points on (sub)trajectory.
std::vector< unsigned int > scatDataIndex
mapping points to data blocks from scatterers
BorderedBandMatrix theMatrix
(Bordered band) matrix of linear equation system
std::vector< std::vector< GblPoint > > thePoints
(list of) List of points on trajectory
void printPoints(unsigned int level=0) const
Print GblPoints on trajectory.
unsigned int skippedMeasLabel
Label of point with measurements skipped in fit (for unbiased residuals) (or 0)
unsigned int numTrajectories
Number of trajectories (in composed trajectory)
unsigned int getFitToStepJacobian(std::array< unsigned int, 9 > &anIndex, Matrix49d &aJacobian, const GblPoint &aPoint) const
Get jacobian for transformation from (trajectory) fit to step parameters at point.
void construct()
Construct trajectory from list of points.
unsigned int externalPoint
Label of external point (or 0)
Eigen::MatrixXd externalSeed
Precision (inverse covariance matrix) of external seed.
unsigned int getMeasResults(unsigned int aLabel, unsigned int &numData, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights)
Get residuals from fit at point for measurement "long list".
unsigned int numAllPoints
Number of all points on trajectory.
double downWeight(unsigned int aMethod)
Down-weight all points.
VVector theVector
Vector of linear equation system.
void calcJacobians()
Calculate Jacobians to previous/next scatterer from point to point ones.
unsigned int numCurvature
Number of curvature parameters (0 or 1) or external parameters.
Eigen::VectorXd externalPrecisions
Precisions for external measurements of composed trajectory.
std::vector< std::array< unsigned int, 5 > > innerTransLab
Labels at innermost points of composed trajectory.
Eigen::VectorXd externalMeasurements
Residuals for external measurements of composed trajectory.
void printTrajectory(unsigned int level=0) const
Print GblTrajectory.
void predict()
Calculate predictions for all points.
unsigned int getFitToKinkAndStepJacobian(std::array< unsigned int, 9 > &anIndex, Matrix49d &aJacobian, const GblPoint &aPoint) const
Get jacobian for transformation from (trajectory) fit to kink and step parameters at point.
void defineOffsets()
Define offsets from list of points.
std::vector< Eigen::MatrixXd > innerTransformations
Transformations at innermost points of composed trajectory (from common external parameters)
unsigned int numLocals
Total number of (additional) local parameters.
unsigned int numOffsetPoints
Number of points with offsets on trajectory.
void milleOut(MilleBinary &aMille)
Write valid trajectory to Millepede-II binary file.
unsigned int getExtResults(Eigen::VectorXd &extPar, Eigen::MatrixXd &extCov) const
Get fit results for external parameters.
void getFitToLocalJacobian(std::array< unsigned int, 5 > &anIndex, Matrix5d &aJacobian, const GblPoint &aPoint, unsigned int measDim, unsigned int nJacobian=1) const
Get (part of) jacobian for transformation from (trajectory) fit to track parameters at point.
unsigned int numInnerTransformations
Number of inner transformations to external parameters.
unsigned int maxNumGlobals
Max. number of global labels/derivatives per point.
bool isValid() const
Retrieve validity of trajectory.
GblTrajectory(const std::vector< std::pair< std::vector< GblPoint >, Eigen::MatrixXd > > &aPointsAndTransList, const Eigen::MatrixBase< Derivatives > &extDerivatives, const Eigen::MatrixBase< Measurements > &extMeasurements, const Eigen::MatrixBase< Precision > &extPrecisions)
Create new composed trajectory from list of points and transformations with independent external meas...
double getBandCondition() const
Get condition from band (decomposition)
GblTrajectory(const std::vector< GblPoint > &aPointList, bool flagCurv=true, bool flagU1dir=true, bool flagU2dir=true)
Create new (simple) trajectory from list of points.
void prepare()
Prepare fit for simple or composed trajectory.
unsigned int getResults(int aSignedLabel, Eigen::VectorXd &localPar, Eigen::MatrixXd &localCov) const
Get fit results at point.
Eigen::MatrixXd externalDerivatives
Derivatives for external measurements of composed trajectory.
unsigned int fit(double &Chi2, int &Ndf, double &lostWeight, const std::string &optionList="", unsigned int aLabel=0)
Perform fit of (valid) trajectory.
unsigned int getScatResults(unsigned int aLabel, unsigned int &numData, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights)
Get (kink) residuals from fit at point for scatterer.
std::vector< GblData > theData
List of data blocks.
bool constructOK
Trajectory has been successfully constructed (ready for fit/output)
unsigned int numInnerTransOffsets
Number of (points with) offsets affected by inner transformations to external parameters.
std::vector< unsigned int > measDataIndex
mapping points to data blocks from measurements
void buildLinearEquationSystem()
Build linear equation system from data (blocks).
void printData() const
Print GblData blocks for trajectory.
unsigned int getLabels(std::vector< unsigned int > &aLabelList) const
Get (list of) labels of points on (simple) valid trajectory.
unsigned int numParameters
Number of fit parameters.
unsigned int numMeasurements
Total number of measurements.
std::vector< Eigen::MatrixXd > innerTransDer
Derivatives at innermost points of composed trajectory.
unsigned int getFitToKinkJacobian(std::array< unsigned int, 9 > &anIndex, Matrix49d &aJacobian, const GblPoint &aPoint) const
Get jacobian for transformation from (trajectory) fit to kink parameters at point.
std::pair< std::vector< unsigned int >, Eigen::MatrixXd > getJacobian(int aSignedLabel) const
Get jacobian for transformation from fit to track parameters at point.
void getResAndErr(unsigned int aData, bool used, double &aResidual, double &aMeasError, double &aResError, double &aDownWeight)
Get residual and errors from data block "long list".
bool fitOK
Trajectory has been successfully fitted (results are valid)
unsigned int numOffsets
Number of (1D or 2D) offsets on trajectory.
std::vector< unsigned int > theDimension
List of active dimensions (0=u1, 1=u2) in fit.
unsigned int getNumPoints() const
Retrieve number of point from trajectory.
Millepede-II (binary) record.
Definition: MilleBinary.h:81
Simple Vector based on std::vector<double>
Definition: VMatrix.h:43
Namespace for the general broken lines package.
Eigen::Matrix< double, 4, 9 > Matrix49d
Definition: GblData.h:47
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: GblData.h:46