StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHbtYlm.cxx
1 /****************************************************************************
2  * $Id: StHbtYlm.cxx,v 1.1 2013/01/18 14:46:02 yyang Exp $
3  * **************************************************************************
4  * Description: Part of StHbtCorrFctnDirectYlm utility
5  * Provide ultilities for complex and matrix process.
6  *
7  ***************************************************************************/
8 
9 #include "StHbtYlm.h"
10 #include <gsl/gsl_sf.h>
11 #define LRANGE 10
12 
13 std::complex<double> StHbtYlm::Ceiphi(double phi)
14 {
15  return ( std::complex<double>( cos(phi), sin(phi) ) );
16 }
17 
18 double StHbtYlm::Legendre(int ell, double ctheta)
19 {
20  return ( gsl_sf_legendre_Pl(ell, ctheta) );
21 }
22 
23 std::complex<double> StHbtYlm::Ylm(int ell, int m, double theta, double phi)
24 {
25  double ctheta;
26  std::complex<double> answer;
27  std::complex<double> ci(0.0, 1.0);
28  ctheta = cos(theta);
29  answer = gsl_sf_legendre_sphPlm(ell, abs(m), ctheta) * Ceiphi(m * phi);
30  if (m < 0) {
31  if (abs(m) % 2) answer *= -1.0;
32  }
33  return (answer);
34 }
35 
36 std::complex<double> StHbtYlm::Ylm(int ell, int m, double x, double y, double z)
37 {
38  std::complex<double> answer;
39  double ctheta, phi;
40  double r = sqrt(x * x + y * y + z * z);
41  if ( r < 1e-10 || fabs(z) < 1e-10 ) ctheta = 0.0;
42  else ctheta = z / r;
43  phi = atan2(y, x);
44  answer = gsl_sf_legendre_sphPlm(ell, abs(m), ctheta) * Ceiphi(m * phi);
45  if (m < 0) {
46  if (abs(m) % 2) answer *= -1.0;
47  }
48  return (answer);
49 }
50 
51 void StHbtYlm::YlmUpToL(int lmax, double x, double y, double z, std::complex<double>* ylms)
52 {
53  std::complex<double> answer;
54  double ctheta, phi;
55  int lcur = 0;
56  double lpol;
57 
58  double coss[LRANGE];
59  double sins[LRANGE];
60 
61  double r = sqrt(x * x + y * y + z * z);
62  if ( r < 1e-10 || fabs(z) < 1e-10 ) ctheta = 0.0;
63  else ctheta = z / r;
64  phi = atan2(y, x);
65 
66  for (int iter = 1; iter <= lmax; iter++) {
67  coss[iter - 1] = cos(iter * phi);
68  sins[iter - 1] = sin(iter * phi);
69  }
70  ylms[lcur++] = gsl_sf_legendre_sphPlm(0, 0, ctheta) * std::complex<double>(1, 0);
71 
72  for (int il = 1; il <= lmax; il++) {
73  for (int im = 0; im <= il; im++) {
74  lpol = gsl_sf_legendre_sphPlm(il, im, ctheta);
75  if (im) {
76  ylms[lcur + il + im] = lpol * std::complex<double>(coss[im - 1], sins[im - 1]);
77  if (im % 2)
78  ylms[lcur + il - im] = -lpol* std::complex<double>(coss[im - 1], -sins[im - 1]);
79  else
80  ylms[lcur + il - im] = lpol * std::complex<double>(coss[im - 1], -sins[im - 1]);
81  }
82  else {
83  ylms[lcur + il] = lpol * std::complex<double>(1, 0);
84  }
85  }
86  lcur += 2 * il + 1;
87  }
88 }
89 
90 void StHbtYlm::YlmUpToL(int lmax, double ctheta, double phi, std::complex<double>* ylms)
91 {
92  int lcur = 0;
93  double lpol;
94 
95  double coss[LRANGE];
96  double sins[LRANGE];
97 
98  for (int iter = 1; iter <= lmax; iter++) {
99  coss[iter - 1] = cos(iter * phi);
100  sins[iter - 1] = sin(iter * phi);
101  }
102  ylms[lcur++] = gsl_sf_legendre_sphPlm(0, 0, ctheta) * std::complex<double>(1, 0);
103 
104  for (int il = 1; il <= lmax; il++) {
105  for (int im = 0; im <= il; im++) {
106  lpol = gsl_sf_legendre_sphPlm(il, im, ctheta);
107  if (im) {
108  ylms[lcur + il + im] = lpol * std::complex<double>(coss[im - 1], sins[im - 1]);
109  if (im % 2)
110  ylms[lcur + il - im] = -lpol* std::complex<double>(coss[im - 1], -sins[im - 1]);
111  else
112  ylms[lcur + il - im] = lpol * std::complex<double>(coss[im - 1], -sins[im - 1]);
113  }
114  else {
115  ylms[lcur + il] = lpol * std::complex<double>(1, 0);
116  }
117  }
118  lcur += 2 * il + 1;
119  }
120 }
121 
122 double StHbtYlm::ReYlm(int ell, int m, double theta, double phi)
123 {
124  return ( real( StHbtYlm::Ylm(ell, m, theta, phi) ) );
125 }
126 
127 double StHbtYlm::ImYlm(int ell, int m, double theta, double phi)
128 {
129  return ( imag( StHbtYlm::Ylm(ell, m, theta, phi) ) );
130 }
131 
132 double StHbtYlm::ReYlm(int ell, int m, double x, double y, double z)
133 {
134  return ( real( StHbtYlm::Ylm(ell, m, x, y, z) ) );
135 }
136 
137 double StHbtYlm::ImYlm(int ell, int m, double x, double y, double z)
138 {
139  return ( imag( StHbtYlm::Ylm(ell, m, x, y, z) ) );
140 }
141 
142 /*************************************************************************
143  * $Log: StHbtYlm.cxx,v $
144  * Revision 1.1 2013/01/18 14:46:02 yyang
145  * Add ultilities for SHD of CF
146  *
147  ************************************************************************/