84 return arg ==
"PI" || arg ==
"EULER" || arg ==
"TMath";
106 std::set<std::string> arguments;
108 for (
size_t i = 0; i <
expr.size(); ++i) {
120 if (
expr[i] ==
'(') {
127 arguments.insert(arg);
135 arguments.insert(arg);
143 std::string
in(
expr.Data());
145 out.reserve(
in.size());
147 for (std::size_t pos = 0; pos <
in.size();) {
150 pos > 0 && (std::isalnum(
static_cast<unsigned char>(
in[pos - 1])) ||
in[pos - 1] ==
'_');
151 const std::size_t end = pos +
identifier.size();
153 end <
in.size() && (std::isalnum(
static_cast<unsigned char>(
in[end])) ||
in[end] ==
'_');
158 out.push_back(
in[pos]);
179 value >
static_cast<double>(std::numeric_limits<int>::max())) {
182 return static_cast<int>(
value);
185std::unique_ptr<RooAbsBinning>
188 const std::string context =
"axis '" +
axisName +
"' of generic formula '" +
formulaName +
"'";
190 const bool hasMin = axis.
has_child(
"min");
191 const bool hasMax = axis.
has_child(
"max");
192 const bool hasNBins = axis.
has_child(
"nbins");
194 if (
hasEdges && (hasMin || hasMax || hasNBins)) {
204 std::vector<double> edges;
211 if (!std::isfinite(
edge)) {
214 if (!edges.empty() &&
edge <= edges.back()) {
217 edges.push_back(
edge);
219 if (edges.size() < 2) {
222 return std::make_unique<RooBinning>(
static_cast<int>(edges.size() - 1), edges.data());
225 if (!hasMin || !hasMax || !hasNBins) {
229 if (!axis[
"min"].is_number() || !axis[
"max"].is_number()) {
234 if (!std::isfinite(min) || !std::isfinite(max) || max <= min) {
237 return std::make_unique<RooUniformBinning>(min, max,
readPositiveInteger(axis[
"nbins"], context));
240template <
class RooArg_t>
247 const JSONNode &axes = node[
"axes"];
250 "' must be a sequence");
254 for (
const JSONNode &axis : axes.children()) {
257 "' must be a map with a \"name\"");
267 "axis '" +
axisName +
"' is not a real-valued formula variable of generic formula '" + arg.GetName() +
"'");
271 arg.setBinning(*observable, *binning,
false);
275template <
class RooArg_t>
279 if (!
p.has_child(
"expression")) {
282 TString formula(
p[
"expression"].val());
342template <
bool Div
ideByBinW
idth>
363 obs->GetName() +
"' as indicated by parent RooBinSamplingPdf '" +
name +
367 if (!
p.has_child(
"epsilon")) {
370 double epsilon(
p[
"epsilon"].val_double());
382 if (
p.has_child(
"extended") &&
p[
"extended"].val_bool()) {
398template <
class RooArg_t>
402 if (!
p.has_child(
"coefficients")) {
409 for (
const auto &coef :
p[
"coefficients"].children()) {
413 if (order == 0 && (coef.val() ==
"1.0" || coef.val() ==
"1")) {
415 }
else if (coefs.empty() && (coef.val() ==
"0.0" || coef.val() ==
"0")) {
475 if (
p.has_child(
"normalization")) {
482 domain =
p[
"domain"].val();
495 Int_t order =
p[
"order"].val_int();
496 double eps =
p[
"eps"].val_double();
497 if (
p.has_child(
"normalization")) {
511 Int_t order =
p[
"ipOrder"].val_int();
514 if (
p.has_child(
"conv_func")) {
528 if (
p.has_child(
"range")) {
544 const std::string
muName =
p[
"mu"].val();
545 const std::string
sigmaName =
p[
"sigma"].val();
605 bool has_cov =
p.has_child(
"covariances");
606 bool has_corr =
p.has_child(
"correlations") &&
p.has_child(
"standard_deviations");
614 int n =
p[
"covariances"].num_children();
617 for (
const auto &row :
p[
"covariances"].children()) {
619 for (
const auto &val : row.children()) {
620 covmat(i,
j) = val.val_double();
627 for (
const auto &
v :
p[
"standard_deviations"].children()) {
632 for (
const auto &row :
p[
"correlations"].children()) {
634 for (
const auto &val : row.children()) {
649 std::map<std::string, std::unique_ptr<RooRealVar>>
varMap;
653 const std::string
name = node[
"name"].
val();
654 std::unique_ptr<RooRealVar> obs;
657 std::vector<double> edges;
658 for (
const auto &
bound : node[
"edges"].children()) {
659 edges.push_back(
bound.val_double());
661 obs = std::make_unique<RooRealVar>(
name.c_str(),
name.c_str(), edges.front(), edges.back());
662 RooBinning bins(obs->getMin(), obs->getMax());
665 obs->setBinning(bins);
667 obs = std::make_unique<RooRealVar>(
name.c_str(),
name.c_str(), node[
"min"].val_double(),
668 node[
"max"].val_double());
669 obs->setBins(node[
"nbins"].val_int());
683 vars.
addOwned(std::move(it->second));
691 if (!
p.has_child(
"parameters")) {
696 if (!
p.has_child(
"axes")) {
697 std::stringstream
ss;
698 ss <<
"No axes given in '" <<
name <<
"'"
699 <<
". Using default binning (uniform; nbins=100). If needed, export the Workspace to JSON with a newer "
700 <<
"Root version that supports custom ParamHistFunc binnings(>=6.38.00)." << std::endl;
714 if (!
p.has_child(
"x")) {
717 if (!
p.has_child(
"x0") || !
p.has_child(
"y0")) {
724 std::string
algo =
p.has_child(
"interpolation") ?
p[
"interpolation"].val() :
"poly3";
728 else if (
algo ==
"poly5")
732 "': allowed are 'poly3' and 'poly5'");
734 const bool logx =
p.has_child(
"logx") ?
p[
"logx"].val_bool() :
false;
735 const bool logy =
p.has_child(
"logy") ?
p[
"logy"].val_bool() :
false;
738 std::vector<double> x0;
739 std::vector<double>
y0;
740 x0.reserve(
p[
"x0"].num_children());
741 y0.reserve(
p[
"y0"].num_children());
743 for (
const auto &
v :
p[
"x0"].children())
744 x0.push_back(
v.val_double());
745 for (
const auto &
v :
p[
"y0"].children())
746 y0.push_back(
v.val_double());
748 if (x0.size() !=
y0.size()) {
750 ", y0 has " + std::to_string(
y0.size()));
758 std::span<const double>(
y0.data(),
y0.size()), order, logx, logy);
766template <
class RooArg_t>
773 elem[
"extended"] << (pdf->extendMode() != RooArg_t::CanNotBeExtended);
796template <
class RooArg_t>
802 tool->exportHisto(*
dh.get(),
dh.numEntries(),
dh.weightArray(),
elem[
"data"].set_map());
806template <
class RooArg_t>
810 if (!
p.has_child(
"data")) {
813 std::unique_ptr<RooDataHist> dataHist =
823 elem[
"pdf"] << pdf->
pdf().GetName();
869template <
class RooArg_t>
874 TString expression(pdf->expression());
882 for (
size_t idx = pdf->nParameters(); idx--;) {
883 const RooAbsArg *par = pdf->getParameter(idx);
884 expression.ReplaceAll((
"x[" + std::to_string(idx) +
"]").c_str(), par->
GetName());
885 expression.ReplaceAll((
"@" + std::to_string(idx)).c_str(), par->
GetName());
887 elem[
"expression"] << expression.Data();
899 auto &axes =
elem[
"axes"];
904 axis[
"name"] << observable->GetName();
916 elem[
"x"] << pdf->x().GetName();
917 auto &coefs =
elem[
"coefficients"].set_seq();
918 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
919 coefs.append_child() << (i == 0 ? 1.0 : 0.0);
921 for (
const auto &coef : pdf->coefList()) {
922 coefs.append_child() << coef->GetName();
926template <
class RooArg_t>
936 auto *pdf =
static_cast<const RooPoisson *
>(func);
938 elem[
"x"] << pdf->getX().GetName();
939 elem[
"mean"] << pdf->getMean().GetName();
940 elem[
"integer"] << !pdf->getNoRounding();
946 auto *pdf =
static_cast<const RooDecay *
>(func);
948 elem[
"t"] << pdf->getT().GetName();
949 elem[
"tau"] << pdf->getTau().GetName();
950 elem[
"resolutionModel"] << pdf->getModel().GetName();
951 elem[
"decayType"] << pdf->getDecayType();
960 elem[
"x"] << pdf->convVar().GetName();
969 elem[
"x"] << pdf->convVar().GetName();
970 elem[
"mean"] << pdf->getMean().GetName();
971 elem[
"sigma"] << pdf->getSigma().GetName();
980 elem[
"x"] << pdf->getX().GetName();
982 auto &m0 = pdf->getMedian();
983 auto &k = pdf->getShapeK();
985 if (pdf->useStandardParametrization()) {
986 elem[
"mu"] << m0.GetName();
987 elem[
"sigma"] << k.GetName();
989 elem[
"mu"] <<
tool->exportTransformed(&m0,
"_lognormal_log",
"log(%s)");
990 elem[
"sigma"] <<
tool->exportTransformed(&k,
"_lognormal_log",
"log(%s)");
1000 elem[
"x"] << pdf->variable().GetName();
1001 auto &
c = pdf->coefficient();
1002 if (pdf->negateCoefficient()) {
1003 elem[
"c"] <<
c.GetName();
1005 elem[
"c"] <<
tool->exportTransformed(&
c,
"_exponential_inverted",
"-%s");
1014 elem[
"type"] << key;
1017 elem[
"covariances"].fill_mat(pdf->covarianceMatrix());
1024 elem[
"type"] << key;
1026 TString formula(pdf->function().GetExpFormula());
1027 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
1028 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
1029 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
1030 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
1032 formula.ReplaceAll(
pname, pdf->parameters()[i].GetName());
1034 elem[
"expression"] << formula.Data();
1041 elem[
"type"] << key;
1042 elem[
"x"] << pdf->getX().GetName();
1043 elem[
"function"] << pdf->getFunc().GetName();
1044 if (!pdf->getNset().empty()) {
1047 elem[
"order"] << pdf->order();
1048 elem[
"eps"] << pdf->eps();
1055 elem[
"type"] << key;
1056 std::string integrand = integral->integrand().GetName();
1057 elem[
"integrand"] << integrand;
1058 if (integral->intRange()) {
1059 elem[
"domain"] << integral->intRange();
1062 if (
RooArgSet const *funcNormSet = integral->funcNormSet()) {
1071 elem[
"type"] << key;
1072 if (
auto convFunc = pdf->getPdfConvVar()) {
1075 elem[
"conv_var"] << pdf->getConvVar().GetName();
1076 elem[
"pdf1"] << pdf->getPdf1().GetName();
1077 elem[
"pdf2"] << pdf->getPdf2().GetName();
1078 elem[
"ipOrder"] << pdf->getInterpolationOrder();
1085 elem[
"type"] << key;
1086 if (
auto rangeName = pdf->getRangeName()) {
1089 elem[
"pdf"] << pdf->pdf().GetName();
1090 elem[
"norm"] << pdf->getN().GetName();
1097 elem[
"type"] << key;
1110 auto const *
rs =
static_cast<RooSpline const *
>(func);
1112 elem[
"type"] << key;
1115 elem[
"x"] <<
rs->x().GetName();
1119 elem[
"interpolation"] << (
rs->order() == 5 ?
"poly5" :
"poly3");
1120 elem[
"logx"] <<
rs->logx();
1121 elem[
"logy"] <<
rs->logy();
1125 auto &x0 =
elem[
"x0"].set_seq();
1126 auto &
y0 =
elem[
"y0"].set_seq();
1128 const int np =
sp.GetNp();
1129 for (
int i = 0; i <
np; ++i) {
1130 double xk = 0.0,
yk = 0.0;
1132 x0.append_child() <<
xk;
1133 y0.append_child() <<
yk;
1141 if (node[
"type"].val() !=
"density_function_dist")
1147 bool selfNormalized =
false;
1149 if (
auto sn = node.find(
"selfNormalized"))
1150 selfNormalized =
sn->val_bool();
1162 node[
"type"] << key;
1170 node[
"function"] <<
funcProxy->absArg()->GetName();
1171 if (pdf->selfNormalized())
1172 node[
"selfnormalized"] <<
true;
1193 FuncExporter(std::string key) : _key{std::
move(key)} {}
1194 std::string
const &key()
const override {
return _key; }
1197 return Func(
tool, func,
elem, _key);
1201 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)
void writeAxisBinning(JSONNode &node, const RooAbsBinning &binning)
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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.
Abstract base class for RooRealVar binning definitions.
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 that may appear on the left hand side of ...
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.
virtual std::string val() const =0
virtual double val_double() const
virtual JSONNode & append_child()=0
virtual JSONNode & set_seq()=0
virtual bool is_seq() const =0
virtual bool is_map() const =0
virtual bool has_child(std::string const &) const =0
virtual bool is_number() const
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)