70std::vector<std::string> extractArguments(std::string expr)
73 expr.erase(std::remove_if(expr.begin(), expr.end(), [](
unsigned char c) { return std::isspace(c); }), expr.end());
75 std::vector<std::string> arguments;
76 size_t startidx = expr.size();
77 for (
size_t i = 0; i < expr.size(); ++i) {
78 if (startidx >= expr.size()) {
79 if (isalpha(expr[i])) {
83 if (!isdigit(expr[i]) && !isalpha(expr[i]) && expr[i] !=
'_') {
85 startidx = expr.size();
88 std::string arg(expr.substr(startidx, i - startidx));
89 startidx = expr.size();
90 arguments.push_back(arg);
94 if (startidx < expr.size()) {
95 arguments.push_back(expr.substr(startidx));
100template <
class RooArg_t>
106 if (!
p.has_child(
"expression")) {
109 TString formula(
p[
"expression"].val());
111 for (
const auto &
d : extractArguments(formula.Data())) {
114 tool->
wsImport(RooArg_t{
name.c_str(), formula, dependents});
152 obs->GetName() +
"' as indicated by parent RooBinSamplingPdf '" +
name +
156 if (!
p.has_child(
"epsilon")) {
159 double epsilon(
p[
"epsilon"].val_double());
173 bool extended =
false;
174 if (
p.has_child(
"extended") &&
p[
"extended"].val_bool()) {
199 if (!
p.has_child(
"coefficients")) {
206 for (
const auto &coef :
p[
"coefficients"].children()) {
210 if (order == 0 && coef.val() ==
"1.0") {
212 }
else if (coefs.empty() && coef.val() ==
"0.0") {
246 if (
p.has_child(
"normalization")) {
248 normSetPtr = &normSet;
251 bool hasDomain =
p.has_child(
"domain");
253 domain =
p[
"domain"].val();
257 hasDomain ? domain.c_str() :
nullptr);
271 const std::string muName =
p[
"mu"].val();
272 const std::string sigmaName =
p[
"sigma"].val();
273 const bool isTransformed =
endsWith(muName,
"_lognormal_log");
274 const std::string suffixToRemove = isTransformed ?
"_lognormal_log" :
"";
322 const std::string constParamName =
p[
"c"].val();
323 const bool isInverted =
endsWith(constParamName,
"_exponential_inverted");
324 const std::string suffixToRemove = isInverted ?
"_exponential_inverted" :
"";
338 if (!
p.has_child(
"coefficients")) {
345 for (
const auto &coef :
p[
"coefficients"].children()) {
349 if (order == 0 && coef.val() ==
"1.0") {
351 }
else if (coefs.empty() && coef.val() ==
"0.0") {
369 bool has_cov =
p.has_child(
"covariances");
370 bool has_corr =
p.has_child(
"correlations") &&
p.has_child(
"standard_deviations");
371 if (!has_cov && !has_corr) {
378 int n =
p[
"covariances"].num_children();
381 for (
const auto &row :
p[
"covariances"].children()) {
383 for (
const auto &val : row.children()) {
384 covmat(i, j) = val.val_double();
390 std::vector<double> variances;
391 for (
const auto &
v :
p[
"standard_deviations"].children()) {
392 variances.push_back(
v.val_double());
394 covmat.
ResizeTo(variances.size(), variances.size());
396 for (
const auto &row :
p[
"correlations"].children()) {
398 for (
const auto &val : row.children()) {
399 covmat(i, j) = val.val_double() * variances[i] * variances[j];
417 std::string
const &
key()
const override;
421 elem[
"type"] <<
key();
431 std::string
const &
key()
const override;
435 elem[
"type"] <<
key();
445 std::string
const &
key()
const override;
449 elem[
"type"] <<
key();
458 std::string
const &
key()
const override;
462 elem[
"type"] <<
key();
474 if (!
p.has_child(
"data")) {
477 std::unique_ptr<RooDataHist> dataHist =
486 std::string
const &
key()
const override;
490 elem[
"type"] <<
key();
502 if (!
p.has_child(
"data")) {
505 std::unique_ptr<RooDataHist> dataHist =
514 std::string
const &
key()
const override;
518 elem[
"type"] <<
key();
521 elem[
"epsilon"] << pdf->
epsilon();
528 std::string
const &
key()
const override;
532 elem[
"type"] <<
key();
539template <
class RooArg_t>
542 std::string
const &
key()
const override;
545 const RooArg_t *pdf =
static_cast<const RooArg_t *
>(func);
546 elem[
"type"] <<
key();
547 TString expression(pdf->expression());
548 std::vector<std::pair<RooAbsArg *, std::size_t>> paramsWithIndex;
549 paramsWithIndex.reserve(pdf->nParameters());
550 for (
size_t i = 0; i < pdf->nParameters(); ++i) {
551 paramsWithIndex.emplace_back(pdf->getParameter(i), i);
553 std::sort(paramsWithIndex.begin(), paramsWithIndex.end());
556 for (
auto [par, idx] : paramsWithIndex) {
557 expression.ReplaceAll((
"x[" + std::to_string(idx) +
"]").c_str(), par->GetName());
564 for (
auto it = paramsWithIndex.rbegin(); it != paramsWithIndex.rend(); ++it) {
566 std::size_t idx = it->second;
567 expression.ReplaceAll((
"@" + std::to_string(idx)).c_str(), par->
GetName());
569 elem[
"expression"] << expression.Data();
576 std::string
const &
key()
const override;
580 elem[
"type"] <<
key();
581 elem[
"x"] << pdf->x().GetName();
582 auto &coefs = elem[
"coefficients"].
set_seq();
586 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
589 for (
const auto &coef : pdf->coefList()) {
598 std::string
const &
key()
const override;
602 elem[
"type"] <<
key();
603 elem[
"x"] << pdf->x().GetName();
604 auto &coefs = elem[
"coefficients"].
set_seq();
608 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
611 for (
const auto &coef : pdf->coefList()) {
620 std::string
const &
key()
const override;
623 auto *pdf =
static_cast<const RooPoisson *
>(func);
624 elem[
"type"] <<
key();
625 elem[
"x"] << pdf->getX().GetName();
626 elem[
"mean"] << pdf->getMean().GetName();
627 elem[
"integer"] << !pdf->getNoRounding();
634 std::string
const &
key()
const override;
639 elem[
"type"] <<
key();
640 elem[
"x"] << pdf->getX().GetName();
642 auto &m0 = pdf->getMedian();
643 auto &k = pdf->getShapeK();
645 if (pdf->useStandardParametrization()) {
646 elem[
"mu"] << m0.GetName();
647 elem[
"sigma"] << k.GetName();
659 std::string
const &
key()
const override;
663 elem[
"type"] <<
key();
664 elem[
"x"] << pdf->variable().GetName();
665 auto &
c = pdf->coefficient();
666 if (pdf->negateCoefficient()) {
667 elem[
"c"] <<
c.GetName();
678 std::string
const &
key()
const override;
682 elem[
"type"] <<
key();
685 elem[
"covariances"].
fill_mat(pdf->covarianceMatrix());
692 std::string
const &
key()
const override;
696 elem[
"type"] <<
key();
698 TString formula(pdf->function().GetExpFormula());
699 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
700 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
701 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
702 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
704 formula.ReplaceAll(pname, pdf->parameters()[i].GetName());
706 elem[
"expression"] << formula.Data();
713 std::string
const &
key()
const override;
717 elem[
"type"] <<
key();
718 elem[
"integrand"] << integral->integrand().GetName();
719 if (integral->intRange()) {
720 elem[
"domain"] << integral->intRange();
723 if (
RooArgSet const *funcNormSet = integral->funcNormSet()) {
730#define DEFINE_EXPORTER_KEY(class_name, name) \
731 std::string const &class_name::key() const \
733 const static std::string keystring = name; \
764 registerImporter<RooAddPdfFactory>(
"mixture_dist",
false);
765 registerImporter<RooBinSamplingPdfFactory>(
"binsampling_dist",
false);
766 registerImporter<RooBinWidthFunctionFactory>(
"binwidth",
false);
767 registerImporter<RooLegacyExpPolyFactory>(
"legacy_exp_poly_dist",
false);
768 registerImporter<RooExponentialFactory>(
"exponential_dist",
false);
769 registerImporter<RooFormulaArgFactory<RooFormulaVar>>(
"generic_function",
false);
770 registerImporter<RooFormulaArgFactory<RooGenericPdf>>(
"generic_dist",
false);
771 registerImporter<RooHistFuncFactory>(
"histogram",
false);
772 registerImporter<RooHistPdfFactory>(
"histogram_dist",
false);
773 registerImporter<RooLogNormalFactory>(
"lognormal_dist",
false);
774 registerImporter<RooMultiVarGaussianFactory>(
"multivariate_normal_dist",
false);
775 registerImporter<RooPoissonFactory>(
"poisson_dist",
false);
776 registerImporter<RooPolynomialFactory>(
"polynomial_dist",
false);
777 registerImporter<RooRealSumPdfFactory>(
"weighted_sum_dist",
false);
778 registerImporter<RooRealSumFuncFactory>(
"weighted_sum",
false);
779 registerImporter<RooRealIntegralFactory>(
"integral",
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.
RooArgSet 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.
Holds the configuration parameters of the various numeric integrators used by RooRealIntegral.
RooPolynomial implements a polynomial p.d.f of the form.
Performs hybrid numerical/analytical integrals of RooAbsReal objects.
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)