66std::vector<std::string> extractArguments(std::string expr)
69 expr.erase(std::remove_if(expr.begin(), expr.end(), [](
unsigned char c) { return std::isspace(c); }), expr.end());
71 std::vector<std::string> arguments;
72 size_t startidx = expr.size();
73 for (
size_t i = 0; i < expr.size(); ++i) {
74 if (startidx >= expr.size()) {
75 if (isalpha(expr[i])) {
79 if (!isdigit(expr[i]) && !isalpha(expr[i]) && expr[i] !=
'_') {
81 startidx = expr.size();
84 std::string arg(expr.substr(startidx, i - startidx));
85 startidx = expr.size();
86 arguments.push_back(arg);
90 if (startidx < expr.size()) {
91 arguments.push_back(expr.substr(startidx));
96template <
class RooArg_t>
102 if (!
p.has_child(
"expression")) {
105 TString formula(
p[
"expression"].val());
107 for (
const auto &
d : extractArguments(formula.Data())) {
110 tool->
wsImport(RooArg_t{
name.c_str(), formula, dependents});
148 obs->GetName() +
"' as indicated by parent RooBinSamplingPdf '" +
name +
152 if (!
p.has_child(
"epsilon")) {
155 double epsilon(
p[
"epsilon"].val_double());
169 bool extended =
false;
170 if (
p.has_child(
"extended") &&
p[
"extended"].val_bool()) {
195 if (!
p.has_child(
"coefficients")) {
202 for (
const auto &coef :
p[
"coefficients"].children()) {
206 if (order == 0 && coef.val() ==
"1.0") {
208 }
else if (coefs.empty() && coef.val() ==
"0.0") {
269 bool has_cov =
p.has_child(
"covariances");
270 bool has_corr =
p.has_child(
"correlations") &&
p.has_child(
"standard_deviations");
271 if (!has_cov && !has_corr) {
278 int n =
p[
"covariances"].num_children();
281 for (
const auto &row :
p[
"covariances"].children()) {
283 for (
const auto &val : row.children()) {
284 covmat(i, j) = val.val_double();
290 std::vector<double> variances;
291 for (
const auto &
v :
p[
"standard_deviations"].children()) {
292 variances.push_back(
v.val_double());
294 covmat.
ResizeTo(variances.size(), variances.size());
296 for (
const auto &row :
p[
"correlations"].children()) {
298 for (
const auto &val : row.children()) {
299 covmat(i, j) = val.val_double() * variances[i] * variances[j];
317 std::string
const &
key()
const override;
321 elem[
"type"] <<
key();
331 std::string
const &
key()
const override;
335 elem[
"type"] <<
key();
345 std::string
const &
key()
const override;
349 elem[
"type"] <<
key();
358 std::string
const &
key()
const override;
362 elem[
"type"] <<
key();
374 if (!
p.has_child(
"data")) {
377 std::unique_ptr<RooDataHist> dataHist =
386 std::string
const &
key()
const override;
390 elem[
"type"] <<
key();
402 if (!
p.has_child(
"data")) {
405 std::unique_ptr<RooDataHist> dataHist =
414 std::string
const &
key()
const override;
418 elem[
"type"] <<
key();
421 elem[
"epsilon"] << pdf->
epsilon();
428 std::string
const &
key()
const override;
432 elem[
"type"] <<
key();
439template <
class RooArg_t>
442 std::string
const &
key()
const override;
445 const RooArg_t *pdf =
static_cast<const RooArg_t *
>(func);
446 elem[
"type"] <<
key();
447 TString expression(pdf->expression());
448 for (
size_t i = 0; i < pdf->nParameters(); ++i) {
450 std::stringstream ss_1;
451 ss_1 <<
"x[" << i <<
"]";
452 std::stringstream ss_2;
453 ss_2 <<
"@" << i <<
"";
454 expression.ReplaceAll(ss_1.str().c_str(), par->
GetName());
455 expression.ReplaceAll(ss_2.str().c_str(), par->
GetName());
457 elem[
"expression"] << expression.Data();
464 std::string
const &
key()
const override;
468 elem[
"type"] <<
key();
469 elem[
"x"] << pdf->x().GetName();
470 auto &coefs = elem[
"coefficients"].
set_seq();
474 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
477 for (
const auto &coef : pdf->coefList()) {
486 std::string
const &
key()
const override;
489 auto *pdf =
static_cast<const RooPoisson *
>(func);
490 elem[
"type"] <<
key();
491 elem[
"x"] << pdf->getX().GetName();
492 elem[
"mean"] << pdf->getMean().GetName();
493 elem[
"integer"] << !pdf->getNoRounding();
500 std::string
const &
key()
const override;
505 elem[
"type"] <<
key();
506 elem[
"x"] << pdf->getX().GetName();
508 auto &m0 = pdf->getMedian();
509 auto &k = pdf->getShapeK();
511 if(pdf->useStandardParametrization()) {
512 elem[
"mu"] << m0.GetName();
513 elem[
"sigma"] << k.GetName();
525 std::string
const &
key()
const override;
529 elem[
"type"] <<
key();
530 elem[
"x"] << pdf->variable().GetName();
531 auto &
c = pdf->coefficient();
532 if (pdf->negateCoefficient()) {
533 elem[
"c"] <<
c.GetName();
544 std::string
const &
key()
const override;
548 elem[
"type"] <<
key();
551 elem[
"covariances"].
fill_mat(pdf->covarianceMatrix());
558 std::string
const &
key()
const override;
562 elem[
"type"] <<
key();
564 TString formula(pdf->function().GetExpFormula());
565 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
566 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
567 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
568 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
570 formula.ReplaceAll(pname, pdf->parameters()[i].GetName());
572 elem[
"expression"] << formula.Data();
577#define DEFINE_EXPORTER_KEY(class_name, name) \
578 std::string const &class_name::key() const \
580 const static std::string keystring = name; \
609 registerImporter<RooAddPdfFactory>(
"mixture_dist",
false);
610 registerImporter<RooBinSamplingPdfFactory>(
"binsampling_dist",
false);
611 registerImporter<RooBinWidthFunctionFactory>(
"binwidth",
false);
612 registerImporter<RooExponentialFactory>(
"exponential_dist",
false);
613 registerImporter<RooFormulaArgFactory<RooFormulaVar>>(
"generic_function",
false);
614 registerImporter<RooFormulaArgFactory<RooGenericPdf>>(
"generic_dist",
false);
615 registerImporter<RooHistFuncFactory>(
"histogram",
false);
616 registerImporter<RooHistPdfFactory>(
"histogram_dist",
false);
617 registerImporter<RooLogNormalFactory>(
"lognormal_dist",
false);
618 registerImporter<RooMultiVarGaussianFactory>(
"multivariate_normal_dist",
false);
619 registerImporter<RooPoissonFactory>(
"poisson_dist",
false);
620 registerImporter<RooPolynomialFactory>(
"polynomial_dist",
false);
621 registerImporter<RooRealSumPdfFactory>(
"weighted_sum_dist",
false);
622 registerImporter<RooRealSumFuncFactory>(
"weighted_sum",
false);
#define DEFINE_EXPORTER_KEY(class_name, name)
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
RooBinWidthFunction is a class that returns the bin width (or volume) given a RooHistFunc.
bool divideByBinWidth() const
const RooHistFunc & histFunc() const
The RooDataHist is a 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
RooHistFunc implements a real-valued function sampled from a multidimensional histogram.
RooDataHist & dataHist()
Return RooDataHist that is represented.
RooHistPdf implements a propability density function sampled from a multidimensional histogram.
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
RooRealVar represents a 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)