47 #include "EvtGenBase/EvtValError.hh"
48 #include "EvtGenBase/EvtPredGen.hh"
49 #include "EvtGenBase/EvtStreamInputIterator.hh"
50 #include "EvtGenBase/EvtPdfMax.hh"
51 #include "EvtGenBase/EvtMacros.hh"
52 #include "EvtGenBase/EvtRandom.hh"
65 double evaluate(
const T& p)
const {
66 if(p.isValid())
return pdf(p);
84 if(!_itg.valueKnown()) _itg = compute_integral();
88 if(!_itg.valueKnown()) _itg = compute_integral(N);
94 { printf(
"Analytic integration of PDF is not defined\n"); assert(0);
return compute_integral();}
95 virtual EvtValError compute_integral(
int)
const {
return compute_integral(); }
106 virtual T randomPoint();
110 virtual double pdf(
const T&)
const = 0;
117 typedef T result_type;
121 _pdf(other._pdf ? other._pdf->clone() : 0)
128 result_type operator()() {
return _pdf->randomPoint();}
138 typedef T argument_type;
139 typedef bool result_type;
146 result_type operator()(argument_type p)
149 assert(itsPdfMax.valueKnown());
151 double random = EvtRandom::Flat(0.,itsPdfMax.value());
152 return (random <= itsPdf->evaluate(p));
156 void setMax(
const EvtPdfMax<T>& max) { itsPdfMax = max; }
157 template <
class InputIterator>
void compute_max(InputIterator it, InputIterator end,
163 while(!(it == end)) {
165 double val = itsPdf->evaluate(p)*factor;
166 if(val > itsPdfMax.value()) itsPdfMax =
EvtPdfMax<T>(p,val);
179 typedef double result_type;
180 typedef T argument_type;
187 result_type operator()(argument_type p)
190 double ret = itsPdf->evaluate(p);
205 :
EvtPdf<T>(), itsNum(theNum.clone()), itsDen(theDen.clone())
208 :
EvtPdf<T>(other), COPY_PTR(itsNum), COPY_PTR(itsDen)
210 virtual ~
EvtPdfDiv() {
delete itsNum;
delete itsDen; }
214 virtual double pdf(
const T& p)
const
216 double num = itsNum->evaluate(p);
217 double den = itsDen->evaluate(p);
234 pred.compute_max(iter(gen,N),iter(gen));
243 assert(N > 0 || nFindMax > 0);
246 for(i=0;i<N;i++) gen();
247 double eff = double(gen.getPassed())/
double(gen.getTried());
248 double err = sqrt(
double(gen.getPassed()))/double(gen.getTried());
267 while(!(begin == end)) {
269 double value = pdfdiv.evaluate(*begin++);
276 double av = sum/((double) N);
278 double dev2 = (sum2 - av*av*N)/((
double) (N - 1));
280 if(dev2 < 0.) dev2 = 0.;
281 double error = sqrt(dev2/((
double) N));
286 _itg = x * pc.getItg();
293 printf(
"Function defined for analytic PDFs only\n");
306 pred.compute_max(iter(gen,nMax),iter(gen),factor);