CMS 3D CMS Logo

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