CMS 3D CMS Logo

Public Member Functions | Private Attributes

FastHisto2D Class Reference

#include <FastTemplate.h>

Inheritance diagram for FastHisto2D:
FastTemplate

List of all members.

Public Member Functions

void Dump () const
 FastHisto2D ()
 FastHisto2D (const TH2 &hist, bool normXonly=false)
 FastHisto2D (const FastHisto2D &other)
T GetAt (const T &x, const T &y) const
T IntegralWidth () const
void Normalize ()
void NormalizeXSlices ()
 For each X, normalize along Y.
FastHisto2Doperator= (const FastHisto2D &other)
void swap (FastHisto2D &other)
 ~FastHisto2D ()

Private Attributes

TbinEdgesX_
TbinEdgesY_
TbinWidths_
unsigned int binX_
unsigned int binY_

Detailed Description

Definition at line 103 of file FastTemplate.h.


Constructor & Destructor Documentation

FastHisto2D::FastHisto2D ( ) [inline]

Definition at line 105 of file FastTemplate.h.

FastHisto2D::FastHisto2D ( const TH2 &  hist,
bool  normXonly = false 
)

Definition at line 89 of file FastTemplate.cc.

References create_public_lumi_plots::ax, binEdgesX_, binEdgesY_, binWidths_, binX_, binY_, and i.

                                                        :
    FastTemplate(hist),
    binX_(hist.GetNbinsX()), binY_(hist.GetNbinsY()),
    binEdgesX_(new T[binX_+1]),
    binEdgesY_(new T[binY_+1]),
    binWidths_(new T[size_])
{
    TAxis *ax = hist.GetXaxis(), *ay = hist.GetYaxis();
    for (unsigned int ix = 0; ix < binX_; ++ix) {
        binEdgesX_[ix] = ax->GetBinLowEdge(ix+1);
    }
    binEdgesX_[binX_] = ax->GetBinLowEdge(binX_+1);
    for (unsigned int iy = 0; iy < binY_; ++iy) {
        binEdgesY_[iy] = ay->GetBinLowEdge(iy+1);
    }
    binEdgesY_[binY_] = ay->GetBinLowEdge(binY_+1);
    for (unsigned int ix = 1, i = 0; ix <= binX_; ++ix) {
        for (unsigned int iy = 1; iy <= binY_; ++iy, ++i) {
            binWidths_[i] = (normXonly ? 1 : ax->GetBinWidth(ix))*ay->GetBinWidth(iy);
        }
    }
}
FastHisto2D::FastHisto2D ( const FastHisto2D other)

Definition at line 112 of file FastTemplate.cc.

References binEdgesX_, binEdgesY_, binWidths_, binX_, binY_, and FastTemplate::size_.

                                                 :
    FastTemplate(other),
    binX_(other.binX_), binY_(other.binY_),
    binEdgesX_(binX_ ? new T[binX_+1] : 0),
    binEdgesY_(binX_ ? new T[binY_+1] : 0),
    binWidths_(binX_ ? new T[size_] : 0)
{
    if (binX_) {
        memcpy(binEdgesX_, other.binEdgesX_, (binX_+1)*sizeof(T));
        memcpy(binEdgesY_, other.binEdgesY_, (binY_+1)*sizeof(T));
        memcpy(binWidths_, other.binWidths_, size_*sizeof(T));
    }
}
FastHisto2D::~FastHisto2D ( ) [inline]

Definition at line 115 of file FastTemplate.h.

References binEdgesX_, binEdgesY_, and binWidths_.

{ delete [] binEdgesX_; delete [] binEdgesY_; delete [] binWidths_; }

Member Function Documentation

void FastHisto2D::Dump ( void  ) const

Reimplemented from FastTemplate.

Definition at line 154 of file FastTemplate.cc.

