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

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

set schechter mmin=1e8 -> 1e7 cmv 09/10/2007

File size: 6.8 KB
RevLine 
[3284]1/* Distributions de masse pour n=1,2,3,... tirages */
2#include "sopnamsp.h"
3#include "machdefs.h"
[3319]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 ?
[3344]8// > cmvschdist -a -v -m 1e+7,1e+13 -n -100 -r 200 -N 100000
[3320]9// compare with:
[3344]10// > cmvschdist -a -v -m 1e+7,1e+13 -n -100 -r 200 -N 100000 -0
[3322]11// Fabriquer un fichier pour la prod
[3344]12// > cmvschdist -a -m 1e+7,1e+13 -n -100 -r 2000 -N 5000000 -W schdist_2000.ppf
[3284]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{
[3320]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
[3319]40 <<" -v : back verification of random trials"<<endl
[3320]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;
[3284]44}
45
46int main(int narg,char *arg[])
47{
48 double h75 = 0.71 / 0.75;
49 double nstar = 0.006*pow(h75,3.); //
[3343]50 double mstar = pow(10.,9.8); // MSol
[3284]51 double alpha = -1.37;
52 cout<<"h75= "<<h75<<" nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
53
[3344]54 double xmin=1.e7, xmax=1.e13;
[3320]55 int npt = -100;
[3284]56 int ngmax = 200, ngmin = 1;
[3320]57 bool useonly1 = false;
[3284]58 unsigned long long nalea = 10000;
[3319]59 bool verif = false;
[3320]60 bool readfrppf = false;
61 string namefrppf = "";
62 string nametoppf = "";
[3284]63
64 char c;
[3320]65 while((c = getopt(narg,arg,"h0avm:N:n:r:R:W:")) != -1) {
[3284]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);
[3320]81 if(npt<=0) npt = -100;
[3284]82 break;
83 case 'N' :
84 sscanf(optarg,"%llu",&nalea);
85 if(nalea<=0) nalea=10000;
86 break;
[3319]87 case 'v' :
88 verif = true;
89 break;
[3320]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;
[3284]100 case 'a' :
101 Auto_Ini_Ranf(5);
102 break;
103 case 'h' :
104 default :
105 usage(); return -1;
106 }
107 }
108
[3320]109 double lnx1=log10(xmin), lnx2=log10(xmax);
110 cout<<"xmin="<<xmin<<" ("<<lnx1<<") xmax="<<xmax<<" ("<<lnx2<<")"<<endl;
[3284]111 cout<<"npt="<<npt<<", nalea="<<nalea<<endl;
[3320]112 cout<<"useonly1="<<useonly1<<" ngmin="<<ngmin<<" ngmax="<<ngmax<<endl;
[3319]113 cout<<"verif="<<verif<<endl;
[3320]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;
[3284]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
[3320]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);
[3284]128 }
[3320]129 Histo hmdndm = schdmass.GetHmDnDm();
130 FunRan tirhmdndm = schdmass.GetTmDnDm();
[3284]131
132 //------- Random
133 InitTim();
[3320]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");
[3284]138 }
[3320]139 schdmass.Print();
[3284]140
[3320]141 //------- Generation des histos de verif
142 vector<Histo> vthisto; vector<string> vthname;
[3319]143 if(verif) {
[3320]144 cout<<"> Creating "<<ngmax-ngmin+1<<" Histos for back-verif"<<endl;
[3319]145 for(int i=ngmin;i<=ngmax;i++) {
[3320]146 Histo h(hmdndm); h.Zero();
[3319]147 vthisto.push_back(h);
[3320]148 char str[32]; sprintf(str,"th%d",i);
[3319]149 vthname.push_back(string(str));
150 }
[3320]151 cout<<" "<<vthisto.size()<<" Histos created"<<endl;
152 vthisto[20].Show();
[3319]153
154 cout<<"> Checking tirage"<<endl;
[3320]155 int lpmod = nalea/20; if(lpmod<=0) lpmod=1;
[3319]156 for(unsigned long long ia=0;ia<nalea;ia++) {
[3320]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));
[3319]162 }
163 }
[3320]164 schdmass.PrintStatus();
[3319]165 PrtTim("End Random loop back-tirage");
166 }
167
[3320]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;
[3284]175 string tag = "cmvschdist.ppf";
176 POutPersist pos(tag);
[3320]177 {
178 cout<<" writing hmdndm tirhmdndm"<<endl;
[3284]179 tag = "hmdndm"; pos.PutObject(hmdndm,tag);
[3320]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++)
[3319]200 if(vthisto[i].NEntries()>0) pos.PutObject(vthisto[i],vthname[i]);
[3320]201 }
[3284]202
[3320]203 PrtTim("End of Job");
204
[3284]205 return 0;
206}
207
208/*
209delobjs *
210openppf cmvschdist.ppf
211
[3319]212set n 70
213echo ${h70.vmax}
214
215set h h$n
[3320]216set t t$n
[3319]217set th th$n
218
[3320]219disp tirhmdndm
220disp $t "same red"
221
[3284]222disp $h
[3319]223disp $th "same red"
224
[3284]225n/plot $h.val%x ! ! "connectpoints"
[3319]226n/plot $th.val%x ! ! "nsta connectpoints same red"
227
[3284]228n/plot $h.log10(val)%x val>0. ! "connectpoints"
[3319]229n/plot $th.log10(val)%x val>0. ! "nsta connectpoints same red"
[3284]230
[3320]231n/plot $h.val%pow(10.,x) ! ! "connectpoints"
232n/plot $th.val%pow(10.,x) ! ! "nsta connectpoints same red"
233
[3284]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
[3319]246# Compare evolution
[3322]247disp h2000
248disp h1000 "same red"
249disp h500 "same blue"
250disp h200 "same green"
[3319]251disp h100 "same red"
252disp h50 "same blue"
253disp h10 "same green"
254disp h1 "same yellow"
[3284]255*/
Note: See TracBrowser for help on using the repository browser.