source: Sophya/trunk/Cosmo/SimLSS/cmvtstsch.cc@ 3315

Last change on this file since 3315 was 3284, checked in by cmv, 18 years ago

Creation de cmvschdist.cc cmv 27/07/2007

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 "ntuple.h"
12#include "srandgen.h"
13#include "perandom.h"
14
15#include "geneutils.h"
16#include "cosmocalc.h"
17#include "schechter.h"
18
19void usage(void);
20void usage(void)
21{
22 cout<<"cmvtstsch -m xmin,xmax -a -i perc,dlxinc,dlxmax,glorder -n nbin -N nalea"<<endl
23 <<" xmin,xmax : limites en masse"<<endl
24 <<" perc : see IntegrateFunc"<<endl
25 <<" dlnx : see IntegrateFunc"<<endl
26 <<" si <0 nombre de point dlx = (log10(xmax)-log10(xmin))/(-dlx)"<<endl
27 <<" dlxmax : see IntegrateFunc, si <0 -dlxmax*dlx, si ==0 no check"<<endl
28 <<" glorder : odre gauss-legendre"<<endl
29 <<" nbin : nombre de bins"<<endl
30 <<" nalea : nombre de tirages aleatoires"<<endl
31 <<" -a : init auto de l\'aleatoire"<<endl;
32}
33
34
35int main(int narg,char *arg[])
36{
37 double h75 = 0.71 / 0.75;
38 double nstar = 0.006*pow(h75,3.); //
39 double mstar = pow(10.,9.8/(h75*h75)); // MSol
40 double alpha = -1.37;
41 cout<<"h75= "<<h75<<" nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
42
43 double xmin=1e6, xmax=1e12;
44 double perc=0.01,dlxinc=-1000.,dlxmax=0.; unsigned short glorder=4;
45 int npt = 1000;
46 int nalea = 100000;
47
48 char c;
49 while((c = getopt(narg,arg,"ham:i:n:N:")) != -1) {
50 switch (c) {
51 case 'm' :
52 sscanf(optarg,"%lf,%lf",&xmin,&xmax);
53 break;
54 case 'i' :
55 int ig;
56 sscanf(optarg,"%lf,%lf,%lf,%u",&perc,&dlxinc,&dlxmax,&ig);
57 if(perc<=0.) perc = 0.01;
58 glorder = (ig<=0) ? 4: ig;
59 break;
60 case 'n' :
61 sscanf(optarg,"%d",&npt);
62 if(npt<=0) npt = 1000;
63 break;
64 case 'N' :
65 sscanf(optarg,"%d",&nalea);
66 break;
67 case 'a' :
68 Auto_Ini_Ranf(5);
69 break;
70 case 'h' :
71 default :
72 usage(); return -1;
73 }
74 }
75
76 double lnx1=log10(xmin), lnx2=log10(xmax), dlnx = (lnx2-lnx1)/npt;
77 cout<<"xmin="<<xmin<<" ("<<lnx1<<") xmax="<<xmax<<" ("<<lnx2<<"), dlnx="<<dlnx<<endl;
78
79 if(dlxinc<0.) dlxinc=(lnx2-lnx1)/(-dlxinc);
80 if(dlxmax<0.) dlxmax *= -dlxinc; else if(dlxmax==0.) dlxmax=-1.;
81 cout<<"perc="<<perc<<" dlxinc="<<dlxinc<<" dlxmax="<<dlxmax<<" glorder="<<glorder<<endl;
82
83 cout<<"npt="<<npt<<", nalea="<<nalea<<endl;
84
85 Schechter sch(nstar,mstar,alpha);
86
87 InitTim();
88
89 //-------dn/dm
90 cout<<endl;
91 cout<<"sch(mstar) = "<<sch(mstar)<<" /Mpc^3/Msol"<<endl;
92 sch.SetOutValue(0);
93 cout<<"......"<<endl;
94 for(double lnx=lnx1-3.;lnx<=lnx2-1.;lnx+=1.) {
95 double num = IntegrateFuncLog(sch,lnx,lnx2,perc,dlxinc,dlxmax,glorder);
96 cout<<"["<<lnx<<","<<lnx2<<"] integrated number = "<<num<<" Mpc^-3"<<endl;
97 }
98 cout<<"......"<<endl;
99 for(double lnx=lnx1+1.;lnx<=lnx2+3.;lnx+=1.) {
100 double num = IntegrateFuncLog(sch,lnx1,lnx,perc,dlxinc,dlxmax,glorder);
101 cout<<"["<<lnx1<<","<<lnx<<"] integrated number = "<<num<<" Mpc^-3"<<endl;
102 }
103 cout<<"......"<<endl;
104 for(double lnx=lnx1-3.;lnx<=lnx2+3.;lnx+=1.) {
105 double num = IntegrateFuncLog(sch,lnx,lnx+1.,perc,dlxinc,dlxmax,glorder);
106 cout<<"["<<lnx<<","<<lnx+1.<<"] integrated number = "<<num<<" Mpc^-3"<<endl;
107 }
108 Histo hdndm(lnx1,lnx2,npt); hdndm.ReCenterBin();
109 FuncToHisto(sch,hdndm,true);
110
111 //-------m*dn/dm
112 cout<<endl;
113 sch.SetOutValue(1);
114 cout<<"mstar*sch(mstar) = "<<sch(mstar)<<" Msol/Mpc^3/Msol"<<endl;
115 cout<<"......"<<endl;
116 for(double lnx=lnx1-3.;lnx<=lnx2-1.;lnx+=1.) {
117 double sum = IntegrateFuncLog(sch,lnx,lnx2,perc,dlxinc,dlxmax,glorder);
118 cout<<"["<<lnx<<","<<lnx2<<"] integrated mass = "<<sum<<" Msol.Mpc^-3"<<endl;
119 }
120 cout<<"......"<<endl;
121 for(double lnx=lnx1+1.;lnx<=lnx2+3.;lnx+=1.) {
122 double sum = IntegrateFuncLog(sch,lnx1,lnx,perc,dlxinc,dlxmax,glorder);
123 cout<<"["<<lnx1<<","<<lnx<<"] integrated mass = "<<sum<<" Msol.Mpc^-3"<<endl;
124 }
125 cout<<"......"<<endl;
126 for(double lnx=lnx1-3.;lnx<=lnx2+3.;lnx+=1.) {
127 double sum = IntegrateFuncLog(sch,lnx,lnx+1.,perc,dlxinc,dlxmax,glorder);
128 cout<<"["<<lnx<<","<<lnx+1.<<"] integrated mass = "<<sum<<" Msol.Mpc^-3"<<endl;
129 }
130 Histo hmdndm(lnx1,lnx2,npt); hmdndm.ReCenterBin();
131 FuncToHisto(sch,hmdndm,true);
132
133 //------- Le flux HI pour M=mstar a 1 Gpc
134 cout<<endl;
135 double d = 1000.;
136 double f = Msol2FluxHI(mstar,d);
137 cout<<"FluxHI: d="<<d<<" Mpc:"<<" M= "<<mstar<<" Msol "
138 <<"-> Flux= "<<f<<" W/m^2"<<endl;
139 cout<<"Check... MassHI: d="<<d<<" Mpc:"<<" f= "<<f<<" W/m^2 "
140 <<"-> Mass= "<<FluxHI2Msol(f,d)<<" Msol"<<endl;
141
142 //------- Random
143 Histo hdna(hdndm); hdna.Zero();
144 Histo hmdna(hmdndm); hmdna.Zero();
145 FunRan tirhdndm = FunRan(hdndm,true);
146 FunRan tirhmdndm = FunRan(hmdndm,true);
147 if(nalea>0) {
148 double summ=0.;
149 PrtTim("--- avant tirage aleatoire");
150 for(int i=0;i<nalea;i++) {
151 double a = tirhdndm.RandomInterp();
152 hdna.Add(a);
153 a = tirhmdndm.RandomInterp();
154 summ += pow(10.,a);
155 hmdna.Add(a);
156 }
157 cout<<"Tirgae aleatoire: <m>="<<summ/(double)nalea<<endl;
158 hdna *= hdndm.Sum()/hdna.Sum();
159 hmdna *= hmdndm.Sum()/hmdna.Sum();
160 PrtTim("--- apres tirage aleatoire");
161 }
162
163 //-------
164 const int n = 3;
165 char *vname[n] = {"m","f","mf"};
166 NTuple nt(n,vname);
167 double xnt[n];
168 for(double lx=lnx1;lx<lnx2+dlnx/2.;lx+=dlnx) {
169 double x = pow(10.,lx);
170 xnt[0] = x;
171 sch.SetOutValue(0);
172 xnt[1] = sch(x);
173 sch.SetOutValue(1);
174 xnt[2] = sch(x);
175 nt.Fill(xnt);
176 }
177
178 cout<<"Ecriture"<<endl;
179 string tag = "cmvtstsch.ppf";
180 POutPersist pos(tag);
181 tag = "nt"; pos.PutObject(nt,tag);
182 tag = "hdndm"; pos.PutObject(hdndm,tag);
183 tag = "hmdndm"; pos.PutObject(hmdndm,tag);
184 tag = "hdna"; pos.PutObject(hdna,tag);
185 tag = "hmdna"; pos.PutObject(hmdna,tag);
186 Histo hdum1(tirhdndm);
187 tag = "tirhdndm"; pos.PutObject(hdum1,tag);
188 Histo hdum2(tirhmdndm);
189 tag = "tirhmdndm"; pos.PutObject(hdum2,tag);
190
191 return 0;
192}
193
194/*
195openppf cmvtstsch.ppf
196
197#--- la fonction de masse numerique
198zone 2 2
199n/plot nt.f%m ! ! "nsta crossmarker3"
200n/plot nt.f%log10(m) ! ! "nsta crossmarker3"
201n/plot nt.log10(f)%log10(m) f>0. ! "nsta crossmarker3"
202
203# ce qu'on integre (en log10)
204n/plot nt.m*f%log10(m) ! ! "nsta crossmarker3"
205
206#--- la fonction de masse
207zone 2 2
208n/plot nt.mf%m ! ! "nsta crossmarker3"
209n/plot nt.mf%log10(m) f>0. ! "nsta crossmarker3"
210n/plot nt.log10(mf)%log10(m) mf>0. ! "nsta crossmarker3"
211
212# ce qu'on integre (en log10)
213n/plot nt.m*mf%log10(m) ! ! "nsta crossmarker3"
214
215#--- Check histos
216zone 2 1
217disp hdndm "red"
218n/plot nt.f%log10(m) ! ! "nsta crossmarker3 same"
219
220disp hmdndm "red"
221n/plot nt.m*f%log10(m) ! ! "nsta crossmarker3 same"
222
223#--- Check tirage aleatoire
224zone 2 1
225disp hdndm
226disp hdna "same red"
227
228disp hmdndm
229disp hmdna "same red"
230
231zone
232disp tirhdndm
233disp tirhmdndm "same red"
234
235 */
Note: See TracBrowser for help on using the repository browser.