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
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
25
26#include <assert.h>
27#include <memory>
28#include <vector>
29
30template <class T>
31class EvtAmplitudeSum : public EvtAmplitude<T> {
32 public:
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
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
double imag(const EvtComplex &c)
double real(const EvtComplex &c)
std::vector< EvtAmplitude< T > * > m_term
EvtAmplitude< T > * getTerm(int i) const
void addOwnedTerm(EvtComplex c, std::unique_ptr< EvtAmplitude< T > > amp)
virtual ~EvtAmplitudeSum()
void addTerm(EvtComplex c, const EvtAmplitude< T > &amp)
void print() const
EvtComplex amplitude(const T &p) const override
EvtAmplitudeSum(const EvtAmplitudeSum< T > &other)
std::vector< EvtComplex > m_c
EvtAmplitudeSum< T > * clone() const override
EvtComplex c(int i) const
virtual EvtAmplitude< T > * clone() const =0
EvtAmplitude()=default