33#include <unordered_map>
38 unsigned int extraTopics,
unsigned int removeTopics,
bool overrideExternalLevel) {
41 if (overrideExternalLevel) msg.setGlobalKillBelow(lvl);
43 for (
int i = 0; i < msg.numStreams(); ++i) {
44 fOldConf.push_back(msg.getStream(i));
45 if (overrideExternalLevel) msg.getStream(i).minLevel = lvl;
47 msg.setStreamStatus(i,
true);
50 if (extraTopics != 0) {
59 for (
int i=0; i < msg.numStreams(); ++i) {
60 if (i <
static_cast<int>(
fOldConf.size()))
78 msg.setGlobalKillBelow(level);
80 std::vector<RooMsgService::StreamConfig> tmpStreams;
81 for (
int i = 0; i < msg.numStreams(); ++i) {
82 _oldConf.push_back(msg.getStream(i));
83 if (msg.getStream(i).match(level, topics,
static_cast<RooAbsArg*
>(
nullptr))) {
84 tmpStreams.push_back(msg.getStream(i));
85 msg.setStreamStatus(i,
false);
95 msg.addStream(st.minLevel,
109 for (
unsigned int i = 0; i <
_oldConf.size(); ++i) {
126 double min,
double max,
bool limitsInAllowedRange, std::string
const& extraMessage) {
127 const char openBr = limitsInAllowedRange ?
'[' :
'(';
128 const char closeBr = limitsInAllowedRange ?
']' :
')';
130 for (
auto parameter : pars) {
133 (par->getMin() < min || par->getMax() > max)
134 || (!limitsInAllowedRange && (par->getMin() == min || par->getMax() == max)) )) {
135 std::stringstream rangeMsg;
137 if (min > -std::numeric_limits<double>::max())
138 rangeMsg << min <<
", ";
140 rangeMsg <<
"-inf, ";
142 if (max < std::numeric_limits<double>::max())
143 rangeMsg << max << closeBr;
145 rangeMsg <<
"inf" << closeBr;
147 oocoutW(callingClass, InputArguments) <<
"The parameter '" << par->GetName() <<
"' with range [" << par->getMin(
"") <<
", "
148 << par->getMax() <<
"] of the " << callingClass->
ClassName() <<
" '" << callingClass->
GetName()
149 <<
"' exceeds the safe range of " << rangeMsg.str() <<
". Advise to limit its range."
150 << (!extraMessage.empty() ?
"\n" :
"") << extraMessage << std::endl;
157 std::pair<double, double> getBinningInterval(
RooAbsBinning const& binning) {
177 if (rangeName && rlv->hasRange(rangeName)) {
178 return {rlv->
getMin(rangeName), rlv->getMax(rangeName)};
179 }
else if (
auto binning = rlv->getBinningPtr(rangeName)) {
180 return getBinningInterval(*binning);
183 return {-std::numeric_limits<double>::infinity(), +std::numeric_limits<double>::infinity()};
193 std::vector<std::pair<double,double>> limits;
194 limits.reserve(rangeNames.size() * observables.
size());
196 for (
auto const& range : rangeNames) {
197 for (
auto const& obs : observables) {
201 limits.emplace_back(rlv->getMin(range.c_str()), rlv->getMax(range.c_str()));
203 throw std::logic_error(
"Classes that represent observables are expected to inherit from RooAbsRealLValue or RooAbsCategory!");
208 auto nRanges = rangeNames.size();
209 auto nObs = limits.size() / nRanges;
212 for(
size_t ir1 = 0; ir1 < nRanges; ++ir1) {
213 for(
size_t ir2 = ir1 + 1; ir2 < nRanges; ++ir2) {
219 for(
size_t io1 = 0; io1 < nObs; ++io1) {
220 auto r1 = limits[ir1 * nObs + io1];
221 auto r2 = limits[ir2 * nObs + io1];
222 overlaps += (r1.second > r2.first && r1.first < r2.second)
223 || (r2.second > r1.first && r2.first < r1.second);
225 if(overlaps == nObs)
return true;
241 for(
auto const& arg : tmp) {
242 content += arg->GetName();
245 if(!content.empty()) {
267 if (splitRange && !rangeName.empty()) {
270 for(std::string
const& token : tokens) {
271 out += token +
"_" + catName +
",";
288 if (component->getAttribute(
"BinnedLikelihood") && component->IsA()->InheritsFrom(
RooRealSumPdf::Class())) {
289 return {
static_cast<RooAbsPdf *
>(component),
true};
291 if (component->getAttribute(
"MAIN_MEASUREMENT")) {
293 return {
static_cast<RooAbsPdf *
>(component),
false};
297 return {
nullptr,
false};
319using ToCloneList = std::vector<RooAbsArg const *>;
320using ToCloneMap = std::unordered_map<TNamed const *, RooAbsArg const *>;
323void addServerClonesToList(
const RooAbsArg &var, ToCloneList &outlist, ToCloneMap &outmap,
bool deepCopy,
326 if (outmap.find(var.
namePtr()) != outmap.end()) {
335 outlist.push_back(&var);
338 for (
const auto server : var.servers()) {
339 addServerClonesToList(*server, outlist, outmap, deepCopy, observables);
356 ToCloneList toCloneList;
357 ToCloneMap toCloneMap;
359 addServerClonesToList(*orig, toCloneList, toCloneMap, deepCopy, observables);
363 output.reserve(toCloneList.size());
364 for (
RooAbsArg const *arg : toCloneList) {
365 std::unique_ptr<RooAbsArg> serverClone{
static_cast<RooAbsArg *
>(arg->Clone())};
367 output.addOwned(std::move(serverClone));
397 clonedNodes.
remove(*head);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
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.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
void treeNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool doBranch=true, bool doLeaf=true, bool valueOnly=false, bool recurseNonDerived=false) const
Fill supplied list with nodes of the arg tree, following all server links, starting with ourself as t...
RooAbsBinning is the 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.
A space to attach TBranches.
RooAbsCollection is an 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 sort(bool reverse=false)
Sort collection using std::sort and name comparison.
RooAbsArg * find(const char *name) const
Find object with given name in list.
TClass * IsA() const override
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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.
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
RooFit::MsgLevel _oldKillBelow
HijackMessageStream(RooFit::MsgLevel level, RooFit::MsgTopic topics, const char *objectName=nullptr)
Hijack all messages with given level and topics while this object is alive.
std::vector< RooMsgService::StreamConfig > _oldConf
~HijackMessageStream()
Deregister the hijacked stream and restore the stream state of all previous streams.
RooFit::MsgLevel fOldKillBelow
LocalChangeMsgLevel(RooFit::MsgLevel lvl=RooFit::DEBUG, unsigned int extraTopics=0u, unsigned int removeTopics=0u, bool overrideExternalLevel=true)
Change message level (and topics) while this object is alive, reset when it goes out of scope.
std::vector< RooMsgService::StreamConfig > fOldConf
static RooMsgService & instance()
Return reference to singleton instance.
RooProdPdf is an 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.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
RooCmdArg ClassName(const char *name)
RooCmdArg OutputStream(std::ostream &os)
RooCmdArg Topic(Int_t topic)
RooCmdArg TagName(const char *name)
RooCmdArg BaseClassName(const char *name)
RooCmdArg ObjectName(const char *name)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
MsgTopic
Topics for a RooMsgService::StreamConfig in RooMsgService.
RooAbsArg * cloneTreeWithSameParametersImpl(RooAbsArg const &arg, RooArgSet const *observables)
bool snapshotImpl(RooAbsCollection const &input, RooAbsCollection &output, bool deepCopy, RooArgSet const *observables)
Implementation of RooAbsCollection::snapshot() with some extra parameters.
void checkRangeOfParameters(const RooAbsReal *callingClass, std::initializer_list< const RooAbsReal * > pars, double min=-std::numeric_limits< double >::max(), double max=std::numeric_limits< double >::max(), bool limitsInAllowedRange=false, std::string const &extraMessage="")
Check if the parameters have a range, and warn if the range extends below / above the set limits.
BinnedLOutput getBinnedL(RooAbsPdf &pdf)
std::string getRangeNameForSimComponent(std::string const &rangeName, bool splitRange, std::string const &catName)
RooArgSet selectFromArgSet(RooArgSet const &, std::string const &names)
Construct a RooArgSet of objects in a RooArgSet whose names match to those in the names string.
void getSortedComputationGraph(RooAbsArg const &func, RooArgSet &out)
Get the topologically-sorted list of all nodes in the computation graph.
bool checkIfRangesOverlap(RooArgSet const &observables, std::vector< std::string > const &rangeNames)
Check if there is any overlap when a list of ranges is applied to a set of observables.
std::pair< double, double > getRangeOrBinningInterval(RooAbsArg const *arg, const char *rangeName)
Get the lower and upper bound of parameter range if arg can be casted to RooAbsRealLValue.
std::string getColonSeparatedNameString(RooArgSet const &argSet)
Create a string with all sorted names of RooArgSet elements separated by colons.