Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooFitImplHelpers.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 *
4 * Copyright (c) 2023, CERN
5 *
6 * Redistribution and use in source and binary forms,
7 * with or without modification, are permitted according to the terms
8 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
9 */
10
11#ifndef RooFit_RooFitImplHelpers_h
12#define RooFit_RooFitImplHelpers_h
13
14#include <RooAbsArg.h>
15#include <RooAbsPdf.h>
16#include <RooAbsReal.h>
17#include <RooMsgService.h>
18
19#include <RooNaNPacker.h>
20
21#include <TMath.h>
22
23#include <sstream>
24#include <string>
25#include <string_view>
26#include <utility>
27#include <vector>
28
29class RooAbsPdf;
30class RooAbsData;
31
32/// Disable all caches for sub-branches in an expression tree.
33/// This is helpful when an expression with cached sub-branches needs to be integrated numerically.
35public:
36 /// Inhibit all dirty-state propagation, and assume every node as dirty.
37 /// \param[in] oldState Restore this state when going out of scope.
39
42
44
45private:
47};
48
49/// Struct to temporarily change the operation mode of a RooAbsArg until it
50/// goes out of scope.
69
70namespace RooHelpers {
71
72std::pair<double, double> getRangeOrBinningInterval(RooAbsArg const *arg, const char *rangeName);
73
74bool checkIfRangesOverlap(RooArgSet const &observables, std::vector<std::string> const &rangeNames);
75
76std::string getColonSeparatedNameString(RooArgSet const &argSet, char delim = ':');
77RooArgSet selectFromArgSet(RooArgSet const &, std::string const &names);
78
79namespace Detail {
80
81bool snapshotImpl(RooAbsCollection const &input, RooAbsCollection &output, bool deepCopy, RooArgSet const *observables);
83
84} // namespace Detail
85
86/// Clone RooAbsArg object and reattach to original parameters.
87template <class T>
88std::unique_ptr<T> cloneTreeWithSameParameters(T const &arg, RooArgSet const *observables = nullptr)
89{
90 return std::unique_ptr<T>{static_cast<T *>(Detail::cloneTreeWithSameParametersImpl(arg, observables))};
91}
92
93std::string getRangeNameForSimComponent(std::string const &rangeName, bool splitRange, std::string const &catName);
94
96 RooAbsPdf *binnedPdf = nullptr;
97 bool isBinnedL = false;
98};
99
101
103
104} // namespace RooHelpers
105
106namespace RooFit::Detail {
107
108std::string makeValidVarName(std::string const &in);
109
110void replaceAll(std::string &inOut, std::string_view what, std::string_view with);
111
113
114// Inlined because this is called inside RooAbsPdf::getValV(), and therefore
115// performance critical.
116inline double normalizeWithNaNPacking(RooAbsPdf const &pdf, double rawVal, double normVal)
117{
118
119 if (normVal < 0. || (normVal == 0. && rawVal != 0)) {
120 // Unreasonable normalisations. A zero integral can be tolerated if the function vanishes, though.
121 const std::string msg = "p.d.f normalization integral is zero or negative: " + std::to_string(normVal);
122 pdf.logEvalError(msg.c_str());
123 return RooNaNPacker::packFloatIntoNaN(-normVal + (rawVal < 0. ? -rawVal : 0.));
124 }
125
126 if (rawVal < 0.) {
127 std::stringstream ss;
128 ss << "p.d.f value is less than zero (" << rawVal << "), trying to recover";
129 pdf.logEvalError(ss.str().c_str());
131 }
132
133 if (TMath::IsNaN(rawVal)) {
134 pdf.logEvalError("p.d.f value is Not-a-Number");
135 return rawVal;
136 }
137
138 return (rawVal == 0. && normVal == 0.) ? 0. : rawVal / normVal;
139}
140
141} // namespace RooFit::Detail
142
143double toDouble(const char *s);
144double toDouble(const std::string &s);
145
146#endif
double toDouble(const char *s)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Struct to temporarily change the operation mode of a RooAbsArg until it goes out of scope.
ChangeOperModeRAII(RooAbsArg *arg, RooAbsArg::OperMode opMode)
ChangeOperModeRAII & operator=(ChangeOperModeRAII &&other)=delete
ChangeOperModeRAII & operator=(ChangeOperModeRAII const &other)=delete
ChangeOperModeRAII(ChangeOperModeRAII &&other)=delete
RooAbsArg::OperMode _oldOpMode
ChangeOperModeRAII(ChangeOperModeRAII const &other)=delete
Disable all caches for sub-branches in an expression tree.
DisableCachingRAII(DisableCachingRAII const &other)=delete
DisableCachingRAII & operator=(DisableCachingRAII const &other)=delete
DisableCachingRAII(bool oldState)
Inhibit all dirty-state propagation, and assume every node as dirty.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
void setOperMode(OperMode mode, bool recurseADirty=true)
Set the operation mode of this node.
static void setDirtyInhibit(bool flag)
Control global dirty inhibit mode.
Abstract container object that can hold multiple RooAbsArg objects.
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:56
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
void logEvalError(const char *message, const char *serverValueString=nullptr) const
Log evaluation error message.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
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)
double normalizeWithNaNPacking(RooAbsPdf const &pdf, double rawVal, double normVal)
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)
std::unique_ptr< T > cloneTreeWithSameParameters(T const &arg, RooArgSet const *observables=nullptr)
Clone RooAbsArg object and reattach to original parameters.
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)
Bool_t IsNaN(Double_t x)
Definition TMath.h:903
static const char * what
Definition stlLoader.cc:5
static double packFloatIntoNaN(float payload)
Pack float into mantissa of a NaN.