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

Last change on this file since 3533 was 3510, checked in by ansari, 17 years ago

Nettoyage alm.h .cc , utilisation RandomGenerator par Alm<T> et SphericalTransformServer , Reza 08/08/2008

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