CMS 3D CMS Logo

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

#include <Histograms.h>

Inheritance diagram for HCovarianceVSxy:
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
 
- Public Member Functions inherited from Histograms
virtual void Fill (const reco::Particle::LorentzVector &p1, const reco::Particle::LorentzVector &p2)
 
virtual void Fill (const reco::Particle::LorentzVector &p1, const reco::Particle::LorentzVector &p2, const int charge, const double &weight=1.)
 
virtual void Fill (const CLHEP::HepLorentzVector &momentum1, const CLHEP::HepLorentzVector &momentum2)
 
virtual void Fill (const CLHEP::HepLorentzVector &momentum1, const CLHEP::HepLorentzVector &momentum2, const int charge, const double &weight=1.)
 
virtual void Fill (const CLHEP::HepLorentzVector &p1, const reco::Particle::LorentzVector &p2)
 
virtual void Fill (const reco::Particle::LorentzVector &p4, const double &weight=1.)
 
virtual void Fill (const reco::Particle::LorentzVector &p4, const int charge, const double &weight=1.)
 
virtual void Fill (const CLHEP::HepLorentzVector &momentum, const int charge, const double &weight=1.)
 
virtual void Fill (const reco::Particle::LorentzVector &p4, const double &resValue, const int charge)
 
virtual void Fill (const reco::Particle::LorentzVector &p4, const double &genValue, const double recValue, const int charge)
 
virtual void Fill (const CLHEP::HepLorentzVector &p, const double &likeValue)
 
virtual void Fill (const unsigned int number)
 
virtual void Fill (const reco::Particle::LorentzVector &recoP1, const int charge1, const reco::Particle::LorentzVector &genP1, const reco::Particle::LorentzVector &recoP2, const int charge2, const reco::Particle::LorentzVector &genP2, const double &recoMass, const double &genMass)
 
virtual void Fill (const reco::Particle::LorentzVector &recoP1, const int charge1, const reco::Particle::LorentzVector &recoP2, const int charge2, const double &recoMass, const double &genMass)
 
virtual void Fill (const reco::Particle::LorentzVector &recoP1, const reco::Particle::LorentzVector &genP1, const reco::Particle::LorentzVector &recoP2, const reco::Particle::LorentzVector &genP2)
 
virtual void Fill (const double &x, const double &y)
 
virtual void Fill (const reco::Particle::LorentzVector &p41, const reco::Particle::LorentzVector &p42, const reco::Particle::LorentzVector &p4Res, const double &weight=1.)
 
virtual void Fill (const CLHEP::HepLorentzVector &momentum1, const CLHEP::HepLorentzVector &momentum2, const CLHEP::HepLorentzVector &momentumRes, const double &weight=1.)
 
virtual double Get (const reco::Particle::LorentzVector &recoP1, const TString &covarianceName)
 
virtual TString GetName ()
 
 Histograms ()
 
 Histograms (const TString &name)
 
 Histograms (TFile *outputFile, const TString &name)
 
virtual void SetWeight (double weight)
 
virtual ~Histograms ()
 

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_
 
- Protected Attributes inherited from Histograms
TDirectory * histoDir_
 
TString name_
 
TFile * outputFile_
 
double theWeight_
 

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

References dir, Histograms::histoDir_, mps_fire::i, dataset::name, and Histograms::name_.

1824  :
1825  totBinsX_(totBinsX), totBinsY_(totBinsY),
1827  readMode_(false),
1828  varianceCheck_(varianceCheck)
1829  {
1830  name_ = name;
1831  histoDir_ = dir;
1832  histoCovariance_ = new TH2D(name+"Covariance", title+" covariance", totBinsX, xMin, xMax, totBinsY, yMin, yMax);
1833 
1834  covariances_ = new Covariance*[totBinsX];
1835  for( int i=0; i<totBinsX; ++i ) {
1836  covariances_[i] = new Covariance[totBinsY];
1837  }
1838  if( varianceCheck_ ) {
1839  histoVarianceCheck_ = new TH1D**[totBinsX_];
1840  for( int i=0; i<totBinsX_; ++i ) {
1841  histoVarianceCheck_[i] = new TH1D*[totBinsY_];
1842  for( int j=0; j<totBinsY_; ++j ) {
1843  std::stringstream namei;
1844  std::stringstream namej;
1845  namei << i;
1846  namej << j;
1847  histoVarianceCheck_[i][j] = new TH1D(name+"_"+namei.str()+"_"+namej.str(), name, 10000, -1, 1);
1848  }
1849  }
1850  }
1851  }
TH2D * histoCovariance_
Definition: Histograms.h:1971
TString name_
Definition: Histograms.h:122
TDirectory * histoDir_
Definition: Histograms.h:124
Covariance ** covariances_
Definition: Histograms.h:1972
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1977
dbl *** dir
Definition: mlp_gen.cc:35
HCovarianceVSxy::HCovarianceVSxy ( TFile *  inputFile,
const TString &  name,
const TString &  dirName 
)
inline

