[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>
|
---|
[3615] | 9 | #include "sophyainit.h"
|
---|
[3115] | 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 | void usage(void);
|
---|
| 21 | void 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 |
|
---|
| 36 | int main(int narg,char *arg[])
|
---|
| 37 | {
|
---|
[3615] | 38 | SophyaInit();
|
---|
[3115] | 39 | double h75 = 0.71 / 0.75;
|
---|
| 40 | double nstar = 0.006*pow(h75,3.); //
|
---|
[3343] | 41 | double mstar = pow(10.,9.8); // MSol
|
---|
[3115] | 42 | double alpha = -1.37;
|
---|
[3246] | 43 | cout<<"h75= "<<h75<<" nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
|
---|
[3115] | 44 |
|
---|
| 45 | double xmin=1e6, xmax=1e12;
|
---|
| 46 | double perc=0.01,dlxinc=-1000.,dlxmax=0.; unsigned short glorder=4;
|
---|
| 47 | int npt = 1000;
|
---|
| 48 | int nalea = 100000;
|
---|
| 49 |
|
---|
| 50 | char c;
|
---|
| 51 | while((c = getopt(narg,arg,"ham:i:n:N:")) != -1) {
|
---|
| 52 | switch (c) {
|
---|
| 53 | case 'm' :
|
---|
| 54 | sscanf(optarg,"%lf,%lf",&xmin,&xmax);
|
---|
| 55 | break;
|
---|
| 56 | case 'i' :
|
---|
| 57 | int ig;
|
---|
| 58 | sscanf(optarg,"%lf,%lf,%lf,%u",&perc,&dlxinc,&dlxmax,&ig);
|
---|
| 59 | if(perc<=0.) perc = 0.01;
|
---|
| 60 | glorder = (ig<=0) ? 4: ig;
|
---|
| 61 | break;
|
---|
| 62 | case 'n' :
|
---|
| 63 | sscanf(optarg,"%d",&npt);
|
---|
| 64 | if(npt<=0) npt = 1000;
|
---|
| 65 | break;
|
---|
| 66 | case 'N' :
|
---|
| 67 | sscanf(optarg,"%d",&nalea);
|
---|
| 68 | break;
|
---|
| 69 | case 'a' :
|
---|
[3615] | 70 | AutoInitRand(5);
|
---|
[3115] | 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 |
|
---|
| 81 | if(dlxinc<0.) dlxinc=(lnx2-lnx1)/(-dlxinc);
|
---|
| 82 | if(dlxmax<0.) dlxmax *= -dlxinc; else if(dlxmax==0.) dlxmax=-1.;
|
---|
| 83 | cout<<"perc="<<perc<<" dlxinc="<<dlxinc<<" dlxmax="<<dlxmax<<" glorder="<<glorder<<endl;
|
---|
| 84 |
|
---|
| 85 | cout<<"npt="<<npt<<", nalea="<<nalea<<endl;
|
---|
| 86 |
|
---|
| 87 | Schechter sch(nstar,mstar,alpha);
|
---|
| 88 |
|
---|
| 89 | InitTim();
|
---|
| 90 |
|
---|
| 91 | //-------dn/dm
|
---|
| 92 | cout<<endl;
|
---|
[3246] | 93 | cout<<"sch(mstar) = "<<sch(mstar)<<" /Mpc^3/Msol"<<endl;
|
---|
[3115] | 94 | sch.SetOutValue(0);
|
---|
[3284] | 95 | cout<<"......"<<endl;
|
---|
| 96 | for(double lnx=lnx1-3.;lnx<=lnx2-1.;lnx+=1.) {
|
---|
[3320] | 97 | double num = sch.Integrate(pow(10.,lnx),pow(10.,lnx2),npt);
|
---|
| 98 | double numc = IntegrateFuncLog(sch,lnx,lnx2,perc,dlxinc,dlxmax,glorder);
|
---|
| 99 | cout<<"["<<lnx<<","<<lnx2<<"] integrated number = "<<num<<" Mpc^-3 , check: "<<numc<<endl;
|
---|
[3115] | 100 | }
|
---|
[3284] | 101 | cout<<"......"<<endl;
|
---|
| 102 | for(double lnx=lnx1+1.;lnx<=lnx2+3.;lnx+=1.) {
|
---|
[3320] | 103 | double num = sch.Integrate(pow(10.,lnx1),pow(10.,lnx),npt);
|
---|
| 104 | double numc = IntegrateFuncLog(sch,lnx1,lnx,perc,dlxinc,dlxmax,glorder);
|
---|
| 105 | cout<<"["<<lnx1<<","<<lnx<<"] integrated number = "<<num<<" Mpc^-3 , check: "<<numc<<endl;
|
---|
[3284] | 106 | }
|
---|
| 107 | cout<<"......"<<endl;
|
---|
| 108 | for(double lnx=lnx1-3.;lnx<=lnx2+3.;lnx+=1.) {
|
---|
[3320] | 109 | double num = sch.Integrate(pow(10.,lnx),pow(10.,lnx+1.),npt);
|
---|
| 110 | double numc = IntegrateFuncLog(sch,lnx,lnx+1.,perc,dlxinc,dlxmax,glorder);
|
---|
| 111 | cout<<"["<<lnx<<","<<lnx+1.<<"] integrated number = "<<num<<" Mpc^-3 , check: "<<numc<<endl;
|
---|
[3284] | 112 | }
|
---|
[3115] | 113 | Histo hdndm(lnx1,lnx2,npt); hdndm.ReCenterBin();
|
---|
| 114 | FuncToHisto(sch,hdndm,true);
|
---|
| 115 |
|
---|
| 116 | //-------m*dn/dm
|
---|
| 117 | cout<<endl;
|
---|
| 118 | sch.SetOutValue(1);
|
---|
| 119 | cout<<"mstar*sch(mstar) = "<<sch(mstar)<<" Msol/Mpc^3/Msol"<<endl;
|
---|
[3284] | 120 | cout<<"......"<<endl;
|
---|
| 121 | for(double lnx=lnx1-3.;lnx<=lnx2-1.;lnx+=1.) {
|
---|
[3320] | 122 | double sum = sch.Integrate(pow(10.,lnx),pow(10.,lnx2),npt);
|
---|
| 123 | double sumc = IntegrateFuncLog(sch,lnx,lnx2,perc,dlxinc,dlxmax,glorder);
|
---|
| 124 | cout<<"["<<lnx<<","<<lnx2<<"] integrated mass = "<<sum<<" Msol.Mpc^-3 , check: "<<sumc<<endl;
|
---|
[3115] | 125 | }
|
---|
[3284] | 126 | cout<<"......"<<endl;
|
---|
| 127 | for(double lnx=lnx1+1.;lnx<=lnx2+3.;lnx+=1.) {
|
---|
[3320] | 128 | double sum = sch.Integrate(pow(10.,lnx1),pow(10.,lnx),npt);
|
---|
| 129 | double sumc = IntegrateFuncLog(sch,lnx1,lnx,perc,dlxinc,dlxmax,glorder);
|
---|
| 130 | cout<<"["<<lnx1<<","<<lnx<<"] integrated mass = "<<sum<<" Msol.Mpc^-3 , check: "<<sumc<<endl;
|
---|
[3284] | 131 | }
|
---|
| 132 | cout<<"......"<<endl;
|
---|
| 133 | for(double lnx=lnx1-3.;lnx<=lnx2+3.;lnx+=1.) {
|
---|
[3320] | 134 | double sum = sch.Integrate(pow(10.,lnx),pow(10.,lnx+1.),npt);
|
---|
| 135 | double sumc = IntegrateFuncLog(sch,lnx,lnx+1.,perc,dlxinc,dlxmax,glorder);
|
---|
| 136 | cout<<"["<<lnx<<","<<lnx+1.<<"] integrated mass = "<<sum<<" Msol.Mpc^-3 , check: "<<sumc<<endl;
|
---|
[3284] | 137 | }
|
---|
[3115] | 138 | Histo hmdndm(lnx1,lnx2,npt); hmdndm.ReCenterBin();
|
---|
| 139 | FuncToHisto(sch,hmdndm,true);
|
---|
| 140 |
|
---|
| 141 | //------- Le flux HI pour M=mstar a 1 Gpc
|
---|
| 142 | cout<<endl;
|
---|
| 143 | double d = 1000.;
|
---|
[3196] | 144 | double f = Msol2FluxHI(mstar,d);
|
---|
[3115] | 145 | cout<<"FluxHI: d="<<d<<" Mpc:"<<" M= "<<mstar<<" Msol "
|
---|
[3196] | 146 | <<"-> Flux= "<<f<<" W/m^2"<<endl;
|
---|
| 147 | cout<<"Check... MassHI: d="<<d<<" Mpc:"<<" f= "<<f<<" W/m^2 "
|
---|
| 148 | <<"-> Mass= "<<FluxHI2Msol(f,d)<<" Msol"<<endl;
|
---|
[3115] | 149 |
|
---|
| 150 | //------- Random
|
---|
| 151 | Histo hdna(hdndm); hdna.Zero();
|
---|
| 152 | Histo hmdna(hmdndm); hmdna.Zero();
|
---|
| 153 | FunRan tirhdndm = FunRan(hdndm,true);
|
---|
| 154 | FunRan tirhmdndm = FunRan(hmdndm,true);
|
---|
| 155 | if(nalea>0) {
|
---|
| 156 | double summ=0.;
|
---|
| 157 | PrtTim("--- avant tirage aleatoire");
|
---|
| 158 | for(int i=0;i<nalea;i++) {
|
---|
| 159 | double a = tirhdndm.RandomInterp();
|
---|
| 160 | hdna.Add(a);
|
---|
| 161 | a = tirhmdndm.RandomInterp();
|
---|
| 162 | summ += pow(10.,a);
|
---|
| 163 | hmdna.Add(a);
|
---|
| 164 | }
|
---|
| 165 | cout<<"Tirgae aleatoire: <m>="<<summ/(double)nalea<<endl;
|
---|
| 166 | hdna *= hdndm.Sum()/hdna.Sum();
|
---|
| 167 | hmdna *= hmdndm.Sum()/hmdna.Sum();
|
---|
| 168 | PrtTim("--- apres tirage aleatoire");
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | //-------
|
---|
| 172 | const int n = 3;
|
---|
[3572] | 173 | const char *vname[n] = {"m","f","mf"};
|
---|
[3115] | 174 | NTuple nt(n,vname);
|
---|
| 175 | double xnt[n];
|
---|
| 176 | for(double lx=lnx1;lx<lnx2+dlnx/2.;lx+=dlnx) {
|
---|
| 177 | double x = pow(10.,lx);
|
---|
| 178 | xnt[0] = x;
|
---|
| 179 | sch.SetOutValue(0);
|
---|
| 180 | xnt[1] = sch(x);
|
---|
| 181 | sch.SetOutValue(1);
|
---|
| 182 | xnt[2] = sch(x);
|
---|
| 183 | nt.Fill(xnt);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | cout<<"Ecriture"<<endl;
|
---|
| 187 | string tag = "cmvtstsch.ppf";
|
---|
| 188 | POutPersist pos(tag);
|
---|
| 189 | tag = "nt"; pos.PutObject(nt,tag);
|
---|
| 190 | tag = "hdndm"; pos.PutObject(hdndm,tag);
|
---|
| 191 | tag = "hmdndm"; pos.PutObject(hmdndm,tag);
|
---|
| 192 | tag = "hdna"; pos.PutObject(hdna,tag);
|
---|
| 193 | tag = "hmdna"; pos.PutObject(hmdna,tag);
|
---|
| 194 | Histo hdum1(tirhdndm);
|
---|
| 195 | tag = "tirhdndm"; pos.PutObject(hdum1,tag);
|
---|
| 196 | Histo hdum2(tirhmdndm);
|
---|
| 197 | tag = "tirhmdndm"; pos.PutObject(hdum2,tag);
|
---|
| 198 |
|
---|
| 199 | return 0;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | /*
|
---|
| 203 | openppf cmvtstsch.ppf
|
---|
| 204 |
|
---|
| 205 | #--- la fonction de masse numerique
|
---|
| 206 | zone 2 2
|
---|
| 207 | n/plot nt.f%m ! ! "nsta crossmarker3"
|
---|
| 208 | n/plot nt.f%log10(m) ! ! "nsta crossmarker3"
|
---|
| 209 | n/plot nt.log10(f)%log10(m) f>0. ! "nsta crossmarker3"
|
---|
| 210 |
|
---|
| 211 | # ce qu'on integre (en log10)
|
---|
| 212 | n/plot nt.m*f%log10(m) ! ! "nsta crossmarker3"
|
---|
| 213 |
|
---|
| 214 | #--- la fonction de masse
|
---|
| 215 | zone 2 2
|
---|
| 216 | n/plot nt.mf%m ! ! "nsta crossmarker3"
|
---|
| 217 | n/plot nt.mf%log10(m) f>0. ! "nsta crossmarker3"
|
---|
| 218 | n/plot nt.log10(mf)%log10(m) mf>0. ! "nsta crossmarker3"
|
---|
| 219 |
|
---|
| 220 | # ce qu'on integre (en log10)
|
---|
| 221 | n/plot nt.m*mf%log10(m) ! ! "nsta crossmarker3"
|
---|
| 222 |
|
---|
| 223 | #--- Check histos
|
---|
| 224 | zone 2 1
|
---|
| 225 | disp hdndm "red"
|
---|
| 226 | n/plot nt.f%log10(m) ! ! "nsta crossmarker3 same"
|
---|
| 227 |
|
---|
| 228 | disp hmdndm "red"
|
---|
| 229 | n/plot nt.m*f%log10(m) ! ! "nsta crossmarker3 same"
|
---|
| 230 |
|
---|
| 231 | #--- Check tirage aleatoire
|
---|
| 232 | zone 2 1
|
---|
| 233 | disp hdndm
|
---|
| 234 | disp hdna "same red"
|
---|
| 235 |
|
---|
| 236 | disp hmdndm
|
---|
| 237 | disp hmdna "same red"
|
---|
| 238 |
|
---|
| 239 | zone
|
---|
| 240 | disp tirhdndm
|
---|
| 241 | disp tirhmdndm "same red"
|
---|
| 242 |
|
---|
| 243 | */
|
---|