Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
rf901_numintconfig.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -nodraw
4/// Numeric algorithm tuning: configuration and customization of how numeric (partial) integrals are executed
5///
6/// \macro_code
7/// \macro_output
8///
9/// \date July 2008
10/// \author Wouter Verkerke
11
12#include "RooRealVar.h"
13#include "RooDataSet.h"
14#include "RooGaussian.h"
15#include "RooConstVar.h"
16#include "TCanvas.h"
17#include "TAxis.h"
18#include "RooPlot.h"
19#include "RooNumIntConfig.h"
20#include "RooLandau.h"
21#include "RooArgSet.h"
22#include <iomanip>
23using namespace RooFit;
24
26{
27
28 // A d j u s t g l o b a l 1 D i n t e g r a t i o n p r e c i s i o n
29 // ----------------------------------------------------------------------------
30
31 // Print current global default configuration for numeric integration strategies
33
34 // Example: Change global precision for 1D integrals from 1e-7 to 1e-6
35 //
36 // The relative epsilon (change as fraction of current best integral estimate) and
37 // absolute epsilon (absolute change w.r.t last best integral estimate) can be specified
38 // separately. For most pdf integrals the relative change criterium is the most important,
39 // however for certain non-pdf functions that integrate out to zero a separate absolute
40 // change criterium is necessary to declare convergence of the integral
41 //
42 // NB: This change is for illustration only. In general the precision should be at least 1e-7
43 // for normalization integrals for MINUIT to succeed.
44 //
47
48 // N u m e r i c i n t e g r a t i o n o f l a n d a u p d f
49 // ------------------------------------------------------------------
50
51 RooRealVar x("x", "x", -10, 10);
52 RooLandau landau("landau", "landau", x, RooConst(0), RooConst(0.1));
53
54 // Disable analytic integration from demonstration purposes
55 landau.forceNumInt(true);
56
57 // Activate debug-level messages for topic integration to be able to follow actions below
59
60 // Calculate integral over landau with default choice of numeric integrator
61 std::unique_ptr<RooAbsReal> intLandau{landau.createIntegral(x)};
62 double val = intLandau->getVal();
63 cout << " [1] int_dx landau(x) = " << setprecision(15) << val << endl;
64
65 // S a m e w i t h c u s t o m c o n f i g u r a t i o n
66 // -----------------------------------------------------------
67
68 // Construct a custom configuration which uses the adaptive Gauss-Kronrod technique
69 // for closed 1D integrals
71#ifdef R__HAS_MATHMORE
72 customConfig.method1D().setLabel("RooAdaptiveGaussKronrodIntegrator1D");
73#else
74 Warning("rf901_numintconfig","ROOT is built without Mathmore (GSL) support. Cannot use RooAdaptiveGaussKronrodIntegrator1D");
75#endif
76
77 // Calculate integral over landau with custom integral specification
78 std::unique_ptr<RooAbsReal> intLandau2{landau.createIntegral(x, NumIntConfig(customConfig))};
79 double val2 = intLandau2->getVal();
80 cout << " [2] int_dx landau(x) = " << val2 << endl;
81
82 // A d j u s t i n g d e f a u l t c o n f i g f o r a s p e c i f i c p d f
83 // -------------------------------------------------------------------------------------
84
85 // Another possibility: associate custom numeric integration configuration as default for object 'landau'
86 landau.setIntegratorConfig(customConfig);
87
88 // Calculate integral over landau custom numeric integrator specified as object default
89 std::unique_ptr<RooAbsReal> intLandau3{landau.createIntegral(x)};
90 double val3 = intLandau3->getVal();
91 cout << " [3] int_dx landau(x) = " << val3 << endl;
92
93 // Another possibility: Change global default for 1D numeric integration strategy on finite domains
94#ifdef R__HAS_MATHMORE
95 RooAbsReal::defaultIntegratorConfig()->method1D().setLabel("RooAdaptiveGaussKronrodIntegrator1D");
96
97 // A d j u s t i n g p a r a m e t e r s o f a s p e c i f i c t e c h n i q u e
98 // ---------------------------------------------------------------------------------------
99
100 // Adjust maximum number of steps of RooIntegrator1D in the global default configuration
101 RooAbsReal::defaultIntegratorConfig()->getConfigSection("RooIntegrator1D").setRealValue("maxSteps", 30);
102
103 // Example of how to change the parameters of a numeric integrator
104 // (Each config section is a RooArgSet with RooRealVars holding real-valued parameters
105 // and RooCategories holding parameters with a finite set of options)
106 customConfig.getConfigSection("RooAdaptiveGaussKronrodIntegrator1D").setRealValue("maxSeg", 50);
107 customConfig.getConfigSection("RooAdaptiveGaussKronrodIntegrator1D").setCatLabel("method", "15Points");
108
109 // Example of how to print set of possible values for "method" category
110 customConfig.getConfigSection("RooAdaptiveGaussKronrodIntegrator1D").find("method")->Print("v");
111#endif
112
113}
#define DEBUG
#define e(i)
Definition RSha256.hxx:103
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:241
bool setRealValue(const char *name, double newVal=0.0, bool verbose=false)
Set value of a RooAbsRealLValye stored in set with given name to newVal No error messages are printed...
static RooNumIntConfig * defaultIntegratorConfig()
Returns the default numeric integration configuration for all RooAbsReals.
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Landau distribution p.d.f.
Definition RooLandau.h:24
static RooMsgService & instance()
Return reference to singleton instance.
Int_t addStream(RooFit::MsgLevel level, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg())
Add a message logging stream for message with given RooFit::MsgLevel or higher.
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
void setEpsRel(double newEpsRel)
Set relative convergence criteria (convergence if std::abs(Err)/abs(Int)<newEpsRel)
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
RooCategory & method1D()
void setEpsAbs(double newEpsAbs)
Set absolute convergence criteria (convergence if std::abs(Err)<newEpsAbs)
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
RooCmdArg Topic(Int_t topic)
RooCmdArg NumIntConfig(const RooNumIntConfig &cfg)
RooConstVar & RooConst(double val)
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition Common.h:18