Contructor to read histograms from file.

Definition at line 1853 of file Histograms.h.

References gather_cfg::cout, cmsRelvalreport::exit, and Histograms::histoDir_.

1853  :
1854  readMode_(true)
1855  {
1856  histoDir_ = (TDirectory*)(inputFile->Get(dirName.Data()));
1857  if( histoDir_ == nullptr ) {
1858  std::cout << "Error: directory not found" << std::endl;
1859  exit(0);
1860  }
1861  histoCovariance_ = (TH2D*)(histoDir_->Get(name));
1862  totBinsX_ = histoCovariance_->GetNbinsX();
1863  xMin_ = histoCovariance_->GetXaxis()->GetBinLowEdge(1);
1864  deltaX_ = histoCovariance_->GetXaxis()->GetBinUpEdge(totBinsX_) - xMin_;
1865  totBinsY_ = histoCovariance_->GetNbinsY();
1866  yMin_ = histoCovariance_->GetYaxis()->GetBinLowEdge(1);
1867  deltaY_ = histoCovariance_->GetYaxis()->GetBinUpEdge(totBinsY_) - yMin_;
1868  }
TH2D * histoCovariance_
Definition: Histograms.h:1971
TDirectory * histoDir_
Definition: Histograms.h:124
HCovarianceVSxy::~HCovarianceVSxy ( )
inlineoverride

Definition at line 1870 of file Histograms.h.

References mps_fire::i.

1870  {
1871  delete histoCovariance_;
1872  // Free covariances
1873  for(int i=0; i<totBinsX_; ++i) {
1874  delete[] covariances_[i];
1875  }
1876  delete[] covariances_;
1877  // Free variance check histograms
1878  if( varianceCheck_ ) {
1879  for( int i=0; i<totBinsX_; ++i ) {
1880  for( int j=0; j<totBinsY_; ++j ) {
1881  delete histoVarianceCheck_[i][j];
1882  }
1883  delete[] histoVarianceCheck_[i];
1884  }
1885  delete[] histoVarianceCheck_;
1886  }
1887  }
TH2D * histoCovariance_
Definition: Histograms.h:1971
Covariance ** covariances_
Definition: Histograms.h:1972
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1977

Member Function Documentation

void HCovarianceVSxy::Clear ( )
inlineoverridevirtual

Implements Histograms.

Definition at line 1954 of file Histograms.h.

References mps_fire::i.

1954  {
1955  histoCovariance_->Clear();
1956  if( varianceCheck_ ) {
1957  for( int i=0; i<totBinsX_; ++i ) {
1958  for( int j=0; j<totBinsY_; ++j ) {
1959  histoVarianceCheck_[i][j]->Clear();
1960  }
1961  }
1962  }
1963  }
TH2D * histoCovariance_
Definition: Histograms.h:1971
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1977
void HCovarianceVSxy::Fill ( const double &  x,
const double &  y,
const double &  a,
const double &  b 
)
inlineoverridevirtual

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

Reimplemented from Histograms.

Definition at line 1893 of file Histograms.h.

Referenced by ResolutionAnalyzer::analyze().

1893  {
1894  // Need to convert the (x,y) values to the array indeces
1895  int xIndex = getXindex(x);
1896  int yIndex = getYindex(y);
1897  // Only fill values if they are in the selected range
1898  if ( 0 <= xIndex && xIndex < totBinsX_ && 0 <= yIndex && yIndex < totBinsY_ ) {
1899  // if( TString(histoCovariance_->GetName()).Contains("CovarianceCotgTheta_Covariance") )
1900  covariances_[xIndex][yIndex].fill(a,b);
1901  // Should be used with the variance, in which case a==b
1902  if( varianceCheck_ ) histoVarianceCheck_[xIndex][yIndex]->Fill(a);
1903  }
1904  }
int getXindex(const double &x) const
Definition: Histograms.h:1965
void fill(const double &x, const double &y)
Definition: Histograms.h:1791
Covariance ** covariances_
Definition: Histograms.h:1972
double b
Definition: hdecay.h:120
int getYindex(const double &y) const
Definition: Histograms.h:1968
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1977
double a
Definition: hdecay.h:121
double HCovarianceVSxy::Get ( const double &  x,
const double &  y 
) const
inline

Definition at line 1906 of file Histograms.h.

