CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions
LinearFitErrorsIn2Coord Class Reference

#include <LinearFitErrorsIn2Coord.h>

Public Member Functions

float intercept (const std::vector< float > &x, const std::vector< float > &y, int ndat, const std::vector< float > &sigx, const std::vector< float > &sigy) const
 
float slope (const std::vector< float > &x, const std::vector< float > &y, int ndat, const std::vector< float > &sigx, const std::vector< float > &sigy) const
 

Private Member Functions

float variance (const std::vector< float > &x, int ndat) const
 

Detailed Description

Straight line fit for data with errors on both coordinates source: Numerical Recipes

Definition at line 10 of file LinearFitErrorsIn2Coord.h.

Member Function Documentation

◆ intercept()

float LinearFitErrorsIn2Coord::intercept ( const std::vector< float > &  x,
const std::vector< float > &  y,
int  ndat,
const std::vector< float > &  sigx,
const std::vector< float > &  sigy 
) const

Approached intercept computed with approached slope

Definition at line 31 of file LinearFitErrorsIn2Coord.cc.

35  {
36  float fs = slope(x, y, ndat, sigx, sigy);
37  float fi = 0;
38  float sumWi = 0;
39  for (int i = 0; i != ndat; i++) {
40  float wi = 1. / (sigy[i] + fs * fs * sigx[i]);
41  fi += wi * (y[i] - fs * x[i]);
42  sumWi += wi;
43  }
44 
45  return fi / sumWi;
46 }

References mps_fire::i, slope(), x, and y.

◆ slope()

float LinearFitErrorsIn2Coord::slope ( const std::vector< float > &  x,
const std::vector< float > &  y,
int  ndat,
const std::vector< float > &  sigx,
const std::vector< float > &  sigy 
) const

Approached slope:

  • rescale y and sigy by var(x)/var(y)
  • fit a straight line with weights derived from the scaled sum sigx^2 + sigy^2

Definition at line 5 of file LinearFitErrorsIn2Coord.cc.

9  {
10  // scale y and sigy, compute scaled errors
11  float scale = sqrt(variance(x, ndat) / variance(y, ndat));
12  std::vector<float> yScaled = y;
13  std::vector<float> sigyScaled = sigy;
14  std::vector<float> sig(ndat);
15  for (int i = 0; i != ndat; i++) {
16  yScaled[i] *= scale;
17  sigyScaled[i] *= scale;
18  sig[i] = sqrt(sigx[i] * sigx[i] + sigyScaled[i] * sigyScaled[i]);
19  }
20 
21  // usual linear fit
22  LinearFit lf;
23  float fs, fi, covss, covii, covsi;
24  lf.fit(x, yScaled, ndat, sig, fs, fi, covss, covii, covsi);
25 
26  // unscale result
27  fs /= scale;
28  return fs;
29 }

References LinearFit::fit(), mps_fire::i, HLT_FULL_cff::scale, mathSSE::sqrt(), variance(), x, and y.

Referenced by intercept().

◆ variance()

float LinearFitErrorsIn2Coord::variance ( const std::vector< float > &  x,
int  ndat 
) const
private

Definition at line 48 of file LinearFitErrorsIn2Coord.cc.

48  {
49  double m1 = 0., m2 = 0.;
50  for (int i = 0; i != ndat; i++) {
51  m1 += x[i];
52  m2 += x[i] * x[i];
53  }
54  m1 /= ndat;
55  m2 /= ndat;
56 
57  return float(m2 - m1 * m1);
58 }

References dqmMemoryStats::float, mps_fire::i, and x.

Referenced by slope(), and average.Average::uncertainty().

DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:428
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
HLT_FULL_cff.scale
scale
Definition: HLT_FULL_cff.py:6637
LinearFitErrorsIn2Coord::slope
float slope(const std::vector< float > &x, const std::vector< float > &y, int ndat, const std::vector< float > &sigx, const std::vector< float > &sigy) const
Definition: LinearFitErrorsIn2Coord.cc:5
DDAxes::x
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
LinearFit::fit
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: LinearFit.cc:3
LinearFitErrorsIn2Coord::variance
float variance(const std::vector< float > &x, int ndat) const
Definition: LinearFitErrorsIn2Coord.cc:48
LinearFit
Definition: LinearFit.h:9