CLHEP 2.4.7.1
C++ Class Library for High Energy Physics
FourierFit.icc
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id:
3#include <sstream>
4#include <cmath>
5#include <complex>
6namespace Genfun {
7
8FUNCTION_OBJECT_IMP(FourierFit)
9
10inline
11FourierFit::FourierFit(unsigned int N):
12 N(N)
13{
14 for (unsigned int i=0;i<N;i++) {
15 std::ostringstream stream;
16 stream << "Fraction " << i;
17 fraction.push_back(new Parameter(stream.str(), 0.5, 0.0, 1.0));
18 }
19 for (unsigned int i=0;i<N;i++) {
20 std::ostringstream stream;
21 stream << "Phase " << i;
22 phase.push_back(new Parameter(stream.str(), M_PI, 0.0, 2.0*M_PI));
23 }
24}
25
26inline
28 for (unsigned int i=0;i<N;i++) {
29 delete fraction[i];
30 delete phase[i];
31 }
32}
33
34inline
36 N(right.N)
37{
38 for (int i=0;i<N;i++) {
39 fraction.push_back(new Parameter(*right.fraction[i]));
40 phase.push_back(new Parameter(*right.phase[i]));
41 }
42}
43
44inline
45double FourierFit::operator() (double x) const {
46
47 unsigned int n=N;
48 std::complex<double> P=0.0;
49 std::complex<double> I(0,1.0);
50 double f=1.0;
51 while (1) {
52 if (n==0) {
53 double fn=1.0;
54 double Pn=sqrt(1/2.0/M_PI);
55
56 P+=(sqrt(f*fn)*Pn);
57 break;
58 }
59 else {
60 double fn=getFraction(n-1)->getValue();
61 double px=getPhase(n-1)->getValue();
62 double Pn=sqrt(1/M_PI)*sin(n*x/2.0);
63 P+=exp(I*px)*sqrt(f*fn)*Pn;
64 f*=(1-fn);
65 n--;
66 }
67 }
68 return std::norm(P);
69}
70inline
71unsigned int FourierFit::order() const{
72 return N;
73}
74inline
76 return fraction[i];
77}
78inline
79const Parameter *FourierFit::getFraction(unsigned int i) const{
80 return fraction[i];
81}
82inline
84 return phase[i];
85}
86inline
87const Parameter *FourierFit::getPhase(unsigned int i) const{
88 return phase[i];
89}
90
91
92} // end namespace Genfun
#define FUNCTION_OBJECT_IMP(classname)
Parameter * getFraction(unsigned int i)
virtual double operator()(double argument) const override
FourierFit(unsigned int N)
Parameter * getPhase(unsigned int i)
virtual ~FourierFit()
unsigned int order() const
virtual double getValue() const
Definition Abs.hh:14