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