1 | /* Distributions de masse pour n=1,2,3,... tirages */
|
---|
2 | #include "sopnamsp.h"
|
---|
3 | #include "machdefs.h"
|
---|
4 | #include <iostream>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <stdio.h>
|
---|
7 | #include <string.h>
|
---|
8 | #include <math.h>
|
---|
9 | #include <unistd.h>
|
---|
10 | #include "timing.h"
|
---|
11 | #include "histos.h"
|
---|
12 | #include "ntuple.h"
|
---|
13 | #include "srandgen.h"
|
---|
14 | #include "perandom.h"
|
---|
15 |
|
---|
16 | #include "geneutils.h"
|
---|
17 | #include "cosmocalc.h"
|
---|
18 | #include "schechter.h"
|
---|
19 |
|
---|
20 | #include <vector>
|
---|
21 |
|
---|
22 | void usage(void);
|
---|
23 | void usage(void)
|
---|
24 | {
|
---|
25 | cout<<"cmvschdist -m xmin,xmax -a -n nbin -r ngmax,ngmin -N nalea"<<endl
|
---|
26 | <<" xmin,xmax : limites en masse"<<endl
|
---|
27 | <<" nbin : nombre de bins"<<endl
|
---|
28 | <<" ngmax,ngmin : distribution pour tirage de ngmin a ngmax galaxies"<<endl
|
---|
29 | <<" nalea : nombre de tirages aleatoires"<<endl
|
---|
30 | <<" -a : init auto de l\'aleatoire"<<endl;
|
---|
31 | }
|
---|
32 |
|
---|
33 | int main(int narg,char *arg[])
|
---|
34 | {
|
---|
35 | double h75 = 0.71 / 0.75;
|
---|
36 | double nstar = 0.006*pow(h75,3.); //
|
---|
37 | double mstar = pow(10.,9.8/(h75*h75)); // MSol
|
---|
38 | double alpha = -1.37;
|
---|
39 | cout<<"h75= "<<h75<<" nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
|
---|
40 |
|
---|
41 | double xmin=1e8, xmax=1e13;
|
---|
42 | int npt = 100;
|
---|
43 | int ngmax = 200, ngmin = 1;
|
---|
44 | unsigned long long nalea = 10000;
|
---|
45 |
|
---|
46 | char c;
|
---|
47 | while((c = getopt(narg,arg,"ham:N:n:r:")) != -1) {
|
---|
48 | switch (c) {
|
---|
49 | case 'm' :
|
---|
50 | sscanf(optarg,"%lf,%lf",&xmin,&xmax);
|
---|
51 | if(xmin<=0.) xmin=1e6;
|
---|
52 | if(xmax<=0.) xmax=xmin;
|
---|
53 | if(xmin>xmax) xmax=10.*xmin;
|
---|
54 | break;
|
---|
55 | case 'r' :
|
---|
56 | sscanf(optarg,"%d,%d",&ngmax,&ngmin);
|
---|
57 | if(ngmin<=0) ngmin=1;
|
---|
58 | if(ngmax<=0) ngmax=ngmin;
|
---|
59 | if(ngmin>ngmax) ngmin=ngmax;
|
---|
60 | break;
|
---|
61 | case 'n' :
|
---|
62 | sscanf(optarg,"%d",&npt);
|
---|
63 | if(npt<=0) npt = 100;
|
---|
64 | break;
|
---|
65 | case 'N' :
|
---|
66 | sscanf(optarg,"%llu",&nalea);
|
---|
67 | if(nalea<=0) nalea=10000;
|
---|
68 | break;
|
---|
69 | case 'a' :
|
---|
70 | Auto_Ini_Ranf(5);
|
---|
71 | break;
|
---|
72 | case 'h' :
|
---|
73 | default :
|
---|
74 | usage(); return -1;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | double lnx1=log10(xmin), lnx2=log10(xmax), dlnx = (lnx2-lnx1)/npt;
|
---|
79 | cout<<"xmin="<<xmin<<" ("<<lnx1<<") xmax="<<xmax<<" ("<<lnx2<<"), dlnx="<<dlnx<<endl;
|
---|
80 | cout<<"npt="<<npt<<", nalea="<<nalea<<endl;
|
---|
81 | cout<<"ngmin="<<ngmin<<" ngmax="<<ngmax<<endl;
|
---|
82 |
|
---|
83 |
|
---|
84 | //-------m*dn/dm
|
---|
85 | cout<<"> Schechter m*dn/dm nstar="<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
|
---|
86 | Schechter sch(nstar,mstar,alpha);
|
---|
87 | sch.SetOutValue(1);
|
---|
88 | Histo hmdndm(lnx1,lnx2,npt); hmdndm.ReCenterBin();
|
---|
89 | FuncToHisto(sch,hmdndm,true);
|
---|
90 | FunRan tirhmdndm = FunRan(hmdndm,true);
|
---|
91 |
|
---|
92 | //------- Construct histo
|
---|
93 | int nbhist = ngmax-ngmin+1;
|
---|
94 | cout<<"> Creating "<<nbhist<<" histos"<<endl;
|
---|
95 | vector<Histo *> vhisto;
|
---|
96 | vector<string> vhname;
|
---|
97 | for(int i=ngmin;i<=ngmax;i++) {
|
---|
98 | Histo* h = new Histo(hmdndm); h->Zero();
|
---|
99 | vhisto.push_back(h);
|
---|
100 | char str[32]; sprintf(str,"h%d",i);
|
---|
101 | vhname.push_back(string(str));
|
---|
102 | }
|
---|
103 |
|
---|
104 | //------- Random
|
---|
105 | InitTim();
|
---|
106 | cout<<"> Random: "<<nalea<<" trials"<<endl;
|
---|
107 | int lpmod = nalea/25; if(lpmod<=0) lpmod=1;
|
---|
108 | for(unsigned long long ia=0;ia<nalea;ia++) {
|
---|
109 | if(ia%lpmod==0) cout<<"... "<<ia<<endl;
|
---|
110 | double sum = 0.;
|
---|
111 | for(int i=1;i<=ngmax;i++) {
|
---|
112 | //sum += tirhmdndm.Random();
|
---|
113 | sum += tirhmdndm.RandomInterp();
|
---|
114 | int ipo = i-ngmin;
|
---|
115 | if(ipo<0) continue;
|
---|
116 | vhisto[ipo]->Add(sum/(double)i);
|
---|
117 | }
|
---|
118 | if(ia%lpmod==0) PrtTim(" ");
|
---|
119 | }
|
---|
120 | PrtTim("End Random loop");
|
---|
121 |
|
---|
122 | //------- Ecriture ppf
|
---|
123 | cout<<"Ecriture"<<endl;
|
---|
124 | string tag = "cmvschdist.ppf";
|
---|
125 | POutPersist pos(tag);
|
---|
126 | tag = "hmdndm"; pos.PutObject(hmdndm,tag);
|
---|
127 | Histo hdum2(tirhmdndm);
|
---|
128 | tag = "tirhmdndm"; pos.PutObject(hdum2,tag);
|
---|
129 | for(unsigned int i=0;i<vhisto.size();i++)
|
---|
130 | if(vhisto[i]->NEntries()>0) pos.PutObject(*vhisto[i],vhname[i]);
|
---|
131 |
|
---|
132 | //------- des-allocation
|
---|
133 | for(unsigned int i=0;i<vhisto.size();i++) delete vhisto[i];
|
---|
134 |
|
---|
135 | return 0;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /*
|
---|
139 | delobjs *
|
---|
140 | openppf cmvschdist.ppf
|
---|
141 |
|
---|
142 | set h h100
|
---|
143 | disp $h
|
---|
144 | n/plot $h.val%x ! ! "connectpoints"
|
---|
145 | n/plot $h.log10(val)%x val>0. ! "connectpoints"
|
---|
146 |
|
---|
147 | echo ${h100.vmax}
|
---|
148 |
|
---|
149 | c++exec \
|
---|
150 | for(int i=0;i<$h.NBins();i++) \
|
---|
151 | if($h(i)>0.) { \
|
---|
152 | cout<<i<<" m="<<$h.BinCenter(i)<<" ("<<pow(10.,$h.BinCenter(i))<<") h="<<$h(i)<<endl; \
|
---|
153 | break; \
|
---|
154 | } \
|
---|
155 | for(int i=$h.NBins()-1;i>=0;i--) \
|
---|
156 | if($h(i)>0.) { \
|
---|
157 | cout<<i<<" m="<<$h.BinCenter(i)<<" ("<<pow(10.,$h.BinCenter(i))<<") h="<<$h(i)<<endl; \
|
---|
158 | break; \
|
---|
159 | }
|
---|
160 |
|
---|
161 | */
|
---|