CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ()
 
virtual void Fill (const double &x, const double &y, const double &a, const double &b)
 
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 ()
 
 ~HCovarianceVSxy ()
 
- Public Member Functions inherited from Histograms
void declareHistograms ()
 
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.)
 
void fillEventInfo (int proc, int strk, int ntrkr)
 
void fillRecHistograms (const RecTrack_t &r)
 
void fillSimHistograms (const SimTrack_t &s)
 
void fillVzeroHistograms (const RecVzero_t &r, int part)
 
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)
 
 Histograms (const edm::ParameterSet &pset)
 
virtual void SetWeight (double weight)
 
void writeHistograms ()
 
virtual ~Histograms ()
 
 ~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 1819 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 1822 of file Histograms.h.

References covariances_, dir, histoCovariance_, Histograms::histoDir_, histoVarianceCheck_, i, j, mergeVDriftHistosByStation::name, Histograms::name_, totBinsX_, totBinsY_, and varianceCheck_.

1825  :
1826  totBinsX_(totBinsX), totBinsY_(totBinsY),
1827  xMin_(xMin), deltaX_(xMax-xMin), yMin_(yMin), deltaY_(yMax-yMin),
1828  readMode_(false),
1829  varianceCheck_(varianceCheck)
1830  {
1831  name_ = name;
1832  histoDir_ = dir;
1833  histoCovariance_ = new TH2D(name+"Covariance", title+" covariance", totBinsX, xMin, xMax, totBinsY, yMin, yMax);
1834 
1835  covariances_ = new Covariance*[totBinsX];
1836  for( int i=0; i<totBinsX; ++i ) {
1837  covariances_[i] = new Covariance[totBinsY];
1838  }
1839  if( varianceCheck_ ) {
1840  histoVarianceCheck_ = new TH1D**[totBinsX_];
1841  for( int i=0; i<totBinsX_; ++i ) {
1842  histoVarianceCheck_[i] = new TH1D*[totBinsY_];
1843  for( int j=0; j<totBinsY_; ++j ) {
1844  std::stringstream namei;
1845  std::stringstream namej;
1846  namei << i;
1847  namej << j;
1848  histoVarianceCheck_[i][j] = new TH1D(name+"_"+namei.str()+"_"+namej.str(), name, 10000, -1, 1);
1849  }
1850  }
1851  }
1852  }
int i
Definition: DBlmapReader.cc:9
TH2D * histoCovariance_
Definition: Histograms.h:1972
TString name_
Definition: Histograms.h:123
TDirectory * histoDir_
Definition: Histograms.h:125
int j
Definition: DBlmapReader.cc:9
Covariance ** covariances_
Definition: Histograms.h:1973
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1978
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 1854 of file Histograms.h.

References gather_cfg::cout, deltaX_, deltaY_, cmsRelvalreport::exit, histoCovariance_, Histograms::histoDir_, totBinsX_, totBinsY_, xMin_, and yMin_.

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

Definition at line 1871 of file Histograms.h.

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

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

Member Function Documentation

void HCovarianceVSxy::Clear ( )
inlinevirtual

Implements Histograms.

Definition at line 1955 of file Histograms.h.

References histoCovariance_, histoVarianceCheck_, i, j, totBinsX_, totBinsY_, and varianceCheck_.

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

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

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

Referenced by ResolutionAnalyzer::analyze().

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

Definition at line 1907 of file Histograms.h.

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

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

Definition at line 1966 of file Histograms.h.

References deltaX_, totBinsX_, and xMin_.

Referenced by Fill(), and Get().

1966  {
1967  return int((x-xMin_)/deltaX_*totBinsX_);
1968  }
Definition: DDAxes.h:10
int HCovarianceVSxy::getYindex ( const double &  y) const
inlineprotected

Definition at line 1969 of file Histograms.h.

References deltaY_, totBinsY_, and yMin_.

Referenced by Fill(), and Get().

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

Implements Histograms.

Definition at line 1919 of file Histograms.h.

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

Referenced by ResolutionAnalyzer::writeHistoMap().

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

Member Data Documentation

Covariance** HCovarianceVSxy::covariances_
protected

Definition at line 1973 of file Histograms.h.

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

double HCovarianceVSxy::deltaX_
protected

Definition at line 1975 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

double HCovarianceVSxy::deltaY_
protected

Definition at line 1975 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().

TH2D* HCovarianceVSxy::histoCovariance_
protected

Definition at line 1972 of file Histograms.h.

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

TH1D*** HCovarianceVSxy::histoVarianceCheck_
protected

Definition at line 1978 of file Histograms.h.

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

bool HCovarianceVSxy::readMode_
protected

Definition at line 1976 of file Histograms.h.

Referenced by Write().

int HCovarianceVSxy::totBinsX_
protected

Definition at line 1974 of file Histograms.h.

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

int HCovarianceVSxy::totBinsY_
protected

Definition at line 1974 of file Histograms.h.

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

int HCovarianceVSxy::totBinsZ_
protected

Definition at line 1974 of file Histograms.h.

bool HCovarianceVSxy::varianceCheck_
protected

Definition at line 1977 of file Histograms.h.

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

double HCovarianceVSxy::xMin_
protected

Definition at line 1975 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

double HCovarianceVSxy::yMin_
protected

Definition at line 1975 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().