References binEdgesX_, binEdgesY_, binWidths_, binX_, binY_, i, FastTemplate::size_, and FastTemplate::values_.

                             {
    printf("--- dumping histo template with %d x %d bins (@%p)---\n", binX_, binY_, (void*)values_);
    for (unsigned int i = 0; i < size_; ++i) {
        printf(" bin %3d, x = %6.2f, y = %6.2f: yval = %9.5f, width = %6.3f\n", 
                    i, 0.5*(binEdgesX_[i/binY_]+binEdgesX_[i/binY_+1]), 
                       0.5*(binEdgesY_[i%binY_]+binEdgesY_[(i%binY_)+1]),
                     values_[i], binWidths_[i]);
    }
    printf("\n"); 
}
FastHisto2D::T FastHisto2D::GetAt ( const T x,
const T y 
) const

Definition at line 126 of file FastTemplate.cc.

References binEdgesX_, binEdgesY_, binX_, binY_, and FastTemplate::values_.

Referenced by FastVerticalInterpHistPdf2D::evaluate().

                                                            {
    T *matchx = std::lower_bound(binEdgesX_, binEdgesX_+binX_+1, x);
    int ix = (matchx - binEdgesX_ - 1);
    if (ix < 0 || unsigned(ix) >= binX_) return T(0.0);
    T *matchy = std::lower_bound(binEdgesY_, binEdgesY_+binY_+1, y);
    int iy = (matchy - binEdgesY_ - 1);
    if (iy < 0 || unsigned(iy) >= binY_) return T(0.0);
    return values_[ix * binY_ + iy];
}
FastHisto2D::T FastHisto2D::IntegralWidth ( ) const

Definition at line 136 of file FastTemplate.cc.

References binWidths_, i, FastTemplate::size_, pileupDistInMC::total, and FastTemplate::values_.

Referenced by Normalize().

                                              {
    double total = 0;
    for (unsigned int i = 0; i < size_; ++i) total += values_[i] * binWidths_[i];
    return total;
}
void FastHisto2D::Normalize ( ) [inline]
void FastHisto2D::NormalizeXSlices ( )

For each X, normalize along Y.

Definition at line 142 of file FastTemplate.cc.

References binWidths_, binX_, binY_, i, pileupDistInMC::total, makeHLTPrescaleTable::values, and FastTemplate::values_.

Referenced by FastVerticalInterpHistPdf2D::syncComponents(), FastVerticalInterpHistPdf2D::syncNominal(), and FastVerticalInterpHistPdf2D::syncTotal().

                                   {
    for (unsigned int ix = 0, offs = 0; ix < binX_; ++ix, offs += binY_) {
       T *values = & values_[offs], *widths = & binWidths_[offs];
       double total = 0;
       for (unsigned int i = 0; i < binY_; ++i) total += values[i] * widths[i];
       if (total > 0) {
            total = T(1.0)/total;
            for (unsigned int i = 0; i < binY_; ++i) values[i] *= total;
       } 
    }
}
FastHisto2D& FastHisto2D::operator= ( const FastHisto2D other) [inline]

Definition at line 108 of file FastTemplate.h.

References binX_, binY_, FastTemplate::CopyValues(), and swap().

                                                          { 
            if (binX_ != other.binY_ || binY_ != other.binY_) {
                FastHisto2D fh(other);
                swap(fh);
            } else CopyValues(other); 
            return *this; 
        }
void FastHisto2D::swap ( FastHisto2D other) [inline]

Member Data Documentation

Definition at line 137 of file FastTemplate.h.

Referenced by Dump(), FastHisto2D(), GetAt(), swap(), and ~FastHisto2D().

Definition at line 138 of file FastTemplate.h.

Referenced by Dump(), FastHisto2D(), GetAt(), swap(), and ~FastHisto2D().

Definition at line 139 of file FastTemplate.h.

Referenced by Dump(), FastHisto2D(), IntegralWidth(), NormalizeXSlices(), swap(), and ~FastHisto2D().

unsigned int FastHisto2D::binX_ [private]

Definition at line 136 of file FastTemplate.h.

Referenced by Dump(), FastHisto2D(), GetAt(), NormalizeXSlices(), operator=(), and swap().

unsigned int FastHisto2D::binY_ [private]

Definition at line 136 of file FastTemplate.h.

Referenced by Dump(), FastHisto2D(), GetAt(), NormalizeXSlices(), operator=(), and swap().