#include <LinFitAlg.h>
Definition at line 18 of file LinFitAlg.h.
void trkf::LinFitAlg::LinFit |
( |
std::vector< float > & |
x, |
|
|
std::vector< float > & |
y, |
|
|
std::vector< float > & |
ey2, |
|
|
float & |
Intercept, |
|
|
float & |
Slope, |
|
|
float & |
InterceptError, |
|
|
float & |
SlopeError, |
|
|
float & |
ChiDOF |
|
) |
| const |
Definition at line 17 of file LinFitAlg.cxx.
26 if(y.size() < 2)
return;
27 if(x.size() < y.size() || ey2.size() < y.size())
return;
38 for(ii = 0; ii < y.size(); ++ii) {
39 weight = 1. / ey2[ii];
41 sumx += weight * x[ii];
42 sumy += weight * y[ii];
43 sumx2 += weight * x[ii] * x[ii];
44 sumxy += weight * x[ii] * y[ii];
45 sumy2 += weight * y[ii] * y[ii];
48 double delta = sum * sumx2 - sumx * sumx;
49 if(delta == 0.)
return;
50 double A = (sumx2 * sumy - sumx * sumxy) / delta;
51 double B = (sumxy * sum - sumx * sumy) / delta;
58 double ndof = x.size() - 2;
59 double varnce = (sumy2 + A*A*sum + B*B*sumx2 - 2 * (A*sumy + B*sumxy - A*B*sumx)) / ndof;
61 InterceptError = sqrt(varnce * sumx2 / delta);
62 SlopeError = sqrt(varnce * sum / delta);
69 for(ii = 0; ii < y.size(); ++ii) {
70 arg = y[ii] - A - B * x[ii];
71 sum += arg * arg / ey2[ii];
The documentation for this class was generated from the following files: