CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
FastHisto2D Class Reference

#include <FastTemplate.h>

Inheritance diagram for FastHisto2D:
FastTemplate

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. More...
 
FastHisto2Doperator= (const FastHisto2D &other)
 
void swap (FastHisto2D &other)
 
 ~FastHisto2D ()
 
- Public Member Functions inherited from FastTemplate
void Clear ()
 
void CopyValues (const FastTemplate &other)
 
void CopyValues (const TH1 &other)
 
void CopyValues (const TH2 &other)
 
void CropUnderflows (T minimum=1e-9)
 protect from underflows (*this = max(*this, minimum)); More...
 
void Dump () const
 
void Exp ()
 *this = exp(*this) More...
 
 FastTemplate ()
 
 FastTemplate (unsigned int size)
 
 FastTemplate (const FastTemplate &other)
 
 FastTemplate (const TH1 &other)
 
 FastTemplate (const TH2 &other)
 
T Integral () const
 
void Log ()
 *this = log(*this) More...
 
void LogRatio (const FastTemplate &reference)
 *this = log(*this)/(reference) More...
 
void Meld (const FastTemplate &diff, const FastTemplate &sum, T x, T y)
 Does this += x * (diff + (sum)*y) More...
 
FastTemplateoperator= (const FastTemplate &other)
 
FastTemplateoperator= (const TH1 &other)
 
Toperator[] (unsigned int i)
 
const Toperator[] (unsigned int i) const
 
void Resize (unsigned int newsize)
 
void Scale (T factor)
 
const unsigned int size () const
 
void Subtract (const FastTemplate &reference)
 *this = *this - reference More...
 
 ~FastTemplate ()
 

Private Attributes

TbinEdgesX_
 
TbinEdgesY_
 
TbinWidths_
 
unsigned int binX_
 
unsigned int binY_
 

Additional Inherited Members

- Public Types inherited from FastTemplate
typedef double T
 
- Static Public Member Functions inherited from FastTemplate
static void SumDiff (const FastTemplate &h1, const FastTemplate &h2, FastTemplate &sum, FastTemplate &diff)
 assigns sum and diff More...
 
- Protected Attributes inherited from FastTemplate
unsigned int size_
 
Tvalues_
 

Detailed Description

Definition at line 103 of file FastTemplate.h.

Constructor & Destructor Documentation

FastHisto2D::FastHisto2D ( )
inline

Definition at line 105 of file FastTemplate.h.

105 : FastTemplate(), binX_(0), binY_(0), binEdgesX_(0), binEdgesY_(0), binWidths_(0) {}
unsigned int binX_
Definition: FastTemplate.h:136
unsigned int binY_
Definition: FastTemplate.h:136
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.

89  :
91  binX_(hist.GetNbinsX()), binY_(hist.GetNbinsY()),
92  binEdgesX_(new T[binX_+1]),
93  binEdgesY_(new T[binY_+1]),
94  binWidths_(new T[size_])
95 {
96  TAxis *ax = hist.GetXaxis(), *ay = hist.GetYaxis();
97  for (unsigned int ix = 0; ix < binX_; ++ix) {
98  binEdgesX_[ix] = ax->GetBinLowEdge(ix+1);
99  }
100  binEdgesX_[binX_] = ax->GetBinLowEdge(binX_+1);
101  for (unsigned int iy = 0; iy < binY_; ++iy) {
102  binEdgesY_[iy] = ay->GetBinLowEdge(iy+1);
103  }
104  binEdgesY_[binY_] = ay->GetBinLowEdge(binY_+1);
105  for (unsigned int ix = 1, i = 0; ix <= binX_; ++ix) {
106  for (unsigned int iy = 1; iy <= binY_; ++iy, ++i) {
107  binWidths_[i] = (normXonly ? 1 : ax->GetBinWidth(ix))*ay->GetBinWidth(iy);
108  }
109  }
110 }
int i
Definition: DBlmapReader.cc:9
unsigned int binX_
Definition: FastTemplate.h:136
unsigned int size_
Definition: FastTemplate.h:61
long double T
unsigned int binY_
Definition: FastTemplate.h:136
FastHisto2D::FastHisto2D ( const FastHisto2D other)

Definition at line 112 of file FastTemplate.cc.

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

112  :
113  FastTemplate(other),
114  binX_(other.binX_), binY_(other.binY_),
115  binEdgesX_(binX_ ? new T[binX_+1] : 0),
116  binEdgesY_(binX_ ? new T[binY_+1] : 0),
117  binWidths_(binX_ ? new T[size_] : 0)
118 {
119  if (binX_) {
120  memcpy(binEdgesX_, other.binEdgesX_, (binX_+1)*sizeof(T));
121  memcpy(binEdgesY_, other.binEdgesY_, (binY_+1)*sizeof(T));
122  memcpy(binWidths_, other.binWidths_, size_*sizeof(T));
123  }
124 }
unsigned int binX_
Definition: FastTemplate.h:136
unsigned int size_
Definition: FastTemplate.h:61
long double T
unsigned int binY_
Definition: FastTemplate.h:136
FastHisto2D::~FastHisto2D ( )
inline

