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 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)
 
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 1536 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 1539 of file Histograms.h.

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

1542  :
1543  totBinsX_(totBinsX), totBinsY_(totBinsY),
1544  xMin_(xMin), deltaX_(xMax-xMin), yMin_(yMin), deltaY_(yMax-yMin),
1545  readMode_(false),
1546  varianceCheck_(varianceCheck)
1547  {
1548  name_ = name;
1549  histoDir_ = dir;
1550  histoCovariance_ = new TH2D(name+"Covariance", title+" covariance", totBinsX, xMin, xMax, totBinsY, yMin, yMax);
1551 
1552  covariances_ = new Covariance*[totBinsX];
1553  for( int i=0; i<totBinsX; ++i ) {
1554  covariances_[i] = new Covariance[totBinsY];
1555  }
1556  if( varianceCheck_ ) {
1557  histoVarianceCheck_ = new TH1D**[totBinsX_];
1558  for( int i=0; i<totBinsX_; ++i ) {
1559  histoVarianceCheck_[i] = new TH1D*[totBinsY_];
1560  for( int j=0; j<totBinsY_; ++j ) {
1561  std::stringstream namei;
1562  std::stringstream namej;
1563  namei << i;
1564  namej << j;
1565  histoVarianceCheck_[i][j] = new TH1D(name+"_"+namei.str()+"_"+namej.str(), name, 10000, -1, 1);
1566  }
1567  }
1568  }
1569  }
int i
Definition: DBlmapReader.cc:9
TH2D * histoCovariance_
Definition: Histograms.h:1689
TString name_
Definition: Histograms.h:106
TDirectory * histoDir_
Definition: Histograms.h:108
int j
Definition: DBlmapReader.cc:9
Covariance ** covariances_
Definition: Histograms.h:1690
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1695
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 1571 of file Histograms.h.

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

1571  :
1572  readMode_(true)
1573  {
1574  histoDir_ = (TDirectory*)(inputFile->Get(dirName.Data()));
1575  if( histoDir_ == 0 ) {
1576  std::cout << "Error: directory not found" << std::endl;
1577  exit(0);
1578  }
1579  histoCovariance_ = (TH2D*)(histoDir_->Get(name));
1580  totBinsX_ = histoCovariance_->GetNbinsX();
1581  xMin_ = histoCovariance_->GetXaxis()->GetBinLowEdge(1);
1582  deltaX_ = histoCovariance_->GetXaxis()->GetBinUpEdge(totBinsX_) - xMin_;
1583  totBinsY_ = histoCovariance_->GetNbinsY();
1584  yMin_ = histoCovariance_->GetYaxis()->GetBinLowEdge(1);
1585  deltaY_ = histoCovariance_->GetYaxis()->GetBinUpEdge(totBinsY_) - yMin_;
1586  }
TH2D * histoCovariance_
Definition: Histograms.h:1689
TDirectory * histoDir_
Definition: Histograms.h:108
tuple cout
Definition: gather_cfg.py:41
HCovarianceVSxy::~HCovarianceVSxy ( )
inline

Definition at line 1588 of file Histograms.h.

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

1588  {
1589  delete histoCovariance_;
1590  // Free covariances
1591  for(int i=0; i<totBinsX_; ++i) {
1592  delete[] covariances_[i];
1593  }
1594  delete[] covariances_;
1595  // Free variance check histograms
1596  if( varianceCheck_ ) {
1597  for( int i=0; i<totBinsX_; ++i ) {
1598  for( int j=0; j<totBinsY_; ++j ) {
1599  delete histoVarianceCheck_[i][j];
1600  }
1601  delete[] histoVarianceCheck_[i];
1602  }
1603  delete[] histoVarianceCheck_;
1604  }
1605  }
int i
Definition: DBlmapReader.cc:9
TH2D * histoCovariance_
Definition: Histograms.h:1689
int j
Definition: DBlmapReader.cc:9
Covariance ** covariances_
Definition: Histograms.h:1690
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1695

Member Function Documentation

void HCovarianceVSxy::Clear ( )
inlinevirtual

Implements Histograms.

Definition at line 1672 of file Histograms.h.

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

1672  {
1673  histoCovariance_->Clear();
1674  if( varianceCheck_ ) {
1675  for( int i=0; i<totBinsX_; ++i ) {
1676  for( int j=0; j<totBinsY_; ++j ) {
1677  histoVarianceCheck_[i][j]->Clear();
1678  }
1679  }
1680  }
1681  }
int i
Definition: DBlmapReader.cc:9
TH2D * histoCovariance_
Definition: Histograms.h:1689
int j
Definition: DBlmapReader.cc:9
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1695
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 1611 of file Histograms.h.

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

Referenced by ResolutionAnalyzer::analyze().

1611  {
1612  // Need to convert the (x,y) values to the array indeces
1613  int xIndex = getXindex(x);
1614  int yIndex = getYindex(y);
1615  // Only fill values if they are in the selected range
1616  if ( 0 <= xIndex && xIndex < totBinsX_ && 0 <= yIndex && yIndex < totBinsY_ ) {
1617  // if( TString(histoCovariance_->GetName()).Contains("CovarianceCotgTheta_Covariance") )
1618  covariances_[xIndex][yIndex].fill(a,b);
1619  // Should be used with the variance, in which case a==b
1620  if( varianceCheck_ ) histoVarianceCheck_[xIndex][yIndex]->Fill(a);
1621  }
1622  }
int getXindex(const double &x) const
Definition: Histograms.h:1683
void fill(const double &x, const double &y)
Definition: Histograms.h:1509
Covariance ** covariances_
Definition: Histograms.h:1690
double b
Definition: hdecay.h:120
int getYindex(const double &y) const
Definition: Histograms.h:1686
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1695
double a
Definition: hdecay.h:121
double HCovarianceVSxy::Get ( const double &  x,
const double &  y 
) const
inline

