int main(int argc, char **argv) { double s1, delta_vir, omega_m, x; int i, j; FILE *fp; #ifdef PARALLEL printf("STARTING>>>\n"); fflush(stdout); MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask); MPI_Comm_size(MPI_COMM_WORLD, &NTask); printf("TASK %d reporting for duty.\n",ThisTask); fflush(stdout); #endif ARGC = argc; ARGV = argv; OUTPUT=0; HOD.fredc = HOD.freds = 1.0; for(i=1; i<=99; ++i) HOD.free[i]=0; wp.esys=0; Work.chi2=0; Work.imodel=1; USE_ERRORS = 0; ITRANS=4; HUBBLE=0.7; BEST_FIT = 0; HOD.M_sat_break = 1.0e14; HOD.alpha1 = 1.0; if(argc==1) endrun("./HOD.x hod.bat_file > output"); read_parameter_file(argv[1]); if(REDSHIFT>0) { SIGMA_8 = SIGMA_8*growthfactor(REDSHIFT); HUBBLEZ = sqrt(OMEGA_M*pow(1+REDSHIFT,3.0)+1-OMEGA_M); OMEGA_Z = OMEGA_M*pow(1+REDSHIFT,3.0)/(OMEGA_M*pow(1+REDSHIFT,3.0)+(1-OMEGA_M)); fprintf(stdout,"SIGMA_8(Z=%.3f)= %.4f\n",REDSHIFT,SIGMA_8); fprintf(stdout,"H(Z=%.3f)/H0= %.4f\n",REDSHIFT,HUBBLEZ); HOD.M_min = 0; RESET_COSMOLOGY++; set_HOD_params(); } /* Output the virial overdensity for reference. */ if(OUTPUT) { omega_m=OMEGA_M*pow(1+REDSHIFT,3.0)/(OMEGA_M*pow(1+REDSHIFT,3.0)+(1-OMEGA_M)); x=omega_m-1; delta_vir=(18*PI*PI+82*x-39*x*x)/(1+x); printf("DELTA_VIR(Omega_m,z) = %f\n",delta_vir); } /* Do some initialization if we're doing SHMR */ if(SHMR_FLAG) { if(SATELLITE_PARAMETERIZATION)SHMR_PARAMS = 14; if(VARIABLE_ALPHA)SHMR_PARAMS += 2; if(VARIABLE_EXCLUSION)wpl.a[SHMR_PARAMS+1] = EXCLUSION_RADIUS; wpl.ncf = SHMR_PARAMS + VARIABLE_EXCLUSION; HOD.pdfs = 100; HOD.pdfc = 101; wpx.calculate_two_halo = 1; input_stellar_mass_bins(); // if we have input from the prompt, take that if(argc>2 && atoi(argv[2])!=999) { fp = openfile(argv[2]); fscanf(fp,"%d %d",&i,&j); for(i=1; i<=wpl.ncf; ++i) fscanf(fp,"%lf",&wpl.a[i]); fclose(fp); } } for(i=1; i<=wpl.ncf; ++i) printf("wpl.a[%d]= %e\n",i,wpl.a[i]); /* LENSING TESTING FOR ALEXIE */ if(argc>2) IDUM_MCMC=atoi(argv[2]); SIGMA_8Z0 = 0.8; if(argc>2) if(atoi(argv[2])==999) test(argc,argv); /* If there's no cross-correlation function, * set the second number density equal to the first */ if(!XCORR) GALAXY_DENSITY2 = GALAXY_DENSITY; /* Initialize the non-linear power spectrum. */ nonlinear_sigmac(8.0); sigmac_interp(1.0E13); sigmac_radius_interp(1.0); /* Skip the HOD stuff if we're SHMR-ing it: */ if(SHMR_FLAG) { if(argc>2 && atoi(argv[2])==999)test(argc, argv); if(argc>3 && atoi(argv[3])==999)test(argc, argv); goto TASKS; } /* Get the galaxy bias factor */ s1=qromo(func_galaxy_bias,log(HOD.M_low),log(HOD.M_max),midpnt); GALAXY_BIAS=s1/GALAXY_DENSITY; if(OUTPUT) fprintf(stdout,"Galaxy Bias bg= %f\n",GALAXY_BIAS); fflush(stdout); /* Get the galaxy satellite fraction */ s1=qromo(func_satellite_density,log(HOD.M_low),log(HOD.M_max),midpnt)/ GALAXY_DENSITY; if(OUTPUT) fprintf(stdout,"fsat %e\n",s1); fflush(stdout); /* Mean halo mass. */ if(OUTPUT) fprintf(stdout,"M_eff %e\n",number_weighted_halo_mass()); fflush(stdout); /* Set up BETA for wp integration. */ BETA = pow(OMEGA_M,0.6)/GALAXY_BIAS; if(OUTPUT) printf("BETA = %f\n",BETA); TASKS: tasks(argc,argv); }
void populate_simulation() { FILE *fp,*fpa[9],*fp2,*fp3,*fpb[9],*fpc[9],*fps[9],*fpt,*fpblue, *fpsub,*fp2r,*fp3r; int i,j,k,n,imass,n1,j_start=0,i1,galcnt[1000],halocnt[1000]; double mass,xg[3],vg[3],nsat,nc[10],ncen,mlo,mag,err1,err2,r,fac,sigv; char aa[1000]; float x1,xh[3],vh[3],vgf[3]; long IDUM3 = -445; float **galarr; int *galid,id1=0,id2=0,j1,*ibluecen,nhalo; float dx,dy,dz,dr,drh,rv1,rv2,rmin,rmax, fred,p; float **haloarr; int ngal,nsati[9],ALL_FILES=0,TRACK_GALAXIES=0,WARREN_MASS_CORRECTION=0,haloid; float *xt,*yt,*zt,*vxt,*vyt,*vzt; //static int nhalo, *used_halo, iuse_flag = 1; int ihalo=0, ii; int SO_FILE = 0, JEANS_DISPERSION = 0; // new for mcmc_lensing; double m1, m2, mfslope, rad, mstar, rproj, xs[20], vhalo, imag, minimum_halo_mass, minimum_mstar, minimum_lgmstar; long IDUM=-555; float xx[20], xd[3], xv[3], *subi, *submass, *temp; fprintf(stderr,"\n\nPOPULATING SIMULATION WITH SHMR.\n"); fprintf(stderr, "--------------------------------\n\n"); fp=openfile(Files.HaloFile); fprintf(stderr,"opening file: [%s]\n",Files.HaloFile); nhalo = filesize(fp); fprintf(stderr,"number of lines: [%d]\n",nhalo); ibluecen = ivector(1,nhalo); if(Files.UseStellarMassBinsClustering) input_stellar_mass_bins(); minimum_mstar = pow(10.0,wpl.mstar_wplo[0][1]); minimum_lgmstar = wpl.mstar_wplo[0][1]; fmuh(minimum_lgmstar); if(!COLOR) { sprintf(aa,"%s.shmr_mock",Task.root_filename); fp2 = fopen(aa,"w"); fprintf(stderr,"outfile: [%s]\n",aa); sprintf(aa,"%s.shmr_mock_haloid",Task.root_filename); fp3 = fopen(aa,"w"); } else { sprintf(aa,"%s.shmr_mock_blue",Task.root_filename); fp2 = fopen(aa,"w"); fprintf(stderr,"outfile: [%s]\n",aa); sprintf(aa,"%s.shmr_mock_haloid_blue",Task.root_filename); fp3 = fopen(aa,"w"); } BLUE_FLAG = 1; wpl.reset_inversion = 1; set_up_hod_for_shmr(minimum_mstar,5.0E12,wpl.a); minimum_halo_mass = HOD.M_low; generate_satellite_galaxy_tab(1.0E12,minimum_lgmstar,1); fprintf(stderr,"Expected number density of galaxies N(>%.2f Msol)= %e\n",log10(minimum_mstar),GALAXY_DENSITY); fprintf(stderr,"Minimum halo mass (M_low) required= %e\n",minimum_halo_mass); haloid = 0; for(ii=1;ii<=nhalo;++ii) { ibluecen[ii] = 0; fscanf(fp,"%d %lf %f %f %f %f %f %f %f %f", &i,&mass,&x1,&x1,&xh[0],&xh[1],&xh[2],&vh[0],&vh[1],&vh[2]); // output the central with probability given by red_central_fraction fred = red_central_fraction(mass,wpl.a); p = drand48(); if(p>fred)ibluecen[ii] = 1; // mark as blue or red before cutting for min halo mass if(mass<minimum_halo_mass)continue; haloid++; // decide whether this halo's center is red or blue if(p>fred) { // get the mass of the central galaxy mstar = log10(ms_to_mhalo_inversion(mass)); m1 = gasdev(&IDUM)*wpl.a[6+(1-BLUE_FLAG)*11]+(mstar); if(m1>minimum_lgmstar) { fprintf(fp2,"%e %e %e %e %e %e %d %e %e\n",xh[0],xh[1],xh[2],vh[0],vh[1],vh[2],1,m1,mass); fprintf(fp3,"%d\n",haloid); } } // tabulate the CLF for this halo mass //nsat = generate_satellite_galaxy(-mass,9.0); nsat = generate_satellite_galaxy_tab(-mass,minimum_lgmstar,0); //printf("nsat check> %e\n",nsat); n1 = poisson_deviate(nsat); for(i=1;i<=n1;++i) { //m1 = generate_satellite_galaxy(mass,9.0); m1 = generate_satellite_galaxy_tab(mass,minimum_lgmstar,0); r = NFW_position(mass,xg); NFW_velocity(mass,vg,mag); boxwrap_galaxy(xh,xg); fprintf(fp2,"%e %e %e %e %e %e %d %e %e\n", xg[0],xg[1],xg[2],vh[0]+vg[0],vh[1]+vg[1],vh[2]+vg[2],0,m1,mass); fprintf(fp3,"%d\n",haloid); } fflush(fp2); fflush(fp3); } fclose(fp2); fclose(fp3); /* --------------------------------------------- * now got back and do the REDS, if required * --------------------------------------------- */ if(!COLOR)return; sprintf(aa,"%s.shmr_mock_red",Task.root_filename); fp2 = fopen(aa,"w"); fprintf(stderr,"outfile: [%s]\n",aa); sprintf(aa,"%s.shmr_mock_haloid_red",Task.root_filename); fp3 = fopen(aa,"w"); rewind(fp); BLUE_FLAG = 0; wpl.reset_inversion = 1; set_up_hod_for_shmr(2.0E9,5.0E12,wpl.a); set_up_hod_for_shmr(1.0E9,5.0E12,wpl.a); minimum_halo_mass = HOD.M_low; fprintf(stderr,"Expected number density of red galaxies N(>10^9 Msol)= %e\n",GALAXY_DENSITY); fprintf(stderr,"Minimum halo mass (M_low) required= %e\n",minimum_halo_mass); generate_satellite_galaxy_tab(1.0E12,minimum_lgmstar,1); haloid = 0; for(ii=1;ii<=nhalo;++ii) { fscanf(fp,"%d %lf %f %f %f %f %f %f %f %f", &i,&mass,&x1,&x1,&xh[0],&xh[1],&xh[2],&vh[0],&vh[1],&vh[2]); if(mass<minimum_halo_mass)continue; haloid++; // we already know whether this halo is blue central if(ibluecen[ii])goto POP_SATS; // get the mass of the central galaxy mstar = log10(ms_to_mhalo_inversion(mass)); m1 = gasdev(&IDUM)*wpl.a[6+(1-BLUE_FLAG)*11]+(mstar); if(m1>minimum_lgmstar) { fprintf(fp2,"%e %e %e %e %e %e %d %e %e\n",xh[0],xh[1],xh[2],vh[0],vh[1],vh[2],1,m1,mass); fprintf(fp3,"%d\n",haloid); } POP_SATS: // tabulate the CLF for this halo mass nsat = generate_satellite_galaxy_tab(-mass,minimum_lgmstar,0); n1 = poisson_deviate(nsat); for(i=1;i<=n1;++i) { m1 = generate_satellite_galaxy_tab(mass,minimum_lgmstar,0); r = NFW_position(mass,xg); NFW_velocity(mass,vg,mag); boxwrap_galaxy(xh,xg); fprintf(fp2,"%e %e %e %e %e %e %d %e %e\n", xg[0],xg[1],xg[2],vh[0]+vg[0],vh[1]+vg[1],vh[2]+vg[2],0,m1,mass); fprintf(fp3,"%d\n",haloid); } fflush(fp2); fflush(fp3); } fclose(fp); return ; }