CLHEP  2.4.7.2
C++ Class Library for High Energy Physics
LegendreExpansion.icc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id:
3 #include <sstream>
4 #include <cmath>
5 #include <gsl/gsl_sf_legendre.h>
6 #include <complex>
7 #include <cstdlib>
8 #include <stdexcept>
9 namespace Genfun {
10 
11  FUNCTION_OBJECT_IMP(LegendreExpansion)
12 
13  class LegendreExpansion::Clockwork {
14 
15  public:
16 
17  Clockwork(LegendreExpansion::Type type, const LegendreCoefficientSet & coefficients):type(type),coefficients(coefficients){}
18 
19  LegendreExpansion::Type type;
20  LegendreCoefficientSet coefficients;
21 
22  };
23 
24 
25  inline
26  LegendreExpansion::LegendreExpansion(Type type, const LegendreCoefficientSet & coefficients):
27  c(new Clockwork(type,coefficients))
28  {
29 
30  }
31 
32 
33  inline
34  LegendreExpansion::~LegendreExpansion() {
35  delete c;
36  }
37 
38  inline
39  LegendreExpansion::LegendreExpansion(const LegendreExpansion & right):
40  AbsFunction(),
41  c(new Clockwork(right.c->type,right.c->coefficients))
42  {
43  }
44 
45  inline
46  double LegendreExpansion::operator() (double x) const {
47 
48  int N=c->coefficients.getLMax();
49  std::vector<double> Pk(N+1);
50  gsl_sf_legendre_Pl_array(N, x, &Pk[0]);
51  unsigned int n=N;
52  std::complex<double> P=0.0;
53  std::complex<double> I(0,1.0);
54  while (1) {
55  if (n==0) {
56  P+=c->coefficients(n)*Pk[n];
57  break;
58  }
59  else {
60  P+=c->coefficients(n)*Pk[n];
61  n--;
62  }
63  }
64 
65  double retVal=0;
66  if (c->type==MAGSQ) return norm(P);
67  if (c->type==MAG) return abs(P);
68  if (c->type==REAL) return real(P);
69  if (c->type==IMAG) return imag(P);
70  if (!finite(retVal)) {
71  throw std::runtime_error("Non-finite return value in LegendreExpansion");
72  }
73  return retVal;
74  }
75 
76  inline
77  const LegendreCoefficientSet & LegendreExpansion::coefficientSet() const {
78  return c->coefficients;
79  }
80 
81 } // end namespace Genfun
Definition: Airy.icc:9
Clockwork(LegendreExpansion::Type type, const LegendreCoefficientSet &coefficients)