CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Triplet.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2010 by Federico Marulli, Michele Moresco *
3  * and Alfonso Veropalumbo *
4  * *
5  * federico.marulli3@unibo.it *
6  * *
7  * This program is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU General Public License as *
9  * published by the Free Software Foundation; either version 2 of *
10  * the License, or (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public *
18  * License along with this program; if not, write to the Free *
19  * Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ********************************************************************/
22 
38 #include "Triplet.h"
39 #include "Triplet1D.h"
40 #include "Triplet2D.h"
41 
42 using namespace std;
43 
44 using namespace cbl;
45 using namespace triplets;
46 
47 
48 // ============================================================================================
49 
50 
51 std::shared_ptr<Triplet> cbl::triplets::Triplet::Create (const cbl::triplets::TripletType type, const double r12, const double r12_binSize, const double r13, const double r13_binSize, const int nbins)
52 {
53  if (type==TripletType::_comoving_theta_) return move(unique_ptr<Triplet1D_comoving_theta>{new Triplet1D_comoving_theta(r12, r12_binSize, r13, r13_binSize, nbins)});
54  else if (type==TripletType::_comoving_side_) return move(unique_ptr<Triplet1D_comoving_side>{new Triplet1D_comoving_side(r12, r12_binSize, r13, r13_binSize, nbins)});
55  else if (type==TripletType::_comoving_costheta_) return move(unique_ptr<Triplet1D_comoving_costheta>{new Triplet1D_comoving_costheta(r12, r12_binSize, r13, r13_binSize, nbins)});
56  else if (type==TripletType::_multipoles_direct_) return move(unique_ptr<Triplet1D_multipoles_direct>{new Triplet1D_multipoles_direct(r12, r12_binSize, r13, r13_binSize, nbins)});
57 
58  else ErrorCBL("no such type of object!", "Create", "Triple.cpp");
59 
60  return NULL;
61 }
62 
63 
64 // ============================================================================================
65 // ============================================================================================
66 
67 
68 void cbl::triplets::Triplet1D::Sum (const std::shared_ptr<Triplet> tt, const double ww)
69 {
70  for (size_t i=0; i<m_TT1D.size(); i++)
71  m_TT1D[i] += ww*tt->TT1D(i);
72 }
73 
74 
75 // ============================================================================================
76 // ============================================================================================
77 
78 
80 {
81  m_min = (m_r13-0.5*m_r13_binSize)-(m_r12+0.5*m_r12_binSize);
82  m_max = (m_r13+0.5*m_r13_binSize)+(m_r12+0.5*m_r12_binSize);
83  m_binSize = (m_max-m_min)/m_nbins;
84 
85  m_scale.resize(m_nbins);
86  for (int i=0; i<m_nbins; i++)
87  m_scale[i] = m_min+(i+0.5)*m_binSize;
88 }
89 
90 
91 // ============================================================================================
92 
93 
94 void cbl::triplets::Triplet1D_comoving_side::get_triplet (const double r12, const double r13, const double r23, int &klin)
95 {
96  (void)r12; (void)r13;
97 
98  klin = int((r23-m_min)/m_binSize);
99 }
100 
101 // ============================================================================================
102 
103 
104 void cbl::triplets::Triplet1D_comoving_side::set_triplet (const int klin, const double ww)
105 {
106  m_TT1D[klin] += ww;
107 }
108 
109 // ============================================================================================
110 
111 
112 void cbl::triplets::Triplet1D_comoving_side::put (const double r12, const double r13, const double r23, const double ww)
113 {
114  (void)r12; (void)r13;
115 
116  int klin = int((r23-m_min)/m_binSize);
117 
118  m_TT1D[klin] += ww;
119 }
120 
121 
122 // ============================================================================================
123 
124 
125 void cbl::triplets::Triplet1D_comoving_side::put (const std::shared_ptr<catalogue::Object> obj1, const std::shared_ptr<catalogue::Object> obj2, const std::shared_ptr<catalogue::Object> obj3)
126 {
127  (void)obj1;
128 
129  double x2 = obj2->xx(), y2 = obj2->yy(), z2 = obj2->zz(), w2 = obj2->weight();
130  double x3 = obj3->xx(), y3 = obj3->yy(), z3 = obj3->zz(), w3 = obj3->weight();
131 
132  double r23 = cbl::Euclidean_distance(x2, x3, y2, y3, z2, z3);
133 
134  double ww = w2*w3;
135 
136  int klin = int((r23-m_min)/m_binSize);
137 
138  m_TT1D[klin] += ww;
139 }
140 
141 
142 // ============================================================================================
143 // ============================================================================================
144 
145 
147 {
148  m_binSize = par::pi/m_nbins;
149 
150  m_scale.resize(m_nbins);
151  for (int i=0; i<m_nbins; i++)
152  m_scale[i] = (i+0.5)*m_binSize/par::pi;
153 }
154 
155 
156 // ============================================================================================
157 
158 
159 void cbl::triplets::Triplet1D_comoving_theta::get_triplet (const double r12, const double r13, const double r23, int &klin)
160 {
161  double shift_angle = ((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))<0.) ? 0.00000001 : -0.00000001;
162  double angle = (abs((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13)))>0.99999999) ? acos((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))+shift_angle) : acos(((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13));
163  //angle = acos(((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13));
164  klin = int(angle/m_binSize);
165 
166 }
167 
168 
169 // ============================================================================================
170 
171 
172 void cbl::triplets::Triplet1D_comoving_theta::set_triplet (const int klin, const double ww)
173 {
174  m_TT1D[klin] += ww;
175 }
176 
177 
178 // ============================================================================================
179 
180 
181 void cbl::triplets::Triplet1D_comoving_theta::put (const double r12, const double r13, const double r23, const double ww)
182 {
183  double shift_angle = ((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))<0.) ? 0.00000001 : -0.00000001;
184  double angle = (abs((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13)))>0.99999999) ? acos((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))+shift_angle) : acos(((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13));
185  //angle = acos(((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13));
186  int klin = int(angle/m_binSize);
187 
188  m_TT1D[klin] += ww;
189 }
190 
191 
192 // ============================================================================================
193 
194 
195 void cbl::triplets::Triplet1D_comoving_theta::put (const std::shared_ptr<catalogue::Object> obj1, const std::shared_ptr<catalogue::Object> obj2, const std::shared_ptr<catalogue::Object> obj3)
196 {
197  double x1 = obj1->xx(), y1 = obj1->yy(), z1 = obj1->zz(), w1 = obj1->weight();
198  double x2 = obj2->xx(), y2 = obj2->yy(), z2 = obj2->zz(), w2 = obj2->weight();
199  double x3 = obj3->xx(), y3 = obj3->yy(), z3 = obj3->zz(), w3 = obj3->weight();
200 
201  double r12 = cbl::Euclidean_distance(x1, x2, y1, y2, z1, z2);
202  double r13 = cbl::Euclidean_distance(x1, x3, y1, y3, z1, z3);
203  double r23 = cbl::Euclidean_distance(x2, x3, y2, y3, z2, z3);
204 
205  double ww = w1*w2*w3;
206 
207  double shift_angle = ((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))<0.) ? 0.00000001 : -0.00000001;
208  double angle = (abs((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13)))>0.99999999) ? acos((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))+shift_angle) : acos(((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13));
209  //angle = acos(((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13));
210  int klin = int(angle/m_binSize);
211 
212  m_TT1D[klin] += ww;
213 }
214 
215 
216 // ============================================================================================
217 // ============================================================================================
218 
219 
221 {
222  m_binSize = 2./m_nbins;
223 
224  m_scale.resize(m_nbins);
225  for (int i=0; i<m_nbins; i++)
226  m_scale[i] = (i+0.5)*m_binSize-1;
227 }
228 
229 
230 // ============================================================================================
231 
232 
233 void cbl::triplets::Triplet1D_comoving_costheta::get_triplet (const double r12, const double r13, const double r23, int &klin)
234 {
235  double shift_angle = ((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))<0.) ? 0.00000001 : -0.00000001;
236  double cos_angle = (abs((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13)))>0.99999999) ? (((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))+shift_angle : ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
237  //double cos_angle = ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
238  klin = int((cos_angle+1)/m_binSize);
239 
240 }
241 
242 
243 // ============================================================================================
244 
245 
246 void cbl::triplets::Triplet1D_comoving_costheta::set_triplet (const int klin, const double ww)
247 {
248  m_TT1D[klin] += ww;
249 }
250 
251 
252 // ============================================================================================
253 
254 
255 void cbl::triplets::Triplet1D_comoving_costheta::put (const double r12, const double r13, const double r23, const double ww)
256 {
257  double shift_angle = ((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))<0.) ? 0.00000001 : -0.00000001;
258  double cos_angle = (abs((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13)))>0.99999999) ? (((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))+shift_angle : ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
259  //double cos_angle = ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
260  int klin = int((cos_angle+1)/m_binSize);
261 
262  m_TT1D[klin] += ww;
263 }
264 
265 
266 // ============================================================================================
267 
268 
269 void cbl::triplets::Triplet1D_comoving_costheta::put (const std::shared_ptr<catalogue::Object> obj1, const std::shared_ptr<catalogue::Object> obj2, const std::shared_ptr<catalogue::Object> obj3)
270 {
271  double x1 = obj1->xx(), y1 = obj1->yy(), z1 = obj1->zz(), w1 = obj1->weight();
272  double x2 = obj2->xx(), y2 = obj2->yy(), z2 = obj2->zz(), w2 = obj2->weight();
273  double x3 = obj3->xx(), y3 = obj3->yy(), z3 = obj3->zz(), w3 = obj3->weight();
274 
275  double r12 = cbl::Euclidean_distance(x1, x2, y1, y2, z1, z2);
276  double r13 = cbl::Euclidean_distance(x1, x3, y1, y3, z1, z3);
277  double r23 = cbl::Euclidean_distance(x2, x3, y2, y3, z2, z3);
278 
279  double ww = w1*w2*w3;
280 
281  double shift_angle = ((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))<0.) ? 0.00000001 : -0.00000001;
282  double cos_angle = (abs((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13)))>0.99999999) ? (((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))+shift_angle : ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
283  //double cos_angle = ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
284  int klin = int((cos_angle+1)/m_binSize);
285 
286  m_TT1D[klin] += ww;
287 }
288 
289 
290 // ============================================================================================
291 
292 
294 {
295  m_scale.resize(m_nbins);
296  for (int i=0; i<m_nbins; i++)
297  m_scale[i] = i;
298 }
299 
300 
301 // ============================================================================================
302 
303 
304 void cbl::triplets::Triplet1D_multipoles_direct::put (const double r12, const double r13, const double r23, const double ww)
305 {
306  //double shift_angle = ((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))<0.) ? 0.00000001 : -0.00000001;
307  //double cos_angle = (abs((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13)))>0.99999999) ? (((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))+shift_angle : ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
308  double cos_angle = ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
309 
310  for(int i=0; i<m_nbins; i++)
311  m_TT1D[i] += ww*legendre_polynomial(cos_angle, i);
312 
313 }
314 
315 
316 // ============================================================================================
317 
318 
319 void cbl::triplets::Triplet1D_multipoles_direct::put (const std::shared_ptr<catalogue::Object> obj1, const std::shared_ptr<catalogue::Object> obj2, const std::shared_ptr<catalogue::Object> obj3)
320 {
321  double x1 = obj1->xx(), y1 = obj1->yy(), z1 = obj1->zz(), w1 = obj1->weight();
322  double x2 = obj2->xx(), y2 = obj2->yy(), z2 = obj2->zz(), w2 = obj2->weight();
323  double x3 = obj3->xx(), y3 = obj3->yy(), z3 = obj3->zz(), w3 = obj3->weight();
324 
325  double r12 = cbl::Euclidean_distance(x1, x2, y1, y2, z1, z2);
326  double r13 = cbl::Euclidean_distance(x1, x3, y1, y3, z1, z3);
327  double r23 = cbl::Euclidean_distance(x2, x3, y2, y3, z2, z3);
328 
329  double ww = w1*w2*w3;
330 
331  //double shift_angle = ((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))<0.) ? 0.00000001 : -0.00000001;
332  //double cos_angle = (abs((((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13)))>0.99999999) ? (((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13))+shift_angle : ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
333 
334  double cos_angle = ((r12*r12)+(r13*r13)-(r23*r23))/(2*r12*r13);
335 
336  for(int i=0; i<m_nbins; i++)
337  m_TT1D[i] += ww*legendre_polynomial(cos_angle, i);
338 
339 }
The class Triplet1D.
The class Triplet2D.
The class Triplet.
The class Triplet1D_comoving_costheta.
Definition: Triplet1D.h:679
void put(const double r12, const double r13, const double r23, const double ww=1.) override
estimate the distance between three objects and update the triplet vectors accordingly
Definition: Triplet.cpp:255
void set_parameters() override
set the binning parameters
Definition: Triplet.cpp:220
void set_triplet(const int klin, const double ww=1.) override
update the triplet
Definition: Triplet.cpp:246
void get_triplet(const double r12, const double r13, const double r23, int &klin) override
estimate the distance between two objects and update the triplet vectors accordingly
Definition: Triplet.cpp:233
The class Triplet1D_comoving_side.
Definition: Triplet1D.h:563
void set_triplet(const int klin, const double ww=1.) override
update the triplet
Definition: Triplet.cpp:104
void put(const double r12, const double r13, const double r23, const double ww=1.) override
estimate the distance between three objects and update the triplet vectors accordingly
Definition: Triplet.cpp:112
void set_parameters() override
set the binning parameters
Definition: Triplet.cpp:79
void get_triplet(const double r12, const double r13, const double r23, int &klin) override
estimate the distance between two objects and update the triplet vectors accordingly
Definition: Triplet.cpp:94
The class Triplet1D_comoving_theta.
Definition: Triplet1D.h:343
void set_triplet(const int klin, const double ww=1.) override
update the triplet
Definition: Triplet.cpp:172
void get_triplet(const double r12, const double r13, const double r23, int &klin) override
estimate the distance between two objects and update the triplet vectors accordingly
Definition: Triplet.cpp:159
void set_parameters() override
set the binning parameters
Definition: Triplet.cpp:146
void put(const double r12, const double r13, const double r23, const double ww=1.) override
estimate the distance between three objects and update the triplet vectors accordingly
Definition: Triplet.cpp:181
The class Triplet1D_multipoles_direct.
Definition: Triplet1D.h:451
void set_parameters() override
set the binning parameters
Definition: Triplet.cpp:293
void put(const double r12, const double r13, const double r23, const double ww=1.) override
estimate the distance between three objects and update the triplet vectors accordingly
Definition: Triplet.cpp:304
void Sum(const std::shared_ptr< Triplet > tt, const double ww=1) override
sum the number of triplets
Definition: Triplet.cpp:68
static std::shared_ptr< Triplet > Create(const TripletType type, const double r12, const double r12_binSize, const double r13, const double r13_binSize, const int nbins)
static factory used to construct triplets of any type
Definition: Triplet.cpp:51
static const double pi
: the ratio of a circle's circumference to its diameter
Definition: Constants.h:199
TripletType
the triplet type
Definition: Triplet.h:62
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
double Euclidean_distance(const double x1, const double x2, const double y1, const double y2, const double z1, const double z2)
the Euclidean distance in 3D relative to the origin (0,0,0), i.e. the Euclidean norm
Definition: Func.cpp:250
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 legendre_polynomial(const double mu, const int l)
the order l Legendre polynomial
Definition: Func.cpp:1786