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); }
void read_run_params(char *fname) { ////// // Reads and checks the parameter file FILE *fi; int n_lin,ii; char estim[64]="none"; Binner binner; binner.dim1_max=-1; binner.dim2_max=-1; binner.dim3_min=-1; binner.dim3_max=-1; binner.dim1_nbin=-1; binner.dim1_nbin=-1; binner.dim1_nbin=-1; binner.logbin=-1; binner.n_logint=-1; print_info("*** Reading run parameters \n"); //Read parameters from file fi=fopen(fname,"r"); if(fi==NULL) error_open_file(fname); n_lin=linecount(fi); rewind(fi); for(ii=0;ii<n_lin;ii++) { char s0[512],s1[64],s2[256]; if(fgets(s0,sizeof(s0),fi)==NULL) error_read_line(fname,ii+1); if((s0[0]=='#')||(s0[0]=='\n')) continue; int sr=sscanf(s0,"%s %s",s1,s2); if(sr!=2) error_read_line(fname,ii+1); if(!strcmp(s1,"data_filename=")) sprintf(fnameData,"%s",s2); else if(!strcmp(s1,"random_filename=")) sprintf(fnameRandom,"%s",s2); else if(!strcmp(s1,"num_lines=")) { if(!strcmp(s2,"all")) n_objects=-1; else n_objects=atoi(s2); } else if(!strcmp(s1,"input_format=")) input_format=atoi(s2); else if(!strcmp(s1,"output_filename=")) sprintf(fnameOut,"%s",s2); else if(!strcmp(s1,"mask_filename=")) sprintf(fnameMask,"%s",s2); else if(!strcmp(s1,"z_dist_filename=")) sprintf(fnamedNdz,"%s",s2); else if(!strcmp(s1,"corr_estimator=")) { sprintf(estim,"%s",s2); if(!strcmp(estim,"PH")) estimator=0; else if(!strcmp(estim,"DP")) estimator=1; else if(!strcmp(estim,"HAM")) estimator=2; else if(!strcmp(estim,"LS")) estimator=3; else if(!strcmp(estim,"HEW")) estimator=4; else { fprintf(stderr,"CUTE: Unknown estimator %s, using 'LS'\n",estim); estimator=3; } } else if(!strcmp(s1,"corr_type=")) { if(!strcmp(s2,"radial")) corr_type=0; else if(!strcmp(s2,"angular")) corr_type=1; else if(!strcmp(s2,"monopole")) corr_type=2; else if(!strcmp(s2,"3D_ps")) corr_type=3; else if(!strcmp(s2,"3D_rm")) corr_type=4; else if(!strcmp(s2,"full")) corr_type=5; else if(!strcmp(s2,"angular_cross")) corr_type=6; else { fprintf(stderr,"CUTE: wrong corr type %s.",s2); fprintf(stderr," Possible types are \"radial\", \"angular\", \"full\","); fprintf(stderr," \"monopole\", \"3D_ps\" and \"3D_rm\".\n"); } } else if(!strcmp(s1,"np_rand_fact=")) fact_n_rand=atoi(s2); else if(!strcmp(s1,"omega_M=")) omega_M=atof(s2); else if(!strcmp(s1,"omega_L=")) omega_L=atof(s2); else if(!strcmp(s1,"w=")) weos=atof(s2); else if(!strcmp(s1,"radial_aperture=")) aperture_los=atof(s2)*DTORAD; else if(!strcmp(s1,"dim1_max=")) binner.dim1_max=atof(s2); else if(!strcmp(s1,"dim2_max=")) binner.dim2_max=atof(s2); else if(!strcmp(s1,"dim3_max=")) binner.dim3_max=atof(s2); else if(!strcmp(s1,"dim3_min=")) binner.dim3_min=atof(s2); else if(!strcmp(s1,"dim1_nbin=")) binner.dim1_nbin=atoi(s2); else if(!strcmp(s1,"dim2_nbin=")) binner.dim2_nbin=atoi(s2); else if(!strcmp(s1,"dim3_nbin=")) binner.dim3_nbin=atoi(s2); else if(!strcmp(s1,"log_bin=")) binner.logbin=atoi(s2); else if(!strcmp(s1,"n_logint=")) binner.n_logint=atoi(s2); else if(!strcmp(s1,"use_pm=")) use_pm=atoi(s2); else if(!strcmp(s1,"n_pix_sph=")) { n_side_cth=atoi(s2); n_side_phi=2*n_side_cth; } else fprintf(stderr,"CUTE: Unknown parameter %s\n",s1); } fclose(fi); process_binner(binner); check_params(); #ifdef _VERBOSE print_info(" Using estimator: %s\n",estim); if(gen_ran) { print_info(" The random catalog will be generated "); if(fact_n_rand==1) print_info("with as many particles as in the data \n"); else print_info("with %d times more particles than the data \n",fact_n_rand); } #endif //_VERBOSE print_info("\n"); }
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 }