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