Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions roofit/xroofit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitXRooFit
src/xRooNLLVar.cxx
src/xRooNode.cxx
src/xRooNode_interactive.cxx
src/PythonInterface.cxx
DICTIONARY_OPTIONS
"-writeEmptyRootPCM"
DEPENDENCIES
Expand Down
20 changes: 14 additions & 6 deletions roofit/xroofit/inc/RooFit/xRooFit/xRooNLLVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class xRooNLLVar : public std::shared_ptr<RooAbsReal> {
xValueWithError(const std::pair<double, double> &in = {0, 0}) : std::pair<double, double>(in) {}
double value() const { return std::pair<double, double>::first; }
double error() const { return std::pair<double, double>::second; }
std::string __repr__() const { return Form("%g +/- %g", value(), error()); }
};

void Print(Option_t *opt = "");
Expand Down Expand Up @@ -405,8 +406,8 @@ class xRooNLLVar : public std::shared_ptr<RooAbsReal> {
double alt_value = std::numeric_limits<double>::quiet_NaN(),
const xRooFit::Asymptotics::PLLType &pllType = xRooFit::Asymptotics::Unknown);
xRooHypoSpace hypoSpace(const char *parName, xRooFit::TestStatistic::Type tsType, int nPoints = 0,
double low = -std::numeric_limits<double>::infinity(),
double high = std::numeric_limits<double>::infinity(),
double low = std::numeric_limits<double>::quiet_NaN(),
double high = std::numeric_limits<double>::quiet_NaN(),
double alt_value = std::numeric_limits<double>::quiet_NaN())
{
return hypoSpace(parName, nPoints, low, high, alt_value, xRooFit::Asymptotics::Unknown, tsType);
Expand Down Expand Up @@ -511,11 +512,18 @@ class xRooNLLVar : public std::shared_ptr<RooAbsReal> {
bool kReuseNLL = true;
};

END_XROOFIT_NAMESPACE

#ifndef XROOFIT_NAMESPACE_NAME
#ifdef XROOFIT_NAMESPACE
#define XROOFIT_NAMESPACE_NAME XROOFIT_NAMESPACE
#else
#define XROOFIT_NAMESPACE_NAME
#endif
#endif
namespace cling {
std::string printValue(const xRooNLLVar::xValueWithError *val);
std::string printValue(const std::map<std::string, xRooNLLVar::xValueWithError> *m);
std::string printValue(const XROOFIT_NAMESPACE_NAME::xRooNLLVar::xValueWithError *val);
std::string printValue(const std::map<std::string, XROOFIT_NAMESPACE_NAME::xRooNLLVar::xValueWithError> *m);
} // namespace cling

END_XROOFIT_NAMESPACE

#endif // include guard
35 changes: 31 additions & 4 deletions roofit/xroofit/inc/RooFit/xRooFit/xRooNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,23 @@ class xRooNode : public TNamed, public std::vector<std::shared_ptr<xRooNode>> {
return aa == bb;
};
};
auto begin() const -> xRooNodeIterator { return xRooNodeIterator(std::vector<std::shared_ptr<xRooNode>>::begin()); }
auto begin() const -> xRooNodeIterator
{
// this update is to resolve need for calling browse() before iterating, e.g.
// for(auto a : xRooNode(b).browse()) ...
// can now become the more natural:
// for(auto a : xRooNode(b)) ...
// but would still need e.g. xRooNode(s).browse().size() rather than xRooNode(s).size() which would give 0 for
// unpopulated case
static bool browseLock =
false; // need for blocking recursive calls to browse (since browse method uses the iterators)
if (!browseLock && get() && empty()) {
browseLock = true;
const_cast<xRooNode &>(*this).browse();
browseLock = false;
}
return xRooNodeIterator(std::vector<std::shared_ptr<xRooNode>>::begin());
}
auto end() const -> xRooNodeIterator { return xRooNodeIterator(std::vector<std::shared_ptr<xRooNode>>::end()); }

// needed in pyROOT to avoid it creating iterators that follow the 'get' to death
Expand Down Expand Up @@ -312,6 +328,9 @@ class xRooNode : public TNamed, public std::vector<std::shared_ptr<xRooNode>> {
xRooNode datasets()
const; // datasets corresponding to this pdf (parent nodes that do observable selections automatically applied)

xRooNode parents() const; // the clients of this node
xRooNode args() const; // all the nodes underneath this node

xRooNode Replace(const xRooNode &node); // use to replace a node in the tree at the location of this node
xRooNode Remove(const xRooNode &child);
xRooNode
Expand All @@ -326,6 +345,7 @@ class xRooNode : public TNamed, public std::vector<std::shared_ptr<xRooNode>> {

xRooNode reduced(const std::string &range = "", bool invert = false)
const; // return a node representing reduced version of this node, will use the SetRange to reduce if blank
xRooNode reduced(const std::function<bool(const xRooNode &)> selector) const;

// following versions are for the menu in the GUI
/** @private */
Expand Down Expand Up @@ -537,10 +557,17 @@ class xRooNode : public TNamed, public std::vector<std::shared_ptr<xRooNode>> {
ClassDefOverride(xRooNode, 0)
};

END_XROOFIT_NAMESPACE

#ifndef XROOFIT_NAMESPACE_NAME
#ifdef XROOFIT_NAMESPACE
#define XROOFIT_NAMESPACE_NAME XROOFIT_NAMESPACE
#else
#define XROOFIT_NAMESPACE_NAME
#endif
#endif
namespace cling {
std::string printValue(const xRooNode *val);
std::string printValue(const XROOFIT_NAMESPACE_NAME::xRooNode *val);
}

END_XROOFIT_NAMESPACE

#endif // include guard
30 changes: 30 additions & 0 deletions roofit/xroofit/src/PythonInterface.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "./PythonInterface.h"

#include <TSystem.h>

namespace xPython {

// https://docs.python.org/3.11/c-api/init.html#c.Py_IsInitialized
bool isPythonInitialized() {
using fn_t = int (*)();
static auto f = reinterpret_cast<fn_t>(gSystem->DynFindSymbol("*", "Py_IsInitialized"));
return f && f();
}

// https://docs.python.org/3/c-api/sys.html#c.PySys_WriteStdout
void writeStdoutLine(const char *msg) {
using fn_t = void (*)(const char *, ...);
static auto f = reinterpret_cast<fn_t>(gSystem->DynFindSymbol("*", "PySys_WriteStdout"));
if (f)
f("%s\n", msg);
}

// https://docs.python.org/3/c-api/sys.html#c.PySys_WriteStderr
void writeStderrLine(const char *msg) {
using fn_t = void (*)(const char *, ...);
static auto f = reinterpret_cast<fn_t>(gSystem->DynFindSymbol("*", "PySys_WriteStderr"));
if (f)
f("%s\n", msg);
}

} // namespace xPython
18 changes: 18 additions & 0 deletions roofit/xroofit/src/PythonInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef xRooFit_PythonInterface_h
#define xRooFit_PythonInterface_h

// Helper functions to use the Python C API without introducint a link-time
// dependency on libpython. These are intended to be used only when xRooFit is
// used from Python, where libpython is loaded by default and the required
// symbols can be found with gSystem.

namespace xPython {

bool isPythonInitialized();

// Don't call these other functions if Python is not initialized!
void writeStdoutLine(const char *msg);
void writeStderrLine(const char *msg);
} // namespace xPython

#endif
Loading
Loading