CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
TwoPointCorrelationCross1D.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2017 by Federico Marulli and Carlo Giocoli *
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 shared_ptr<data::Data> cbl::measure::twopt::TwoPointCorrelationCross1D::correlation_SzapudiSzalayEstimator (const shared_ptr<pairs::Pair> d1d2, const shared_ptr<pairs::Pair> rr, const shared_ptr<pairs::Pair> d1r, const shared_ptr<pairs::Pair> d2r, const int nData1, const double nData1_weighted, const int nData2, const double nData2_weighted, const int nRandom, const double nRandom_weighted)
55 {
56  vector<double> rad(m_d1d2->nbins()), xi(m_d1d2->nbins(), -1.), error(m_d1d2->nbins(), 1000.);
57 
58  // number of objects in the first data catalogue
59  int nD1 = (nData1>0) ? nData1 : m_data->nObjects();
60 
61  // number of objects in the second data catalogue
62  int nD2 = (nData2>0) ? nData2 : m_data2->nObjects();
63 
64  // weighted number of objects in the first data catalogue
65  double nD1w = (nData1_weighted>0) ? nData1_weighted : m_data->weightedN();
66 
67  // weighted number of objects in the second data catalogue
68  double nD2w = (nData2_weighted>0) ? nData2_weighted : m_data2->weightedN();
69 
70  // number of objects in the random catalogue
71  int nR = (nRandom>0) ? nRandom : m_random->nObjects();
72 
73  // weighted number of objects in the random catalogue
74  double nRw = (nRandom_weighted>0) ? nRandom_weighted : m_random->weightedN();
75 
76  // inverse of the total number of data1-data2 pairs
77  double nD1D2i = 1./(nD1w*nD2w);
78 
79  // inverse of the total number of random-random pairs
80  double nRRi = 1./(nRw*m_random_dilution_fraction*(nRw*m_random_dilution_fraction-1.)*0.5);
81 
82  // inverse of the total number of data1-random pairs
83  double nD1Ri = 1./(nD1w*nRw);
84 
85  // inverse of the total number of data2-random pairs
86  double nD2Ri = 1./(nD2w*nRw);
87 
88  for (int i=0; i<d1d2->nbins(); i++) {
89 
90  rad[i] = d1d2->scale(i);
91 
92  if (d1d2->PP1D_weighted(i)>0) {
93 
94  if (rr->PP1D_weighted(i)<1.e-30)
95  ErrorCBL("there are no random objects in the bin "+conv(i, par::fINT)+"; please, either increase the total number of random objects or enlarge the bin size!", "correlation_SzapudiSzalayEstimator", "TwoPointCorrelationCross1D.cpp");
96 
97  // normalised number of data1-data2 weighted pairs
98  double D1D2_norm = d1d2->PP1D_weighted(i)*nD1D2i;
99 
100  // normalised number of random-random weighted pairs
101  double RR_norm = rr->PP1D_weighted(i)*nRRi;
102 
103  // normalised number of data1-random weighted pairs
104  double D1R_norm = d1r->PP1D_weighted(i)*nD1Ri;
105 
106  // normalised number of data2-random weighted pairs
107  double D2R_norm = d2r->PP1D_weighted(i)*nD2Ri;
108 
109  // Szapudi & Szalay estimator
110  xi[i] = max(-1., (D1D2_norm-D1R_norm-D2R_norm+RR_norm)/RR_norm);
111 
112  // Poisson error
113  error[i] = PoissonError(Estimator::_SzapudiSzalay_, d1d2->PP1D(i), rr->PP1D(i), d1r->PP1D(i), d2r->PP1D(i), nD1, nD2, nR);
114 
115  }
116  }
117 
118  return (!m_compute_extra_info) ? move(unique_ptr<data::Data1D>(new data::Data1D(rad, xi, error))) : data_with_extra_info(d1d2, rad, xi, error);
119 }
The class Data1D_extra.
The class TwoPointCorrelationCross1D.
The class Data1D.
Definition: Data1D.h:51
std::shared_ptr< data::Data > correlation_SzapudiSzalayEstimator(const std::shared_ptr< pairs::Pair > d1d2, const std::shared_ptr< pairs::Pair > rr, const std::shared_ptr< pairs::Pair > d1r, const std::shared_ptr< pairs::Pair > d2r, const int nData1=0, const double nData1_weighted=0., const int nData2=0, const double nData2_weighted=0., const int nRandom=0, const double nRandom_weighted=0.) override
get a dataset containing the two-point cross correlation function measured with the Szapudi-Szalay es...
static const char fINT[]
conversion symbol for: int -> std::string
Definition: Constants.h:121
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
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