87 std::set<std::string> arguments;
89 for (
size_t i = 0; i <
expr.size(); ++i) {
101 if (
expr[i] ==
'(') {
107 arguments.insert(arg);
117template <
class RooArg_t>
123 if (!
p.has_child(
"expression")) {
126 TString formula(
p[
"expression"].val());
184 obs->GetName() +
"' as indicated by parent RooBinSamplingPdf '" +
name +
188 if (!
p.has_child(
"epsilon")) {
191 double epsilon(
p[
"epsilon"].val_double());
206 if (
p.has_child(
"extended") &&
p[
"extended"].val_bool()) {
225template <
class RooArg_t>
231 if (!
p.has_child(
"coefficients")) {
238 for (
const auto &coef :
p[
"coefficients"].children()) {
242 if (order == 0 && coef.val() ==
"1.0") {
244 }
else if (coefs.empty() && coef.val() ==
"0.0") {
316 if (
p.has_child(
"normalization")) {
323 domain =
p[
"domain"].val();
339 Int_t order =
p[
"order"].val_int();
340 double eps =
p[
"eps"].val_double();
341 if (
p.has_child(
"normalization")) {
358 Int_t order =
p[
"ipOrder"].val_int();
361 if (
p.has_child(
"conv_func")) {
378 if (
p.has_child(
"range")) {
397 const std::string
muName =
p[
"mu"].val();
398 const std::string
sigmaName =
p[
"sigma"].val();
464 if (!
p.has_child(
"coefficients")) {
471 for (
const auto &coef :
p[
"coefficients"].children()) {
475 if (order == 0 && coef.val() ==
"1.0") {
477 }
else if (coefs.empty() && coef.val() ==
"0.0") {
495 bool has_cov =
p.has_child(
"covariances");
496 bool has_corr =
p.has_child(
"correlations") &&
p.has_child(
"standard_deviations");
504 int n =
p[
"covariances"].num_children();
507 for (
const auto &row :
p[
"covariances"].children()) {
509 for (
const auto &val : row.children()) {
510 covmat(i,
j) = val.val_double();
517 for (
const auto &
v :
p[
"standard_deviations"].children()) {
522 for (
const auto &row :
p[
"correlations"].children()) {
524 for (
const auto &val : row.children()) {
543 if (!
p.has_child(
"axes")) {
544 std::stringstream
ss;
545 ss <<
"No axes given in '" <<
name <<
"'"
546 <<
". Using default binning (uniform; nbins=100). If needed, export the Workspace to JSON with a newer "
547 <<
"Root version that supports custom ParamHistFunc binnings(>=6.38.00)." << std::endl;
560 std::map<std::string, std::unique_ptr<RooRealVar>>
varMap;
564 const std::string
name = node[
"name"].val();
565 std::unique_ptr<RooRealVar> obs;
567 if (node.has_child(
"edges")) {
568 std::vector<double> edges;
569 for (
const auto &
bound : node[
"edges"].children()) {
570 edges.push_back(
bound.val_double());
572 obs = std::make_unique<RooRealVar>(
name.c_str(),
name.c_str(), edges.front(), edges.back());
573 RooBinning bins(obs->getMin(), obs->getMax());
576 obs->setBinning(bins);
578 obs = std::make_unique<RooRealVar>(
name.c_str(),
name.c_str(), node[
"min"].val_double(),
579 node[
"max"].val_double());
580 obs->setBins(node[
"nbins"].val_int());
588 for (
int i = 0; i <
varList.getSize(); ++i) {
595 vars.
addOwned(std::move(it->second));
605template <
class RooArg_t>
608 std::string
const &key()
const override;
612 elem[
"type"] << key();
615 elem[
"extended"] << (pdf->extendMode() != RooArg_t::CanNotBeExtended);
622 std::string
const &key()
const override;
626 elem[
"type"] << key();
636 std::string
const &key()
const override;
640 elem[
"type"] << key();
649 std::string
const &key()
const override;
653 elem[
"type"] << key();
655 tool->exportHisto(*
dh.get(),
dh.numEntries(),
dh.weightArray(),
elem[
"data"].set_map());
665 if (!
p.has_child(
"data")) {
668 std::unique_ptr<RooDataHist> dataHist =
677 std::string
const &key()
const override;
681 elem[
"type"] << key();
683 tool->exportHisto(*
dh.get(),
dh.numEntries(),
dh.weightArray(),
elem[
"data"].set_map());
693 if (!
p.has_child(
"data")) {
696 std::unique_ptr<RooDataHist> dataHist =
705 std::string
const &key()
const override;
709 elem[
"type"] << key();
710 elem[
"pdf"] << pdf->
pdf().GetName();
719 std::string
const &key()
const override;
723 elem[
"type"] << key();
730template <
class RooArg_t>
733 std::string
const &key()
const override;
737 elem[
"type"] << key();
738 TString expression(pdf->expression());
746 for (
size_t idx = pdf->nParameters(); idx--;) {
747 const RooAbsArg *par = pdf->getParameter(idx);
748 expression.ReplaceAll((
"x[" + std::to_string(idx) +
"]").c_str(), par->
GetName());
749 expression.ReplaceAll((
"@" + std::to_string(idx)).c_str(), par->
GetName());
751 elem[
"expression"] << expression.Data();
758 expr.ReplaceAll(
"TMath::Exp",
"exp");
759 expr.ReplaceAll(
"TMath::Min",
"min");
760 expr.ReplaceAll(
"TMath::Max",
"max");
761 expr.ReplaceAll(
"TMath::Log",
"log");
762 expr.ReplaceAll(
"TMath::Cos",
"cos");
763 expr.ReplaceAll(
"TMath::Sin",
"sin");
764 expr.ReplaceAll(
"TMath::Sqrt",
"sqrt");
765 expr.ReplaceAll(
"TMath::Power",
"pow");
766 expr.ReplaceAll(
"TMath::Erf",
"erf");
769template <
class RooArg_t>
772 std::string
const &key()
const override;
775 auto *pdf =
static_cast<const RooArg_t *
>(func);
776 elem[
"type"] << key();
777 elem[
"x"] << pdf->x().GetName();
778 auto &coefs =
elem[
"coefficients"].set_seq();
782 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
783 coefs.append_child() << (i == 0 ?
"1.0" :
"0.0");
785 for (
const auto &coef : pdf->coefList()) {
786 coefs.append_child() << coef->GetName();
794 std::string
const &key()
const override;
798 elem[
"type"] << key();
799 elem[
"x"] << pdf->x().GetName();
800 auto &coefs =
elem[
"coefficients"].set_seq();
804 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
805 coefs.append_child() << (i == 0 ?
"1.0" :
"0.0");
807 for (
const auto &coef : pdf->coefList()) {
808 coefs.append_child() << coef->GetName();
816 std::string
const &key()
const override;
819 auto *pdf =
static_cast<const RooPoisson *
>(func);
820 elem[
"type"] << key();
821 elem[
"x"] << pdf->getX().GetName();
822 elem[
"mean"] << pdf->getMean().GetName();
823 elem[
"integer"] << !pdf->getNoRounding();
830 std::string
const &key()
const override;
833 auto *pdf =
static_cast<const RooDecay *
>(func);
834 elem[
"type"] << key();
835 elem[
"t"] << pdf->getT().GetName();
836 elem[
"tau"] << pdf->getTau().GetName();
837 elem[
"resolutionModel"] << pdf->getModel().GetName();
838 elem[
"decayType"] << pdf->getDecayType();
846 std::string
const &key()
const override;
850 elem[
"type"] << key();
851 elem[
"x"] << pdf->convVar().GetName();
859 std::string
const &key()
const override;
863 elem[
"type"] << key();
864 elem[
"x"] << pdf->convVar().GetName();
865 elem[
"mean"] << pdf->getMean().GetName();
866 elem[
"sigma"] << pdf->getSigma().GetName();
873 std::string
const &key()
const override;
878 elem[
"type"] << key();
879 elem[
"x"] << pdf->getX().GetName();
881 auto &m0 = pdf->getMedian();
882 auto &k = pdf->getShapeK();
884 if (pdf->useStandardParametrization()) {
885 elem[
"mu"] << m0.GetName();
886 elem[
"sigma"] << k.GetName();
888 elem[
"mu"] <<
tool->exportTransformed(&m0,
"_lognormal_log",
"log(%s)");
889 elem[
"sigma"] <<
tool->exportTransformed(&k,
"_lognormal_log",
"log(%s)");
898 std::string
const &key()
const override;
902 elem[
"type"] << key();
903 elem[
"x"] << pdf->variable().GetName();
904 auto &
c = pdf->coefficient();
905 if (pdf->negateCoefficient()) {
906 elem[
"c"] <<
c.GetName();
908 elem[
"c"] <<
tool->exportTransformed(&
c,
"_exponential_inverted",
"-%s");
917 std::string
const &key()
const override;
921 elem[
"type"] << key();
924 elem[
"covariances"].fill_mat(pdf->covarianceMatrix());
931 std::string
const &key()
const override;
935 elem[
"type"] << key();
937 TString formula(pdf->function().GetExpFormula());
938 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
939 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
940 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
941 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
943 formula.ReplaceAll(
pname, pdf->parameters()[i].GetName());
945 elem[
"expression"] << formula.Data();
952 std::string
const &key()
const override;
956 elem[
"type"] << key();
957 elem[
"x"] << pdf->getX().GetName();
958 elem[
"function"] << pdf->getFunc().GetName();
959 if (!pdf->getNset().empty()) {
962 elem[
"order"] << pdf->order();
963 elem[
"eps"] << pdf->eps();
970 std::string
const &key()
const override;
974 elem[
"type"] << key();
975 std::string integrand = integral->integrand().GetName();
977 elem[
"integrand"] << integrand;
978 if (integral->intRange()) {
979 elem[
"domain"] << integral->intRange();
982 if (
RooArgSet const *funcNormSet = integral->funcNormSet()) {
991 std::string
const &key()
const override;
995 elem[
"type"] << key();
996 if (
auto convFunc = pdf->getPdfConvVar()) {
999 elem[
"conv_var"] << pdf->getConvVar().GetName();
1000 elem[
"pdf1"] << pdf->getPdf1().GetName();
1001 elem[
"pdf2"] << pdf->getPdf2().GetName();
1002 elem[
"ipOrder"] << pdf->getInterpolationOrder();
1009 std::string
const &key()
const override;
1013 elem[
"type"] << key();
1014 if (
auto rangeName = pdf->getRangeName()) {
1017 elem[
"pdf"] << pdf->pdf().GetName();
1018 elem[
"norm"] << pdf->getN().GetName();
1025 std::string
const &key()
const override;
1029 elem[
"type"] << key();
1042 std::string
name = var->GetName();
1046 if (var->getBinning().isUniform()) {
1047 obsNode[
"min"] << var->getMin();
1048 obsNode[
"max"] << var->getMax();
1049 obsNode[
"nbins"] << var->getBins();
1051 auto &edges =
obsNode[
"edges"];
1053 double val = var->getBinning().binLow(0);
1054 edges.append_child() << val;
1055 for (
int i = 0; i < var->getBinning().numBins(); ++i) {
1056 val = var->getBinning().binHigh(i);
1057 edges.append_child() << val;
1064#define DEFINE_EXPORTER_KEY(class_name, name) \
1065 std::string const &class_name::key() const \
1067 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
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...
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.
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)