GeneralBrokenLines  Rev: 2.2.0
GblData.h
Go to the documentation of this file.
1 /*
2  * GblData.h
3  *
4  * Created on: Aug 18, 2011
5  * Author: kleinwrt
6  */
7 
32 #ifndef GBLDATA_H_
33 #define GBLDATA_H_
34 
35 #include<iostream>
36 #include<vector>
37 #include <array>
38 #include<math.h>
39 #include "VMatrix.h"
40 
41 #include <Eigen/Core>
42 
44 namespace gbl {
45 
46 typedef Eigen::Matrix<double, 5, 5> Matrix5d;
47 typedef Eigen::Matrix<double, 2, 7> Matrix27d;
48 
51 };
52 
54 
58 class GblData {
59 public:
60  GblData(unsigned int aLabel, dataBlockType aType, double aMeas,
61  double aPrec, unsigned int aTraj = 0, unsigned int aPoint = 0);
62  GblData(const GblData&) = default;
63  GblData& operator=(const GblData&) = default;
64  GblData(GblData&&) = default;
65  GblData& operator=(GblData&&) = default;
66  virtual ~GblData();
67 
69 
81  template<typename LocalDerivative, typename ExtDerivative>
82  void addDerivatives(unsigned int iRow,
83  const std::array<unsigned int, 5>& labDer, const Matrix5d &matDer,
84  unsigned int iOff,
85  const Eigen::MatrixBase<LocalDerivative>& derLocal,
86  unsigned int extOff,
87  const Eigen::MatrixBase<ExtDerivative>& extDer);
88 
90 
99  template<typename ExtDerivative>
100  void addDerivatives(unsigned int iRow,
101  const std::array<unsigned int, 7>& labDer, const Matrix27d &matDer,
102  unsigned int extOff,
103  const Eigen::MatrixBase<ExtDerivative>& extDer);
104 
105  void addDerivatives(const std::vector<unsigned int> &index,
106  const std::vector<double> &derivatives);
107 
108  void setPrediction(const VVector &aVector);
109  double setDownWeighting(unsigned int aMethod);
110  double getChi2() const;
111  void printData() const;
112  unsigned int getLabel() const;
113  dataBlockType getType() const;
114  unsigned int getNumSimple() const;
115  void getLocalData(double &aValue, double &aWeight, unsigned int &numLocal,
116  unsigned int* &indLocal, double* &derLocal);
117  void getAllData(double &aValue, double &aErr, unsigned int &numLocal,
118  unsigned int* &indLocal, double* &derLocal, unsigned int &aTraj,
119  unsigned int &aPoint, unsigned int &aRow);
120  void getResidual(double &aResidual, double &aVariance, double &aDownWeight,
121  unsigned int &numLocal, unsigned int* &indLocal, double* &derLocal);
122 
123 private:
124  unsigned int theLabel;
125  unsigned int theRow;
127  double theValue;
128  double thePrecision;
129  unsigned int theTrajectory;
130  unsigned int thePoint;
131  unsigned int theDWMethod;
132  double theDownWeight;
133  double thePrediction;
134  // standard local parameters (curvature, offsets), fixed size
135  unsigned int theNumLocal;
136  unsigned int theParameters[7];
137  double theDerivatives[7];
138  // more local parameters, dynamic size
139  std::vector<unsigned int> moreParameters;
140  std::vector<double> moreDerivatives;
141 };
142 
143 template<typename LocalDerivative, typename ExtDerivative>
144 void GblData::addDerivatives(unsigned int iRow,
145  const std::array<unsigned int, 5>& labDer, const Matrix5d &matDer,
146  unsigned int iOff, const Eigen::MatrixBase<LocalDerivative>& derLocal,
147  unsigned int extOff, const Eigen::MatrixBase<ExtDerivative>& extDer) {
148 
149  unsigned int nParMax = 5 + derLocal.cols() + extDer.cols();
150  theRow = iRow - iOff;
151  if (nParMax > 7) {
152  // dynamic data block size
153  moreParameters.reserve(nParMax); // have to be sorted
154  moreDerivatives.reserve(nParMax);
155 
156  for (int i = 0; i < derLocal.cols(); ++i) // local derivatives
157  {
158  if (derLocal(iRow - iOff, i)) {
159  moreParameters.push_back(i + 1);
160  moreDerivatives.push_back(derLocal(iRow - iOff, i));
161  }
162  }
163 
164  for (int i = 0; i < extDer.cols(); ++i) // external derivatives
165  {
166  if (extDer(iRow - iOff, i)) {
167  moreParameters.push_back(extOff + i + 1);
168  moreDerivatives.push_back(extDer(iRow - iOff, i));
169  }
170  }
171 
172  for (size_t i = 0; i < labDer.size(); ++i) // curvature, offset derivatives
173  {
174  if (labDer[i] and matDer(iRow, i)) {
175  moreParameters.push_back(labDer[i]);
176  moreDerivatives.push_back(matDer(iRow, i));
177  }
178  }
179  } else {
180  // simple (static) data block
181  for (int i = 0; i < derLocal.cols(); ++i) // local derivatives
182  {
183  if (derLocal(iRow - iOff, i)) {
184  theParameters[theNumLocal] = i + 1;
185  theDerivatives[theNumLocal] = derLocal(iRow - iOff, i);
186  theNumLocal++;
187  }
188  }
189 
190  for (int i = 0; i < extDer.cols(); ++i) // external derivatives
191  {
192  if (extDer(iRow - iOff, i)) {
193  theParameters[theNumLocal] = extOff + i + 1;
194  theDerivatives[theNumLocal] = extDer(iRow - iOff, i);
195  theNumLocal++;
196  }
197  }
198  for (size_t i = 0; i < labDer.size(); ++i) // curvature, offset derivatives
199  {
200  if (labDer[i] and matDer(iRow, i)) {
201  theParameters[theNumLocal] = labDer[i];
202  theDerivatives[theNumLocal] = matDer(iRow, i);
203  theNumLocal++;
204  }
205  }
206  }
207 }
208 
209 template<typename ExtDerivative>
210 void GblData::addDerivatives(unsigned int iRow,
211  const std::array<unsigned int, 7>& labDer, const Matrix27d &matDer,
212  unsigned int extOff, const Eigen::MatrixBase<ExtDerivative>& extDer) {
213 
214  unsigned int nParMax = 7 + extDer.cols();
215  theRow = iRow;
216  if (nParMax > 7) {
217  // dynamic data block size
218  moreParameters.reserve(nParMax); // have to be sorted
219  moreDerivatives.reserve(nParMax);
220 
221  for (int i = 0; i < extDer.cols(); ++i) // external derivatives
222  {
223  if (extDer(iRow, i)) {
224  moreParameters.push_back(extOff + i + 1);
225  moreDerivatives.push_back(extDer(iRow, i));
226  }
227  }
228 
229  for (size_t i = 0; i < labDer.size(); ++i) // curvature, offset derivatives
230  {
231  if (labDer[i] and matDer(iRow, i)) {
232  moreParameters.push_back(labDer[i]);
233  moreDerivatives.push_back(matDer(iRow, i));
234  }
235  }
236  } else {
237  // simple (static) data block
238  for (size_t i = 0; i < labDer.size(); ++i) // curvature, offset derivatives
239  {
240  if (labDer[i] and matDer(iRow, i)) {
241  theParameters[theNumLocal] = labDer[i];
242  theDerivatives[theNumLocal] = matDer(iRow, i);
243  theNumLocal++;
244  }
245  }
246  }
247 }
248 
249 }
250 
251 #endif /* GBLDATA_H_ */
Data (block) for independent scalar measurement.
Definition: GblData.h:58
double thePrecision
Precision (1/sigma**2)
Definition: GblData.h:128
std::vector< unsigned int > moreParameters
List of fit parameters (with non zero derivatives)
Definition: GblData.h:139
unsigned int getNumSimple() const
double theDownWeight
Down-weighting factor (0-1)
Definition: GblData.h:132
double theDerivatives[7]
List of derivatives for fit.
Definition: GblData.h:137
double thePrediction
Prediction from fit.
Definition: GblData.h:133
GblData(unsigned int aLabel, dataBlockType aType, double aMeas, double aPrec, unsigned int aTraj=0, unsigned int aPoint=0)
Create data block.
Definition: GblData.cpp:45
unsigned int theTrajectory
Trajectory number.
Definition: GblData.h:129
unsigned int theNumLocal
Number of (non zero) local derivatives (max 7 for kinks)
Definition: GblData.h:135
unsigned int theLabel
Label (of corresponding point)
Definition: GblData.h:124
dataBlockType theType
Type (None, InternalMeasurement, InternalKink, ExternalSeed, ExternalMeasurement)
Definition: GblData.h:126
unsigned int theDWMethod
Down-weighting method (0: None, 1: Tukey, 2: Huber, 3: Cauchy)
Definition: GblData.h:131
virtual ~GblData()
Definition: GblData.cpp:53
GblData & operator=(GblData &&)=default
void addDerivatives(unsigned int iRow, const std::array< unsigned int, 5 > &labDer, const Matrix5d &matDer, unsigned int iOff, const Eigen::MatrixBase< LocalDerivative > &derLocal, unsigned int extOff, const Eigen::MatrixBase< ExtDerivative > &extDer)
Add derivatives from measurement.
Definition: GblData.h:144
dataBlockType getType() const
Get type.
Definition: GblData.cpp:185
unsigned int theParameters[7]
List of parameters (with non zero derivatives)
Definition: GblData.h:136
GblData(GblData &&)=default
unsigned int getLabel() const
Get label.
Definition: GblData.cpp:177
unsigned int theRow
Row number (of measurement)
Definition: GblData.h:125
GblData & operator=(const GblData &)=default
double getChi2() const
Calculate Chi2 contribution.
Definition: GblData.cpp:125
void printData() const
Print data block.
Definition: GblData.cpp:150
void getResidual(double &aResidual, double &aVariance, double &aDownWeight, unsigned int &numLocal, unsigned int *&indLocal, double *&derLocal)
Get data for residual (and errors).
Definition: GblData.cpp:252
unsigned int thePoint
Point number (on trajectory)
Definition: GblData.h:130
GblData(const GblData &)=default
void getLocalData(double &aValue, double &aWeight, unsigned int &numLocal, unsigned int *&indLocal, double *&derLocal)
Get Data for local fit.
Definition: GblData.cpp:197
void getAllData(double &aValue, double &aErr, unsigned int &numLocal, unsigned int *&indLocal, double *&derLocal, unsigned int &aTraj, unsigned int &aPoint, unsigned int &aRow)
Get all Data for MP-II binary record.
Definition: GblData.cpp:224
double theValue
Value (residual)
Definition: GblData.h:127
double setDownWeighting(unsigned int aMethod)
Outlier down weighting with M-estimators (by GblTrajectory::fit).
Definition: GblData.cpp:93
std::vector< double > moreDerivatives
List of derivatives for fit.
Definition: GblData.h:140
void setPrediction(const VVector &aVector)
Calculate prediction for data from fit (by GblTrajectory::fit).
Definition: GblData.cpp:74
Simple Vector based on std::vector<double>
Definition: VMatrix.h:43
Namespace for the general broken lines package.
Eigen::Matrix< double, 2, 7 > Matrix27d
Definition: GblData.h:47
dataBlockType
Definition: GblData.h:49
@ InternalMeasurement
Definition: GblData.h:50
@ ExternalMeasurement
Definition: GblData.h:50
@ None
Definition: GblData.h:50
@ ExternalSeed
Definition: GblData.h:50
@ InternalKink
Definition: GblData.h:50
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: GblData.h:46