EvtGen
2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Toggle main menu visibility
Loading...
Searching...
No Matches
src
EvtGenModels
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
21
#include "
EvtGenModels/EvtItgAbsIntegrator.hh
"
22
23
//-------------
24
// C Headers --
25
//-------------
26
extern
"C"
{
27
}
28
29
#include "
EvtGenBase/EvtReport.hh
"
30
31
#include "
EvtGenModels/EvtItgAbsFunction.hh
"
32
33
#include <iostream>
34
#include <math.h>
35
using
std::endl;
36
37
EvtItgAbsIntegrator::EvtItgAbsIntegrator
(
const
EvtItgAbsFunction
& theFunction ) :
38
m_myFunction
( theFunction )
39
{
40
}
41
42
double
EvtItgAbsIntegrator::normalisation
()
const
43
{
44
return
evaluateIt
(
m_myFunction
.lowerRange(),
m_myFunction
.upperRange() );
45
}
46
47
double
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
56
double
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
86
void
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
}
EvtItgAbsFunction.hh
EvtItgAbsIntegrator.hh
EvtReport.hh
EvtGenReport
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=nullptr)
Definition
EvtReport.cpp:32
EVTGEN_WARNING
@ EVTGEN_WARNING
Definition
EvtReport.hh:50
EvtItgAbsFunction
Definition
EvtItgAbsFunction.hh:35
EvtItgAbsIntegrator::trapezoid
double trapezoid(double lower, double higher, int n, double &result) const
Definition
EvtItgAbsIntegrator.cpp:56
EvtItgAbsIntegrator::EvtItgAbsIntegrator
EvtItgAbsIntegrator()
EvtItgAbsIntegrator::m_myFunction
const EvtItgAbsFunction & m_myFunction
Definition
EvtItgAbsIntegrator.hh:48
EvtItgAbsIntegrator::evaluateIt
virtual double evaluateIt(double lower, double higher) const =0
EvtItgAbsIntegrator::evaluate
double evaluate(double lower, double upper) const
Definition
EvtItgAbsIntegrator.cpp:47
EvtItgAbsIntegrator::boundsCheck
void boundsCheck(double &, double &) const
Definition
EvtItgAbsIntegrator.cpp:86
EvtItgAbsIntegrator::normalisation
double normalisation() const
Definition
EvtItgAbsIntegrator.cpp:42
Generated by
1.17.0