test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

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 33 of file LinearFitErrorsIn2Coord.cc.

References i, and slope().

36 {
37 
38  float fs = slope(x, y, ndat, sigx, sigy);
39  float fi = 0;
40  float sumWi = 0;
41  for (int i = 0; i != ndat; i++) {
42  float wi = 1./(sigy[i] + fs*fs*sigx[i]);
43  fi += wi*(y[i] - fs*x[i]);
44  sumWi += wi;
45  }
46 
47  return fi / sumWi;
48 
49 }
int i
Definition: DBlmapReader.cc:9
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
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.

References LinearFit::fit(), i, pileupReCalc_HLTpaths::scale, mathSSE::sqrt(), variance(), and y.

Referenced by Vispa.Views.LineDecayView.DecayLine::containsPoint(), intercept(), and Vispa.Views.LineDecayView.DecayLine::transform().

8 {
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 
30 }
int i
Definition: DBlmapReader.cc:9
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
T sqrt(T t)
Definition: SSEVec.h:48
float variance(const std::vector< float > &x, int ndat) const
float LinearFitErrorsIn2Coord::variance ( const std::vector< float > &  x,
int  ndat 
) const
private

Definition at line 53 of file LinearFitErrorsIn2Coord.cc.

References i.

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

54 {
55  double m1 = 0., m2 = 0.;
56  for (int i = 0; i != ndat; i++) {
57  m1 += x[i];
58  m2 += x[i]*x[i];
59  }
60  m1 /= ndat;
61  m2 /= ndat;
62 
63  return float(m2 - m1*m1);
64 
65 }
int i
Definition: DBlmapReader.cc:9