Ejemplo n.º 1
0
/* THis is the integrand of the mean number integral:
 * dM dn/dM P(N_gals|M) N_true(M)
 *
 * NB! need to do a correction for the fact that the radius for N
 * isn't R200 exactly for all masses-- it's R200 for the mean mass in the bin.
 *
 */
double m2n_func2(double m)
{
  int i;
  double x, logm, mu, sig, c, rvir, rs, rhos, nsat, logj;

  logm = m;
  m = exp(m);
  i = M2N.current_bin;
  logj = log(M2N.current_Ngals);

  //mu = exp(-0.12)*pow(M2N.current_Ngals/40.0,1.15);
  //mu = B_rozo + alpha_rozo*log(M2N.current_Ngals/40.0) + log(4e14*HUBBLE);
  sig = sig_rozo;
  mu = B_rozo - sig*sig/2 + alpha_rozo*(logm-log(1.0e14*HUBBLE)) + log(40.0);
  x = exp(-(mu - logj)*(mu - logj)/(2*sig*sig))/(RT2PI*sig)/m;

  // extrapolate the HOD profile out/in to the mean radius of the bin
  c = CVIR_FAC*halo_concentration(m);
  rvir = pow(3*m/(4*PI*RHO_CRIT*OMEGA_M*DELTA_HALO),THIRD);
  rs = rvir/c;
  rhos = N_sat(m)/(4*PI*rvir*rvir*rvir*HK_func(rs/rvir));
  nsat = 4*PI*rhos*pow(M2N.radius[i],3.0)*HK_func(rs/M2N.radius[i]);
  //printf("%e %e %e %e\n",m,rvir,M2N.radius[i],nsat/N_sat(m));

  return m*nsat*dndM_interp(m)*x;
}
Ejemplo n.º 2
0
/* Same as above, only now we're calculating the number of pairs
 * in the cross-correlation.
 *
 * NB! -- We're assuming that the satellite galaxy profiles
 * of both HODs are the same.
 */
double func1_xcorr(double m)
{
  double N,n,fac2,rvir,f_ss=0,f_cs=0,cvir,x,rfof,ncen1,nsat1,ncen2,nsat2;

  m=exp(m);
  cvir=halo_concentration(m)*CVIR_FAC;
  n=dndM_interp(m);
  
  nsat1=N_sat(m);
  ncen1=N_cen(m);

  nsat2=N_sat2(m);
  ncen2=N_cen2(m);
  
  rvir=2*pow(3.0*m/(4*DELTA_HALO*PI*OMEGA_M*RHO_CRIT),1.0/3.0);

  /* Break up the contribution of pairs into
   * central-satellite (cs) and satellite-satellite (ss) pairs.
   * But for x-corr, we have c1-s2, c2-s1, s1-s2.
   */
  f_ss=dFdx_ss(r_g2/rvir,cvir)*nsat1*nsat2;
  f_cs=dFdx_cs(r_g2/rvir,cvir)*(nsat1*ncen2 + nsat2*ncen1);
  x=n*(f_ss+f_cs)/rvir*m;

  return(x);

}
Ejemplo n.º 3
0
double func1cs(double m)
{
  double N,n,fac2,rvir,f_ss,f_cs,cvir,x,rfof,ncen,nsat;

  m=exp(m);
  cvir=halo_concentration(m)*CVIR_FAC;

  n=dndM_interp(m);
  
  nsat=N_sat(m);
  ncen=N_cen(m);
  
  rvir=2*pow(3.0*m/(4*DELTA_HALO*PI*OMEGA_M*RHO_CRIT),1.0/3.0);

  /* Break up the contribution of pairs into
   * central-satellite (cs) and satellite-satellite (ss) pairs.
   */
  f_cs=dFdx_cs(r_g2/rvir,cvir)*nsat*ncen;
  x=n*(f_cs)/rvir*m;

  //  if(OUTPUT==3)
  //    printf("%e %e %e %e %e\n",m,n,f_ss,f_cs,rvir);

  return(x);

}
Ejemplo n.º 4
0
double func_central_bias(double m)
{
  double n1,n2,m0;
  m=exp(m);
  n1=dndM_interp(m);
  n2=N_cen(m);
  return(n1*n2*m*bias_interp(m,-1));
}
Ejemplo n.º 5
0
/* This is a copy of the above function that can be called from any routine.
 * (But this one integrates over dlogm).
 */
