#include <Histograms.h>
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. | |
void | Write () |
~HCovarianceVSxy () | |
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_ |
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.
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_.
: totBinsX_(totBinsX), totBinsY_(totBinsY), xMin_(xMin), deltaX_(xMax-xMin), yMin_(yMin), deltaY_(yMax-yMin), readMode_(false), varianceCheck_(varianceCheck) { name_ = name; histoDir_ = dir; histoCovariance_ = new TH2D(name+"Covariance", title+" covariance", totBinsX, xMin, xMax, totBinsY, yMin, yMax); covariances_ = new Covariance*[totBinsX]; for( int i=0; i<totBinsX; ++i ) { covariances_[i] = new Covariance[totBinsY]; } if( varianceCheck_ ) { histoVarianceCheck_ = new TH1D**[totBinsX_]; for( int i=0; i<totBinsX_; ++i ) { histoVarianceCheck_[i] = new TH1D*[totBinsY_]; for( int j=0; j<totBinsY_; ++j ) { std::stringstream namei; std::stringstream namej; namei << i; namej << j; histoVarianceCheck_[i][j] = new TH1D(name+"_"+namei.str()+"_"+namej.str(), name, 10000, -1, 1); } } } }
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_.
: readMode_(true) { histoDir_ = (TDirectory*)(inputFile->Get(dirName.Data())); if( histoDir_ == 0 ) { std::cout << "Error: directory not found" << std::endl; exit(0); } histoCovariance_ = (TH2D*)(histoDir_->Get(name)); totBinsX_ = histoCovariance_->GetNbinsX(); xMin_ = histoCovariance_->GetXaxis()->GetBinLowEdge(1); deltaX_ = histoCovariance_->GetXaxis()->GetBinUpEdge(totBinsX_) - xMin_; totBinsY_ = histoCovariance_->GetNbinsY(); yMin_ = histoCovariance_->GetYaxis()->GetBinLowEdge(1); deltaY_ = histoCovariance_->GetYaxis()->GetBinUpEdge(totBinsY_) - yMin_; }
HCovarianceVSxy::~HCovarianceVSxy | ( | ) | [inline] |
Definition at line 1588 of file Histograms.h.
References covariances_, histoCovariance_, histoVarianceCheck_, i, j, totBinsX_, totBinsY_, and varianceCheck_.
{ delete histoCovariance_; // Free covariances for(int i=0; i<totBinsX_; ++i) { delete[] covariances_[i]; } delete[] covariances_; // Free variance check histograms if( varianceCheck_ ) { for( int i=0; i<totBinsX_; ++i ) { for( int j=0; j<totBinsY_; ++j ) { delete histoVarianceCheck_[i][j]; } delete[] histoVarianceCheck_[i]; } delete[] histoVarianceCheck_; } }
void HCovarianceVSxy::Clear | ( | ) | [inline, virtual] |
Implements Histograms.
Definition at line 1672 of file Histograms.h.
References histoCovariance_, histoVarianceCheck_, i, j, totBinsX_, totBinsY_, and varianceCheck_.
{ histoCovariance_->Clear(); if( varianceCheck_ ) { for( int i=0; i<totBinsX_; ++i ) { for( int j=0; j<totBinsY_; ++j ) { histoVarianceCheck_[i][j]->Clear(); } } } }
virtual void HCovarianceVSxy::Fill | ( | const double & | x, |
const double & | y, | ||
const double & | a, | ||
const double & | b | ||
) | [inline, virtual] |
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().
{ // Need to convert the (x,y) values to the array indeces int xIndex = getXindex(x); int yIndex = getYindex(y); // Only fill values if they are in the selected range if ( 0 <= xIndex && xIndex < totBinsX_ && 0 <= yIndex && yIndex < totBinsY_ ) { // if( TString(histoCovariance_->GetName()).Contains("CovarianceCotgTheta_Covariance") ) covariances_[xIndex][yIndex].fill(a,b); // Should be used with the variance, in which case a==b if( varianceCheck_ ) histoVarianceCheck_[xIndex][yIndex]->Fill(a); } }
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_.
{ // Need to convert the (x,y) values to the array indeces int xIndex = getXindex(x); int yIndex = getYindex(y); // If the values exceed the limits of the histogram, return the border values if ( xIndex < 0 ) xIndex = 0; if ( xIndex >= totBinsX_ ) xIndex = totBinsX_-1; if ( yIndex < 0 ) yIndex = 0; if ( yIndex >= totBinsY_ ) yIndex = totBinsY_-1; return histoCovariance_->GetBinContent(xIndex+1, yIndex+1); }
int HCovarianceVSxy::getXindex | ( | const double & | x | ) | const [inline, protected] |
int HCovarianceVSxy::getYindex | ( | const double & | y | ) | const [inline, protected] |
void HCovarianceVSxy::Write | ( | ) | [inline, virtual] |
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().
{ if( !readMode_ ) { std::cout << "writing: " << histoCovariance_->GetName() << std::endl; for( int xBin=0; xBin<totBinsX_; ++xBin ) { for( int yBin=0; yBin<totBinsY_; ++yBin ) { double covariance = covariances_[xBin][yBin].covariance(); // Histogram bins start from 1 // std::cout << "covariance["<<xBin<<"]["<<yBin<<"] with N = "<<covariances_[xBin][yBin].getN()<<" is: " << covariance << std::endl; histoCovariance_->SetBinContent(xBin+1, yBin+1, covariance); } } if( histoDir_ != 0 ) histoDir_->cd(); TCanvas canvas(TString(histoCovariance_->GetName())+"_canvas", TString(histoCovariance_->GetTitle())+" canvas", 1000, 800); canvas.Divide(2); canvas.cd(1); histoCovariance_->Draw("lego"); canvas.cd(2); histoCovariance_->Draw("surf5"); canvas.Write(); histoCovariance_->Write(); TDirectory * binsDir = 0; if( varianceCheck_ ) { if ( histoDir_ != 0 ) { histoDir_->cd(); if( binsDir == 0 ) binsDir = histoDir_->mkdir(name_+"Bins"); binsDir->cd(); } for( int xBin=0; xBin<totBinsX_; ++xBin ) { for( int yBin=0; yBin<totBinsY_; ++yBin ) { histoVarianceCheck_[xBin][yBin]->Write(); } } } } }
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().