source: Sophya/trunk/SophyaLib/Samba/alm.cc@ 758

Last change on this file since 758 was 729, checked in by ansari, 26 years ago

addition des Ylm etc.

File size: 2.0 KB
Line 
1#include "alm.h"
2template <class T>
3Alm<T>::Alm(const TVector<T>& clin, const r_8 fwhm)
4
5{
6
7
8 /*=======================================================================
9 creates the a_lm from the power spectrum,
10 assuming they are gaussian and complex
11 with a variance given by C(l)
12
13 the input file should contain : l and C(l) with *consecutive* l's
14 (missing C(l) are put to 0.)
15
16 because the map is real we have : a_l-m = (-)^m conjug(a_lm)
17 so we actually compute them only for m >= 0
18
19=======================================================================*/
20 int_4 nlmax= clin.NElts()-1;
21
22 //alm.ReSize(nlmax);
23 ReSizeRow(nlmax+1);
24
25 r_8 sig_smooth = fwhm/sqrt(8.*log(2.))/(60.*180.)* M_PI;
26 int_4 n_l = nlmax+1;
27
28
29 // --- smoothes the initial power spectrum ---
30 TVector<T> cl=clin;
31 for (int l=0;l<n_l;l++)
32 {
33 r_8 gauss=exp(-l*(l+1.)*sig_smooth*sig_smooth);
34 cl(l)*=(T)gauss;
35 }
36
37
38 // --- generates randomly the alm according to their power spectrum ---
39 r_8 hsqrt2 = 1.0 / Rac2;
40
41 for (int l=0;l<n_l;l++)
42 {
43 T rms=sqrt(cl(l));
44 // ------ m = 0 ------
45 complex<T> zeta1(NorRand());
46 (*this)(l,0) = zeta1 * rms;
47
48 //------ m > 0 ------
49 for (int m=1;m<=l;m++)
50 {
51 complex<T> aux1(hsqrt2);
52 complex<T> aux2(NorRand(),NorRand());
53 zeta1=aux1*aux2;
54 (*this)(l,m)=rms*zeta1;
55 }
56 }
57}
58
59
60template <class T>
61TVector<T> Alm<T>::powerSpectrum() const
62{
63 int_4 nlmax=Lmax();
64
65 TVector<T> pow(nlmax+1);
66 pow.SetTemp(true);
67
68 for (int l=0; l<=nlmax;l++)
69 {
70 pow(l)=( (*this)(l,0) ).real()*( (*this)(l,0) ).real();
71 for (int m=1; m<=l; m++)
72 {
73 pow(l)+=2.*( (*this)(l,m) ).real()*( (*this)(l,m) ).real()+
74 2.*( (*this)(l,m) ).imag()*( (*this)(l,m) ).imag();
75 }
76 pow(l)/=(2.*l+1.);
77 }
78 return pow;
79}
80
81#ifdef __CXX_PRAGMA_TEMPLATES__
82#pragma define_template Alm<r_8>
83#pragma define_template Alm<r_4>
84#endif
85#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
86template class Alm<r_8>;
87template class Alm<r_4>;
88#endif
Note: See TracBrowser for help on using the repository browser.