CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes
Covariance Class Reference

#include <Histograms.h>

Public Member Functions

 Covariance ()
 
double covariance ()
 
void fill (const double &x, const double &y)
 
double getN ()
 

Protected Attributes

int N_
 
double productXY_
 
double sumX_
 
double sumY_
 

Detailed Description

This class can be used to compute the covariance between two input variables. The Fill method needs the two input variables. In the end the covariance method computes the covariance as: cov(x,y) = Sum_i(x_i*y_i)/N - x_mean*y_mean. Of course passing the same variable for x and y gives the variance of that variable.

Definition at line 1875 of file Histograms.h.

Constructor & Destructor Documentation

◆ Covariance()

Covariance::Covariance ( )
inline

Definition at line 1877 of file Histograms.h.

1877 : productXY_(0), sumX_(0), sumY_(0), N_(0) {}

Member Function Documentation

◆ covariance()

double Covariance::covariance ( void  )
inline

Definition at line 1884 of file Histograms.h.

1884  {
1885  if (N_ != 0) {
1886  double meanX = sumX_ / N_;
1887  double meanY = sumY_ / N_;
1888  // std::cout << "meanX*meanY = "<<meanX<<"*"<<meanY<< " = " << meanX*meanY << std::endl;
1889  return (productXY_ / N_ - meanX * meanY);
1890  }
1891  return 0.;
1892  }

References N_, productXY_, sumX_, and sumY_.

Referenced by HCovarianceVSxy::Write().

◆ fill()

void Covariance::fill ( const double &  x,
const double &  y 
)
inline

Definition at line 1878 of file Histograms.h.

1878  {
1879  productXY_ += x * y;
1880  sumX_ += x;
1881  sumY_ += y;
1882  ++N_;
1883  }

References N_, productXY_, sumX_, sumY_, x, and y.

Referenced by HCovarianceVSxy::Fill().

◆ getN()

double Covariance::getN ( )
inline

Definition at line 1893 of file Histograms.h.

1893 { return N_; }

References N_.

Member Data Documentation

◆ N_

int Covariance::N_
protected

Definition at line 1899 of file Histograms.h.

Referenced by covariance(), fill(), and getN().

◆ productXY_

double Covariance::productXY_
protected

Definition at line 1896 of file Histograms.h.

Referenced by covariance(), and fill().

◆ sumX_

double Covariance::sumX_
protected

Definition at line 1897 of file Histograms.h.

Referenced by covariance(), and fill().

◆ sumY_

double Covariance::sumY_
protected

Definition at line 1898 of file Histograms.h.

Referenced by covariance(), and fill().

Covariance::N_
int N_
Definition: Histograms.h:1899
DDAxes::y
Covariance::productXY_
double productXY_
Definition: Histograms.h:1896
DDAxes::x
Covariance::sumX_
double sumX_
Definition: Histograms.h:1897
Covariance::sumY_
double sumY_
Definition: Histograms.h:1898