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

Last change on this file since 3521 was 3485, checked in by cmv, 17 years ago

reprise de la normalisation du spectre cmv 09/04/2008

File size: 6.5 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 normalise le spectre avec 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 = 2.54499e+07; // normalisation du spectre a z=0 selon SDSS
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 pkini.SetNorm(scale);
84
85 TransfertEisenstein tf(h100,Om0-Ob0,Ob0,T_CMB_Par,false);
86 cout<<"kpeak="<<tf.KPeak()<<endl;
87 TransfertEisenstein tfnosc2(tf); tfnosc2.SetNoOscEnv(2);
88 TransfertEisenstein tfnosc1(tf); tfnosc1.SetNoOscEnv(1);
89 TransfertEisenstein tfnob(h100,Om0,0.,T_CMB_Par,true);
90
91 GrowthFactor d1(Om0,Ol0);
92 cout<<"GrowthFactor: "<<d1(zval)<<endl;
93
94 PkSpectrum0 pk0(pkini,tf);
95 PkSpectrum0 pk0nosc2(pkini,tfnosc2);
96 PkSpectrum0 pk0nosc1(pkini,tfnosc1);
97 PkSpectrum0 pk0nob(pkini,tfnob);
98
99 PkSpectrumZ pkz(pk0,d1,zval);
100 PkSpectrumZ pkznosc2(pk0nosc2,d1,zval);
101 PkSpectrumZ pkznosc1(pk0nosc1,d1,zval);
102 PkSpectrumZ pkznob(pk0nob,d1,zval);
103
104 //--------------------------
105 Histo hd1(0.,20.,10000); hd1.ReCenterBin();
106 FuncToHisto(d1,hd1,false);
107
108 Histo hpkz(lkmin,lkmax,npt); hpkz.ReCenterBin();
109 FuncToHisto(pkz,hpkz,true);
110 TVector<r_8> vpkz(npt);
111 FuncToVec(pkz,vpkz,lkmin,lkmax,true);
112
113 FunRan talea(hpkz,true);
114 Histo halea(hpkz); halea.Zero();
115 int nalea = 100000;
116 for(int i=0;i<nalea;i++) halea.Add(talea.Random());
117 halea *= hpkz.Sum()/halea.Sum();
118
119 //--------------------------
120 const int n = 14;
121 char *vname[n] = {
122 "k","pkini",
123 "tf","pk0","pk",
124 "tfnosc2","pk0nosc2","pknosc2",
125 "tfnosc1","pk0nosc1","pknosc1",
126 "tfnob","pk0nob","pknob"
127 };
128 NTuple nt(n,vname);
129 double xnt[n];
130
131 for(double lk=lkmin;lk<lkmax+dlk/2.;lk+=dlk) {
132 double k = pow(10.,lk);
133 xnt[0] = k;
134 xnt[1] = pkini(k);
135 xnt[2] = tf(k);
136 xnt[3] = pk0(k);
137 xnt[4] = pkz(k,zval);
138 xnt[5] = tfnosc2(k);
139 xnt[6] = pk0nosc2(k);
140 xnt[7] = pkznosc2(k,zval);
141 xnt[8] = tfnosc1(k);
142 xnt[9] = pk0nosc1(k);
143 xnt[10] = pkznosc1(k,zval);
144 xnt[11] = tfnob(k);
145 xnt[12] = pk0nob(k);
146 xnt[13] = pkznob(k,zval);
147 nt.Fill(xnt);
148 }
149
150 //--------------------------
151 if(wrascii) {
152 cout<<">>>> ASCII"<<endl;
153 FILE * fdata = fopen("cmvtstpk.data","w");
154 fprintf(fdata,"# z= %g : k(Mpc^-1) pkini, tf pk0 pkz, tfnosc2 pk0nosc2 pkznosc2, ",zval);
155 fprintf(fdata,"tfnosc1 pk0nosc1 pkznosc1, tfnob pk0nob pkznob\n");
156 for(double lk=lkmin;lk<lkmax+dlk/2.;lk+=dlk) {
157 double k = pow(10.,lk);
158 fprintf(fdata,"%e %e %e %e %e %e %e %e %e %e %e %e %e %e\n",
159 k,pkini(k),
160 tf(k),pk0(k),pkz(k,zval),
161 tfnosc2(k),pk0nosc2(k),pkznosc2(k,zval),
162 tfnosc1(k),pk0nosc1(k),pkznosc1(k,zval),
163 tfnob(k),pk0nob(k),pkznob(k,zval));
164 }
165 fclose(fdata);
166 }
167
168 //--------------------------
169 cout<<">>>> Ecriture"<<endl;
170 string tag = "cmvtstpk.ppf";
171 POutPersist pos(tag);
172 tag = "nt"; pos.PutObject(nt,tag);
173 tag = "hd1"; pos.PutObject(hd1,tag);
174 tag = "hpkz"; pos.PutObject(hpkz,tag);
175 tag = "vpkz"; pos.PutObject(vpkz,tag);
176 tag = "halea"; pos.PutObject(halea,tag);
177 return 0;
178}
179
180/*
181openppf cmvtstpk.ppf
182
183#### growth-factor
184zone
185n/plot hd1.val%x ! ! "nsta connectpoints"
186
187#### Spectre initial
188zone
189n/plot nt.log10(pkini)%log10(k) pkini>0. ! "nsta connectpoints"
190
191#### Gestion des abscisses
192set xk log10(k)
193set xk k
194
195#### fct de transfert
196zone
197n/plot nt.tf%$xk ! ! "nsta connectpoints"
198n/plot nt.tfnosc2%$xk ! ! "nsta connectpoints same red"
199n/plot nt.tfnosc1%$xk ! ! "nsta connectpoints same blue"
200n/plot nt.tfnob%$xk ! ! "nsta connectpoints same green"
201
202n/plot nt.tf/tfnosc2%$xk ! ! "nsta connectpoints red"
203n/plot nt.tf/tfnosc1%$xk ! ! "nsta connectpoints same blue"
204n/plot nt.tf/tfnob%$xk ! ! "nsta connectpoints same green"
205addline -10 1 10 1
206
207#### Spectre a z=0
208zone
209n/plot nt.pk0%$xk ! ! "nsta connectpoints"
210n/plot nt.pk0nosc2%$xk ! ! "nsta connectpoints same red"
211n/plot nt.pk0nosc1%$xk ! ! "nsta connectpoints same blue"
212n/plot nt.pk0nob%$xk ! ! "nsta connectpoints same green"
213
214# Check
215zone 2 2
216n/plot nt.pk0/pkini-tf*tf%$xk pkini>0 ! "nsta crossmarker3"
217n/plot nt.pk0nosc2/pkini-tfnosc2*tfnosc2%$xk pkini>0 ! "nsta crossmarker3"
218n/plot nt.pk0nosc1/pkini-tfnosc1*tfnosc1%$xk pkini>0 ! "nsta crossmarker3"
219n/plot nt.pk0nob/pkini-tfnob*tfnob%$xk pkini>0 ! "nsta crossmarker3"
220
221#### Spectre a z
222zone
223n/plot nt.pk%$xk ! ! "nsta connectpoints"
224n/plot nt.pknosc2%$xk ! ! "nsta connectpoints same red"
225n/plot nt.pknosc1%$xk ! ! "nsta connectpoints same blue"
226n/plot nt.pknob%$xk ! ! "nsta connectpoints same green"
227
228n/plot nt.pk/pknosc2%$xk ! ! "nsta connectpoints red"
229n/plot nt.pk/pknosc1%$xk ! ! "nsta connectpoints same blue"
230n/plot nt.pk/pknob%$xk ! ! "nsta connectpoints same green"
231addline -10 1 10 1
232
233#### Le spectre version Delta^2
234set D2 k*k*k*pk/(2*M_PI*M_PI)
235n/plot nt.$D2%$xk ! ! "nsta crossmarker3 connectpoints"
236
237#### Test des transferts dans Histo et TVector
238zone 1 2
239n/plot nt.pk%log10(k) ! ! "nsta crossmarker3"
240disp hpkz "same red"
241
242disp vpkz
243c++exec cout<<hpkz(0)<<" =?= "<<vpkz(0)<<endl;
244
245zone
246disp hpkz
247disp halea "same red"
248
249*/
Note: See TracBrowser for help on using the repository browser.