CMS 3D CMS Logo

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

#include <Histograms.h>

Inherits Histograms.

Public Member Functions

void Clear () override
 
void Fill (const double &x, const double &y, const double &a, const double &b) override
 
double Get (const double &x, const double &y) const
 
 HCovarianceVSxy (const TString &name, const TString &title, const int totBinsX, const double &xMin, const double &xMax, const int totBinsY, const double &yMin, const double &yMax, TDirectory *dir=nullptr, bool varianceCheck=false)
 
 HCovarianceVSxy (TFile *inputFile, const TString &name, const TString &dirName)
 Contructor to read histograms from file. More...
 
void Write () override
 
 ~HCovarianceVSxy () override
 

Protected Member Functions

int getXindex (const double &x) const
 
int getYindex (const double &y) const
 

Protected Attributes

Covariance ** covariances_
 
double deltaX_
 
double deltaY_
 
TH2D * histoCovariance_
 
TH1D *** histoVarianceCheck_
 
bool readMode_
 
int totBinsX_
 
int totBinsY_
 
int totBinsZ_
 
bool varianceCheck_
 
double xMin_
 
double yMin_
 

Additional Inherited Members

- Public Attributes inherited from Histograms
dqm::reco::MonitorElementlumiVsLS
 
dqm::reco::MonitorElementnumberOfPixelClustersVsLS
 
dqm::reco::MonitorElementnumberOfPixelClustersVsLumi
 
dqm::reco::MonitorElementpixelLumiVsLS
 
dqm::reco::MonitorElementpixelLumiVsLumi
 
dqm::reco::MonitorElementpuVsLS
 

Detailed Description

