test_GData.cpp
7.58 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/***************************************************************************
* test_GData.cpp - test GData class *
* ----------------------------------------------------------------------- *
* copyright (C) 2009 by Jurgen Knodlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* __ Includes ___________________________________________________________ */
#include <stdlib.h>
#include "test_GData.hpp"
#include "GModelPar.hpp"
/* __ Namespaces _________________________________________________________ */
/* __ Globals ____________________________________________________________ */
/***************************************************************************
* Test: LAT unbinned observation handling *
***************************************************************************/
void test_lat_unbinned(void)
{
// Write header
std::cout << "Test LAT unbinned data handling: ";
// Declare observations
GData data;
GLATObservation obs;
// Load unbinned LAT observation
try {
obs.load_unbinned("data/lat/ft1.fits.gz", "data/lat/ft2.fits.gz", "");
}
catch (std::exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to load LAT observation."
<< std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ".";
//std::cout << obs << std::endl;
// Add observation (twice) to data
try {
data.add(obs);
data.add(obs);
}
catch (std::exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to add LAT observation to data."
<< std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ".";
// Loop over all events in GData using iterators
try {
int num = 0;
for (GData::iterator event = data.begin(); event != data.end(); ++event) {
// std::cout << *event << std::endl;
// std::cout << event->test() << std::endl;
num++;
}
if (num != 4038) {
std::cout << std::endl <<
"TEST ERROR: Wrong number of iterations in GData::iterator."
<< std::endl;
throw;
}
}
catch (std::exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to iterate GData." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ".";
// Loop over all events using iterator
try {
int num = 0;
GLATEventList *ptr = (GLATEventList*)obs.events();
for (GLATEventList::iterator event = ptr->begin(); event != ptr->end(); ++event) {
// std::cout << *event << std::endl;
num++;
}
if (num != 2019) {
std::cout << std::endl <<
"TEST ERROR: Wrong number of iterations in GLATEventList::iterator."
<< std::endl;
throw;
}
}
catch (std::exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to iterate GLATEventList." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ".";
// Plot final test success
std::cout << " ok." << std::endl;
//GLATEventList *ptr = (GLATEventList*)obs.events();
//std::cout << obs << std::endl;
//std::cout << *ptr << std::endl;
// Exit test
return;
}
/***************************************************************************
* Test: LAT binned observation handling *
***************************************************************************/
void test_lat_binned(void)
{
// Write header
std::cout << "Test LAT binned data handling: ";
// Declare observations
GData data;
GLATObservation obs;
// Load LAT binned observation
try {
obs.load_binned("data/lat/cntmap.fits.gz", "", "");
}
catch (std::exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to load binned LAT observation."
<< std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ".";
// Reload LAT binned observation from srcmap
try {
obs.load_binned("data/lat/srcmap.fits.gz", "", "");
}
catch (std::exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to reload binned LAT observation."
<< std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ".";
// Add observation (twice) to data
try {
data.add(obs);
data.add(obs);
}
catch (std::exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to add LAT observation to data."
<< std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ".";
// Loop over all events in GData using iterators
try {
int num = 0;
int sum = 0;
for (GData::iterator event = data.begin(); event != data.end(); ++event) {
num++;
sum += (int)event->counts();
}
if (sum != 2718 || num != 400000) {
std::cout << std::endl <<
"TEST ERROR: Wrong number of iterations in GData::iterator."
<< std::endl;
throw;
}
}
catch (std::exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to iterate GData." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ".";
// Loop over all events using iterator
try {
int num = 0;
int sum = 0;
GLATEventCube *ptr = (GLATEventCube*)obs.events();
for (GLATEventCube::iterator event = ptr->begin(); event != ptr->end(); ++event) {
// std::cout << *((GLATEventBin*)&(*event));
num++;
sum += (int)event->counts();
}
if (sum != 1359 || num != 200000) {
std::cout << std::endl <<
"TEST ERROR: Wrong number of iterations in GLATEventCube::iterator."
<< std::endl;
throw;
}
}
catch (std::exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to iterate GLATEventCube." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ".";
// Plot final test success
std::cout << " ok." << std::endl;
// Exit test
return;
}
/***************************************************************************
* Main test function *
***************************************************************************/
int main(void)
{
// Dump header
std::cout << std::endl;
std::cout << "***********************" << std::endl;
std::cout << "* GData class testing *" << std::endl;
std::cout << "***********************" << std::endl;
// Execute the tests
test_lat_unbinned();
test_lat_binned();
// Return
return 0;
}