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.
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 
30 template <class T>
31 class 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  _c.push_back( c );
41  EvtAmplitude<T>* amp = other.getTerm( i );
42  assert( amp );
43  EvtAmplitude<T>* amp1 = amp->clone();
44  assert( amp1 );
45  _term.push_back( amp1 );
46  }
47  }
48 
49  virtual ~EvtAmplitudeSum()
50  {
51  for ( size_t i = 0; i < _term.size(); i++ ) {
52  delete _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  _c.push_back( c );
64  _term.push_back( amp.clone() );
65  }
66 
67  void addOwnedTerm( EvtComplex c, std::unique_ptr<EvtAmplitude<T>> amp )
68  {
69  assert( amp );
70  _c.push_back( c );
71  _term.push_back( amp.release() );
72  }
73 
74  int nTerms() const { return _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( _c[i] ), imag( _c[i] ) );
83  assert( _term[i] );
84  }
85  }
86 
87  inline EvtComplex c( int i ) const { return _c[i]; }
88  inline EvtAmplitude<T>* getTerm( int i ) const { return _term[i]; }
89 
90  protected:
91  EvtComplex amplitude( const T& p ) const override
92  {
93  if ( _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 < _term.size(); i++ ) {
99  value += _c[i] * _term[i]->evaluate( p );
100  }
101  return value;
102  }
103 
104  private:
105  std::vector<EvtComplex> _c; // coefficients
106  std::vector<EvtAmplitude<T>*> _term; // pointers to amplitudes
107 };
108 
109 #endif
void addTerm(EvtComplex c, const EvtAmplitude< T > &amp)
EvtAmplitudeSum< T > * clone() const override
EvtComplex c(int i) const
std::vector< EvtComplex > _c
void print() const
EvtComplex amplitude(const T &p) const override
virtual EvtAmplitude< T > * clone() const =0
virtual ~EvtAmplitudeSum()
EvtAmplitudeSum(const EvtAmplitudeSum< T > &other)
EvtAmplitude< T > * getTerm(int i) const
double imag(const EvtComplex &c)
Definition: EvtComplex.hh:235
std::vector< EvtAmplitude< T > * > _term
int nTerms() const
double real(const EvtComplex &c)
Definition: EvtComplex.hh:230
void addOwnedTerm(EvtComplex c, std::unique_ptr< EvtAmplitude< T >> amp)
Index other(Index i, Index j)
Definition: EvtCyclic3.cpp:156