| 1 | #include "alm.h" | 
|---|
| 2 | template <class T> | 
|---|
| 3 | Alm<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 | int l; | 
|---|
| 32 | for (l=0;l<n_l;l++) | 
|---|
| 33 | { | 
|---|
| 34 | r_8 gauss=exp(-l*(l+1.)*sig_smooth*sig_smooth); | 
|---|
| 35 | cl(l)*=(T)gauss; | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 |  | 
|---|
| 39 | //     --- generates randomly the alm according to their power spectrum --- | 
|---|
| 40 | r_8 hsqrt2 = 1.0 / Rac2; | 
|---|
| 41 |  | 
|---|
| 42 | for (l=0;l<n_l;l++) | 
|---|
| 43 | { | 
|---|
| 44 | T rms=sqrt(cl(l)); | 
|---|
| 45 | //        ------ m = 0 ------ | 
|---|
| 46 | complex<T> zeta1(NorRand()); | 
|---|
| 47 | (*this)(l,0)   = zeta1 * rms; | 
|---|
| 48 |  | 
|---|
| 49 | //------ m > 0 ------ | 
|---|
| 50 | for (int m=1;m<=l;m++) | 
|---|
| 51 | { | 
|---|
| 52 | complex<T> aux1(hsqrt2); | 
|---|
| 53 | complex<T> aux2(NorRand(),NorRand()); | 
|---|
| 54 | zeta1=aux1*aux2; | 
|---|
| 55 | (*this)(l,m)=rms*zeta1; | 
|---|
| 56 | } | 
|---|
| 57 | } | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 | template <class T> | 
|---|
| 62 | TVector<T> Alm<T>::powerSpectrum() const | 
|---|
| 63 | { | 
|---|
| 64 | int_4 nlmax=Lmax(); | 
|---|
| 65 |  | 
|---|
| 66 | TVector<T>  pow(nlmax+1); | 
|---|
| 67 | pow.SetTemp(true); | 
|---|
| 68 |  | 
|---|
| 69 | for (int l=0; l<=nlmax;l++) | 
|---|
| 70 | { | 
|---|
| 71 | pow(l)=( (*this)(l,0) ).real()*( (*this)(l,0) ).real(); | 
|---|
| 72 | for (int m=1; m<=l; m++) | 
|---|
| 73 | { | 
|---|
| 74 | pow(l)+=2.*( (*this)(l,m).real()*(*this)(l,m).real()+ | 
|---|
| 75 | (*this)(l,m).imag()*(*this)(l,m).imag() ); | 
|---|
| 76 | } | 
|---|
| 77 | pow(l)/=(2.*l+1.); | 
|---|
| 78 | } | 
|---|
| 79 | return pow; | 
|---|
| 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 Alm<r_8>; | 
|---|
| 88 | template class Alm<r_4>; | 
|---|
| 89 | #endif | 
|---|