source: Sophya/trunk/SophyaLib/Samba/anagen.cc@ 468

Last change on this file since 468 was 468, checked in by ansari, 26 years ago

First versions of anagen and syngen -- Alex Kim

File size: 4.3 KB
Line 
1#include <math.h>
2#include "anagen.h"
3#include "lambuilder.h"
4#include "fftserver.h"
5
6/* assumes the map is symmetric about the equator and that
7each strip is divided equally*/
8
9extern "C" {
10 void fft_gpd_(long double* ,int& ,int& ,int& ,int& ,long double*);
11 }
12
13void map2almgen(int nsmax,int nlmax,int nmmax,const SphericalMap& map,
14 vector< vector< complex<double> > >& alm, double cos_theta_cut){
15
16 // REAL*4 map(12*nsmax**2) ! 4*12*nsmax**2
17
18 // REAL*4 powspec(0:nlmax)
19
20 // integer npmiss,npmt,id_miss(10000)
21
22 alm.resize(nlmax+1);
23 for (int i=0; i< (signed) alm.size();i++)
24 {
25 alm[i].resize(nmmax+1);
26 for (int j=0; j< (signed) alm[i].size();j++)alm[i][j]=0;
27 }
28
29 /*-----------------------------------------------------------------------
30 computes the integral in phi : phas_m(theta)
31 for each parallele from north to south pole
32 -----------------------------------------------------------------------*/
33
34 vector< complex<double> > phas_n(nmmax+1), phas_s(nmmax+1);
35 for (int ith = 0; ith <= (map.NbThetaSlices()+1)/2-1;ith++){
36 int nph;
37 double phi0;
38 float theta;
39 Vector phin, datan, phis, datas;
40 map.GetThetaSlice(map.NbThetaSlices()-ith-1,theta,phis,datas);
41 map.GetThetaSlice(ith,theta,phin,datan);
42 for (int i=0;i< nmmax+1;i++){
43 phas_n[i]=0; phas_s[i]=0;
44 }
45 nph = phin.NElts();
46 phi0 = phin(0);
47 double cth = cos(theta);
48
49 //part of the sky out of the symetric cut
50 bool keep_it = (abs(cth) >= cos_theta_cut);
51
52 //make sure that map is well defined
53 if (keep_it){
54 comp_phas2gen(nsmax,nlmax,nmmax,datan,nph,phas_n,phi0);
55 }
56
57 if (ith != map.NbThetaSlices()/2 && keep_it){
58 comp_phas2gen(nsmax,nlmax,nmmax,datas,nph,phas_s,phi0);
59 }
60 /*-----------------------------------------------------------------------
61 computes the a_lm by integrating over theta
62 lambda_lm(theta) * phas_m(theta)
63 for each m and l
64 -----------------------------------------------------------------------*/
65 LambdaBuilder lb(acos(cth),nlmax,nmmax);
66 double domega=map.PixSolAngle(map.PixIndexSph(theta,phi0));
67 for (int m = 0; m <= nmmax; m++)
68 {
69 alm[m][m] += (lb.lamlm(m,m) * (phas_n[m] + phas_s[m])) * domega; //m,m even
70 for (int l = m+1; l<= nlmax; l++)
71 {
72 alm[l][m] += (lb.lamlm(l,m) * phas_n[m] + lb.lamlm(l,m,-1)*phas_s[m])*domega; //assuming the map is symmetric about the equator
73 }
74 }
75 }
76}
77
78
79void comp_phas2gen(int nsmax,int nlmax,int nmmax, Vector datain,
80 int nph,vector< complex<double> >& dataout,double phi0){
81 /*=======================================================================
82 integrates (data * phi-dependence-of-Ylm) over phi
83 --> function of m can be computed by FFT
84 with 0<= m <= npoints/2 (: Nyquist)
85 because the data is real the negative m are the conjugate of the
86 positive ones
87
88 arguments d'appels : GLM
89 =======================================================================*/
90
91 //FFTVector inf(datain);
92 //FFTVector outf=FFTServer::solve(inf,-1);
93 FFTServer fft;
94 Vector outf;
95 //cout<<"in :"<<datain<<endl;
96 fft.fftb(datain,outf);
97 // cout<<outf<<endl;
98 long double * data = new long double[nph*2];
99 //outf.d((double*)data, nph);
100 data[0]=outf(0); data[1]=0;
101 for (int i=2;i<=nph;i++) data[i]=outf(i-1);
102 for (int i=nph+1;i<2*nph;i++) data[i]=0;
103
104 int ksign = -1;
105// long double data[nph*2];
106
107// for (int i = 0; i< nph;i++){
108// data[2*i] = datain(i);
109// data[2*i+1]=0;
110// }
111
112// long double work[nph*2];
113// int dum1=1;
114// int dum0=0;
115// fft_gpd_(data,nph,dum1,ksign,dum0,work); /* real to complex
116// for any nph (not necessary power of 2)*/
117// //in the output the frequencies are respectively 0,1,2,..,nph/2,-nph/2+1,..,-2,-1
118// // only the first nph/2+1 (positive freq.) are interesting
119// for (int i=0;i<nph*2;i++){cout << "heh"<<test[i]<<" "<<data[i]<<endl;}*/
120
121 int im_max = min(nph/2,nmmax);
122 dataout.resize(nmmax+1);
123 for (int i = 1;i <= im_max + 1;i++){
124 int m = ksign*(i-1);
125 complex<double> shit(data[2*(i-1)],data[2*(i-1)+1]);
126 complex<double> fuck(cos(m*phi0),sin(m*phi0));
127 dataout[i-1]=shit*fuck;
128 }
129 for (int i = im_max + 2;i <= nmmax + 1;i++){
130 dataout[i-1] = 0;
131 }
132 delete data;
133}
Note: See TracBrowser for help on using the repository browser.