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.
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 #include "EvtGenBase/EvtPatches.hh"
24 
25 //-------------
26 // C Headers --
27 //-------------
28 extern "C" {
29 }
30 
31 #include "EvtGenBase/EvtReport.hh"
32 
34 
35 #include <iostream>
36 #include <math.h>
37 using std::endl;
38 
40  _myFunction( theFunction )
41 {
42 }
43 
45 {
47 }
48 
49 double EvtItgAbsIntegrator::evaluate( double lower, double upper ) const
50 {
51  double newLower( lower ), newUpper( upper );
52 
53  boundsCheck( newLower, newUpper );
54 
55  return evaluateIt( newLower, newUpper );
56 }
57 
58 double EvtItgAbsIntegrator::trapezoid( double lower, double higher, int n,
59  double& result ) const
60 {
61  if ( n == 1 )
62  return 0.5 * ( higher - lower ) *
63  ( _myFunction( lower ) + _myFunction( higher ) );
64 
65  int it, j;
66 
67  for ( it = 1, j = 1; j < n - 1; j++ )
68  it <<= 1;
69 
70  double itDouble( it );
71 
72  double sum( 0.0 );
73 
74  double deltaX( ( higher - lower ) / itDouble );
75 
76  double x( lower + 0.5 * deltaX );
77 
78  for ( j = 1; j <= it; j++ ) {
79  sum += _myFunction( x );
80  x += deltaX;
81  }
82 
83  result = 0.5 * ( result + ( higher - lower ) * sum / itDouble );
84 
85  return result;
86 }
87 
88 void EvtItgAbsIntegrator::boundsCheck( double& lower, double& upper ) const
89 {
90  if ( lower < _myFunction.lowerRange() ) {
91  EvtGenReport( EVTGEN_WARNING, "EvtGen" )
92  << "Warning in EvtItgAbsIntegrator::evaluate. Lower bound "
93  << lower << " of integral "
94  << " is less than lower bound " << _myFunction.lowerRange()
95  << " of function. No contribution from this range will be counted."
96  << endl;
97  lower = _myFunction.lowerRange();
98  }
99 
100  if ( upper > _myFunction.upperRange() ) {
101  EvtGenReport( EVTGEN_WARNING, "EvtGen" )
102  << "Warning in EvtItgAbsIntegrator::evaluate. Upper bound "
103  << upper << " of integral "
104  << " is greater than upper bound " << _myFunction.upperRange()
105  << " of function. No contribution from this range will be counted."
106  << endl;
107  upper = _myFunction.upperRange();
108  }
109 }
virtual double evaluateIt(double lower, double higher) const =0
double normalisation() const
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
Definition: EvtReport.cpp:33
double lowerRange() const
double evaluate(double lower, double upper) const
void boundsCheck(double &, double &) const
double trapezoid(double lower, double higher, int n, double &result) const
double upperRange() const
const EvtItgAbsFunction & _myFunction