1906  {
1907  // Need to convert the (x,y) values to the array indeces
1908  int xIndex = getXindex(x);
1909  int yIndex = getYindex(y);
1910  // If the values exceed the limits of the histogram, return the border values
1911  if ( xIndex < 0 ) xIndex = 0;
1912  if ( xIndex >= totBinsX_ ) xIndex = totBinsX_-1;
1913  if ( yIndex < 0 ) yIndex = 0;
1914  if ( yIndex >= totBinsY_ ) yIndex = totBinsY_-1;
1915  return histoCovariance_->GetBinContent(xIndex+1, yIndex+1);
1916  }
int getXindex(const double &x) const
Definition: Histograms.h:1965
TH2D * histoCovariance_
Definition: Histograms.h:1971
int getYindex(const double &y) const
Definition: Histograms.h:1968
int HCovarianceVSxy::getXindex ( const double &  x) const
inlineprotected

Definition at line 1965 of file Histograms.h.

References createfilelist::int.

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

Definition at line 1968 of file Histograms.h.

References createfilelist::int.

1968  {
1969  return int((y-yMin_)/deltaY_*totBinsY_);
1970  }
void HCovarianceVSxy::Write ( )
inlineoverridevirtual

Implements Histograms.

Definition at line 1918 of file Histograms.h.

References svgfig::canvas(), gather_cfg::cout, Histograms::histoDir_, Histograms::name_, and cuy::yBin.

Referenced by ResolutionAnalyzer::writeHistoMap().

1918  {
1919  if( !readMode_ ) {
1920  std::cout << "writing: " << histoCovariance_->GetName() << std::endl;
1921  for( int xBin=0; xBin<totBinsX_; ++xBin ) {
1922  for( int yBin=0; yBin<totBinsY_; ++yBin ) {
1923  double covariance = covariances_[xBin][yBin].covariance();
1924  // Histogram bins start from 1
1925  // std::cout << "covariance["<<xBin<<"]["<<yBin<<"] with N = "<<covariances_[xBin][yBin].getN()<<" is: " << covariance << std::endl;
1926  histoCovariance_->SetBinContent(xBin+1, yBin+1, covariance);
1927  }
1928  }
1929  if( histoDir_ != nullptr ) histoDir_->cd();
1930  TCanvas canvas(TString(histoCovariance_->GetName())+"_canvas", TString(histoCovariance_->GetTitle())+" canvas", 1000, 800);
1931  canvas.Divide(2);
1932  canvas.cd(1);
1933  histoCovariance_->Draw("lego");
1934  canvas.cd(2);
1935  histoCovariance_->Draw("surf5");
1936  canvas.Write();
1937  histoCovariance_->Write();
1938 
1939  TDirectory * binsDir = nullptr;
1940  if( varianceCheck_ ) {
1941  if ( histoDir_ != nullptr ) {
1942  histoDir_->cd();
1943  if( binsDir == nullptr ) binsDir = histoDir_->mkdir(name_+"Bins");
1944  binsDir->cd();
1945  }
1946  for( int xBin=0; xBin<totBinsX_; ++xBin ) {
1947  for( int yBin=0; yBin<totBinsY_; ++yBin ) {
1948  histoVarianceCheck_[xBin][yBin]->Write();
1949  }
1950  }
1951  }
1952  }
1953  }
double covariance()
Definition: Histograms.h:1797
TH2D * histoCovariance_
Definition: Histograms.h:1971
TString name_
Definition: Histograms.h:122
TDirectory * histoDir_
Definition: Histograms.h:124
Covariance ** covariances_
Definition: Histograms.h:1972
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1977
def canvas(sub, attr)
Definition: svgfig.py:481
yBin
Definition: cuy.py:891

Member Data Documentation

Covariance** HCovarianceVSxy::covariances_
protected

Definition at line 1972 of file Histograms.h.

double HCovarianceVSxy::deltaX_
protected

Definition at line 1974 of file Histograms.h.

double HCovarianceVSxy::deltaY_
protected

Definition at line 1974 of file Histograms.h.

TH2D* HCovarianceVSxy::histoCovariance_
protected

Definition at line 1971 of file Histograms.h.

TH1D*** HCovarianceVSxy::histoVarianceCheck_
protected

Definition at line 1977 of file Histograms.h.

bool HCovarianceVSxy::readMode_
protected

Definition at line 1975 of file Histograms.h.

int HCovarianceVSxy::totBinsX_
protected

Definition at line 1973 of file Histograms.h.

int HCovarianceVSxy::totBinsY_
protected

Definition at line 1973 of file Histograms.h.

int HCovarianceVSxy::totBinsZ_
protected

Definition at line 1973 of file Histograms.h.

bool HCovarianceVSxy::varianceCheck_
protected

Definition at line 1976 of file Histograms.h.

double HCovarianceVSxy::xMin_
protected

Definition at line 1974 of file Histograms.h.

double HCovarianceVSxy::yMin_
protected

Definition at line 1974 of file Histograms.h.