ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id: RooSegmentedIntegrator1D.cxx 28259 2009-04-16 16:21:16Z wouter $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
//
// BEGIN_HTML
// 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)
;

// Register this class with RooNumIntConfig

//_____________________________________________________________________________
void RooSegmentedIntegrator1D::registerIntegrator(RooNumIntFactory& fact)
{
  // Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactory

  RooRealVar numSeg("numSeg","Number of segments",3) ;
  fact.storeProtoIntegrator(new RooSegmentedIntegrator1D(),numSeg,RooIntegrator1D::Class()->GetName()) ;
}
 


//_____________________________________________________________________________
RooSegmentedIntegrator1D::RooSegmentedIntegrator1D()
{
  // Destructor

}



//_____________________________________________________________________________
RooSegmentedIntegrator1D::RooSegmentedIntegrator1D(const RooAbsFunc& function, const RooNumIntConfig& config) :
  RooAbsIntegrator(function), _config(config)
{
  // Constructor of integral on given function binding and with given configuration. The
  // integration limits are taken from the definition in the function binding

  _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) 
{
  // Constructor integral on given function binding, with given configuration and
  // explicit definition of integration range

  _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
{
  // Virtual constructor with given function and configuration. Needed by RooNumIntFactory
  
  return new RooSegmentedIntegrator1D(function,config) ;
}



typedef RooIntegrator1D* pRooIntegrator1D ;

//_____________________________________________________________________________
Bool_t RooSegmentedIntegrator1D::initialize()
{
  // One-time integrator initialization

  _array = 0 ;
  
  Bool_t limitsOK = checkLimits(); 
  if (!limitsOK) return kFALSE ;

  // Make array of integrators for each segment
  _array = new pRooIntegrator1D[_nseg] ;

  Int_t i ;

  Double_t segSize = (_xmax - _xmin) / _nseg ;

  // Adjust integrator configurations for reduced intervals
  _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()
{
  // Destructor
}



//_____________________________________________________________________________
Bool_t RooSegmentedIntegrator1D::setLimits(Double_t* xmin, Double_t* xmax) 
{
  // Change our integration limits. Return kTRUE if the new limits are
  // ok, or otherwise kFALSE. Always returns kFALSE and does nothing
  // if this object was constructed to always use our integrand's limits.

  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 
{
  // Check that our integration range is finite and otherwise return kFALSE.
  // Update the limits from the integrand if requested.
  
  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;

  // Adjust component integrators, if already created
  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) 
{
  // Evaluate integral at given function binding parameter values

  assert(isValid());

  Int_t i ;
  Double_t result(0) ;
  for (i=0 ; i<_nseg ; i++) {
    result += _array[i]->integral(yvec) ;
  }

  return result;
}

 RooSegmentedIntegrator1D.cxx:1
 RooSegmentedIntegrator1D.cxx:2
 RooSegmentedIntegrator1D.cxx:3
 RooSegmentedIntegrator1D.cxx:4
 RooSegmentedIntegrator1D.cxx:5
 RooSegmentedIntegrator1D.cxx:6
 RooSegmentedIntegrator1D.cxx:7
 RooSegmentedIntegrator1D.cxx:8
 RooSegmentedIntegrator1D.cxx:9
 RooSegmentedIntegrator1D.cxx:10
 RooSegmentedIntegrator1D.cxx:11
 RooSegmentedIntegrator1D.cxx:12
 RooSegmentedIntegrator1D.cxx:13
 RooSegmentedIntegrator1D.cxx:14
 RooSegmentedIntegrator1D.cxx:15
 RooSegmentedIntegrator1D.cxx:16
 RooSegmentedIntegrator1D.cxx:17
 RooSegmentedIntegrator1D.cxx:18
 RooSegmentedIntegrator1D.cxx:19
 RooSegmentedIntegrator1D.cxx:20
 RooSegmentedIntegrator1D.cxx:21
 RooSegmentedIntegrator1D.cxx:22
 RooSegmentedIntegrator1D.cxx:23
 RooSegmentedIntegrator1D.cxx:24
 RooSegmentedIntegrator1D.cxx:25
 RooSegmentedIntegrator1D.cxx:26
 RooSegmentedIntegrator1D.cxx:27
 RooSegmentedIntegrator1D.cxx:28
 RooSegmentedIntegrator1D.cxx:29
 RooSegmentedIntegrator1D.cxx:30
 RooSegmentedIntegrator1D.cxx:31
 RooSegmentedIntegrator1D.cxx:32
 RooSegmentedIntegrator1D.cxx:33
 RooSegmentedIntegrator1D.cxx:34
 RooSegmentedIntegrator1D.cxx:35
 RooSegmentedIntegrator1D.cxx:36
 RooSegmentedIntegrator1D.cxx:37
 RooSegmentedIntegrator1D.cxx:38
 RooSegmentedIntegrator1D.cxx:39
 RooSegmentedIntegrator1D.cxx:40
 RooSegmentedIntegrator1D.cxx:41
 RooSegmentedIntegrator1D.cxx:42
 RooSegmentedIntegrator1D.cxx:43
 RooSegmentedIntegrator1D.cxx:44
 RooSegmentedIntegrator1D.cxx:45
 RooSegmentedIntegrator1D.cxx:46
 RooSegmentedIntegrator1D.cxx:47
 RooSegmentedIntegrator1D.cxx:48
 RooSegmentedIntegrator1D.cxx:49
 RooSegmentedIntegrator1D.cxx:50
 RooSegmentedIntegrator1D.cxx:51
 RooSegmentedIntegrator1D.cxx:52
 RooSegmentedIntegrator1D.cxx:53
 RooSegmentedIntegrator1D.cxx:54
 RooSegmentedIntegrator1D.cxx:55
 RooSegmentedIntegrator1D.cxx:56
 RooSegmentedIntegrator1D.cxx:57
 RooSegmentedIntegrator1D.cxx:58
 RooSegmentedIntegrator1D.cxx:59
 RooSegmentedIntegrator1D.cxx:60
 RooSegmentedIntegrator1D.cxx:61
 RooSegmentedIntegrator1D.cxx:62
 RooSegmentedIntegrator1D.cxx:63
 RooSegmentedIntegrator1D.cxx:64
 RooSegmentedIntegrator1D.cxx:65
 RooSegmentedIntegrator1D.cxx:66
 RooSegmentedIntegrator1D.cxx:67
 RooSegmentedIntegrator1D.cxx:68
 RooSegmentedIntegrator1D.cxx:69
 RooSegmentedIntegrator1D.cxx:70
 RooSegmentedIntegrator1D.cxx:71
 RooSegmentedIntegrator1D.cxx:72
 RooSegmentedIntegrator1D.cxx:73
 RooSegmentedIntegrator1D.cxx:74
 RooSegmentedIntegrator1D.cxx:75
 RooSegmentedIntegrator1D.cxx:76
 RooSegmentedIntegrator1D.cxx:77
 RooSegmentedIntegrator1D.cxx:78
 RooSegmentedIntegrator1D.cxx:79
 RooSegmentedIntegrator1D.cxx:80
 RooSegmentedIntegrator1D.cxx:81
 RooSegmentedIntegrator1D.cxx:82
 RooSegmentedIntegrator1D.cxx:83
 RooSegmentedIntegrator1D.cxx:84
 RooSegmentedIntegrator1D.cxx:85
 RooSegmentedIntegrator1D.cxx:86
 RooSegmentedIntegrator1D.cxx:87
 RooSegmentedIntegrator1D.cxx:88
 RooSegmentedIntegrator1D.cxx:89
 RooSegmentedIntegrator1D.cxx:90
 RooSegmentedIntegrator1D.cxx:91
 RooSegmentedIntegrator1D.cxx:92
 RooSegmentedIntegrator1D.cxx:93
 RooSegmentedIntegrator1D.cxx:94
 RooSegmentedIntegrator1D.cxx:95
 RooSegmentedIntegrator1D.cxx:96
 RooSegmentedIntegrator1D.cxx:97
 RooSegmentedIntegrator1D.cxx:98
 RooSegmentedIntegrator1D.cxx:99
 RooSegmentedIntegrator1D.cxx:100
 RooSegmentedIntegrator1D.cxx:101
 RooSegmentedIntegrator1D.cxx:102
 RooSegmentedIntegrator1D.cxx:103
 RooSegmentedIntegrator1D.cxx:104
 RooSegmentedIntegrator1D.cxx:105
 RooSegmentedIntegrator1D.cxx:106
 RooSegmentedIntegrator1D.cxx:107
 RooSegmentedIntegrator1D.cxx:108
 RooSegmentedIntegrator1D.cxx:109
 RooSegmentedIntegrator1D.cxx:110
 RooSegmentedIntegrator1D.cxx:111
 RooSegmentedIntegrator1D.cxx:112
 RooSegmentedIntegrator1D.cxx:113
 RooSegmentedIntegrator1D.cxx:114
 RooSegmentedIntegrator1D.cxx:115
 RooSegmentedIntegrator1D.cxx:116
 RooSegmentedIntegrator1D.cxx:117
 RooSegmentedIntegrator1D.cxx:118
 RooSegmentedIntegrator1D.cxx:119
 RooSegmentedIntegrator1D.cxx:120
 RooSegmentedIntegrator1D.cxx:121
 RooSegmentedIntegrator1D.cxx:122
 RooSegmentedIntegrator1D.cxx:123
 RooSegmentedIntegrator1D.cxx:124
 RooSegmentedIntegrator1D.cxx:125
 RooSegmentedIntegrator1D.cxx:126
 RooSegmentedIntegrator1D.cxx:127
 RooSegmentedIntegrator1D.cxx:128
 RooSegmentedIntegrator1D.cxx:129
 RooSegmentedIntegrator1D.cxx:130
 RooSegmentedIntegrator1D.cxx:131
 RooSegmentedIntegrator1D.cxx:132
 RooSegmentedIntegrator1D.cxx:133
 RooSegmentedIntegrator1D.cxx:134
 RooSegmentedIntegrator1D.cxx:135
 RooSegmentedIntegrator1D.cxx:136
 RooSegmentedIntegrator1D.cxx:137
 RooSegmentedIntegrator1D.cxx:138
 RooSegmentedIntegrator1D.cxx:139
 RooSegmentedIntegrator1D.cxx:140
 RooSegmentedIntegrator1D.cxx:141
 RooSegmentedIntegrator1D.cxx:142
 RooSegmentedIntegrator1D.cxx:143
 RooSegmentedIntegrator1D.cxx:144
 RooSegmentedIntegrator1D.cxx:145
 RooSegmentedIntegrator1D.cxx:146
 RooSegmentedIntegrator1D.cxx:147
 RooSegmentedIntegrator1D.cxx:148
 RooSegmentedIntegrator1D.cxx:149
 RooSegmentedIntegrator1D.cxx:150
 RooSegmentedIntegrator1D.cxx:151
 RooSegmentedIntegrator1D.cxx:152
 RooSegmentedIntegrator1D.cxx:153
 RooSegmentedIntegrator1D.cxx:154
 RooSegmentedIntegrator1D.cxx:155
 RooSegmentedIntegrator1D.cxx:156
 RooSegmentedIntegrator1D.cxx:157
 RooSegmentedIntegrator1D.cxx:158
 RooSegmentedIntegrator1D.cxx:159
 RooSegmentedIntegrator1D.cxx:160
 RooSegmentedIntegrator1D.cxx:161
 RooSegmentedIntegrator1D.cxx:162
 RooSegmentedIntegrator1D.cxx:163
 RooSegmentedIntegrator1D.cxx:164
 RooSegmentedIntegrator1D.cxx:165
 RooSegmentedIntegrator1D.cxx:166
 RooSegmentedIntegrator1D.cxx:167
 RooSegmentedIntegrator1D.cxx:168
 RooSegmentedIntegrator1D.cxx:169
 RooSegmentedIntegrator1D.cxx:170
 RooSegmentedIntegrator1D.cxx:171
 RooSegmentedIntegrator1D.cxx:172
 RooSegmentedIntegrator1D.cxx:173
 RooSegmentedIntegrator1D.cxx:174
 RooSegmentedIntegrator1D.cxx:175
 RooSegmentedIntegrator1D.cxx:176
 RooSegmentedIntegrator1D.cxx:177
 RooSegmentedIntegrator1D.cxx:178
 RooSegmentedIntegrator1D.cxx:179
 RooSegmentedIntegrator1D.cxx:180
 RooSegmentedIntegrator1D.cxx:181
 RooSegmentedIntegrator1D.cxx:182
 RooSegmentedIntegrator1D.cxx:183
 RooSegmentedIntegrator1D.cxx:184
 RooSegmentedIntegrator1D.cxx:185
 RooSegmentedIntegrator1D.cxx:186
 RooSegmentedIntegrator1D.cxx:187
 RooSegmentedIntegrator1D.cxx:188
 RooSegmentedIntegrator1D.cxx:189
 RooSegmentedIntegrator1D.cxx:190
 RooSegmentedIntegrator1D.cxx:191
 RooSegmentedIntegrator1D.cxx:192
 RooSegmentedIntegrator1D.cxx:193
 RooSegmentedIntegrator1D.cxx:194
 RooSegmentedIntegrator1D.cxx:195
 RooSegmentedIntegrator1D.cxx:196
 RooSegmentedIntegrator1D.cxx:197
 RooSegmentedIntegrator1D.cxx:198
 RooSegmentedIntegrator1D.cxx:199
 RooSegmentedIntegrator1D.cxx:200
 RooSegmentedIntegrator1D.cxx:201
 RooSegmentedIntegrator1D.cxx:202
 RooSegmentedIntegrator1D.cxx:203
 RooSegmentedIntegrator1D.cxx:204
 RooSegmentedIntegrator1D.cxx:205
 RooSegmentedIntegrator1D.cxx:206
 RooSegmentedIntegrator1D.cxx:207
 RooSegmentedIntegrator1D.cxx:208
 RooSegmentedIntegrator1D.cxx:209
 RooSegmentedIntegrator1D.cxx:210
 RooSegmentedIntegrator1D.cxx:211
 RooSegmentedIntegrator1D.cxx:212
 RooSegmentedIntegrator1D.cxx:213
 RooSegmentedIntegrator1D.cxx:214
 RooSegmentedIntegrator1D.cxx:215