double func_halo_density(double m)
{
  double n1;

  m=exp(m);
  n1=dndM_interp(m);
  return(n1*m);
}
Ejemplo n.º 6
0
double func_mean_halo_mass(double m)
{
  double n1,n2,m0;

  m=exp(m);
  n1=dndM_interp(m);
  n2=N_avg(m);
  return(n1*n2*m*m);
}
Ejemplo n.º 7
0
void analytic_sham()
{
  int i,j,k,nlogm=400,imag,nmag,jmin;
  double dlogm,halocnt[401],magcnt[200],subcnt[401],m,msub,n1,mlow,dmag,magmin,nsub;

  double *hmass, *mag, *yy;

  dmag = 0.2;
  magmin = -18.0;
  nmag = 5/dmag;
  
  for(i=0;i<200;++i)
    magcnt[i] = 0;
  hmass = dvector(1,nlogm);
  mag = dvector(1,nlogm);
  yy = dvector(1,nlogm);
  
  mlow = HOD.M_low;

  for(i=1;i<=nlogm;++i)
    halocnt[i] = subcnt[i] = 0;
  
  // go through the mass function to find TOTAL number of halos
  dlogm = log(HOD.M_max/mlow)/nlogm;
  
  // get all HOD
  HOD.mass_shift = 0;
  HOD.fredc = 0.44;

  HOD.mass_shift = 0.6616;
  HOD.fredc = 1.00;

  HOD.mass_shift = 0.2;
  HOD.fredc = 0.66;

  for(i=1;i<=nlogm;++i)
    {
      m = exp(dlogm*(i-0.5))*mlow;
      halocnt[i] += dndM_interp(m)*m*dlogm;
      
      n1 = 0;
      for(j=1;j<=nlogm;++j)
	{
	  msub = exp(dlogm*(j-0.5))*mlow;
	  if(msub>m/3)continue; // no subhalo greater than half total mass
	  //n1 = pow(m,0.5)/2.6*pow(msub,-1.5)*exp(-pow(msub/m/0.7,6))*dlogm*m/2; //original +2
	  //n1 = pow(m,0.7)/2.6*pow(msub,-1.7)*exp(-pow(msub/m/0.7,6))*dlogm*m/3.16;
	  n1 = pow(msub,-2)*m*m*dlogm*15.7*HOD.M1;
	  halocnt[0] += n1;
	  subcnt[0] += N_cen(msub)*n1;	  
	}
      //printf("%e %e %e\n",m,N_sat(m),n1);
    }
  printf("%f\n",subcnt[0]/halocnt[0]);
  exit(0);

}
Ejemplo n.º 8
0
/* This is a copy of the above function that can be called from any routine.
 * (But this one integrates over dlogm
 */
