CMS 3D CMS Logo

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=0, 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_
 

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 1906 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 = 0,
bool  varianceCheck = false 
)
inline

Definition at line 1908 of file Histograms.h.

References DeadROC_duringRun::dir, mps_fire::i, dqmiolumiharvest::j, and Skims_PA_cff::name.

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

Contructor to read histograms from file.

Definition at line 1949 of file Histograms.h.

References gather_cfg::cout, and beamvalidation::exit().

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

Definition at line 1964 of file Histograms.h.

References mps_fire::i, and dqmiolumiharvest::j.

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

Member Function Documentation

void HCovarianceVSxy::Clear ( )
inlineoverride

Definition at line 2059 of file Histograms.h.

References mps_fire::i, and dqmiolumiharvest::j.

2059  {
2060  histoCovariance_->Clear();
2061  if (varianceCheck_) {
2062  for (int i = 0; i < totBinsX_; ++i) {
2063  for (int j = 0; j < totBinsY_; ++j) {
2064  histoVarianceCheck_[i][j]->Clear();
2065  }
2066  }
2067  }
2068  }
TH2D * histoCovariance_
Definition: Histograms.h:2073
TH1D *** histoVarianceCheck_
Definition: Histograms.h:2079
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 1987 of file Histograms.h.

Referenced by ResolutionAnalyzer::analyze().

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

Definition at line 2002 of file Histograms.h.

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

Definition at line 2071 of file Histograms.h.

References createfilelist::int.

int HCovarianceVSxy::getYindex ( const double &  y) const
inlineprotected

Definition at line 2072 of file Histograms.h.

References createfilelist::int.

void HCovarianceVSxy::Write ( )
inlineoverride

Definition at line 2018 of file Histograms.h.

References svgfig::canvas(), gather_cfg::cout, photonAnalyzer_cfi::xBin, and photonAnalyzer_cfi::yBin.

Referenced by ResolutionAnalyzer::writeHistoMap().

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

Member Data Documentation

Covariance** HCovarianceVSxy::covariances_
protected

Definition at line 2074 of file Histograms.h.

double HCovarianceVSxy::deltaX_
protected

Definition at line 2076 of file Histograms.h.

double HCovarianceVSxy::deltaY_
protected

Definition at line 2076 of file Histograms.h.

TH2D* HCovarianceVSxy::histoCovariance_
protected

Definition at line 2073 of file Histograms.h.

TH1D*** HCovarianceVSxy::histoVarianceCheck_
protected

Definition at line 2079 of file Histograms.h.

bool HCovarianceVSxy::readMode_
protected

Definition at line 2077 of file Histograms.h.

int HCovarianceVSxy::totBinsX_
protected

Definition at line 2075 of file Histograms.h.

int HCovarianceVSxy::totBinsY_
protected

Definition at line 2075 of file Histograms.h.

int HCovarianceVSxy::totBinsZ_
protected

Definition at line 2075 of file Histograms.h.

bool HCovarianceVSxy::varianceCheck_
protected

Definition at line 2078 of file Histograms.h.

double HCovarianceVSxy::xMin_
protected

Definition at line 2076 of file Histograms.h.

double HCovarianceVSxy::yMin_
protected

Definition at line 2076 of file Histograms.h.