source: Sophya/trunk/Cosmo/SimLSS/cmvtstpk.cc@ 3805

Last change on this file since 3805 was 3805, checked in by cmv, 15 years ago

Refonte totale de la structure des classes InitialSpectrum, TransfertFunction, GrowthFactor, PkSpectrum et classes tabulate pour lecture des fichiers CAMB, cmv 24/07/2010

File size: 7.8 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <iostream>
4#include <stdlib.h>
5#include <stdio.h>
6#include <string.h>
7#include <math.h>
8#include <unistd.h>
9#include "timing.h"
10#include "histos.h"
11#include "tvector.h"
12#include "ntuple.h"
13#include "perandom.h"
14
15#include "constcosmo.h"
16#include "pkspectrum.h"
17#include "geneutils.h"
18
19void usage(void);
20void usage(void) {
21cout
22<<"cmvtstpk [options] z_redshift"<<endl
23<<" -H h100 -B Ob0 -M Om0 -L Ol0,w0"<<endl
24<<" -k npt,lkmin,lkmax : les valeurs sont en log10"<<endl
25<<" -s scale : on normalise le spectre avec scale"<<endl
26<<" -w : write spectra on ASCII file"<<endl
27<<" -F filename : read also CAMB file"<<endl;
28}
29
30int main(int narg,char *arg[])
31{
32 // -- WMAP
33 double h100=0.71, Om0=0.267804, Ob0 = 0.0444356, Ol0=0.73,w0=-1.;
34
35 double ns = 1., as = 1.;
36 int npt = 10000;
37 double lkmin = -3., lkmax=2.;
38 double scale = 2.54499e+07; // normalisation du spectre a z=0 selon SDSS
39 bool wrascii = false;
40 string fcmbfile = "";
41
42 char c;
43 while((c = getopt(narg,arg,"hwk:s:H:M:B:L:F:")) != -1) {
44 switch (c) {
45 case 'H' :
46 sscanf(optarg,"%lf",&h100);
47 break;
48 case 'M' :
49 sscanf(optarg,"%lf",&Om0);
50 break;
51 case 'B' :
52 sscanf(optarg,"%lf",&Ob0);
53 break;
54 case 'L' :
55 sscanf(optarg,"%lf,%lf",&Ol0,&w0);
56 break;
57 case 'k' :
58 sscanf(optarg,"%d,%lf,%lf",&npt,&lkmin,&lkmax);
59 if(npt<=0) npt=1000;
60 if(lkmax<lkmin) {lkmin=-4.; lkmax=2.;}
61 break;
62 case 's' :
63 sscanf(optarg,"%lf",&scale);
64 break;
65 case 'w' :
66 wrascii = true;
67 break;
68 case 'F' :
69 fcmbfile = optarg;
70 break;
71 case 'h' :
72 default :
73 usage(); return -1;
74 }
75 }
76 double dlk=(lkmax-lkmin)/npt;
77
78 // Fill z value into list
79 double zval = 0.;
80 if(optind<narg) zval = atof(arg[optind]);
81
82 cout<<"h100="<<h100<<" Om0="<<Om0<<" Ob0="<<Ob0<<" Ol0="<<Ol0<<" w0="<<w0<<endl;
83 cout<<"lkmin="<<lkmin<<" lkmax="<<lkmax<<" npt="<<npt<<" dlk="<<dlk<<endl;
84 cout<<"scale="<<scale<<endl;
85 cout<<"zval="<<zval<<endl;
86 cout<<"fcmbfile="<<fcmbfile<<endl;
87
88 //--------------------------
89 InitialPowerLaw pkini(ns,as);
90 pkini.SetNorm(scale);
91
92 TransfertEisenstein tf(h100,Om0-Ob0,Ob0,T_CMB_Par,false);
93 cout<<"kpeak="<<tf.KPeak()<<endl;
94 TransfertEisenstein tfnosc2(tf); tfnosc2.SetNoOscEnv(2);
95 TransfertEisenstein tfnosc1(tf); tfnosc1.SetNoOscEnv(1);
96 TransfertEisenstein tfnob(h100,Om0,0.,T_CMB_Par,true);
97
98 GrowthEisenstein d1(Om0,Ol0);
99 cout<<"GrowthFactor: "<<d1(zval)<<endl;
100
101 PkSpecCalc pk0(pkini,tf,d1,0.);
102 PkSpecCalc pk0nosc2(pkini,tfnosc2,d1,0.);
103 PkSpecCalc pk0nosc1(pkini,tfnosc1,d1,0.);
104 PkSpecCalc pk0nob(pkini,tfnob,d1,0.);
105
106 PkSpecCalc pkz(pkini,tf,d1,zval);
107 PkSpecCalc pkznosc2(pkini,tfnosc2,d1,zval);
108 PkSpecCalc pkznosc1(pkini,tfnosc1,d1,zval);
109 PkSpecCalc pkznob(pkini,tfnob,d1,zval);
110
111 PkTabulate* pkcamb = NULL;
112 if(fcmbfile.size()>0) {
113 cout<<endl<<"PkTabulate for CAMB"<<endl;
114 pkcamb = new PkTabulate;
115 pkcamb->ReadCAMB(fcmbfile,h100,0.);
116 pkcamb->SetInterpTyp(1);
117 if(pkcamb->NPoints()==0) {delete pkcamb; pkcamb = NULL;}
118 }
119
120 //--------------------------
121 Histo hd1(0.,20.,10000); hd1.ReCenterBin();
122 FuncToHisto(d1,hd1,false);
123
124 Histo hpkz(lkmin,lkmax,npt); hpkz.ReCenterBin();
125 FuncToHisto(pkz,hpkz,true);
126 TVector<r_8> vpkz(npt);
127 FuncToVec(pkz,vpkz,lkmin,lkmax,true);
128
129 FunRan talea(hpkz,true);
130 Histo halea(hpkz); halea.Zero();
131 int nalea = 100000;
132 for(int i=0;i<nalea;i++) halea.Add(talea.Random());
133 halea *= hpkz.Sum()/halea.Sum();
134
135 //--------------------------
136 const int n = 15;
137 const char *vname[n] = {
138 "k","pkini",
139 "tf","pk0","pk",
140 "tfnosc2","pk0nosc2","pknosc2",
141 "tfnosc1","pk0nosc1","pknosc1",
142 "tfnob","pk0nob","pknob","pktab"
143 };
144 NTuple nt(n,vname);
145 double xnt[n];
146
147 for(double lk=lkmin;lk<lkmax+dlk/2.;lk+=dlk) {
148 double k = pow(10.,lk);
149 xnt[0] = k;
150 xnt[1] = pkini(k);
151 xnt[2] = tf(k);
152 xnt[3] = pk0(k);
153 xnt[4] = pkz(k,zval);
154 xnt[5] = tfnosc2(k);
155 xnt[6] = pk0nosc2(k);
156 xnt[7] = pkznosc2(k,zval);
157 xnt[8] = tfnosc1(k);
158 xnt[9] = pk0nosc1(k);
159 xnt[10] = pkznosc1(k,zval);
160 xnt[11] = tfnob(k);
161 xnt[12] = pk0nob(k);
162 xnt[13] = pkznob(k,zval);
163 if(pkcamb != NULL) xnt[14] = (*pkcamb)(k); else xnt[14] = 0;
164 nt.Fill(xnt);
165 }
166
167 if(pkcamb != NULL) {delete pkcamb; pkcamb = NULL;}
168
169 //--------------------------
170 if(wrascii) {
171 cout<<">>>> ASCII"<<endl;
172 FILE * fdata = fopen("cmvtstpk.data","w");
173 fprintf(fdata,"# z= %g : k(Mpc^-1) pkini, tf pk0 pkz, tfnosc2 pk0nosc2 pkznosc2, ",zval);
174 fprintf(fdata,"tfnosc1 pk0nosc1 pkznosc1, tfnob pk0nob pkznob\n");
175 for(double lk=lkmin;lk<lkmax+dlk/2.;lk+=dlk) {
176 double k = pow(10.,lk);
177 fprintf(fdata,"%e %e %e %e %e %e %e %e %e %e %e %e %e %e\n",
178 k,pkini(k),
179 tf(k),pk0(k),pkz(k,zval),
180 tfnosc2(k),pk0nosc2(k),pkznosc2(k,zval),
181 tfnosc1(k),pk0nosc1(k),pkznosc1(k,zval),
182 tfnob(k),pk0nob(k),pkznob(k,zval));
183 }
184 fclose(fdata);
185 }
186
187 //--------------------------
188 cout<<">>>> Ecriture"<<endl;
189 string tag = "cmvtstpk.ppf";
190 POutPersist pos(tag);
191 tag = "nt"; pos.PutObject(nt,tag);
192 tag = "hd1"; pos.PutObject(hd1,tag);
193 tag = "hpkz"; pos.PutObject(hpkz,tag);
194 tag = "vpkz"; pos.PutObject(vpkz,tag);
195 tag = "halea"; pos.PutObject(halea,tag);
196 return 0;
197}
198
199/*
200openppf cmvtstpk.ppf
201
202#### growth-factor
203zone
204n/plot hd1.val%x ! ! "nsta connectpoints"
205n/plot hd1.1./(1.+x)%x ! ! "nsta connectpoints same red"
206
207#### Spectre initial
208zone
209n/plot nt.log10(pkini)%log10(k) pkini>0.&&k>0. ! "nsta connectpoints"
210
211#### fct de transfert
212zone
213n/plot nt.tf%k k>0&&tf>0 ! "nsta connectpoints logx logy"
214n/plot nt.tfnosc2%k k>0&&tfnosc2>0 ! "nsta connectpoints same red logx logy"
215n/plot nt.tfnosc1%k k>0&&tfnosc1>0 ! "nsta connectpoints same blue logx logy"
216n/plot nt.tfnob%k k>0&&tfnob>0 ! "nsta connectpoints same green logx logy"
217
218n/plot nt.tf/tfnosc2%k k>0&&tfnosc2>0 ! "nsta connectpoints red logx"
219n/plot nt.tf/tfnosc1%k k>0&&tfnosc1>0 ! "nsta connectpoints same blue logx"
220n/plot nt.tf/tfnob%k k>0&&tfnob>0 ! "nsta connectpoints same green logx"
221addline -10 1 10 1
222
223#### Spectre a z=0
224zone
225n/plot nt.pk0%k k>0&&pk0>0 ! "nsta connectpoints logx logy"
226n/plot nt.pk0nosc2%k k>0&&pk0nosc2>0 ! "nsta connectpoints same red logx logy"
227n/plot nt.pk0nosc1%k k>0&&pk0nosc1>0 ! "nsta connectpoints same blue logx logy"
228n/plot nt.pk0nob%k k>0&&pk0nob>0 ! "nsta connectpoints same green logx logy"
229
230# Check
231zone 2 2
232n/plot nt.pk0/pkini-tf*tf%k k>0&&pkini>0 ! "nsta crossmarker3 logx"
233n/plot nt.pk0nosc2/pkini-tfnosc2*tfnosc2%k k>0&&pkini>0 ! "nsta crossmarker3 logx"
234n/plot nt.pk0nosc1/pkini-tfnosc1*tfnosc1%k k>0&&pkini>0 ! "nsta crossmarker3 logx"
235n/plot nt.pk0nob/pkini-tfnob*tfnob%k k>0&&pkini>0 ! "nsta crossmarker3 logx"
236
237#### Spectre a z
238zone
239n/plot nt.pk%k k>0&&pk>0 ! "nsta connectpoints logx logy"
240n/plot nt.pknosc2%k k>0&&pknosc2>0 ! "nsta connectpoints same red logx logy"
241n/plot nt.pknosc1%k k>0&&pknosc1>0 ! "nsta connectpoints same blue logx logy"
242n/plot nt.pknob%k k>0&&pknob>0 ! "nsta connectpoints same green logx logy"
243
244n/plot nt.pk/pknosc2%k k>0&&pknosc2>0 ! "nsta connectpoints red logx"
245n/plot nt.pk/pknosc1%k k>0&&pknosc1>0 ! "nsta connectpoints same blue logx"
246n/plot nt.pk/pknob%k k>0&&pknob>0 ! "nsta connectpoints same green logx"
247addline -10 1 10 1
248
249#### Le spectre version Delta^2
250set D2 k*k*k*pk/(2*M_PI*M_PI)
251n/plot nt.$D2%k k>0 ! "nsta crossmarker3 connectpoints logx"
252
253#### Test des transferts dans Histo et TVector
254zone 1 2
255n/plot nt.pk%log10(k) ! ! "nsta crossmarker3"
256disp hpkz "same red"
257
258disp vpkz
259c++exec cout<<hpkz(0)<<" =?= "<<vpkz(0)<<endl;
260
261zone
262disp hpkz
263disp halea "same red"
264
265#### Le spectre tabule
266n/plot nt.pk%k pk>0&&k>0 ! "nsta connectpoints logx logy"
267n/plot nt.pktab%k pktab>0&&k>0 ! "nsta connectpoints same red logx logy"
268
269n/plot nt.(pktab-pk)%k k>0&&pk>0 ! "nsta connectpoints"
270n/plot nt.(pktab-pk)/pk%k k>0&&pk>0 ! "nsta connectpoints"
271
272n/plot nt.pk/pknosc2%k k>0&&pknosc2>0 ! "nsta connectpoints logx"
273n/plot nt.pktab/pknosc2%k k>0&&pknosc2>0 ! "nsta connectpoints same red logx"
274
275*/
Note: See TracBrowser for help on using the repository browser.