12 #include <sys/types.h> 27 std::vector<float>& ey2,
float& Intercept,
float& Slope,
28 float& InterceptError,
float& SlopeError,
float& ChiDOF)
35 if(y.size() < 2)
return;
36 if(x.size() < y.size() || ey2.size() < y.size())
return;
47 for(ii = 0; ii < y.size(); ++ii) {
48 weight = 1. / ey2[ii];
50 sumx += weight * x[ii];
51 sumy += weight * y[ii];
52 sumx2 += weight * x[ii] * x[ii];
53 sumxy += weight * x[ii] * y[ii];
54 sumy2 += weight * y[ii] * y[ii];
57 double delta = sum * sumx2 - sumx * sumx;
58 if(delta == 0.)
return;
59 double A = (sumx2 * sumy - sumx * sumxy) / delta;
60 double B = (sumxy * sum - sumx * sumy) / delta;
67 double ndof = x.size() - 2;
68 double varnce = (sumy2 + A*A*sum + B*B*sumx2 - 2 * (A*sumy + B*sumxy - A*B*sumx)) / ndof;
70 InterceptError = sqrt(varnce * sumx2 / delta);
71 SlopeError = sqrt(varnce * sum / delta);
78 for(ii = 0; ii < y.size(); ++ii) {
79 arg = y[ii] - A - B * x[ii];
80 sum += arg * arg / ey2[ii];
void LinFit(std::vector< float > &x, std::vector< float > &y, std::vector< float > &ey2, float &Intercept, float &Slope, float &InterceptError, float &SlopeError, float &ChiDOF)