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");
834 elem[
"x"] << pdf->x().GetName();
835 auto &coefs =
elem[
"coefficients"].set_seq();
836 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
837 coefs.append_child() << (i == 0 ?
"1.0" :
"0.0");
839 for (
const auto &coef : pdf->coefList()) {
840 coefs.append_child() << coef->GetName();
844template <
class RooArg_t>
847 std::string
const &key()
const override;
850 elem[
"type"] << key();
858 std::string
const &key()
const override;
861 elem[
"type"] << key();
869 std::string
const &key()
const override;
872 auto *pdf =
static_cast<const RooPoisson *
>(func);
873 elem[
"type"] << key();
874 elem[
"x"] << pdf->getX().GetName();
875 elem[
"mean"] << pdf->getMean().GetName();
876 elem[
"integer"] << !pdf->getNoRounding();
883 std::string
const &key()
const override;
886 auto *pdf =
static_cast<const RooDecay *
>(func);
887 elem[
"type"] << key();
888 elem[
"t"] << pdf->getT().GetName();
889 elem[
"tau"] << pdf->getTau().GetName();
890 elem[
"resolutionModel"] << pdf->getModel().GetName();
891 elem[
"decayType"] << pdf->getDecayType();
899 std::string
const &key()
const override;
903 elem[
"type"] << key();
904 elem[
"x"] << pdf->convVar().GetName();
912 std::string
const &key()
const override;
916 elem[
"type"] << key();
917 elem[
"x"] << pdf->convVar().GetName();
918 elem[
"mean"] << pdf->getMean().GetName();
919 elem[
"sigma"] << pdf->getSigma().GetName();
926 std::string
const &key()
const override;
931 elem[
"type"] << key();
932 elem[
"x"] << pdf->getX().GetName();
934 auto &m0 = pdf->getMedian();
935 auto &k = pdf->getShapeK();
937 if (pdf->useStandardParametrization()) {
938 elem[
"mu"] << m0.GetName();
939 elem[
"sigma"] << k.GetName();
941 elem[
"mu"] <<
tool->exportTransformed(&m0,
"_lognormal_log",
"log(%s)");
942 elem[
"sigma"] <<
tool->exportTransformed(&k,
"_lognormal_log",
"log(%s)");
951 std::string
const &key()
const override;
955 elem[
"type"] << key();
956 elem[
"x"] << pdf->variable().GetName();
957 auto &
c = pdf->coefficient();
958 if (pdf->negateCoefficient()) {
959 elem[
"c"] <<
c.GetName();
961 elem[
"c"] <<
tool->exportTransformed(&
c,
"_exponential_inverted",
"-%s");
970 std::string
const &key()
const override;
974 elem[
"type"] << key();
977 elem[
"covariances"].fill_mat(pdf->covarianceMatrix());
984 std::string
const &key()
const override;
988 elem[
"type"] << key();
990 TString formula(pdf->function().GetExpFormula());
991 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
992 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
993 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
994 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
996 formula.ReplaceAll(
pname, pdf->parameters()[i].GetName());
998 elem[
"expression"] << formula.Data();
1005 std::string
const &key()
const override;
1009 elem[
"type"] << key();
1010 elem[
"x"] << pdf->getX().GetName();
1011 elem[
"function"] << pdf->getFunc().GetName();
1012 if (!pdf->getNset().empty()) {
1015 elem[
"order"] << pdf->order();
1016 elem[
"eps"] << pdf->eps();
1023 std::string
const &key()
const override;
1027 elem[
"type"] << key();
1028 std::string integrand = integral->integrand().GetName();
1030 elem[
"integrand"] << integrand;
1031 if (integral->intRange()) {
1032 elem[
"domain"] << integral->intRange();
1035 if (
RooArgSet const *funcNormSet = integral->funcNormSet()) {
1044 std::string
const &key()
const override;
1048 elem[
"type"] << key();
1049 if (
auto convFunc = pdf->getPdfConvVar()) {
1052 elem[
"conv_var"] << pdf->getConvVar().GetName();
1053 elem[
"pdf1"] << pdf->getPdf1().GetName();
1054 elem[
"pdf2"] << pdf->getPdf2().GetName();
1055 elem[
"ipOrder"] << pdf->getInterpolationOrder();
1062 std::string
const &key()
const override;
1066 elem[
"type"] << key();
1067 if (
auto rangeName = pdf->getRangeName()) {
1070 elem[
"pdf"] << pdf->pdf().GetName();
1071 elem[
"norm"] << pdf->getN().GetName();
1078 std::string
const &key()
const override;
1082 elem[
"type"] << key();
1095 std::string
name = var->GetName();
1099 auto const &binning = var->getBinning();
1100 if (binning.isUniform()) {
1101 obsNode[
"min"] << var->getMin();
1102 obsNode[
"max"] << var->getMax();
1103 obsNode[
"nbins"] << var->getBins();
1105 auto &edges =
obsNode[
"edges"].set_seq();
1106 edges.append_child() << binning.binLow(0);
1107 for (
int i = 0; i < binning.numBins(); ++i) {
1108 edges.append_child() << binning.binHigh(i);
1117 std::string
const &key()
const override;
1121 auto const *
rs =
static_cast<RooSpline const *
>(func);
1123 elem[
"type"] << key();
1126 elem[
"x"] <<
rs->x().GetName();
1130 elem[
"interpolation"] << (
rs->order() == 5 ?
"poly5" :
"poly3");
1131 elem[
"logx"] <<
rs->logx();
1132 elem[
"logy"] <<
rs->logy();
1136 auto &x0 =
elem[
"x0"].set_seq();
1137 auto &
y0 =
elem[
"y0"].set_seq();
1139 const int np =
sp.GetNp();
1140 for (
int i = 0; i <
np; ++i) {
1141 double xk = 0.0,
yk = 0.0;
1143 x0.append_child() <<
xk;
1144 y0.append_child() <<
yk;
1151#define DEFINE_EXPORTER_KEY(class_name, name) \
1152 std::string const &class_name::key() const \
1154 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)