CMS 3D CMS Logo

Public Member Functions | Private Attributes

funct::HistoPdf Class Reference

#include <HistoPdf.h>

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

List of all members.

Public Member Functions

void dump ()
 HistoPdf ()
template<typename Iterator >
 HistoPdf (double xMin, double xMax, const Iterator &begin, const Iterator &end)
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, alignCSCRings::s, and y_.

                                                           :
      xMin_(xMin), xMax_(xMax), delta_(xMax - xMin), binSize_(delta_ / (end - begin)), y_(end - begin) {
      double s = 0;
      unsigned int i = 0;
      for(Iterator it = begin; it != end; ++it)
        s += (y_[i++] = *it);
      for(std::vector<double>::iterator i = y_.begin(); i != y_.end(); ++i)
        *i /= s;
    }
funct::HistoPdf::HistoPdf ( ) [inline]

Definition at line 20 of file HistoPdf.h.

{ }

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()(), alignCSCRings::s, x, xMax_, xMin_, detailsBasic3DVector::y, and y_.

                {
      std::cout << ">>> range: [" << xMin_ << ", " << xMax_ << "], bin size: " 
           << delta_ << "/" << y_.size() << " = " << binSize_ << std::endl;
       double s = 0;
      for(unsigned int i = 0; i != y_.size(); ++i) {
        double x = xMin_ + (0.5 + i)*binSize_;
        double y = operator()(x);
        std::cout << ">>> pdf(" << x << ") = " << y << std::endl;
        s+= y*binSize_;
      }
     std::cout << ">>>: PDF normalization is " << s << std::endl;
    }
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, alignCSCRings::s, xMax_, xMin_, and y_.

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

                                                            {
      xMin_ = xMin;
      xMax_ = xMax;
      delta_ = xMax - xMin;
      unsigned int n = end - begin;
      binSize_ = delta_ / n;
      y_.resize(n);
      double s = 0;
      unsigned int i = 0;
      for(Iterator it = begin; it != end; ++it)
        s += (y_[i++] = *it);
      for(std::vector<double>::iterator i = y_.begin(); i != y_.end(); ++i)
        *i /= s;
    }
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().

                                      {
      if (x < xMin_ || x > xMax_) return 0;
      double pdf = y_[static_cast<unsigned int>(((x -xMin_)/delta_)*y_.size())] / binSize_;
      return pdf;
    }
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, alignCSCRings::r, detailsBasic3DVector::y, and y_.

                               {
      if(y_.size() % r != 0) 
        throw edm::Exception(edm::errors::Configuration) <<
          "HistoPdf: can't rebin histogram of " << y_.size() << " entries by " << r << "\n";
      unsigned int n = y_.size() / r;
      std::vector<double> y(n, 0);
      for(unsigned int i = 0, j = 0; i < n; ++i)
        for(unsigned int k = 0; k < r; ++k) 
          y[i] += y_[j++];
      y_ = y;
      binSize_ *= r;
    }

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