23 TUnuranDiscrDist::TUnuranDiscrDist (
const ROOT::Math::IGenFunction & func,
bool copyFunc) :
43 TUnuranDiscrDist::TUnuranDiscrDist (TF1 * func) :
44 fPmf( (func) ? new ROOT::Math::WrappedTF1 ( *func) : 0 ),
59 TUnuranDiscrDist::TUnuranDiscrDist(
const TUnuranDiscrDist & rhs) :
68 TUnuranDiscrDist & TUnuranDiscrDist::operator = (
const TUnuranDiscrDist &rhs)
71 if (
this == &rhs)
return *
this;
73 fPVecSum = rhs.fPVecSum;
78 fHasDomain = rhs.fHasDomain;
79 fHasMode = rhs.fHasMode;
80 fHasSum = rhs.fHasSum;
81 fOwnFunc = rhs.fOwnFunc;
87 if (fPmf)
delete fPmf;
88 if (fCdf)
delete fCdf;
89 fPmf = (rhs.fPmf) ? rhs.fPmf->Clone() : 0;
90 fCdf = (rhs.fCdf) ? rhs.fCdf->Clone() : 0;
96 TUnuranDiscrDist::~TUnuranDiscrDist() {
99 if (fPmf)
delete fPmf;
100 if (fCdf)
delete fCdf;
104 void TUnuranDiscrDist::SetCdf(
const ROOT::Math::IGenFunction & cdf) {
106 fCdf = (fOwnFunc) ? cdf.Clone() : &cdf;
109 void TUnuranDiscrDist::SetCdf(TF1 * cdf) {
111 if (!fOwnFunc && fPmf) {
113 fPmf = fPmf->Clone();
116 if (fCdf)
delete fCdf;
118 fCdf = (cdf) ?
new ROOT::Math::WrappedTF1 ( *cdf) : 0;
122 double TUnuranDiscrDist::Pmf (
int x)
const {
125 if (x < static_cast<int>(fPVec.size()) || x >= static_cast<int>(fPVec.size()) )
return 0;
128 return (*fPmf)(double(x));
131 double TUnuranDiscrDist::Cdf (
int x)
const {
134 if (fHasDomain && x < fXmin)
return 0;
137 return (*fCdf)(double(x));
141 int vsize = fPVecSum.size();
146 int x0 = ( fHasDomain) ? fXmin : 0;
150 double sum = ( i0 > 0 ) ? fPVecSum.back() : 0;
151 for (
int i = i0; i < iN; ++i) {
156 return fPVecSum.back();