Definition at line 1624 of file Histograms.h.

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

1624  {
1625  // Need to convert the (x,y) values to the array indeces
1626  int xIndex = getXindex(x);
1627  int yIndex = getYindex(y);
1628  // If the values exceed the limits of the histogram, return the border values
1629  if ( xIndex < 0 ) xIndex = 0;
1630  if ( xIndex >= totBinsX_ ) xIndex = totBinsX_-1;
1631  if ( yIndex < 0 ) yIndex = 0;
1632  if ( yIndex >= totBinsY_ ) yIndex = totBinsY_-1;
1633  return histoCovariance_->GetBinContent(xIndex+1, yIndex+1);
1634  }
int getXindex(const double &x) const
Definition: Histograms.h:1683
TH2D * histoCovariance_
Definition: Histograms.h:1689
int getYindex(const double &y) const
Definition: Histograms.h:1686
int HCovarianceVSxy::getXindex ( const double &  x) const
inlineprotected

Definition at line 1683 of file Histograms.h.

References deltaX_, totBinsX_, and xMin_.

Referenced by Fill(), and Get().

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

Definition at line 1686 of file Histograms.h.

References deltaY_, totBinsY_, and yMin_.

Referenced by Fill(), and Get().

void HCovarianceVSxy::Write ( )
inlinevirtual

Implements Histograms.

Definition at line 1636 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().

1636  {
1637  if( !readMode_ ) {
1638  std::cout << "writing: " << histoCovariance_->GetName() << std::endl;
1639  for( int xBin=0; xBin<totBinsX_; ++xBin ) {
1640  for( int yBin=0; yBin<totBinsY_; ++yBin ) {
1641  double covariance = covariances_[xBin][yBin].covariance();
1642  // Histogram bins start from 1
1643  // std::cout << "covariance["<<xBin<<"]["<<yBin<<"] with N = "<<covariances_[xBin][yBin].getN()<<" is: " << covariance << std::endl;
1644  histoCovariance_->SetBinContent(xBin+1, yBin+1, covariance);
1645  }
1646  }
1647  if( histoDir_ != 0 ) histoDir_->cd();
1648  TCanvas canvas(TString(histoCovariance_->GetName())+"_canvas", TString(histoCovariance_->GetTitle())+" canvas", 1000, 800);
1649  canvas.Divide(2);
1650  canvas.cd(1);
1651  histoCovariance_->Draw("lego");
1652  canvas.cd(2);
1653  histoCovariance_->Draw("surf5");
1654  canvas.Write();
1655  histoCovariance_->Write();
1656 
1657  TDirectory * binsDir = 0;
1658  if( varianceCheck_ ) {
1659  if ( histoDir_ != 0 ) {
1660  histoDir_->cd();
1661  if( binsDir == 0 ) binsDir = histoDir_->mkdir(name_+"Bins");
1662  binsDir->cd();
1663  }
1664  for( int xBin=0; xBin<totBinsX_; ++xBin ) {
1665  for( int yBin=0; yBin<totBinsY_; ++yBin ) {
1666  histoVarianceCheck_[xBin][yBin]->Write();
1667  }
1668  }
1669  }
1670  }
1671  }
double covariance()
Definition: Histograms.h:1515
TH2D * histoCovariance_
Definition: Histograms.h:1689
def canvas
Definition: svgfig.py:481
TString name_
Definition: Histograms.h:106
TDirectory * histoDir_
Definition: Histograms.h:108
Covariance ** covariances_
Definition: Histograms.h:1690
TH1D *** histoVarianceCheck_
Definition: Histograms.h:1695
tuple cout
Definition: gather_cfg.py:41

Member Data Documentation

Covariance** HCovarianceVSxy::covariances_
protected

Definition at line 1690 of file Histograms.h.

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

double HCovarianceVSxy::deltaX_
protected

Definition at line 1692 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

double HCovarianceVSxy::deltaY_
protected

Definition at line 1692 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().

TH2D* HCovarianceVSxy::histoCovariance_
protected

Definition at line 1689 of file Histograms.h.

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

TH1D*** HCovarianceVSxy::histoVarianceCheck_
protected

Definition at line 1695 of file Histograms.h.

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

bool HCovarianceVSxy::readMode_
protected

Definition at line 1693 of file Histograms.h.

Referenced by Write().

int HCovarianceVSxy::totBinsX_
protected

Definition at line 1691 of file Histograms.h.

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

int HCovarianceVSxy::totBinsY_
protected

Definition at line 1691 of file Histograms.h.

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

int HCovarianceVSxy::totBinsZ_
protected

Definition at line 1691 of file Histograms.h.

bool HCovarianceVSxy::varianceCheck_
protected

Definition at line 1694 of file Histograms.h.

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

double HCovarianceVSxy::xMin_
protected

Definition at line 1692 of file Histograms.h.

Referenced by getXindex(), and HCovarianceVSxy().

double HCovarianceVSxy::yMin_
protected

Definition at line 1692 of file Histograms.h.

Referenced by getYindex(), and HCovarianceVSxy().