-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cmbdata.cpp
202 lines (174 loc) · 5.26 KB
/
Cmbdata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "Cmbdata_i.h"
// Constructor
Cmbdata::Cmbdata()
:
mResolution(0),
mMinimum(NAN),
mMaximum(NAN),
mAverageTemp(NAN),
mStandardDevTemp(NAN),
mResAzimuth(0),
mResZenith(0)
{
}
// Destructor
Cmbdata::~Cmbdata()
{
}
// resets the data
void Cmbdata::clear()
{
resolution(0);
mMinimum = NAN;
mMaximum = NAN;
}
/* Getting and setting parameters */
// Get the current resolution
int Cmbdata::resolution()
{
return mResolution;
}
// Set a new resolution
int Cmbdata::resolution(int pResolution)
{
mResAzimuth = int(sqrt(pResolution*1.0));
mResZenith = pResolution/mResAzimuth;
mResolution = mResAzimuth * mResZenith;
CmbDataVector::resize(mResolution);
fillCoords();
return mResolution;
}
// Get the maximum value of the (real part of the) cmb
double Cmbdata::maximum()
{
if( isnan(mMaximum) )
{
fillMinMax();
}
return mMaximum;
}
// Get the minimum value of the (real part of the) cmb
double Cmbdata::minimum()
{
if( isnan(mMaximum) )
{
fillMinMax();
}
return mMinimum;
}
// Do a reality check (i.e. sum the non real parts)
double Cmbdata::reality()
{
double reality=0;
for (Cmbdata::iterator cmbEl = this->begin();
cmbEl != this->end();
++cmbEl)
{
reality+=imag(cmbEl->temperature)*cmbEl->weight;
}
return reality;
}
/* Calculating Values */
// Calculate the coordinates corresponding to the dataset
void Cmbdata::fillCoords()
{
// filling the coordinates..
int thei;
int iAzi, nAzi0, nAzi1, nAzi2;
int iZen, nZen0, nZen1, nZen2;
double zenith;
double azimuth;
for(iAzi = 0; iAzi < mResAzimuth; iAzi++)
{
for(iZen=0; iZen<mResZenith; iZen++)
{
double circ = 6.2831853071795862;
thei = mResZenith * iAzi + iZen;
// -1 because we want inclusive!
// even though all these points are the same)
zenith = ((circ/2)*iZen) / (mResZenith-1);
// exclusive!
azimuth = ( circ *iAzi) / (mResAzimuth);
/* Triangles to be drawn like this:
\ | \ |
-( iA, iZ)--(nA0,nZ0)-
| \ | \
\ | \ |
-(nA2,nZ2)--(nA1,nZ1)-
| \ | \
*/
nAzi0 = iAzi+1;
if (nAzi0 >= mResAzimuth) nAzi0 = 0;
nAzi1 = nAzi0;
nAzi2 = iAzi;
nZen0 = iZen;
nZen1 = iZen+1;
if (nZen1 >= mResZenith) nZen1 = mResZenith-1;
nZen2 = nZen1;
(*this)[thei].coordinate.sphericalRadius(1.0);
(*this)[thei].coordinate.sphericalAzimuth(azimuth);
(*this)[thei].coordinate.sphericalZenith(zenith);
(*this)[thei].weight=sin((*this)[thei].coordinate.ze());
(*this)[thei].temperature=dcomp(0,0);
(*this)[thei].triangle[0] = &(*this)[mResZenith * nAzi0 + nZen0];
(*this)[thei].triangle[1] = &(*this)[mResZenith * nAzi1 + nZen1];
(*this)[thei].triangle[2] = &(*this)[mResZenith * nAzi2 + nZen2];
} // iZen
} // iAzi
}
// Calculate the minimum and maximum
void Cmbdata::fillMinMax()
{
mMaximum=-100000;
mMinimum= 100000;
double temperature;
double totalTemp = 0;
double totalStdDev = 0;
for (Cmbdata::iterator cmbEl = this->begin();
cmbEl != this->end();
++cmbEl)
{
temperature = real(cmbEl->temperature);
totalTemp += temperature;
if (temperature > mMaximum) mMaximum = temperature;
if (temperature < mMinimum) mMinimum = temperature;
}
mAverageTemp = totalTemp / (this->end() - this->begin());
for (Cmbdata::iterator cmbEl = this->begin();
cmbEl != this->end();
++cmbEl)
{
temperature =real(cmbEl->temperature);
totalStdDev += (temperature - mAverageTemp) * (temperature - mAverageTemp);
}
mStandardDevTemp = sqrt(totalStdDev / (this->end() - this->begin()));
}
/* Input and Output functions */
// print out the cmb to cout
void Cmbdata::print(std::ostream *ost)
{
double circ = 6.2831853071795862;
cout.precision(6);
*ost << "Printing cmbdata"<<endl;
*ost << " cmbdatasize: " << size() << endl;
*ost << " minimum:" << minimum() << " maximum:"<< maximum() << endl;
for (Cmbdata::iterator cmbEl = this->begin();
cmbEl != this->end();
++cmbEl)
{
*ost << "Point ze:" << cmbEl->coordinate.sphericalZenith()/circ
<< " az:" << cmbEl->coordinate.sphericalAzimuth()/circ
<< " dT:" << cmbEl->temperature
<< endl;
*ost << " t0: ze:" << cmbEl->triangle[0]->coordinate.sphericalZenith()/circ
<< " az:" << cmbEl->triangle[0]->coordinate.sphericalAzimuth()/circ
<< endl;
*ost << " t1: ze:" << cmbEl->triangle[1]->coordinate.sphericalZenith()/circ
<< " az:" << cmbEl->triangle[1]->coordinate.sphericalAzimuth()/circ
<< endl;
*ost << " t2: ze:" << cmbEl->triangle[2]->coordinate.sphericalZenith()/circ
<< " az:" << cmbEl->triangle[2]->coordinate.sphericalAzimuth()/circ
<< endl;
}
return;
}