69std::vector<std::string> extractArguments(std::string expr)
72 expr.erase(std::remove_if(expr.begin(), expr.end(), [](
unsigned char c) { return std::isspace(c); }), expr.end());
74 std::vector<std::string> arguments;
75 size_t startidx = expr.size();
76 for (
size_t i = 0; i < expr.size(); ++i) {
77 if (startidx >= expr.size()) {
78 if (isalpha(expr[i])) {
82 if (!isdigit(expr[i]) && !isalpha(expr[i]) && expr[i] !=
'_') {
84 startidx = expr.size();
87 std::string arg(expr.substr(startidx, i - startidx));
88 startidx = expr.size();
89 arguments.push_back(arg);
93 if (startidx < expr.size()) {
94 arguments.push_back(expr.substr(startidx));
99template <
class RooArg_t>
105 if (!
p.has_child(
"expression")) {
108 TString formula(
p[
"expression"].val());
110 for (
const auto &
d : extractArguments(formula.Data())) {
113 tool->
wsImport(RooArg_t{
name.c_str(), formula, dependents});
151 obs->GetName() +
"' as indicated by parent RooBinSamplingPdf '" +
name +
155 if (!
p.has_child(
"epsilon")) {
158 double epsilon(
p[
"epsilon"].val_double());
172 bool extended =
false;
173 if (
p.has_child(
"extended") &&
p[
"extended"].val_bool()) {
198 if (!
p.has_child(
"coefficients")) {
205 for (
const auto &coef :
p[
"coefficients"].children()) {
209 if (order == 0 && coef.val() ==
"1.0") {
211 }
else if (coefs.empty() && coef.val() ==
"0.0") {
245 const std::string muName =
p[
"mu"].val();
246 const std::string sigmaName =
p[
"sigma"].val();
247 const bool isTransformed =
endsWith(muName,
"_lognormal_log");
248 const std::string suffixToRemove = isTransformed ?
"_lognormal_log" :
"";
296 const std::string constParamName =
p[
"c"].val();
297 const bool isInverted =
endsWith(constParamName,
"_exponential_inverted");
298 const std::string suffixToRemove = isInverted ?
"_exponential_inverted" :
"";
312 if (!
p.has_child(
"coefficients")) {
319 for (
const auto &coef :
p[
"coefficients"].children()) {
323 if (order == 0 && coef.val() ==
"1.0") {
325 }
else if (coefs.empty() && coef.val() ==
"0.0") {
343 bool has_cov =
p.has_child(
"covariances");
344 bool has_corr =
p.has_child(
"correlations") &&
p.has_child(
"standard_deviations");
345 if (!has_cov && !has_corr) {
352 int n =
p[
"covariances"].num_children();
355 for (
const auto &row :
p[
"covariances"].children()) {
357 for (
const auto &val : row.children()) {
358 covmat(i, j) = val.val_double();
364 std::vector<double> variances;
365 for (
const auto &
v :
p[
"standard_deviations"].children()) {
366 variances.push_back(
v.val_double());
368 covmat.
ResizeTo(variances.size(), variances.size());
370 for (
const auto &row :
p[
"correlations"].children()) {
372 for (
const auto &val : row.children()) {
373 covmat(i, j) = val.val_double() * variances[i] * variances[j];
391 std::string
const &
key()
const override;
395 elem[
"type"] <<
key();
405 std::string
const &
key()
const override;
409 elem[
"type"] <<
key();
419 std::string
const &
key()
const override;
423 elem[
"type"] <<
key();
432 std::string
const &
key()
const override;
436 elem[
"type"] <<
key();
448 if (!
p.has_child(
"data")) {
451 std::unique_ptr<RooDataHist> dataHist =
460 std::string
const &
key()
const override;
464 elem[
"type"] <<
key();
476 if (!
p.has_child(
"data")) {
479 std::unique_ptr<RooDataHist> dataHist =
488 std::string
const &
key()
const override;
492 elem[
"type"] <<
key();
495 elem[
"epsilon"] << pdf->
epsilon();
502 std::string
const &
key()
const override;
506 elem[
"type"] <<
key();
513template <
class RooArg_t>
516 std::string
const &
key()
const override;
519 const RooArg_t *pdf =
static_cast<const RooArg_t *
>(func);
520 elem[
"type"] <<
key();
521 TString expression(pdf->expression());
522 std::vector<std::pair<RooAbsArg *, std::size_t>> paramsWithIndex;
523 paramsWithIndex.reserve(pdf->nParameters());
524 for (
size_t i = 0; i < pdf->nParameters(); ++i) {
525 paramsWithIndex.emplace_back(pdf->getParameter(i), i);
527 std::sort(paramsWithIndex.begin(), paramsWithIndex.end());
528 for (
auto [par, idx] : paramsWithIndex) {
529 expression.ReplaceAll((
"x[" + std::to_string(idx) +
"]").c_str(), par->GetName());
530 expression.ReplaceAll((
"@" + std::to_string(idx)).c_str(), par->GetName());
532 elem[
"expression"] << expression.Data();
539 std::string
const &
key()
const override;
543 elem[
"type"] <<
key();
544 elem[
"x"] << pdf->x().GetName();
545 auto &coefs = elem[
"coefficients"].
set_seq();
549 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
552 for (
const auto &coef : pdf->coefList()) {
561 std::string
const &
key()
const override;
565 elem[
"type"] <<
key();
566 elem[
"x"] << pdf->x().GetName();
567 auto &coefs = elem[
"coefficients"].
set_seq();
571 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
574 for (
const auto &coef : pdf->coefList()) {
583 std::string
const &
key()
const override;
586 auto *pdf =
static_cast<const RooPoisson *
>(func);
587 elem[
"type"] <<
key();
588 elem[
"x"] << pdf->getX().GetName();
589 elem[
"mean"] << pdf->getMean().GetName();
590 elem[
"integer"] << !pdf->getNoRounding();
597 std::string
const &
key()
const override;
602 elem[
"type"] <<
key();
603 elem[
"x"] << pdf->getX().GetName();
605 auto &m0 = pdf->getMedian();
606 auto &k = pdf->getShapeK();
608 if (pdf->useStandardParametrization()) {
609 elem[
"mu"] << m0.GetName();
610 elem[
"sigma"] << k.GetName();
622 std::string
const &
key()
const override;
626 elem[
"type"] <<
key();
627 elem[
"x"] << pdf->variable().GetName();
628 auto &
c = pdf->coefficient();
629 if (pdf->negateCoefficient()) {
630 elem[
"c"] <<
c.GetName();
641 std::string
const &
key()
const override;
645 elem[
"type"] <<
key();
648 elem[
"covariances"].
fill_mat(pdf->covarianceMatrix());
655 std::string
const &
key()
const override;
659 elem[
"type"] <<
key();
661 TString formula(pdf->function().GetExpFormula());
662 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
663 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
664 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
665 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
667 formula.ReplaceAll(pname, pdf->parameters()[i].GetName());
669 elem[
"expression"] << formula.Data();
674#define DEFINE_EXPORTER_KEY(class_name, name) \
675 std::string const &class_name::key() const \
677 const static std::string keystring = name; \
707 registerImporter<RooAddPdfFactory>(
"mixture_dist",
false);
708 registerImporter<RooBinSamplingPdfFactory>(
"binsampling_dist",
false);
709 registerImporter<RooBinWidthFunctionFactory>(
"binwidth",
false);
710 registerImporter<RooLegacyExpPolyFactory>(
"legacy_exp_poly_dist",
false);
711 registerImporter<RooExponentialFactory>(
"exponential_dist",
false);
712 registerImporter<RooFormulaArgFactory<RooFormulaVar>>(
"generic_function",
false);
713 registerImporter<RooFormulaArgFactory<RooGenericPdf>>(
"generic_dist",
false);
714 registerImporter<RooHistFuncFactory>(
"histogram",
false);
715 registerImporter<RooHistPdfFactory>(
"histogram_dist",
false);
716 registerImporter<RooLogNormalFactory>(
"lognormal_dist",
false);
717 registerImporter<RooMultiVarGaussianFactory>(
"multivariate_normal_dist",
false);
718 registerImporter<RooPoissonFactory>(
"poisson_dist",
false);
719 registerImporter<RooPolynomialFactory>(
"polynomial_dist",
false);
720 registerImporter<RooRealSumPdfFactory>(
"weighted_sum_dist",
false);
721 registerImporter<RooRealSumFuncFactory>(
"weighted_sum",
false);
#define DEFINE_EXPORTER_KEY(class_name, name)
bool endsWith(std::string_view str, std::string_view suffix)
std::string removeSuffix(std::string_view str, std::string_view suffix)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
winID h TVirtualViewer3D TVirtualGLPainter p
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value and implements functionality common to al...
Efficient implementation of a sum of PDFs of the form.
const RooArgList & coefList() const
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
const RooArgList & pdfList() const
RooArgList is a container object that can hold multiple RooAbsArg objects.
The RooBinSamplingPdf is supposed to be used as an adapter between a continuous PDF and a binned dist...
const RooAbsPdf & pdf() const
const RooAbsReal & observable() const
Returns the bin width (or volume) given a RooHistFunc.
bool divideByBinWidth() const
const RooHistFunc & histFunc() const
Container class to hold N-dimensional binned data.
double const * weightArray() const
const RooArgSet * get() const override
Get bin centre of current bin.
virtual JSONNode & append_child()=0
virtual JSONNode & set_seq()=0
void fill_mat(Matrix const &mat)
virtual std::string const & key() const =0
virtual bool exportObject(RooJSONFactoryWSTool *, const RooAbsArg *, RooFit::Detail::JSONNode &) const
virtual bool importArg(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
A real-valued function sampled from a multidimensional histogram.
RooDataHist & dataHist()
Return RooDataHist that is represented.
A propability density function sampled from a multidimensional histogram.
RooLegacyExpPoly implements a polynomial PDF of the form.
Multivariate Gaussian p.d.f.
RooPolynomial implements a polynomial p.d.f of the form.
const RooArgList & coefList() const
const RooArgList & funcList() const
Implements a PDF constructed from a sum of functions:
const RooArgList & funcList() const
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
const RooArgList & coefList() const
Variable that can be changed from the outside.
Use TF1, TF2, TF3 functions as RooFit objects.
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
const char * GetName() const override
Returns name of object.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
#define STATIC_EXECUTE(MY_FUNC)