CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
TwoPointCorrelation_wedges.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2015 by Federico Marulli and Alfonso Veropalumbo *
3  * federico.marulli3@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ********************************************************************/
20 
39 #include "Data1D_extra.h"
40 
41 using namespace std;
42 
43 using namespace cbl;
44 using namespace catalogue;
45 using namespace chainmesh;
46 using namespace pairs;
47 using namespace measure;
48 using namespace twopt;
49 
50 
51 // ============================================================================
52 
53 
54 std::shared_ptr<data::Data> cbl::measure::twopt::TwoPointCorrelation_wedges::data_with_extra_info (const std::vector<double> rad, const std::vector<double> wedges, const std::vector<double> error) const
55 {
57 
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.);
59 
60  double fact_err, fact_scale, fact_z;
61 
62  for (int i=0; i<dd2D->nbins_D1(); ++i) {
63 
64  for (int j=0; j<dd2D->nbins_D2(); ++j)
65  weightTOT[i] += dd2D->PP2D_weighted(i, j);
66 
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];
70  }
71 
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);
74 
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;
82  }
83  }
84  }
85 
86  vector<vector<double>> extra(4);
87 
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]));
93  }
94 
95  return move(unique_ptr<data::Data1D_extra>(new data::Data1D_extra(rad, wedges, error, extra)));
96 }
97 
98 
99 // ============================================================================================
100 
101 
103 {
104  vector<double> rad, xx = m_dataset->xx();
105 
106  for (size_t i=0; i<xx.size()/2; i++)
107  rad.push_back(xx[i]);
108 
109  return rad;
110 }
111 
112 
113 // ============================================================================================
114 
115 
117 {
118  vector<double> vv = m_dataset->data();
119 
120  size_t sz = vv.size();
121 
122  vector<double> xiPerp;
123 
124  for (size_t i=0; i<sz/2; i++)
125  xiPerp.push_back(vv[i]);
126 
127  return xiPerp;
128 }
129 
130 
131 // ============================================================================================
132 
133 
135 {
136  vector<double> vv = m_dataset->error();
137 
138  size_t sz = vv.size();
139 
140  vector<double> error_xiPerp;
141 
142  for (size_t i=0; i<sz/2; i++)
143  error_xiPerp.push_back(vv[i]);
144 
145  return error_xiPerp;
146 }
147 
148 
149 // ============================================================================================
150 
151 
153 {
154  vector<double> vv = m_dataset->data();
155 
156  size_t sz = vv.size();
157 
158  vector<double> xiParallel;
159 
160  for (size_t i=sz/2; i<sz; i++)
161  xiParallel.push_back(vv[i]);
162 
163  return xiParallel;
164 }
165 
166 
167 // ============================================================================================
168 
169 
171 {
172  vector<double> vv = m_dataset->error();
173 
174  size_t sz = vv.size();
175 
176  vector<double> error_xiParallel;
177 
178  for (size_t i=sz/2; i<sz; i++)
179  error_xiParallel.push_back(vv[i]);
180 
181  return error_xiParallel;
182 }
183 
184 
185 // ============================================================================================
186 
187 
188 void cbl::measure::twopt::TwoPointCorrelation_wedges::write (const std::string dir, const std::string file, const int rank) const
189 {
190  (void)rank;
191 
192  vector<double> rad = m_dataset->xx();
193  vector<double> xiw = m_dataset->data();
194  vector<double> error = m_dataset->error();
195 
196  checkDim(rad, m_dd->nbins_D1()*m_nWedges, "rad");
197 
198  string file_out = dir+file;
199  ofstream fout(file_out.c_str()); checkIO(fout, file_out);
200 
201  string header = "[1] separation at the bin centre";
202  if (m_nWedges==2)
203  header += " # [2] perpendicular wedge # [3] error on the perpendicular wedge # [4] parallel wedge # [5] error on the parallel wedge";
204  else {
205  int index = 2;
206  for (int j=0; j<m_nWedges; ++j) {
207  header += " # ["+conv(index, par::fINT)+"] wedge "+conv(j+1, par::fINT)+" # ["+conv(index+1, par::fINT)+"] error on the wedge "+conv(j+1, par::fINT)+" ";
208  index ++;
209  }
210  }
211 
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";
214 
215  fout << "### " << header << " ###" <<endl;
216 
217  for (int i=0; i<m_dd->nbins_D1(); ++i) {
218  fout << setiosflags(ios::fixed) << setprecision(5) << setw(10) << right << rad[i];
219 
220  int fact = 0;
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();
225  }
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);
229  fout << endl;
230  }
231 
232  fout.close(); cout << endl; coutCBL << "I wrote the file: " << file_out << endl << endl;
233 }
234 
235 
236 // ============================================================================================
237 
238 
239 std::shared_ptr<data::Data> cbl::measure::twopt::TwoPointCorrelation_wedges::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)
240 {
241  const double binSize = mu[1]-mu[0];
242 
243  vector<double> rad(m_nWedges*rr.size(), 0), wedges(m_nWedges*rr.size(), 0), error(m_nWedges*rr.size(), 0);
244 
245  for (size_t i=0; i<rr.size(); i++) { // loop on the comoving scale
246  size_t fact = 0;
247 
248  for (int wd=0; wd<m_nWedges; ++wd) { // loop on the number of wedges
249  rad[i+fact] = rr[i]; // set the comoving scale for each wedge
250 
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);
253 
254  if (j_min>=j_max)
255  ErrorCBL("j_min="+conv(j_min, par::fINT)+" >= j_max="+conv(j_max, par::fINT)+" !", "measure", "TwoPointCorrelation_multipoles.cpp");
256 
257  for (int j=j_min; j<j_max; j++) { // integral loop
258 
259  wedges[i+fact] += xi[i][j]*binSize; // wd_th wedge
260 
261  if (wedges[i+fact]>-1.) error[i+fact] += pow(error_xi[i][j]*binSize, 2); // error of the wd_th wedge
262 
263  }
264 
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);
267 
268  fact += rr.size();
269  }
270  }
271 
272  for_each( error.begin(), error.end(), [] (double &vv) { vv = sqrt(vv);} );
273 
274  return (!m_compute_extra_info) ? unique_ptr<data::Data1D>(new data::Data1D(rad, wedges, error)) : data_with_extra_info(rad, wedges, error);
275 }
276 
277 
278 // ============================================================================================
279 
280 
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)
282 {
283  switch (errorType) {
284  case (ErrorType::_Poisson_) :
285  measurePoisson(dir_output_pairs, dir_input_pairs, count_dd, count_rr, count_dr, tcount, estimator, fact);
286  break;
287  case (ErrorType::_Jackknife_) :
288  measureJackknife(dir_output_pairs, dir_input_pairs, dir_output_resample, count_dd, count_rr, count_dr, tcount, estimator, fact);
289  break;
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);
292  break;
293  default:
294  ErrorCBL("unknown type of error!", "measure", "TwoPointCorrelation_multipoles.cpp");
295  }
296 }
297 
298 
299 // ============================================================================================
300 
301 
302 void cbl::measure::twopt::TwoPointCorrelation_wedges::measurePoisson (const std::string dir_output_pairs, const std::vector<std::string> dir_input_pairs, const bool count_dd, const bool count_rr, const bool count_dr, const bool tcount, const Estimator estimator, const double fact)
303 {
304  // ----------- measure the 2D two-point correlation function, xi(rp,pi) -----------
305 
306  TwoPointCorrelation2D_polar::measurePoisson(dir_output_pairs, dir_input_pairs, count_dd, count_rr, count_dr, tcount, estimator, fact);
307 
308 
309  // ----------- integrate the 2D two-point correlation function along the parallel direction -----------
310 
311  m_dataset = Wedges(TwoPointCorrelation2D_polar::xx(), TwoPointCorrelation2D_polar::yy(), TwoPointCorrelation2D_polar::xi2D(), TwoPointCorrelation2D_polar::error2D());
312 }
313 
314 
315 // ============================================================================================
316 
317 
318 void cbl::measure::twopt::TwoPointCorrelation_wedges::measureJackknife (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)
319 {
320  if (dir_output_resample!=par::defaultString && dir_output_resample!="") {
321  string mkdir = "mkdir -p "+dir_output_resample;
322  if (system(mkdir.c_str())) {}
323  }
324 
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);
328 
329  auto data_polar = (estimator==Estimator::_natural_) ? correlation_NaturalEstimator(m_dd, m_rr) : correlation_LandySzalayEstimator(m_dd, m_rr, m_dr);
330 
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);
335  else
336  ErrorCBL("the chosen estimator is not implemented!", "measureJackknife", "TwoPointCorrelation_wedges.cpp");
337 
338  vector<vector<double> > ww, covariance;
339 
340  for (size_t i=0; i<data.size(); i++) {
341  ww.push_back(data[i]->data());
342 
343  if (dir_output_resample!=par::defaultString && dir_output_resample!="") {
344  string file_out = dir_output_resample+"xi_wedges_Jackknife_"+conv(i, par::fINT)+".dat";
345 
346  vector<double> rad = data[i]->xx();
347  vector<double> xiw = data[i]->data();
348  vector<double> error = data[i]->error();
349 
350  checkDim(rad, m_dd->nbins_D1()*2, "rad");
351 
352  ofstream fout(file_out.c_str()); checkIO(fout, file_out);
353 
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;
355 
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;
362 
363  fout.close(); cout << endl; coutCBL << "I wrote the file: " << file_out << endl << endl;
364  }
365  }
366 
367  covariance_matrix(ww, covariance, true);
368 
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);
372 
373  m_dataset = Wedges(xx_polar, yy_polar, dd_polar, error_polar);
374  m_dataset->set_covariance(covariance);
375 
376 }
377 
378 
379 // ============================================================================================
380 
381 
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)
383 {
384  if (nMocks<=0)
385  ErrorCBL("the number of mocks must be >0!", "measureBootstrap", "TwoPointCorrelation1D_monopole.cpp");
386 
387  if (dir_output_resample!=par::defaultString && dir_output_resample!="") {
388  string mkdir = "mkdir -p "+dir_output_resample;
389  if (system(mkdir.c_str())) {}
390  }
391 
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);
395 
396  auto data_polar = (estimator==Estimator::_natural_) ? correlation_NaturalEstimator(m_dd, m_rr) : correlation_LandySzalayEstimator(m_dd, m_rr, m_dr);
397 
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);
402  else
403  ErrorCBL("the chosen estimator is not implemented!", "measureBootstrap", "TwoPointCorrelation_wedges.cpp");
404 
405  vector<vector<double> > ww, covariance;
406 
407  for (size_t i=0; i<data.size(); i++) {
408  ww.push_back(data[i]->data());
409 
410  if (dir_output_resample!=par::defaultString && dir_output_resample!="") {
411  string file_out = dir_output_resample+"xi_wedges_Bootstrap_"+conv(i, par::fINT)+".dat";
412 
413  vector<double> rad = data[i]->xx();
414  vector<double> xiw = data[i]->data();
415  vector<double> error = data[i]->error();
416 
417  checkDim(rad, m_dd->nbins_D1()*2, "rad");
418 
419  ofstream fout(file_out.c_str()); checkIO(fout, file_out);
420 
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;
422 
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;
429 
430  fout.close(); cout << endl; coutCBL << "I wrote the file: " << file_out << endl << endl;
431  }
432  }
433 
434  covariance_matrix(ww, covariance, false);
435 
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);
439 
440  m_dataset = Wedges(xx_polar, yy_polar, dd_polar, error_polar);
441  m_dataset->set_covariance(covariance);
442 }
443 
444 
445 // ============================================================================================
446 
447 
448 std::vector<std::shared_ptr<data::Data> > cbl::measure::twopt::TwoPointCorrelation_wedges::XiJackknife (const std::vector<std::shared_ptr<pairs::Pair> > dd, const std::vector<std::shared_ptr<pairs::Pair> > rr)
449 {
450  vector<shared_ptr<data::Data> > data;
451 
452  auto data2d = TwoPointCorrelation2D_polar::XiJackknife(dd, rr);
453 
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)));
459  }
460 
461  return data;
462 }
463 
464 
465 // ============================================================================================
466 
467 
468 std::vector<std::shared_ptr<data::Data> > cbl::measure::twopt::TwoPointCorrelation_wedges::XiJackknife (const std::vector<std::shared_ptr<pairs::Pair> > dd, const std::vector<std::shared_ptr<pairs::Pair> > rr, const std::vector<std::shared_ptr<pairs::Pair> > dr)
469 {
470  vector<shared_ptr<data::Data> > data;
471 
472  auto data2d = TwoPointCorrelation2D_polar::XiJackknife(dd, rr, dr);
473 
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)));
479  }
480 
481  return data;
482 }
483 
484 
485 // ============================================================================================
486 
487 
488 std::vector<std::shared_ptr<data::Data> > cbl::measure::twopt::TwoPointCorrelation_wedges::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)
489 {
490  vector<shared_ptr<data::Data> > data;
491 
492  auto data2d = TwoPointCorrelation2D_polar::XiBootstrap(nMocks, dd, rr, seed);
493 
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)));
499  }
500 
501  return data;
502 }
503 
504 
505 // ============================================================================================
506 
507 
508 std::vector<std::shared_ptr<data::Data> > cbl::measure::twopt::TwoPointCorrelation_wedges::XiBootstrap (const int nMocks, const std::vector<std::shared_ptr<pairs::Pair> > dd, const std::vector<std::shared_ptr<pairs::Pair> > rr, const std::vector<std::shared_ptr<pairs::Pair> > dr, const int seed)
509 {
510  vector<shared_ptr<data::Data> > data;
511 
512  auto data2d = TwoPointCorrelation2D_polar::XiBootstrap(nMocks, dd, rr, dr, seed);
513 
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)));
519  }
520 
521  return data;
522 }
523 
524 
525 // ============================================================================
526 
527 
528 void cbl::measure::twopt::TwoPointCorrelation_wedges::read_covariance (const std::string dir, const std::string file)
529 {
530  m_dataset->set_covariance(dir+file);
531 }
532 
533 
534 // ============================================================================
535 
536 
537 void cbl::measure::twopt::TwoPointCorrelation_wedges::write_covariance (const std::string dir, const std::string file) const
538 {
539  m_dataset->write_covariance(dir, file);
540 }
541 
542 
543 // ============================================================================
544 
545 
546 void cbl::measure::twopt::TwoPointCorrelation_wedges::compute_covariance (const std::vector<std::shared_ptr<data::Data>> xi, const bool JK)
547 {
548  vector<vector<double>> Xi;
549 
550  for (size_t i=0; i<xi.size(); i++)
551  Xi.push_back(xi[i]->data());
552 
553  vector<vector<double>> cov_mat;
554  cbl::covariance_matrix(Xi, cov_mat, JK);
555 
556  m_dataset->set_covariance(cov_mat);
557 }
558 
559 
560 // ============================================================================
561 
562 
563 void cbl::measure::twopt::TwoPointCorrelation_wedges::compute_covariance (const std::vector<std::string> file, const bool JK)
564 {
565  vector<double> rad, mean;
566  vector<vector<double>> cov_mat;
567 
568  cbl::covariance_matrix(file, rad, mean, cov_mat, JK);
569  m_dataset->set_covariance(cov_mat);
570 }
The class Data1D_extra.
#define coutCBL
CBL print message.
Definition: Kernel.h:734
The class TwoPointCorrelation_wedges.
The class Data1D_extra.
Definition: Data1D_extra.h:52
The class Data1D.
Definition: Data1D.h:51
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
Definition: Constants.h:121
static const std::string defaultString
default std::string value
Definition: Constants.h:336
Estimator
the two-point correlation estimator
ErrorType
the two-point correlation function error type
Definition: Measure.h:59
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
std::string conv(const T val, const char *fact)
convert a number to a std::string
Definition: Kernel.h:903
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
Definition: Kernel.h:1532
void checkIO(const std::ifstream &fin, const std::string file="NULL")
check if an input file can be opened
Definition: Kernel.cpp:160
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
Definition: Kernel.h:780
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
Definition: Func.cpp:761
int nint(const T val)
the nearest integer
Definition: Kernel.h:915