CMS 3D CMS Logo

funct::HistoPdf Class Reference

#include <PhysicsTools/Utilities/interface/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 i, it, s, and y_.

00011                                                            :
00012       xMin_(xMin), xMax_(xMax), delta_(xMax - xMin), binSize_(delta_ / (end - begin)), y_(end - begin) {
00013       double s = 0;
00014       unsigned int i = 0;
00015       for(Iterator it = begin; it != end; ++it)
00016         s += (y_[i++] = *it);
00017       for(std::vector<double>::iterator i = y_.begin(); i != y_.end(); ++i)
00018         *i /= s;
00019     }
    HistoPdf() { }

funct::HistoPdf::HistoPdf (  )  [inline]

Definition at line 20 of file HistoPdf.h.

00020 { }


Member Function Documentation

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

Definition at line 54 of file HistoPdf.h.

References binSize_, GenMuonPlsPt100GeV_cfg::cout, delta_, lat::endl(), i, operator()(), s, x, xMax_, xMin_, y, and y_.

00054                 {
00055       std::cout << ">>> range: [" << xMin_ << ", " << xMax_ << "], bin size: " 
00056            << delta_ << "/" << y_.size() << " = " << binSize_ << std::endl;
00057        double s = 0;
00058       for(unsigned int i = 0; i != y_.size(); ++i) {
00059         double x = xMin_ + (0.5 + i)*binSize_;
00060         double y = operator()(x);
00061         std::cout << ">>> pdf(" << x << ") = " << y << std::endl;
00062         s+= y*binSize_;
00063       }
00064      std::cout << ">>>: PDF normalization is " << s << std::endl;
00065     }

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 binSize_, delta_, i, it, n, s, xMax_, xMin_, and y_.

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

00023                                                             {
00024       xMin_ = xMin;
00025       xMax_ = xMax;
00026       delta_ = xMax - xMin;
00027       unsigned int n = end - begin;
00028       binSize_ = delta_ / n;
00029       y_.resize(n);
00030       double s = 0;
00031       unsigned int i = 0;
00032       for(Iterator it = begin; it != end; ++it)
00033         s += (y_[i++] = *it);
00034       for(std::vector<double>::iterator i = y_.begin(); i != y_.end(); ++i)
00035         *i /= s;
00036     }

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

00037                                       {
00038       if (x < xMin_ || x > xMax_) return 0;
00039       double pdf = y_[static_cast<unsigned int>(((x -xMin_)/delta_)*y_.size())] / binSize_;
00040       return pdf;
00041     }

void funct::HistoPdf::rebin ( unsigned int  r  )  [inline]

Definition at line 42 of file HistoPdf.h.

References binSize_, edm::errors::Configuration, i, j, k, n, y, and y_.

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


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


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:47:02 2009 for CMSSW by  doxygen 1.5.4