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

Last change on this file since 3143 was 3120, checked in by cmv, 19 years ago

Suite de la mise dans la base cvs cmv 21/12/2006

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