31#include <unordered_map>
36std::pair<double, double> getBinningInterval(
RooAbsBinning const &binning)
57 if (rangeName && rlv->hasRange(rangeName)) {
58 return {rlv->
getMin(rangeName), rlv->getMax(rangeName)};
59 }
else if (
auto binning = rlv->getBinningPtr(rangeName)) {
60 return getBinningInterval(*binning);
63 return {-std::numeric_limits<double>::infinity(), +std::numeric_limits<double>::infinity()};
72 std::vector<std::pair<double, double>> limits;
73 limits.reserve(rangeNames.size() * observables.
size());
75 for (
auto const &range : rangeNames) {
76 for (
auto const &obs : observables) {
80 limits.emplace_back(rlv->getMin(range.c_str()), rlv->getMax(range.c_str()));
82 throw std::logic_error(
83 "Classes that represent observables are expected to inherit from RooAbsRealLValue or RooAbsCategory!");
88 auto nRanges = rangeNames.size();
89 auto nObs = limits.size() / nRanges;
92 for (
size_t ir1 = 0; ir1 < nRanges; ++ir1) {
93 for (
size_t ir2 = ir1 + 1; ir2 < nRanges; ++ir2) {
99 for (
size_t io1 = 0; io1 < nObs; ++io1) {
100 auto r1 = limits[ir1 * nObs + io1];
101 auto r2 = limits[ir2 * nObs + io1];
103 (r1.second > r2.first && r1.first < r2.second) || (r2.second > r1.first && r2.first < r1.second);
105 if (overlaps == nObs)
122 for (
auto const &arg : tmp) {
126 if (!content.empty()) {
140 if (
auto arg = argSet.
find(
name.c_str()))
148 if (splitRange && !rangeName.empty()) {
151 for (std::string
const &token : tokens) {
152 out += token +
"_" + catName +
",";
165 return {
const_cast<RooAbsPdf *
>(&pdf),
true};
169 if (component->getAttribute(
"BinnedLikelihood") && component->IsA()->InheritsFrom(
RooRealSumPdf::Class())) {
170 return {
static_cast<RooAbsPdf *
>(component),
true};
172 if (component->getAttribute(
"MAIN_MEASUREMENT")) {
175 return {
static_cast<RooAbsPdf *
>(component),
false};
179 return {
nullptr,
false};
201using ToCloneList = std::vector<RooAbsArg const *>;
202using ToCloneMap = std::unordered_map<TNamed const *, RooAbsArg const *>;
205void addServerClonesToList(
const RooAbsArg &var, ToCloneList &outlist, ToCloneMap &outmap,
bool deepCopy,
208 if (outmap.find(var.
namePtr()) != outmap.end()) {
217 outlist.push_back(&var);
220 for (
const auto server : var.servers()) {
221 addServerClonesToList(*server, outlist, outmap, deepCopy, observables);
238 ToCloneList toCloneList;
239 ToCloneMap toCloneMap;
241 addServerClonesToList(*orig, toCloneList, toCloneMap, deepCopy, observables);
245 output.
reserve(toCloneList.size());
246 for (
RooAbsArg const *arg : toCloneList) {
247 std::unique_ptr<RooAbsArg> serverClone{
static_cast<RooAbsArg *
>(arg->
Clone())};
249 output.
addOwned(std::move(serverClone));
279 clonedNodes.
remove(*head);
295 const double fractions[] = {0.04, 0.27, 0.5, 0.73, 0.96};
297 const double savedVal = obs.
getVal();
300 for (std::size_t i = 0; i + 1 < boundaries.size() && isFlat; ++i) {
301 const double lo = boundaries[i];
302 const double hi = boundaries[i + 1];
303 double reference = 0.0;
307 const double val = function.
getVal();
313 const double scale = std::max(std::abs(reference), 1
e-12);
314 if (std::abs(val - reference) > relTol * scale) {
336 if (std::isdigit(in[0])) {
340 std::transform(out.begin(), out.end(), out.begin(), [](
char c) { return std::isalnum(c) ? c :
'_'; });
345void replaceAll(std::string &inOut, std::string_view
what, std::string_view with)
347 for (std::string::size_type pos{}; inOut.npos != (pos = inOut.find(
what.data(), pos,
what.length()));
348 pos += with.length()) {
349 inOut.replace(pos,
what.length(), with.data(), with.length());
355 std::stringstream cutString;
357 for (
RooAbsArg *sliceVar : sliceDataSet) {
365 cutString << real->GetName() <<
"==" << real->getVal();
367 cutString << cat->GetName() <<
"==" << cat->getCurrentIndex();
370 return cutString.str();
377double stringToDoubleImpl(std::stringstream &ss)
380 if (!(ss >> output)) {
381 throw std::invalid_argument(
"Conversion to floating point failed");
390 std::stringstream ss(s);
391 return stringToDoubleImpl(ss);
394double toDouble(
const std::string &s)
396 std::stringstream ss(s);
397 return stringToDoubleImpl(ss);
double toDouble(const char *s)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Common abstract base class for objects that represent a value and a "shape" in RooFit.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
void treeNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool doBranch=true, bool doLeaf=true, bool valueOnly=false, bool recurseFundamental=false) const
Fill supplied list with nodes of the arg tree, following all server links, starting with ourself as t...
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
bool redirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool isRecursionStep=false)
Replace all direct servers of this object with the new servers in newServerList.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Abstract base class for RooRealVar binning definitions.
virtual bool isParameterized() const
Interface function.
virtual double highBound() const =0
virtual double lowBound() const =0
virtual RooAbsReal * highBoundFunc() const
Return pointer to RooAbsReal parameterized upper bound, if any.
virtual RooAbsReal * lowBoundFunc() const
Return pointer to RooAbsReal parameterized lower bound, if any.
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
Abstract container object that can hold multiple RooAbsArg objects.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
void sortTopologically()
Sort collection topologically: the servers of any RooAbsArg will be before that RooAbsArg in the coll...
Storage_t::const_reverse_iterator rend() const
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::const_reverse_iterator rbegin() const
Storage_t::size_type size() const
void reserve(Storage_t::size_type count)
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract interface for all probability density functions.
TClass * IsA() const override
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual void setVal(double value)=0
Set the current value of the object. Needs to be overridden by implementations.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
Abstract base class for objects that represent a real value and implements functionality common to al...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Efficient implementation of a product of PDFs of the form.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
const char * GetName() const override
Returns name of object.
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
std::string makeValidVarName(std::string const &in)
void replaceAll(std::string &inOut, std::string_view what, std::string_view with)
std::string makeSliceCutString(RooArgSet const &sliceDataSet)
RooAbsArg * cloneTreeWithSameParametersImpl(RooAbsArg const &arg, RooArgSet const *observables)
bool snapshotImpl(RooAbsCollection const &input, RooAbsCollection &output, bool deepCopy, RooArgSet const *observables)
RooArgSet selectFromArgSet(RooArgSet const &, std::string const &names)
bool checkIfRangesOverlap(RooArgSet const &observables, std::vector< std::string > const &rangeNames)
bool isFunctionFlatInBins(const RooAbsReal &function, RooAbsRealLValue &obs, std::span< const double > boundaries, double relTol=1e-9)
Check that function is constant (flat) inside each bin defined by the sorted boundaries when scanning...
std::string getRangeNameForSimComponent(std::string const &rangeName, bool splitRange, std::string const &catName)
void getSortedComputationGraph(RooAbsArg const &func, RooArgSet &out)
BinnedLOutput getBinnedL(RooAbsPdf const &pdf)
std::string getColonSeparatedNameString(RooArgSet const &argSet, char delim=':')
std::pair< double, double > getRangeOrBinningInterval(RooAbsArg const *arg, const char *rangeName)