double func_galaxy_density(double m)
{
  double n1,n2,m0;

  m=exp(m);
  n1=dndM_interp(m);
  n2=N_avg(m);
  //fprintf(stdout,"%e %e %e\n",m,n1,n2);
  return(n1*n2*m);
}
Ejemplo n.º 9
0
double func2_m2n(double m)
{
  double ncen,nsat,x;
  m = exp(m);
  ncen = N_cen(m);
  nsat = N_sat(m);
  x = poisson_prob(g31_number-1,nsat);
  if(isnan(x))x = 0;
  return ncen*x*m*dndM_interp(m);
}
Ejemplo n.º 10
0
double m2n_func1a(double m)
{
  int i;
  double x, logm, mu, sig, c, rvir, rs, rhos, mtrue, logj;

  logm = m;
  m = exp(m);
  i = M2N.current_bin;  
  logj = log(M2N.current_Ngals);


  sig = sig_rozo;
  mu = B_rozo - sig*sig/2 + alpha_rozo*(logm-log(1.0e14*HUBBLE)) + log(40.0);
  x = exp(-(mu - logj)*(mu - logj)/(2*sig*sig))/(RT2PI*sig)/m;

  return m*m*dndM_interp(m)*x;
}
Ejemplo n.º 11
0
/* THis is the integrand of the number of systems
 * dM dn/dM P(N_gals|M)
 *
 */
double m2n_func3(double m)
{
  int i;
  double x, logm, mu, sig, logj;

  logm = m;
  m = exp(m);
  logj = log(M2N.current_Ngals);

  //mu = exp(-0.12)*pow(M2N.current_Ngals/40.0,1.15);
  sig = sig_rozo;
  mu = B_rozo - sig*sig/2 + alpha_rozo*(logm-log(1.0e14*HUBBLE)) + log(40.0);
  x = exp(-(mu - logj)*(mu - logj)/(2*sig*sig))/(RT2PI*sig)/m;
  //printf("%e %e %e %f %f\n",m,dndM_interp(m),x,mu,logm);

  return m*dndM_interp(m)*x;
}
Ejemplo n.º 12
0
/* This is the function passed to qromo in the above routine. 
 * It is the number density of
 * galaxy pairs in halos of mass m at separation r_g2.
 * See Equation (11) from Berlind & Weinberg.
 */
double func1(double m)
{
  double N,n,fac2,rvir,f_ss,f_cs,cvir,x,rfof,ncen,nsat,ss;

  m=exp(m);
  cvir=halo_concentration(m)*CVIR_FAC;

  n=dndM_interp(m);
  
  nsat=N_sat(m);
  ncen=N_cen(m);
  
  rvir=2*pow(3.0*m/(4*DELTA_HALO*PI*OMEGA_M*RHO_CRIT),1.0/3.0);

  /* Break up the contribution of pairs into
   * central-satellite (cs) and satellite-satellite (ss) pairs.
   */
  f_ss=dFdx_ss(r_g2/rvir,cvir)*moment_ss(m)*0.5;
  f_cs=dFdx_cs(r_g2/rvir,cvir)*nsat*ncen;
  x=n*(f_ss+f_cs)/rvir*m;

  // only send the cs term
  //x = n*f_cs/rvir*m;

  // only send the ss term
  //x = n*f_ss/rvir*m;

  // HAMANA
  /*
  ss = moment_ss(m);
  if(ss>1)
    return x;
  else
    return n*dFdx_cs(r_g2/rvir,cvir)*moment_ss(m)*0.5/rvir*m;
  */

  //  if(OUTPUT==3)
  //    printf("%e %e %e %e %e\n",m,n,f_ss,f_cs,rvir);

  return(x);

}
Ejemplo n.º 13
0
void output_halo_mass_function()
{
  int k,nr=100;
  double x,dlogm,m,mvir,cdelta,mmin=1e8,mmax=1e16,delta_vir;
  FILE *fp;
  char aa[100];

  fprintf(stderr,"\n\nCALCULATING HALO MASS FUNCTION.\n");
  fprintf(stderr,    "-------------------------------\n\n");

  sprintf(aa,"%s.massfunc",Task.root_filename);
  fp = fopen(aa,"w");

  dlogm = (log(mmax) - log(mmin))/(nr-1);

  for(k=0;k<nr;++k)
    {
      m = exp(k*dlogm)*mmin;
      x = dndM_interp(m);
      fprintf(fp,"%e %e\n",m,x);
    }
  fclose(fp);
}
Ejemplo n.º 14
0
/* This function is to be passed to qromo to integrate the number density
 * of satellite galaxies.
 */
