89 std::set<std::string> arguments;
91 for (
size_t i = 0; i <
expr.size(); ++i) {
103 if (
expr[i] ==
'(') {
109 arguments.insert(arg);
119template <
class RooArg_t>
125 if (!
p.has_child(
"expression")) {
128 TString formula(
p[
"expression"].val());
186 obs->GetName() +
"' as indicated by parent RooBinSamplingPdf '" +
name +
190 if (!
p.has_child(
"epsilon")) {
193 double epsilon(
p[
"epsilon"].val_double());
208 if (
p.has_child(
"extended") &&
p[
"extended"].val_bool()) {
227template <
class RooArg_t>
233 if (!
p.has_child(
"coefficients")) {
240 for (
const auto &coef :
p[
"coefficients"].children()) {
244 if (order == 0 && coef.val() ==
"1.0") {
246 }
else if (coefs.empty() && coef.val() ==
"0.0") {
318 if (
p.has_child(
"normalization")) {
325 domain =
p[
"domain"].val();
341 Int_t order =
p[
"order"].val_int();
342 double eps =
p[
"eps"].val_double();
343 if (
p.has_child(
"normalization")) {
360 Int_t order =
p[
"ipOrder"].val_int();
363 if (
p.has_child(
"conv_func")) {
380 if (
p.has_child(
"range")) {
399 const std::string
muName =
p[
"mu"].val();
400 const std::string
sigmaName =
p[
"sigma"].val();
466 if (!
p.has_child(
"coefficients")) {
473 for (
const auto &coef :
p[
"coefficients"].children()) {
477 if (order == 0 && coef.val() ==
"1.0") {
479 }
else if (coefs.empty() && coef.val() ==
"0.0") {
497 bool has_cov =
p.has_child(
"covariances");
498 bool has_corr =
p.has_child(
"correlations") &&
p.has_child(
"standard_deviations");
506 int n =
p[
"covariances"].num_children();
509 for (
const auto &row :
p[
"covariances"].children()) {
511 for (
const auto &val : row.children()) {
512 covmat(i,
j) = val.val_double();
519 for (
const auto &
v :
p[
"standard_deviations"].children()) {
524 for (
const auto &row :
p[
"correlations"].children()) {
526 for (
const auto &val : row.children()) {
545 if (!
p.has_child(
"axes")) {
546 std::stringstream
ss;
547 ss <<
"No axes given in '" <<
name <<
"'"
548 <<
". Using default binning (uniform; nbins=100). If needed, export the Workspace to JSON with a newer "
549 <<
"Root version that supports custom ParamHistFunc binnings(>=6.38.00)." << std::endl;
562 std::map<std::string, std::unique_ptr<RooRealVar>>
varMap;
566 const std::string
name = node[
"name"].val();
567 std::unique_ptr<RooRealVar> obs;
569 if (node.has_child(
"edges")) {
570 std::vector<double> edges;
571 for (
const auto &
bound : node[
"edges"].children()) {
572 edges.push_back(
bound.val_double());
574 obs = std::make_unique<RooRealVar>(
name.c_str(),
name.c_str(), edges.front(), edges.back());
575 RooBinning bins(obs->getMin(), obs->getMax());
578 obs->setBinning(bins);
580 obs = std::make_unique<RooRealVar>(
name.c_str(),
name.c_str(), node[
"min"].val_double(),
581 node[
"max"].val_double());
582 obs->setBins(node[
"nbins"].val_int());
590 for (
int i = 0; i <
varList.getSize(); ++i) {
597 vars.
addOwned(std::move(it->second));
611 if (!
p.has_child(
"x")) {
614 if (!
p.has_child(
"x0") || !
p.has_child(
"y0")) {
621 std::string
algo =
p.has_child(
"interpolation") ?
p[
"interpolation"].val() :
"poly3";
625 else if (
algo ==
"poly5")
629 "': allowed are 'poly3' and 'poly5'");
631 const bool logx =
p.has_child(
"logx") ?
p[
"logx"].val_bool() :
false;
632 const bool logy =
p.has_child(
"logy") ?
p[
"logy"].val_bool() :
false;
635 std::vector<double> x0;
636 std::vector<double>
y0;
637 x0.reserve(
p[
"x0"].num_children());
638 y0.reserve(
p[
"y0"].num_children());
640 for (
const auto &
v :
p[
"x0"].children())
641 x0.push_back(
v.val_double());
642 for (
const auto &
v :
p[
"y0"].children())
643 y0.push_back(
v.val_double());
645 if (x0.size() !=
y0.size()) {
647 ", y0 has " + std::to_string(
y0.size()));
655 std::span<const double>(
y0.data(),
y0.size()), order, logx, logy);
664template <
class RooArg_t>
667 std::string
const &key()
const override;
671 elem[
"type"] << key();
674 elem[
"extended"] << (pdf->extendMode() != RooArg_t::CanNotBeExtended);
681 std::string
const &key()
const override;
685 elem[
"type"] << key();
695 std::string
const &key()
const override;
699 elem[
"type"] << key();
708 std::string
const &key()
const override;
712 elem[
"type"] << key();
714 tool->exportHisto(*
dh.get(),
dh.numEntries(),
dh.weightArray(),
elem[
"data"].set_map());
724 if (!
p.has_child(
"data")) {
727 std::unique_ptr<RooDataHist> dataHist =
736 std::string
const &key()
const override;
740 elem[
"type"] << key();
742 tool->exportHisto(*
dh.get(),
dh.numEntries(),
dh.weightArray(),
elem[
"data"].set_map());
752 if (!
p.has_child(
"data")) {
755 std::unique_ptr<RooDataHist> dataHist =
764 std::string
const &key()
const override;
768 elem[
"type"] << key();
769 elem[
"pdf"] << pdf->
pdf().GetName();
778 std::string
const &key()
const override;
782 elem[
"type"] << key();
789template <
class RooArg_t>
792 std::string
const &key()
const override;
796 elem[
"type"] << key();
797 TString expression(pdf->expression());
805 for (
size_t idx = pdf->nParameters(); idx--;) {
806 const RooAbsArg *par = pdf->getParameter(idx);
807 expression.ReplaceAll((
"x[" + std::to_string(idx) +
"]").c_str(), par->
GetName());
808 expression.ReplaceAll((
"@" + std::to_string(idx)).c_str(), par->
GetName());
810 elem[
"expression"] << expression.Data();
817 expr.ReplaceAll(
"TMath::Exp",
"exp");
818 expr.ReplaceAll(
"TMath::Min",
"min");
819 expr.ReplaceAll(
"TMath::Max",
"max");
820 expr.ReplaceAll(
"TMath::Log",
"log");
821 expr.ReplaceAll(
"TMath::Cos",
"cos");
822 expr.ReplaceAll(
"TMath::Sin",
"sin");
823 expr.ReplaceAll(
"TMath::Sqrt",
"sqrt");
824 expr.ReplaceAll(
"TMath::Power",
"pow");
825 expr.ReplaceAll(
"TMath::Erf",
"erf");
828template <
class RooArg_t>
831 std::string
const &key()
const override;
834 auto *pdf =
static_cast<const RooArg_t *
>(func);
835 elem[
"type"] << key();
836 elem[
"x"] << pdf->x().GetName();
837 auto &coefs =
elem[
"coefficients"].set_seq();
841 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
842 coefs.append_child() << (i == 0 ?
"1.0" :
"0.0");
844 for (
const auto &coef : pdf->coefList()) {
845 coefs.append_child() << coef->GetName();
853 std::string
const &key()
const override;
857 elem[
"type"] << key();
858 elem[
"x"] << pdf->x().GetName();
859 auto &coefs =
elem[
"coefficients"].set_seq();
863 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
864 coefs.append_child() << (i == 0 ?
"1.0" :
"0.0");
866 for (
const auto &coef : pdf->coefList()) {
867 coefs.append_child() << coef->GetName();
875 std::string
const &key()
const override;
878 auto *pdf =
static_cast<const RooPoisson *
>(func);
879 elem[
"type"] << key();
880 elem[
"x"] << pdf->getX().GetName();
881 elem[
"mean"] << pdf->getMean().GetName();
882 elem[
"integer"] << !pdf->getNoRounding();
889 std::string
const &key()
const override;
892 auto *pdf =
static_cast<const RooDecay *
>(func);
893 elem[
"type"] << key();
894 elem[
"t"] << pdf->getT().GetName();
895 elem[
"tau"] << pdf->getTau().GetName();
896 elem[
"resolutionModel"] << pdf->getModel().GetName();
897 elem[
"decayType"] << pdf->getDecayType();
905 std::string
const &key()
const override;
909 elem[
"type"] << key();
910 elem[
"x"] << pdf->convVar().GetName();
918 std::string
const &key()
const override;
922 elem[
"type"] << key();
923 elem[
"x"] << pdf->convVar().GetName();
924 elem[
"mean"] << pdf->getMean().GetName();
925 elem[
"sigma"] << pdf->getSigma().GetName();
932 std::string
const &key()
const override;
937 elem[
"type"] << key();
938 elem[
"x"] << pdf->getX().GetName();
940 auto &m0 = pdf->getMedian();
941 auto &k = pdf->getShapeK();
943 if (pdf->useStandardParametrization()) {
944 elem[
"mu"] << m0.GetName();
945 elem[
"sigma"] << k.GetName();
947 elem[
"mu"] <<
tool->exportTransformed(&m0,
"_lognormal_log",
"log(%s)");
948 elem[
"sigma"] <<
tool->exportTransformed(&k,
"_lognormal_log",
"log(%s)");
957 std::string
const &key()
const override;
961 elem[
"type"] << key();
962 elem[
"x"] << pdf->variable().GetName();
963 auto &
c = pdf->coefficient();
964 if (pdf->negateCoefficient()) {
965 elem[
"c"] <<
c.GetName();
967 elem[
"c"] <<
tool->exportTransformed(&
c,
"_exponential_inverted",
"-%s");
976 std::string
const &key()
const override;
980 elem[
"type"] << key();
983 elem[
"covariances"].fill_mat(pdf->covarianceMatrix());
990 std::string
const &key()
const override;
994 elem[
"type"] << key();
996 TString formula(pdf->function().GetExpFormula());
997 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
998 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
999 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
1000 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
1002 formula.ReplaceAll(
pname, pdf->parameters()[i].GetName());
1004 elem[
"expression"] << formula.Data();
1011 std::string
const &key()
const override;
1015 elem[
"type"] << key();
1016 elem[
"x"] << pdf->getX().GetName();
1017 elem[
"function"] << pdf->getFunc().GetName();
1018 if (!pdf->getNset().empty()) {
1021 elem[
"order"] << pdf->order();
1022 elem[
"eps"] << pdf->eps();
1029 std::string
const &key()
const override;
1033 elem[
"type"] << key();
1034 std::string integrand = integral->integrand().GetName();
1036 elem[
"integrand"] << integrand;
1037 if (integral->intRange()) {
1038 elem[
"domain"] << integral->intRange();
1041 if (
RooArgSet const *funcNormSet = integral->funcNormSet()) {
1050 std::string
const &key()
const override;
1054 elem[
"type"] << key();
1055 if (
auto convFunc = pdf->getPdfConvVar()) {
1058 elem[
"conv_var"] << pdf->getConvVar().GetName();
1059 elem[
"pdf1"] << pdf->getPdf1().GetName();
1060 elem[
"pdf2"] << pdf->getPdf2().GetName();
1061 elem[
"ipOrder"] << pdf->getInterpolationOrder();
1068 std::string
const &key()
const override;
1072 elem[
"type"] << key();
1073 if (
auto rangeName = pdf->getRangeName()) {
1076 elem[
"pdf"] << pdf->pdf().GetName();
1077 elem[
"norm"] << pdf->getN().GetName();
1084 std::string
const &key()
const override;
1088 elem[
"type"] << key();
1101 std::string
name = var->GetName();
1105 if (var->getBinning().isUniform()) {
1106 obsNode[
"min"] << var->getMin();
1107 obsNode[
"max"] << var->getMax();
1108 obsNode[
"nbins"] << var->getBins();
1110 auto &edges =
obsNode[
"edges"];
1112 double val = var->getBinning().binLow(0);
1113 edges.append_child() << val;
1114 for (
int i = 0; i < var->getBinning().numBins(); ++i) {
1115 val = var->getBinning().binHigh(i);
1116 edges.append_child() << val;
1125 std::string
const &key()
const override;
1129 auto const *
rs =
static_cast<RooSpline const *
>(func);
1131 elem[
"type"] << key();
1134 elem[
"x"] <<
rs->x().GetName();
1138 elem[
"interpolation"] << (
rs->order() == 5 ?
"poly5" :
"poly3");
1139 elem[
"logx"] <<
rs->logx();
1140 elem[
"logy"] <<
rs->logy();
1144 auto &x0 =
elem[
"x0"].set_seq();
1145 auto &
y0 =
elem[
"y0"].set_seq();
1147 const int np =
sp.GetNp();
1148 for (
int i = 0; i <
np; ++i) {
1149 double xk = 0.0,
yk = 0.0;
1151 x0.append_child() <<
xk;
1152 y0.append_child() <<
yk;
1159#define DEFINE_EXPORTER_KEY(class_name, name) \
1160 std::string const &class_name::key() const \
1162 const static std::string keystring = name; \
#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)
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
const_iterator begin() const
const_iterator end() const
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 bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value and implements functionality common to al...
RooAddModel is an efficient implementation of a sum of PDFs of the form.
Efficient implementation of a sum of PDFs of the form.
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
Implements a RooAbsBinning in terms of an array of boundary values, posing no constraints on the choi...
Container class to hold N-dimensional binned data.
Single or double sided decay function that can be analytically convolved with any RooResolutionModel ...
Represents the first, second, or third order derivative of any RooAbsReal as calculated (numerically)...
RooExtendPdf is a wrapper around an existing PDF that adds a parameteric extended likelihood term to ...
PDF for the numerical (FFT) convolution of two PDFs.
Class RooGaussModel implements a RooResolutionModel that models a Gaussian distribution.
A real-valued function sampled from a multidimensional histogram.
A probability 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.
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.
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
A RooFit class for creating spline functions.
Use TF1, TF2, TF3 functions as RooFit objects.
Implements a RooResolution model that corresponds to a delta function.
const char * GetName() const override
Returns name of object.
Base class for spline implementation containing the Draw/Paint methods.
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)