source: Sophya/trunk/Cosmo/SimLSS/cmvschdist.cc@ 3320

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

intro SchechterMassDist pour accelerer la simulations cmv 05/09/2007

File size: 6.8 KB
Line 
1/* Distributions de masse pour n=1,2,3,... tirages */
2#include "sopnamsp.h"
3#include "machdefs.h"
4// Pour faire les histogrammes des distributions de masses
5// pour ntirages:
6// ex: on a un pixel qui a N galaxies, quelle est la distribution
7// statistique de masse dans un tel pixel ?
8// > cmvschdist -a -v -m 1e+8,1e+13 -n -100 -r 200 -N 100000
9// compare with:
10// > cmvschdist -a -v -m 1e+8,1e+13 -n -100 -r 200 -N 100000 -0
11// Fabriquer un fichier
12// > cmvschdist -a -m 1e+8,1e+13 -n -100 -r 2000 -N 5000000 -W schdist_2000.ppf
13#include <iostream>
14#include <stdlib.h>
15#include <stdio.h>
16#include <string.h>
17#include <math.h>
18#include <unistd.h>
19#include "timing.h"
20#include "histos.h"
21#include "ntuple.h"
22#include "srandgen.h"
23#include "perandom.h"
24
25#include "geneutils.h"
26#include "cosmocalc.h"
27#include "schechter.h"
28
29#include <vector>
30
31void usage(void);
32void usage(void)
33{
34 cout<<"cmvschdist -m xmin,xmax -a -0 -n nbin -r ngmax,ngmin -N nalea "
35 <<"-R readfile.ppf -W writefile.ppf"<<endl
36 <<" -m xmin,xmax : limites en masse"<<endl
37 <<" -n nbin : nombre de bins (si <0 alors nb par decade)"<<endl
38 <<" -r ngmax,ngmin : distribution pour tirage de ngmin a ngmax galaxies"<<endl
39 <<" -N nalea : nombre de tirages aleatoires"<<endl
40 <<" -v : back verification of random trials"<<endl
41 <<" -0 : only use ngal=1 histogram"<<endl
42 <<" -a : init auto de l\'aleatoire"<<endl
43 <<" -R readfile.ppf : read SchechterMassDist from ppf file"<<endl;
44}
45
46int main(int narg,char *arg[])
47{
48 double h75 = 0.71 / 0.75;
49 double nstar = 0.006*pow(h75,3.); //
50 double mstar = pow(10.,9.8/(h75*h75)); // MSol
51 double alpha = -1.37;
52 cout<<"h75= "<<h75<<" nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
53
54 double xmin=1e8, xmax=1e13;
55 int npt = -100;
56 int ngmax = 200, ngmin = 1;
57 bool useonly1 = false;
58 unsigned long long nalea = 10000;
59 bool verif = false;
60 bool readfrppf = false;
61 string namefrppf = "";
62 string nametoppf = "";
63
64 char c;
65 while((c = getopt(narg,arg,"h0avm:N:n:r:R:W:")) != -1) {
66 switch (c) {
67 case 'm' :
68 sscanf(optarg,"%lf,%lf",&xmin,&xmax);
69 if(xmin<=0.) xmin=1e6;
70 if(xmax<=0.) xmax=xmin;
71 if(xmin>xmax) xmax=10.*xmin;
72 break;
73 case 'r' :
74 sscanf(optarg,"%d,%d",&ngmax,&ngmin);
75 if(ngmin<=0) ngmin=1;
76 if(ngmax<=0) ngmax=ngmin;
77 if(ngmin>ngmax) ngmin=ngmax;
78 break;
79 case 'n' :
80 sscanf(optarg,"%d",&npt);
81 if(npt<=0) npt = -100;
82 break;
83 case 'N' :
84 sscanf(optarg,"%llu",&nalea);
85 if(nalea<=0) nalea=10000;
86 break;
87 case 'v' :
88 verif = true;
89 break;
90 case '0' :
91 useonly1 = true;
92 break;
93 case 'R' :
94 readfrppf = true;
95 namefrppf = optarg;
96 break;
97 case 'W' :
98 nametoppf = optarg;
99 break;
100 case 'a' :
101 Auto_Ini_Ranf(5);
102 break;
103 case 'h' :
104 default :
105 usage(); return -1;
106 }
107 }
108
109 double lnx1=log10(xmin), lnx2=log10(xmax);
110 cout<<"xmin="<<xmin<<" ("<<lnx1<<") xmax="<<xmax<<" ("<<lnx2<<")"<<endl;
111 cout<<"npt="<<npt<<", nalea="<<nalea<<endl;
112 cout<<"useonly1="<<useonly1<<" ngmin="<<ngmin<<" ngmax="<<ngmax<<endl;
113 cout<<"verif="<<verif<<endl;
114 if(readfrppf) cout<<"SchechterMassDist will be read from file "<<namefrppf<<endl;
115 if(nametoppf.size()>0) cout<<"SchechterMassDist will be written to file "<<nametoppf<<endl;
116
117
118 //-------m*dn/dm
119 cout<<"> Schechter m*dn/dm nstar="<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
120 Schechter sch(nstar,mstar,alpha);
121
122 //------- Construct Mass Distribution
123 cout<<"> Creating Mass Distribution"<<endl;
124 SchechterMassDist schdmass(sch,xmin,xmax,npt);
125 if(readfrppf) {
126 cout<<"> Mass Distribution read from "<<namefrppf<<endl;
127 schdmass.ReadPPF(namefrppf);
128 }
129 Histo hmdndm = schdmass.GetHmDnDm();
130 FunRan tirhmdndm = schdmass.GetTmDnDm();
131
132 //------- Random
133 InitTim();
134 if(!useonly1 && !readfrppf) {
135 cout<<"> Creating "<<ngmax-ngmin+1<<" histos and filling with "<<nalea<<" trials"<<endl;
136 schdmass.SetNgalLim(ngmax,ngmin,nalea);
137 PrtTim("End of filling histos for trials");
138 }
139 schdmass.Print();
140
141 //------- Generation des histos de verif
142 vector<Histo> vthisto; vector<string> vthname;
143 if(verif) {
144 cout<<"> Creating "<<ngmax-ngmin+1<<" Histos for back-verif"<<endl;
145 for(int i=ngmin;i<=ngmax;i++) {
146 Histo h(hmdndm); h.Zero();
147 vthisto.push_back(h);
148 char str[32]; sprintf(str,"th%d",i);
149 vthname.push_back(string(str));
150 }
151 cout<<" "<<vthisto.size()<<" Histos created"<<endl;
152 vthisto[20].Show();
153
154 cout<<"> Checking tirage"<<endl;
155 int lpmod = nalea/20; if(lpmod<=0) lpmod=1;
156 for(unsigned long long ia=0;ia<nalea;ia++) {
157 if(ia%lpmod==0) cout<<"...filling tirage "<<ia<<endl;
158 for(unsigned int i=0;i<vthisto.size();i++) {
159 int ng = ngmin+i;
160 double v = schdmass.TirMass(ng)/(double)ng;
161 vthisto[i].Add(log10(v));
162 }
163 }
164 schdmass.PrintStatus();
165 PrtTim("End Random loop back-tirage");
166 }
167
168 //------- Ecritures ppf
169 if(nametoppf.size()>0) {
170 cout<<"Ecriture de l\'objet SchechterMassDist dans "<<nametoppf<<endl;
171 schdmass.WritePPF(nametoppf);
172 }
173
174 cout<<"Ecriture pour verification"<<endl;
175 string tag = "cmvschdist.ppf";
176 POutPersist pos(tag);
177 {
178 cout<<" writing hmdndm tirhmdndm"<<endl;
179 tag = "hmdndm"; pos.PutObject(hmdndm,tag);
180 Histo hdum(tirhmdndm);
181 tag = "tirhmdndm"; pos.PutObject(hdum,tag);
182 }
183 if(schdmass.GetNgalLim()>0) {
184 cout<<" writing h t"<<endl;
185 for(int i=0;i<schdmass.GetNgalLim();i++) {
186 int ng = schdmass.NGalFrIndex(i);
187 if(ng<=0) continue;
188 char str[32];
189 sprintf(str,"h%d",ng);
190 Histo hdum = schdmass.GetHisto(i);
191 tag = str; pos.PutObject(hdum,tag);
192 sprintf(str,"t%d",ng);
193 Histo hdum2(schdmass.GetFunRan(i));
194 tag = str; pos.PutObject(hdum2,tag);
195 }
196 }
197 if(vthisto.size()>0) {
198 cout<<" writing th"<<endl;
199 for(unsigned int i=0;i<vthisto.size();i++)
200 if(vthisto[i].NEntries()>0) pos.PutObject(vthisto[i],vthname[i]);
201 }
202
203 PrtTim("End of Job");
204
205 return 0;
206}
207
208/*
209delobjs *
210openppf cmvschdist.ppf
211
212set n 70
213echo ${h70.vmax}
214
215set h h$n
216set t t$n
217set th th$n
218
219disp tirhmdndm
220disp $t "same red"
221
222disp $h
223disp $th "same red"
224
225n/plot $h.val%x ! ! "connectpoints"
226n/plot $th.val%x ! ! "nsta connectpoints same red"
227
228n/plot $h.log10(val)%x val>0. ! "connectpoints"
229n/plot $th.log10(val)%x val>0. ! "nsta connectpoints same red"
230
231n/plot $h.val%pow(10.,x) ! ! "connectpoints"
232n/plot $th.val%pow(10.,x) ! ! "nsta connectpoints same red"
233
234c++exec \
235for(int i=0;i<$h.NBins();i++) \
236 if($h(i)>0.) { \
237 cout<<i<<" m="<<$h.BinCenter(i)<<" ("<<pow(10.,$h.BinCenter(i))<<") h="<<$h(i)<<endl; \
238 break; \
239} \
240for(int i=$h.NBins()-1;i>=0;i--) \
241 if($h(i)>0.) { \
242 cout<<i<<" m="<<$h.BinCenter(i)<<" ("<<pow(10.,$h.BinCenter(i))<<") h="<<$h(i)<<endl; \
243 break; \
244}
245
246# Compare evolution
247disp h200
248disp h100 "same red"
249disp h50 "same blue"
250disp h10 "same green"
251disp h1 "same yellow"
252*/
Note: See TracBrowser for help on using the repository browser.