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.
52public:
54 {
55 arg->setOperMode(opMode, /*recurse=*/false);
56 }
57
60
61 ~ChangeOperModeRAII() { _arg->setOperMode(_oldOpMode, /*recurse=*/false); }
62
63private:
64 RooAbsArg *_arg = nullptr;
66};
67
68namespace RooHelpers {
69
70std::pair<double, double> getRangeOrBinningInterval(RooAbsArg const *arg, const char *rangeName);
71
72bool checkIfRangesOverlap(RooArgSet const &observables, std::vector<std::string> const &rangeNames);
73
74std::string getColonSeparatedNameString(RooArgSet const &argSet, char delim = ':');
75RooArgSet selectFromArgSet(RooArgSet const &, std::string const &names);
76
77namespace Detail {
78
81
82} // namespace Detail
83
84/// Clone RooAbsArg object and reattach to original parameters.
85template <class T>
86std::unique_ptr<T> cloneTreeWithSameParameters(T const &arg, RooArgSet const *observables = nullptr)
87{
88 return std::unique_ptr<T>{static_cast<T *>(Detail::cloneTreeWithSameParametersImpl(arg, observables))};
89}
90
91std::string getRangeNameForSimComponent(std::string const &rangeName, bool splitRange, std::string const &catName);
92
94 RooAbsPdf *binnedPdf = nullptr;
95 bool isBinnedL = false;
96};
97
99
101
102} // namespace RooHelpers
103
104namespace RooFit::Detail {
105
106std::string makeValidVarName(std::string const &in);
107
108void replaceAll(std::string &inOut, std::string_view what, std::string_view with);
109
111
112// Inlined because this is called inside RooAbsPdf::getValV(), and therefore
113// performance critical.
114inline double normalizeWithNaNPacking(RooAbsPdf const &pdf, double rawVal, double normVal)
115{
116
117 if (normVal < 0. || (normVal == 0. && rawVal != 0)) {
118 // Unreasonable normalisations. A zero integral can be tolerated if the function vanishes, though.
119 const std::string msg = "p.d.f normalization integral is zero or negative: " + std::to_string(normVal);
120 pdf.logEvalError(msg.c_str());
121 return RooNaNPacker::packFloatIntoNaN(-normVal + (rawVal < 0. ? -rawVal : 0.));
122 }
123
124 if (rawVal < 0.) {
125 std::stringstream ss;
126 ss << "p.d.f value is less than zero (" << rawVal << "), trying to recover";
127 pdf.logEvalError(ss.str().c_str());
129 }
130
131 if (TMath::IsNaN(rawVal)) {
132 pdf.logEvalError("p.d.f value is Not-a-Number");
133 return rawVal;
134 }
135
136 return (rawVal == 0. && normVal == 0.) ? 0. : rawVal / normVal;
137}
138
139} // namespace RooFit::Detail
140
141double toDouble(const char *s);
142double toDouble(const std::string &s);
143
144#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 const &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.
static void output()