CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTLinearFit.cc
Go to the documentation of this file.
1 
6 /* This Class Header */
8 
9 /* Collaborating Class Header */
10 
11 /* C++ Headers */
12 using namespace std;
13 
14 /* ====================================================================== */
15 
18 
19 }
20 
23 }
24 
25 /* Operations */
26 void DTLinearFit::fit(const vector<float> & x,
27  const vector<float> & y,
28  int ndat,
29  const vector<float> & sigy,
30  float& slope,
31  float& intercept,
32  float& covss,
33  float& covii,
34  float& covsi) const
35 {
36 
37  float g1 = 0, g2 = 0;
38  float s11 = 0, s12 = 0, s22 = 0;
39  for (int i = 0; i != ndat; i++) {
40  float sy2 = sigy[i] * sigy[i];
41  g1 += y[i] / sy2;
42  g2 += x[i]*y[i] / sy2;
43  s11 += 1. / sy2;
44  s12 += x[i] / sy2;
45  s22 += x[i]*x[i] / sy2;
46  }
47 
48  float d = s11*s22 - s12*s12;
49  intercept = (g1*s22 - g2*s12) / d;
50  slope = (g2*s11 - g1*s12) / d;
51 
52  covii = s22 / d;
53  covss = s11 / d;
54  covsi = -s12 / d;
55 
56 }
int i
Definition: DBlmapReader.cc:9
static const double slope[3]
~DTLinearFit()
Destructor.
Definition: DTLinearFit.cc:22
DTLinearFit()
Constructor.
Definition: DTLinearFit.cc:17
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
Definition: DTLinearFit.cc:26
Definition: DDAxes.h:10