Skip to content

Commit

Permalink
[RF] Implement code generation support for RooProdPdf
Browse files Browse the repository at this point in the history
Also, simplify the code generation for RooProduct.
  • Loading branch information
guitargeek committed Jul 9, 2024
1 parent 7d899a5 commit cc9d9b1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
9 changes: 9 additions & 0 deletions roofit/roofitcore/inc/RooFit/Detail/MathFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ inline double gaussian(double x, double mean, double sigma)
return std::exp(-0.5 * arg * arg / (sig * sig));
}

inline double product(double const *factors, std::size_t nFactors)
{
double out = 1.0;
for (std::size_t i = 0; i < nFactors; ++i) {
out *= factors[i];
}
return out;
}

// RooRatio evaluate function.
inline double ratio(double numerator, double denominator)
{
Expand Down
9 changes: 9 additions & 0 deletions roofit/roofitcore/src/RooProdPdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,15 @@ class RooFixedProdPdf : public RooAbsPdf {
_prodPdf->doEvalImpl(this, *_cache, ctx);
}

void translate(RooFit::Detail::CodeSquashContext &ctx) const override
{
if (_cache->_isRearranged) {
ctx.addResult(this, ctx.buildCall("RooFit::Detail::MathFuncs::ratio", *_cache->_rearrangedNum, *_cache->_rearrangedDen));
} else {
ctx.addResult(this, ctx.buildCall("RooFit::Detail::MathFuncs::product", _cache->_partList, _cache->_partList.size()));
}
}

ExtendMode extendMode() const override { return _prodPdf->extendMode(); }
double expectedEvents(const RooArgSet * /*nset*/) const override { return _prodPdf->expectedEvents(&_normSet); }
std::unique_ptr<RooAbsReal> createExpectedEventsFunc(const RooArgSet * /*nset*/) const override
Expand Down
12 changes: 1 addition & 11 deletions roofit/roofitcore/src/RooProduct.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,7 @@ void RooProduct::setCacheAndTrackHints(RooArgSet& trackNodes)

void RooProduct::translate(RooFit::Detail::CodeSquashContext &ctx) const
{
std::string result;
// Build a (node1 * node2 * node3 * ...) like expression.
result = '(';
for (RooAbsArg* item : _compRSet) {
RooConstVar *constItem = dynamic_cast<RooConstVar *>(item);
if (constItem && constItem->getValV(nullptr) == 1)
continue;
result += ctx.getResult(*item) + "*";
}
result.back() = ')';
ctx.addResult(this, result);
ctx.addResult(this, ctx.buildCall("RooFit::Detail::MathFuncs::product", _compRSet, _compRSet.size()));
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion roofit/roofitcore/test/testRooFuncWrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <RooMinimizer.h>
#include <RooPoisson.h>
#include <RooPolynomial.h>
#include <RooProduct.h>
#include <RooRealSumPdf.h>
#include <RooRealVar.h>
#include <RooSimultaneous.h>
Expand Down

0 comments on commit cc9d9b1

Please sign in to comment.