Commit 86b320561c95562ecbacef5cbc8353efa92c9f57
Merge branch '1513-bining-tools-consider-ebounds' into integration
Showing
7 changed files
with
76 additions
and
5 deletions
include/GEbounds.hpp
| ... | ... | @@ -103,6 +103,7 @@ public: |
| 103 | 103 | GEnergy elogmean(const int& index) const; |
| 104 | 104 | GEnergy ewidth(const int& index) const; |
| 105 | 105 | bool contains(const GEnergy& eng) const; |
| 106 | + bool contains(const GEnergy& emin, const GEnergy& emax) const; | |
| 106 | 107 | std::string print(const GChatter& chatter = NORMAL) const; |
| 107 | 108 | |
| 108 | 109 | ... | ... |
inst/cta/src/GCTACubeBackground.cpp
| ... | ... | @@ -327,6 +327,9 @@ void GCTACubeBackground::fill(const GObservations& obs, GLog* log) |
| 327 | 327 | // Extract region of interest from CTA observation |
| 328 | 328 | GCTARoi roi = cta->roi(); |
| 329 | 329 | |
| 330 | + // Extract energy boundaries from CTA observation | |
| 331 | + GEbounds obs_ebounds = cta->ebounds(); | |
| 332 | + | |
| 330 | 333 | // Check for RoI sanity |
| 331 | 334 | if (!roi.is_valid()) { |
| 332 | 335 | std::string msg = "No RoI information found in input observation " |
| ... | ... | @@ -347,6 +350,15 @@ void GCTACubeBackground::fill(const GObservations& obs, GLog* log) |
| 347 | 350 | // Get event bin |
| 348 | 351 | GCTAEventBin* bin = eventcube[i]; |
| 349 | 352 | |
| 353 | + // Determine energy bin index. Skip if bin is not fully contained | |
| 354 | + // within the energy boundaries of the observation | |
| 355 | + int index = m_ebounds.index(bin->energy()); | |
| 356 | + if (index == -1 || | |
| 357 | + !obs_ebounds.contains(m_ebounds.emin(index), | |
| 358 | + m_ebounds.emax(index))) { | |
| 359 | + continue; | |
| 360 | + } | |
| 361 | + | |
| 350 | 362 | // Continue only if binned in contained in ROI |
| 351 | 363 | if (roi.contains(*bin)) { |
| 352 | 364 | ... | ... |
inst/cta/src/GCTACubeExposure.cpp
| ... | ... | @@ -423,6 +423,9 @@ void GCTACubeExposure::fill(const GObservations& obs, GLog* log) |
| 423 | 423 | // Extract region of interest from CTA observation |
| 424 | 424 | GCTARoi roi = cta->roi(); |
| 425 | 425 | |
| 426 | + // Extract energy boundaries from CTA observation | |
| 427 | + GEbounds obs_ebounds = cta->ebounds(); | |
| 428 | + | |
| 426 | 429 | // Check for RoI sanity |
| 427 | 430 | if (!roi.is_valid()) { |
| 428 | 431 | std::string msg = "No RoI information found in input observation " |
| ... | ... | @@ -473,12 +476,19 @@ void GCTACubeExposure::fill(const GObservations& obs, GLog* log) |
| 473 | 476 | // Loop over all exposure cube energy bins |
| 474 | 477 | for (int iebin = 0; iebin < m_ebounds.size(); ++iebin){ |
| 475 | 478 | |
| 476 | - // Get logE/TeV | |
| 477 | - double logE = m_ebounds.elogmean(iebin).log10TeV(); | |
| 479 | + // Only add exposure to pixel if energy bin is inside | |
| 480 | + // observation energy boundaries | |
| 481 | + if (obs_ebounds.contains(m_ebounds.emin(iebin), | |
| 482 | + m_ebounds.emax(iebin))) { | |
| 483 | + | |
| 484 | + // Get logE/TeV | |
| 485 | + double logE = m_ebounds.elogmean(iebin).log10TeV(); | |
| 486 | + | |
| 487 | + // Add to exposure cube (effective area * livetime) | |
| 488 | + m_cube(pixel, iebin) += rsp->aeff(theta, 0.0, 0.0, 0.0, logE) * | |
| 489 | + cta->livetime(); | |
| 478 | 490 | |
| 479 | - // Add to exposure cube (effective area * livetime) | |
| 480 | - m_cube(pixel, iebin) += rsp->aeff(theta, 0.0, 0.0, 0.0, logE) * | |
| 481 | - cta->livetime(); | |
| 491 | + } // endif: energy bin was inside observation energy boundaries | |
| 482 | 492 | |
| 483 | 493 | } // endfor: looped over energy bins |
| 484 | 494 | ... | ... |
inst/cta/src/GCTACubePsf.cpp
| ... | ... | @@ -487,6 +487,9 @@ void GCTACubePsf::fill(const GObservations& obs, GLog* log) |
| 487 | 487 | // Extract region of interest from CTA observation |
| 488 | 488 | GCTARoi roi = cta->roi(); |
| 489 | 489 | |
| 490 | + // Extract energy boundaries from CTA observation | |
| 491 | + GEbounds obs_ebounds = cta->ebounds(); | |
| 492 | + | |
| 490 | 493 | // Check for RoI sanity |
| 491 | 494 | if (!roi.is_valid()) { |
| 492 | 495 | std::string msg = "No RoI information found in input observation " |
| ... | ... | @@ -537,6 +540,12 @@ void GCTACubePsf::fill(const GObservations& obs, GLog* log) |
| 537 | 540 | // Loop over all energy bins |
| 538 | 541 | for (int iebin = 0; iebin < m_ebounds.size(); ++iebin) { |
| 539 | 542 | |
| 543 | + // Skip if pixel is not within observation energy boundaries | |
| 544 | + if (!obs_ebounds.contains(m_ebounds.emin(iebin), | |
| 545 | + m_ebounds.emax(iebin))) { | |
| 546 | + continue; | |
| 547 | + } | |
| 548 | + | |
| 540 | 549 | // Get logE/TeV |
| 541 | 550 | double logE = m_ebounds.elogmean(iebin).log10TeV(); |
| 542 | 551 | ... | ... |
pyext/GEbounds.i
src/obs/GEbounds.cpp
| ... | ... | @@ -995,6 +995,34 @@ bool GEbounds::contains(const GEnergy& eng) const |
| 995 | 995 | |
| 996 | 996 | |
| 997 | 997 | /***********************************************************************//** |
| 998 | + * @brief Checks whether energy boundaries contain and energy bin | |
| 999 | + * | |
| 1000 | + * @param[in] emin Minimum energy of bin to be checked. | |
| 1001 | + * @param[in] emax Maximum energy of bin to be checked. | |
| 1002 | + * @return True if energy bin [emin, emax] is fully contained inside energy | |
| 1003 | + * the boundaries, false otherwiese | |
| 1004 | + * | |
| 1005 | + * Checks if the energy interval [@p emin, @p emax ] falls is fully contained | |
| 1006 | + * by energy boundaries | |
| 1007 | + * | |
| 1008 | + * @todo This method is so far only correct for contiguous energy boundaries. | |
| 1009 | + ***************************************************************************/ | |
| 1010 | +bool GEbounds::contains(const GEnergy& emin, const GEnergy& emax) const | |
| 1011 | +{ | |
| 1012 | + // Initialise result | |
| 1013 | + bool contained = false; | |
| 1014 | + | |
| 1015 | + // Check if emin, emax is fully contained within this ebounds | |
| 1016 | + if (emin >= m_emin && emax <= m_emax) { | |
| 1017 | + contained = true; | |
| 1018 | + } | |
| 1019 | + | |
| 1020 | + // Return result | |
| 1021 | + return contained; | |
| 1022 | +} | |
| 1023 | + | |
| 1024 | + | |
| 1025 | +/***********************************************************************//** | |
| 998 | 1026 | * @brief Print energy boundaries |
| 999 | 1027 | * |
| 1000 | 1028 | * @param[in] chatter Chattiness (defaults to NORMAL). | ... | ... |
test/test_GObservation.cpp
| ... | ... | @@ -242,6 +242,16 @@ void TestGObservation::test_ebounds(void) |
| 242 | 242 | test_try_failure(e); |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | + // Check energy containment | |
| 246 | + GEbounds containment(1, GEnergy(100.0, "MeV"), GEnergy(1000.0, "MeV")); | |
| 247 | + test_assert(containment.contains(GEnergy(200.0, "MeV")), "Energy 200 MeV should be contained."); | |
| 248 | + test_assert(!containment.contains(GEnergy(10.0, "MeV")), "Energy 10 MeV should not be contained."); | |
| 249 | + test_assert(!containment.contains(GEnergy(2000.0, "MeV")), "Energy 2000 MeV should not be contained."); | |
| 250 | + test_assert(containment.contains(GEnergy(200.0, "MeV"), GEnergy(800.0, "MeV")), "Energy bin [200,800] MeV should be contained."); | |
| 251 | + test_assert(!containment.contains(GEnergy(80.0, "MeV"), GEnergy(800.0, "MeV")), "Energy bin [80,800] MeV should not be contained."); | |
| 252 | + test_assert(!containment.contains(GEnergy(200.0, "MeV"), GEnergy(2000.0, "MeV")), "Energy bin [200,2000] MeV should not be contained."); | |
| 253 | + test_assert(!containment.contains(GEnergy(80.0, "MeV"), GEnergy(2000.0, "MeV")), "Energy bin [80,2000] MeV should not be contained."); | |
| 254 | + | |
| 245 | 255 | // Return |
| 246 | 256 | return; |
| 247 | 257 | } | ... | ... |