Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooGaussKronrodIntegrator1D.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 RooGaussKronrodIntegrator1D.cxx
19\class RooGaussKronrodIntegrator1D
20\ingroup Roofitcore
21
22RooGaussKronrodIntegrator1D implements the Gauss-Kronrod integration algorithm.
23
24An Gaussian quadrature method for numerical integration in which
25error is estimation based on evaluation at special points known as
26"Kronrod points." By suitably picking these points, abscissas from
27previous iterations can be reused as part of the new set of points,
28whereas usual Gaussian quadrature would require recomputation of
29all abscissas at each iteration.
30
31This class automatically handles (-inf,+inf) integrals by dividing
32the integration in three regions (-inf,-1), (-1,1), (1,inf) and
33calculating the 1st and 3rd term using a x -> 1/x coordinate
34transformation
35
36This class embeds the Gauss-Kronrod integrator from the GNU
37Scientific Library version 1.5 and applies the 10-, 21-, 43- and
3887-point rule in succession until the required target precision is
39reached
40**/
41
43
44#include <RooArgSet.h>
45#include <RooMsgService.h>
46#include <RooNumIntFactory.h>
47#include <RooNumber.h>
48#include <RooRealVar.h>
49
50#include <Riostream.h>
51
52#include <TMath.h>
53
54#include <gsl/gsl_integration.h>
55
56#include <cassert>
57#include <cfloat>
58#include <cmath>
59
60using namespace std;
61
63
64/// \cond ROOFIT_INTERNAL
65
66// register integrator class
67// create a derived class in order to call the protected method of the
68// RoodaptiveGaussKronrodIntegrator1D
69namespace RooFit_internal {
70struct Roo_internal_GKInteg1D : public RooGaussKronrodIntegrator1D {
71
72 static void registerIntegrator()
73 {
74 auto &intFactory = RooNumIntFactory::instance();
76 }
77};
78// class used to register integrator at loafing time
79struct Roo_reg_GKInteg1D {
80 Roo_reg_GKInteg1D() { Roo_internal_GKInteg1D::registerIntegrator(); }
81};
82
83static Roo_reg_GKInteg1D instance;
84} // namespace RooFit_internal
85
86/// \endcond
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Register RooGaussKronrodIntegrator1D, its parameters and capabilities with RooNumIntConfig
91
93{
94 auto creator = [](const RooAbsFunc &function, const RooNumIntConfig &config) {
95 return std::make_unique<RooGaussKronrodIntegrator1D>(function, config);
96 };
97
98 fact.registerPlugin("RooGaussKronrodIntegrator1D", creator, {},
99 /*canIntegrate1D=*/true,
100 /*canIntegrate2D=*/false,
101 /*canIntegrateND=*/false,
102 /*canIntegrateOpenEnded=*/true);
103
104 oocoutI(nullptr, Integration) << "RooGaussKronrodIntegrator1D has been registered" << std::endl;
105}
106
107
108
109////////////////////////////////////////////////////////////////////////////////
110/// Construct integral on 'function' using given configuration object. The integration
111/// range is taken from the definition in the function binding
112
114 RooAbsIntegrator(function),
115 _epsAbs(config.epsRel()),
116 _epsRel(config.epsAbs())
117{
120}
121
122
123
124////////////////////////////////////////////////////////////////////////////////
125/// Construct integral on 'function' using given configuration object in the given range
126
128 double xmin, double xmax, const RooNumIntConfig& config) :
129 RooAbsIntegrator(function),
130 _epsAbs(config.epsRel()),
131 _epsRel(config.epsAbs()),
132 _xmin(xmin),
133 _xmax(xmax)
134{
135 _useIntegrandLimits= false;
137}
138
139
140////////////////////////////////////////////////////////////////////////////////
141/// Perform one-time initialization of integrator
142
144{
145 // Allocate coordinate buffer size after number of function dimensions
146 _x.resize(_function->getDimension());
147
148 return checkLimits();
149}
150
151
152
153////////////////////////////////////////////////////////////////////////////////
154/// Change our integration limits. Return true if the new limits are
155/// ok, or otherwise false. Always returns false and does nothing
156/// if this object was constructed to always use our integrand's limits.
157
159{
161 oocoutE(nullptr,Eval) << "RooGaussKronrodIntegrator1D::setLimits: cannot override integrand's limits" << endl;
162 return false;
163 }
164 _xmin= *xmin;
165 _xmax= *xmax;
166 return checkLimits();
167}
168
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Check that our integration range is finite and otherwise return false.
173/// Update the limits from the integrand if requested.
174
176{
178 assert(nullptr != integrand() && integrand()->isValid());
181 }
182 return true ;
183}
184
185
186
188{
190 return instance->integrand(instance->xvec(x)) ;
191}
192
193
194
195////////////////////////////////////////////////////////////////////////////////
196/// Calculate and return integral
197
199{
200 assert(isValid());
201
202 // Copy yvec to xvec if provided
203 if (yvec) {
204 UInt_t i ; for (i=0 ; i<_function->getDimension()-1 ; i++) {
205 _x[i+1] = yvec[i] ;
206 }
207 }
208
209 // Setup glue function
212 F.params = this ;
213
214 // Return values
215 double result, error;
216 size_t neval = 0 ;
217
218 // Call GSL implementation of integeator
219 gsl_integration_qng (&F, _xmin, _xmax, _epsAbs, _epsRel, &result, &error, &neval);
220
221 return result;
222}
static Roo_reg_AGKInteg1D instance
double RooGaussKronrodIntegrator1D_GSL_GlueFunction(double x, void *data)
#define oocoutE(o, a)
#define oocoutI(o, a)
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
float xmin
float xmax
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
UInt_t getDimension() const
Definition RooAbsFunc.h:33
Abstract interface for integrators of real-valued functions that implement the RooAbsFunc interface.
bool isValid() const
Is integrator in valid state.
const RooAbsFunc * _function
Pointer to function binding of integrand.
const RooAbsFunc * integrand() const
Return integrand function binding.
bool _valid
Is integrator in valid state?
RooGaussKronrodIntegrator1D implements the Gauss-Kronrod integration algorithm.
double integral(const double *yvec=nullptr) override
Calculate and return integral.
double _xmax
Lower integration bound.
RooGaussKronrodIntegrator1D(const RooAbsFunc &function, const RooNumIntConfig &config)
Construct integral on 'function' using given configuration object.
friend double RooGaussKronrodIntegrator1D_GSL_GlueFunction(double x, void *data)
bool initialize()
Perform one-time initialization of integrator.
bool checkLimits() const override
Check that our integration range is finite and otherwise return false.
bool setLimits(double *xmin, double *xmax) override
Change our integration limits.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooGaussKronrodIntegrator1D, its parameters and capabilities with RooNumIntConfig.
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
RooNumIntFactory is a factory to instantiate numeric integrators from a given function binding and a ...
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
bool registerPlugin(std::string const &name, Creator const &creator, const RooArgSet &defConfig, bool canIntegrate1D, bool canIntegrate2D, bool canIntegrateND, bool canIntegrateOpenEnded, const char *depName="")
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
Double_t x[n]
Definition legend1.C:17
#define F(x, y, z)