![]() |
GeneralBrokenLines
V01-11-00
|
00001 /* 00002 * GblData.cpp 00003 * 00004 * Created on: Aug 18, 2011 00005 * Author: kleinwrt 00006 */ 00007 00008 #include "GblData.h" 00009 00011 00016 GblData::GblData(unsigned int aLabel, double aValue, double aPrec) : 00017 theLabel(aLabel), theValue(aValue), thePrecision(aPrec), theDownWeight( 00018 1.), thePrediction(0.), theParameters(), theDerivatives(), globalLabels(), globalDerivatives() { 00019 // TODO Auto-generated constructor stub 00020 } 00021 00022 GblData::~GblData() { 00023 // TODO Auto-generated destructor stub 00024 } 00025 00027 00037 void GblData::addDerivatives(unsigned int iRow, 00038 const std::vector<unsigned int> &labDer, const SMatrix55 &matDer, 00039 unsigned int iOff, const TMatrixD &derLocal, 00040 const std::vector<int> &labGlobal, const TMatrixD &derGlobal) { 00041 00042 unsigned int nParMax = 5 + derLocal.GetNcols(); 00043 theParameters.reserve(nParMax); // have to be sorted 00044 theDerivatives.reserve(nParMax); 00045 00046 for (int i = 0; i < derLocal.GetNcols(); i++) // local derivatives 00047 { 00048 if (derLocal(iRow - iOff, i)) { 00049 theParameters.push_back(i + 1); 00050 theDerivatives.push_back(derLocal(iRow - iOff, i)); 00051 } 00052 } 00053 00054 for (unsigned int i = 0; i < 5; i++) // curvature, offset derivatives 00055 { 00056 if (labDer[i] and matDer(iRow, i)) { 00057 theParameters.push_back(labDer[i]); 00058 theDerivatives.push_back(matDer(iRow, i)); 00059 } 00060 } 00061 00062 globalLabels = labGlobal; 00063 for (int i = 0; i < derGlobal.GetNcols(); i++) // global derivatives 00064 globalDerivatives.push_back(derGlobal(iRow - iOff, i)); 00065 } 00066 00068 00074 void GblData::addDerivatives(unsigned int iRow, 00075 const std::vector<unsigned int> &labDer, const SMatrix27 &matDer) { 00076 00077 unsigned int nParMax = 7; 00078 theParameters.reserve(nParMax); // have to be sorted 00079 theDerivatives.reserve(nParMax); 00080 00081 for (unsigned int i = 0; i < 7; i++) // curvature, offset derivatives 00082 { 00083 if (labDer[i] and matDer(iRow, i)) { 00084 theParameters.push_back(labDer[i]); 00085 theDerivatives.push_back(matDer(iRow, i)); 00086 } 00087 } 00088 } 00089 00091 00096 void GblData::addDerivatives(const std::vector<unsigned int> &index, 00097 const std::vector<double> &derivatives) { 00098 for (unsigned int i = 0; i < derivatives.size(); i++) // any derivatives 00099 { 00100 if (derivatives[i]) { 00101 theParameters.push_back(index[i]); 00102 theDerivatives.push_back(derivatives[i]); 00103 } 00104 } 00105 } 00106 00108 void GblData::setPrediction(const VVector &aVector) { 00109 00110 thePrediction = 0.; 00111 for (unsigned int i = 0; i < theDerivatives.size(); i++) { 00112 thePrediction += theDerivatives[i] * aVector(theParameters[i] - 1); 00113 } 00114 } 00115 00117 00120 double GblData::setDownWeighting(unsigned int aMethod) { 00121 00122 double aWeight = 1.; 00123 double scaledResidual = fabs(theValue - thePrediction) * sqrt(thePrecision); 00124 if (aMethod == 1) // Tukey 00125 { 00126 if (scaledResidual < 4.6851) { 00127 aWeight = (1.0 - 0.045558 * scaledResidual * scaledResidual); 00128 aWeight *= aWeight; 00129 } else { 00130 aWeight = 0.; 00131 } 00132 } else if (aMethod == 2) //Huber 00133 { 00134 if (scaledResidual >= 1.345) { 00135 aWeight = 1.345 / scaledResidual; 00136 } 00137 } else if (aMethod == 3) //Cauchy 00138 { 00139 aWeight = 1.0 / (1.0 + (scaledResidual * scaledResidual / 5.6877)); 00140 } 00141 theDownWeight = aWeight; 00142 return aWeight; 00143 } 00144 00146 00149 double GblData::getChi2() const { 00150 double aDiff = theValue - thePrediction; 00151 return aDiff * aDiff * thePrecision * theDownWeight; 00152 } 00153 00155 void GblData::printData() const { 00156 00157 std::cout << " meas. " << theLabel << "," << theValue << "," << thePrecision 00158 << std::endl; 00159 std::cout << " param " << theParameters.size() << ":"; 00160 for (unsigned int i = 0; i < theParameters.size(); i++) { 00161 std::cout << " " << theParameters[i]; 00162 } 00163 std::cout << std::endl; 00164 std::cout << " deriv " << theDerivatives.size() << ":"; 00165 for (unsigned int i = 0; i < theDerivatives.size(); i++) { 00166 std::cout << " " << theDerivatives[i]; 00167 } 00168 std::cout << std::endl; 00169 } 00170 00172 00178 void GblData::getLocalData(double &aValue, double &aWeight, 00179 std::vector<unsigned int>* &indLocal, std::vector<double>* &derLocal) { 00180 00181 aValue = theValue; 00182 aWeight = thePrecision * theDownWeight; 00183 indLocal = &theParameters; 00184 derLocal = &theDerivatives; 00185 } 00186 00188 00196 void GblData::getAllData(float &fValue, float &fErr, 00197 std::vector<unsigned int>* &indLocal, std::vector<double>* &derLocal, 00198 std::vector<int>* &labGlobal, std::vector<double>* &derGlobal) { 00199 fValue = theValue; 00200 fErr = 1.0 / sqrt(thePrecision); 00201 indLocal = &theParameters; 00202 derLocal = &theDerivatives; 00203 labGlobal = &globalLabels; 00204 derGlobal = &globalDerivatives; 00205 }
1.7.6.1