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