Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_sample_photoz.c File Reference
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <ccl.h>
#include <ccl_redshifts.h>
Include dependency graph for ccl_sample_photoz.c:

Go to the source code of this file.

Classes

struct  user_pz_params
 
struct  user_dN_params
 

Functions

double sigmaz_sources (double z)
 
double user_pz_probability (double z_ph, double z_s, void *user_par, int *status)
 
double user_dNdz (double z, void *user_par, int *status)
 
int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 48 of file ccl_sample_photoz.c.

References user_dN_params::alpha, user_dN_params::beta, ccl_create_dNdz_info(), ccl_create_photoz_info(), ccl_dNdz_tomog(), ccl_free_dNdz_info(), ccl_free_photoz_info(), user_pz_params::sigma_z, sigmaz_sources(), user_dNdz(), user_pz_probability(), z, and user_dN_params::z0.

49 {
50  // The user declares and sets an instance of parameters to their photo_z function:
51  struct user_pz_params my_pz_params_example;
52  my_pz_params_example.sigma_z = sigmaz_sources;
53  struct user_dN_params my_dN_params_example;
54  my_dN_params_example.alpha = 1.24;
55  my_dN_params_example.beta = 1.01;
56  my_dN_params_example.z0 = 0.51;
57 
58  // Declare a variable of the type of user_pz_info to hold the struct to be created.
59  pz_info * my_pz_info;
60 
61  // Create the struct to hold the user information about photo_z's.
62  my_pz_info = ccl_create_photoz_info(&my_pz_params_example, &user_pz_probability);
63 
64  // Declare a variable of the type of user_dN_info to hold the struct to be created
65  dNdz_info * my_dN_info;
66 
67  // Create a simple analytic true redshift distribution:
68  my_dN_info = ccl_create_dNdz_info(&my_dN_params_example, &user_dNdz);
69 
70  int status = 0;
71  double z_test;
72  int z;
73  double tmp1,tmp2,tmp3,tmp4,tmp5;
74  double dNdz_tomo;
75  FILE * output;
76  output = fopen("./tests/example_tomographic_bins.out", "w");
77  for (z=0; z<100; z=z+1) {
78  z_test = 0.035*z;
79 
80  ccl_dNdz_tomog(z_test, 0.,6.,my_pz_info, my_dN_info, &dNdz_tomo, &status);
81  if (status!=0) {
82  printf("Error in initiating the tomographic bins. Exiting.\n");
83  exit(1);
84  }
85 
86  ccl_dNdz_tomog(z_test, 0.,0.6,my_pz_info, my_dN_info, &tmp1, &status);
87  if (status!=0) {
88  printf("Error in initiating the tomographic bins. Exiting.\n");
89  exit(1);
90  }
91 
92  ccl_dNdz_tomog(z_test, 0.6,1.2,my_pz_info, my_dN_info, &tmp2, &status);
93  if (status!=0) {
94  printf("Error in initiating the tomographic bins. Exiting.\n");
95  exit(1);
96  }
97  ccl_dNdz_tomog(z_test, 1.2,1.8,my_pz_info, my_dN_info, &tmp3, &status);
98  if (status!=0) {
99  printf("Error in initiating the tomographic bins. Exiting.\n");
100  exit(1);
101  }
102  ccl_dNdz_tomog(z_test, 1.8,2.4,my_pz_info, my_dN_info, &tmp4, &status);
103  if (status!=0) {
104  printf("Error in initiating the tomographic bins. Exiting.\n");
105  exit(1);
106  }
107  ccl_dNdz_tomog(z_test, 2.4,3.0,my_pz_info, my_dN_info, &tmp5, &status);
108  if (status!=0) {
109  printf("Error in initiating the tomographic bins. Exiting.\n");
110  exit(1);
111  }
112  fprintf(output, "%f %f %f %f %f %f %f\n", z_test,tmp1,tmp2,tmp3,tmp4,tmp5,dNdz_tomo);
113  }
114 
115  fclose(output);
116 
117  // Free the photo_z information
118  ccl_free_photoz_info(my_pz_info);
119 
120  // Free the dNdz information
121  ccl_free_dNdz_info(my_dN_info);
122 
123  return 0;
124 }
double(* sigma_z)(double)
dNdz_info * ccl_create_dNdz_info(void *params, double(*dNdz_func)(double, void *, int *))
Definition: ccl_redshifts.c:94
double user_dNdz(double z, void *user_par, int *status)
static double z[8]
double user_pz_probability(double z_ph, double z_s, void *user_par, int *status)
pz_info * ccl_create_photoz_info(void *params, double(*pz_func)(double, double, void *, int *))
Definition: ccl_redshifts.c:21
double sigmaz_sources(double z)
void ccl_free_photoz_info(pz_info *my_photoz_info)
Definition: ccl_redshifts.c:84
void ccl_dNdz_tomog(double z, double bin_zmin, double bin_zmax, pz_info *photo_info, dNdz_info *dN_info, double *tomoout, int *status)
void ccl_free_dNdz_info(dNdz_info *dN_info)
double sigmaz_sources ( double  z)

Definition at line 17 of file ccl_sample_photoz.c.

References z.

Referenced by main().

18 {
19  return 0.05*(1.0+z);
20 }
static double z[8]
double user_dNdz ( double  z,
void *  user_par,
int *  status 
)

Definition at line 40 of file ccl_sample_photoz.c.

References user_dN_params::alpha, user_dN_params::beta, p, pow(), and user_dN_params::z0.

Referenced by main().

41 {
42  struct user_dN_params * p = (struct user_dN_params *) user_par;
43 
44  return pow(z, p->alpha) * exp(- pow(z/(p->z0), p->beta) );
45 
46 }
static double z[8]
static int p
Definition: ccl_emu17.c:25
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
double user_pz_probability ( double  z_ph,
double  z_s,
void *  user_par,
int *  status 
)

Definition at line 24 of file ccl_sample_photoz.c.

References M_PI, p, pow(), and user_pz_params::sigma_z.

Referenced by main().

25 {
26  struct user_pz_params * p = (struct user_pz_params *) user_par;
27 
28  return exp(- (z_ph-z_s)*(z_ph-z_s) / (2.*(p->sigma_z(z_s))*(p->sigma_z(z_s)))) / (pow(2.*M_PI,0.5)*(p->sigma_z(z_s))*(p->sigma_z(z_s)));
29 }
double(* sigma_z)(double)
#define M_PI
Definition: ccl_constants.h:22
static int p
Definition: ccl_emu17.c:25
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39