Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooSegmentedIntegrator1D.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 RooSegmentedIntegrator1D.cxx
19\class RooSegmentedIntegrator1D
20\ingroup Roofitcore
21
22RooSegmentedIntegrator1D implements an adaptive one-dimensional
23numerical integration algorithm.
24**/
25
26#include "Riostream.h"
27
28#include "TClass.h"
30#include "RooArgSet.h"
31#include "RooRealVar.h"
32#include "RooNumber.h"
33#include "RooMsgService.h"
34#include "RooNumIntFactory.h"
35
36#include <assert.h>
37
38
39
40using namespace std;
41
43
44// Register this class with RooNumIntConfig
45
46////////////////////////////////////////////////////////////////////////////////
47/// Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactory
48
50{
51 RooRealVar numSeg("numSeg","Number of segments",3) ;
53}
54
55
58
59
60////////////////////////////////////////////////////////////////////////////////
61/// Constructor of integral on given function binding and with given configuration. The
62/// integration limits are taken from the definition in the function binding
63
65 RooAbsIntegrator(function), _config(config)
66{
67 _nseg = (Int_t) config.getConfigSection(ClassName()).getRealValue("numSeg",3) ;
69
71}
72
73
74
75////////////////////////////////////////////////////////////////////////////////
76/// Constructor integral on given function binding, with given configuration and
77/// explicit definition of integration range
78
80 const RooNumIntConfig& config) :
81 RooAbsIntegrator(function), _config(config)
82{
83 _nseg = (Int_t) config.getConfigSection(ClassName()).getRealValue("numSeg",3) ;
85 _xmin= xmin;
86 _xmax= xmax;
87
89}
90
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// Virtual constructor with given function and configuration. Needed by RooNumIntFactory
95
97{
98 return new RooSegmentedIntegrator1D(function,config) ;
99}
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// One-time integrator initialization
104
106{
107 _array.clear();
108
109 bool limitsOK = checkLimits();
110 if (!limitsOK) return false ;
111
112 // Make array of integrators for each segment
113 _array.resize(_nseg);
114
115 Int_t i ;
116
117 double segSize = (_xmax - _xmin) / _nseg ;
118
119 // Adjust integrator configurations for reduced intervals
120 _config.setEpsRel(_config.epsRel()/sqrt(1.*_nseg)) ;
121 _config.setEpsAbs(_config.epsAbs()/sqrt(1.*_nseg)) ;
122
123 for (i=0 ; i<_nseg ; i++) {
124 _array[i] = std::make_unique<RooIntegrator1D>(*_function,_xmin+i*segSize,_xmin+(i+1)*segSize,_config) ;
125 }
126
127 return true ;
128}
129
130
131////////////////////////////////////////////////////////////////////////////////
132/// Change our integration limits. Return true if the new limits are
133/// ok, or otherwise false. Always returns false and does nothing
134/// if this object was constructed to always use our integrand's limits.
135
137{
139 oocoutE(nullptr,InputArguments) << "RooSegmentedIntegrator1D::setLimits: cannot override integrand's limits" << endl;
140 return false;
141 }
142 _xmin= *xmin;
143 _xmax= *xmax;
144 return checkLimits();
145}
146
147
148
149////////////////////////////////////////////////////////////////////////////////
150/// Check that our integration range is finite and otherwise return false.
151/// Update the limits from the integrand if requested.
152
154{
156 assert(0 != integrand() && integrand()->isValid());
159 }
160 _range= _xmax - _xmin;
161 if(_range <= 0) {
162 oocoutE(nullptr,InputArguments) << "RooIntegrator1D::checkLimits: bad range with min >= max" << endl;
163 return false;
164 }
165 bool ret = (RooNumber::isInfinite(_xmin) || RooNumber::isInfinite(_xmax)) ? false : true;
166
167 // Adjust component integrators, if already created
168 if (!_array.empty() && ret) {
169 double segSize = (_xmax - _xmin) / _nseg ;
170 Int_t i ;
171 for (i=0 ; i<_nseg ; i++) {
172 _array[i]->setLimits(_xmin+i*segSize,_xmin+(i+1)*segSize) ;
173 }
174 }
175
176 return ret ;
177}
178
179
180
181
182////////////////////////////////////////////////////////////////////////////////
183/// Evaluate integral at given function binding parameter values
184
185double RooSegmentedIntegrator1D::integral(const double *yvec)
186{
187 assert(isValid());
188
189 Int_t i ;
190 double result(0) ;
191 for (i=0 ; i<_nseg ; i++) {
192 result += _array[i]->integral(yvec) ;
193 }
194
195 return result;
196}
#define oocoutE(o, a)
int Int_t
Definition RtypesCore.h:45
#define ClassImp(name)
Definition Rtypes.h:377
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
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
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.
static TClass * Class()
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
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.
double epsRel() const
double epsAbs() const
void setEpsAbs(double newEpsAbs)
Set absolute convergence criteria (convergence if std::abs(Err)<newEpsAbs)
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...
static constexpr int isInfinite(double x)
Return true if x is infinite by RooNumber internal specification.
Definition RooNumber.h:34
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
RooSegmentedIntegrator1D implements an adaptive one-dimensional numerical integration algorithm.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactor...
double integral(const double *yvec=nullptr) override
Evaluate integral at given function binding parameter values.
bool checkLimits() const override
Check that our integration range is finite and otherwise return false.
~RooSegmentedIntegrator1D() override
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< std::unique_ptr< RooIntegrator1D > > _array
Array of segment integrators.
bool initialize()
One-time integrator initialization.
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207