CMS 3D CMS Logo

GblData.cc
Go to the documentation of this file.
1 /*
2  * GblData.cpp
3  *
4  * Created on: Aug 18, 2011
5  * Author: kleinwrt
6  */
7 
31 using namespace Eigen;
32 
34 namespace gbl {
35 
37 
45  GblData::GblData(unsigned int aLabel, dataBlockType aType, double aValue,
46  double aPrec, unsigned int aTraj, unsigned int aPoint) :
47  theLabel(aLabel), theRow(0), theType(aType), theValue(aValue),
48  thePrecision(aPrec), theTrajectory(aTraj), thePoint(aPoint),
49  theDownWeight(1.), thePrediction(0.), theNumLocal(0), moreParameters(),
50  moreDerivatives()
51  {
52  }
53 
55  }
56 
58 
63  void GblData::addDerivatives(const std::vector<unsigned int> &index,
64  const std::vector<double> &derivatives) {
65  for (unsigned int i = 0; i < derivatives.size(); ++i) // any derivatives
66  {
67  if (derivatives[i]) {
68  moreParameters.push_back(index[i]);
69  moreDerivatives.push_back(derivatives[i]);
70  }
71  }
72  }
73 
75  void GblData::setPrediction(const VVector &aVector) {
76 
77  thePrediction = 0.;
78  if (theNumLocal > 0) {
79  for (unsigned int i = 0; i < theNumLocal; ++i) {
80  thePrediction += theDerivatives[i] * aVector(theParameters[i] - 1);
81  }
82  } else {
83  for (unsigned int i = 0; i < moreDerivatives.size(); ++i) {
85  * aVector(moreParameters[i] - 1);
86  }
87  }
88  }
89 
91 
94  double GblData::setDownWeighting(unsigned int aMethod) {
95 
96  double aWeight = 1.;
97  double scaledResidual = fabs(theValue - thePrediction) * sqrt(thePrecision);
98  if (aMethod == 1) // Tukey
99  {
100  if (scaledResidual < 4.6851) {
101  aWeight = (1.0 - 0.045558 * scaledResidual * scaledResidual);
102  aWeight *= aWeight;
103  } else {
104  aWeight = 0.;
105  }
106  } else if (aMethod == 2) //Huber
107  {
108  if (scaledResidual >= 1.345) {
109  aWeight = 1.345 / scaledResidual;
110  }
111  } else if (aMethod == 3) //Cauchy
112  {
113  aWeight = 1.0 / (1.0 + (scaledResidual * scaledResidual / 5.6877));
114  }
115  theDownWeight = aWeight;
116  return aWeight;
117  }
118 
120 
123  double GblData::getChi2() const {
124  double aDiff = theValue - thePrediction;
125  return aDiff * aDiff * thePrecision * theDownWeight;
126  }
127 
129  void GblData::printData() const {
130 
131  std::cout << " measurement at label " << theLabel << " of type " << theType
132  << " from row " << theRow << ": " << theValue << ", "
133  << thePrecision << std::endl;
134  std::cout << " param " << moreParameters.size() + theNumLocal << ":";
135  for (unsigned int i = 0; i < moreParameters.size(); ++i) {
136  std::cout << " " << moreParameters[i];
137  }
138  for (unsigned int i = 0; i < theNumLocal; ++i) {
139  std::cout << " " << theParameters[i];
140  }
141  std::cout << std::endl;
142  std::cout << " deriv " << moreDerivatives.size() + theNumLocal << ":";
143  for (unsigned int i = 0; i < moreDerivatives.size(); ++i) {
144  std::cout << " " << moreDerivatives[i];
145  }
146  for (unsigned int i = 0; i < theNumLocal; ++i) {
147  std::cout << " " << theDerivatives[i];
148  }
149  std::cout << std::endl;
150  }
151 
153 
156  unsigned int GblData::getLabel() const {
157  return theLabel;
158  }
159 
161 
165  return theType;
166  }
167 
169 
176  void GblData::getLocalData(double &aValue, double &aWeight,
177  unsigned int &numLocal, unsigned int* &indLocal, double* &derLocal) {
178 
179  aValue = theValue;
180  aWeight = thePrecision * theDownWeight;
181  if (theNumLocal > 0) {
182  numLocal = theNumLocal;
183  indLocal = theParameters;
184  derLocal = theDerivatives;
185  } else {
186  numLocal = moreParameters.size();
187  indLocal = &moreParameters[0];
188  derLocal = &moreDerivatives[0];
189  }
190  }
191 
193 
203  void GblData::getAllData(double &aValue, double &aErr, unsigned int &numLocal,
204  unsigned int* &indLocal, double* &derLocal, unsigned int &aTraj,
205  unsigned int &aPoint, unsigned int &aRow) {
206  aValue = theValue;
207  aErr = 1.0 / sqrt(thePrecision);
208  if (theNumLocal > 0) {
209  numLocal = theNumLocal;
210  indLocal = theParameters;
211  derLocal = theDerivatives;
212  } else {
213  numLocal = moreParameters.size();
214  indLocal = &moreParameters[0];
215  derLocal = &moreDerivatives[0];
216  }
217  aTraj = theTrajectory;
218  aPoint = thePoint;
219  aRow = theRow;
220  }
221 
223 
231  void GblData::getResidual(double &aResidual, double &aVariance,
232  double &aDownWeight, unsigned int &numLocal, unsigned int* &indLocal,
233  double* &derLocal) {
234  aResidual = theValue - thePrediction;
235  aVariance = 1.0 / thePrecision;
236  aDownWeight = theDownWeight;
237  if (theNumLocal > 0) {
238  numLocal = theNumLocal;
239  indLocal = theParameters;
240  derLocal = theDerivatives;
241  } else {
242  numLocal = moreParameters.size();
243  indLocal = &moreParameters[0];
244  derLocal = &moreDerivatives[0];
245  }
246  }
247 }
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
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
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
T sqrt(T t)
Definition: SSEVec.h:18
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
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
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
unsigned int getLabel() const
Get label.
Definition: GblData.cc:156
unsigned int theTrajectory
Trajectory number.
Definition: GblData.h:100