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