CLHEP  2.4.7.2
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>
6 namespace Genfun {
7 
8 FUNCTION_OBJECT_IMP(FourierFit)
9 
10 inline
11 FourierFit::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 
26 inline
27 FourierFit::~FourierFit() {
28  for (unsigned int i=0;i<N;i++) {
29  delete fraction[i];
30  delete phase[i];
31  }
32 }
33 
34 inline
35 FourierFit::FourierFit(const FourierFit & right):
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 
44 inline
45 double 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 }
70 inline
71 unsigned int FourierFit::order() const{
72  return N;
73 }
74 inline
75 Parameter *FourierFit::getFraction(unsigned int i) {
76  return fraction[i];
77 }
78 inline
79 const Parameter *FourierFit::getFraction(unsigned int i) const{
80  return fraction[i];
81 }
82 inline
83 Parameter *FourierFit::getPhase(unsigned int i) {
84  return phase[i];
85 }
86 inline
87 const Parameter *FourierFit::getPhase(unsigned int i) const{
88  return phase[i];
89 }
90 
91 
92 } // end namespace Genfun
Definition: Airy.icc:9