00001
00008
00009 #include "RecoLocalMuon/DTSegment/src/DTLinearFit.h"
00010
00011
00012
00013
00014 using namespace std;
00015
00016
00017
00019 DTLinearFit::DTLinearFit() {
00020
00021 }
00022
00024 DTLinearFit::~DTLinearFit() {
00025 }
00026
00027
00028 void DTLinearFit::fit(const vector<float> & x,
00029 const vector<float> & y,
00030 int ndat,
00031 const vector<float> & sigy,
00032 float& slope,
00033 float& intercept,
00034 float& covss,
00035 float& covii,
00036 float& covsi) const
00037 {
00038
00039 float g1 = 0, g2 = 0;
00040 float s11 = 0, s12 = 0, s22 = 0;
00041 for (int i = 0; i != ndat; i++) {
00042 float sy2 = sigy[i] * sigy[i];
00043 g1 += y[i] / sy2;
00044 g2 += x[i]*y[i] / sy2;
00045 s11 += 1. / sy2;
00046 s12 += x[i] / sy2;
00047 s22 += x[i]*x[i] / sy2;
00048 }
00049
00050 float d = s11*s22 - s12*s12;
00051 intercept = (g1*s22 - g2*s12) / d;
00052 slope = (g2*s11 - g1*s12) / d;
00053
00054 covii = s22 / d;
00055 covss = s11 / d;
00056 covsi = -s12 / d;
00057
00058 }