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
EvtGenBase
EvtAmplitudeSum.hh
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
#ifndef EVT_AMPLITUDE_SUM_HH
22
#define EVT_AMPLITUDE_SUM_HH
23
24
#include "
EvtGenBase/EvtAmplitude.hh
"
25
26
#include <assert.h>
27
#include <memory>
28
#include <vector>
29
30
template
<
class
T>
31
class
EvtAmplitudeSum
:
public
EvtAmplitude
<T> {
32
public
:
33
EvtAmplitudeSum
() {}
34
EvtAmplitudeSum
(
const
EvtAmplitudeSum<T>
& other ) :
35
EvtAmplitude
<T>( other )
36
{
37
int
i;
38
for
( i = 0; i < other.nTerms(); i++ ) {
39
EvtComplex
c
= other.c( i );
40
m_c
.push_back(
c
);
41
EvtAmplitude<T>
* amp = other.getTerm( i );
42
assert( amp );
43
EvtAmplitude<T>
* amp1 = amp->
clone
();
44
assert( amp1 );
45
m_term
.push_back( amp1 );
46
}
47
}
48
49
virtual
~EvtAmplitudeSum
()
50
{
51
for
(
size_t
i = 0; i <
m_term
.size(); i++ ) {
52
delete
m_term
[i];
53
}
54
}
55
56
EvtAmplitudeSum<T>
*
clone
()
const override
57
{
58
return
new
EvtAmplitudeSum<T>
( *
this
);
59
}
60
61
void
addTerm
(
EvtComplex
c
,
const
EvtAmplitude<T>
& amp )
62
{
63
m_c
.push_back(
c
);
64
m_term
.push_back( amp.
clone
() );
65
}
66
67
void
addOwnedTerm
(
EvtComplex
c
, std::unique_ptr<
EvtAmplitude<T>
> amp )
68
{
69
assert( amp );
70
m_c
.push_back(
c
);
71
m_term
.push_back( amp.release() );
72
}
73
74
int
nTerms
()
const
{
return
m_term
.size(); }
// number of terms
75
76
void
print
()
const
77
{
78
int
N =
nTerms
();
79
printf(
"Amplitude has %d terms\n"
, N );
80
int
i;
81
for
( i = 0; i < N; i++ ) {
82
printf(
"c%d = (%f,%f)\n"
, i,
real
(
m_c
[i] ),
imag
(
m_c
[i] ) );
83
assert(
m_term
[i] );
84
}
85
}
86
87
inline
EvtComplex
c
(
int
i )
const
{
return
m_c
[i]; }
88
inline
EvtAmplitude<T>
*
getTerm
(
int
i )
const
{
return
m_term
[i]; }
89
90
protected
:
91
EvtComplex
amplitude
(
const
T& p )
const override
92
{
93
if
(
m_term
.size() == 0 )
94
printf(
"Warning: amplitude sum has zero terms\n"
);
95
96
EvtComplex
value = 0.;
97
98
for
(
size_t
i = 0; i <
m_term
.size(); i++ ) {
99
value +=
m_c
[i] *
m_term
[i]->evaluate( p );
100
}
101
return
value;
102
}
103
104
private
:
105
std::vector<EvtComplex>
m_c
;
// coefficients
106
std::vector<EvtAmplitude<T>*>
m_term
;
// pointers to amplitudes
107
};
108
109
#endif
EvtAmplitude.hh
imag
double imag(const EvtComplex &c)
Definition
EvtComplex.hh:237
real
double real(const EvtComplex &c)
Definition
EvtComplex.hh:232
EvtAmplitudeSum::m_term
std::vector< EvtAmplitude< T > * > m_term
Definition
EvtAmplitudeSum.hh:106
EvtAmplitudeSum::EvtAmplitudeSum
EvtAmplitudeSum()
Definition
EvtAmplitudeSum.hh:33
EvtAmplitudeSum::getTerm
EvtAmplitude< T > * getTerm(int i) const
Definition
EvtAmplitudeSum.hh:88
EvtAmplitudeSum::addOwnedTerm
void addOwnedTerm(EvtComplex c, std::unique_ptr< EvtAmplitude< T > > amp)
Definition
EvtAmplitudeSum.hh:67
EvtAmplitudeSum::~EvtAmplitudeSum
virtual ~EvtAmplitudeSum()
Definition
EvtAmplitudeSum.hh:49
EvtAmplitudeSum::addTerm
void addTerm(EvtComplex c, const EvtAmplitude< T > &)
Definition
EvtAmplitudeSum.hh:61
EvtAmplitudeSum::print
void print() const
Definition
EvtAmplitudeSum.hh:76
EvtAmplitudeSum::amplitude
EvtComplex amplitude(const T &p) const override
Definition
EvtAmplitudeSum.hh:91
EvtAmplitudeSum::EvtAmplitudeSum
EvtAmplitudeSum(const EvtAmplitudeSum< T > &other)
Definition
EvtAmplitudeSum.hh:34
EvtAmplitudeSum::m_c
std::vector< EvtComplex > m_c
Definition
EvtAmplitudeSum.hh:105
EvtAmplitudeSum::clone
EvtAmplitudeSum< T > * clone() const override
Definition
EvtAmplitudeSum.hh:56
EvtAmplitudeSum::nTerms
int nTerms() const
Definition
EvtAmplitudeSum.hh:74
EvtAmplitudeSum::c
EvtComplex c(int i) const
Definition
EvtAmplitudeSum.hh:87
EvtAmplitude::clone
virtual EvtAmplitude< T > * clone() const =0
EvtAmplitude::EvtAmplitude
EvtAmplitude()=default
EvtComplex
Definition
EvtComplex.hh:29
Generated by
1.17.0