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

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 end, mps_fire::i, alignCSCRings::s, and y_.

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

Definition at line 23 of file HistoPdf.h.

23 { }

Member Function Documentation

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

Definition at line 57 of file HistoPdf.h.

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

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

Definition at line 25 of file HistoPdf.h.

References begin, binSize_, delta_, end, mps_fire::i, gen::n, alignCSCRings::s, anotherprimaryvertexanalyzer_cfi::xMax, xMax_, anotherprimaryvertexanalyzer_cfi::xMin, xMin_, and y_.

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

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

Definition at line 40 of file HistoPdf.h.

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

Referenced by dump().

40  {
41  if (x < xMin_ || x > xMax_) return 0;
42  double pdf = y_[static_cast<unsigned int>(((x -xMin_)/delta_)*y_.size())] / binSize_;
43  return pdf;
44  }
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 45 of file HistoPdf.h.

References binSize_, edm::errors::Configuration, mps_fire::i, gen::k, gen::n, alignCSCRings::r, and y_.

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