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
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 7 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 10 of file HistoPdf.h.

References end, i, asciidump::s, and y_.

11  :
12  xMin_(xMin), xMax_(xMax), delta_(xMax - xMin), binSize_(delta_ / (end - begin)), y_(end - begin) {
13  double s = 0;
14  unsigned int i = 0;
15  for(Iterator it = begin; it != end; ++it)
16  s += (y_[i++] = *it);
17  for(std::vector<double>::iterator i = y_.begin(); i != y_.end(); ++i)
18  *i /= s;
19  }
int i
Definition: DBlmapReader.cc:9
double binSize_
Definition: HistoPdf.h:67
double xMin_
Definition: HistoPdf.h:67
double xMax_
Definition: HistoPdf.h:67
#define end
Definition: vmac.h:38
std::vector< double > y_
Definition: HistoPdf.h:68
#define begin
Definition: vmac.h:31
double delta_
Definition: HistoPdf.h:67
string s
Definition: asciidump.py:422
funct::HistoPdf::HistoPdf ( )
inline

Definition at line 20 of file HistoPdf.h.

20 { }

Member Function Documentation

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

Definition at line 54 of file HistoPdf.h.

References binSize_, gather_cfg::cout, delta_, i, operator()(), asciidump::s, ExpressReco_HICollisions_FallBack::x, xMax_, xMin_, ExpressReco_HICollisions_FallBack::y, and y_.

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

Definition at line 22 of file HistoPdf.h.

References begin, binSize_, delta_, end, i, n, asciidump::s, xMax_, xMin_, and y_.

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

23  {
24  xMin_ = xMin;
25  xMax_ = xMax;
26  delta_ = xMax - xMin;
27  unsigned int n = end - begin;
28  binSize_ = delta_ / n;
29  y_.resize(n);
30  double s = 0;
31  unsigned int i = 0;
32  for(Iterator it = begin; it != end; ++it)
33  s += (y_[i++] = *it);
34  for(std::vector<double>::iterator i = y_.begin(); i != y_.end(); ++i)
35  *i /= s;
36  }
int i
Definition: DBlmapReader.cc:9
double binSize_
Definition: HistoPdf.h:67
double xMin_
Definition: HistoPdf.h:67
double xMax_
Definition: HistoPdf.h:67
#define end
Definition: vmac.h:38
std::vector< double > y_
Definition: HistoPdf.h:68
#define begin
Definition: vmac.h:31
double delta_
Definition: HistoPdf.h:67
string s
Definition: asciidump.py:422
double funct::HistoPdf::operator() ( double  x) const
inline

Definition at line 37 of file HistoPdf.h.

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

Referenced by dump().

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

Definition at line 42 of file HistoPdf.h.

References binSize_, edm::errors::Configuration, i, j, gen::k, n, csvReporter::r, ExpressReco_HICollisions_FallBack::y, and y_.

42  {
43  if(y_.size() % r != 0)
45  "HistoPdf: can't rebin histogram of " << y_.size() << " entries by " << r << "\n";
46  unsigned int n = y_.size() / r;
47  std::vector<double> y(n, 0);
48  for(unsigned int i = 0, j = 0; i < n; ++i)
49  for(unsigned int k = 0; k < r; ++k)
50  y[i] += y_[j++];
51  y_ = y;
52  binSize_ *= r;
53  }
int i
Definition: DBlmapReader.cc:9
double binSize_
Definition: HistoPdf.h:67
int j
Definition: DBlmapReader.cc:9
int k[5][pyjets_maxn]
std::vector< double > y_
Definition: HistoPdf.h:68

Member Data Documentation

double funct::HistoPdf::binSize_
private

Definition at line 67 of file HistoPdf.h.

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

double funct::HistoPdf::delta_
private

Definition at line 67 of file HistoPdf.h.

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

double funct::HistoPdf::xMax_
private

Definition at line 67 of file HistoPdf.h.

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

double funct::HistoPdf::xMin_
private

Definition at line 67 of file HistoPdf.h.

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

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

Definition at line 68 of file HistoPdf.h.

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