BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtAmplitudeSum.hh
Go to the documentation of this file.
1/*******************************************************************************
2 * Project: BaBar detector at the SLAC PEP-II B-factory
3 * Package: EvtGenBase
4 * File: $Id: EvtAmplitudeSum.hh,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
5 * Author: Alexei Dvoretskii, [email protected], 2001-2002
6 *
7 * Copyright (C) 2002 Caltech
8 *******************************************************************************/
9
10#ifndef EVT_AMPLITUDE_SUM_HH
11#define EVT_AMPLITUDE_SUM_HH
12
13#include <stdio.h>
14#include <assert.h>
15#include <vector>
17
18template <class T>
19class EvtAmplitudeSum : public EvtAmplitude<T> {
20
21public:
22
25 : EvtAmplitude<T>(other)
26 {
27 int i;
28 for(i=0;i<other.nTerms();i++) {
29
30 EvtComplex c = other.c(i);
31 _c.push_back(c);
32 EvtAmplitude<T>* amp = other.getTerm(i);
33 assert(amp);
34 EvtAmplitude<T>* amp1 = amp->clone();
35 assert(amp1);
36 _term.push_back(amp1);
37 }
38 }
39
41 {
42 int i;
43 for(i=0;i<_term.size();i++) {
44
45 delete _term[i];
46 }
47 }
48
49 virtual EvtAmplitude<T>* clone() const
50 {
51 return new EvtAmplitudeSum<T>(*this);
52 }
53
54
56 {
57 _c.push_back(c);
58 _term.push_back(amp.clone());
59 }
60
62 {
63 assert(amp);
64 _c.push_back(c);
65 _term.push_back(amp);
66 }
67
68 int nTerms() const { return _term.size(); } // number of terms
69
70 void print() const {
71
72 int N = nTerms();
73 printf("Amplitude has %d terms\n",N);
74 int i;
75 for(i=0;i<N;i++) {
76 printf("c%d = (%f,%f)\n",i,real(_c[i]),imag(_c[i]));
77 assert(_term[i]);
78 }
79 }
80
81
82 inline EvtComplex c(int i) const { return _c[i]; }
83 inline EvtAmplitude<T>* getTerm(int i) const { return _term[i]; }
84
85protected:
86
87 virtual EvtComplex amplitude(const T& p) const
88 {
89 if(_term.size() == 0)
90 printf("Warning: amplitude sum has zero terms\n");
91
92 EvtComplex value = 0.;
93 int i;
94 for(i=0;i<_term.size();i++) {
95
96 value+=_c[i]*_term[i]->evaluate(p);
97 }
98 return value;
99 }
100
101private:
102
103 std::vector<EvtComplex> _c; // coefficients
104 std::vector<EvtAmplitude<T>*> _term; // pointers to amplitudes
105};
106
107
108#endif
109
110
double imag(const EvtComplex &c)
Definition: EvtComplex.hh:246
virtual EvtAmplitude< T > * clone() const
EvtAmplitude< T > * getTerm(int i) const
virtual ~EvtAmplitudeSum()
void addTerm(EvtComplex c, const EvtAmplitude< T > &amp)
void print() const
EvtAmplitudeSum(const EvtAmplitudeSum< T > &other)
void addOwnedTerm(EvtComplex c, EvtAmplitude< T > *amp)
virtual EvtComplex amplitude(const T &p) const
int nTerms() const
EvtComplex c(int i) const
virtual EvtAmplitude< T > * clone() const =0