Commit b457936ca8c03130e01da6e13637d231db42eeaf
1 parent
6173b98f
Use methods instead of cached variables in several places (similar to what is done in disk model).
Showing
2 changed files
with
9 additions
and
22 deletions
src/model/GModelSpatialRadialRing.cpp
| ... | ... | @@ -344,12 +344,9 @@ GSkyDir GModelSpatialRadialRing::mc(const GEnergy& energy, |
| 344 | 344 | const GTime& time, |
| 345 | 345 | GRan& ran) const |
| 346 | 346 | { |
| 347 | - // Update precomputation cache | |
| 348 | - update(); | |
| 349 | - | |
| 350 | 347 | // Simulate offset from photon arrival direction |
| 351 | - double cosirad = std::cos(m_inner_radius_rad); | |
| 352 | - double cosorad = std::cos(m_outer_radius_rad); | |
| 348 | + double cosirad = std::cos((radius()-width()) * gammalib::deg2rad); | |
| 349 | + double cosorad = std::cos(radius() * gammalib::deg2rad); | |
| 353 | 350 | double theta = std::acos(cosirad - ran.uniform() * (cosirad - cosorad)) * |
| 354 | 351 | gammalib::rad2deg; |
| 355 | 352 | double phi = 360.0 * ran.uniform(); |
| ... | ... | @@ -375,19 +372,12 @@ GSkyDir GModelSpatialRadialRing::mc(const GEnergy& energy, |
| 375 | 372 | bool GModelSpatialRadialRing::contains(const GSkyDir& dir, |
| 376 | 373 | const double& margin) const |
| 377 | 374 | { |
| 378 | - // Update precomputation cache | |
| 379 | - update(); | |
| 380 | - | |
| 381 | 375 | // Compute distance to centre (radians) |
| 382 | 376 | double distance = dir.dist(this->dir()); |
| 383 | 377 | |
| 384 | - // Set flag | |
| 385 | - bool flag; | |
| 386 | - flag = (distance <= m_outer_radius_rad + margin*gammalib::deg2rad) | |
| 387 | - *(distance >= m_inner_radius_rad - margin*gammalib::deg2rad); | |
| 388 | - | |
| 389 | 378 | // Return flag |
| 390 | - return flag; | |
| 379 | + return (distance <= theta_max() + margin*gammalib::deg2rad) | |
| 380 | + *(distance >= theta_min() - margin*gammalib::deg2rad);; | |
| 391 | 381 | } |
| 392 | 382 | |
| 393 | 383 | |
| ... | ... | @@ -399,7 +389,7 @@ bool GModelSpatialRadialRing::contains(const GSkyDir& dir, |
| 399 | 389 | double GModelSpatialRadialRing::theta_max(void) const |
| 400 | 390 | { |
| 401 | 391 | // Return value |
| 402 | - return m_outer_radius_rad; | |
| 392 | + return (radius() * gammalib::deg2rad); | |
| 403 | 393 | } |
| 404 | 394 | |
| 405 | 395 | |
| ... | ... | @@ -411,7 +401,7 @@ double GModelSpatialRadialRing::theta_max(void) const |
| 411 | 401 | double GModelSpatialRadialRing::theta_min(void) const |
| 412 | 402 | { |
| 413 | 403 | // Return value |
| 414 | - return m_inner_radius_rad; | |
| 404 | + return ((radius()-width()) * gammalib::deg2rad); | |
| 415 | 405 | } |
| 416 | 406 | |
| 417 | 407 | /***********************************************************************//** |
| ... | ... | @@ -673,9 +663,6 @@ void GModelSpatialRadialRing::update() const |
| 673 | 663 | |
| 674 | 664 | } // endif: update required |
| 675 | 665 | |
| 676 | - // Also update region | |
| 677 | - set_region(); | |
| 678 | - | |
| 679 | 666 | // Return |
| 680 | 667 | return; |
| 681 | 668 | } | ... | ... |
test/test_GModel.cpp
| ... | ... | @@ -981,8 +981,8 @@ void TestGModel::test_radial_ring(void) |
| 981 | 981 | test_assert(model3.dir() == dir2, "Test sky direction"); |
| 982 | 982 | |
| 983 | 983 | // Test radius method |
| 984 | - model3.radius(1.0); | |
| 985 | - test_value(model3.radius(), 1.0); | |
| 984 | + model3.radius(2.0); | |
| 985 | + test_value(model3.radius(), 2.0); | |
| 986 | 986 | |
| 987 | 987 | // Test width method |
| 988 | 988 | model3.width(0.5); |
| ... | ... | @@ -996,7 +996,7 @@ void TestGModel::test_radial_ring(void) |
| 996 | 996 | test_assert(!model3.region()->contains(dir3), "Test region() method (outside)"); |
| 997 | 997 | |
| 998 | 998 | // Test contains method |
| 999 | - dir3.radec_deg(83.6331, +22.75); | |
| 999 | + dir3.radec_deg(83.6331, +23.75); | |
| 1000 | 1000 | test_assert(model3.contains(dir3), "Test contains() method (inside)"); |
| 1001 | 1001 | dir3.radec_deg(83.6331, +22.0145); |
| 1002 | 1002 | test_assert(!model3.contains(dir3), "Test contains() method (outside interior of ring)"); | ... | ... |