32#ifndef GBLTRAJECTORY_H_
33#define GBLTRAJECTORY_H_
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);
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);
87 template<
typename Derivatives,
typename Measurements,
typename Precision,
88 typename std::enable_if<(Precision::ColsAtCompileTime != 1)>::type* =
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);
109 template<
typename Derivatives,
typename Measurements,
typename Precision,
110 typename std::enable_if<(Precision::ColsAtCompileTime == 1)>::type* =
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);
118#ifdef GBL_EIGEN_SUPPORT_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);
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
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);
162 unsigned int getLabels(std::vector<unsigned int> &aLabelList)
const;
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);
207 std::pair<std::vector<unsigned int>, Eigen::MatrixXd>
getJacobian(
208 int aSignedLabel)
const;
211 unsigned int nJacobian = 1)
const;
217 std::array<unsigned int, 9> &anIndex,
Matrix49d &aJacobian,
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,
232template<
typename Seed>
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() {
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() {
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");
270 Eigen::SelfAdjointEigenSolver<typename Precision::PlainObject> extEigen {
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();
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);
287 theDimension.push_back(0);
288 theDimension.push_back(1);
290 numInnerTransOffsets = innerTransformations[0].rows() == 5 ? 2 : 1;
292 innerTransformations[0].rows() == 5 ?
293 innerTransformations[0].cols() :
294 innerTransformations[0].cols() + numInnerTransformations;
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");
317 for (
unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
318 thePoints.push_back(aPointsAndTransList[iTraj].first);
BorderedBandMatrix definition.
(Symmetric) Bordered Band Matrix.
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.
Simple Vector based on std::vector<double>
Namespace for the general broken lines package.
Eigen::Matrix< double, 4, 9 > Matrix49d
Eigen::Matrix< double, 5, 5 > Matrix5d