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

Last change on this file since 3353 was 3318, checked in by cmv, 18 years ago

TransfertTabulate pour avoir les fct de transfert de CMBFast cmv 28/08/2007

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