Logo ROOT   6.10/09
Reference Guide
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 
22 RooSegmentedIntegrator1D implements an adaptive one-dimensional
23 numerical 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 
42 using 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) ;
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 
77 {
78  _nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
80 
81  _valid= initialize();
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) :
93 {
94  _nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
96  _xmin= xmin;
97  _xmax= xmax;
98 
99  _valid= initialize();
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
127  _array = new pRooIntegrator1D[_nseg] ;
128 
129  Int_t i ;
130 
131  Double_t segSize = (_xmax - _xmin) / _nseg ;
132 
133  // Adjust integrator configurations for reduced intervals
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 {
168  if(_useIntegrandLimits) {
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 {
185  if(_useIntegrandLimits) {
186  assert(0 != integrand() && integrand()->isValid());
187  _xmin= integrand()->getMinLimit(0);
188  _xmax= integrand()->getMaxLimit(0);
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 
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:145
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
float xmin
Definition: THbookFile.cxx:93
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
Double_t epsAbs() const
RooNumIntFactory is a factory to instantiate numeric integrators from a given function binding and a ...
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
virtual RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const
Virtual constructor with given function and configuration. Needed by RooNumIntFactory.
static Int_t isInfinite(Double_t x)
Return true if x is infinite by RooNumBer internal specification.
Definition: RooNumber.cxx:58
STL namespace.
virtual Bool_t checkLimits() const
Check that our integration range is finite and otherwise return kFALSE.
Bool_t isValid() const
Bool_t initialize()
One-time integrator initialization.
double sqrt(double)
void Class()
Definition: Class.C:29
#define oocoutE(o, a)
Definition: RooMsgService.h:47
static void registerIntegrator(RooNumIntFactory &fact)
Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactor...
RooSegmentedIntegrator1D implements an adaptive one-dimensional numerical integration algorithm...
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:146
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
virtual Double_t integral(const Double_t *yvec=0)
Calculate numeric integral at given set of function binding parameters.
const RooAbsFunc * _function
virtual ~RooSegmentedIntegrator1D()
Destructor.
virtual Double_t getMinLimit(UInt_t dimension) const =0
float xmax
Definition: THbookFile.cxx:93
Bool_t setLimits(Double_t *xmin, Double_t *xmax)
Change our integration limits.
RooIntegrator1D * pRooIntegrator1D
const Bool_t kFALSE
Definition: RtypesCore.h:92
const RooAbsFunc * integrand() const
RooIntegrator1D implements an adaptive one-dimensional numerical integration algorithm.
virtual Double_t integral(const Double_t *yvec=0)
Evaluate integral at given function binding parameter values.
#define ClassImp(name)
Definition: Rtypes.h:336
virtual Double_t getMaxLimit(UInt_t dimension) const =0
double Double_t
Definition: RtypesCore.h:55
Mother of all ROOT objects.
Definition: TObject.h:37
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.
Definition: RooArgSet.cxx:527
Double_t epsRel() const
Bool_t setLimits(Double_t *xmin, Double_t *xmax)
Change our integration limits.
double result[121]
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:364
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
const Bool_t kTRUE
Definition: RtypesCore.h:91
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition: RooAbsFunc.h:23
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
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...