Logo ROOT  
Reference Guide
rf901_numintconfig.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -nodraw
4 ///
5 /// Numeric algorithm tuning: configuration and customization of how numeric (partial) integrals are executed
6 ///
7 /// \macro_output
8 /// \macro_code
9 ///
10 /// \date 07/2008
11 /// \author Wouter Verkerke
12 
13 #include "RooRealVar.h"
14 #include "RooDataSet.h"
15 #include "RooGaussian.h"
16 #include "RooConstVar.h"
17 #include "TCanvas.h"
18 #include "TAxis.h"
19 #include "RooPlot.h"
20 #include "RooNumIntConfig.h"
21 #include "RooLandau.h"
22 #include "RooArgSet.h"
23 #include <iomanip>
24 using namespace RooFit;
25 
26 void rf901_numintconfig()
27 {
28 
29  // 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
30  // ----------------------------------------------------------------------------
31 
32  // Print current global default configuration for numeric integration strategies
34 
35  // Example: Change global precision for 1D integrals from 1e-7 to 1e-6
36  //
37  // The relative epsilon (change as fraction of current best integral estimate) and
38  // absolute epsilon (absolute change w.r.t last best integral estimate) can be specified
39  // separately. For most p.d.f integrals the relative change criterium is the most important,
40  // however for certain non-p.d.f functions that integrate out to zero a separate absolute
41  // change criterium is necessary to declare convergence of the integral
42  //
43  // NB: This change is for illustration only. In general the precision should be at least 1e-7
44  // for normalization integrals for MINUIT to succeed.
45  //
48 
49  // 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
50  // ------------------------------------------------------------------
51 
52  // Construct p.d.f without support for analytical integrator for demonstration purposes
53  RooRealVar x("x", "x", -10, 10);
54  RooLandau landau("landau", "landau", x, RooConst(0), RooConst(0.1));
55 
56  // Activate debug-level messages for topic integration to be able to follow actions below
58 
59  // Calculate integral over landau with default choice of numeric integrator
60  RooAbsReal *intLandau = landau.createIntegral(x);
61  Double_t val = intLandau->getVal();
62  cout << " [1] int_dx landau(x) = " << setprecision(15) << val << endl;
63 
64  // 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
65  // -----------------------------------------------------------
66 
67  // Construct a custom configuration which uses the adaptive Gauss-Kronrod technique
68  // for closed 1D integrals
70 #ifdef R__HAS_MATHMORE
71  customConfig.method1D().setLabel("RooAdaptiveGaussKronrodIntegrator1D");
72 #else
73  Warning("rf901_numintconfig","ROOT is built without Mathmore (GSL) support. Cannot use RooAdaptiveGaussKronrodIntegrator1D");
74 #endif
75 
76  // Calculate integral over landau with custom integral specification
77  RooAbsReal *intLandau2 = landau.createIntegral(x, NumIntConfig(customConfig));
78  Double_t val2 = intLandau2->getVal();
79  cout << " [2] int_dx landau(x) = " << val2 << endl;
80 
81  // 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
82  // -------------------------------------------------------------------------------------
83 
84  // Another possibility: associate custom numeric integration configuration as default for object 'landau'
85  landau.setIntegratorConfig(customConfig);
86 
87  // Calculate integral over landau custom numeric integrator specified as object default
88  RooAbsReal *intLandau3 = landau.createIntegral(x);
89  Double_t val3 = intLandau3->getVal();
90  cout << " [3] int_dx landau(x) = " << val3 << endl;
91 
92  // Another possibility: Change global default for 1D numeric integration strategy on finite domains
93 #ifdef R__HAS_MATHMORE
94  RooAbsReal::defaultIntegratorConfig()->method1D().setLabel("RooAdaptiveGaussKronrodIntegrator1D");
95 
96  // 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
97  // ---------------------------------------------------------------------------------------
98 
99  // Adjust maximum number of steps of RooIntegrator1D in the global default configuration
100  RooAbsReal::defaultIntegratorConfig()->getConfigSection("RooIntegrator1D").setRealValue("maxSteps", 30);
101 
102  // Example of how to change the parameters of a numeric integrator
103  // (Each config section is a RooArgSet with RooRealVars holding real-valued parameters
104  // and RooCategories holding parameters with a finite set of options)
105  customConfig.getConfigSection("RooAdaptiveGaussKronrodIntegrator1D").setRealValue("maxSeg", 50);
106  customConfig.getConfigSection("RooAdaptiveGaussKronrodIntegrator1D").setCatLabel("method", "15Points");
107 
108  // Example of how to print set of possible values for "method" category
109  customConfig.getConfigSection("RooAdaptiveGaussKronrodIntegrator1D").find("method")->Print("v");
110 #endif
111 
112 }
RooArgSet::setRealValue
Bool_t setRealValue(const char *name, Double_t newVal=0, Bool_t verbose=kFALSE)
Set value of a RooAbsRealLValye stored in set with given name to newVal No error messages are printed...
Definition: RooArgSet.cxx:495
RooNumIntConfig::getConfigSection
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
Definition: RooNumIntConfig.cxx:222
e
#define e(i)
Definition: RSha256.hxx:121
Warning
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition: TError.cxx:232
RooNumIntConfig.h
RooArgSet.h
RooFit::DEBUG
@ DEBUG
Definition: RooGlobalFunc.h:65
RooAbsReal::createIntegral
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
Definition: RooAbsReal.cxx:561
RooLandau
Definition: RooLandau.h:24
RooNumIntConfig::method1D
RooCategory & method1D()
Definition: RooNumIntConfig.h:34
RooGaussian.h
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
x
Double_t x[n]
Definition: legend1.C:17
RooAbsReal
Definition: RooAbsReal.h:61
TCanvas.h
RooDataSet.h
RooFit::NumIntConfig
RooCmdArg NumIntConfig(const RooNumIntConfig &cfg)
Definition: RooGlobalFunc.cxx:257
rf901_numintconfig
Definition: rf901_numintconfig.py:1
RooCategory::setLabel
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Definition: RooCategory.cxx:185
RooFit
Definition: RooCFunction1Binding.h:29
RooPlot.h
RooNumIntConfig::setEpsRel
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
Definition: RooNumIntConfig.cxx:268
RooMsgService::addStream
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 (i....
Definition: RooMsgService.cxx:201
RooNumIntConfig::Print
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
Definition: RooNumIntConfig.h:69
RooRealVar.h
RooConstVar.h
RooAbsReal::defaultIntegratorConfig
static RooNumIntConfig * defaultIntegratorConfig()
Returns the default numeric integration configuration for all RooAbsReals.
Definition: RooAbsReal.cxx:3531
Double_t
double Double_t
Definition: RtypesCore.h:59
RooNumIntConfig::setEpsAbs
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
Definition: RooNumIntConfig.cxx:238
TAxis.h
RooFit::Topic
RooCmdArg Topic(Int_t topic)
Definition: RooGlobalFunc.cxx:298
RooNumIntConfig
Definition: RooNumIntConfig.h:25
RooFit::Integration
@ Integration
Definition: RooGlobalFunc.h:67
RooRealVar
Definition: RooRealVar.h:35
RooMsgService::instance
static RooMsgService & instance()
Return reference to singleton instance.
Definition: RooMsgService.cxx:363
RooLandau.h
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:341