[2615] | 1 | #include "sopnamsp.h"
|
---|
[729] | 2 | #include "alm.h"
|
---|
[3510] | 3 |
|
---|
| 4 |
|
---|
| 5 | /*!
|
---|
| 6 | \class Alm
|
---|
| 7 | \ingroup Samba
|
---|
| 8 | Class for manipulating the coefficients \f$a_{lm}\f$ of the development
|
---|
| 9 | in spherical harmonics of a function efined on a sphere.
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | /*!
|
---|
| 13 | fwhm specifies the gaussian beam half witdh in arc.minutes
|
---|
| 14 | */
|
---|
[729] | 15 | template <class T>
|
---|
| 16 | Alm<T>::Alm(const TVector<T>& clin, const r_8 fwhm)
|
---|
| 17 |
|
---|
| 18 | {
|
---|
[3510] | 19 | int_4 nlmax= clin.NElts()-1;
|
---|
[729] | 20 |
|
---|
[3510] | 21 | //alm.ReSize(nlmax);
|
---|
[3613] | 22 | this->ReSizeRow(nlmax+1);
|
---|
| 23 | GenFromCl(clin, fwhm, *(RandomGeneratorInterface::GetGlobalRandGenP()) );
|
---|
[3510] | 24 | }
|
---|
[729] | 25 |
|
---|
[3510] | 26 | /*!
|
---|
| 27 | fwhm specifies the gaussian beam half witdh in arc.minutes
|
---|
| 28 | */
|
---|
| 29 | template <class T>
|
---|
[3613] | 30 | Alm<T>::Alm(const TVector<T>& clin, const r_8 fwhm, RandomGeneratorInterface & rg)
|
---|
[3510] | 31 | {
|
---|
| 32 | int_4 nlmax= clin.NElts()-1;
|
---|
| 33 |
|
---|
| 34 | //alm.ReSize(nlmax);
|
---|
| 35 | this->ReSizeRow(nlmax+1);
|
---|
| 36 | GenFromCl(clin, fwhm, rg);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | template <class T>
|
---|
[3613] | 42 | void Alm<T>::GenFromCl(const TVector<T> & clin, const r_8 fwhm, RandomGeneratorInterface & rg)
|
---|
[3510] | 43 | {
|
---|
[729] | 44 | /*=======================================================================
|
---|
| 45 | creates the a_lm from the power spectrum,
|
---|
| 46 | assuming they are gaussian and complex
|
---|
| 47 | with a variance given by C(l)
|
---|
| 48 |
|
---|
| 49 | the input file should contain : l and C(l) with *consecutive* l's
|
---|
| 50 | (missing C(l) are put to 0.)
|
---|
| 51 |
|
---|
| 52 | because the map is real we have : a_l-m = (-)^m conjug(a_lm)
|
---|
| 53 | so we actually compute them only for m >= 0
|
---|
| 54 |
|
---|
| 55 | =======================================================================*/
|
---|
| 56 | int_4 nlmax= clin.NElts()-1;
|
---|
| 57 |
|
---|
| 58 | r_8 sig_smooth = fwhm/sqrt(8.*log(2.))/(60.*180.)* M_PI;
|
---|
| 59 | int_4 n_l = nlmax+1;
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | // --- smoothes the initial power spectrum ---
|
---|
[3510] | 63 | TVector<T> cl(clin, false);
|
---|
[833] | 64 | int l;
|
---|
| 65 | for (l=0;l<n_l;l++)
|
---|
[729] | 66 | {
|
---|
| 67 | r_8 gauss=exp(-l*(l+1.)*sig_smooth*sig_smooth);
|
---|
| 68 | cl(l)*=(T)gauss;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | // --- generates randomly the alm according to their power spectrum ---
|
---|
| 73 | r_8 hsqrt2 = 1.0 / Rac2;
|
---|
| 74 |
|
---|
[833] | 75 | for (l=0;l<n_l;l++)
|
---|
[729] | 76 | {
|
---|
| 77 | T rms=sqrt(cl(l));
|
---|
| 78 | // ------ m = 0 ------
|
---|
[3510] | 79 | complex<T> zeta1((T)rg.Gaussian() );
|
---|
[729] | 80 | (*this)(l,0) = zeta1 * rms;
|
---|
| 81 |
|
---|
| 82 | //------ m > 0 ------
|
---|
| 83 | for (int m=1;m<=l;m++)
|
---|
| 84 | {
|
---|
| 85 | complex<T> aux1(hsqrt2);
|
---|
[3510] | 86 | complex<T> aux2((T)rg.Gaussian() , (T)rg.Gaussian() );
|
---|
[729] | 87 | zeta1=aux1*aux2;
|
---|
| 88 | (*this)(l,m)=rms*zeta1;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | template <class T>
|
---|
| 95 | TVector<T> Alm<T>::powerSpectrum() const
|
---|
| 96 | {
|
---|
| 97 | int_4 nlmax=Lmax();
|
---|
| 98 |
|
---|
[1621] | 99 | TVector<T> powsp(nlmax+1);
|
---|
[729] | 100 |
|
---|
| 101 | for (int l=0; l<=nlmax;l++)
|
---|
| 102 | {
|
---|
[1621] | 103 | powsp(l)=( (*this)(l,0) ).real()*( (*this)(l,0) ).real();
|
---|
[729] | 104 | for (int m=1; m<=l; m++)
|
---|
| 105 | {
|
---|
[1621] | 106 | powsp(l)+=2.*( (*this)(l,m).real()*(*this)(l,m).real()+
|
---|
[865] | 107 | (*this)(l,m).imag()*(*this)(l,m).imag() );
|
---|
[729] | 108 | }
|
---|
[1621] | 109 | powsp(l)/=(2.*l+1.);
|
---|
[729] | 110 | }
|
---|
[1621] | 111 | return powsp;
|
---|
[729] | 112 | }
|
---|
[3510] | 113 |
|
---|
| 114 | /*!
|
---|
| 115 | \class Bm
|
---|
| 116 | \ingroup Samba
|
---|
| 117 | Class for a vector with an index running from \f$-m_{max}\f$ to \f$+m_{max}\f$
|
---|
| 118 | (then the size of the vector will be actually \f$2m_{max}+1)\f$.
|
---|
| 119 | This class is used by the spherical harmonics transform server
|
---|
| 120 | */
|
---|
| 121 |
|
---|
[1683] | 122 |
|
---|
[729] | 123 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 124 | #pragma define_template Alm<r_8>
|
---|
| 125 | #pragma define_template Alm<r_4>
|
---|
| 126 | #endif
|
---|
| 127 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[2872] | 128 | template class SOPHYA::Alm<r_8>;
|
---|
| 129 | template class SOPHYA::Alm<r_4>;
|
---|
[729] | 130 | #endif
|
---|