CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions
LinearFit Class Reference

#include <LinearFit.h>

Public Member Functions

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
 

Detailed Description

Straight line fit for data with errors on one coordinate

Definition at line 9 of file LinearFit.h.

Member Function Documentation

void LinearFit::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

x_i, y_i: measurements of y(x_i), sigy_i: error (sigma) on y_i slope, intercept: fitted parameters covss, covii, covsi: covariance matrix of fitted parameters, s denoting slope, i denoting intercept

Definition at line 3 of file LinearFit.cc.

References ztail::d, diffTwoXMLs::g1, diffTwoXMLs::g2, and i.

Referenced by trackingPlots.Iteration::modules(), and LinearFitErrorsIn2Coord::slope().

7 {
8 
9  float g1 = 0, g2 = 0;
10  float s11 = 0, s12 = 0, s22 = 0;
11  for (int i = 0; i != ndat; i++) {
12  float sy2 = sigy[i] * sigy[i];
13  g1 += y[i] / sy2;
14  g2 += x[i]*y[i] / sy2;
15  s11 += 1. / sy2;
16  s12 += x[i] / sy2;
17  s22 += x[i]*x[i] / sy2;
18  }
19 
20  float d = s11*s22 - s12*s12;
21  intercept = (g1*s22 - g2*s12) / d;
22  slope = (g2*s11 - g1*s12) / d;
23 
24  covii = s22 / d;
25  covss = s11 / d;
26  covsi = -s12 / d;
27 
28 }
int i
Definition: DBlmapReader.cc:9
static const double slope[3]
tuple d
Definition: ztail.py:151