double func_satfrac(double m)
{
  m=exp(m);
  return(N_sat(m)*dndM_interp(m)*m);
}
Ejemplo n.º 15
0
/* This is a function to set the HOD parameters until 
 * I get some input code or batch file set up.
 * 
 */
void set_HOD_params()
{
  int i,j=1;
  double m,error=1.0,tol=1.0E-4,prev,s1,mlo;

  /* If the mass function at M_max is undefined, reset M_max
   */
  //LOCAL_DENSITY = -0.2;
  if(LOCAL_DENSITY!=0)
    {
      HOD.M_max = 1.0E16;
      while(dndM_interp(HOD.M_max)<=0) 
	{
	  HOD.M_max*=0.9;
	}
      fprintf(stderr,"NEW M_max= %e\n",HOD.M_max);
    }

  if(HOD.pdfc == 2 || HOD.pdfc == 3 || HOD.pdfc == 6 || HOD.pdfc == 8 || HOD.pdfc == 9 || HOD.pdfc == 12 || HOD.pdfc == 13)
    SOFT_CENTRAL_CUTOFF=1;

  /* Error trap both the galaxy density and M_min both left unspecified.
   */
  if(HOD.M_min<=0 && GALAXY_DENSITY<=0 && HOD.free[0]==0)
    endrun("ERROR: Must specify either M_min or GALAXY_DENSITY");

  /* If the user has specified M_min and M1, calculate the galaxy density.
   */
  if(HOD.M_min>0 && HOD.M1>0)
    {
      HOD.M_low = -1;
      if (wp.ngal==0) wp.ngal = GALAXY_DENSITY;
      if(SOFT_CENTRAL_CUTOFF)
	HOD.M_low0 = HOD.M_low = exp(zbrent(func_mlow,log(HOD.M_min*1.0E-6),log(HOD.M_min*1.1),1.0E-5));
      else
	HOD.M_low0 = HOD.M_low = HOD.M_min;

      if(HOD.M_low > HOD.M1 ) {
	while(N_cen(HOD.M_low) > 0.01) HOD.M_low /= 2.;
      }

      //if(HOD.M_low < HOD.M_min/100.) HOD.M_low = HOD.M_min/100.;

      GALAXY_DENSITY=qromo(func_galaxy_density,log(HOD.M_low),log(HOD.M_max),midpnt);
      if(OUTPUT) {
	fprintf(stdout,"M_low= %e\n",HOD.M_low);
	fprintf(stdout,"ng= %e\n",GALAXY_DENSITY); }
    }      

  /* If M_min<=0 then use the specified galaxy density to calculate M_min
   */
  if(HOD.M_min<=0)
    {
      if(HOD.pdfc==7 && HOD.pdfc==8)
	HOD.M_min=pow(10.0,zbrent(fixfunc1,8.0,log10(HOD.M_cen_max*0.99),1.0E-5));
      else
	HOD.M_min=pow(10.0,zbrent(fixfunc1,7.0,14.8,1.0E-5));

      if(OUTPUT) fprintf(stderr,"SOFT_CENTRAL_CUTOFF Delta-n %d %e\n",SOFT_CENTRAL_CUTOFF,
			 fixfunc1(log10(HOD.M_min)));
      HOD.M_low = -1;
      if(SOFT_CENTRAL_CUTOFF) {
	//HOD.M_low = exp(zbrent(func_mlow,log(HOD.M_min)-5*HOD.sigma_logM*2.3,
	//		       log(HOD.M_min),1.0E-5));
	HOD.M_low = HOD.M_min/2.;
	while(N_cen(HOD.M_low) > 0.01)
	  HOD.M_low /= 2.;
      } else
	HOD.M_low = HOD.M_min;
      if(HOD.M_low<1.0E7)HOD.M_low=1.0E+7;
      if(OUTPUT) {
	fprintf(stdout,"M_min %e [ng= %e]\n",HOD.M_min,GALAXY_DENSITY);
	fprintf(stdout,"M_low= %e\n",HOD.M_low); }
    }

  /* If M1<=0 then use the specified galaxy density to calculate M1
   */
  if(HOD.M1<=0)
    {
      HOD.M_low = -1;
      if(SOFT_CENTRAL_CUTOFF)
	HOD.M_low = exp(zbrent(func_mlow,log(HOD.M_min)-5*HOD.sigma_logM*2.3,
			       log(HOD.M_min*1.1),1.0E-5));
      else
	HOD.M_low = HOD.M_min;
      if(HOD.M_low<1.0E7)HOD.M_low=1.0E+7;
      HOD.M1=pow(10.0,zbrent(fixfunc2,log10(HOD.M_low),15.8,1.0E-5));
      if(OUTPUT) {
	fprintf(stdout,"M1 %e [ng= %e]\n",HOD.M1,GALAXY_DENSITY);
	fprintf(stdout,"M_min = %e M_low= %e\n",HOD.M_min,HOD.M_low); }
    }

  /* Set the number of halo mass bins we've got.
   */
  NUM_POW2MASS_BINS=log(HOD.M_max/HOD.M_low)/LN_2+1;

  if(HOD.pdfc==6)
    HOD.M_hi = set_high_central_mass();
  HOD.M_low0 = set_low_mass();
  return;

}
Ejemplo n.º 16
0
void output_drg_lf(int iout)
{
  FILE *fp;
  char fname[100];

  int i,j,k,nlogm=400,imag,nmag,jmin;
  double dlogm,halocnt[401],magcnt[200],m,msub,n1,mlow,dmag,magmin,nsub;

  double *hmass, *mag, *yy;

  dmag = 0.2;
  magmin = -18.0;
  nmag = 5/dmag;
  
  for(i=0;i<200;++i)
    magcnt[i] = 0;
  hmass = dvector(1,nlogm);
  mag = dvector(1,nlogm);
  yy = dvector(1,nlogm);
  
  mlow = HOD.M_low/5.0;

  for(i=1;i<=nlogm;++i)
    halocnt[i] = 0;
  
  // go through the mass function to find TOTAL number of halos
  dlogm = log(HOD.M_max/mlow)/nlogm;
  
  for(i=1;i<=nlogm;++i)
    {
      m = exp(dlogm*(i-0.5))*mlow;
      halocnt[i] += dndM_interp(m)*m*dlogm;
      
      for(j=1;j<=nlogm;++j)
	{
	  msub = exp(dlogm*(j-0.5))*mlow;
	  if(msub>m/2)continue; // no subhalo greater than half total mass
	  
	  // charlie's fit (with extra factor of log(10)?)
	  halocnt[j] += 0.02*log(10)*pow(msub/m,-0.9)*exp(-msub/(2*m))*dlogm*dndM_interp(m)*m*dlogm;
	  
	  // gao et al 2004-- gives ~4% at M=1e12 z=0.
	  //halocnt[i] += 6.3e-4*pow(msub,-1.9)*m*msub*dlogm*dndM_interp(m)*m*dlogm;
	}	  
    }
  
  // make it cumulative
  // and associate a magnitude at every mass.
  mag[nlogm] = mag_at_fixed_ngal(halocnt[nlogm]);
  hmass[nlogm] = exp(dlogm*(nlogm-0.5)*mlow);

  for(i=nlogm-1;i>=1;--i)
    {
      halocnt[i] += halocnt[i+1];
      mag[i] = mag_at_fixed_ngal(halocnt[i]);
      hmass[i] = exp(dlogm*(i-0.5))*mlow;
      //printf("CNT %e %e %e\n",hmass[i],halocnt[i],lf_number_density(-27.9,-2.0));
    }
  
  // prepare for spline interpolation
  spline(hmass,mag,nlogm,1.0E+30,1.0E+30,yy);
  
  // now go through HOD and create the DRG luminosity function
  for(i=1;i<=nlogm-1;++i)
    {
      m = hmass[i];
      if(m<HOD.M_low)continue;
      imag = (magmin-mag[i])/dmag+1;
      //printf("%e\n",magcnt[i]);
      magcnt[imag] += N_cen(m)*dndM_interp(m)*dlogm*m;

      //printf("%e %f %d %e %e %e %e %e\n",m,mag[i],imag,magcnt[imag],N_cen(m),m,dlogm,dndM_interp(m));
      //continue;
      
      // find the minimum subhalo mass
      nsub = 0;
      for(j=nlogm;j>=1;--j)
	{
	  msub = hmass[j];
	  if(msub>m/2)continue;
	  nsub += 0.02*log(10)*pow(msub/m,-0.9)*exp(msub/(2*m))*dlogm;
	  if(nsub>N_sat(m)/HOD.freds) break;
	}
      if(j==nlogm)continue;
      jmin = j;
      if(jmin>=0)
	{
	  printf("ERR %d %e %e %e %e %f\n",j,m,msub,nsub,N_sat(m)/HOD.freds,mag[jmin]);
	}

      // go through the satellites
      for(j=jmin;j<=nlogm;++j)
	{
	  msub = hmass[j];
	  if(msub>m/2)break;
	  imag = (magmin-mag[j])/dmag+1;
	  magcnt[imag] += HOD.freds*0.02*log(10)*pow(msub/m,-0.9)*exp(msub/(2*m))*dlogm*dndM_interp(m)*m*dlogm;
	}
    }

  // print out the results
  sprintf(fname,"drg_lf.%d",iout);
  fp = fopen(fname,"w");

  n1 = 0;
  for(i=0;i<200;++i)
    {
      if(-(i-0.5)*dmag+magmin >-21.6)continue;
      magcnt[i]/=dmag;
      if(magcnt[i]>0)
	fprintf(fp,"%f %e\n",-(i-0.5)*dmag + magmin,magcnt[i]);
      n1 += magcnt[i]*dmag;
    }
  printf("TOTAL ngal = %e\n",n1);
  fclose(fp);
}
double every_fucking_observers_mass_function(double mass)
{
  double h = HUBBLE;
  return dndM_interp(mass/h)*pow(HUBBLE,3.0);
}
Ejemplo n.º 18
0
double funcxx1(double m)
{
  m=exp(m);
  return(m*N_avg(m)*dndM_interp(m)*m);
}
Ejemplo n.º 19
0
double funcxx2(double m)
{
  m=exp(m);
  return(m*N_cen(m)*dndM_interp(m)*m);
}
Ejemplo n.º 20
0
// this is to calculate the numer-weighted mass of DRG galaxies
double func_drg1(double m)
{
  m = exp(m);
  return N_cen(m)*m*dndM_interp(m)*m;
}
Ejemplo n.º 21
0
/* This function is to be passed to qromo to integrate the number density
 * of satellite galaxies.
 */
double func_satellite_density(double m)
{
  m=exp(m);
  return(N_sat(m)*dndM_interp(m)*m);
}
Ejemplo n.º 22
0
/* This is the integrand which qromo or qtrap would call
 * to calculate the large-scale galaxy bias.
 * The integral is a number-weighted average of the halo
 * bias function, integrated over the halo mass function.
 */
double func_galaxy_bias(double m)
{
  m=exp(m);
  return(dndM_interp(m)*N_avg(m)*bias_interp(m,-1.)*m);
}
Ejemplo n.º 23
0
/* This function is to be passed to qromo to integrate the number density
 * of satellite galaxies.
 */
double func_central_density(double m)
{
  m=exp(m);
  return(N_cen(m)*dndM_interp(m)*m);
}