82 return arg ==
"PI" || arg ==
"EULER" || arg ==
"TMath";
104 std::set<std::string> arguments;
106 for (
size_t i = 0; i <
expr.size(); ++i) {
118 if (
expr[i] ==
'(') {
125 arguments.insert(arg);
133 arguments.insert(arg);
141 std::string in(
expr.Data());
143 out.reserve(in.size());
145 for (std::size_t pos = 0; pos < in.size();) {
148 pos > 0 && (std::isalnum(
static_cast<unsigned char>(in[pos - 1])) || in[pos - 1] ==
'_');
149 const std::size_t end = pos +
identifier.size();
151 end < in.size() && (std::isalnum(
static_cast<unsigned char>(in[end])) || in[end] ==
'_');
156 out.push_back(in[pos]);
177 value >
static_cast<double>(std::numeric_limits<int>::max())) {
180 return static_cast<int>(
value);
183std::unique_ptr<RooAbsBinning>
186 const std::string context =
"axis '" +
axisName +
"' of generic formula '" +
formulaName +
"'";
188 const bool hasMin = axis.
has_child(
"min");
189 const bool hasMax = axis.
has_child(
"max");
190 const bool hasNBins = axis.
has_child(
"nbins");
192 if (
hasEdges && (hasMin || hasMax || hasNBins)) {
202 std::vector<double> edges;
209 if (!std::isfinite(
edge)) {
212 if (!edges.empty() &&
edge <= edges.back()) {
215 edges.push_back(
edge);
217 if (edges.size() < 2) {
220 return std::make_unique<RooBinning>(
static_cast<int>(edges.size() - 1), edges.data());
223 if (!hasMin || !hasMax || !hasNBins) {
227 if (!axis[
"min"].is_number() || !axis[
"max"].is_number()) {
232 if (!std::isfinite(min) || !std::isfinite(max) || max <= min) {
235 return std::make_unique<RooUniformBinning>(min, max,
readPositiveInteger(axis[
"nbins"], context));
238template <
class RooArg_t>
245 const JSONNode &axes = node[
"axes"];
248 "' must be a sequence");
252 for (
const JSONNode &axis : axes.children()) {
255 "' must be a map with a \"name\"");
265 "axis '" +
axisName +
"' is not a real-valued formula variable of generic formula '" + arg.GetName() +
"'");
269 arg.setBinning(*observable, *binning,
false);
273template <
class RooArg_t>
277 if (!
p.has_child(
"expression")) {
340template <
bool Div
ideByBinW
idth>
361 obs->GetName() +
"' as indicated by parent RooBinSamplingPdf '" +
name +
365 if (!
p.has_child(
"epsilon")) {
368 double epsilon(
p[
"epsilon"].val_double());
375template <
class RooArg_t>
381 if constexpr (std::is_same_v<RooArg_t, RooRealSumPdf>) {
382 const bool extended =
p.has_child(
"extended") &&
p[
"extended"].val_bool();
390template <
class RooArg_t>
394 if (!
p.has_child(
"coefficients")) {
401 for (
const auto &coef :
p[
"coefficients"].children()) {
405 if (order == 0 && (coef.val() ==
"1.0" || coef.val() ==
"1")) {
407 }
else if (coefs.empty() && (coef.val() ==
"0.0" || coef.val() ==
"0")) {
467 if (
p.has_child(
"normalization")) {
487 Int_t order =
p[
"order"].val_int();
488 double eps =
p[
"eps"].val_double();
489 if (
p.has_child(
"normalization")) {
503 Int_t order =
p[
"ipOrder"].val_int();
506 if (
p.has_child(
"conv_func")) {
520 if (
p.has_child(
"range")) {
536 const std::string
muName =
p[
"mu"].val();
537 const std::string
sigmaName =
p[
"sigma"].val();
597 bool has_cov =
p.has_child(
"covariances");
598 bool has_corr =
p.has_child(
"correlations") &&
p.has_child(
"standard_deviations");
606 int n =
p[
"covariances"].num_children();
609 for (
const auto &row :
p[
"covariances"].children()) {
611 for (
const auto &val : row.children()) {
612 covmat(i,
j) = val.val_double();
622 for (
const auto &row :
p[
"correlations"].children()) {
624 for (
const auto &val : row.children()) {
651 if (!
p.has_child(
"parameters")) {
656 if (!
p.has_child(
"axes")) {
657 std::stringstream
ss;
658 ss <<
"No axes given in '" <<
name <<
"'"
659 <<
". Using default binning (uniform; nbins=100). If needed, export the Workspace to JSON with a newer "
660 <<
"Root version that supports custom ParamHistFunc binnings(>=6.38.00)." << std::endl;
674 if (!
p.has_child(
"x")) {
677 if (!
p.has_child(
"x0") || !
p.has_child(
"y0")) {
684 std::string
algo =
p.has_child(
"interpolation") ?
p[
"interpolation"].val() :
"poly3";
688 else if (
algo ==
"poly5")
692 "': allowed are 'poly3' and 'poly5'");
694 const bool logx =
p.has_child(
"logx") ?
p[
"logx"].val_bool() :
false;
695 const bool logy =
p.has_child(
"logy") ?
p[
"logy"].val_bool() :
false;
698 std::vector<double> x0;
699 std::vector<double>
y0;
703 if (x0.size() !=
y0.size()) {
705 ", y0 has " + std::to_string(
y0.size()));
713 std::span<const double>(
y0.data(),
y0.size()), order, logx, logy);
721template <
class RooArg_t>
728 elem[
"extended"] << (pdf->extendMode() != RooArg_t::CanNotBeExtended);
732template <
class RooArg_t>
735 auto const *pdf =
static_cast<const RooArg_t *
>(func);
739 if constexpr (std::is_same_v<RooArg_t, RooRealSumPdf>) {
745template <
class RooArg_t>
751 tool->exportHisto(*
dh.get(),
dh.numEntries(),
dh.weightArray(),
elem[
"data"].set_map());
755template <
class RooArg_t>
759 if (!
p.has_child(
"data")) {
762 std::unique_ptr<RooDataHist> dataHist =
772 elem[
"pdf"] << pdf->
pdf().GetName();
818template <
class RooArg_t>
823 TString expression(pdf->expression());
831 for (
size_t idx = pdf->nParameters(); idx--;) {
832 const RooAbsArg *par = pdf->getParameter(idx);
833 expression.ReplaceAll((
"x[" + std::to_string(idx) +
"]").c_str(), par->
GetName());
834 expression.ReplaceAll((
"@" + std::to_string(idx)).c_str(), par->
GetName());
836 elem[
"expression"] << expression.Data();
848 auto &axes =
elem[
"axes"];
849 if (!axes.is_seq()) {
852 auto &axis = axes.append_child().set_map();
853 axis[
"name"] << observable->GetName();
862template <
class RooArg_t>
865 auto const *pdf =
static_cast<const RooArg_t *
>(func);
867 elem[
"x"] << pdf->x().GetName();
868 auto &coefs =
elem[
"coefficients"].set_seq();
869 for (
int i = 0; i < pdf->lowestOrder(); ++i) {
870 coefs.append_child() << (i == 0 ? 1.0 : 0.0);
872 for (
const auto &coef : pdf->coefList()) {
873 coefs.append_child() << coef->GetName();
880 auto *pdf =
static_cast<const RooPoisson *
>(func);
882 elem[
"x"] << pdf->getX().GetName();
883 elem[
"mean"] << pdf->getMean().GetName();
884 elem[
"integer"] << !pdf->getNoRounding();
894 auto *pdf =
static_cast<const RooDecay *
>(func);
896 elem[
"t"] << pdf->getT().GetName();
897 elem[
"tau"] << pdf->getTau().GetName();
898 elem[
"resolutionModel"] << pdf->getModel().GetName();
899 elem[
"decayType"] << pdf->getDecayType();
901 tool->queueExport(pdf->getT());
902 tool->queueExport(pdf->getTau());
903 tool->queueExport(pdf->getModel());
912 elem[
"x"] << pdf->convVar().GetName();
921 elem[
"x"] << pdf->convVar().GetName();
922 elem[
"mean"] << pdf->getMean().GetName();
923 elem[
"sigma"] << pdf->getSigma().GetName();
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)");
952 elem[
"x"] << pdf->variable().GetName();
953 auto &
c = pdf->coefficient();
954 if (pdf->negateCoefficient()) {
955 elem[
"c"] <<
c.GetName();
957 elem[
"c"] <<
tool->exportTransformed(&
c,
"_exponential_inverted",
"-%s");
969 elem[
"covariances"].fill_mat(pdf->covarianceMatrix());
979 formula.ReplaceAll(
"x", pdf->observables()[0].GetName());
980 formula.ReplaceAll(
"y", pdf->observables()[1].GetName());
981 formula.ReplaceAll(
"z", pdf->observables()[2].GetName());
982 for (
size_t i = 0; i < pdf->parameters().
size(); ++i) {
984 formula.ReplaceAll(
pname, pdf->parameters()[i].GetName());
994 elem[
"x"] << pdf->getX().GetName();
995 elem[
"function"] << pdf->getFunc().GetName();
996 if (!pdf->getNset().empty()) {
999 elem[
"order"] << pdf->order();
1000 elem[
"eps"] << pdf->eps();
1007 elem[
"type"] << key;
1008 std::string integrand = integral->integrand().GetName();
1009 elem[
"integrand"] << integrand;
1010 if (integral->intRange()) {
1011 elem[
"domain"] << integral->intRange();
1014 if (
RooArgSet const *funcNormSet = integral->funcNormSet()) {
1023 elem[
"type"] << key;
1024 if (
auto convFunc = pdf->getPdfConvVar()) {
1027 elem[
"conv_var"] << pdf->getConvVar().GetName();
1028 elem[
"pdf1"] << pdf->getPdf1().GetName();
1029 elem[
"pdf2"] << pdf->getPdf2().GetName();
1030 elem[
"ipOrder"] << pdf->getInterpolationOrder();
1037 elem[
"type"] << key;
1038 if (
auto rangeName = pdf->getRangeName()) {
1041 elem[
"pdf"] << pdf->pdf().GetName();
1042 elem[
"norm"] << pdf->getN().GetName();
1049 elem[
"type"] << key;
1062 auto const *
rs =
static_cast<RooSpline const *
>(func);
1064 elem[
"type"] << key;
1067 elem[
"x"] <<
rs->x().GetName();
1071 elem[
"interpolation"] << (
rs->order() == 5 ?
"poly5" :
"poly3");
1072 elem[
"logx"] <<
rs->logx();
1073 elem[
"logy"] <<
rs->logy();
1077 auto &x0 =
elem[
"x0"].set_seq();
1078 auto &
y0 =
elem[
"y0"].set_seq();
1080 const int np =
sp.GetNp();
1081 for (
int i = 0; i <
np; ++i) {
1082 double xk = 0.0,
yk = 0.0;
1084 x0.append_child() <<
xk;
1085 y0.append_child() <<
yk;
1093 if (node[
"type"].val() !=
"density_function_dist")
1099 bool selfNormalized =
false;
1101 auto sn = node.find(
"self_normalized");
1104 sn = node.find(
"selfnormalized");
1106 selfNormalized =
sn->val_bool();
1118 node[
"type"] << key;
1126 node[
"function"] <<
funcProxy->absArg()->GetName();
1127 if (pdf->selfNormalized())
1128 node[
"self_normalized"] <<
true;
1149 FuncExporter(std::string key,
bool autoExportDependants)
1150 : _key{std::
move(key)}, _autoExportDependants{autoExportDependants}
1153 std::string
const &key()
const override {
return _key; }
1154 bool autoExportDependants()
const override {
return _autoExportDependants; }
1157 return Func(
tool, func,
elem, _key);
1161 const std::string _key;
1162 const bool _autoExportDependants;
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, 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 RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
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
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 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.
Implements a PDF constructed from a sum of functions:
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)