5 #include <gsl/gsl_sf_legendre.h> 9 FUNCTION_OBJECT_IMP(LegendreFit)
12 LegendreFit::LegendreFit(
unsigned int N):
13 N(N),coefA(N),coefASq(2*N)
15 for (
unsigned int i=0;i<N;i++) {
16 std::ostringstream stream;
17 stream <<
"Fraction " << i;
18 fraction.push_back(
new Parameter(stream.str(), 0.5, 0.0, 1.0));
20 for (
unsigned int i=0;i<N;i++) {
21 std::ostringstream stream;
22 stream <<
"Phase " << i;
23 phase.push_back(
new Parameter(stream.str(), M_PI, 0.0, 2.0*M_PI));
28 LegendreFit::~LegendreFit() {
29 for (
unsigned int i=0;i<N;i++) {
36 LegendreFit::LegendreFit(
const LegendreFit & right):
38 N(right.N),coefA(right.N), coefASq(2*right.N)
40 for (
unsigned int i=0;i<N;i++) {
41 fraction.push_back(
new Parameter(*right.fraction[i]));
42 phase.push_back(
new Parameter(*right.phase[i]));
47 double LegendreFit::operator() (
double x)
const {
48 recomputeCoefficients();
49 std::vector<double> Pk(N+1);
50 gsl_sf_legendre_Pl_array(N, x, &Pk[0]);
52 std::complex<double> P=0.0;
53 std::complex<double> I(0,1.0);
56 double Pn=sqrt((2*n+1.0)/2.0)*Pk[n];
62 double Pn=sqrt((2*n+1.0)/2.0)*Pk[n];
71 unsigned int LegendreFit::order()
const{
75 Parameter *LegendreFit::getFraction(
unsigned int i) {
79 const Parameter *LegendreFit::getFraction(
unsigned int i)
const{
83 Parameter *LegendreFit::getPhase(
unsigned int i) {
87 const Parameter *LegendreFit::getPhase(
unsigned int i)
const{
91 const LegendreCoefficientSet & LegendreFit::coefficientsA()
const {
92 recomputeCoefficients();
97 const LegendreCoefficientSet & LegendreFit::coefficientsASq()
const {
98 recomputeCoefficients();
99 unsigned int LMAX=coefA.getLMax();
100 for (
unsigned int L=0;L<=2*LMAX;L++) {
102 for (
unsigned int l1=0;l1<=LMAX;l1++) {
103 for (
unsigned int l2=0;l2<=LMAX;l2++) {
104 if (((l1+l2) >= L) && abs(l1-l2) <=
int(L)) {
105 coefASq(L) += (coefA(l1)*
107 sqrt((2*l1+1)*(2*l2+1)/4.0)*
108 pow(ClebschGordan(l1,l2,0,0,L,0),2));
117 void LegendreFit::recomputeCoefficients()
const {
119 std::complex<double> P=0.0;
120 std::complex<double> I(0,1.0);
129 double fn=getFraction(n-1)->getValue();
130 double px=getPhase(n-1)->getValue();
131 coefA(n)=exp(I*px)*sqrt(f*fn);