1 #ifndef PhysicsTools_Utilities_HistoPdf_h
2 #define PhysicsTools_Utilities_HistoPdf_h
9 template<
typename Iterator>
17 for(std::vector<double>::iterator i =
y_.begin(); i !=
y_.end(); ++
i)
21 template<
typename Iterator>
22 void init(
double xMin,
double xMax,
27 unsigned int n = end -
begin;
34 for(std::vector<double>::iterator i =
y_.begin(); i !=
y_.end(); ++
i)
38 if (x < xMin_ || x >
xMax_)
return 0;
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)
58 for(
unsigned int i = 0;
i !=
y_.size(); ++
i) {
61 std::cout <<
">>> pdf(" << x <<
") = " << y << std::endl;
64 std::cout <<
">>>: PDF normalization is " << s << std::endl;
68 std::vector<double>
y_;
74 unsigned int nBins = histo.GetNbinsX();
75 std::vector<double> y;
77 double xMin = histo.GetXaxis()->GetXmin();
78 double xMax = histo.GetXaxis()->GetXmax();
79 double deltaX =(xMax - xMin) / nBins;
80 for(
unsigned int i = 0;
i != nBins; ++
i) {
81 double x = xMin + (
i + .5) * deltaX;
82 if(x > fMin && x < fMax) {
83 y.push_back(histo.GetBinContent(
i+1));
86 init(fMin, fMax, y.begin(), y.end());
HistoPdf(double xMin, double xMax, const Iterator &begin, const Iterator &end)
RootHistoPdf(const TH1 &histo, double fMin, double fMax)
double operator()(double x) const
void init(double xMin, double xMax, const Iterator &begin, const Iterator &end)
T x() const
Cartesian x coordinate.
void rebin(unsigned int r)