78 return arg ==
"PI" || arg ==
"EULER" || arg ==
"TMath";
100 std::set<std::string> arguments;
102 for (
size_t i = 0; i <
expr.size(); ++i) {
114 if (
expr[i] ==
'(') {
121 arguments.insert(arg);
129 arguments.insert(arg);
137 std::string
in(
expr.Data());
139 out.reserve(
in.size());
141 for (std::size_t pos = 0; pos <
in.size();) {
144 pos > 0 && (std::isalnum(
static_cast<unsigned char>(
in[pos - 1])) ||
in[pos - 1] ==
'_');
145 const std::size_t end = pos +
identifier.size();
147 end <
in.size() && (std::isalnum(
static_cast<unsigned char>(
in[end])) ||
in[end] ==
'_');
152 out.push_back(
in[pos]);
166template <
class RooArg_t>
170 if (!
p.has_child(
"expression")) {
173 TString formula(
p[
"expression"].val());
231template <
bool Div
ideByBinW
idth>
252 obs->GetName() +
"' as indicated by parent RooBinSamplingPdf '" +
name +
256 if (!
p.has_child(
"epsilon")) {
259 double epsilon(
p[
"epsilon"].val_double());
271 if (
p.has_child(
"extended") &&
p[
"extended"].val_bool()) {
287template <
class RooArg_t>
291 if (!
p.has_child(
"coefficients")) {
298 for (
const auto &coef :
p[
"coefficients"].children()) {
302 if (order == 0 && (coef.val() ==
"1.0" || coef.val() ==
"1")) {
304 }
else if (coefs.empty() && (coef.val() ==
"0.0" || coef.val() ==
"0")) {
364 if (
p.has_child(
"normalization")) {
371 domain =
p[
"domain"].val();
384 Int_t order =
p[
"order"].val_int();
385 double eps =
p[
"eps"].val_double();
386 if (
p.has_child(
"normalization")) {
400 Int_t order =
p[
"ipOrder"].val_int();
403 if (
p.has_child(
"conv_func")) {
417 if (
p.has_child(
"range")) {
433 const std::string
muName =
p[
"mu"].val();
434 const std::string
sigmaName =
p[
"sigma"].val();
494 bool has_cov =
p.has_child(
"covariances");
495 bool has_corr =
p.has_child(
"correlations") &&
p.has_child(
"standard_deviations");
503 int n =
p[
"covariances"].num_children();
506 for (
const auto &row :
p[
"covariances"].children()) {
508 for (
const auto &val : row.children()) {
509 covmat(i,
j) = val.val_double();
516 for (
const auto &
v :
p[
"standard_deviations"].children()) {
521 for (
const auto &row :
p[
"correlations"].children()) {
523 for (
const auto &val : row.children()) {
538 std::map<std::string, std::unique_ptr<RooRealVar>>
varMap;
542 const std::string
name = node[
"name"].val();
543 std::unique_ptr<RooRealVar> obs;
545 if (node.has_child(
"edges")) {
546 std::vector<double> edges;
547 for (
const auto &
bound : node[
"edges"].children()) {
548 edges.push_back(
bound.val_double());
550 obs = std::make_unique<RooRealVar>(
name.c_str(),
name.c_str(), edges.front(), edges.back());
551 RooBinning bins(obs->getMin(), obs->getMax());
554 obs->setBinning(bins);
556 obs = std::make_unique<RooRealVar>(
name.c_str(),
name.c_str(), node[
"min"].val_double(),
557 node[
"max"].val_double());
558 obs->setBins(node[
"nbins"].val_int());
572 vars.
addOwned(std::move(it->second));
580 if (!
p.has_child(
"parameters")) {
585 if (!
p.has_child(
"axes")) {
586 std::stringstream
ss;
587 ss <<
"No axes given in '" <<
name <<
"'"
588 <<
". Using default binning (uniform; nbins=100). If needed, export the Workspace to JSON with a newer "
589 <<
"Root version that supports custom ParamHistFunc binnings(>=6.38.00)." << std::endl;
603 if (!
p.has_child(
"x")) {
606 if (!
p.has_child(
"x0") || !
p.has_child(
"y0")) {
613 std::string
algo =
p.has_child(
"interpolation") ?
p[
"interpolation"].val() :
"poly3";
617 else if (
algo ==
"poly5")
621 "': allowed are 'poly3' and 'poly5'");
623 const bool logx =
p.has_child(
"logx") ?
p[
"logx"].val_bool() :
false;
624 const bool logy =
p.has_child(
"logy") ?
p[
"logy"].val_bool() :
false;
627 std::vector<double> x0;
628 std::vector<double>
y0;
629 x0.reserve(
p[
"x0"].num_children());
630 y0.reserve(
p[
"y0"].num_children());
632 for (
const auto &
v :
p[
"x0"].children())
633 x0.push_back(
v.val_double());
634 for (
const auto &
v :
p[
"y0"].children())
635 y0.push_back(
v.val_double());
637 if (x0.size() !=
y0.size()) {
639 ", y0 has " + std::to_string(
y0.size()));
647 std::span<const double>(
y0.data(),
y0.size()), order, logx, logy);
655template <
class RooArg_t>
662 elem[
"extended"] << (pdf->extendMode() != RooArg_t::CanNotBeExtended);
685template <
class RooArg_t>
691 tool->exportHisto(*
dh.get(),
dh.numEntries(),
dh.weightArray(),
elem[
"data"].set_map());
695template <
class RooArg_t>
699 if (!
p.has_child(
"data")) {
702 std::unique_ptr<RooDataHist> dataHist =
712 elem[
"pdf"] << pdf->
pdf().GetName();
758template <
class RooArg_t>
763 TString expression(pdf->expression());
771 for (
size_t idx = pdf->nParameters(); idx--;) {
772 const RooAbsArg *par = pdf->getParameter(idx);
773 expression.ReplaceAll((
"x[" + std::to_string(idx) +
"]").c_str(), par->
GetName());
774 expression.ReplaceAll((
"@" + std::to_string(idx)).c_str(), par->
GetName());
776 elem[
"expression"] << expression.Data();
786 elem[
"x"] << pdf->x().GetName();
787 auto &coefs =
elem[
"coefficients"].set_seq();
788 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
789 coefs.append_child() << (i == 0 ? 1.0 : 0.0);
791 for (
const auto &coef : pdf->coefList()) {
792 coefs.append_child() << coef->GetName();
796template <
class RooArg_t>
806 auto *pdf =
static_cast<const RooPoisson *
>(func);
808 elem[
"x"] << pdf->getX().GetName();
809 elem[
"mean"] << pdf->getMean().GetName();
810 elem[
"integer"] << !pdf->getNoRounding();
816 auto *pdf =
static_cast<const RooDecay *
>(func);
818 elem[
"t"] << pdf->getT().GetName();
819 elem[
"tau"] << pdf->getTau().GetName();
820 elem[
"resolutionModel"] << pdf->getModel().GetName();
821 elem[
"decayType"] << pdf->getDecayType();
830 elem[
"x"] << pdf->convVar().GetName();
839 elem[
"x"] << pdf->convVar().GetName();
840 elem[
"mean"] << pdf->getMean().GetName();
841 elem[
"sigma"] << pdf->getSigma().GetName();
850 elem[
"x"] << pdf->getX().GetName();
852 auto &m0 = pdf->getMedian();
853 auto &k = pdf->getShapeK();
855 if (pdf->useStandardParametrization()) {
856 elem[
"mu"] << m0.GetName();
857 elem[
"sigma"] << k.GetName();
859 elem[
"mu"] <<
tool->exportTransformed(&m0,
"_lognormal_log",
"log(%s)");
860 elem[
"sigma"] <<
tool->exportTransformed(&k,
"_lognormal_log",
"log(%s)");
870 elem[
"x"] << pdf->variable().GetName();
871 auto &
c = pdf->coefficient();
872 if (pdf->negateCoefficient()) {
873 elem[
"c"] <<
c.GetName();
875 elem[
"c"] <<
tool->exportTransformed(&
c,
"_exponential_inverted",
"-%s");
887 elem[
"covariances"].fill_mat(pdf->covarianceMatrix());
896 TString formula(pdf->function().GetExpFormula());
897 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
898 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
899 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
900 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
902 formula.ReplaceAll(
pname, pdf->parameters()[i].GetName());
904 elem[
"expression"] << formula.Data();
912 elem[
"x"] << pdf->getX().GetName();
913 elem[
"function"] << pdf->getFunc().GetName();
914 if (!pdf->getNset().empty()) {
917 elem[
"order"] << pdf->order();
918 elem[
"eps"] << pdf->eps();
926 std::string integrand = integral->integrand().GetName();
927 elem[
"integrand"] << integrand;
928 if (integral->intRange()) {
929 elem[
"domain"] << integral->intRange();
932 if (
RooArgSet const *funcNormSet = integral->funcNormSet()) {
942 if (
auto convFunc = pdf->getPdfConvVar()) {
945 elem[
"conv_var"] << pdf->getConvVar().GetName();
946 elem[
"pdf1"] << pdf->getPdf1().GetName();
947 elem[
"pdf2"] << pdf->getPdf2().GetName();
948 elem[
"ipOrder"] << pdf->getInterpolationOrder();
956 if (
auto rangeName = pdf->getRangeName()) {
959 elem[
"pdf"] << pdf->pdf().GetName();
960 elem[
"norm"] << pdf->getN().GetName();
980 auto const *
rs =
static_cast<RooSpline const *
>(func);
985 elem[
"x"] <<
rs->x().GetName();
989 elem[
"interpolation"] << (
rs->order() == 5 ?
"poly5" :
"poly3");
990 elem[
"logx"] <<
rs->logx();
991 elem[
"logy"] <<
rs->logy();
995 auto &x0 =
elem[
"x0"].set_seq();
996 auto &
y0 =
elem[
"y0"].set_seq();
998 const int np =
sp.GetNp();
999 for (
int i = 0; i <
np; ++i) {
1000 double xk = 0.0,
yk = 0.0;
1002 x0.append_child() <<
xk;
1003 y0.append_child() <<
yk;
1011 if (node[
"type"].val() !=
"density_function_dist")
1017 bool selfNormalized =
false;
1019 if (
auto sn = node.find(
"selfNormalized"))
1020 selfNormalized =
sn->val_bool();
1032 node[
"type"] << key;
1040 node[
"function"] <<
funcProxy->absArg()->GetName();
1041 if (pdf->selfNormalized())
1042 node[
"selfnormalized"] <<
true;
1063 FuncExporter(std::string key) : _key{std::
move(key)} {}
1064 std::string
const &key()
const override {
return _key; }
1067 return Func(
tool, func,
elem, _key);
1071 const std::string _key;
bool endsWith(std::string_view str, std::string_view suffix)
std::string removeSuffix(std::string_view str, std::string_view suffix)
ROOT::RRangeCast< T, true, Range_t > dynamic_range_cast(Range_t &&coll)
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.
Calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
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.
Multivariate Gaussian p.d.f.
Holds the configuration parameters of the various numeric integrators used by RooRealIntegral.
Efficient implementation of a product of PDFs of the form.
Represents the product of a given set of RooAbsReal objects.
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.
The RooWrapperPdf is a class that can be used to convert a function into a PDF.
TClass instances represent classes, structs and namespaces in the ROOT type system.
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.
static bool registerImporter(const std::string &key, bool topPriority=true)
bool registerImporter(const std::string &key, std::unique_ptr< const Importer > f, bool topPriority=true)
static bool registerExporter(const TClass *key, bool topPriority=true)
bool registerExporter(const TClass *key, std::unique_ptr< const Exporter > f, bool topPriority=true)
#define STATIC_EXECUTE(MY_FUNC)