CMS 3D CMS Logo

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

#include <HistoPdf.h>

Inheritance diagram for funct::HistoPdf:
funct::RootHistoPdf

Public Member Functions

void dump ()
 
template<typename Iterator >
 HistoPdf (double xMin, double xMax, const Iterator &begin, const Iterator &end)
 
 HistoPdf ()
 
template<typename Iterator >
void init (double xMin, double xMax, const Iterator &begin, const Iterator &end)
 
double operator() (double x) const
 
void rebin (unsigned int r)
 

Private Attributes

double binSize_
 
double delta_
 
double xMax_
 
double xMin_
 
std::vector< double > y_
 

Detailed Description

Definition at line 10 of file HistoPdf.h.

Constructor & Destructor Documentation

template<typename Iterator >
funct::HistoPdf::HistoPdf ( double  xMin,
double  xMax,
const Iterator begin,
const Iterator end 
)
inline

Definition at line 13 of file HistoPdf.h.

References dataset::end, mps_fire::i, alignCSCRings::s, and y_.

14  : xMin_(xMin), xMax_(xMax), delta_(xMax - xMin), binSize_(delta_ / (end - begin)), y_(end - begin) {
15  double s = 0;
16  unsigned int i = 0;
17  for (Iterator it = begin; it != end; ++it)
18  s += (y_[i++] = *it);
19  for (std::vector<double>::iterator i = y_.begin(); i != y_.end(); ++i)
20  *i /= s;
21  }
double binSize_
Definition: HistoPdf.h:70
double xMin_
Definition: HistoPdf.h:70
double xMax_
Definition: HistoPdf.h:70
std::vector< double > y_
Definition: HistoPdf.h:71
string end
Definition: dataset.py:937
double delta_
Definition: HistoPdf.h:70
funct::HistoPdf::HistoPdf ( )
inline

Definition at line 22 of file HistoPdf.h.

22 {}

Member Function Documentation

void funct::HistoPdf::dump ( void  )
inline

Definition at line 56 of file HistoPdf.h.

References binSize_, gather_cfg::cout, delta_, mps_fire::i, operator()(), alignCSCRings::s, xMax_, xMin_, and y_.

56  {
57  std::cout << ">>> range: [" << xMin_ << ", " << xMax_ << "], bin size: " << delta_ << "/" << y_.size() << " = "
58  << binSize_ << std::endl;
59  double s = 0;
60  for (unsigned int i = 0; i != y_.size(); ++i) {
61  double x = xMin_ + (0.5 + i) * binSize_;
62  double y = operator()(x);
63  std::cout << ">>> pdf(" << x << ") = " << y << std::endl;
64  s += y * binSize_;
65  }
66  std::cout << ">>>: PDF normalization is " << s << std::endl;
67  }
double operator()(double x) const
Definition: HistoPdf.h:38
double binSize_
Definition: HistoPdf.h:70
double xMin_
Definition: HistoPdf.h:70
double xMax_
Definition: HistoPdf.h:70
std::vector< double > y_
Definition: HistoPdf.h:71
double delta_
Definition: HistoPdf.h:70
tuple cout
Definition: gather_cfg.py:144
template<typename Iterator >
void funct::HistoPdf::init ( double  xMin,
double  xMax,
const Iterator begin,
const Iterator end 
)
inline

Definition at line 24 of file HistoPdf.h.

References SplitLinear::begin, binSize_, delta_, dataset::end, mps_fire::i, dqmiodumpmetadata::n, alignCSCRings::s, xMax_, xMin_, and y_.

Referenced by funct::RootHistoPdf::RootHistoPdf().

24  {
25  xMin_ = xMin;
26  xMax_ = xMax;
27  delta_ = xMax - xMin;
28  unsigned int n = end - begin;
29  binSize_ = delta_ / n;
30  y_.resize(n);
31  double s = 0;
32  unsigned int i = 0;
33  for (Iterator it = begin; it != end; ++it)
34  s += (y_[i++] = *it);
35  for (std::vector<double>::iterator i = y_.begin(); i != y_.end(); ++i)
36  *i /= s;
37  }
double binSize_
Definition: HistoPdf.h:70
double xMin_
Definition: HistoPdf.h:70
double xMax_
Definition: HistoPdf.h:70
std::vector< double > y_
Definition: HistoPdf.h:71
string end
Definition: dataset.py:937
double delta_
Definition: HistoPdf.h:70
double funct::HistoPdf::operator() ( double  x) const
inline

Definition at line 38 of file HistoPdf.h.

References binSize_, delta_, xMax_, xMin_, and y_.

Referenced by dump().

38  {
39  if (x < xMin_ || x > xMax_)
40  return 0;
41  double pdf = y_[static_cast<unsigned int>(((x - xMin_) / delta_) * y_.size())] / binSize_;
42  return pdf;
43  }
double binSize_
Definition: HistoPdf.h:70
double xMin_
Definition: HistoPdf.h:70
double xMax_
Definition: HistoPdf.h:70
std::vector< double > y_
Definition: HistoPdf.h:71
double delta_
Definition: HistoPdf.h:70
void funct::HistoPdf::rebin ( unsigned int  r)
inline

Definition at line 44 of file HistoPdf.h.

References binSize_, edm::errors::Configuration, mps_fire::i, dqmiolumiharvest::j, isotrackApplyRegressor::k, dqmiodumpmetadata::n, alignCSCRings::r, and y_.

44  {
45  if (y_.size() % r != 0)
47  << "HistoPdf: can't rebin histogram of " << y_.size() << " entries by " << r << "\n";
48  unsigned int n = y_.size() / r;
49  std::vector<double> y(n, 0);
50  for (unsigned int i = 0, j = 0; i < n; ++i)
51  for (unsigned int k = 0; k < r; ++k)
52  y[i] += y_[j++];
53  y_ = y;
54  binSize_ *= r;
55  }
double binSize_
Definition: HistoPdf.h:70
std::vector< double > y_
Definition: HistoPdf.h:71

Member Data Documentation

double funct::HistoPdf::binSize_
private

Definition at line 70 of file HistoPdf.h.

Referenced by dump(), init(), operator()(), and rebin().

double funct::HistoPdf::delta_
private

Definition at line 70 of file HistoPdf.h.

Referenced by dump(), init(), and operator()().

double funct::HistoPdf::xMax_
private

Definition at line 70 of file HistoPdf.h.

Referenced by dump(), init(), and operator()().

double funct::HistoPdf::xMin_
private

Definition at line 70 of file HistoPdf.h.

Referenced by dump(), init(), and operator()().

std::vector<double> funct::HistoPdf::y_
private

Definition at line 71 of file HistoPdf.h.

Referenced by dump(), HistoPdf(), init(), operator()(), and rebin().