44 using namespace catalogue;
 
   45 using namespace chainmesh;
 
   46 using namespace pairs;
 
   47 using namespace measure;
 
   48 using namespace twopt;
 
   58   vector<double> weightTOT(dd2D->nbins_D1(), 0.), scale_mean(dd2D->nbins_D1(), 0.), scale_sigma(dd2D->nbins_D1(), 0.), z_mean(dd2D->nbins_D1(), 0.), z_sigma(dd2D->nbins_D1(), 0.);
 
   60   double fact_err, fact_scale, fact_z;
 
   62   for (
int i=0; i<dd2D->nbins_D1(); ++i) {
 
   64     for (
int j=0; j<dd2D->nbins_D2(); ++j)
 
   65       weightTOT[i] += dd2D->PP2D_weighted(i, j);
 
   67     for (
int j=0; j<dd2D->nbins_D2(); ++j) {
 
   68       scale_mean[i] += dd2D->scale_D1_mean(i, j)*dd2D->PP2D_weighted(i, j)/weightTOT[i];
 
   69       z_mean[i] += dd2D->z_mean(i, j)*dd2D->PP2D_weighted(i, j)/weightTOT[i];
 
   72     scale_sigma[i] = pow(dd2D->scale_D1_sigma(i, 0), 2)*dd2D->PP2D_weighted(i, 0);
 
   73     z_sigma[i] = pow(dd2D->z_sigma(i, 0), 2)*dd2D->PP2D_weighted(i, 0);
 
   75     for (
int j=1; j<dd2D->nbins_D2(); ++j) {
 
   76       if (dd2D->PP2D_weighted(i, j)>0) {
 
   77     fact_err = dd2D->PP2D_weighted(i, j)*dd2D->PP2D_weighted(i, j-1)/(dd2D->PP2D_weighted(i, j)+dd2D->PP2D_weighted(i, j-1));
 
   78     fact_scale = pow(dd2D->scale_D1_mean(i, j)-dd2D->scale_D1_mean(i, j-1), 2)*fact_err;
 
   79     fact_z = pow(dd2D->z_mean(i, j)-dd2D->z_mean(i, j-1), 2)*fact_err;
 
   80     scale_sigma[i] += pow(dd2D->scale_D1_sigma(i, j), 2)*dd2D->PP2D_weighted(i, j)+fact_scale;
 
   81     z_sigma[i] += pow(dd2D->z_sigma(i, j),2)*weightTOT[i]+fact_z;
 
   86   vector<vector<double>> extra(4);
 
   88   for (
int i=0; i<dd2D->nbins_D1(); ++i) {
 
   89     extra[0].push_back(scale_mean[i]);
 
   90     extra[1].push_back(sqrt(scale_sigma[i]/weightTOT[i]));
 
   91     extra[2].push_back(z_mean[i]);
 
   92     extra[3].push_back(sqrt(z_sigma[i]/weightTOT[i]));
 
   95   return move(unique_ptr<data::Data1D_extra>(
new data::Data1D_extra(rad, wedges, error, extra)));
 
  104   vector<double> rad, xx = m_dataset->xx();
 
  106   for (
size_t i=0; i<xx.size()/2; i++)
 
  107     rad.push_back(xx[i]);
 
  118   vector<double> vv = m_dataset->data();
 
  120   size_t sz = vv.size();
 
  122   vector<double> xiPerp;
 
  124   for (
size_t i=0; i<sz/2; i++)
 
  125     xiPerp.push_back(vv[i]);
 
  136   vector<double> vv = m_dataset->error();
 
  138   size_t sz = vv.size();
 
  140   vector<double> error_xiPerp;
 
  142   for (
size_t i=0; i<sz/2; i++)
 
  143     error_xiPerp.push_back(vv[i]);
 
  154   vector<double> vv = m_dataset->data();
 
  156   size_t sz = vv.size();
 
  158   vector<double> xiParallel;
 
  160   for (
size_t i=sz/2; i<sz; i++)
 
  161     xiParallel.push_back(vv[i]);
 
  172   vector<double> vv = m_dataset->error();
 
  174   size_t sz = vv.size();
 
  176   vector<double> error_xiParallel;
 
  178   for (
size_t i=sz/2; i<sz; i++)
 
  179     error_xiParallel.push_back(vv[i]);
 
  181   return error_xiParallel;
 
  192   vector<double> rad = m_dataset->xx();
 
  193   vector<double> xiw = m_dataset->data();
 
  194   vector<double> error = m_dataset->error();
 
  196   checkDim(rad, m_dd->nbins_D1()*m_nWedges, 
"rad");
 
  198   string file_out = dir+file;
 
  199   ofstream fout(file_out.c_str()); 
checkIO(fout, file_out);
 
  201   string header = 
"[1] separation at the bin centre"; 
 
  203     header += 
" # [2] perpendicular wedge # [3] error on the perpendicular wedge # [4] parallel wedge # [5] error on the parallel wedge";
 
  206     for (
int j=0; j<m_nWedges; ++j) {
 
  212   if (m_compute_extra_info)
 
  213     header += 
" # [6] mean separation # [7] standard deviation of the separation distribution # [8] mean redshift # [9] standard deviation of the redshift distribution";
 
  215   fout << 
"### " << header << 
" ###" <<endl;
 
  217   for (
int i=0; i<m_dd->nbins_D1(); ++i) {
 
  218     fout << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << rad[i];
 
  221     for (
int j=0; j<m_nWedges; ++j) {
 
  222       fout << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << xiw[i+fact]
 
  223        << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << error[i+fact];
 
  224       fact += m_dd->nbins_D1();
 
  226     if (m_compute_extra_info)
 
  227       for (
size_t ex=0; ex<m_dataset->extra_info().size(); ++ex)
 
  228     fout << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << m_dataset->extra_info(ex, i);
 
  232   fout.close(); cout << endl; 
coutCBL << 
"I wrote the file: " << file_out << endl << endl;
 
  241   const double binSize = mu[1]-mu[0];
 
  243   vector<double> rad(m_nWedges*rr.size(), 0), wedges(m_nWedges*rr.size(), 0), error(m_nWedges*rr.size(), 0);
 
  245   for (
size_t i=0; i<rr.size(); i++) { 
 
  248     for (
int wd=0; wd<m_nWedges; ++wd) { 
 
  251       const int j_min = 
nint(m_mu_integral_limits[wd][0]/binSize);
 
  252       const int j_max = 
nint(m_mu_integral_limits[wd][1]/binSize);
 
  257       for (
int j=j_min; j<j_max; j++) { 
 
  259     wedges[i+fact] += xi[i][j]*binSize; 
 
  261     if (wedges[i+fact]>-1.) error[i+fact] += pow(error_xi[i][j]*binSize, 2); 
 
  265       wedges[i+fact] /= m_mu_integral_limits[wd][1]-m_mu_integral_limits[wd][0];
 
  266       error[i+fact] /= pow(m_mu_integral_limits[wd][1]-m_mu_integral_limits[wd][0], 2);
 
  272   for_each( error.begin(), error.end(), [] (
double &vv) { vv = sqrt(vv);} );
 
  274   return (!m_compute_extra_info) ? unique_ptr<data::Data1D>(
new data::Data1D(rad, wedges, error)) : data_with_extra_info(rad, wedges, error);
 
  281 void cbl::measure::twopt::TwoPointCorrelation_wedges::measure (
const ErrorType errorType, 
const std::string dir_output_pairs, 
const std::vector<std::string> dir_input_pairs, 
const std::string dir_output_resample, 
const int nMocks, 
const bool count_dd, 
const bool count_rr, 
const bool count_dr, 
const bool tcount, 
const Estimator estimator, 
const double fact, 
const int seed)
 
  284     case (ErrorType::_Poisson_) :
 
  285       measurePoisson(dir_output_pairs, dir_input_pairs, count_dd, count_rr, count_dr, tcount, estimator, fact);
 
  287     case (ErrorType::_Jackknife_) :
 
  288       measureJackknife(dir_output_pairs, dir_input_pairs, dir_output_resample, count_dd, count_rr, count_dr, tcount, estimator, fact);
 
  290     case (ErrorType::_Bootstrap_) :
 
  291       measureBootstrap(nMocks, dir_output_pairs, dir_input_pairs, dir_output_resample, count_dd, count_rr, count_dr, tcount, estimator, fact, seed);
 
  294       ErrorCBL(
"unknown type of error!", 
"measure", 
"TwoPointCorrelation_multipoles.cpp");
 
  306   TwoPointCorrelation2D_polar::measurePoisson(dir_output_pairs, dir_input_pairs, count_dd, count_rr, count_dr, tcount, estimator, fact);
 
  311   m_dataset = Wedges(TwoPointCorrelation2D_polar::xx(), TwoPointCorrelation2D_polar::yy(), TwoPointCorrelation2D_polar::xi2D(), TwoPointCorrelation2D_polar::error2D());
 
  321     string mkdir = 
"mkdir -p "+dir_output_resample;
 
  322     if (system(mkdir.c_str())) {}
 
  325   vector<shared_ptr<data::Data> > data;
 
  326   vector<shared_ptr<pairs::Pair> > dd_regions, rr_regions, dr_regions;
 
  327   count_allPairs_region (dd_regions, rr_regions, dr_regions, TwoPType::_2D_polar_, dir_output_pairs,dir_input_pairs, count_dd, count_rr, count_dr, tcount, estimator, fact);
 
  329   auto data_polar = (estimator==Estimator::_natural_) ? correlation_NaturalEstimator(m_dd, m_rr) : correlation_LandySzalayEstimator(m_dd, m_rr, m_dr);
 
  331   if (estimator==Estimator::_natural_) 
 
  332     data = XiJackknife(dd_regions, rr_regions);
 
  333   else if (estimator==Estimator::_LandySzalay_)
 
  334     data = XiJackknife(dd_regions, rr_regions, dr_regions);
 
  336     ErrorCBL(
"the chosen estimator is not implemented!", 
"measureJackknife", 
"TwoPointCorrelation_wedges.cpp");
 
  338   vector<vector<double> > ww, covariance;
 
  340   for (
size_t i=0; i<data.size(); i++) {
 
  341     ww.push_back(data[i]->data());
 
  344       string file_out = dir_output_resample+
"xi_wedges_Jackknife_"+
conv(i, 
par::fINT)+
".dat";
 
  346       vector<double> rad = data[i]->xx();
 
  347       vector<double> xiw = data[i]->data();
 
  348       vector<double> error = data[i]->error();
 
  350       checkDim(rad, m_dd->nbins_D1()*2, 
"rad");
 
  352       ofstream fout(file_out.c_str()); 
checkIO(fout, file_out);
 
  354       fout << 
"### [1] separation at the bin centre # [2] perpendicular wedge # [3] error on the perpendicular wedge # [4] parallel wedge # [5] error on the parallel wedge ###" << endl;
 
  356       for (
int i=0; i<m_dd->nbins_D1(); i++) 
 
  357     fout << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << rad[i]
 
  358          << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << xiw[i]
 
  359          << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << error[i]
 
  360          << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << xiw[i+m_dd->nbins_D1()]
 
  361          << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << error[i+m_dd->nbins_D1()] << endl;
 
  363       fout.close(); cout << endl; 
coutCBL << 
"I wrote the file: " << file_out << endl << endl;
 
  369   vector<double> xx_polar = data_polar->xx(), yy_polar = data_polar->yy();
 
  370   vector<vector<double>> dd_polar, error_polar;
 
  371   data_polar->get_data(dd_polar); data_polar->get_error(error_polar);
 
  373   m_dataset = Wedges(xx_polar, yy_polar, dd_polar, error_polar);
 
  374   m_dataset->set_covariance(covariance);
 
  382 void cbl::measure::twopt::TwoPointCorrelation_wedges::measureBootstrap (
const int nMocks, 
const std::string dir_output_pairs, 
const std::vector<std::string> dir_input_pairs, 
const std::string dir_output_resample, 
const bool count_dd, 
const bool count_rr, 
const bool count_dr, 
const bool tcount, 
const Estimator estimator, 
const double fact, 
const int seed)
 
  385     ErrorCBL(
"the number of mocks must be >0!", 
"measureBootstrap", 
"TwoPointCorrelation1D_monopole.cpp");
 
  388     string mkdir = 
"mkdir -p "+dir_output_resample;
 
  389     if (system(mkdir.c_str())) {}
 
  392   vector<shared_ptr<data::Data> > data;
 
  393   vector<shared_ptr<pairs::Pair> > dd_regions, rr_regions, dr_regions;
 
  394   count_allPairs_region(dd_regions, rr_regions, dr_regions, TwoPType::_2D_polar_, dir_output_pairs,dir_input_pairs, count_dd, count_rr, count_dr, tcount, estimator, fact);
 
  396   auto data_polar = (estimator==Estimator::_natural_) ? correlation_NaturalEstimator(m_dd, m_rr) : correlation_LandySzalayEstimator(m_dd, m_rr, m_dr);
 
  398   if (estimator==Estimator::_natural_)
 
  399     data = XiBootstrap(nMocks, dd_regions, rr_regions, seed);
 
  400   else if (estimator==Estimator::_LandySzalay_)
 
  401     data = XiBootstrap(nMocks, dd_regions, rr_regions, dr_regions, seed);
 
  403     ErrorCBL(
"the chosen estimator is not implemented!", 
"measureBootstrap", 
"TwoPointCorrelation_wedges.cpp");
 
  405   vector<vector<double> > ww, covariance;
 
  407   for (
size_t i=0; i<data.size(); i++) {
 
  408     ww.push_back(data[i]->data());
 
  411       string file_out = dir_output_resample+
"xi_wedges_Bootstrap_"+
conv(i, 
par::fINT)+
".dat";
 
  413       vector<double> rad = data[i]->xx();
 
  414       vector<double> xiw = data[i]->data();
 
  415       vector<double> error = data[i]->error();
 
  417       checkDim(rad, m_dd->nbins_D1()*2, 
"rad");
 
  419       ofstream fout(file_out.c_str()); 
checkIO(fout, file_out);
 
  421       fout << 
"### [1] separation at the bin centre # [2] perpendicular wedge # [3] error on the perpendicular wedge # [4] parallel wedge # [5] error on the parallel wedge ###" << endl;
 
  423       for (
int i=0; i<m_dd->nbins_D1(); i++) 
 
  424     fout << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << rad[i]
 
  425          << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << xiw[i]
 
  426          << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << error[i]
 
  427          << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << xiw[i+m_dd->nbins_D1()]
 
  428          << 
"  " << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << error[i+m_dd->nbins_D1()] << endl;
 
  430       fout.close(); cout << endl; 
coutCBL << 
"I wrote the file: " << file_out << endl << endl;
 
  436   vector<double> xx_polar = data_polar->xx(), yy_polar = data_polar->yy();
 
  437   vector<vector<double>> dd_polar, error_polar;
 
  438   data_polar->get_data(dd_polar); data_polar->get_error(error_polar);
 
  440   m_dataset = Wedges(xx_polar, yy_polar, dd_polar, error_polar);
 
  441   m_dataset->set_covariance(covariance);
 
  450   vector<shared_ptr<data::Data> > data;
 
  452   auto data2d = TwoPointCorrelation2D_polar::XiJackknife(dd, rr);
 
  454   for (
size_t i=0; i<data2d.size(); i++) {
 
  455     vector<double> xx_polar = data2d[i]->xx(), yy_polar = data2d[i]->yy();
 
  456     vector<vector<double>> dd_polar, error_polar;
 
  457     data2d[i]->get_data(dd_polar); data2d[i]->get_error(error_polar);
 
  458     data.push_back(move(Wedges(xx_polar, yy_polar, dd_polar, error_polar)));
 
  470   vector<shared_ptr<data::Data> > data;
 
  472   auto data2d = TwoPointCorrelation2D_polar::XiJackknife(dd, rr, dr);
 
  474   for (
size_t i=0; i<data2d.size(); i++) {
 
  475     vector<double> xx_polar = data2d[i]->xx(), yy_polar = data2d[i]->yy();
 
  476     vector<vector<double>> dd_polar, error_polar;
 
  477     data2d[i]->get_data(dd_polar); data2d[i]->get_error(error_polar);
 
  478     data.push_back(move(Wedges(xx_polar, yy_polar, dd_polar, error_polar)));
 
  490   vector<shared_ptr<data::Data> > data;
 
  492   auto data2d = TwoPointCorrelation2D_polar::XiBootstrap(nMocks, dd, rr, seed);
 
  494   for (
size_t i=0; i<data2d.size(); i++) {
 
  495     vector<double> xx_polar = data2d[i]->xx(), yy_polar = data2d[i]->yy();
 
  496     vector<vector<double>> dd_polar, error_polar;
 
  497     data2d[i]->get_data(dd_polar); data2d[i]->get_error(error_polar);
 
  498     data.push_back(move(Wedges(xx_polar, yy_polar, dd_polar, error_polar)));
 
  510   vector<shared_ptr<data::Data> > data;
 
  512   auto data2d = TwoPointCorrelation2D_polar::XiBootstrap(nMocks, dd, rr, dr, seed);
 
  514   for (
size_t i=0; i<data2d.size(); i++) {
 
  515     vector<double> xx_polar = data2d[i]->xx(), yy_polar = data2d[i]->yy();
 
  516     vector<vector<double>> dd_polar, error_polar;
 
  517     data2d[i]->get_data(dd_polar); data2d[i]->get_error(error_polar);
 
  518     data.push_back(move(Wedges(xx_polar, yy_polar, dd_polar, error_polar)));
 
  530   m_dataset->set_covariance(dir+file);
 
  539   m_dataset->write_covariance(dir, file);
 
  548   vector<vector<double>> Xi;
 
  550   for (
size_t i=0; i<xi.size(); i++)
 
  551     Xi.push_back(xi[i]->data());
 
  553   vector<vector<double>> cov_mat;
 
  556   m_dataset->set_covariance(cov_mat);
 
  565   vector<double> rad, mean;
 
  566   vector<vector<double>> cov_mat;
 
  569   m_dataset->set_covariance(cov_mat);
 
#define coutCBL
CBL print message.
The class TwoPointCorrelation_wedges.
void measure(const ErrorType errorType=ErrorType::_Poisson_, const std::string dir_output_pairs=par::defaultString, const std::vector< std::string > dir_input_pairs={}, const std::string dir_output_resample=par::defaultString, const int nMocks=0, const bool count_dd=true, const bool count_rr=true, const bool count_dr=true, const bool tcount=true, const Estimator estimator=Estimator::_LandySzalay_, const double fact=0.1, const int seed=3213) override
measure the wedges of the two-point correlation function
void write(const std::string dir=par::defaultString, const std::string file=par::defaultString, const int rank=0) const override
write the wedges of the two-point correlation function
std::vector< double > xiParallel() const override
get the parallel wedge
void write_covariance(const std::string dir, const std::string file) const override
write the measured two-point correlation
void measureBootstrap(const int nMocks, const std::string dir_output_pairs=par::defaultString, const std::vector< std::string > dir_input_pairs={}, const std::string dir_output_resample=par::defaultString, const bool count_dd=true, const bool count_rr=true, const bool count_dr=true, const bool tcount=true, const Estimator estimator=Estimator::_LandySzalay_, const double fact=0.1, const int seed=3213) override
measure the wedges of the two-point correlation function estimating the covariance with Bootstrap res...
std::vector< std::shared_ptr< data::Data > > XiBootstrap(const int nMocks, const std::vector< std::shared_ptr< pairs::Pair > > dd, const std::vector< std::shared_ptr< pairs::Pair > > rr, const int seed=3213) override
measure the bootstrap resampling of the wedges of the two-point correlation function
void read_covariance(const std::string dir, const std::string file) override
read the measured covariance matrix
std::shared_ptr< data::Data > Wedges(const std::vector< double > rr, const std::vector< double > mu, const std::vector< std::vector< double > > xi, const std::vector< std::vector< double > > error_xi) override
pointer to the data containing the wedges of the two-point correlation function
void compute_covariance(const std::vector< std::shared_ptr< data::Data >> xi, const bool JK) override
compute the covariance matrix
std::shared_ptr< data::Data > data_with_extra_info(const std::vector< double > rad, const std::vector< double > wedges, const std::vector< double > error) const
pointer to the data object containing the values of the wedges with the extra info retrieved from the...
std::vector< double > xx() const override
get the x coordinates
void measurePoisson(const std::string dir_output_pairs=par::defaultString, const std::vector< std::string > dir_input_pairs={}, const bool count_dd=true, const bool count_rr=true, const bool count_dr=true, const bool tcount=true, const Estimator estimator=Estimator::_LandySzalay_, const double fact=0.1) override
measure the wedges of the two-point correlation function with Poisson errors
void measureJackknife(const std::string dir_output_pairs=par::defaultString, const std::vector< std::string > dir_input_pairs={}, const std::string dir_output_resample=par::defaultString, const bool count_dd=true, const bool count_rr=true, const bool count_dr=true, const bool tcount=true, const Estimator estimator=Estimator::_LandySzalay_, const double fact=0.1) override
measure the wedges of the two-point correlation function estimating the covariance with Jackknife res...
std::vector< double > xiPerpendicular() const override
get the perpendicular wedge
std::vector< std::shared_ptr< data::Data > > XiJackknife(const std::vector< std::shared_ptr< pairs::Pair > > dd, const std::vector< std::shared_ptr< pairs::Pair > > rr) override
measure the jackknife resampling of the wedges of the two-point correlation function
std::vector< double > errorParallel() const override
get the errors on the parallel wedge
std::vector< double > errorPerpendicular() const override
get the errors on the perpendicular wedge
std::shared_ptr< pairs::Pair > m_dd
number of data-data pairs
static const char fINT[]
conversion symbol for: int -> std::string
static const std::string defaultString
default std::string value
Estimator
the two-point correlation estimator
ErrorType
the two-point correlation function error type
The global namespace of the  CosmoBolognaLib
std::string conv(const T val, const char *fact)
convert a number to a std::string
void checkDim(const std::vector< T > vect, const int val, const std::string vector, bool equal=true)
check if the dimension of a std::vector is equal/lower than an input value
void checkIO(const std::ifstream &fin, const std::string file="NULL")
check if an input file can be opened
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
void covariance_matrix(const std::vector< std::vector< double >> mat, std::vector< std::vector< double >> &cov, const bool JK=false)
compute the covariance matrix from an input dataset
int nint(const T val)
the nearest integer