Public Member Functions | Public Attributes | List of all members
Pdf Struct Reference
Inheritance diagram for Pdf:

Public Member Functions

 Pdf (IRandom::pointer rng, const std::vector< double > &pdf, const std::vector< double > &edges)
 
double operator() ()
 

Public Attributes

IRandom::pointer rng
 
std::vector< double > cumulative
 
std::vector< double > edges
 
double total
 

Detailed Description

Definition at line 86 of file BlipSource.cxx.

Constructor & Destructor Documentation

Pdf::Pdf ( IRandom::pointer  rng,
const std::vector< double > &  pdf,
const std::vector< double > &  edges 
)
inline

Definition at line 91 of file BlipSource.cxx.

92  : rng(rng), edges(edges.begin(), edges.end()) {
93  total = 0.0;
94  cumulative.push_back(0.0);
95  for (double val : pdf) {
96  total += val;
97  cumulative.push_back(total);
98  }
99  }
std::vector< double > cumulative
Definition: BlipSource.cxx:88
std::vector< double > edges
Definition: BlipSource.cxx:89
double total
Definition: BlipSource.cxx:90
IRandom::pointer rng
Definition: BlipSource.cxx:87

Member Function Documentation

double Pdf::operator() ( void  )
inline

Definition at line 100 of file BlipSource.cxx.

100  {
101  double cp = rng->uniform(0.0, total);
102  for (size_t ind=1; ind<cumulative.size(); ++ind) { // start at 2nd element
103  if (cumulative[ind] >= cp) {
104  double rel = (cp - cumulative[ind-1]) / (cumulative[ind]-cumulative[ind-1]);
105  return edges[ind-1] + rel*(edges[ind] - edges[ind-1]);
106  }
107  }
108  return -1; // should not happen
109  }
std::vector< double > cumulative
Definition: BlipSource.cxx:88
std::vector< double > edges
Definition: BlipSource.cxx:89
double total
Definition: BlipSource.cxx:90
IRandom::pointer rng
Definition: BlipSource.cxx:87

Member Data Documentation

std::vector<double> Pdf::cumulative

Definition at line 88 of file BlipSource.cxx.

std::vector<double> Pdf::edges

Definition at line 89 of file BlipSource.cxx.

IRandom::pointer Pdf::rng

Definition at line 87 of file BlipSource.cxx.

double Pdf::total

Definition at line 90 of file BlipSource.cxx.


The documentation for this struct was generated from the following file: