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

Last change on this file since 3730 was 3613, checked in by ansari, 16 years ago

Adaptation a l'introduction de la suite des classes RandomGeneratorInterface et Cie , Reza 30/04/2009

File size: 3.1 KB
Line 
1#include "sopnamsp.h"
2#include "alm.h"
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*/
15template <class T>
16Alm<T>::Alm(const TVector<T>& clin, const r_8 fwhm)
17
18{
19 int_4 nlmax= clin.NElts()-1;
20
21 //alm.ReSize(nlmax);
22 this->ReSizeRow(nlmax+1);
23 GenFromCl(clin, fwhm, *(RandomGeneratorInterface::GetGlobalRandGenP()) );
24}
25
26/*!
27 fwhm specifies the gaussian beam half witdh in arc.minutes
28*/
29template <class T>
30Alm<T>::Alm(const TVector<T>& clin, const r_8 fwhm, RandomGeneratorInterface & rg)
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
41template <class T>
42void Alm<T>::GenFromCl(const TVector<T> & clin, const r_8 fwhm, RandomGeneratorInterface & rg)
43{
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 ---
63 TVector<T> cl(clin, false);
64 int l;
65 for (l=0;l<n_l;l++)
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
75 for (l=0;l<n_l;l++)
76 {
77 T rms=sqrt(cl(l));
78 // ------ m = 0 ------
79 complex<T> zeta1((T)rg.Gaussian() );
80 (*this)(l,0) = zeta1 * rms;
81
82 //------ m > 0 ------
83 for (int m=1;m<=l;m++)
84 {
85 complex<T> aux1(hsqrt2);
86 complex<T> aux2((T)rg.Gaussian() , (T)rg.Gaussian() );
87 zeta1=aux1*aux2;
88 (*this)(l,m)=rms*zeta1;
89 }
90 }
91}
92
93
94template <class T>
95TVector<T> Alm<T>::powerSpectrum() const
96{
97 int_4 nlmax=Lmax();
98
99 TVector<T> powsp(nlmax+1);
100
101 for (int l=0; l<=nlmax;l++)
102 {
103 powsp(l)=( (*this)(l,0) ).real()*( (*this)(l,0) ).real();
104 for (int m=1; m<=l; m++)
105 {
106 powsp(l)+=2.*( (*this)(l,m).real()*(*this)(l,m).real()+
107 (*this)(l,m).imag()*(*this)(l,m).imag() );
108 }
109 powsp(l)/=(2.*l+1.);
110 }
111 return powsp;
112}
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
122
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)
128template class SOPHYA::Alm<r_8>;
129template class SOPHYA::Alm<r_4>;
130#endif
Note: See TracBrowser for help on using the repository browser.