test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
9 
11 namespace gbl {
12 
14 
19 GblData::GblData(unsigned int aLabel, double aValue, double aPrec) :
20  theLabel(aLabel), theValue(aValue), thePrecision(aPrec), theDownWeight(
21  1.), thePrediction(0.), theParameters(), theDerivatives(), globalLabels(), globalDerivatives() {
22 
23 }
24 
26 }
27 
29 
41 void GblData::addDerivatives(unsigned int iRow,
42  const std::vector<unsigned int> &labDer, const SMatrix55 &matDer,
43  unsigned int iOff, const TMatrixD &derLocal,
44  const std::vector<int> &labGlobal, const TMatrixD &derGlobal,
45  unsigned int extOff, const TMatrixD &extDer) {
46 
47  unsigned int nParMax = 5 + derLocal.GetNcols() + extDer.GetNcols();
48  theParameters.reserve(nParMax); // have to be sorted
49  theDerivatives.reserve(nParMax);
50 
51  for (int i = 0; i < derLocal.GetNcols(); ++i) // local derivatives
52  {
53  if (derLocal(iRow - iOff, i)) {
54  theParameters.push_back(i + 1);
55  theDerivatives.push_back(derLocal(iRow - iOff, i));
56  }
57  }
58 
59  for (int i = 0; i < extDer.GetNcols(); ++i) // external derivatives
60  {
61  if (extDer(iRow - iOff, i)) {
62  theParameters.push_back(extOff + i + 1);
63  theDerivatives.push_back(extDer(iRow - iOff, i));
64  }
65  }
66 
67  for (unsigned int i = 0; i < 5; ++i) // curvature, offset derivatives
68  {
69  if (labDer[i] and matDer(iRow, i)) {
70  theParameters.push_back(labDer[i]);
71  theDerivatives.push_back(matDer(iRow, i));
72  }
73  }
74 
75  globalLabels = labGlobal;
76  for (int i = 0; i < derGlobal.GetNcols(); ++i) // global derivatives
77  globalDerivatives.push_back(derGlobal(iRow - iOff, i));
78 }
79 
81 
89 void GblData::addDerivatives(unsigned int iRow,
90  const std::vector<unsigned int> &labDer, const SMatrix27 &matDer,
91  unsigned int extOff, const TMatrixD &extDer) {
92 
93  unsigned int nParMax = 7 + extDer.GetNcols();
94  theParameters.reserve(nParMax); // have to be sorted
95  theDerivatives.reserve(nParMax);
96 
97  for (int i = 0; i < extDer.GetNcols(); ++i) // external derivatives
98  {
99  if (extDer(iRow, i)) {
100  theParameters.push_back(extOff + i + 1);
101  theDerivatives.push_back(extDer(iRow, i));
102  }
103  }
104 
105  for (unsigned int i = 0; i < 7; ++i) // curvature, offset derivatives
106  {
107  if (labDer[i] and matDer(iRow, i)) {
108  theParameters.push_back(labDer[i]);
109  theDerivatives.push_back(matDer(iRow, i));
110  }
111  }
112 }
113 
115 
120 void GblData::addDerivatives(const std::vector<unsigned int> &index,
121  const std::vector<double> &derivatives) {
122  for (unsigned int i = 0; i < derivatives.size(); ++i) // any derivatives
123  {
124  if (derivatives[i]) {
125  theParameters.push_back(index[i]);
126  theDerivatives.push_back(derivatives[i]);
127  }
128  }
129 }
130 
132 void GblData::setPrediction(const VVector &aVector) {
133 
134  thePrediction = 0.;
135  for (unsigned int i = 0; i < theDerivatives.size(); ++i) {
136  thePrediction += theDerivatives[i] * aVector(theParameters[i] - 1);
137  }
138 }
139 
141 
144 double GblData::setDownWeighting(unsigned int aMethod) {
145 
146  double aWeight = 1.;
147  double scaledResidual = fabs(theValue - thePrediction) * sqrt(thePrecision);
148  if (aMethod == 1) // Tukey
149  {
150  if (scaledResidual < 4.6851) {
151  aWeight = (1.0 - 0.045558 * scaledResidual * scaledResidual);
152  aWeight *= aWeight;
153  } else {
154  aWeight = 0.;
155  }
156  } else if (aMethod == 2) //Huber
157  {
158  if (scaledResidual >= 1.345) {
159  aWeight = 1.345 / scaledResidual;
160  }
161  } else if (aMethod == 3) //Cauchy
162  {
163  aWeight = 1.0 / (1.0 + (scaledResidual * scaledResidual / 5.6877));
164  }
165  theDownWeight = aWeight;
166  return aWeight;
167 }
168 
170 
173 double GblData::getChi2() const {
174  double aDiff = theValue - thePrediction;
175  return aDiff * aDiff * thePrecision * theDownWeight;
176 }
177 
179 void GblData::printData() const {
180 
181  std::cout << " measurement at label " << theLabel << ": " << theValue
182  << ", " << thePrecision << std::endl;
183  std::cout << " param " << theParameters.size() << ":";
184  for (unsigned int i = 0; i < theParameters.size(); ++i) {
185  std::cout << " " << theParameters[i];
186  }
187  std::cout << std::endl;
188  std::cout << " deriv " << theDerivatives.size() << ":";
189  for (unsigned int i = 0; i < theDerivatives.size(); ++i) {
190  std::cout << " " << theDerivatives[i];
191  }
192  std::cout << std::endl;
193 }
194 
196 
202 void GblData::getLocalData(double &aValue, double &aWeight,
203  std::vector<unsigned int>* &indLocal, std::vector<double>* &derLocal) {
204 
205  aValue = theValue;
206  aWeight = thePrecision * theDownWeight;
207  indLocal = &theParameters;
208  derLocal = &theDerivatives;
209 }
210 
212 
220 void GblData::getAllData(double &aValue, double &aErr,
221  std::vector<unsigned int>* &indLocal, std::vector<double>* &derLocal,
222  std::vector<int>* &labGlobal, std::vector<double>* &derGlobal) {
223  aValue = theValue;
224  aErr = 1.0 / sqrt(thePrecision);
225  indLocal = &theParameters;
226  derLocal = &theDerivatives;
227  labGlobal = &globalLabels;
228  derGlobal = &globalDerivatives;
229 }
230 
232 
239 void GblData::getResidual(double &aResidual, double &aVariance,
240  double &aDownWeight, std::vector<unsigned int>* &indLocal,
241  std::vector<double>* &derLocal) {
242  aResidual = theValue - thePrediction;
243  aVariance = 1.0 / thePrecision;
244  aDownWeight = theDownWeight;
245  indLocal = &theParameters;
246  derLocal = &theDerivatives;
247 }
248 }
std::vector< unsigned int > theParameters
List of fit parameters (with non zero derivatives)
Definition: GblData.h:69
int i
Definition: DBlmapReader.cc:9
std::vector< double > theDerivatives
List of derivatives for fit.
Definition: GblData.h:70
ROOT::Math::SMatrix< double, 2, 7 > SMatrix27
Definition: GblData.h:22
GblData(unsigned int aLabel, double aMeas, double aPrec)
Create data block.
Definition: GblData.cc:19
void getLocalData(double &aValue, double &aWeight, std::vector< unsigned int > *&indLocal, std::vector< double > *&derLocal)
Get Data for local fit.
Definition: GblData.cc:202
double getChi2() const
Calculate Chi2 contribution.
Definition: GblData.cc:173
void getResidual(double &aResidual, double &aVariance, double &aDownWeight, std::vector< unsigned int > *&indLocal, std::vector< double > *&derLocal)
Get data for residual (and errors).
Definition: GblData.cc:239
unsigned int theLabel
Label (of measurements point)
Definition: GblData.h:64
ROOT::Math::SMatrix< double, 5, 5 > SMatrix55
Definition: GblData.h:23
T sqrt(T t)
Definition: SSEVec.h:18
double theDownWeight
Down-weighting factor (0-1)
Definition: GblData.h:67
void setPrediction(const VVector &aVector)
Calculate prediction for data from fit (by GblTrajectory::fit).
Definition: GblData.cc:132
double thePrediction
Prediction from fit.
Definition: GblData.h:68
std::vector< int > globalLabels
Labels for global derivatives.
Definition: GblData.h:71
std::vector< double > globalDerivatives
Global derivatives.
Definition: GblData.h:72
double thePrecision
Precision (1/sigma**2)
Definition: GblData.h:66
void printData() const
Print data block.
Definition: GblData.cc:179
double setDownWeighting(unsigned int aMethod)
Outlier down weighting with M-estimators (by GblTrajectory::fit).
Definition: GblData.cc:144
virtual ~GblData()
Definition: GblData.cc:25
Simple Vector based on std::vector&lt;double&gt;
Definition: VMatrix.h:21
double theValue
Value (residual)
Definition: GblData.h:65
tuple cout
Definition: gather_cfg.py:145
void addDerivatives(unsigned int iRow, const std::vector< unsigned int > &labDer, const SMatrix55 &matDer, unsigned int iOff, const TMatrixD &derLocal, const std::vector< int > &labGlobal, const TMatrixD &derGlobal, unsigned int nLocal, const TMatrixD &derTrans)
Add derivatives from measurement.
Definition: GblData.cc:41
void getAllData(double &aValue, double &aErr, std::vector< unsigned int > *&indLocal, std::vector< double > *&derLocal, std::vector< int > *&labGlobal, std::vector< double > *&derGlobal)
Get all Data for MP-II binary record.
Definition: GblData.cc:220