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
EvtItgSimpsonIntegrator.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
29//---------------
30// C++ Headers --
31//---------------
32
33#include <math.h>
34
35//-------------------------------
36// Collaborating Class Headers --
37//-------------------------------
38
40
42using std::endl;
43
45 const EvtItgAbsFunction& theFunction, double precision, int maxLoop ) :
46 EvtItgAbsIntegrator( theFunction ),
47 m_precision( precision ),
48 m_maxLoop( maxLoop )
49{
50}
51
52double EvtItgSimpsonIntegrator::evaluateIt( double lower, double higher ) const
53{
54 // EvtGenReport(EVTGEN_INFO,"EvtGen")<<"in evaluate"<<endl;
55 int j;
56 double result( 0.0 );
57 double s, st, ost( 0.0 );
58 for ( j = 1; j < 4; j++ ) {
59 st = trapezoid( lower, higher, j, result );
60 s = ( 4.0 * st - ost ) / 3.0;
61 ost = st;
62 }
63
64 double olds( s );
65 st = trapezoid( lower, higher, j, result );
66 s = ( 4.0 * st - ost ) / 3.0;
67
68 if ( fabs( s - olds ) < m_precision * fabs( olds ) ||
69 ( s == 0.0 && olds == 0.0 ) )
70 return s;
71
72 ost = st;
73
74 for ( j = 5; j < m_maxLoop; j++ ) {
75 st = trapezoid( lower, higher, j, result );
76 s = ( 4.0 * st - ost ) / 3.0;
77
78 if ( fabs( s - olds ) < m_precision * fabs( olds ) ||
79 ( s == 0.0 && olds == 0.0 ) )
80 return s;
81 olds = s;
82 ost = st;
83 }
84
85 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
86 << "Severe error in EvtItgSimpsonIntegrator. Failed to converge after loop with 2**"
87 << m_maxLoop << " calls to the integrand in." << endl;
88
89 return 0.0;
90}
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=nullptr)
Definition EvtReport.cpp:32
@ EVTGEN_ERROR
Definition EvtReport.hh:49
double trapezoid(double lower, double higher, int n, double &result) const
EvtItgAbsIntegrator(const EvtItgAbsFunction &)
double evaluateIt(double, double) const override
EvtItgSimpsonIntegrator(const EvtItgAbsFunction &, double precision=1.0e-5, int maxLoop=20)