BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtItgAbsIntegrator.cc
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2//
3// Copyright Information: See EvtGen/COPYRIGHT
4//
5// Environment:
6// This software is part of the EvtGen package developed jointly
7// for the BaBar and CLEO collaborations. If you use all or part
8// of it, please give an appropriate acknowledgement.
9//
10// Module: EvtItgIntegrator.cc
11//
12// Description:
13// Simpson integrator (Stolen and modified from
14// the BaBar IntegrationUtils package - author: Phil Strother).
15//
16// Modification history:
17//
18// Jane Tinslay March 21, 2001 Module adapted for use in
19// EvtGen
20//
21//------------------------------------------------------------------------
24
25//-------------
26// C Headers --
27//-------------
28extern "C" {}
29
30#include <iostream>
31#include <math.h>
32
34#include "EvtItgAbsFunction.hh"
35using std::endl;
36
38 : _myFunction( theFunction ) {}
39
41
43 return evaluateIt( _myFunction.lowerRange(), _myFunction.upperRange() );
44}
45
46double EvtItgAbsIntegrator::evaluate( double lower, double upper ) const {
47
48 double newLower( lower ), newUpper( upper );
49
50 boundsCheck( newLower, newUpper );
51
52 return evaluateIt( newLower, newUpper );
53}
54
55double EvtItgAbsIntegrator::trapezoid( double lower, double higher, int n,
56 double& result ) const {
57
58 if ( n == 1 )
59 return 0.5 * ( higher - lower ) * ( _myFunction( lower ) + _myFunction( higher ) );
60
61 int it, j;
62
63 for ( it = 1, j = 1; j < n - 1; j++ ) it <<= 1;
64
65 double itDouble( it );
66
67 double sum( 0.0 );
68
69 double deltaX( ( higher - lower ) / itDouble );
70
71 double x( lower + 0.5 * deltaX );
72
73 for ( j = 1; j <= it; j++ )
74 {
75 sum += _myFunction( x );
76 x += deltaX;
77 }
78
79 result = 0.5 * ( result + ( higher - lower ) * sum / itDouble );
80
81 return result;
82}
83
84void EvtItgAbsIntegrator::boundsCheck( double& lower, double& upper ) const {
85
86 if ( lower < _myFunction.lowerRange() )
87 {
88 report( WARNING, "EvtGen" )
89 << "Warning in EvtItgAbsIntegrator::evaluate. Lower bound " << lower
90 << " of integral "
91 << " is less than lower bound " << _myFunction.lowerRange()
92 << " of function. No contribution from this range will be counted." << endl;
93 lower = _myFunction.lowerRange();
94 }
95
96 if ( upper > _myFunction.upperRange() )
97 {
98 report( WARNING, "EvtGen" )
99 << "Warning in EvtItgAbsIntegrator::evaluate. Upper bound " << upper
100 << " of integral "
101 << " is greater than upper bound " << _myFunction.upperRange()
102 << " of function. No contribution from this range will be counted." << endl;
103 upper = _myFunction.upperRange();
104 }
105}
const Int_t n
Double_t x[10]
ostream & report(Severity severity, const char *facility)
Definition EvtReport.cc:34
@ WARNING
Definition EvtReport.hh:50
double lowerRange() const
double trapezoid(double lower, double higher, int n, double &result) const
virtual double evaluateIt(double lower, double higher) const =0
EvtItgAbsIntegrator(const EvtItgAbsFunction &)
double evaluate(double lower, double upper) const