CMS 3D CMS Logo

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 
30 #ifndef GBLTRAJECTORY_H_
31 #define GBLTRAJECTORY_H_
32 
38 
40 namespace gbl {
41 
43 
47  class GblTrajectory {
48  public:
49  GblTrajectory(const std::vector<GblPoint> &aPointList, bool flagCurv = true,
50  bool flagU1dir = true, bool flagU2dir = true);
51  template <typename Seed>
52  GblTrajectory(const std::vector<GblPoint> &aPointList, unsigned int aLabel,
53  const Eigen::MatrixBase<Seed>& aSeed,
54  bool flagCurv = true, bool flagU1dir = true, bool flagU2dir = true);
55  GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> >& aPointsAndTransList);
56  template <typename Derivatives, typename Measurements, typename Precision,
59  GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> >& aPointsAndTransList,
60  const Eigen::MatrixBase<Derivatives>& extDerivatives,
61  const Eigen::MatrixBase<Measurements>& extMeasurements,
62  const Eigen::MatrixBase<Precision>& extPrecisions);
63  template <typename Derivatives, typename Measurements, typename Precision,
64  typename std::enable_if<(Measurements::ColsAtCompileTime == 1)>::type* = nullptr,
66  GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> >& aPointsAndTransList,
67  const Eigen::MatrixBase<Derivatives>& extDerivatives,
68  const Eigen::MatrixBase<Measurements>& extMeasurements,
69  const Eigen::MatrixBase<Precision>& extPrecisions);
70 #ifdef GBL_EIGEN_SUPPORT_ROOT
71  // input from ROOT
72  GblTrajectory(const std::vector<GblPoint> &aPointList, unsigned int aLabel,
73  const TMatrixDSym &aSeed, bool flagCurv = true, bool flagU1dir =
74  true, bool flagU2dir = true);
75  GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > &aPointsAndTransList);
76  GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > &aPointsAndTransList,
77  const TMatrixD &extDerivatives, const TVectorD &extMeasurements,
78  const TVectorD &extPrecisions);
79  GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > &aPointsAndTransList,
80  const TMatrixD &extDerivatives, const TVectorD &extMeasurements,
81  const TMatrixDSym &extPrecisions);
82 #endif
83  virtual ~GblTrajectory();
84  bool isValid() const;
85  unsigned int getNumPoints() const;
86  unsigned int getResults(int aSignedLabel, Eigen::VectorXd &localPar,
87  Eigen::MatrixXd &localCov) const;
88  unsigned int getMeasResults(unsigned int aLabel, unsigned int &numRes,
89  Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors,
90  Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights);
91  unsigned int getScatResults(unsigned int aLabel, unsigned int &numRes,
92  Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors,
93  Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights);
94 #ifdef GBL_EIGEN_SUPPORT_ROOT
95  // input from ROOT
96  unsigned int getResults(int aSignedLabel, TVectorD &localPar,
97  TMatrixDSym &localCov) const;
98  unsigned int getMeasResults(unsigned int aLabel, unsigned int &numRes,
99  TVectorD &aResiduals, TVectorD &aMeasErrors, TVectorD &aResErrors,
100  TVectorD &aDownWeights);
101  unsigned int getScatResults(unsigned int aLabel, unsigned int &numRes,
102  TVectorD &aResiduals, TVectorD &aMeasErrors, TVectorD &aResErrors,
103  TVectorD &aDownWeights);
104 #endif
105  unsigned int getLabels(std::vector<unsigned int> &aLabelList);
106  unsigned int getLabels(std::vector<std::vector<unsigned int> > &aLabelList);
107  unsigned int fit(double &Chi2, int &Ndf, double &lostWeight,
108  const std::string& optionList = "", unsigned int aLabel = 0);
109  void milleOut(MilleBinary &aMille);
110  void printTrajectory(unsigned int level = 0);
111  void printPoints(unsigned int level = 0);
112  void printData();
113 
114  private:
115  unsigned int numAllPoints;
116  std::vector<unsigned int> numPoints;
117  unsigned int numTrajectories;
118  unsigned int numOffsets;
119  unsigned int numInnerTrans;
120  unsigned int numCurvature;
121  unsigned int numParameters;
122  unsigned int numLocals;
123  unsigned int numMeasurements;
124  unsigned int externalPoint;
125  unsigned int skippedMeasLabel;
126  unsigned int maxNumGlobals;
127  bool constructOK;
128  bool fitOK;
129  std::vector<unsigned int> theDimension;
130  std::vector<std::vector<GblPoint> > thePoints;
131  std::vector<GblData> theData;
132  std::vector<unsigned int> measDataIndex;
133  std::vector<unsigned int> scatDataIndex;
134  Eigen::MatrixXd externalSeed;
135  std::vector<Eigen::MatrixXd> innerTransformations;
136  // composed trajectory (from common external parameters)
137  Eigen::MatrixXd externalDerivatives; // Derivatives for external measurements of composed trajectory
138  Eigen::VectorXd externalMeasurements; // Residuals for external measurements of composed trajectory
139  Eigen::VectorXd externalPrecisions; // Precisions for external measurements of composed trajectory
142 
143  std::pair<std::vector<unsigned int>, Eigen::MatrixXd> getJacobian(int aSignedLabel) const;
144  void getFitToLocalJacobian(std::array<unsigned int, 5>& anIndex,
145  Matrix5d &aJacobian, const GblPoint &aPoint,
146  unsigned int measDim,
147  unsigned int nJacobian = 1) const;
148  void getFitToKinkJacobian(std::array<unsigned int, 7>& anIndex,
149  Matrix27d &aJacobian, const GblPoint &aPoint) const;
150  void construct();
151  void defineOffsets();
152  void calcJacobians();
153  void prepare();
155  void predict();
156  double downWeight(unsigned int aMethod);
157  void getResAndErr(unsigned int aData, bool used, double &aResidual,
158  double &aMeadsError, double &aResError, double &aDownWeight);
159  };
160 
161 
163 
174  template <typename Seed>
175  GblTrajectory::GblTrajectory(const std::vector<GblPoint> &aPointList,
176  unsigned int aLabel,
177  const Eigen::MatrixBase<Seed>& aSeed,
178  bool flagCurv,
179  bool flagU1dir, bool flagU2dir) :
180  numAllPoints(aPointList.size()), numPoints(), numOffsets(0),
181  numInnerTrans(0), numCurvature(flagCurv ? 1 : 0), numParameters(0),
182  numLocals(0), numMeasurements(0), externalPoint(aLabel),
187  {
188 
189  if (flagU1dir)
190  theDimension.push_back(0);
191  if (flagU2dir)
192  theDimension.push_back(1);
193  // simple (single) trajectory
194  thePoints.push_back(aPointList);
195  numPoints.push_back(numAllPoints);
196  construct(); // construct trajectory
197  }
198 
200 
209  template <typename Derivatives, typename Measurements, typename Precision,
212  GblTrajectory::GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> >& aPointsAndTransList,
213  const Eigen::MatrixBase<Derivatives>& extDerivatives,
214  const Eigen::MatrixBase<Measurements>& extMeasurements,
215  const Eigen::MatrixBase<Precision>& extPrecisions) :
217  numInnerTrans(aPointsAndTransList.size()), numParameters(0), numLocals(0),
221  {
222  // diagonalize external measurement
223  Eigen::SelfAdjointEigenSolver<typename Precision::PlainObject> extEigen{extPrecisions};
224  // @TODO if (extEigen.info() != Success) abort();
225  auto extTransformation = extEigen.eigenvectors().transpose();
226  externalDerivatives.resize(extDerivatives.rows(),
227  extDerivatives.cols());
228  externalDerivatives = extTransformation * extDerivatives;
229  externalMeasurements.resize(extMeasurements.size());
230  externalMeasurements = extTransformation * extMeasurements;
231  externalPrecisions.resize(extMeasurements.size());
232  externalPrecisions = extEigen.eigenvalues();
233 
234  for (unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
235  thePoints.push_back(aPointsAndTransList[iTraj].first);
236  numPoints.push_back(thePoints.back().size());
237  numAllPoints += numPoints.back();
238  innerTransformations.push_back(aPointsAndTransList[iTraj].second);
239  }
240  theDimension.push_back(0);
241  theDimension.push_back(1);
243  construct(); // construct (composed) trajectory
244  }
245 
247 
256  template <typename Derivatives, typename Measurements, typename Precision,
257  typename std::enable_if<(Measurements::ColsAtCompileTime == 1)>::type*,
259  GblTrajectory::GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> >& aPointsAndTransList,
260  const Eigen::MatrixBase<Derivatives>& extDerivatives,
261  const Eigen::MatrixBase<Measurements>& extMeasurements,
262  const Eigen::MatrixBase<Precision>& extPrecisions) :
264  numInnerTrans(aPointsAndTransList.size()), numParameters(0), numLocals(0),
268  {
269  externalDerivatives = extDerivatives;
270  externalMeasurements = extMeasurements;
271  externalPrecisions = extPrecisions;
272 
273  for (unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
274  thePoints.push_back(aPointsAndTransList[iTraj].first);
275  numPoints.push_back(thePoints.back().size());
276  numAllPoints += numPoints.back();
277  innerTransformations.push_back(aPointsAndTransList[iTraj].second);
278  }
279  theDimension.push_back(0);
280  theDimension.push_back(1);
282  construct(); // construct (composed) trajectory
283  }
284 
285 }
286 #endif /* GBLTRAJECTORY_H_ */
size
Write out results.
type
Definition: HCALResponse.h:21
GBL trajectory.
Definition: GblTrajectory.h:47
std::vector< unsigned int > scatDataIndex
mapping points to data blocks from scatterers
void construct()
Construct trajectory from list of points.
void buildLinearEquationSystem()
Build linear equation system from data (blocks).
void printTrajectory(unsigned int level=0)
Print GblTrajectory.
unsigned int numParameters
Number of fit parameters.
bool constructOK
Trajectory has been successfully constructed (ready for fit/output)
std::vector< unsigned int > measDataIndex
mapping points to data blocks from measurements
bool fitOK
Trajectory has been successfully fitted (results are valid)
(Symmetric) Bordered Band Matrix.
std::vector< unsigned int > theDimension
List of active dimensions (0=u1, 1=u2) in fit.
unsigned int getLabels(std::vector< unsigned int > &aLabelList)
Get (list of) labels of points on (simple) valid trajectory.
void predict()
Calculate predictions for all points.
unsigned int numOffsets
Number of (points with) offsets on trajectory.
Eigen::VectorXd externalMeasurements
bool isValid() const
Retrieve validity of trajectory.
unsigned int getResults(int aSignedLabel, Eigen::VectorXd &localPar, Eigen::MatrixXd &localCov) const
Get fit results at point.
U second(std::pair< T, U > const &p)
unsigned int fit(double &Chi2, int &Ndf, double &lostWeight, const std::string &optionList="", unsigned int aLabel=0)
Perform fit of (valid) trajectory.
unsigned int externalPoint
Label of external point (or 0)
unsigned int numInnerTrans
Number of inner transformations to external parameters.
void calcJacobians()
Calculate Jacobians to previous/next scatterer from point to point ones.
unsigned int numMeasurements
Total number of measurements.
void getFitToKinkJacobian(std::array< unsigned int, 7 > &anIndex, Matrix27d &aJacobian, const GblPoint &aPoint) const
Get jacobian for transformation from (trajectory) fit to kink parameters at point.
Eigen::MatrixXd externalSeed
Precision (inverse covariance matrix) of external seed.
void defineOffsets()
Define offsets from list of points.
void prepare()
Prepare fit for simple or composed trajectory.
unsigned int getScatResults(unsigned int aLabel, unsigned int &numRes, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights)
Get (kink) residuals from fit at point for scatterer.
void printData()
Print GblData blocks for trajectory.
Namespace for the general broken lines package.
double downWeight(unsigned int aMethod)
Down-weight all points.
std::vector< unsigned int > numPoints
Number of points on (sub)trajectory.
std::pair< std::vector< unsigned int >, Eigen::MatrixXd > getJacobian(int aSignedLabel) const
Get jacobian for transformation from fit to track parameters at point.
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...
void milleOut(MilleBinary &aMille)
Write valid trajectory to Millepede-II binary file.
std::vector< GblData > theData
List of data blocks.
Eigen::Matrix< double, 2, 7 > Matrix27d
Definition: GblData.h:44
unsigned int maxNumGlobals
Max. number of global labels/derivatives per point.
std::vector< Eigen::MatrixXd > innerTransformations
Transformations at innermost points of.
Eigen::MatrixXd externalDerivatives
std::vector< std::vector< GblPoint > > thePoints
(list of) List of points on trajectory
BorderedBandMatrix theMatrix
(Bordered band) matrix of linear equation system
VVector theVector
Vector of linear equation system.
unsigned int numTrajectories
Number of trajectories (in composed trajectory)
unsigned int getMeasResults(unsigned int aLabel, unsigned int &numRes, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights)
Get residuals from fit at point for measurement.
Simple Vector based on std::vector<double>
Definition: VMatrix.h:43
GblTrajectory(const std::vector< GblPoint > &aPointList, bool flagCurv=true, bool flagU1dir=true, bool flagU2dir=true)
Create new (simple) trajectory from list of points.
unsigned int numLocals
Total number of (additional) local parameters.
virtual ~GblTrajectory()
Millepede-II (binary) record.
Definition: MilleBinary.h:68
unsigned int getNumPoints() const
Retrieve number of point from trajectory.
AlgebraicMatrix Derivatives
Definition: Definitions.h:37
unsigned int numAllPoints
Number of all points on trajectory.
void getResAndErr(unsigned int aData, bool used, double &aResidual, double &aMeadsError, double &aResError, double &aDownWeight)
Get residual and errors from data block.
void printPoints(unsigned int level=0)
Print GblPoints on trajectory.
Definition: Chi2.h:17
unsigned int numCurvature
Number of curvature parameters (0 or 1) or external parameters.
unsigned int skippedMeasLabel
Label of point with measurements skipped in fit (for unbiased residuals) (or 0)
Eigen::VectorXd externalPrecisions
Point on trajectory.
Definition: GblPoint.h:66
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: GblData.h:43