// RooSegmentedIntegrator1D implements an adaptive one-dimensional
// numerical integration algorithm.
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "TClass.h"
#include "RooSegmentedIntegrator1D.h"
#include "RooArgSet.h"
#include "RooRealVar.h"
#include "RooNumber.h"
#include "RooMsgService.h"
#include "RooNumIntFactory.h"
#include <assert.h>
ClassImp(RooSegmentedIntegrator1D)
;
void RooSegmentedIntegrator1D::registerIntegrator(RooNumIntFactory& fact)
{
RooRealVar numSeg("numSeg","Number of segments",3) ;
fact.storeProtoIntegrator(new RooSegmentedIntegrator1D(),numSeg,RooIntegrator1D::Class()->GetName()) ;
}
RooSegmentedIntegrator1D::RooSegmentedIntegrator1D()
{
}
RooSegmentedIntegrator1D::RooSegmentedIntegrator1D(const RooAbsFunc& function, const RooNumIntConfig& config) :
RooAbsIntegrator(function), _config(config)
{
_nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
_useIntegrandLimits= kTRUE;
_valid= initialize();
}
RooSegmentedIntegrator1D::RooSegmentedIntegrator1D(const RooAbsFunc& function, Double_t xmin, Double_t xmax,
const RooNumIntConfig& config) :
RooAbsIntegrator(function), _config(config)
{
_nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
_useIntegrandLimits= kFALSE;
_xmin= xmin;
_xmax= xmax;
_valid= initialize();
}
RooAbsIntegrator* RooSegmentedIntegrator1D::clone(const RooAbsFunc& function, const RooNumIntConfig& config) const
{
return new RooSegmentedIntegrator1D(function,config) ;
}
typedef RooIntegrator1D* pRooIntegrator1D ;
Bool_t RooSegmentedIntegrator1D::initialize()
{
_array = 0 ;
Bool_t limitsOK = checkLimits();
if (!limitsOK) return kFALSE ;
_array = new pRooIntegrator1D[_nseg] ;
Int_t i ;
Double_t segSize = (_xmax - _xmin) / _nseg ;
_config.setEpsRel(_config.epsRel()/sqrt(1.*_nseg)) ;
_config.setEpsAbs(_config.epsAbs()/sqrt(1.*_nseg)) ;
for (i=0 ; i<_nseg ; i++) {
_array[i] = new RooIntegrator1D(*_function,_xmin+i*segSize,_xmin+(i+1)*segSize,_config) ;
}
return kTRUE ;
}
RooSegmentedIntegrator1D::~RooSegmentedIntegrator1D()
{
}
Bool_t RooSegmentedIntegrator1D::setLimits(Double_t xmin, Double_t xmax)
{
if(_useIntegrandLimits) {
oocoutE((TObject*)0,InputArguments) << "RooSegmentedIntegrator1D::setLimits: cannot override integrand's limits" << endl;
return kFALSE;
}
_xmin= xmin;
_xmax= xmax;
return checkLimits();
}
Bool_t RooSegmentedIntegrator1D::checkLimits() const
{
if(_useIntegrandLimits) {
assert(0 != integrand() && integrand()->isValid());
_xmin= integrand()->getMinLimit(0);
_xmax= integrand()->getMaxLimit(0);
}
_range= _xmax - _xmin;
if(_range <= 0) {
oocoutE((TObject*)0,InputArguments) << "RooIntegrator1D::checkLimits: bad range with min >= max" << endl;
return kFALSE;
}
Bool_t ret = (RooNumber::isInfinite(_xmin) || RooNumber::isInfinite(_xmax)) ? kFALSE : kTRUE;
if (_array && ret) {
Double_t segSize = (_xmax - _xmin) / _nseg ;
Int_t i ;
for (i=0 ; i<_nseg ; i++) {
_array[i]->setLimits(_xmin+i*segSize,_xmin+(i+1)*segSize) ;
}
}
return ret ;
}
Double_t RooSegmentedIntegrator1D::integral(const Double_t *yvec)
{
assert(isValid());
Int_t i ;
Double_t result(0) ;
for (i=0 ; i<_nseg ; i++) {
result += _array[i]->integral(yvec) ;
}
return result;
}
Last change: Wed Jun 25 08:34:09 2008
Last generated: 2008-06-25 08:34
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.