42 template <
class eventListType,
class... pdfTypes>
46 typedef typename eventListType::value_type eventValueType;
47 std::tuple<pdfTypes...> m_pdfs;
48 const eventListType* m_events = {
nullptr};
55 SumPDF(
const pdfTypes&...
pdfs ) : m_pdfs( std::tuple<pdfTypes...>(
pdfs... ) ) {}
61 std::vector<real_v> tmp( m_events->nBlocks() );
64 for(
unsigned block = 0 ; block != tmp.size(); ++block ) sum += tmp[block];
70 for_each( m_pdfs, [](
auto& f ) { f.prepare(); } );
71 if constexpr( std::is_same<eventListType,EventList>::value )
73 #pragma omp parallel for
74 for (
unsigned int i = 0; i < m_events->size(); ++i ) {
75 auto prob = ((*this))(( *m_events)[i] );
76 auto w = (*m_events)[i].weight();
77 output[i] = w * std::log(prob);
81 if constexpr( std::is_same<eventListType, EventListSIMD>::value )
83 #pragma omp parallel for
84 for(
unsigned block = 0 ; block < m_events->nBlocks(); ++block )
86 output[block] = m_events->weight(block) * AVX::log(this->
operator()(
nullptr, block));
96 for_each( this->m_pdfs, [&prob, &evt, block](
const auto& f )
mutable { prob += f(evt, block); } );
103 for_each( this->m_pdfs, [&prob, &evt](
const auto& f )
mutable { prob += f(evt); } );
111 for_each( m_pdfs, [&events](
auto& f ) { f.setEvents( events ); } );
115 std::size_t
nPDFs()
const {
return sizeof...(pdfTypes); }
118 std::tuple<pdfTypes...>
pdfs()
const {
return m_pdfs; }
120 std::function<double(
const eventValueType&)>
evaluator(
const eventListType* events)
const
122 std::vector<double> values( events->size() );
123 for_each( this->m_pdfs, [events, &values](
const auto& pdf )
mutable {
124 auto eval = pdf.evaluator(events);
125 for(
unsigned i = 0; i != events->size(); ++i ) values[i] += eval( events->at(i) );
132 for_each( this->m_pdfs, [&view, &events](
const auto& pdf)
mutable {
133 auto eval = pdf.evaluator(events);
134 view.add([eval](
const auto& event){
return eval(event) ; } ,
type_string(pdf),
"" );
150 template <
class eventListType = EventList,
class... pdfTypes>
154 return SumPDF<eventListType, pdfTypes...>( pdfs... );
157 template <
class eventListType = EventList,
class... pdfTypes>
160 auto rt =
SumPDF<eventListType, pdfTypes...>( std::forward<pdfTypes>( pdfs )... );
A pdf that contains one or more terms.
void setEvents(eventListType &events)
Sets the events to be summed over in the likelihood.
double getVal()
Returns negative twice the log-likelihood for this PDF and the given dataset.
real_v operator()(const real_v *evt, const unsigned block)
Returns the probability for the given event.
std::function< double(const eventValueType &)> evaluator(const eventListType *events) const
std::tuple< pdfTypes... > pdfs() const
Returns the tuple of PDFs used by this function.
SumPDF(const pdfTypes &... pdfs)
Constructor from a set of PDF functions.
std::size_t nPDFs() const
Returns the number of PDFs contained by this function.
SumPDF()=default
Default Constructor.
double operator()(const eventValueType &evt)
Returns the probability for the given event.
KeyedFunctors< double(eventValueType)> componentEvaluator(const eventListType *events) const
void fill_likelihood(real_v *output)
auto sum_elements(const simd_type &obj)
std::function< return_type(const contained_type &)> arrayToFunctor(const std::vector< return_type > &values)
std::string type_string()
Utility classes for compile-time metaprogramming, such as identifying the types of arguments for gene...
auto make_likelihood(eventListType &events, pdfTypes &&... pdfs)
std::enable_if_t< I==sizeof...(Tp), void > for_each(std::tuple< Tp... > &, FuncT)
PDFWrapper< FCN > make_pdf(const FCN &fcn)
Implements Kahan summation for better precision with (repeated) floating point addition.