This class can be used to compute the covariance of two variables with respect to other two variables (to see e.g. how does the covariance of ptVSphi vary with respect to (pt,eta).

Definition at line 1908 of file Histograms.h.

Constructor & Destructor Documentation

HCovarianceVSxy::HCovarianceVSxy ( const TString &  name,
const TString &  title,
const int  totBinsX,
const double &  xMin,
const double &  xMax,
const int  totBinsY,
const double &  yMin,
const double &  yMax,
TDirectory *  dir = nullptr,
bool  varianceCheck = false 
)
inline

Definition at line 1910 of file Histograms.h.

References covariances_, DeadROC_duringRun::dir, histoCovariance_, histoVarianceCheck_, mps_fire::i, dqmiolumiharvest::j, mergeVDriftHistosByStation::name, totBinsX_, totBinsY_, and varianceCheck_.

1920  : totBinsX_(totBinsX),
1921  totBinsY_(totBinsY),
1922  xMin_(xMin),
1923  deltaX_(xMax - xMin),
1924  yMin_(yMin),
1925  deltaY_(yMax - yMin),
1926  readMode_(false),
1927  varianceCheck_(varianceCheck) {
1928  name_ = name;
1929  histoDir_ = dir;
1930  histoCovariance_ = new TH2D(name + "Covariance", title + " covariance", totBinsX, xMin, xMax, totBinsY, yMin, yMax);
1931 
1932  covariances_ = new Covariance*[totBinsX];
1933  for (int i = 0; i < totBinsX; ++i) {
1934  covariances_[i] = new Covariance[totBinsY];
1935  }
1936  if (varianceCheck_) {
1937  histoVarianceCheck_ = new TH1D**[totBinsX_];
1938  for (int i = 0; i < totBinsX_; ++i) {
1939  histoVarianceCheck_[i] = new TH1D*[totBinsY_];
1940  for (int j = 0; j < totBinsY_; ++j) {
1941  std::stringstream namei;
1942  std::stringstream namej;
1943  namei << i;
1944  namej << j;
1945  histoVarianceCheck_[i][j] = new TH1D(name + "_" + namei.str() + "_" + namej.str(), name, 10000, -1, 1);
1946  }
1947  }
1948  }
1949  }
TH2D * histoCovariance_
Definition: Histograms.h:2075
Covariance ** covariances_
Definition: Histograms.h:2076
TH1D *** histoVarianceCheck_
Definition: Histograms.h:2081
HCovarianceVSxy::HCovarianceVSxy ( TFile *  inputFile,
const TString &  name,
const TString &  dirName 
)
inline

Contructor to read histograms from file.

Definition at line 1951 of file Histograms.h.

References gather_cfg::cout, deltaX_, deltaY_, beamvalidation::exit(), histoCovariance_, totBinsX_, totBinsY_, xMin_, and yMin_.

1951  : readMode_(true) {
1952  histoDir_ = (TDirectory*)(inputFile->Get(dirName.Data()));
1953  if (histoDir_ == nullptr) {
1954  std::cout << "Error: directory not found" << std::endl;
1955  exit(0);
1956  }
1957  histoCovariance_ = (TH2D*)(histoDir_->Get(name));
1958  totBinsX_ = histoCovariance_->GetNbinsX();
1959  xMin_ = histoCovariance_->GetXaxis()->GetBinLowEdge(1);
1960  deltaX_ = histoCovariance_->GetXaxis()->GetBinUpEdge(totBinsX_) - xMin_;
1961  totBinsY_ = histoCovariance_->GetNbinsY();
1962  yMin_ = histoCovariance_->GetYaxis()->GetBinLowEdge(1);
1963  deltaY_ = histoCovariance_->GetYaxis()->GetBinUpEdge(totBinsY_) - yMin_;
1964  }
TH2D * histoCovariance_
Definition: Histograms.h:2075
tuple cout
Definition: gather_cfg.py:144
HCovarianceVSxy::~HCovarianceVSxy ( )
inlineoverride

Definition at line 1966 of file Histograms.h.

References covariances_, histoCovariance_, histoVarianceCheck_, mps_fire::i, dqmiolumiharvest::j, totBinsX_, totBinsY_, and varianceCheck_.

1966  {
1967  delete histoCovariance_;
1968  // Free covariances
1969  for (int i = 0; i < totBinsX_; ++i) {
1970  delete[] covariances_[i];
1971  }
1972  delete[] covariances_;
1973  // Free variance check histograms
1974  if (varianceCheck_) {
1975  for (int i = 0; i < totBinsX_; ++i) {
1976  for (int j = 0; j < totBinsY_; ++j) {
1977  delete histoVarianceCheck_[i][j];
1978  }
1979  delete[] histoVarianceCheck_[i];
1980  }
1981  delete[] histoVarianceCheck_;
1982  }
1983  }
TH2D * histoCovariance_
Definition: Histograms.h:2075
Covariance ** covariances_
Definition: Histograms.h:2076
TH1D *** histoVarianceCheck_
Definition: Histograms.h:2081

Member Function Documentation

void HCovarianceVSxy::Clear ( )
inlineoverride

Definition at line 2061 of file Histograms.h.

References histoCovariance_, histoVarianceCheck_, mps_fire::i, dqmiolumiharvest::j, totBinsX_, totBinsY_, and varianceCheck_.

2061  {
2062  histoCovariance_->Clear();
2063  if (varianceCheck_) {
2064  for (int i = 0; i < totBinsX_; ++i) {
2065  for (int j = 0; j < totBinsY_; ++j) {
2066  histoVarianceCheck_[i][j]->Clear();
2067  }
2068  }
2069  }
2070  }
TH2D * histoCovariance_
Definition: Histograms.h:2075
TH1D *** histoVarianceCheck_
Definition: Histograms.h:2081
void HCovarianceVSxy::Fill ( const double &  x,
const double &  y,
const double &  a,
const double &  b 
)
inlineoverride

x and y should be the variables VS which we are computing the covariance (pt and eta) a and b should be the variables OF which we are computing the covariance

Definition at line 1989 of file Histograms.h.

References covariances_, Covariance::fill(), getXindex(), getYindex(), histoVarianceCheck_, totBinsX_, totBinsY_, and varianceCheck_.

Referenced by ResolutionAnalyzer::analyze().

1989  {
1990  // Need to convert the (x,y) values to the array indeces
1991  int xIndex = getXindex(x);
1992  int yIndex = getYindex(y);
1993  // Only fill values if they are in the selected range
1994  if (0 <= xIndex && xIndex < totBinsX_ && 0 <= yIndex && yIndex < totBinsY_) {
1995  // if( TString(histoCovariance_->GetName()).Contains("CovarianceCotgTheta_Covariance") )
1996  covariances_[xIndex][yIndex].fill(a, b);
1997  // Should be used with the variance, in which case a==b
1998  if (varianceCheck_)
1999  histoVarianceCheck_[xIndex][yIndex]->Fill(a);
2000  }
2001  }
int getXindex(const double &x) const
Definition: Histograms.h:2073
void fill(const double &x, const double &y)
Definition: Histograms.h:1880
Covariance ** covariances_
Definition: Histograms.h:2076
double b
Definition: hdecay.h:118
int getYindex(const double &y) const
Definition: Histograms.h:2074
TH1D *** histoVarianceCheck_
Definition: Histograms.h:2081
double a
Definition: hdecay.h:119
double HCovarianceVSxy::Get ( const double &  x,
const double &  y 
) const
inline

Definition at line 2004 of file Histograms.h.

References getXindex(), getYindex(), histoCovariance_, totBinsX_, and totBinsY_.

2004  {
2005  // Need to convert the (x,y) values to the array indeces
2006  int xIndex = getXindex(x);
2007  int yIndex = getYindex(y);
2008  // If the values exceed the limits of the histogram, return the border values
2009  if (xIndex < 0)
2010  xIndex = 0;
2011  if (xIndex >= totBinsX_)
2012  xIndex = totBinsX_ - 1;
2013  if (yIndex < 0)
2014  yIndex = 0;
2015  if (yIndex >= totBinsY_)
2016  yIndex = totBinsY_ - 1;
2017  return histoCovariance_->GetBinContent(xIndex + 1, yIndex + 1);
2018  }
int getXindex(const double &x) const
Definition: Histograms.h:2073
TH2D * histoCovariance_
Definition: Histograms.h:2075
int getYindex(const double &y) const
Definition: Histograms.h:2074
int HCovarianceVSxy::getXindex ( const double &  x) const
inlineprotected

Definition at line 2073 of file Histograms.h.

References deltaX_, totBinsX_, and xMin_.

Referenced by Fill(), and Get().

2073 { return int((x - xMin_) / deltaX_ * totBinsX_); }
int HCovarianceVSxy::getYindex ( const double &  y) const
inlineprotected

Definition at line 2074 of file Histograms.h.

References deltaY_, totBinsY_, and yMin_.

Referenced by Fill(), and Get().

2074 { return int((y - yMin_) / deltaY_ * totBinsY_); }
void HCovarianceVSxy::Write ( )
inlineoverride

Definition at line 2020 of file Histograms.h.

References svgfig::canvas(), gather_cfg::cout, Covariance::covariance(), covariances_, histoCovariance_, histoVarianceCheck_, readMode_, totBinsX_, totBinsY_, varianceCheck_, and cuy::yBin.

Referenced by ResolutionAnalyzer::writeHistoMap().

2020  {
2021  if (!readMode_) {
2022  std::cout << "writing: " << histoCovariance_->GetName() << std::endl;
2023  for (int xBin = 0; xBin < totBinsX_; ++xBin) {
2024  for (int yBin = 0; yBin < totBinsY_; ++yBin) {
2025  double covariance = covariances_[xBin][yBin].covariance();
2026  // Histogram bins start from 1
2027  // std::cout << "covariance["<<xBin<<"]["<<yBin<<"] with N = "<<covariances_[xBin][yBin].getN()<<" is: " << covariance << std::endl;
2028  histoCovariance_->SetBinContent(xBin + 1, yBin + 1, covariance);
2029  }
2030  }
2031  if (histoDir_ != nullptr)
2032  histoDir_->cd();
2033  TCanvas canvas(TString(histoCovariance_->GetName()) + "_canvas",
2034  TString(histoCovariance_->GetTitle()) + " canvas",
2035  1000,
2036  800);
2037  canvas.Divide(2);
2038  canvas.cd(1);
2039  histoCovariance_->Draw("lego");
2040  canvas.cd(2);
2041  histoCovariance_->Draw("surf5");
2042  canvas.Write();
2043  histoCovariance_->Write();
2044 
2045  TDirectory* binsDir = nullptr;
2046  if (varianceCheck_) {
2047  if (histoDir_ != nullptr) {
2048  histoDir_->cd();
2049  if (binsDir == nullptr)
2050  binsDir = histoDir_->mkdir(name_ + "Bins");
2051  binsDir->cd();
2052  }
2053  for (int xBin = 0; xBin < totBinsX_; ++xBin) {
2054  for (int yBin = 0; yBin < totBinsY_; ++yBin) {
2055  histoVarianceCheck_[xBin][yBin]->Write();
2056  }
2057  }
2058  }
2059  }
2060  }
tuple yBin
Definition: cuy.py:892
double covariance()
Definition: Histograms.h:1886
TH2D * histoCovariance_
Definition: Histograms.h:2075
def canvas
Definition: svgfig.py:482
Covariance ** covariances_
Definition: Histograms.h:2076
TH1D *** histoVarianceCheck_
Definition: Histograms.h:2081
tuple cout
Definition: gather_cfg.py:144

Member Data Documentation

Covariance** HCovarianceVSxy::covariances_
protected

Definition at line 2076 of file Histograms.h.

Referenced by Fill(), HCovarianceVSxy(), Write(), and ~HCovarianceVSxy().

double HCovarianceVSxy::deltaX_
protected

Definition at line 2078 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

double HCovarianceVSxy::deltaY_
protected

Definition at line 2078 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().

TH2D* HCovarianceVSxy::histoCovariance_
protected

Definition at line 2075 of file Histograms.h.

Referenced by Clear(), Get(), HCovarianceVSxy(), Write(), and ~HCovarianceVSxy().

TH1D*** HCovarianceVSxy::histoVarianceCheck_
protected

Definition at line 2081 of file Histograms.h.

Referenced by Clear(), Fill(), HCovarianceVSxy(), Write(), and ~HCovarianceVSxy().

bool HCovarianceVSxy::readMode_
protected

Definition at line 2079 of file Histograms.h.

Referenced by Write().

int HCovarianceVSxy::totBinsX_
protected

Definition at line 2077 of file Histograms.h.

Referenced by Clear(), Fill(), Get(), getXindex(), HCovarianceVSxy(), Write(), and ~HCovarianceVSxy().

int HCovarianceVSxy::totBinsY_
protected

Definition at line 2077 of file Histograms.h.

Referenced by Clear(), Fill(), Get(), getYindex(), HCovarianceVSxy(), Write(), and ~HCovarianceVSxy().

int HCovarianceVSxy::totBinsZ_
protected

Definition at line 2077 of file Histograms.h.

bool HCovarianceVSxy::varianceCheck_
protected

Definition at line 2080 of file Histograms.h.

Referenced by Clear(), Fill(), HCovarianceVSxy(), Write(), and ~HCovarianceVSxy().

double HCovarianceVSxy::xMin_
protected

Definition at line 2078 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

double HCovarianceVSxy::yMin_
protected

Definition at line 2078 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().