#include <LeastSquares.h>
Public Member Functions | |
void | add (const std::vector< double > &values, double dest, double weight=1.0) |
void | add (const LeastSquares &other, double weight=1.0) |
void | calculate () |
const TMatrixDSym & | getCoefficients () const |
double | getConstant () const |
const TMatrixDSym & | getCorrelations () const |
const TMatrixDSym & | getCovariance () const |
std::vector< double > | getMeans () const |
const TMatrixD & | getRotation () |
unsigned int | getSize () const |
std::vector< double > | getWeights () const |
LeastSquares (unsigned int n) | |
void | load (XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem) |
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * | save (XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc) const |
virtual | ~LeastSquares () |
Static Public Member Functions | |
static TVectorD | solveFisher (const TMatrixDSym &coeffs) |
static TMatrixD | solveRotation (const TMatrixDSym &covar, TVectorD &trace) |
Private Attributes | |
TMatrixDSym | coeffs |
TMatrixDSym | corr |
TMatrixDSym | covar |
const unsigned int | n |
TMatrixD | rotation |
TVectorD | trace |
TVectorD | variance |
TVectorD | weights |
Definition at line 14 of file LeastSquares.h.
PhysicsTools::LeastSquares::LeastSquares | ( | unsigned int | n | ) |
PhysicsTools::LeastSquares::~LeastSquares | ( | ) | [virtual] |
Definition at line 28 of file LeastSquares.cc.
{ }
void PhysicsTools::LeastSquares::add | ( | const std::vector< double > & | values, |
double | dest, | ||
double | weight = 1.0 |
||
) |
Definition at line 32 of file LeastSquares.cc.
References coeffs, i, j, n, and CommonMethods::weight().
{ if (values.size() != n) throw cms::Exception("LeastSquares") << "add(): invalid array size!" << std::endl; for(unsigned int i = 0; i < n; i++) { for(unsigned int j = 0; j < n; j++) coeffs(i, j) += values[i] * values[j] * weight; coeffs(n, i) += values[i] * dest * weight; coeffs(i, n) += values[i] * dest * weight; coeffs(n + 1, i) += values[i] * weight; coeffs(i, n + 1) += values[i] * weight; } coeffs(n, n) += dest * dest * weight; coeffs(n + 1, n) += dest * weight; coeffs(n, n + 1) += dest * weight; coeffs(n + 1, n + 1) += weight; }
void PhysicsTools::LeastSquares::add | ( | const LeastSquares & | other, |
double | weight = 1.0 |
||
) |
Definition at line 55 of file LeastSquares.cc.
References coeffs, getSize(), and n.
{ if (other.getSize() != n) throw cms::Exception("LeastSquares") << "add(): invalid array size!" << std::endl; coeffs += weight * other.coeffs; }
void PhysicsTools::LeastSquares::calculate | ( | ) |
Definition at line 87 of file LeastSquares.cc.
References trackerHits::c, coeffs, corr, covar, i, j, N, n, rotation, solveFisher(), solveRotation(), mathSSE::sqrt(), trace, v, variance, w(), and weights.
{ double N = coeffs(n + 1, n + 1); for(unsigned int i = 0; i <= n; i++) { double M = coeffs(n + 1, i); for(unsigned int j = 0; j <= n; j++) covar(i, j) = coeffs(i, j) * N - M * coeffs(n + 1, j); } for(unsigned int i = 0; i <= n; i++) { double c = covar(i, i); variance[i] = c > 0.0 ? std::sqrt(c) : 0.0; } for(unsigned int i = 0; i <= n; i++) { double M = variance[i]; for(unsigned int j = 0; j <= n; j++) { double v = M * variance[j]; double w = covar(i, j); corr(i, j) = (v >= 1.0e-9) ? (w / v) : (i == j); } } weights = solveFisher(coeffs); rotation = solveRotation(covar, trace); }
const TMatrixDSym& PhysicsTools::LeastSquares::getCoefficients | ( | ) | const [inline] |
double PhysicsTools::LeastSquares::getConstant | ( | ) | const |
const TMatrixDSym& PhysicsTools::LeastSquares::getCorrelations | ( | ) | const [inline] |
const TMatrixDSym& PhysicsTools::LeastSquares::getCovariance | ( | ) | const [inline] |
std::vector< double > PhysicsTools::LeastSquares::getMeans | ( | ) | const |
const TMatrixD& PhysicsTools::LeastSquares::getRotation | ( | ) | [inline] |
unsigned int PhysicsTools::LeastSquares::getSize | ( | ) | const [inline] |
std::vector< double > PhysicsTools::LeastSquares::getWeights | ( | ) | const |
void PhysicsTools::LeastSquares::load | ( | XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * | elem | ) |
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* PhysicsTools::LeastSquares::save | ( | XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * | doc | ) | const |
TVectorD PhysicsTools::LeastSquares::solveFisher | ( | const TMatrixDSym & | coeffs | ) | [static] |
Definition at line 64 of file LeastSquares.cc.
References coeffs, n, convertSQLiteXML::ok, and tmp.
Referenced by calculate().
TMatrixD PhysicsTools::LeastSquares::solveRotation | ( | const TMatrixDSym & | covar, |
TVectorD & | trace | ||
) | [static] |
TMatrixDSym PhysicsTools::LeastSquares::coeffs [private] |
Definition at line 44 of file LeastSquares.h.
Referenced by add(), calculate(), getCoefficients(), getMeans(), TestHistoMgr::save(), and solveFisher().
TMatrixDSym PhysicsTools::LeastSquares::corr [private] |
Definition at line 46 of file LeastSquares.h.
Referenced by calculate(), getCorrelations(), and TestHistoMgr::save().
TMatrixDSym PhysicsTools::LeastSquares::covar [private] |
Definition at line 45 of file LeastSquares.h.
Referenced by calculate(), getCovariance(), and TestHistoMgr::save().
const unsigned int PhysicsTools::LeastSquares::n [private] |
Definition at line 51 of file LeastSquares.h.
Referenced by add(), calculate(), getConstant(), getMeans(), getSize(), getWeights(), TestHistoMgr::save(), and solveFisher().
TMatrixD PhysicsTools::LeastSquares::rotation [private] |
Definition at line 47 of file LeastSquares.h.
Referenced by calculate(), getRotation(), and TestHistoMgr::save().
TVectorD PhysicsTools::LeastSquares::trace [private] |
Definition at line 50 of file LeastSquares.h.
Referenced by calculate(), and TestHistoMgr::save().
TVectorD PhysicsTools::LeastSquares::variance [private] |
Definition at line 49 of file LeastSquares.h.
Referenced by calculate(), and TestHistoMgr::save().
TVectorD PhysicsTools::LeastSquares::weights [private] |
Definition at line 48 of file LeastSquares.h.
Referenced by calculate(), getConstant(), getWeights(), and TestHistoMgr::save().