#include <CommonTools/Statistics/interface/LinearFit.h>
Public Member Functions | |
void | fit (const std::vector< float > &x, const std::vector< float > &y, int ndat, const std::vector< float > &sigy, float &slope, float &intercept, float &covss, float &covii, float &covsi) const |
x_i, y_i: measurements of y(x_i), sigy_i: error (sigma) on y_i slope, intercept: fitted parameters covss, covii, covsi: covariance matrix of fitted parameters, s denoting slope, i denoting intercept |
Definition at line 9 of file LinearFit.h.
void LinearFit::fit | ( | const std::vector< float > & | x, | |
const std::vector< float > & | y, | |||
int | ndat, | |||
const std::vector< float > & | sigy, | |||
float & | slope, | |||
float & | intercept, | |||
float & | covss, | |||
float & | covii, | |||
float & | covsi | |||
) | const |
x_i, y_i: measurements of y(x_i), sigy_i: error (sigma) on y_i slope, intercept: fitted parameters covss, covii, covsi: covariance matrix of fitted parameters, s denoting slope, i denoting intercept
Definition at line 3 of file LinearFit.cc.
References d, g1, g2, i, s12, and s22.
Referenced by LinearFitErrorsIn2Coord::slope().
00007 { 00008 00009 float g1 = 0, g2 = 0; 00010 float s11 = 0, s12 = 0, s22 = 0; 00011 for (int i = 0; i != ndat; i++) { 00012 float sy2 = sigy[i] * sigy[i]; 00013 g1 += y[i] / sy2; 00014 g2 += x[i]*y[i] / sy2; 00015 s11 += 1. / sy2; 00016 s12 += x[i] / sy2; 00017 s22 += x[i]*x[i] / sy2; 00018 } 00019 00020 float d = s11*s22 - s12*s12; 00021 intercept = (g1*s22 - g2*s12) / d; 00022 slope = (g2*s11 - g1*s12) / d; 00023 00024 covii = s22 / d; 00025 covss = s11 / d; 00026 covsi = -s12 / d; 00027 00028 }