Definition at line 115 of file FastTemplate.h.

References binEdgesX_, binEdgesY_, and binWidths_.

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

Member Function Documentation

void FastHisto2D::Dump ( void  ) const

Definition at line 154 of file FastTemplate.cc.

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

154  {
155  printf("--- dumping histo template with %d x %d bins (@%p)---\n", binX_, binY_, (void*)values_);
156  for (unsigned int i = 0; i < size_; ++i) {
157  printf(" bin %3d, x = %6.2f, y = %6.2f: yval = %9.5f, width = %6.3f\n",
158  i, 0.5*(binEdgesX_[i/binY_]+binEdgesX_[i/binY_+1]),
159  0.5*(binEdgesY_[i%binY_]+binEdgesY_[(i%binY_)+1]),
160  values_[i], binWidths_[i]);
161  }
162  printf("\n");
163 }
int i
Definition: DBlmapReader.cc:9
unsigned int binX_
Definition: FastTemplate.h:136
unsigned int size_
Definition: FastTemplate.h:61
unsigned int binY_
Definition: FastTemplate.h:136
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().

126  {
127  T *matchx = std::lower_bound(binEdgesX_, binEdgesX_+binX_+1, x);
128  int ix = (matchx - binEdgesX_ - 1);
129  if (ix < 0 || unsigned(ix) >= binX_) return T(0.0);
130  T *matchy = std::lower_bound(binEdgesY_, binEdgesY_+binY_+1, y);
131  int iy = (matchy - binEdgesY_ - 1);
132  if (iy < 0 || unsigned(iy) >= binY_) return T(0.0);
133  return values_[ix * binY_ + iy];
134 }
unsigned int binX_
Definition: FastTemplate.h:136
x
Definition: VDTMath.h:216
long double T
unsigned int binY_
Definition: FastTemplate.h:136
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().

136  {
137  double total = 0;
138  for (unsigned int i = 0; i < size_; ++i) total += values_[i] * binWidths_[i];
139  return total;
140 }
int i
Definition: DBlmapReader.cc:9
unsigned int size_
Definition: FastTemplate.h:61
void FastHisto2D::Normalize ( )
inline

Definition at line 127 of file FastTemplate.h.

References f, IntegralWidth(), and FastTemplate::Scale().

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

127  {
128  T sum = IntegralWidth();
129  if (sum > 0) Scale(1.0f/sum);
130  }
double f[11][100]
T IntegralWidth() const
long double T
void Scale(T factor)
Definition: FastTemplate.cc:14
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().

142  {
143  for (unsigned int ix = 0, offs = 0; ix < binX_; ++ix, offs += binY_) {
144  T *values = & values_[offs], *widths = & binWidths_[offs];
145  double total = 0;
146  for (unsigned int i = 0; i < binY_; ++i) total += values[i] * widths[i];
147  if (total > 0) {
148  total = T(1.0)/total;
149  for (unsigned int i = 0; i < binY_; ++i) values[i] *= total;
150  }
151  }
152 }
int i
Definition: DBlmapReader.cc:9
unsigned int binX_
Definition: FastTemplate.h:136
long double T
unsigned int binY_
Definition: FastTemplate.h:136
FastHisto2D& FastHisto2D::operator= ( const FastHisto2D other)
inline

Definition at line 108 of file FastTemplate.h.

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

108  {
109  if (binX_ != other.binY_ || binY_ != other.binY_) {
110  FastHisto2D fh(other);
111  swap(fh);
112  } else CopyValues(other);
113  return *this;
114  }
void CopyValues(const FastTemplate &other)
Definition: FastTemplate.cc:22
void swap(FastHisto2D &other)
Definition: FastTemplate.h:116
unsigned int binX_
Definition: FastTemplate.h:136
unsigned int binY_
Definition: FastTemplate.h:136
void FastHisto2D::swap ( FastHisto2D other)
inline

Definition at line 116 of file FastTemplate.h.

References binEdgesX_, binEdgesY_, binWidths_, binX_, binY_, FastTemplate::size_, std::swap(), and FastTemplate::values_.

Referenced by operator=().

116  {
117  std::swap(binX_, other.binX_);
118  std::swap(binY_, other.binY_);
119  std::swap(size_, other.size_);
120  std::swap(values_, other.values_);
124  }
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
unsigned int binX_
Definition: FastTemplate.h:136
unsigned int size_
Definition: FastTemplate.h:61
unsigned int binY_
Definition: FastTemplate.h:136

Member Data Documentation

T* FastHisto2D::binEdgesX_
private

Definition at line 137 of file FastTemplate.h.

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

T* FastHisto2D::binEdgesY_
private

Definition at line 138 of file FastTemplate.h.

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

T* FastHisto2D::binWidths_
private

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().