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());
554 for (
size_t idx = pdf->nParameters(); idx--;) {
555 const RooAbsArg *par = pdf->getParameter(idx);
556 expression.ReplaceAll((
"x[" + std::to_string(idx) +
"]").c_str(), par->
GetName());
557 expression.ReplaceAll((
"@" + std::to_string(idx)).c_str(), par->
GetName());
559 elem[
"expression"] << expression.Data();
566 std::string
const &
key()
const override;
570 elem[
"type"] <<
key();
571 elem[
"x"] << pdf->x().GetName();
572 auto &coefs = elem[
"coefficients"].
set_seq();
576 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
579 for (
const auto &coef : pdf->coefList()) {
588 std::string
const &
key()
const override;
592 elem[
"type"] <<
key();
593 elem[
"x"] << pdf->x().GetName();
594 auto &coefs = elem[
"coefficients"].
set_seq();
598 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
601 for (
const auto &coef : pdf->coefList()) {
610 std::string
const &
key()
const override;
613 auto *pdf =
static_cast<const RooPoisson *
>(func);
614 elem[
"type"] <<
key();
615 elem[
"x"] << pdf->getX().GetName();
616 elem[
"mean"] << pdf->getMean().GetName();
617 elem[
"integer"] << !pdf->getNoRounding();
624 std::string
const &
key()
const override;
629 elem[
"type"] <<
key();
630 elem[
"x"] << pdf->getX().GetName();
632 auto &m0 = pdf->getMedian();
633 auto &k = pdf->getShapeK();
635 if (pdf->useStandardParametrization()) {
636 elem[
"mu"] << m0.GetName();
637 elem[
"sigma"] << k.GetName();
649 std::string
const &
key()
const override;
653 elem[
"type"] <<
key();
654 elem[
"x"] << pdf->variable().GetName();
655 auto &
c = pdf->coefficient();
656 if (pdf->negateCoefficient()) {
657 elem[
"c"] <<
c.GetName();
668 std::string
const &
key()
const override;
672 elem[
"type"] <<
key();
675 elem[
"covariances"].
fill_mat(pdf->covarianceMatrix());
682 std::string
const &
key()
const override;
686 elem[
"type"] <<
key();
688 TString formula(pdf->function().GetExpFormula());
689 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
690 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
691 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
692 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
694 formula.ReplaceAll(pname, pdf->parameters()[i].GetName());
696 elem[
"expression"] << formula.Data();
703 std::string
const &
key()
const override;
707 elem[
"type"] <<
key();
708 elem[
"integrand"] << integral->integrand().GetName();
709 if (integral->intRange()) {
710 elem[
"domain"] << integral->intRange();
713 if (
RooArgSet const *funcNormSet = integral->funcNormSet()) {
720#define DEFINE_EXPORTER_KEY(class_name, name) \
721 std::string const &class_name::key() const \
723 const static std::string keystring = name; \
754 registerImporter<RooAddPdfFactory>(
"mixture_dist",
false);
755 registerImporter<RooBinSamplingPdfFactory>(
"binsampling_dist",
false);
756 registerImporter<RooBinWidthFunctionFactory>(
"binwidth",
false);
757 registerImporter<RooLegacyExpPolyFactory>(
"legacy_exp_poly_dist",
false);
758 registerImporter<RooExponentialFactory>(
"exponential_dist",
false);
759 registerImporter<RooFormulaArgFactory<RooFormulaVar>>(
"generic_function",
false);
760 registerImporter<RooFormulaArgFactory<RooGenericPdf>>(
"generic_dist",
false);
761 registerImporter<RooHistFuncFactory>(
"histogram",
false);
762 registerImporter<RooHistPdfFactory>(
"histogram_dist",
false);
763 registerImporter<RooLogNormalFactory>(
"lognormal_dist",
false);
764 registerImporter<RooMultiVarGaussianFactory>(
"multivariate_normal_dist",
false);
765 registerImporter<RooPoissonFactory>(
"poisson_dist",
false);
766 registerImporter<RooPolynomialFactory>(
"polynomial_dist",
false);
767 registerImporter<RooRealSumPdfFactory>(
"weighted_sum_dist",
false);
768 registerImporter<RooRealSumFuncFactory>(
"weighted_sum",
false);
769 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)