Commit 1ebf09922cebeda72c7a60daa6bb18803c93d7f7
1 parent
fe23cba1
Enhance the COMPTEL event bin unit test
Showing
4 changed files
with
316 additions
and
106 deletions
inst/com/include/GCOMEventBin.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCOMEventBin.hpp - COMPTEL event bin class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2014 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2012-2016 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -65,19 +65,19 @@ public: |
| 65 | 65 | virtual GCOMEventBin* clone(void) const; |
| 66 | 66 | virtual std::string classname(void) const; |
| 67 | 67 | virtual double size(void) const; |
| 68 | - virtual const GCOMInstDir& dir(void) const { return *m_dir; } | |
| 69 | - virtual const GEnergy& energy(void) const { return *m_energy; } | |
| 70 | - virtual const GTime& time(void) const { return *m_time; } | |
| 71 | - virtual double counts(void) const { return *m_counts; } | |
| 68 | + virtual const GCOMInstDir& dir(void) const; | |
| 69 | + virtual const GEnergy& energy(void) const; | |
| 70 | + virtual const GTime& time(void) const; | |
| 71 | + virtual double counts(void) const; | |
| 72 | 72 | virtual double error(void) const; |
| 73 | - virtual void counts(const double& counts) { *m_counts=counts; } | |
| 73 | + virtual void counts(const double& counts); | |
| 74 | 74 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 75 | 75 | |
| 76 | 76 | // Other methods |
| 77 | - const int& index(void) const { return m_index; } | |
| 78 | - const double& solidangle(void) const { return *m_solidangle; } | |
| 79 | - const GEnergy& ewidth(void) const { return *m_ewidth; } | |
| 80 | - const double& ontime(void) const { return *m_ontime; } | |
| 77 | + const int& index(void) const; | |
| 78 | + const double& solidangle(void) const; | |
| 79 | + const GEnergy& ewidth(void) const; | |
| 80 | + const double& ontime(void) const; | |
| 81 | 81 | |
| 82 | 82 | protected: |
| 83 | 83 | // Protected methods |
| ... | ... | @@ -88,13 +88,13 @@ protected: |
| 88 | 88 | // Protected members |
| 89 | 89 | bool m_alloc; //!< Signals proper memory allocation |
| 90 | 90 | int m_index; //!< Dataspace index |
| 91 | - double* m_counts; //!< Pointer to number of counts | |
| 92 | 91 | GCOMInstDir* m_dir; //!< Pointer to bin direction |
| 93 | - double* m_solidangle; //!< Pointer to solid angle of pixel (sr) | |
| 94 | 92 | GTime* m_time; //!< Pointer to bin time |
| 95 | - double* m_ontime; //!< Pointer to ontime of bin (seconds) | |
| 96 | 93 | GEnergy* m_energy; //!< Pointer to bin energy |
| 97 | 94 | GEnergy* m_ewidth; //!< Pointer to energy width of bin |
| 95 | + double* m_counts; //!< Pointer to number of counts | |
| 96 | + double* m_solidangle; //!< Pointer to solid angle of pixel (sr) | |
| 97 | + double* m_ontime; //!< Pointer to ontime of bin (seconds) | |
| 98 | 98 | }; |
| 99 | 99 | |
| 100 | 100 | |
| ... | ... | @@ -109,4 +109,133 @@ std::string GCOMEventBin::classname(void) const |
| 109 | 109 | return ("GCOMEventBin"); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | + | |
| 113 | +/***********************************************************************//** | |
| 114 | + * @brief Return instrument direction | |
| 115 | + * | |
| 116 | + * @return Instrument direction. | |
| 117 | + * | |
| 118 | + * Returns the instrument direction of the event bin. | |
| 119 | + ***************************************************************************/ | |
| 120 | +inline | |
| 121 | +const GCOMInstDir& GCOMEventBin::dir(void) const | |
| 122 | +{ | |
| 123 | + return (*m_dir); | |
| 124 | +} | |
| 125 | + | |
| 126 | + | |
| 127 | +/***********************************************************************//** | |
| 128 | + * @brief Return energy | |
| 129 | + * | |
| 130 | + * @return Energy. | |
| 131 | + * | |
| 132 | + * Returns the energy of the event bin. | |
| 133 | + ***************************************************************************/ | |
| 134 | +inline | |
| 135 | +const GEnergy& GCOMEventBin::energy(void) const | |
| 136 | +{ | |
| 137 | + return (*m_energy); | |
| 138 | +} | |
| 139 | + | |
| 140 | + | |
| 141 | +/***********************************************************************//** | |
| 142 | + * @brief Return time | |
| 143 | + * | |
| 144 | + * @return Time. | |
| 145 | + * | |
| 146 | + * Returns the time of the event bin. | |
| 147 | + ***************************************************************************/ | |
| 148 | +inline | |
| 149 | +const GTime& GCOMEventBin::time(void) const | |
| 150 | +{ | |
| 151 | + return (*m_time); | |
| 152 | +} | |
| 153 | + | |
| 154 | + | |
| 155 | +/***********************************************************************//** | |
| 156 | + * @brief Return number of counts | |
| 157 | + * | |
| 158 | + * @return Number of counts. | |
| 159 | + * | |
| 160 | + * Returns the number of counts in the event bin. | |
| 161 | + ***************************************************************************/ | |
| 162 | +inline | |
| 163 | +double GCOMEventBin::counts(void) const | |
| 164 | +{ | |
| 165 | + return (*m_counts); | |
| 166 | +} | |
| 167 | + | |
| 168 | + | |
| 169 | +/***********************************************************************//** | |
| 170 | + * @brief Set number of counts | |
| 171 | + * | |
| 172 | + * @param[in] counts Number of counts. | |
| 173 | + * | |
| 174 | + * Set the number of counts in the event bin. | |
| 175 | + ***************************************************************************/ | |
| 176 | +inline | |
| 177 | +void GCOMEventBin::counts(const double& counts) | |
| 178 | +{ | |
| 179 | + *m_counts = counts; | |
| 180 | +std::cout << *m_counts << std::endl; | |
| 181 | + return; | |
| 182 | +} | |
| 183 | + | |
| 184 | + | |
| 185 | +/***********************************************************************//** | |
| 186 | + * @brief Return bin index | |
| 187 | + * | |
| 188 | + * @return Bin index. | |
| 189 | + * | |
| 190 | + * Returns the index of the event bin if the bin is part of an event cube. If | |
| 191 | + * the event is not part of an event cube, -1 is returned. | |
| 192 | + ***************************************************************************/ | |
| 193 | +inline | |
| 194 | +const int& GCOMEventBin::index(void) const | |
| 195 | +{ | |
| 196 | + return (m_index); | |
| 197 | +} | |
| 198 | + | |
| 199 | + | |
| 200 | +/***********************************************************************//** | |
| 201 | + * @brief Return solid angle | |
| 202 | + * | |
| 203 | + * @return Solid angle. | |
| 204 | + * | |
| 205 | + * Returns the solid angle of the event bin. | |
| 206 | + ***************************************************************************/ | |
| 207 | +inline | |
| 208 | +const double& GCOMEventBin::solidangle(void) const | |
| 209 | +{ | |
| 210 | + return (*m_solidangle); | |
| 211 | +} | |
| 212 | + | |
| 213 | + | |
| 214 | +/***********************************************************************//** | |
| 215 | + * @brief Return energy width | |
| 216 | + * | |
| 217 | + * @return Energy width. | |
| 218 | + * | |
| 219 | + * Returns the energy width of the event bin. | |
| 220 | + ***************************************************************************/ | |
| 221 | +inline | |
| 222 | +const GEnergy& GCOMEventBin::ewidth(void) const | |
| 223 | +{ | |
| 224 | + return (*m_ewidth); | |
| 225 | +} | |
| 226 | + | |
| 227 | + | |
| 228 | +/***********************************************************************//** | |
| 229 | + * @brief Return ontime | |
| 230 | + * | |
| 231 | + * @return Ontime. | |
| 232 | + * | |
| 233 | + * Returns the ontime of the event bin. | |
| 234 | + ***************************************************************************/ | |
| 235 | +inline | |
| 236 | +const double& GCOMEventBin::ontime(void) const | |
| 237 | +{ | |
| 238 | + return (*m_ontime); | |
| 239 | +} | |
| 240 | + | |
| 112 | 241 | #endif /* GCOMEVENTBIN_HPP */ | ... | ... |
inst/com/src/GCOMEventBin.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCOMEventBin.cpp - COMPTEL event bin class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2012-2016 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -205,7 +205,7 @@ double GCOMEventBin::size(void) const |
| 205 | 205 | double GCOMEventBin::error(void) const |
| 206 | 206 | { |
| 207 | 207 | // Compute uncertainty |
| 208 | - double error = sqrt(counts()+1.0e-50); | |
| 208 | + double error = std::sqrt(counts()+1.0e-50); | |
| 209 | 209 | |
| 210 | 210 | // Return error |
| 211 | 211 | return error; |
| ... | ... | @@ -255,22 +255,22 @@ void GCOMEventBin::init_members(void) |
| 255 | 255 | // Allocate members |
| 256 | 256 | m_alloc = true; |
| 257 | 257 | m_index = -1; // Signals that event bin does not correspond to cube |
| 258 | - m_counts = new double; | |
| 259 | 258 | m_dir = new GCOMInstDir; |
| 260 | - m_solidangle = new double; | |
| 261 | 259 | m_time = new GTime; |
| 262 | - m_ontime = new double; | |
| 263 | 260 | m_energy = new GEnergy; |
| 264 | 261 | m_ewidth = new GEnergy; |
| 262 | + m_counts = new double; | |
| 263 | + m_solidangle = new double; | |
| 264 | + m_ontime = new double; | |
| 265 | 265 | |
| 266 | 266 | // Initialise members |
| 267 | - *m_counts = 0.0; | |
| 268 | 267 | m_dir->clear(); |
| 269 | - *m_solidangle = 0.0; | |
| 270 | 268 | m_time->clear(); |
| 271 | - *m_ontime = 0.0; | |
| 272 | 269 | m_energy->clear(); |
| 273 | 270 | m_ewidth->clear(); |
| 271 | + *m_counts = 0.0; | |
| 272 | + *m_solidangle = 0.0; | |
| 273 | + *m_ontime = 0.0; | |
| 274 | 274 | |
| 275 | 275 | // Return |
| 276 | 276 | return; |
| ... | ... | @@ -287,17 +287,20 @@ void GCOMEventBin::copy_members(const GCOMEventBin& bin) |
| 287 | 287 | // First de-allocate existing memory if needed |
| 288 | 288 | free_members(); |
| 289 | 289 | |
| 290 | - | |
| 291 | 290 | // Copy members by cloning |
| 292 | - m_alloc = true; | |
| 293 | - m_index = bin.m_index; | |
| 294 | - m_counts = new double(*bin.m_counts); | |
| 295 | 291 | m_dir = new GCOMInstDir(*bin.m_dir); |
| 296 | - m_solidangle = new double(*bin.m_solidangle); | |
| 297 | 292 | m_time = new GTime(*bin.m_time); |
| 298 | - m_ontime = new double(*bin.m_ontime); | |
| 299 | 293 | m_energy = new GEnergy(*bin.m_energy); |
| 300 | 294 | m_ewidth = new GEnergy(*bin.m_ewidth); |
| 295 | + m_counts = new double(*bin.m_counts); | |
| 296 | + m_solidangle = new double(*bin.m_solidangle); | |
| 297 | + m_ontime = new double(*bin.m_ontime); | |
| 298 | + | |
| 299 | + // Copy non-pointer members | |
| 300 | + m_index = bin.m_index; | |
| 301 | + | |
| 302 | + // Signal memory allocation | |
| 303 | + m_alloc = true; | |
| 301 | 304 | |
| 302 | 305 | // Return |
| 303 | 306 | return; |
| ... | ... | @@ -321,24 +324,26 @@ void GCOMEventBin::free_members(void) |
| 321 | 324 | { |
| 322 | 325 | // If memory was allocated then free members now |
| 323 | 326 | if (m_alloc) { |
| 324 | - if (m_counts != NULL) delete m_counts; | |
| 325 | 327 | if (m_dir != NULL) delete m_dir; |
| 326 | - if (m_solidangle != NULL) delete m_solidangle; | |
| 327 | 328 | if (m_time != NULL) delete m_time; |
| 328 | - if (m_ontime != NULL) delete m_ontime; | |
| 329 | 329 | if (m_energy != NULL) delete m_energy; |
| 330 | 330 | if (m_ewidth != NULL) delete m_ewidth; |
| 331 | + if (m_counts != NULL) delete m_counts; | |
| 332 | + if (m_solidangle != NULL) delete m_solidangle; | |
| 333 | + if (m_ontime != NULL) delete m_ontime; | |
| 331 | 334 | } |
| 332 | 335 | |
| 333 | 336 | // Signal member pointers as free |
| 334 | - m_alloc = false; | |
| 335 | - m_counts = NULL; | |
| 336 | 337 | m_dir = NULL; |
| 337 | - m_solidangle = NULL; | |
| 338 | 338 | m_time = NULL; |
| 339 | - m_ontime = NULL; | |
| 340 | 339 | m_energy = NULL; |
| 341 | 340 | m_ewidth = NULL; |
| 341 | + m_counts = NULL; | |
| 342 | + m_solidangle = NULL; | |
| 343 | + m_ontime = NULL; | |
| 344 | + | |
| 345 | + // Signal memory de-allocation | |
| 346 | + m_alloc = false; | |
| 342 | 347 | |
| 343 | 348 | // Return |
| 344 | 349 | return; | ... | ... |
inst/com/src/GCOMEventCube.cpp
| ... | ... | @@ -647,7 +647,10 @@ void GCOMEventCube::init_members(void) |
| 647 | 647 | ***************************************************************************/ |
| 648 | 648 | void GCOMEventCube::copy_members(const GCOMEventCube& cube) |
| 649 | 649 | { |
| 650 | - // Copy members | |
| 650 | + // Copy members. Note that the event bin is not copied as it will | |
| 651 | + // be initialised later. The event bin serves just as a container of | |
| 652 | + // pointers, hence we do not want to copy over the pointers from the | |
| 653 | + // original class. | |
| 651 | 654 | m_dir = cube.m_dir; |
| 652 | 655 | m_map = cube.m_map; |
| 653 | 656 | m_time = cube.m_time; | ... | ... |
inst/com/test/test_COM.cpp
| ... | ... | @@ -59,8 +59,10 @@ void TestGCOMResponse::set(void) |
| 59 | 59 | name("GCOMResponse"); |
| 60 | 60 | |
| 61 | 61 | // Append tests to test suite |
| 62 | - append(static_cast<pfunction>(&TestGCOMResponse::test_inst_dir), "Test instrument direction"); | |
| 63 | - append(static_cast<pfunction>(&TestGCOMResponse::test_response), "Test response"); | |
| 62 | + append(static_cast<pfunction>(&TestGCOMResponse::test_inst_dir), | |
| 63 | + "Test instrument direction"); | |
| 64 | + append(static_cast<pfunction>(&TestGCOMResponse::test_response), | |
| 65 | + "Test response"); | |
| 64 | 66 | |
| 65 | 67 | // Return |
| 66 | 68 | return; |
| ... | ... | @@ -88,9 +90,12 @@ void TestGCOMObservation::set(void) |
| 88 | 90 | name("GCOMObservation"); |
| 89 | 91 | |
| 90 | 92 | // Append tests to test suite |
| 91 | - append(static_cast<pfunction>(&TestGCOMObservation::test_binned_obs), "Test binned observation"); | |
| 92 | - append(static_cast<pfunction>(&TestGCOMObservation::test_event_bin), "Test event bin"); | |
| 93 | - append(static_cast<pfunction>(&TestGCOMObservation::test_event_cube), "Test event cube"); | |
| 93 | + append(static_cast<pfunction>(&TestGCOMObservation::test_binned_obs), | |
| 94 | + "Test binned observation"); | |
| 95 | + append(static_cast<pfunction>(&TestGCOMObservation::test_event_bin), | |
| 96 | + "Test event bin"); | |
| 97 | + append(static_cast<pfunction>(&TestGCOMObservation::test_event_cube), | |
| 98 | + "Test event cube"); | |
| 94 | 99 | |
| 95 | 100 | // Return |
| 96 | 101 | return; |
| ... | ... | @@ -118,7 +123,8 @@ void TestGCOMOptimize::set(void) |
| 118 | 123 | name("COMPTEL optimizers"); |
| 119 | 124 | |
| 120 | 125 | // Append tests to test suite |
| 121 | - append(static_cast<pfunction>(&TestGCOMOptimize::test_binned_optimizer), "Test binned optimizer"); | |
| 126 | + append(static_cast<pfunction>(&TestGCOMOptimize::test_binned_optimizer), | |
| 127 | + "Test binned optimizer"); | |
| 122 | 128 | |
| 123 | 129 | // Return |
| 124 | 130 | return; |
| ... | ... | @@ -314,73 +320,140 @@ void TestGCOMObservation::test_binned_obs(void) |
| 314 | 320 | ***************************************************************************/ |
| 315 | 321 | void TestGCOMObservation::test_event_bin(void) |
| 316 | 322 | { |
| 317 | - // Test COMPTEL event bin methods (one by one) | |
| 318 | - test_try("Test event bin methods"); | |
| 319 | - try { | |
| 320 | - // Event bin void constructor | |
| 321 | - GCOMEventBin bin; | |
| 322 | - | |
| 323 | - // Copy constructor | |
| 324 | - GCOMEventBin bin2(bin); | |
| 325 | - | |
| 326 | - // Assignment operator | |
| 327 | - GCOMEventBin bin3 = bin; | |
| 328 | - | |
| 329 | - // clear method | |
| 330 | - bin.clear(); | |
| 331 | - | |
| 332 | - // clone method | |
| 333 | - GCOMEventBin* bin4 = bin.clone(); | |
| 334 | - | |
| 335 | - // size method | |
| 336 | - test_value(bin.size(), 0.0, 1.0e-10, "Test size() method."); | |
| 337 | - test_value(bin4->size(), 0.0, 1.0e-10, "Test size() method."); | |
| 338 | - delete bin4; | |
| 339 | - | |
| 340 | - // dir method | |
| 341 | - GCOMInstDir dir = bin.dir(); | |
| 342 | - | |
| 343 | - // energy method | |
| 344 | - GEnergy energy = bin.energy(); | |
| 345 | - | |
| 346 | - // time method | |
| 347 | - GTime time = bin.time(); | |
| 348 | - | |
| 349 | - // counts method | |
| 350 | - test_value(bin.counts(), 0.0, 1.0e-10, "Test counts() method for zero counts."); | |
| 351 | - | |
| 352 | - // error method | |
| 353 | - test_value(bin.error(), 0.0, 1.0e-10, "Test error() method for zero counts."); | |
| 354 | - | |
| 355 | - // counts setting | |
| 356 | - bin.counts(1.0); | |
| 357 | - test_value(bin.counts(), 1.0, 1.0e-10, "Test counts() method for one count."); | |
| 358 | - test_value(bin.error(), 1.0, 1.0e-10, "Test error() method for one count."); | |
| 359 | - | |
| 360 | - // print method | |
| 361 | - std::string text = bin.print(); | |
| 362 | - test_assert(text == "1", "Test print() method."); | |
| 363 | - | |
| 364 | - // solidangle method | |
| 365 | - test_value(bin.solidangle(), 0.0, 1.0e-10, "Test solidangle() method."); | |
| 366 | - | |
| 367 | - // ewidth method | |
| 368 | - GEnergy ewidth = bin.ewidth(); | |
| 369 | - | |
| 370 | - // ontime method | |
| 371 | - test_value(bin.ontime(), 0.0, 1.0e-10, "Test ontime() method."); | |
| 323 | + // Test event bin void constructor | |
| 324 | + GCOMEventBin bin; | |
| 325 | + test_value(bin.classname(), "GCOMEventBin", "Check classname() for empty bin"); | |
| 326 | + test_value(bin.size(), 0.0, 1.0e-10, "Check size() for empty bin"); | |
| 327 | + test_value(bin.dir().dir().ra_deg(), 0.0, 1.0e-10, | |
| 328 | + "Check dir().dir().ra_deg() for empty bin"); | |
| 329 | + test_value(bin.dir().dir().dec_deg(), 0.0, 1.0e-10, | |
| 330 | + "Check dir().dir().dec_deg() for empty bin"); | |
| 331 | + test_value(bin.dir().phibar(), 0.0, 1.0e-10, | |
| 332 | + "Check dir().phibar() for empty bin"); | |
| 333 | + test_value(bin.energy().MeV(), 0.0, 1.0e-10, "Check energy() for empty bin"); | |
| 334 | + test_value(bin.time().secs(), 0.0, 1.0e-10, "Check time() for empty bin"); | |
| 335 | + test_value(bin.counts(), 0.0, 1.0e-10, "Check counts() for empty bin"); | |
| 336 | + test_value(bin.error(), 0.0, 1.0e-10, "Check error() for empty bin"); | |
| 337 | + test_value(bin.index(), -1, "Check index() for empty bin"); | |
| 338 | + test_value(bin.solidangle(), 0.0, 1.0e-10, "Check solidangle() for empty bin"); | |
| 339 | + test_value(bin.ewidth().MeV(), 0.0, 1.0e-10, "Check ewidth() for empty bin"); | |
| 340 | + test_value(bin.ontime(), 0.0, 1.0e-10, "Check ontime() for empty bin"); | |
| 341 | + test_value(bin.print(), "0", "Check print() for empty bin"); | |
| 342 | + | |
| 343 | + // Test setting of bin attributes (for the moment we can only set the | |
| 344 | + // number of counts, but this should change in the future) | |
| 345 | + bin.counts(4.0); | |
| 346 | + test_value(bin.size(), 0.0, 1.0e-10, "Check size() for filled bin"); | |
| 347 | + test_value(bin.dir().dir().ra_deg(), 0.0, 1.0e-10, | |
| 348 | + "Check dir().dir().ra_deg() for filled bin"); | |
| 349 | + test_value(bin.dir().dir().dec_deg(), 0.0, 1.0e-10, | |
| 350 | + "Check dir().dir().dec_deg() for filled bin"); | |
| 351 | + test_value(bin.dir().phibar(), 0.0, 1.0e-10, | |
| 352 | + "Check dir().phibar() for filled bin"); | |
| 353 | + test_value(bin.energy().MeV(), 0.0, 1.0e-10, | |
| 354 | + "Check energy() for filled bin"); | |
| 355 | + test_value(bin.time().secs(), 0.0, 1.0e-10, "Check time() for filled bin"); | |
| 356 | + test_value(bin.counts(), 4.0, 1.0e-10, "Check counts() for filled bin"); | |
| 357 | + test_value(bin.error(), 2.0, 1.0e-10, "Check error() for filled bin"); | |
| 358 | + test_value(bin.index(), -1, "Check index() for filled bin"); | |
| 359 | + test_value(bin.solidangle(), 0.0, 1.0e-10, | |
| 360 | + "Check solidangle() for filled bin"); | |
| 361 | + test_value(bin.ewidth().MeV(), 0.0, 1.0e-10, | |
| 362 | + "Check ewidth() for filled bin"); | |
| 363 | + test_value(bin.ontime(), 0.0, 1.0e-10, "Check ontime() for filled bin"); | |
| 364 | + test_value(bin.print(), "4", "Check print() for filled bin"); | |
| 365 | + | |
| 366 | + // Test copy constructor | |
| 367 | + GCOMEventBin bin2(bin); | |
| 368 | + test_value(bin2.size(), 0.0, 1.0e-10, "Check size() for copied bin"); | |
| 369 | + test_value(bin2.dir().dir().ra_deg(), 0.0, 1.0e-10, | |
| 370 | + "Check dir().dir().ra_deg() for copied bin"); | |
| 371 | + test_value(bin2.dir().dir().dec_deg(), 0.0, 1.0e-10, | |
| 372 | + "Check dir().dir().dec_deg() for copied bin"); | |
| 373 | + test_value(bin2.dir().phibar(), 0.0, 1.0e-10, | |
| 374 | + "Check dir().phibar() for copied bin"); | |
| 375 | + test_value(bin2.energy().MeV(), 0.0, 1.0e-10, | |
| 376 | + "Check energy() for copied bin"); | |
| 377 | + test_value(bin2.time().secs(), 0.0, 1.0e-10, "Check time() for copied bin"); | |
| 378 | + test_value(bin2.counts(), 4.0, 1.0e-10, "Check counts() for copied bin"); | |
| 379 | + test_value(bin2.error(), 2.0, 1.0e-10, "Check error() for copied bin"); | |
| 380 | + test_value(bin2.index(), -1, "Check index() for copied bin"); | |
| 381 | + test_value(bin2.solidangle(), 0.0, 1.0e-10, | |
| 382 | + "Check solidangle() for copied bin"); | |
| 383 | + test_value(bin2.ewidth().MeV(), 0.0, 1.0e-10, | |
| 384 | + "Check ewidth() for copied bin"); | |
| 385 | + test_value(bin2.ontime(), 0.0, 1.0e-10, "Check ontime() for copied bin"); | |
| 386 | + test_value(bin2.print(), "4", "Check print() for copied bin"); | |
| 387 | + | |
| 388 | + // Assignment operator | |
| 389 | + GCOMEventBin bin3 = bin; | |
| 390 | + test_value(bin3.size(), 0.0, 1.0e-10, "Check size() for assigned bin"); | |
| 391 | + test_value(bin3.dir().dir().ra_deg(), 0.0, 1.0e-10, | |
| 392 | + "Check dir().dir().ra_deg() for assigned bin"); | |
| 393 | + test_value(bin3.dir().dir().dec_deg(), 0.0, 1.0e-10, | |
| 394 | + "Check dir().dir().dec_deg() for assigned bin"); | |
| 395 | + test_value(bin3.dir().phibar(), 0.0, 1.0e-10, | |
| 396 | + "Check dir().phibar() for assigned bin"); | |
| 397 | + test_value(bin3.energy().MeV(), 0.0, 1.0e-10, | |
| 398 | + "Check energy() for assigned bin"); | |
| 399 | + test_value(bin3.time().secs(), 0.0, 1.0e-10, | |
| 400 | + "Check time() for assigned bin"); | |
| 401 | + test_value(bin3.counts(), 4.0, 1.0e-10, "Check counts() for assigned bin"); | |
| 402 | + test_value(bin3.error(), 2.0, 1.0e-10, "Check error() for assigned bin"); | |
| 403 | + test_value(bin3.index(), -1, "Check index() for assigned bin"); | |
| 404 | + test_value(bin3.solidangle(), 0.0, 1.0e-10, | |
| 405 | + "Check solidangle() for assigned bin"); | |
| 406 | + test_value(bin3.ewidth().MeV(), 0.0, 1.0e-10, | |
| 407 | + "Check ewidth() for assigned bin"); | |
| 408 | + test_value(bin3.ontime(), 0.0, 1.0e-10, "Check ontime() for assigned bin"); | |
| 409 | + test_value(bin3.print(), "4", "Check print() for assigned bin"); | |
| 372 | 410 | |
| 373 | - // If we arrived here, signal success | |
| 374 | - test_try_success(); | |
| 375 | - } | |
| 376 | - catch (std::exception &e) { | |
| 377 | - test_try_failure(e); | |
| 378 | - } | |
| 411 | + // clone method | |
| 412 | + GCOMEventBin* bin4 = bin.clone(); | |
| 413 | + test_value(bin4->size(), 0.0, 1.0e-10, "Check size() for cloned bin"); | |
| 414 | + test_value(bin4->dir().dir().ra_deg(), 0.0, 1.0e-10, | |
| 415 | + "Check dir().dir().ra_deg() for cloned bin"); | |
| 416 | + test_value(bin4->dir().dir().dec_deg(), 0.0, 1.0e-10, | |
| 417 | + "Check dir().dir().dec_deg() for cloned bin"); | |
| 418 | + test_value(bin4->dir().phibar(), 0.0, 1.0e-10, | |
| 419 | + "Check dir().phibar() for cloned bin"); | |
| 420 | + test_value(bin4->energy().MeV(), 0.0, 1.0e-10, | |
| 421 | + "Check energy() for cloned bin"); | |
| 422 | + test_value(bin4->time().secs(), 0.0, 1.0e-10, | |
| 423 | + "Check time() for cloned bin"); | |
| 424 | + test_value(bin4->counts(), 4.0, 1.0e-10, "Check counts() for cloned bin"); | |
| 425 | + test_value(bin4->error(), 2.0, 1.0e-10, "Check error() for cloned bin"); | |
| 426 | + test_value(bin4->index(), -1, "Check index() for cloned bin"); | |
| 427 | + test_value(bin4->solidangle(), 0.0, 1.0e-10, | |
| 428 | + "Check solidangle() for cloned bin"); | |
| 429 | + test_value(bin4->ewidth().MeV(), 0.0, 1.0e-10, | |
| 430 | + "Check ewidth() for cloned bin"); | |
| 431 | + test_value(bin4->ontime(), 0.0, 1.0e-10, "Check ontime() for cloned bin"); | |
| 432 | + test_value(bin4->print(), "4", "Check print() for cloned bin"); | |
| 379 | 433 | |
| 380 | - // Test COMPTEL event bin operations | |
| 381 | - GCOMEventBin bin; | |
| 382 | - bin.counts(3.3); | |
| 383 | - test_value(bin.counts(), 3.3, 1.0e-10, "Test counts() method for 3.3 counts."); | |
| 434 | + // clear method | |
| 435 | + bin.clear(); | |
| 436 | + test_value(bin.classname(), "GCOMEventBin", | |
| 437 | + "Check classname() for cleared bin"); | |
| 438 | + test_value(bin.size(), 0.0, 1.0e-10, "Check size() for cleared bin"); | |
| 439 | + test_value(bin.dir().dir().ra_deg(), 0.0, 1.0e-10, | |
| 440 | + "Check dir().dir().ra_deg() for cleared bin"); | |
| 441 | + test_value(bin.dir().dir().dec_deg(), 0.0, 1.0e-10, | |
| 442 | + "Check dir().dir().dec_deg() for cleared bin"); | |
| 443 | + test_value(bin.dir().phibar(), 0.0, 1.0e-10, | |
| 444 | + "Check dir().phibar() for cleared bin"); | |
| 445 | + test_value(bin.energy().MeV(), 0.0, 1.0e-10, | |
| 446 | + "Check energy() for cleared bin"); | |
| 447 | + test_value(bin.time().secs(), 0.0, 1.0e-10, "Check time() for cleared bin"); | |
| 448 | + test_value(bin.counts(), 0.0, 1.0e-10, "Check counts() for cleared bin"); | |
| 449 | + test_value(bin.error(), 0.0, 1.0e-10, "Check error() for cleared bin"); | |
| 450 | + test_value(bin.index(), -1, "Check index() for cleared bin"); | |
| 451 | + test_value(bin.solidangle(), 0.0, 1.0e-10, | |
| 452 | + "Check solidangle() for cleared bin"); | |
| 453 | + test_value(bin.ewidth().MeV(), 0.0, 1.0e-10, | |
| 454 | + "Check ewidth() for cleared bin"); | |
| 455 | + test_value(bin.ontime(), 0.0, 1.0e-10, "Check ontime() for cleared bin"); | |
| 456 | + test_value(bin.print(), "0", "Check print() for cleared bin"); | |
| 384 | 457 | |
| 385 | 458 | // Return |
| 386 | 459 | return; | ... | ... |