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
27#include "RooFit.h"
28#include "Riostream.h"
29
30#include "TClass.h"
32#include "RooArgSet.h"
33#include "RooRealVar.h"
34#include "RooNumber.h"
35#include "RooMsgService.h"
36#include "RooNumIntFactory.h"
37
38#include <assert.h>
39
40
41
42using namespace std;
43
45;
46
47// Register this class with RooNumIntConfig
48
49////////////////////////////////////////////////////////////////////////////////
50/// Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactory
51
53{
54 RooRealVar numSeg("numSeg","Number of segments",3) ;
55 fact.storeProtoIntegrator(new RooSegmentedIntegrator1D(),numSeg,RooIntegrator1D::Class()->GetName()) ;
56}
57
58
59
60////////////////////////////////////////////////////////////////////////////////
61/// Constructor
62///
63/// coverity[UNINIT_CTOR]
64
66{
67}
68
69
70
71////////////////////////////////////////////////////////////////////////////////
72/// Constructor of integral on given function binding and with given configuration. The
73/// integration limits are taken from the definition in the function binding
74
76 RooAbsIntegrator(function), _config(config)
77{
78 _nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
80
82}
83
84
85
86////////////////////////////////////////////////////////////////////////////////
87/// Constructor integral on given function binding, with given configuration and
88/// explicit definition of integration range
89
91 const RooNumIntConfig& config) :
92 RooAbsIntegrator(function), _config(config)
93{
94 _nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
96 _xmin= xmin;
97 _xmax= xmax;
98
100}
101
102
103
104////////////////////////////////////////////////////////////////////////////////
105/// Virtual constructor with given function and configuration. Needed by RooNumIntFactory
106
108{
109 return new RooSegmentedIntegrator1D(function,config) ;
110}
111
112
113
115
116////////////////////////////////////////////////////////////////////////////////
117/// One-time integrator initialization
118
120{
121 _array = 0 ;
122
123 Bool_t limitsOK = checkLimits();
124 if (!limitsOK) return kFALSE ;
125
126 // Make array of integrators for each segment
128
129 Int_t i ;
130
131 Double_t segSize = (_xmax - _xmin) / _nseg ;
132
133 // Adjust integrator configurations for reduced intervals
134 _config.setEpsRel(_config.epsRel()/sqrt(1.*_nseg)) ;
135 _config.setEpsAbs(_config.epsAbs()/sqrt(1.*_nseg)) ;
136
137 for (i=0 ; i<_nseg ; i++) {
138 _array[i] = new RooIntegrator1D(*_function,_xmin+i*segSize,_xmin+(i+1)*segSize,_config) ;
139 }
140
141 return kTRUE ;
142}
143
144
145
146////////////////////////////////////////////////////////////////////////////////
147/// Destructor
148
150{
151 if (_array) {
152 for (Int_t i=0 ; i<_nseg ; i++) {
153 delete _array[i] ;
154 }
155 delete [] _array ;
156 }
157}
158
159
160
161////////////////////////////////////////////////////////////////////////////////
162/// Change our integration limits. Return kTRUE if the new limits are
163/// ok, or otherwise kFALSE. Always returns kFALSE and does nothing
164/// if this object was constructed to always use our integrand's limits.
165
167{
169 oocoutE((TObject*)0,InputArguments) << "RooSegmentedIntegrator1D::setLimits: cannot override integrand's limits" << endl;
170 return kFALSE;
171 }
172 _xmin= *xmin;
173 _xmax= *xmax;
174 return checkLimits();
175}
176
177
178
179////////////////////////////////////////////////////////////////////////////////
180/// Check that our integration range is finite and otherwise return kFALSE.
181/// Update the limits from the integrand if requested.
182
184{
186 assert(0 != integrand() && integrand()->isValid());
189 }
190 _range= _xmax - _xmin;
191 if(_range <= 0) {
192 oocoutE((TObject*)0,InputArguments) << "RooIntegrator1D::checkLimits: bad range with min >= max" << endl;
193 return kFALSE;
194 }
196
197 // Adjust component integrators, if already created
198 if (_array && ret) {
199 Double_t segSize = (_xmax - _xmin) / _nseg ;
200 Int_t i ;
201 for (i=0 ; i<_nseg ; i++) {
202 _array[i]->setLimits(_xmin+i*segSize,_xmin+(i+1)*segSize) ;
203 }
204 }
205
206 return ret ;
207}
208
209
210
211
212////////////////////////////////////////////////////////////////////////////////
213/// Evaluate integral at given function binding parameter values
214
216{
217 assert(isValid());
218
219 Int_t i ;
220 Double_t result(0) ;
221 for (i=0 ; i<_nseg ; i++) {
222 result += _array[i]->integral(yvec) ;
223 }
224
225 return result;
226}
227
#define oocoutE(o, a)
RooIntegrator1D * pRooIntegrator1D
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
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_t getMinLimit(UInt_t dimension) const =0
virtual Double_t getMaxLimit(UInt_t dimension) const =0
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
const RooAbsFunc * _function
const RooAbsFunc * integrand() const
Bool_t isValid() const
RooIntegrator1D implements an adaptive one-dimensional numerical integration algorithm.
Bool_t setLimits(Double_t *xmin, Double_t *xmax)
Change our integration limits.
virtual Double_t integral(const Double_t *yvec=0)
Calculate numeric integral at given set of function binding parameters.
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
Double_t epsAbs() const
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
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...
static Int_t isInfinite(Double_t x)
Return true if x is infinite by RooNumBer internal specification.
Definition RooNumber.cxx:58
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
RooSegmentedIntegrator1D implements an adaptive one-dimensional numerical integration algorithm.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactor...
Bool_t setLimits(Double_t *xmin, Double_t *xmax)
Change our integration limits.
virtual ~RooSegmentedIntegrator1D()
Destructor.
Bool_t initialize()
One-time integrator initialization.
virtual Double_t integral(const Double_t *yvec=0)
Evaluate integral at given function binding parameter values.
virtual RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const
Virtual constructor with given function and configuration. Needed by RooNumIntFactory.
virtual Bool_t checkLimits() const
Check that our integration range is finite and otherwise return kFALSE.
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:429