evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
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 #include "EvtGenBase/EvtPatches.hh"
24 
25 //-------------
26 // C Headers --
27 //-------------
28 extern "C" {
29 }
30 
31 //---------------
32 // C++ Headers --
33 //---------------
34 
35 #include <math.h>
36 
37 //-------------------------------
38 // Collaborating Class Headers --
39 //-------------------------------
40 
41 #include "EvtGenBase/EvtReport.hh"
42 
44 using std::endl;
45 
47  const EvtItgAbsFunction& theFunction, double precision, int maxLoop ) :
48  EvtItgAbsIntegrator( theFunction ),
49  _precision( precision ),
50  _maxLoop( maxLoop )
51 {
52 }
53 
54 double EvtItgSimpsonIntegrator::evaluateIt( double lower, double higher ) const
55 {
56  // EvtGenReport(EVTGEN_INFO,"EvtGen")<<"in evaluate"<<endl;
57  int j;
58  double result( 0.0 );
59  double s, st, ost( 0.0 );
60  for ( j = 1; j < 4; j++ ) {
61  st = trapezoid( lower, higher, j, result );
62  s = ( 4.0 * st - ost ) / 3.0;
63  ost = st;
64  }
65 
66  double olds( s );
67  st = trapezoid( lower, higher, j, result );
68  s = ( 4.0 * st - ost ) / 3.0;
69 
70  if ( fabs( s - olds ) < _precision * fabs( olds ) ||
71  ( s == 0.0 && olds == 0.0 ) )
72  return s;
73 
74  ost = st;
75 
76  for ( j = 5; j < _maxLoop; j++ ) {
77  st = trapezoid( lower, higher, j, result );
78  s = ( 4.0 * st - ost ) / 3.0;
79 
80  if ( fabs( s - olds ) < _precision * fabs( olds ) ||
81  ( s == 0.0 && olds == 0.0 ) )
82  return s;
83  olds = s;
84  ost = st;
85  }
86 
87  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
88  << "Severe error in EvtItgSimpsonIntegrator. Failed to converge after loop with 2**"
89  << _maxLoop << " calls to the integrand in." << endl;
90 
91  return 0.0;
92 }
EvtItgSimpsonIntegrator(const EvtItgAbsFunction &, double precision=1.0e-5, int maxLoop=20)
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
Definition: EvtReport.cpp:33
double trapezoid(double lower, double higher, int n, double &result) const
double evaluateIt(double, double) const override