Beispiel #1
0
void run_3d_rm_corr_bf(void)
{
  //////
  // Runs xi(r,mu) in brute-force mode
  np_t sum_wd,sum_wd2,sum_wr,sum_wr2;
  Catalog cat_dat,cat_ran;

  Box3D *boxes_dat,*boxes_ran;
  int *indices_dat,*indices_ran;
  int nfull_dat,nfull_ran;

  histo_t *DD=(histo_t *)my_calloc(nb_r*nb_mu,sizeof(histo_t));
  histo_t *DR=(histo_t *)my_calloc(nb_r*nb_mu,sizeof(histo_t));
  histo_t *RR=(histo_t *)my_calloc(nb_r*nb_mu,sizeof(histo_t));

  timer(4);

  set_r_z();

#ifdef _VERBOSE
  print_info("*** 3D correlation function (r,mu): \n");
  print_info(" - Range: %.3lf < r < %.3lf Mpc/h\n",
	 0.,1/i_r_max);
  print_info(" - #bins: %d\n",nb_r);
  print_info(" - Range: 0.000 < mu < 1.000\n");
  print_info(" - #bins: %d\n",nb_mu);
  if(logbin) {
    print_info(" - Logarithmic binning with %d bins per decade\n",
	   n_logint);
  }
  else {
    print_info(" - Resolution: d(r) = %.3lf Mpc/h\n",
	   1./(i_r_max*nb_r));
  }
  print_info(" - Using a brute-force approach \n");
  print_info("\n");
#endif

  read_dr_catalogs(&cat_dat,&cat_ran,
		   &sum_wd,&sum_wd2,&sum_wr,&sum_wr2);
  
  print_info("*** Boxing catalogs \n");
  init_3D_params(cat_dat,cat_ran,4);
  boxes_dat=mk_Boxes3D_from_Catalog(cat_dat,&indices_dat,&nfull_dat);
  free_Catalog(cat_dat);
  boxes_ran=mk_Boxes3D_from_Catalog(cat_ran,&indices_ran,&nfull_ran);
  free_Catalog(cat_ran);
  print_info("\n");
  
#ifdef _DEBUG
  write_Boxes3D(n_boxes3D,boxes_dat,"debug_Box3DDat.dat");
  write_Boxes3D(n_boxes3D,boxes_ran,"debug_Box3DRan.dat");
#endif //_DEBUG

  print_info("*** Correlating \n");
  print_info(" - Auto-correlating data \n");
  timer(0);
  auto_3d_rm_bf(nfull_dat,indices_dat,boxes_dat,DD);
  timer(2);
  print_info(" - Auto-correlating random \n");
  auto_3d_rm_bf(nfull_ran,indices_ran,boxes_ran,RR);
  timer(2);
  print_info(" - Cross-correlating \n");
  cross_3d_rm_bf(nfull_dat,indices_dat,
		 boxes_dat,boxes_ran,DR);
  timer(1);

  print_info("\n");
  write_CF(fnameOut,DD,DR,RR,
	   sum_wd,sum_wd2,sum_wr,sum_wr2);

  print_info("*** Cleaning up\n");
  free_Boxes3D(n_boxes3D,boxes_dat);
  free_Boxes3D(n_boxes3D,boxes_ran);
  free(indices_dat);
  free(indices_ran);
  end_r_z();
  free(DD);
  free(DR);
  free(RR);
}
Beispiel #2
0
void run_cross_3d_ps(double *output, int ngal1,
                     double *ra1, double *dec1, double *z1, double *w1,
                     int ngal2,
                     double *ra2, double *dec2, double *z2, double *w2,
                     double r_p_max, int pi_max,
                     int r_p_nbins, int ndecades,
                     int logtrue, double O_M, double O_L) {

    // set the cosmology from given values
    omega_M = O_M;
    omega_L = O_L;
    corr_type = 9;
    nb_r=0;

    // CUTE variables that we need for the calculation
    np_t sum_wd1,sum_wd2,sum_wd1_2,sum_wd2_2;
    Catalog cat_dat1, cat_dat2;

    Box3D *boxes_dat1, *boxes_dat2;
    int *indices_dat1, *indices_dat2;
    int nfull_dat1, nfull_dat2;

    // assume that pi_max is a whole number and we take 1 Mpc bins

    // Set up a binner object
    Binner binner;
    binner.logbin = logtrue;
    binner.n_logint = r_p_nbins / ndecades;
    printf("number of logbins is: %d\n", binner.n_logint);
    binner.dim1_nbin = r_p_nbins;
    binner.dim2_nbin = pi_max;
    binner.dim3_nbin = 1;
    binner.dim1_max = r_p_max;
    binner.dim2_max = pi_max;
    binner.dim3_min = 0.08;
    binner.dim3_max = 0.45;  // this is a dummy bin

    // consistency check and setting more variables
    process_binner(binner);

    // Set up the histograms for the measurements.
    histo_t *D1D2=(histo_t *)my_calloc(nb_rt*nb_rl,sizeof(histo_t));

    timer(4);

    set_r_z();

    // Now to create CUTE catalogues with the arrays
    cat_dat1 = make_cat(ra1, dec1, z1, w1, ngal1,
                        &sum_wd1, &sum_wd1_2);
    cat_dat2 = make_cat(ra2, dec2, z2, w2, ngal2,
                        &sum_wd2, &sum_wd2_2);

    // set up the boxes for pair-counting
    init_3D_params(cat_dat1,cat_dat2,3);

    boxes_dat1=mk_Boxes3D_from_Catalog(cat_dat1,&indices_dat1,&nfull_dat1);
    boxes_dat2=mk_Boxes3D_from_Catalog(cat_dat2,&indices_dat2,&nfull_dat2);

    // Where the meat of the crunching happens.
    // This is the same code as my original edit of CUTE.
    printf("\n");

    printf(" - Cross-correlating data\n");
    timer(0);

    cross_3d_ps_bf(nfull_dat1,indices_dat1,
  		 boxes_dat1,boxes_dat2,D1D2);

    // Fill the output array that the python wrapper gets.
    // (write_CF used to be called here)
    int ii;
    for(ii=0;ii<nb_rt;ii++) {
      int jj;
      double rt;
      if(logtrue) {
        rt=pow(10,((ii+0.5)-nb_rt)/n_logint+log_rt_max);
      }
      else {
        rt=(ii+0.5)/(nb_rt*i_rt_max);
      }
      for(jj=0;jj<nb_rl;jj++) {
        double rl=(jj+0.5)/(nb_rl*i_rl_max);
        int ind=jj+nb_rl*ii;
        output[3 * (ii * pi_max + jj)] = rl;
        output[3 * (ii * pi_max + jj) + 1] = rt;
        output[3 * (ii * pi_max + jj) + 2] = D1D2[ind];
      }
    }

    printf("*** Cleaning up\n");
    free_Catalog(cat_dat1);
    free_Catalog(cat_dat2);
    free_Boxes3D(n_boxes3D,boxes_dat1);
    free_Boxes3D(n_boxes3D,boxes_dat2);
    free(indices_dat1);
    free(indices_dat2);
    end_r_z();
    free(D1D2);
}
Beispiel #3
0
void run_3d_ps_corr_bf(void)
{
  //////
  // Runs xi(pi,sigma) in brute-force mode
  np_t sum_wd,sum_wd2,sum_wr,sum_wr2;
  Catalog cat_dat,cat_ran;

  Box3D *boxes_dat,*boxes_ran;
  int *indices_dat,*indices_ran;
  int nfull_dat,nfull_ran;

  histo_t *DD=(histo_t *)my_calloc(nb_rt*nb_rl,sizeof(histo_t));
  histo_t *DR=(histo_t *)my_calloc(nb_rt*nb_rl,sizeof(histo_t));
  histo_t *RR=(histo_t *)my_calloc(nb_rt*nb_rl,sizeof(histo_t));

  timer(4);

  set_r_z();

#ifdef _VERBOSE
  print_info("*** 3D correlation function (pi,sigma): \n");
  print_info(" - Range: (%.3lf,%.3lf) < (pi,sigma) < (%.3lf,%.3lf) Mpc/h\n",
	 0.,0.,1/i_rl_max,1/i_rt_max);
  print_info(" - #bins: (%d,%d)\n",nb_rl,nb_rt);
  print_info(" - Resolution: (d(pi),d(sigma)) = (%.3lf,%.3lf) Mpc/h\n",
	 1./(i_rl_max*nb_rl),1./(i_rt_max*nb_rt));
  print_info(" - Using a brute-force approach \n");
  print_info("\n");
#endif

  read_dr_catalogs(&cat_dat,&cat_ran,
		   &sum_wd,&sum_wd2,&sum_wr,&sum_wr2);
  
  print_info("*** Boxing catalogs \n");
  init_3D_params(cat_dat,cat_ran,3);
  boxes_dat=mk_Boxes3D_from_Catalog(cat_dat,&indices_dat,&nfull_dat);
  free_Catalog(cat_dat);
  boxes_ran=mk_Boxes3D_from_Catalog(cat_ran,&indices_ran,&nfull_ran);
  free_Catalog(cat_ran);
  print_info("\n");
  
#ifdef _DEBUG
  write_Boxes3D(n_boxes3D,boxes_dat,"debug_Box3DDat.dat");
  write_Boxes3D(n_boxes3D,boxes_ran,"debug_Box3DRan.dat");
#endif //_DEBUG

  print_info("*** Correlating \n");
  print_info(" - Auto-correlating data \n");
  timer(0);
  auto_3d_ps_bf(nfull_dat,indices_dat,boxes_dat,DD);
  timer(2);
  print_info(" - Auto-correlating random \n");
  auto_3d_ps_bf(nfull_ran,indices_ran,boxes_ran,RR);
  timer(2);
  print_info(" - Cross-correlating \n");
  cross_3d_ps_bf(nfull_dat,indices_dat,
		 boxes_dat,boxes_ran,DR);
  timer(1);

  print_info("\n");
  write_CF(fnameOut,DD,DR,RR,
	   sum_wd,sum_wd2,sum_wr,sum_wr2);

  print_info("*** Cleaning up\n");
  free_Boxes3D(n_boxes3D,boxes_dat);
  free_Boxes3D(n_boxes3D,boxes_ran);
  free(indices_dat);
  free(indices_ran);
  end_r_z();
  free(DD);
  free(DR);
  free(RR);
}
Beispiel #4
0
void runfull_xcorr(double *output, int ngal1,
                   double *ra1, double *dec1, double *z1, double *w1,
                   int ngal2,
                   double *ra2, double *dec2, double *z2, double *w2,
                   int nrands1,
                   double *randr1, double *randec1, double *randz1, double *randw1,
                   int nrands2,
                   double *randr2, double *randec2, double *randz2, double *randw2,
                   double r_p_max, int pi_max,
                   int r_p_nbins, int ndecades,
                   int logtrue, double O_M, double O_L) {
    /*
     * This computes xi(r_p, pi) for two data sets with two
     * sets of random points. It does so using a modified version
     * of CUTE. The need for a param file is done away with and
     * most parameters can be set with the python call. The code
     * assumes that bins are to be linear in pi and logspace in
     * r_p. The code returns a set of histograms for the pair
     * counts with correlation and error estimates.
     */

    // set the cosmology from given values
    omega_M = O_M;
    omega_L = O_L;
    corr_type = 9;
    nb_r = 0;

    // CUTE variables that we need for the calculation
    np_t sum_wd,sum_wd2,sum_wr,sum_wr2,sum_wd_2,sum_wd2_2,sum_wr_2,sum_wr2_2;
    Catalog cat_dat_1, cat_dat_2, cat_ran_1, cat_ran_2;

    Box3D *boxes_dat_1, *boxes_ran_1, *boxes_dat_2, *boxes_ran_2;
    int *indices_dat_1, *indices_ran_1, *indices_dat_2, *indices_ran_2;
    int nfull_dat_1, nfull_ran_1, nfull_dat_2, nfull_ran_2;
    int redo_boxing;

    // assume that pi_max is a whole number and we take 1 Mpc bins

    // Set up a binner object
    Binner binner;
    binner.logbin = logtrue;
    binner.n_logint = r_p_nbins / ndecades;
    binner.dim1_nbin = r_p_nbins;
    binner.dim2_nbin = pi_max;
    binner.dim3_nbin = 1;
    binner.dim1_max = r_p_max;
    binner.dim2_max = pi_max;
    binner.dim3_min = 0.08;
    binner.dim3_max = 0.45;  // this is a dummy bin

    // consistency check and setting more variables
    process_binner(binner);

    // Set up the histograms for the measurements.
    histo_t *D1D2=(histo_t *)my_calloc(nb_rt*nb_rl,sizeof(histo_t));
    histo_t *D1R2=(histo_t *)my_calloc(nb_rt*nb_rl,sizeof(histo_t));
    histo_t *R1D2=(histo_t *)my_calloc(nb_rt*nb_rl,sizeof(histo_t));
    histo_t *R1R2=(histo_t *)my_calloc(nb_rt*nb_rl,sizeof(histo_t));

    timer(4);

    set_r_z();

    // Now to create CUTE catalogues with the arrays
    cat_dat_1 = make_cat(ra1, dec1, z1, w1, ngal1,
                         &sum_wd, &sum_wd_2);
    cat_dat_2 = make_cat(ra2, dec2, z2, w2, ngal2,
                         &sum_wd2, &sum_wd2_2);
    cat_ran_1 = make_cat(randr1, randec1, randz1, randw1, nrands1,
                         &sum_wr, &sum_wr_2);
    cat_ran_2 = make_cat(randr2, randec2, randz2, randw2, nrands2,
                         &sum_wr2, &sum_wr2_2);

    // set up the boxes for pair-counting
    init_3D_params_cross(cat_dat_1,cat_ran_1,cat_dat_2,cat_ran_2,3);

    boxes_ran_1=mk_Boxes3D_from_Catalog(cat_ran_1,&indices_ran_1,&nfull_ran_1);
    boxes_ran_2=mk_Boxes3D_from_Catalog(cat_ran_2,&indices_ran_2,&nfull_ran_2);
    boxes_dat_2=mk_Boxes3D_from_Catalog(cat_dat_2,&indices_dat_2,&nfull_dat_2);
    free_Catalog(cat_ran_1);

    // Where the meat of the crunching happens.
    // This is the same code as my original edit of CUTE.
    printf("\n");

    printf(" - Cross-correlating randoms \n");
    timer(0);
    cross_3d_ps_bf(nfull_ran_1,indices_ran_1,
  		 boxes_ran_1,boxes_ran_2,R1R2);
    timer(2);
    printf(" - Cross-correlating R1D2 \n");
    cross_3d_ps_bf(nfull_dat_2,indices_dat_2,
                   boxes_dat_2,boxes_ran_1,R1D2);
    timer(2);

    redo_boxing = cross_followup(cat_dat_1, 3);

    boxes_dat_1=mk_Boxes3D_from_Catalog(cat_dat_1,&indices_dat_1,&nfull_dat_1);
    free_Catalog(cat_dat_1);

    if (redo_boxing)
    {
      printf(" - ** Have to rebox :( \n");
      boxes_ran_2=mk_Boxes3D_from_Catalog(cat_ran_2,&indices_ran_2,&nfull_ran_2);
      free_Catalog(cat_ran_2);
      boxes_dat_2=mk_Boxes3D_from_Catalog(cat_dat_2,&indices_dat_2,&nfull_dat_2);
      free_Catalog(cat_dat_2);
    }
    else
    {
      free_Catalog(cat_ran_2);
      free_Catalog(cat_dat_2);
    }

    timer(2);
    printf(" - Cross-correlating data \n");
    cross_3d_ps_bf(nfull_dat_1,indices_dat_1,
                   boxes_dat_1,boxes_dat_2,D1D2);
    timer(2);
    printf(" - Cross-correlating D1R2 \n");
    cross_3d_ps_bf(nfull_dat_1,indices_dat_1,
                   boxes_dat_1,boxes_ran_2,D1R2);
    timer(1);

    printf("\n");

    // Fill the output array that the python wrapper gets.
    // (write_CF used to be called here)
    int ii;
    for(ii=0;ii<nb_rt;ii++) {
      int jj;
      double rt=pow(10,((ii+0.5)-nb_rt)/n_logint+log_rt_max);
      for(jj=0;jj<nb_rl;jj++) {
        double corr,ercorr;
        double rl=(jj+0.5)/(nb_rl*i_rl_max);
        int ind=jj+nb_rl*ii;
        make_CF_cross(D1D2[ind],D1R2[ind],R1D2[ind],R1R2[ind],
                      sum_wd,sum_wd2,sum_wr,sum_wr2,
                      sum_wd_2,sum_wd2_2,sum_wr_2,sum_wr2_2,
                      &corr,&ercorr);
        output[4 * (ii * pi_max + jj)] = rl;
        output[4 * (ii * pi_max + jj) + 1] = rt;
        output[4 * (ii * pi_max + jj) + 2] = corr;
        output[4 * (ii * pi_max + jj) + 3] = ercorr;
      }
    }

    printf("*** Cleaning up\n");
    free_Boxes3D(n_boxes3D,boxes_dat_1);
    free_Boxes3D(n_boxes3D,boxes_dat_2);
    free_Boxes3D(n_boxes3D,boxes_ran_1);
    free_Boxes3D(n_boxes3D,boxes_ran_2);
    free(indices_dat_1);
    free(indices_ran_1);
    free(indices_dat_2);
    free(indices_ran_2);
    end_r_z();
    free(D1D2);
    free(D1R2);
    free(R1D2);
    free(R1R2);

    // ...and return the arrays
}