EvtGen 2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Loading...
Searching...
No Matches
EvtItgAbsIntegrator.cpp
Go to the documentation of this file.
1
2/***********************************************************************
3* Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4* *
5* This file is part of EvtGen. *
6* *
7* EvtGen is free software: you can redistribute it and/or modify *
8* it under the terms of the GNU General Public License as published by *
9* the Free Software Foundation, either version 3 of the License, or *
10* (at your option) any later version. *
11* *
12* EvtGen is distributed in the hope that it will be useful, *
13* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15* GNU General Public License for more details. *
16* *
17* You should have received a copy of the GNU General Public License *
18* along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19***********************************************************************/
20
22
23//-------------
24// C Headers --
25//-------------
26extern "C" {
27}
28
30
32
33#include <iostream>
34#include <math.h>
35using std::endl;
36
38 m_myFunction( theFunction )
39{
40}
41
43{
44 return evaluateIt( m_myFunction.lowerRange(), m_myFunction.upperRange() );
45}
46
47double EvtItgAbsIntegrator::evaluate( double lower, double upper ) const
48{
49 double newLower( lower ), newUpper( upper );
50
51 boundsCheck( newLower, newUpper );
52
53 return evaluateIt( newLower, newUpper );
54}
55
56double EvtItgAbsIntegrator::trapezoid( double lower, double higher, int n,
57 double& result ) const
58{
59 if ( n == 1 )
60 return 0.5 * ( higher - lower ) *
61 ( m_myFunction( lower ) + m_myFunction( higher ) );
62
63 int it, j;
64
65 for ( it = 1, j = 1; j < n - 1; j++ )
66 it <<= 1;
67
68 double itDouble( it );
69
70 double sum( 0.0 );
71
72 double deltaX( ( higher - lower ) / itDouble );
73
74 double x( lower + 0.5 * deltaX );
75
76 for ( j = 1; j <= it; j++ ) {
77 sum += m_myFunction( x );
78 x += deltaX;
79 }
80
81 result = 0.5 * ( result + ( higher - lower ) * sum / itDouble );
82
83 return result;
84}
85
86void EvtItgAbsIntegrator::boundsCheck( double& lower, double& upper ) const
87{
88 if ( lower < m_myFunction.lowerRange() ) {
89 EvtGenReport( EVTGEN_WARNING, "EvtGen" )
90 << "Warning in EvtItgAbsIntegrator::evaluate. Lower bound "
91 << lower << " of integral "
92 << " is less than lower bound " << m_myFunction.lowerRange()
93 << " of function. No contribution from this range will be counted."
94 << endl;
95 lower = m_myFunction.lowerRange();
96 }
97
98 if ( upper > m_myFunction.upperRange() ) {
99 EvtGenReport( EVTGEN_WARNING, "EvtGen" )
100 << "Warning in EvtItgAbsIntegrator::evaluate. Upper bound "
101 << upper << " of integral "
102 << " is greater than upper bound " << m_myFunction.upperRange()
103 << " of function. No contribution from this range will be counted."
104 << endl;
105 upper = m_myFunction.upperRange();
106 }
107}
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=nullptr)
Definition EvtReport.cpp:32
@ EVTGEN_WARNING
Definition EvtReport.hh:50
double trapezoid(double lower, double higher, int n, double &result) const
const EvtItgAbsFunction & m_myFunction
virtual double evaluateIt(double lower, double higher) const =0
double evaluate(double lower, double upper) const
void boundsCheck(double &, double &) const