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

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() [1/2]

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 1908 of file Histograms.h.

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  }

References covariances_, DeadROC_duringRun::dir, histoCovariance_, histoVarianceCheck_, mps_fire::i, dqmiolumiharvest::j, Skims_PA_cff::name, runGCPTkAlMap::title, totBinsX_, totBinsY_, varianceCheck_, multiplicitycorr_cfi::xMax, photonAnalyzer_cfi::xMin, multiplicitycorr_cfi::yMax, and photonAnalyzer_cfi::yMin.

◆ HCovarianceVSxy() [2/2]

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.

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  }

References gather_cfg::cout, deltaX_, deltaY_, TrackerOfflineValidation_Dqm_cff::dirName, beamvalidation::exit(), histoCovariance_, dtResolutionTest_cfi::inputFile, Skims_PA_cff::name, totBinsX_, totBinsY_, xMin_, and yMin_.

◆ ~HCovarianceVSxy()

HCovarianceVSxy::~HCovarianceVSxy ( )
inlineoverride

Definition at line 1964 of file Histograms.h.

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  }

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

Member Function Documentation

◆ Clear()

void HCovarianceVSxy::Clear ( )
inlineoverride

Definition at line 2059 of file Histograms.h.

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  }

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

◆ Fill()

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.

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  }

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

Referenced by ResolutionAnalyzer::analyze().

◆ Get()

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  }

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

◆ getXindex()

int HCovarianceVSxy::getXindex ( const double &  x) const
inlineprotected

Definition at line 2071 of file Histograms.h.

2071 { return int((x - xMin_) / deltaX_ * totBinsX_); }

References deltaX_, createfilelist::int, totBinsX_, x, and xMin_.

Referenced by Fill(), and Get().

◆ getYindex()

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

Definition at line 2072 of file Histograms.h.

2072 { return int((y - yMin_) / deltaY_ * totBinsY_); }

References deltaY_, createfilelist::int, totBinsY_, y, and yMin_.

Referenced by Fill(), and Get().

◆ Write()

void HCovarianceVSxy::Write ( )
inlineoverride

Definition at line 2018 of file Histograms.h.

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  }

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

Referenced by ResolutionAnalyzer::writeHistoMap().

Member Data Documentation

◆ covariances_

Covariance** HCovarianceVSxy::covariances_
protected

Definition at line 2074 of file Histograms.h.

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

◆ deltaX_

double HCovarianceVSxy::deltaX_
protected

Definition at line 2076 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

◆ deltaY_

double HCovarianceVSxy::deltaY_
protected

Definition at line 2076 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().

◆ histoCovariance_

TH2D* HCovarianceVSxy::histoCovariance_
protected

Definition at line 2073 of file Histograms.h.

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

◆ histoVarianceCheck_

TH1D*** HCovarianceVSxy::histoVarianceCheck_
protected

Definition at line 2079 of file Histograms.h.

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

◆ readMode_

bool HCovarianceVSxy::readMode_
protected

Definition at line 2077 of file Histograms.h.

Referenced by Write().

◆ totBinsX_

int HCovarianceVSxy::totBinsX_
protected

Definition at line 2075 of file Histograms.h.

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

◆ totBinsY_

int HCovarianceVSxy::totBinsY_
protected

Definition at line 2075 of file Histograms.h.

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

◆ totBinsZ_

int HCovarianceVSxy::totBinsZ_
protected

Definition at line 2075 of file Histograms.h.

◆ varianceCheck_

bool HCovarianceVSxy::varianceCheck_
protected

Definition at line 2078 of file Histograms.h.

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

◆ xMin_

double HCovarianceVSxy::xMin_
protected

Definition at line 2076 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

◆ yMin_

double HCovarianceVSxy::yMin_
protected

Definition at line 2076 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().

svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
DDAxes::y
HCovarianceVSxy::totBinsY_
int totBinsY_
Definition: Histograms.h:2075
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
Covariance::fill
void fill(const double &x, const double &y)
Definition: Histograms.h:1878
photonAnalyzer_cfi.xBin
xBin
Definition: photonAnalyzer_cfi.py:81
HCovarianceVSxy::xMin_
double xMin_
Definition: Histograms.h:2076
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HCovarianceVSxy::getXindex
int getXindex(const double &x) const
Definition: Histograms.h:2071
HCovarianceVSxy::histoCovariance_
TH2D * histoCovariance_
Definition: Histograms.h:2073
photonAnalyzer_cfi.yBin
yBin
Definition: photonAnalyzer_cfi.py:85
HCovarianceVSxy::varianceCheck_
bool varianceCheck_
Definition: Histograms.h:2078
photonAnalyzer_cfi.yMin
yMin
Definition: photonAnalyzer_cfi.py:86
DDAxes::x
HCovarianceVSxy::readMode_
bool readMode_
Definition: Histograms.h:2077
photonAnalyzer_cfi.xMin
xMin
Definition: photonAnalyzer_cfi.py:82
HCovarianceVSxy::yMin_
double yMin_
Definition: Histograms.h:2076
multiplicitycorr_cfi.yMax
yMax
Definition: multiplicitycorr_cfi.py:6
b
double b
Definition: hdecay.h:118
Covariance::covariance
double covariance()
Definition: Histograms.h:1884
a
double a
Definition: hdecay.h:119
HCovarianceVSxy::deltaX_
double deltaX_
Definition: Histograms.h:2076
HCovarianceVSxy::covariances_
Covariance ** covariances_
Definition: Histograms.h:2074
createfilelist.int
int
Definition: createfilelist.py:10
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
HCovarianceVSxy::totBinsX_
int totBinsX_
Definition: Histograms.h:2075
TrackerOfflineValidation_Dqm_cff.dirName
dirName
Definition: TrackerOfflineValidation_Dqm_cff.py:55
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
multiplicitycorr_cfi.xMax
xMax
Definition: multiplicitycorr_cfi.py:5
Covariance
Definition: Histograms.h:1875
HCovarianceVSxy::histoVarianceCheck_
TH1D *** histoVarianceCheck_
Definition: Histograms.h:2079
HCovarianceVSxy::getYindex
int getYindex(const double &y) const
Definition: Histograms.h:2072
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
HCovarianceVSxy::deltaY_
double deltaY_
Definition: Histograms.h:2076