Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 _epsRel = 1e-7 ;
71 _epsAbs = 1e-7 ;
72 _nmax = 10000 ;
73 _func = 0 ;
74 _integrator = 0 ;
75 _nError = 0 ;
76 _nWarn = 0 ;
77 _useIntegrandLimits = true ;
78 _intName = "(none)" ;
79}
80
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Constructor of integral on given function binding and with given configuration. The
85/// integration limits are taken from the definition in the function binding
86///_func = function.
87
89 RooAbsIntegrator(function)
90{
91
92 _func = new RooMultiGenFunction(function) ;
93 _nWarn = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxWarn")) ;
94 switch (_func->NDim()) {
95 case 1: throw string(Form("RooAdaptiveIntegratorND::ctor ERROR dimension of function must be at least 2")) ;
96 case 2: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEval2D")) ; break ;
97 case 3: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEval3D")) ; break ;
98 default: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEvalND")) ; break ;
99 }
100 // by default do not use absolute tolerance (see https://root.cern.ch/phpBB3/viewtopic.php?f=15&t=20071 )
101 _epsAbs = 0.0;
102 _epsRel = config.epsRel();
106
107 _nError = 0 ;
108 _nWarn = 0 ;
109 checkLimits() ;
110 _intName = function.getName() ;
111}
112
113
114
115////////////////////////////////////////////////////////////////////////////////
116/// Virtual constructor with given function and configuration. Needed by RooNumIntFactory
117
119{
120 RooAbsIntegrator* ret = new RooAdaptiveIntegratorND(function,config) ;
121
122 return ret ;
123}
124
125
126
127
128////////////////////////////////////////////////////////////////////////////////
129/// Destructor
130
132{
133 delete _integrator ;
134 delete _func ;
135 if (_nError>_nWarn) {
136 coutW(NumIntegration) << "RooAdaptiveIntegratorND::dtor(" << _intName
137 << ") WARNING: Number of suppressed warningings about integral evaluations where target precision was not reached is " << _nError-_nWarn << endl ;
138 }
139
140}
141
142
143
144////////////////////////////////////////////////////////////////////////////////
145/// Check that our integration range is finite and otherwise return false.
146/// Update the limits from the integrand if requested.
147
149{
150 if (_xmin.empty()) {
151 _xmin.resize(_func->NDim());
152 _xmax.resize(_func->NDim());
153 }
154
156 for (UInt_t i=0 ; i<_func->NDim() ; i++) {
157 _xmin[i]= integrand()->getMinLimit(i);
158 _xmax[i]= integrand()->getMaxLimit(i);
159 }
160 }
161
162 return true ;
163}
164
165
166////////////////////////////////////////////////////////////////////////////////
167/// Change our integration limits. Return true if the new limits are
168/// ok, or otherwise false. Always returns false and does nothing
169/// if this object was constructed to always use our integrand's limits.
170
172{
174 oocoutE(nullptr,Integration) << "RooAdaptiveIntegratorND::setLimits: cannot override integrand's limits" << endl;
175 return false;
176 }
177 for (UInt_t i=0 ; i<_func->NDim() ; i++) {
178 _xmin[i]= xmin[i];
179 _xmax[i]= xmax[i];
180 }
181
182 return checkLimits();
183}
184
185
186
187
188////////////////////////////////////////////////////////////////////////////////
189/// Evaluate integral at given function binding parameter values
190
191double RooAdaptiveIntegratorND::integral(const double* /*yvec*/)
192{
193 double ret = _integrator->Integral(_xmin.data(),_xmax.data());
194 if (_integrator->Status()==1) {
195 _nError++ ;
196 if (_nError<=_nWarn) {
197 coutW(NumIntegration) << "RooAdaptiveIntegratorND::integral(" << integrand()->getName() << ") WARNING: target rel. precision not reached due to nEval limit of "
198 << _nmax << ", estimated rel. precision is " << Form("%3.1e",_integrator->RelError()) << endl ;
199 }
200 if (_nError==_nWarn) {
201 coutW(NumIntegration) << "RooAdaptiveIntegratorND::integral(" << integrand()->getName()
202 << ") Further warnings on target precision are suppressed conform specification in integrator specification" << endl ;
203 }
204 }
205 return ret ;
206}
207
#define e(i)
Definition RSha256.hxx:103
#define coutW(a)
#define oocoutE(o, a)
#define ClassImp(name)
Definition Rtypes.h:377
float xmin
float xmax
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
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 getRealValue(const char *name, double defVal=0.0, bool verbose=false) 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 getMaxLimit(UInt_t dimension) const =0
virtual double getMinLimit(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.
bool checkLimits() const override
Check that our integration range is finite and otherwise return false.
bool _useIntegrandLimits
If true limits of function binding are used.
double integral(const double *yvec=nullptr) override
Evaluate integral at given function binding parameter values.
RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const override
Virtual constructor with given function and configuration. Needed by RooNumIntFactory.
bool setLimits(double *xmin, double *xmax) override
Change our integration limits.
std::vector< double > _xmin
Lower bound in each dimension.
double _epsRel
Relative precision.
double _epsAbs
Absolute precision.
TString _intName
Integrand name.
~RooAdaptiveIntegratorND() override
Destructor.
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.
ROOT::Math::AdaptiveIntegratorMultiDim * _integrator
std::vector< double > _xmax
Upper bound in each dimension.
Int_t _nWarn
Max number of warnings to be issued ;.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
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 epsRel() const
RooNumIntFactory is a factory to instantiate numeric integrators from a given function binding and a ...
bool 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