Logo ROOT  
Reference Guide
RooAdaptiveIntegratorND.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooAdaptiveIntegratorND.cxx
19\class RooAdaptiveIntegratorND
20\ingroup Roofitcore
21
22RooAdaptiveIntegratorND implements an adaptive one-dimensional
23numerical integration algorithm.
24**/
25
26
27#include "Riostream.h"
28
29#include "TClass.h"
31#include "RooArgSet.h"
32#include "RooRealVar.h"
33#include "RooNumber.h"
34#include "RooMsgService.h"
35#include "RooNumIntFactory.h"
36#include "RooMultiGenFunction.h"
38
39#include <assert.h>
40
41
42
43using namespace std;
44
46;
47
48// Register this class with RooNumIntConfig
49
50////////////////////////////////////////////////////////////////////////////////
51/// Register RooAdaptiveIntegratorND, its parameters, dependencies and capabilities with RooNumIntFactory
52
54{
55 RooRealVar maxEval2D("maxEval2D","Max number of function evaluations for 2-dim integrals",100000) ;
56 RooRealVar maxEval3D("maxEval3D","Max number of function evaluations for 3-dim integrals",1000000) ;
57 RooRealVar maxEvalND("maxEvalND","Max number of function evaluations for >3-dim integrals",10000000) ;
58 RooRealVar maxWarn("maxWarn","Max number of warnings on precision not reached that is printed",5) ;
59
60 fact.storeProtoIntegrator(new RooAdaptiveIntegratorND(),RooArgSet(maxEval2D,maxEval3D,maxEvalND,maxWarn)) ;
61}
62
63
64
65////////////////////////////////////////////////////////////////////////////////
66/// Default ctor
67
69{
70 _xmin = 0 ;
71 _xmax = 0 ;
72 _epsRel = 1e-7 ;
73 _epsAbs = 1e-7 ;
74 _nmax = 10000 ;
75 _func = 0 ;
76 _integrator = 0 ;
77 _nError = 0 ;
78 _nWarn = 0 ;
80 _intName = "(none)" ;
81}
82
83
84
85////////////////////////////////////////////////////////////////////////////////
86/// Constructor of integral on given function binding and with given configuration. The
87/// integration limits are taken from the definition in the function binding
88///_func = function.
89
92{
93
95 _nWarn = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxWarn")) ;
96 switch (_func->NDim()) {
97 case 1: throw string(Form("RooAdaptiveIntegratorND::ctor ERROR dimension of function must be at least 2")) ;
98 case 2: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEval2D")) ; break ;
99 case 3: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEval3D")) ; break ;
100 default: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEvalND")) ; break ;
101 }
102 // by default do not use absolute tolerance (see https://root.cern.ch/phpBB3/viewtopic.php?f=15&t=20071 )
103 _epsAbs = 0.0;
104 _epsRel = config.epsRel();
108
109 _xmin = 0 ;
110 _xmax = 0 ;
111 _nError = 0 ;
112 _nWarn = 0 ;
113 checkLimits() ;
114 _intName = function.getName() ;
115}
116
117
118
119////////////////////////////////////////////////////////////////////////////////
120/// Virtual constructor with given function and configuration. Needed by RooNumIntFactory
121
123{
125
126 return ret ;
127}
128
129
130
131
132////////////////////////////////////////////////////////////////////////////////
133/// Destructor
134
136{
137 delete[] _xmin ;
138 delete[] _xmax ;
139 delete _integrator ;
140 delete _func ;
141 if (_nError>_nWarn) {
142 coutW(NumIntegration) << "RooAdaptiveIntegratorND::dtor(" << _intName
143 << ") WARNING: Number of suppressed warningings about integral evaluations where target precision was not reached is " << _nError-_nWarn << endl ;
144 }
145
146}
147
148
149
150////////////////////////////////////////////////////////////////////////////////
151/// Check that our integration range is finite and otherwise return kFALSE.
152/// Update the limits from the integrand if requested.
153
155{
156 if (!_xmin) {
157 _xmin = new Double_t[_func->NDim()] ;
158 _xmax = new Double_t[_func->NDim()] ;
159 }
160
162 for (UInt_t i=0 ; i<_func->NDim() ; i++) {
163 _xmin[i]= integrand()->getMinLimit(i);
164 _xmax[i]= integrand()->getMaxLimit(i);
165 }
166 }
167
168 return kTRUE ;
169}
170
171
172////////////////////////////////////////////////////////////////////////////////
173/// Change our integration limits. Return kTRUE if the new limits are
174/// ok, or otherwise kFALSE. Always returns kFALSE and does nothing
175/// if this object was constructed to always use our integrand's limits.
176
178{
180 oocoutE((TObject*)0,Integration) << "RooAdaptiveIntegratorND::setLimits: cannot override integrand's limits" << endl;
181 return kFALSE;
182 }
183 for (UInt_t i=0 ; i<_func->NDim() ; i++) {
184 _xmin[i]= xmin[i];
185 _xmax[i]= xmax[i];
186 }
187
188 return checkLimits();
189}
190
191
192
193
194////////////////////////////////////////////////////////////////////////////////
195/// Evaluate integral at given function binding parameter values
196
198{
200 if (_integrator->Status()==1) {
201 _nError++ ;
202 if (_nError<=_nWarn) {
203 coutW(NumIntegration) << "RooAdaptiveIntegratorND::integral(" << integrand()->getName() << ") WARNING: target rel. precision not reached due to nEval limit of "
204 << _nmax << ", estimated rel. precision is " << Form("%3.1e",_integrator->RelError()) << endl ;
205 }
206 if (_nError==_nWarn) {
207 coutW(NumIntegration) << "RooAdaptiveIntegratorND::integral(" << integrand()->getName()
208 << ") Further warnings on target precision are suppressed conform specification in integrator specification" << endl ;
209 }
210 }
211 return ret ;
212}
213
#define e(i)
Definition: RSha256.hxx:103
#define coutW(a)
Definition: RooMsgService.h:32
#define oocoutE(o, a)
Definition: RooMsgService.h:48
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:375
float xmin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2447
Class for adaptive quadrature integration in multi-dimensions using rectangular regions.
int Status() const override
return status of integration
double Integral(const double *xmin, const double *xmax) override
evaluate the integral with the previously given function between xmin[] and xmax[]
void SetFunction(const IMultiGenFunction &f) override
set the integration function (must implement multi-dim function interface: IBaseFunctionMultiDim)
double RelError() const
return relative error
Double_t getRealValue(const char *name, Double_t defVal=0, Bool_t verbose=kFALSE) const
Get value of a RooAbsReal stored in set with given name.
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition: RooAbsFunc.h:27
virtual Double_t getMinLimit(UInt_t dimension) const =0
virtual Double_t getMaxLimit(UInt_t dimension) const =0
virtual const char * getName() const
Name of function binding.
Definition: RooAbsFunc.h:65
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
const RooAbsFunc * integrand() const
Return integrand function binding.
RooAdaptiveIntegratorND implements an adaptive one-dimensional numerical integration algorithm.
Int_t _nmax
Max number of divisions.
RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const override
Virtual constructor with given function and configuration. Needed by RooNumIntFactory.
Bool_t _useIntegrandLimits
If true limits of function binding are used.
TString _intName
Integrand name.
Double_t * _xmin
Lower bound in each dimension.
Double_t _epsAbs
Absolute precision.
~RooAdaptiveIntegratorND() override
Destructor.
Double_t * _xmax
Upper bound in each dimension.
Bool_t checkLimits() const override
Check that our integration range is finite and otherwise return kFALSE.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooAdaptiveIntegratorND, its parameters, dependencies and capabilities with RooNumIntFactory...
RooMultiGenFunction * _func
! ROOT::Math multi-parameter function binding
Int_t _nError
Number of error occurrences.
Double_t integral(const Double_t *yvec=0) override
Evaluate integral at given function binding parameter values.
Bool_t setLimits(Double_t *xmin, Double_t *xmax) override
Change our integration limits.
ROOT::Math::AdaptiveIntegratorMultiDim * _integrator
Int_t _nWarn
Max number of warnings to be issued ;.
Double_t _epsRel
Relative precision.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
Lightweight interface adaptor that exports a RooAbsReal as a ROOT::Math::IMultiGenFunction.
unsigned int NDim() const override
Retrieve the dimension of the function.
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
Double_t epsRel() const
RooNumIntFactory is a factory to instantiate numeric integrators from a given function binding and a ...
Bool_t storeProtoIntegrator(RooAbsIntegrator *proto, const RooArgSet &defConfig, const char *depName="")
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
Mother of all ROOT objects.
Definition: TObject.h:37
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:167
@ NumIntegration
Definition: RooGlobalFunc.h:65
@ Integration
Definition: RooGlobalFunc.h:63