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