File indexing completed on 2025-08-05 08:18:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #include "GblData.h"
0031
0032
0033 namespace gbl {
0034
0035
0036
0037
0038
0039
0040
0041 GblData::GblData(unsigned int aLabel, double aValue, double aPrec) :
0042 theLabel(aLabel), theValue(aValue), thePrecision(aPrec), theDownWeight(
0043 1.), thePrediction(0.), theParameters(), theDerivatives(), globalLabels(), globalDerivatives() {
0044
0045 }
0046
0047 GblData::~GblData() {
0048 }
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 void GblData::addDerivatives(unsigned int iRow,
0064 const std::vector<unsigned int> &labDer, const SMatrix55 &matDer,
0065 unsigned int iOff, const TMatrixD &derLocal,
0066 const std::vector<int> &labGlobal, const TMatrixD &derGlobal,
0067 unsigned int extOff, const TMatrixD &extDer) {
0068
0069 unsigned int nParMax = 5 + derLocal.GetNcols() + extDer.GetNcols();
0070 theParameters.reserve(nParMax);
0071 theDerivatives.reserve(nParMax);
0072
0073 for (int i = 0; i < derLocal.GetNcols(); ++i)
0074 {
0075 if (derLocal(iRow - iOff, i)) {
0076 theParameters.push_back(i + 1);
0077 theDerivatives.push_back(derLocal(iRow - iOff, i));
0078 }
0079 }
0080
0081 for (int i = 0; i < extDer.GetNcols(); ++i)
0082 {
0083 if (extDer(iRow - iOff, i)) {
0084 theParameters.push_back(extOff + i + 1);
0085 theDerivatives.push_back(extDer(iRow - iOff, i));
0086 }
0087 }
0088
0089 for (unsigned int i = 0; i < 5; ++i)
0090 {
0091 if (labDer[i] and matDer(iRow, i)) {
0092 theParameters.push_back(labDer[i]);
0093 theDerivatives.push_back(matDer(iRow, i));
0094 }
0095 }
0096
0097 globalLabels = labGlobal;
0098 for (int i = 0; i < derGlobal.GetNcols(); ++i)
0099 globalDerivatives.push_back(derGlobal(iRow - iOff, i));
0100 }
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 void GblData::addDerivatives(unsigned int iRow,
0112 const std::vector<unsigned int> &labDer, const SMatrix27 &matDer,
0113 unsigned int extOff, const TMatrixD &extDer) {
0114
0115 unsigned int nParMax = 7 + extDer.GetNcols();
0116 theParameters.reserve(nParMax);
0117 theDerivatives.reserve(nParMax);
0118
0119 for (int i = 0; i < extDer.GetNcols(); ++i)
0120 {
0121 if (extDer(iRow, i)) {
0122 theParameters.push_back(extOff + i + 1);
0123 theDerivatives.push_back(extDer(iRow, i));
0124 }
0125 }
0126
0127 for (unsigned int i = 0; i < 7; ++i)
0128 {
0129 if (labDer[i] and matDer(iRow, i)) {
0130 theParameters.push_back(labDer[i]);
0131 theDerivatives.push_back(matDer(iRow, i));
0132 }
0133 }
0134 }
0135
0136
0137
0138
0139
0140
0141
0142 void GblData::addDerivatives(const std::vector<unsigned int> &index,
0143 const std::vector<double> &derivatives) {
0144 for (unsigned int i = 0; i < derivatives.size(); ++i)
0145 {
0146 if (derivatives[i]) {
0147 theParameters.push_back(index[i]);
0148 theDerivatives.push_back(derivatives[i]);
0149 }
0150 }
0151 }
0152
0153
0154 void GblData::setPrediction(const VVector &aVector) {
0155
0156 thePrediction = 0.;
0157 for (unsigned int i = 0; i < theDerivatives.size(); ++i) {
0158 thePrediction += theDerivatives[i] * aVector(theParameters[i] - 1);
0159 }
0160 }
0161
0162
0163
0164
0165
0166 double GblData::setDownWeighting(unsigned int aMethod) {
0167
0168 double aWeight = 1.;
0169 double scaledResidual = fabs(theValue - thePrediction) * sqrt(thePrecision);
0170 if (aMethod == 1)
0171 {
0172 if (scaledResidual < 4.6851) {
0173 aWeight = (1.0 - 0.045558 * scaledResidual * scaledResidual);
0174 aWeight *= aWeight;
0175 } else {
0176 aWeight = 0.;
0177 }
0178 } else if (aMethod == 2)
0179 {
0180 if (scaledResidual >= 1.345) {
0181 aWeight = 1.345 / scaledResidual;
0182 }
0183 } else if (aMethod == 3)
0184 {
0185 aWeight = 1.0 / (1.0 + (scaledResidual * scaledResidual / 5.6877));
0186 }
0187 theDownWeight = aWeight;
0188 return aWeight;
0189 }
0190
0191
0192
0193
0194
0195 double GblData::getChi2() const {
0196 double aDiff = theValue - thePrediction;
0197 return aDiff * aDiff * thePrecision * theDownWeight;
0198 }
0199
0200
0201 void GblData::printData() const {
0202
0203 std::cout << " measurement at label " << theLabel << ": " << theValue
0204 << ", " << thePrecision << std::endl;
0205 std::cout << " param " << theParameters.size() << ":";
0206 for (unsigned int i = 0; i < theParameters.size(); ++i) {
0207 std::cout << " " << theParameters[i];
0208 }
0209 std::cout << std::endl;
0210 std::cout << " deriv " << theDerivatives.size() << ":";
0211 for (unsigned int i = 0; i < theDerivatives.size(); ++i) {
0212 std::cout << " " << theDerivatives[i];
0213 }
0214 std::cout << std::endl;
0215 }
0216
0217
0218
0219
0220
0221
0222
0223
0224 void GblData::getLocalData(double &aValue, double &aWeight,
0225 std::vector<unsigned int>* &indLocal, std::vector<double>* &derLocal) {
0226
0227 aValue = theValue;
0228 aWeight = thePrecision * theDownWeight;
0229 indLocal = &theParameters;
0230 derLocal = &theDerivatives;
0231 }
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242 void GblData::getAllData(double &aValue, double &aErr,
0243 std::vector<unsigned int>* &indLocal, std::vector<double>* &derLocal,
0244 std::vector<int>* &labGlobal, std::vector<double>* &derGlobal) {
0245 aValue = theValue;
0246 aErr = 1.0 / sqrt(thePrecision);
0247 indLocal = &theParameters;
0248 derLocal = &theDerivatives;
0249 labGlobal = &globalLabels;
0250 derGlobal = &globalDerivatives;
0251 }
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261 void GblData::getResidual(double &aResidual, double &aVariance,
0262 double &aDownWeight, std::vector<unsigned int>* &indLocal,
0263 std::vector<double>* &derLocal) {
0264 aResidual = theValue - thePrediction;
0265 aVariance = 1.0 / thePrecision;
0266 aDownWeight = theDownWeight;
0267 indLocal = &theParameters;
0268 derLocal = &theDerivatives;
0269 }
0270 }