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

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

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

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

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

Definition at line 1872 of file Histograms.h.

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

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

Member Function Documentation

void HCovarianceVSxy::Clear ( )
inlinevirtual

Implements Histograms.

Definition at line 1956 of file Histograms.h.

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

1956  {
1957  histoCovariance_->Clear();
1958  if( varianceCheck_ ) {
1959  for( int i=0; i<totBinsX_; ++i ) {
1960  for( int j=0; j<totBinsY_; ++j ) {
1961  histoVarianceCheck_[i][j]->Clear();
1962  }
1963  }
1964  }
1965  }
int i
Definition: DBlmapReader.cc:9
TH2D * histoCovariance_
Definition: Histograms.h:1973
int j
Definition: DBlmapReader.cc:9
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1979
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 1895 of file Histograms.h.

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

Referenced by ResolutionAnalyzer::analyze().

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

Definition at line 1908 of file Histograms.h.

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

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

Definition at line 1967 of file Histograms.h.

References deltaX_, totBinsX_, and xMin_.

Referenced by Fill(), and Get().

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

Definition at line 1970 of file Histograms.h.

References deltaY_, totBinsY_, and yMin_.

Referenced by Fill(), and Get().

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

Implements Histograms.

Definition at line 1920 of file Histograms.h.

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

Referenced by ResolutionAnalyzer::writeHistoMap().

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

Member Data Documentation

Covariance** HCovarianceVSxy::covariances_
protected

Definition at line 1974 of file Histograms.h.

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

double HCovarianceVSxy::deltaX_
protected

Definition at line 1976 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

double HCovarianceVSxy::deltaY_
protected

Definition at line 1976 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().

TH2D* HCovarianceVSxy::histoCovariance_
protected

Definition at line 1973 of file Histograms.h.

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

TH1D*** HCovarianceVSxy::histoVarianceCheck_
protected

Definition at line 1979 of file Histograms.h.

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

bool HCovarianceVSxy::readMode_
protected

Definition at line 1977 of file Histograms.h.

Referenced by Write().

int HCovarianceVSxy::totBinsX_
protected

Definition at line 1975 of file Histograms.h.

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

int HCovarianceVSxy::totBinsY_
protected

Definition at line 1975 of file Histograms.h.

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

int HCovarianceVSxy::totBinsZ_
protected

Definition at line 1975 of file Histograms.h.

bool HCovarianceVSxy::varianceCheck_
protected

Definition at line 1978 of file Histograms.h.

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

double HCovarianceVSxy::xMin_
protected

Definition at line 1976 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

double HCovarianceVSxy::yMin_
protected

Definition at line 1976 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().