Changeset View
Changeset View
Standalone View
Standalone View
EvtGenBase/EvtPdf.hh
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
class EvtPdfPred; | class EvtPdfPred; | ||||
template <class T> | template <class T> | ||||
class EvtPdfGen; | class EvtPdfGen; | ||||
template <class T> | template <class T> | ||||
class EvtPdf { | class EvtPdf { | ||||
public: | public: | ||||
EvtPdf() {} | EvtPdf() {} | ||||
EvtPdf( const EvtPdf& other ) : _itg( other._itg ) {} | EvtPdf( const EvtPdf& other ) : m_itg( other.m_itg ) {} | ||||
virtual ~EvtPdf() {} | virtual ~EvtPdf() {} | ||||
virtual EvtPdf<T>* clone() const = 0; | virtual EvtPdf<T>* clone() const = 0; | ||||
double evaluate( const T& p ) const | double evaluate( const T& p ) const | ||||
{ | { | ||||
if ( p.isValid() ) | if ( p.isValid() ) | ||||
return pdf( p ); | return pdf( p ); | ||||
else | else | ||||
return 0.; | return 0.; | ||||
} | } | ||||
// Find PDF maximum. Points are sampled according to pc | // Find PDF maximum. Points are sampled according to pc | ||||
EvtPdfMax<T> findMax( const EvtPdf<T>& pc, int N ); | EvtPdfMax<T> findMax( const EvtPdf<T>& pc, int N ); | ||||
// Find generation efficiency. | // Find generation efficiency. | ||||
EvtValError findGenEff( const EvtPdf<T>& pc, int N, int nFindMax ); | EvtValError findGenEff( const EvtPdf<T>& pc, int N, int nFindMax ); | ||||
// Analytic integration. Calls cascade down until an overridden | // Analytic integration. Calls cascade down until an overridden | ||||
// method is called. | // method is called. | ||||
void setItg( EvtValError itg ) { _itg = itg; } | void setItg( EvtValError itg ) { m_itg = itg; } | ||||
EvtValError getItg() const | EvtValError getItg() const | ||||
{ | { | ||||
if ( !_itg.valueKnown() ) | if ( !m_itg.valueKnown() ) | ||||
_itg = compute_integral(); | m_itg = compute_integral(); | ||||
return _itg; | return m_itg; | ||||
} | } | ||||
EvtValError getItg( int N ) const | EvtValError getItg( int N ) const | ||||
{ | { | ||||
if ( !_itg.valueKnown() ) | if ( !m_itg.valueKnown() ) | ||||
_itg = compute_integral( N ); | m_itg = compute_integral( N ); | ||||
return _itg; | return m_itg; | ||||
} | } | ||||
virtual EvtValError compute_integral() const | virtual EvtValError compute_integral() const | ||||
{ | { | ||||
printf( "Analytic integration of PDF is not defined\n" ); | printf( "Analytic integration of PDF is not defined\n" ); | ||||
assert( 0 ); | assert( 0 ); | ||||
return EvtValError{}; | return EvtValError{}; | ||||
} | } | ||||
Show All 12 Lines | public: | ||||
EvtPredGen<EvtPdfGen<T>, EvtPdfPred<T>> accRejGen( const EvtPdf<T>& pc, | EvtPredGen<EvtPdfGen<T>, EvtPdfPred<T>> accRejGen( const EvtPdf<T>& pc, | ||||
int nMax, | int nMax, | ||||
double factor = 1. ); | double factor = 1. ); | ||||
virtual T randomPoint(); | virtual T randomPoint(); | ||||
protected: | protected: | ||||
virtual double pdf( const T& ) const = 0; | virtual double pdf( const T& ) const = 0; | ||||
mutable EvtValError _itg; | mutable EvtValError m_itg; | ||||
}; | }; | ||||
template <class T> | template <class T> | ||||
class EvtPdfGen { | class EvtPdfGen { | ||||
public: | public: | ||||
typedef T result_type; | typedef T result_type; | ||||
EvtPdfGen() : _pdf( 0 ) {} | EvtPdfGen() : m_pdf( 0 ) {} | ||||
EvtPdfGen( const EvtPdfGen<T>& other ) : | EvtPdfGen( const EvtPdfGen<T>& other ) : | ||||
_pdf( other._pdf ? other._pdf->clone() : 0 ) | m_pdf( other.m_pdf ? other.m_pdf->clone() : 0 ) | ||||
{ | { | ||||
} | } | ||||
EvtPdfGen( const EvtPdf<T>& pdf ) : _pdf( pdf.clone() ) {} | EvtPdfGen( const EvtPdf<T>& pdf ) : m_pdf( pdf.clone() ) {} | ||||
~EvtPdfGen() { delete _pdf; } | ~EvtPdfGen() { delete m_pdf; } | ||||
result_type operator()() { return _pdf->randomPoint(); } | result_type operator()() { return m_pdf->randomPoint(); } | ||||
private: | private: | ||||
EvtPdf<T>* _pdf; | EvtPdf<T>* m_pdf; | ||||
}; | }; | ||||
template <class T> | template <class T> | ||||
class EvtPdfPred { | class EvtPdfPred { | ||||
public: | public: | ||||
typedef T argument_type; | typedef T argument_type; | ||||
typedef bool result_type; | typedef bool result_type; | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | if ( N > 0 ) { | ||||
// Due to numerical precision dev2 may sometimes be negative | // Due to numerical precision dev2 may sometimes be negative | ||||
if ( dev2 < 0. ) | if ( dev2 < 0. ) | ||||
dev2 = 0.; | dev2 = 0.; | ||||
double error = sqrt( dev2 / ( (double)N ) ); | double error = sqrt( dev2 / ( (double)N ) ); | ||||
x = EvtValError( av, error ); | x = EvtValError( av, error ); | ||||
} else | } else | ||||
x = EvtValError( av ); | x = EvtValError( av ); | ||||
} | } | ||||
_itg = x * pc.getItg(); | m_itg = x * pc.getItg(); | ||||
return _itg; | return m_itg; | ||||
} | } | ||||
template <class T> | template <class T> | ||||
T EvtPdf<T>::randomPoint() | T EvtPdf<T>::randomPoint() | ||||
{ | { | ||||
printf( "Function defined for analytic PDFs only\n" ); | printf( "Function defined for analytic PDFs only\n" ); | ||||
assert( 0 ); | assert( 0 ); | ||||
T temp; | T temp; | ||||
Show All 16 Lines |