CMS 3D CMS Logo

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

◆ HistoPdf() [1/2]

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 mps_fire::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
double delta_
Definition: HistoPdf.h:70

◆ HistoPdf() [2/2]

funct::HistoPdf::HistoPdf ( )
inline

Definition at line 22 of file HistoPdf.h.

22 {}

Member Function Documentation

◆ dump()

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, x, 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

◆ init()

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 binSize_, delta_, mps_fire::end, mps_fire::i, dqmiodumpmetadata::n, alignCSCRings::s, multiplicitycorr_cfi::xMax, xMax_, photonAnalyzer_cfi::xMin, 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
double delta_
Definition: HistoPdf.h:70

◆ operator()()

double funct::HistoPdf::operator() ( double  x) const
inline

Definition at line 38 of file HistoPdf.h.

References binSize_, delta_, x, 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

◆ rebin()

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, dqmdumpme::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

◆ binSize_

double funct::HistoPdf::binSize_
private

Definition at line 70 of file HistoPdf.h.

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

◆ delta_

double funct::HistoPdf::delta_
private

Definition at line 70 of file HistoPdf.h.

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

◆ xMax_

double funct::HistoPdf::xMax_
private

Definition at line 70 of file HistoPdf.h.

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

◆ xMin_

double funct::HistoPdf::xMin_
private

Definition at line 70 of file HistoPdf.h.

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

◆ y_

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

Definition at line 71 of file HistoPdf.h.

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