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

Last change on this file since 3282 was 3249, checked in by cmv, 18 years ago

print cmv 16/05/2007

File size: 5.6 KB
RevLine 
[3115]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;
[3246]41 cout<<"h75= "<<h75<<" nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
[3115]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;
[3246]91 cout<<"sch(mstar) = "<<sch(mstar)<<" /Mpc^3/Msol"<<endl;
[3115]92 sch.SetOutValue(0);
[3249]93 for(double lnx=lnx1-5.;lnx<=lnx2-1.;lnx+=1.) {
94 double num = IntegrateFuncLog(sch,lnx,lnx2,perc,dlxinc,dlxmax,glorder);
95 cout<<"["<<lnx<<","<<lnx2<<"] integrated number = "<<num<<" Mpc^-3"<<endl;
[3115]96 }
97 Histo hdndm(lnx1,lnx2,npt); hdndm.ReCenterBin();
98 FuncToHisto(sch,hdndm,true);
99
100 //-------m*dn/dm
101 cout<<endl;
102 sch.SetOutValue(1);
103 cout<<"mstar*sch(mstar) = "<<sch(mstar)<<" Msol/Mpc^3/Msol"<<endl;
[3249]104 for(double lnx=lnx1-5.;lnx<=lnx2-1.;lnx+=1.) {
105 double sum = IntegrateFuncLog(sch,lnx,lnx2,perc,dlxinc,dlxmax,glorder);
106 cout<<"["<<lnx<<","<<lnx2<<"] integrated mass = "<<sum<<" Msol.Mpc^-3"<<endl;
[3115]107 }
108 Histo hmdndm(lnx1,lnx2,npt); hmdndm.ReCenterBin();
109 FuncToHisto(sch,hmdndm,true);
110
111 //------- Le flux HI pour M=mstar a 1 Gpc
112 cout<<endl;
113 double d = 1000.;
[3196]114 double f = Msol2FluxHI(mstar,d);
[3115]115 cout<<"FluxHI: d="<<d<<" Mpc:"<<" M= "<<mstar<<" Msol "
[3196]116 <<"-> Flux= "<<f<<" W/m^2"<<endl;
117 cout<<"Check... MassHI: d="<<d<<" Mpc:"<<" f= "<<f<<" W/m^2 "
118 <<"-> Mass= "<<FluxHI2Msol(f,d)<<" Msol"<<endl;
[3115]119
120 //------- Random
121 Histo hdna(hdndm); hdna.Zero();
122 Histo hmdna(hmdndm); hmdna.Zero();
123 FunRan tirhdndm = FunRan(hdndm,true);
124 FunRan tirhmdndm = FunRan(hmdndm,true);
125 if(nalea>0) {
126 double summ=0.;
127 PrtTim("--- avant tirage aleatoire");
128 for(int i=0;i<nalea;i++) {
129 double a = tirhdndm.RandomInterp();
130 hdna.Add(a);
131 a = tirhmdndm.RandomInterp();
132 summ += pow(10.,a);
133 hmdna.Add(a);
134 }
135 cout<<"Tirgae aleatoire: <m>="<<summ/(double)nalea<<endl;
136 hdna *= hdndm.Sum()/hdna.Sum();
137 hmdna *= hmdndm.Sum()/hmdna.Sum();
138 PrtTim("--- apres tirage aleatoire");
139 }
140
141 //-------
142 const int n = 3;
143 char *vname[n] = {"m","f","mf"};
144 NTuple nt(n,vname);
145 double xnt[n];
146 for(double lx=lnx1;lx<lnx2+dlnx/2.;lx+=dlnx) {
147 double x = pow(10.,lx);
148 xnt[0] = x;
149 sch.SetOutValue(0);
150 xnt[1] = sch(x);
151 sch.SetOutValue(1);
152 xnt[2] = sch(x);
153 nt.Fill(xnt);
154 }
155
156 cout<<"Ecriture"<<endl;
157 string tag = "cmvtstsch.ppf";
158 POutPersist pos(tag);
159 tag = "nt"; pos.PutObject(nt,tag);
160 tag = "hdndm"; pos.PutObject(hdndm,tag);
161 tag = "hmdndm"; pos.PutObject(hmdndm,tag);
162 tag = "hdna"; pos.PutObject(hdna,tag);
163 tag = "hmdna"; pos.PutObject(hmdna,tag);
164 Histo hdum1(tirhdndm);
165 tag = "tirhdndm"; pos.PutObject(hdum1,tag);
166 Histo hdum2(tirhmdndm);
167 tag = "tirhmdndm"; pos.PutObject(hdum2,tag);
168
169 return 0;
170}
171
172/*
173openppf cmvtstsch.ppf
174
175#--- la fonction de masse numerique
176zone 2 2
177n/plot nt.f%m ! ! "nsta crossmarker3"
178n/plot nt.f%log10(m) ! ! "nsta crossmarker3"
179n/plot nt.log10(f)%log10(m) f>0. ! "nsta crossmarker3"
180
181# ce qu'on integre (en log10)
182n/plot nt.m*f%log10(m) ! ! "nsta crossmarker3"
183
184#--- la fonction de masse
185zone 2 2
186n/plot nt.mf%m ! ! "nsta crossmarker3"
187n/plot nt.mf%log10(m) f>0. ! "nsta crossmarker3"
188n/plot nt.log10(mf)%log10(m) mf>0. ! "nsta crossmarker3"
189
190# ce qu'on integre (en log10)
191n/plot nt.m*mf%log10(m) ! ! "nsta crossmarker3"
192
193#--- Check histos
194zone 2 1
195disp hdndm "red"
196n/plot nt.f%log10(m) ! ! "nsta crossmarker3 same"
197
198disp hmdndm "red"
199n/plot nt.m*f%log10(m) ! ! "nsta crossmarker3 same"
200
201#--- Check tirage aleatoire
202zone 2 1
203disp hdndm
204disp hdna "same red"
205
206disp hmdndm
207disp hmdna "same red"
208
209zone
210disp tirhdndm
211disp tirhmdndm "same red"
212
213 */
Note: See TracBrowser for help on using the repository browser.