CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
TwoPointCorrelationCross.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2015 by Federico Marulli, 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 
36 
37 using namespace std;
38 
39 using namespace cbl;
40 using namespace catalogue;
41 using namespace chainmesh;
42 using namespace data;
43 using namespace pairs;
44 using namespace measure;
45 using namespace twopt;
46 
47 
48 // ============================================================================
49 
50 
51 void cbl::measure::twopt::TwoPointCorrelationCross::count_allPairs (const TwoPType type, const string dir_output_pairs, const vector<string> dir_input_pairs, const bool count_d1d2, const bool count_rr, const bool count_d1r, const bool count_d2r, const bool tcount, const Estimator estimator, const double fact)
52 {
53  // ----------- compute polar coordinates, if necessary -----------
54 
55  if (!m_data->isSetVar(Var::_RA_) || !m_data->isSetVar(Var::_Dec_) || !m_data->isSetVar(Var::_Dc_))
56  m_data->computePolarCoordinates();
57 
58  if (!m_data2->isSetVar(Var::_RA_) || !m_data2->isSetVar(Var::_Dec_) || !m_data2->isSetVar(Var::_Dc_))
59  m_data2->computePolarCoordinates();
60 
61  if (!m_random->isSetVar(Var::_RA_) || !m_random->isSetVar(Var::_Dec_) || !m_random->isSetVar(Var::_Dc_))
62  m_random->computePolarCoordinates();
63 
64  if (type==TwoPType::_angular_) {
65  m_data->normalizeComovingCoordinates();
66  m_data2->normalizeComovingCoordinates();
67  m_random->normalizeComovingCoordinates();
68  }
69 
70 
71  // ----------- dilute the random catalogue used to compute the RR pairs (to improve the performance) -----------
72 
73  if (estimator==Estimator::_natural_ && m_random_dilution_fraction!=1.) {
74  m_random_dilution_fraction = 1.;
75  WarningMsgCBL("m_random_dilution_fraction = 1, since the random catalogue is not diluted when using the natural estimator!", "count_allPairs", "TwoPointCorrelation.cpp");
76  }
77 
78  auto random_dil = make_shared<catalogue::Catalogue>(catalogue::Catalogue(move(m_random->diluted_catalogue(m_random_dilution_fraction))));
79 
80 
81  // ----------- create the chain-mesh -----------
82 
83  double rMAX;
84  double rMIN;
85 
86  if (type==TwoPType::_monopole_ || type==TwoPType::_filtered_ || type==TwoPType::_multipoles_direct_) {
87  rMAX = m_d1d2->sMax();
88  rMIN = m_d1d2->sMin();
89  }
90 
91  else if (type==TwoPType::_angular_) {
92  double xx, yy, zz;
93  cartesian_coord(radians(m_d1d2->sMax(), m_d1d2->angularUnits()), radians(m_d1d2->sMax(), m_d1d2->angularUnits()), 1., xx, yy, zz);
94  rMAX = sqrt(xx*xx+zz*zz);
95  cartesian_coord(radians(m_d1d2->sMin(), m_d1d2->angularUnits()), radians(m_d1d2->sMin(), m_d1d2->angularUnits()), 1., xx, yy, zz);
96  rMIN = sqrt(xx*xx+zz*zz);
97  }
98 
99  else if (type==TwoPType::_2D_polar_ || type==TwoPType::_multipoles_integrated_ || type ==TwoPType::_wedges_) {
100  rMAX = m_d1d2->sMax_D1();
101  rMIN = m_d1d2->sMin_D1();
102  }
103 
104  else if (type==TwoPType::_2D_Cartesian_ || type==TwoPType::_projected_ || type==TwoPType::_deprojected_) {
105  rMAX = max(m_d1d2->sMax_D1(), m_d1d2->sMax_D2())*sqrt(2.);
106  rMIN = max(m_d1d2->sMin_D1(), m_d1d2->sMin_D2())*sqrt(2.);
107  }
108 
109  else
110  ErrorCBL("the chosen two-point correlation function type is uknown!", "count_allPairs", "TwoPointCorrelationCross.cpp");
111 
112  double cell_size = fact*rMAX; // to be optimized!!!
113 
114  ChainMesh_Catalogue ChM_data1data2, ChM_random_dil, ChM_data1random, ChM_data2random;
115 
116  if (count_d1d2)
117  ChM_data1data2.set_par(cell_size, m_data2, rMAX, rMIN);
118 
119  if (count_rr)
120  ChM_random_dil.set_par(cell_size, random_dil, rMAX, rMIN);
121 
122  if (count_d1r)
123  ChM_data1random.set_par(cell_size, m_random, rMAX, rMIN);
124 
125  if (count_d2r)
126  ChM_data2random.set_par(cell_size, m_random, rMAX, rMIN);
127 
128 
129  // ----------- count the number of pairs or read them from file -----------
130 
131  string file;
132 
133  cout << endl; coutCBL << par::col_green << "data1-data2" << par::col_default << endl;
134  file = "d1d2.dat";
135 
136  if (count_d1d2) {
137  count_pairs(m_data, ChM_data1data2, m_d1d2, true, tcount);
138  if (dir_output_pairs!=par::defaultString) write_pairs(m_d1d2, dir_output_pairs, file);
139  }
140  else read_pairs(m_d1d2, dir_input_pairs, file);
141 
142 
143  cout << endl; coutCBL << par::col_green << "random-random" << par::col_default << endl;
144  file = "rr.dat";
145 
146  if (count_rr) {
147  count_pairs(random_dil, ChM_random_dil, m_rr, false, tcount);
148  if (dir_output_pairs!=par::defaultString) write_pairs(m_rr, dir_output_pairs, file);
149  }
150  else read_pairs(m_rr, dir_input_pairs, file);
151 
152 
153  cout << endl; coutCBL << par::col_green << "data1-random" << par::col_default << endl;
154  file = "d1r.dat";
155 
156  if (count_d1r) {
157  count_pairs(m_data, ChM_data1random, m_d1r, true, tcount);
158  if (dir_output_pairs!=par::defaultString) write_pairs(m_d1r, dir_output_pairs, file);
159  }
160  else read_pairs(m_d1r, dir_input_pairs, file);
161 
162 
163  cout << endl; coutCBL << par::col_green << "data2-random" << par::col_default << endl;
164  file = "d2r.dat";
165 
166  if (count_d2r) {
167  count_pairs(m_data2, ChM_data2random, m_d2r, true, tcount);
168  if (dir_output_pairs!=par::defaultString) write_pairs(m_d2r, dir_output_pairs, file);
169  }
170  else read_pairs(m_d2r, dir_input_pairs, file);
171 
172 
173  if (count_d1d2)
174  m_data2->Order();
175 
176  if (count_rr || count_d1r || count_d2r)
177  m_random->Order();
178 
179  if (type==TwoPType::_angular_) {
180  m_data->restoreComovingCoordinates();
181  m_data2->restoreComovingCoordinates();
182  m_random->restoreComovingCoordinates();
183  }
184 
185 }
186 
187 
188 // ============================================================================
189 
190 
191 double TwoPointCorrelationCross::PoissonError (const Estimator estimator, const double d1d2, const double rr, const double d1r, const double d2r, const int nData1, const int nData2, const int nRandom) const
192 {
193  (void)estimator; (void)d1d2; (void)rr; (void)d1r; (void)d2r; (void)nData1; (void)nData2; (void)nRandom;
194 
195  WarningMsgCBL("the PoissonError has still to be implemented for the cross-correlation function", "PoissonError", "TwoPointCorrelation.cpp");
196 
197  return -1000.;
198 }
#define coutCBL
CBL print message.
Definition: Kernel.h:734
The class TwoPointCorrelationCross.
The class Catalogue.
Definition: Catalogue.h:654
The class ChainMesh_Catalogue.
void set_par(const double cell_size, std::shared_ptr< catalogue::Catalogue > cat, const double rmax, const double rmin=-1.)
function that set parameters for the chain-mesh
void count_allPairs(const TwoPType type, const std::string dir_output_pairs=par::defaultString, const std::vector< std::string > dir_input_pairs={}, const bool count_d1d2=true, const bool count_rr=true, const bool count_d1r=true, const bool count_d2r=true, const bool tcount=true, const Estimator estimator=Estimator::_SzapudiSzalay_, const double fact=0.1)
count the data-data, random-random and data-random pairs, used to construct the estimator of the two-...
static const std::string col_green
green colour (used when printing something on the screen)
Definition: Constants.h:309
static const std::string col_default
default colour (used when printing something on the screen)
Definition: Constants.h:297
static const std::string defaultString
default std::string value
Definition: Constants.h:336
Estimator
the two-point correlation estimator
TwoPType
the two-point correlation function type
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
void cartesian_coord(const double ra, const double dec, const double dd, double &XX, double &YY, double &ZZ)
conversion from polar coordinates to Cartesian coordinates
Definition: Func.cpp:221
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
double radians(const double angle, const CoordinateUnits inputUnits=CoordinateUnits::_degrees_)
conversion to radians
Definition: Func.cpp:126
void WarningMsgCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL)
internal CBL warning message
Definition: Kernel.h:747