Commit 03c28a611cbd1c2bde895480c9eba616bdaad294
1 parent
2b19e9e7
Corrected GCTAEdisp2D methods
Tested Edisp2D and EdispPerfTable methods
Showing
3 changed files
with
208 additions
and
125 deletions
inst/cta/include/GCTAEdisp2D.hpp
| @@ -100,15 +100,6 @@ private: | @@ -100,15 +100,6 @@ private: | ||
| 100 | // Members | 100 | // Members |
| 101 | std::string m_filename; //!< Name of Edisp response file | 101 | std::string m_filename; //!< Name of Edisp response file |
| 102 | GCTAResponseTable m_edisp; //!< Edisp response table | 102 | GCTAResponseTable m_edisp; //!< Edisp response table |
| 103 | - | ||
| 104 | - // Precomputation cache | ||
| 105 | - mutable double m_par_logEobs; | ||
| 106 | - mutable double m_par_logEsrc; | ||
| 107 | - mutable double m_par_theta; | ||
| 108 | - mutable double m_norm; | ||
| 109 | - mutable double m_EobsOnEsrc; //!< linear ratio Eobs/Esrc | ||
| 110 | - mutable double m_eres; | ||
| 111 | - mutable double m_ebias; | ||
| 112 | }; | 103 | }; |
| 113 | 104 | ||
| 114 | /***********************************************************************//** | 105 | /***********************************************************************//** |
inst/cta/src/GCTAEdisp2D.cpp
| @@ -178,7 +178,8 @@ double GCTAEdisp2D::operator()(const double& logEobs, | @@ -178,7 +178,8 @@ double GCTAEdisp2D::operator()(const double& logEobs, | ||
| 178 | double edisp = 0.0; | 178 | double edisp = 0.0; |
| 179 | 179 | ||
| 180 | // Compute edisp | 180 | // Compute edisp |
| 181 | - edisp = m_edisp(0, logEsrc, Eobs / Esrc, theta); | 181 | + edisp = m_edisp(0, logEsrc, std::exp((logEobs-logEsrc)*std::log(10.0)), theta); |
| 182 | + | ||
| 182 | 183 | ||
| 183 | // Return | 184 | // Return |
| 184 | return edisp; | 185 | return edisp; |
| @@ -335,19 +336,20 @@ void GCTAEdisp2D::read(const GFits& fits) | @@ -335,19 +336,20 @@ void GCTAEdisp2D::read(const GFits& fits) | ||
| 335 | 336 | ||
| 336 | // Normalize vectors of migration matrix for all etrue and theta | 337 | // Normalize vectors of migration matrix for all etrue and theta |
| 337 | for (int i_etrue = 0; i_etrue < etrue_size; ++i_etrue) { | 338 | for (int i_etrue = 0; i_etrue < etrue_size; ++i_etrue) { |
| 338 | - double EobsOnEtrue = 0.5 * (m_edisp.axis_hi(1, i_etrue) + m_edisp.axis_lo(1, i_etrue)); | ||
| 339 | for (int i_theta = 0; i_theta < theta_size; ++i_theta) { | 339 | for (int i_theta = 0; i_theta < theta_size; ++i_theta) { |
| 340 | // Compute sum | 340 | // Compute sum |
| 341 | double sum = 0.0; | 341 | double sum = 0.0; |
| 342 | for (int i_migra = 0; i_migra < migra_size; ++i_migra) { | 342 | for (int i_migra = 0; i_migra < migra_size; ++i_migra) { |
| 343 | - // Compute delta(Eobs/Etrue) | 343 | + // Compute delta(Eobs/Etrue) and Eobs/Etrue |
| 344 | double delta = m_edisp.axis_hi(1, i_migra) - m_edisp.axis_lo(1, i_migra); | 344 | double delta = m_edisp.axis_hi(1, i_migra) - m_edisp.axis_lo(1, i_migra); |
| 345 | + double EobsOnEtrue = 0.5 * (m_edisp.axis_hi(1, i_migra) + m_edisp.axis_lo(1, i_migra)); | ||
| 346 | + // Add dispersion to sum | ||
| 345 | sum += m_edisp(0, i_etrue + (i_migra + i_theta*migra_size)*etrue_size) * delta / EobsOnEtrue; | 347 | sum += m_edisp(0, i_etrue + (i_migra + i_theta*migra_size)*etrue_size) * delta / EobsOnEtrue; |
| 346 | } | 348 | } |
| 347 | if (sum > 0.0) { | 349 | if (sum > 0.0) { |
| 348 | for (int i_migra = 0; i_migra < migra_size; ++i_migra) { | 350 | for (int i_migra = 0; i_migra < migra_size; ++i_migra) { |
| 349 | - // Normalize by sum | ||
| 350 | - m_edisp(0, i_etrue + (i_migra + i_theta*migra_size)*etrue_size) /= sum; | 351 | + // Normalize by sum/log(10.0) |
| 352 | + m_edisp(0, i_etrue + (i_migra + i_theta*migra_size)*etrue_size) /= sum / std::log(10.0); | ||
| 351 | } | 353 | } |
| 352 | } | 354 | } |
| 353 | } | 355 | } |
| @@ -355,9 +357,6 @@ void GCTAEdisp2D::read(const GFits& fits) | @@ -355,9 +357,6 @@ void GCTAEdisp2D::read(const GFits& fits) | ||
| 355 | 357 | ||
| 356 | // Set true energy axis to logarithmic scale | 358 | // Set true energy axis to logarithmic scale |
| 357 | m_edisp.axis_log10(0); | 359 | m_edisp.axis_log10(0); |
| 358 | - | ||
| 359 | - // Set migration energy ratio axis to logarithmic scale | ||
| 360 | - m_edisp.axis_log10(1); | ||
| 361 | 360 | ||
| 362 | // Set offset angle axis to radians | 361 | // Set offset angle axis to radians |
| 363 | m_edisp.axis_radians(2); | 362 | m_edisp.axis_radians(2); |
| @@ -389,37 +388,39 @@ GEnergy GCTAEdisp2D::mc(GRan& ran, | @@ -389,37 +388,39 @@ GEnergy GCTAEdisp2D::mc(GRan& ran, | ||
| 389 | // Vector representing cumulative probability distribution | 388 | // Vector representing cumulative probability distribution |
| 390 | std::vector<std::pair<double, double> > cumul; | 389 | std::vector<std::pair<double, double> > cumul; |
| 391 | 390 | ||
| 392 | - const double deltaLogE = 0.01; | ||
| 393 | - double logEobs = 0.01; | 391 | + // Initialize cumulative probability |
| 394 | double sum = 0.0; | 392 | double sum = 0.0; |
| 395 | - // Loop through Eobs | ||
| 396 | - for(int i = 0; i < 3.0 / deltaLogE; ++i) { | ||
| 397 | - // Increment Eobs | ||
| 398 | - logEobs += deltaLogE; | 393 | + |
| 394 | + // Loop through EobsOnEtrue | ||
| 395 | + for (int i = 0; i < m_edisp.axis(1); ++i) { | ||
| 396 | + | ||
| 397 | + // Compute delta(Eobs/Etrue) and Eobs/Etrue values | ||
| 398 | + double delta = m_edisp.axis_hi(1, i) - m_edisp.axis_lo(1, i); | ||
| 399 | + double EobsOnEtrue = 0.5 * (m_edisp.axis_hi(1, i) + m_edisp.axis_lo(1, i)); | ||
| 399 | 400 | ||
| 400 | // Compute cumulated probability | 401 | // Compute cumulated probability |
| 401 | - sum += GCTAEdisp2D::operator()(logEobs, logEsrc, theta) * deltaLogE; | 402 | + sum += m_edisp(0, logEsrc, EobsOnEtrue, theta) * delta; |
| 402 | 403 | ||
| 403 | - // Create pair containing Eobs/Esrc and cumulated probability | ||
| 404 | - std::pair<double, double> pair(std::exp((logEobs - logEsrc) * std::log(10.0)), sum); | 404 | + // Create pair containing EobsOnEtrue and cumulated probability |
| 405 | + std::pair<double, double> pair(EobsOnEtrue, sum); | ||
| 405 | 406 | ||
| 406 | // Add to vector | 407 | // Add to vector |
| 407 | cumul.push_back(pair); | 408 | cumul.push_back(pair); |
| 408 | } | 409 | } |
| 409 | 410 | ||
| 410 | - // Draw random number between 0 and 1 | 411 | + // Draw random number between 0 and 1 from uniform distribution |
| 411 | double p = ran.uniform(); | 412 | double p = ran.uniform(); |
| 412 | 413 | ||
| 413 | // Find right index | 414 | // Find right index |
| 414 | int index = 0; | 415 | int index = 0; |
| 415 | - while(index < 3.0 / deltaLogE - 1.0 && cumul[index+1].second < p) { | 416 | + while(index < m_edisp.axis(1) - 1 && cumul[index+1].second < p) { |
| 416 | index++; | 417 | index++; |
| 417 | } // index found | 418 | } // index found |
| 418 | 419 | ||
| 419 | - // Compute result Eobs/Esrc value | 420 | + // Compute result EobsOnEtrue value |
| 420 | double result = (cumul[index+1].second - p)*cumul[index].first | 421 | double result = (cumul[index+1].second - p)*cumul[index].first |
| 421 | + (p - cumul[index].second)*cumul[index+1].first; | 422 | + (p - cumul[index].second)*cumul[index+1].first; |
| 422 | - result *= (cumul[index+1].second - cumul[index].second); | 423 | + result /= (cumul[index+1].second - cumul[index].second); |
| 423 | 424 | ||
| 424 | 425 | ||
| 425 | // Final result | 426 | // Final result |
| @@ -438,15 +439,14 @@ GEnergy GCTAEdisp2D::mc(GRan& ran, | @@ -438,15 +439,14 @@ GEnergy GCTAEdisp2D::mc(GRan& ran, | ||
| 438 | * @brief Return observed energy interval that contains the energy dispersion. | 439 | * @brief Return observed energy interval that contains the energy dispersion. |
| 439 | * | 440 | * |
| 440 | * @param[in] logEsrc Log10 of the true photon energy (TeV). | 441 | * @param[in] logEsrc Log10 of the true photon energy (TeV). |
| 441 | - * @param[in] theta Offset angle in camera system (rad). Not used. | 442 | + * @param[in] theta Offset angle in camera system (rad). |
| 442 | * @param[in] phi Azimuth angle in camera system (rad). Not used. | 443 | * @param[in] phi Azimuth angle in camera system (rad). Not used. |
| 443 | * @param[in] zenith Zenith angle in Earth system (rad). Not used. | 444 | * @param[in] zenith Zenith angle in Earth system (rad). Not used. |
| 444 | * @param[in] azimuth Azimuth angle in Earth system (rad). Not used. | 445 | * @param[in] azimuth Azimuth angle in Earth system (rad). Not used. |
| 445 | * | 446 | * |
| 446 | * Returns the band of observed energies outside of which the energy | 447 | * Returns the band of observed energies outside of which the energy |
| 447 | - * dispersion becomes negligible for a given true energy @p logEsrc. This | ||
| 448 | - * band is set to \f$\pm 5 \times \sigma\f$, where \f$\sigma\f$ is the | ||
| 449 | - * Gaussian width of the energy dispersion. | 448 | + * dispersion becomes negligible for a given true energy @p logEsrc and offset |
| 449 | + * angle @p theta. An energy in considered negligible if inferior to eps. | ||
| 450 | ***************************************************************************/ | 450 | ***************************************************************************/ |
| 451 | GEbounds GCTAEdisp2D::ebounds_obs(const double& logEsrc, | 451 | GEbounds GCTAEdisp2D::ebounds_obs(const double& logEsrc, |
| 452 | const double& theta, | 452 | const double& theta, |
| @@ -454,17 +454,43 @@ GEbounds GCTAEdisp2D::ebounds_obs(const double& logEsrc, | @@ -454,17 +454,43 @@ GEbounds GCTAEdisp2D::ebounds_obs(const double& logEsrc, | ||
| 454 | const double& zenith, | 454 | const double& zenith, |
| 455 | const double& azimuth) const | 455 | const double& azimuth) const |
| 456 | { | 456 | { |
| 457 | - // Set energy band constant | ||
| 458 | - const double number_of_sigmas = 5.0; | 457 | + // Set epsilon |
| 458 | + const double eps = 1.0e-06; | ||
| 459 | 459 | ||
| 460 | - // Update the parameter cache | ||
| 461 | - update(m_par_logEobs, logEsrc, theta); | 460 | + double logEobsMin = -10.0; |
| 461 | + double logEobsMax = 30.0; | ||
| 462 | + bool minFound = false; | ||
| 463 | + bool maxFound = false; | ||
| 464 | + | ||
| 465 | + for (int i = 0; i < m_edisp.axis(1); ++i) { | ||
| 466 | + // Compute value EobsOnEtrue | ||
| 467 | + double EobsOnEtrue = 0.5 * (m_edisp.axis_hi(1, i) + m_edisp.axis_lo(1, i)); | ||
| 468 | + | ||
| 469 | + // Find first non-negligible matrix term | ||
| 470 | + if (!minFound && m_edisp(0, logEsrc, EobsOnEtrue, theta) >= eps) { | ||
| 471 | + minFound = true; | ||
| 472 | + logEobsMin = std::log10(EobsOnEtrue) + logEsrc; | ||
| 473 | + } | ||
| 474 | + // Find last non-negligible matrix term | ||
| 475 | + else if (minFound && !maxFound && m_edisp(0, logEsrc, EobsOnEtrue, theta) < eps) { | ||
| 476 | + maxFound = true; | ||
| 477 | + logEobsMax = std::log10(EobsOnEtrue) + logEsrc; | ||
| 478 | + } | ||
| 479 | + else if (minFound && maxFound && m_edisp(0, logEsrc, EobsOnEtrue, theta) >= eps) { | ||
| 480 | + maxFound = false; | ||
| 481 | + } | ||
| 482 | + } | ||
| 483 | + | ||
| 484 | + // If energy dispersion has never become negligible until end of loop, reset logEobsMax | ||
| 485 | + if (!maxFound) { | ||
| 486 | + logEobsMax = 30.0; | ||
| 487 | + } | ||
| 462 | 488 | ||
| 463 | // Compute energy boundaries | 489 | // Compute energy boundaries |
| 464 | GEnergy emin; | 490 | GEnergy emin; |
| 465 | GEnergy emax; | 491 | GEnergy emax; |
| 466 | - emin.log10TeV(logEsrc - number_of_sigmas * m_eres); | ||
| 467 | - emax.log10TeV(logEsrc + number_of_sigmas * m_eres); | 492 | + emin.log10TeV(logEobsMin); |
| 493 | + emax.log10TeV(logEobsMax); | ||
| 468 | 494 | ||
| 469 | // Return energy boundaries | 495 | // Return energy boundaries |
| 470 | return (GEbounds(emin, emax)); | 496 | return (GEbounds(emin, emax)); |
| @@ -475,15 +501,14 @@ GEbounds GCTAEdisp2D::ebounds_obs(const double& logEsrc, | @@ -475,15 +501,14 @@ GEbounds GCTAEdisp2D::ebounds_obs(const double& logEsrc, | ||
| 475 | * @brief Return true energy interval that contains the energy dispersion. | 501 | * @brief Return true energy interval that contains the energy dispersion. |
| 476 | * | 502 | * |
| 477 | * @param[in] logEobs Log10 of the observed event energy (TeV). | 503 | * @param[in] logEobs Log10 of the observed event energy (TeV). |
| 478 | - * @param[in] theta Offset angle in camera system (rad). Not used. | 504 | + * @param[in] theta Offset angle in camera system (rad). |
| 479 | * @param[in] phi Azimuth angle in camera system (rad). Not used. | 505 | * @param[in] phi Azimuth angle in camera system (rad). Not used. |
| 480 | * @param[in] zenith Zenith angle in Earth system (rad). Not used. | 506 | * @param[in] zenith Zenith angle in Earth system (rad). Not used. |
| 481 | * @param[in] azimuth Azimuth angle in Earth system (rad). Not used. | 507 | * @param[in] azimuth Azimuth angle in Earth system (rad). Not used. |
| 482 | * | 508 | * |
| 483 | * Returns the band of true photon energies outside of which the energy | 509 | * Returns the band of true photon energies outside of which the energy |
| 484 | - * dispersion becomes negligible for a given observed energy @p logEobs. This | ||
| 485 | - * band is set to \f$\pm 5 \times \sigma\f$, where \f$\sigma\f$ is the | ||
| 486 | - * Gaussian width of the energy dispersion. | 510 | + * dispersion becomes negligible for a given observed energy @p logEobs and |
| 511 | + * offset angle @p theta. An energy in considered negligible if inferior to eps. | ||
| 487 | ***************************************************************************/ | 512 | ***************************************************************************/ |
| 488 | GEbounds GCTAEdisp2D::ebounds_src(const double& logEobs, | 513 | GEbounds GCTAEdisp2D::ebounds_src(const double& logEobs, |
| 489 | const double& theta, | 514 | const double& theta, |
| @@ -491,17 +516,43 @@ GEbounds GCTAEdisp2D::ebounds_src(const double& logEobs, | @@ -491,17 +516,43 @@ GEbounds GCTAEdisp2D::ebounds_src(const double& logEobs, | ||
| 491 | const double& zenith, | 516 | const double& zenith, |
| 492 | const double& azimuth) const | 517 | const double& azimuth) const |
| 493 | { | 518 | { |
| 494 | - // Set energy band constant | ||
| 495 | - const double number_of_sigmas = 5.0; | ||
| 496 | - | ||
| 497 | - // Update the parameter cache | ||
| 498 | - update(logEobs, m_par_logEsrc, theta); | 519 | + // Set epsilon |
| 520 | + const double eps = 1.0e-06; | ||
| 499 | 521 | ||
| 522 | + double logEsrcMin = -10.0; | ||
| 523 | + double logEsrcMax = 30.0; | ||
| 524 | + bool minFound = false; | ||
| 525 | + bool maxFound = false; | ||
| 526 | + | ||
| 527 | + for (int i = 0; i < m_edisp.axis(0); ++i) { | ||
| 528 | + // Compute value of corresponding logEsrc | ||
| 529 | + double logEsrc = 0.5 * (m_edisp.axis_hi(0, i) + m_edisp.axis_lo(0, i)); | ||
| 530 | + double EobsOnEtrue = std::exp((logEobs-logEsrc)*std::log(10.0)); | ||
| 531 | + // Find first non-negligible matrix term | ||
| 532 | + if (!minFound && m_edisp(0, logEsrc, EobsOnEtrue, theta) >= eps) { | ||
| 533 | + minFound = true; | ||
| 534 | + logEsrcMin = logEsrc; | ||
| 535 | + } | ||
| 536 | + // Find last non-negligible matrix term | ||
| 537 | + else if (minFound && !maxFound && m_edisp(0, logEsrc, EobsOnEtrue, theta) < eps) { | ||
| 538 | + maxFound = true; | ||
| 539 | + logEsrcMax = logEsrc; | ||
| 540 | + } | ||
| 541 | + else if (minFound && maxFound && m_edisp(0, logEsrc, EobsOnEtrue, theta) >= eps) { | ||
| 542 | + maxFound = false; | ||
| 543 | + } | ||
| 544 | + } | ||
| 545 | + | ||
| 546 | + // If energy dispersion has never become negligible until end of loop, reset logEobsMax | ||
| 547 | + if (!maxFound) { | ||
| 548 | + logEsrcMax = 30.0; | ||
| 549 | + } | ||
| 550 | + | ||
| 500 | // Compute energy boundaries | 551 | // Compute energy boundaries |
| 501 | GEnergy emin; | 552 | GEnergy emin; |
| 502 | GEnergy emax; | 553 | GEnergy emax; |
| 503 | - emin.log10TeV(logEobs - number_of_sigmas * m_eres); | ||
| 504 | - emax.log10TeV(logEobs + number_of_sigmas * m_eres); | 554 | + emin.log10TeV(logEsrcMin); |
| 555 | + emax.log10TeV(logEsrcMax); | ||
| 505 | 556 | ||
| 506 | // Return energy boundaries | 557 | // Return energy boundaries |
| 507 | return (GEbounds(emin, emax)); | 558 | return (GEbounds(emin, emax)); |
| @@ -564,13 +615,6 @@ void GCTAEdisp2D::init_members(void) | @@ -564,13 +615,6 @@ void GCTAEdisp2D::init_members(void) | ||
| 564 | // Initialise members | 615 | // Initialise members |
| 565 | m_filename.clear(); | 616 | m_filename.clear(); |
| 566 | m_edisp.clear(); | 617 | m_edisp.clear(); |
| 567 | - m_par_logEobs = -1.0e30; | ||
| 568 | - m_par_logEsrc = -1.0e30; | ||
| 569 | - m_par_theta = -1.0; | ||
| 570 | - m_norm = 1.0; | ||
| 571 | - m_EobsOnEsrc = 0.0; | ||
| 572 | - m_eres = 0.0; | ||
| 573 | - m_ebias = 0.0; | ||
| 574 | 618 | ||
| 575 | // Return | 619 | // Return |
| 576 | return; | 620 | return; |
| @@ -601,42 +645,3 @@ void GCTAEdisp2D::free_members(void) | @@ -601,42 +645,3 @@ void GCTAEdisp2D::free_members(void) | ||
| 601 | // Return | 645 | // Return |
| 602 | return; | 646 | return; |
| 603 | } | 647 | } |
| 604 | - | ||
| 605 | -/***********************************************************************//** | ||
| 606 | - * @brief Update Energy dispersion parameter cache | ||
| 607 | - * | ||
| 608 | - * @param[in] logEobs Log10 of the observed photon energy (TeV). | ||
| 609 | - * @param[in] logEsrc Log10 of the true photon energy (TeV). | ||
| 610 | - * @param[in] theta Offset angle in camera system (rad). | ||
| 611 | - * | ||
| 612 | - * This method updates the Energy dispersion parameter cache. | ||
| 613 | - ***************************************************************************/ | ||
| 614 | -void GCTAEdisp2D::update(const double& logEobs, const double& logEsrc, const double& theta) const | ||
| 615 | -{ | ||
| 616 | - /* | ||
| 617 | - // Only compute Edisp parameters if arguments have changed | ||
| 618 | - if (logEobs != m_par_logEobs || logEsrc != m_par_logEsrc || theta != m_par_theta) { | ||
| 619 | - | ||
| 620 | - // Save parameters | ||
| 621 | - m_par_logEobs = logEobs; | ||
| 622 | - m_par_logEsrc = logEsrc; | ||
| 623 | - m_par_theta = theta; | ||
| 624 | - | ||
| 625 | - // Compute linear Eobs/Esrc ratio | ||
| 626 | - m_EobsOnEsrc = std::exp( (logEobs - logEsrc) * std::log(10)); | ||
| 627 | - | ||
| 628 | - | ||
| 629 | - | ||
| 630 | - | ||
| 631 | - // Get ERES and EBIAS values from response table | ||
| 632 | - m_eres = m_edisp(0, logEsrc, theta); | ||
| 633 | - m_ebias = m_edisp(1, logEsrc, theta); | ||
| 634 | - | ||
| 635 | - // Compute global normalization parameter | ||
| 636 | - m_norm = (m_eres > 0.0) ? gammalib::inv_sqrt2pi / m_eres : 0.0; | ||
| 637 | - | ||
| 638 | - } | ||
| 639 | - */ | ||
| 640 | - // Return | ||
| 641 | - return; | ||
| 642 | -} |
inst/cta/test/test_CTA.cpp
| @@ -37,7 +37,9 @@ | @@ -37,7 +37,9 @@ | ||
| 37 | #include "GNodeArray.hpp" | 37 | #include "GNodeArray.hpp" |
| 38 | #include "test_CTA.hpp" | 38 | #include "test_CTA.hpp" |
| 39 | #include "GCTAEdisp2D.hpp" | 39 | #include "GCTAEdisp2D.hpp" |
| 40 | +#include "GCTAEdispPerfTable.hpp" | ||
| 40 | #include "GCTAResponseTable.hpp" | 41 | #include "GCTAResponseTable.hpp" |
| 42 | +#include "GMath.hpp" | ||
| 41 | 43 | ||
| 42 | /* __ Namespaces _________________________________________________________ */ | 44 | /* __ Namespaces _________________________________________________________ */ |
| 43 | 45 | ||
| @@ -590,45 +592,60 @@ void TestGCTAResponse::test_response_edisp2D(void) | @@ -590,45 +592,60 @@ void TestGCTAResponse::test_response_edisp2D(void) | ||
| 590 | catch (std::exception &e) { | 592 | catch (std::exception &e) { |
| 591 | test_try_failure(e); | 593 | test_try_failure(e); |
| 592 | } | 594 | } |
| 593 | - | 595 | + |
| 594 | // Test normalization | 596 | // Test normalization |
| 597 | + test_try("GCTAEdisp2D normalization"); | ||
| 595 | try { | 598 | try { |
| 596 | - GCTAEdisp2D edisp2D_2(cta_irf_matrix); | ||
| 597 | - | ||
| 598 | - GCTAResponseTable m_edisp = edisp2D_2.table(); | ||
| 599 | - int etrue_size = m_edisp.axis(0); | ||
| 600 | - int migra_size = m_edisp.axis(1); | ||
| 601 | - int theta_size = m_edisp.axis(2); | ||
| 602 | - | ||
| 603 | - for (int i_etrue = 0; i_etrue < etrue_size; ++i_etrue) { | ||
| 604 | - double EobsOnEtrue = 0.5 * (m_edisp.axis_hi(1, i_etrue) + m_edisp.axis_lo(1, i_etrue)); | ||
| 605 | - for (int i_theta = 0; i_theta < theta_size; ++i_theta) { | ||
| 606 | - // Compute sum | ||
| 607 | - double sum = 0.0; | ||
| 608 | - for (int i_migra = 0; i_migra < migra_size; ++i_migra) { | ||
| 609 | - // Compute delta(Eobs/Etrue) | ||
| 610 | - double delta = m_edisp.axis_hi(1, i_migra) - m_edisp.axis_lo(1, i_migra); | ||
| 611 | - sum += m_edisp(0, i_etrue + (i_migra + i_theta*migra_size)*etrue_size) * delta / EobsOnEtrue; | 599 | + GCTAEdisp2D edisp2D_2(cta_irf_matrix); |
| 600 | + //std::cout << "TEST NORM 2D" << std::endl; | ||
| 601 | + | ||
| 602 | + const double deltaLogE = 0.01; | ||
| 603 | + for(double logEsrc = -3.0; logEsrc < 4.0; logEsrc += deltaLogE) { | ||
| 604 | + double sum = 0.0; | ||
| 605 | + for(double logEobs = -3.0; logEobs < 7.0; logEobs += deltaLogE) { | ||
| 606 | + sum += edisp2D_2(logEobs, logEsrc) * deltaLogE; | ||
| 612 | } | 607 | } |
| 613 | - std::cout << sum << std::endl; | ||
| 614 | - } | 608 | + //std::cout << sum << std::endl; |
| 609 | + } | ||
| 610 | + | ||
| 611 | + test_try_success(); | ||
| 612 | + } | ||
| 613 | + catch (std::exception &e) { | ||
| 614 | + test_try_failure(e); | ||
| 615 | } | 615 | } |
| 616 | 616 | ||
| 617 | + // Test ebounds_obs and ebounds_src methods | ||
| 618 | + test_try("GCTAEdisp2D ebounds_src and ebounds_obs methods"); | ||
| 619 | + try { | ||
| 620 | + GCTAEdisp2D edisp2D_3(cta_irf_matrix); | ||
| 621 | + //std::cout << "TEST EBOUNDS 2D" << std::endl; | ||
| 622 | + // ebounds_obs (for a given logEsrc) | ||
| 623 | + //std::cout << edisp2D_3.ebounds_obs(-1.0).print(EXPLICIT) << std::endl; | ||
| 624 | + // ebounds_src (for a given logEobs) | ||
| 625 | + //std::cout << edisp2D_3.ebounds_src(2.0).print(EXPLICIT) << std::endl; | ||
| 626 | + | ||
| 627 | + test_try_success(); | ||
| 628 | + } | ||
| 629 | + catch (std::exception &e) { | ||
| 630 | + test_try_failure(e); | ||
| 631 | + } | ||
| 617 | 632 | ||
| 618 | - const double deltaLogE = 0.01; | ||
| 619 | - for(double logEsrc = -1.0; logEsrc < 2.0; logEsrc += deltaLogE) { | ||
| 620 | - double sum = 0.0; | ||
| 621 | - for(double logEobs = -1.0; logEobs < 2.0; logEobs += deltaLogE) { | ||
| 622 | - sum += edisp2D_2(logEobs, logEsrc) * deltaLogE; | 633 | + // Test mc method |
| 634 | + test_try("GCTAEdisp2D mc method"); | ||
| 635 | + try { | ||
| 636 | + GCTAEdisp2D edisp2D_4(cta_irf_matrix); | ||
| 637 | + GRan ran; | ||
| 638 | + //std::cout << "TEST MC 2D" << std::endl; | ||
| 639 | + for (int i = 0; i < 20; ++i) { | ||
| 640 | + //std::cout << edisp2D_4.mc(ran, -1.0).GeV() << std::endl; | ||
| 623 | } | 641 | } |
| 624 | - std::cout << sum << std::endl; | ||
| 625 | - } | ||
| 626 | - | 642 | + |
| 643 | + test_try_success(); | ||
| 627 | } | 644 | } |
| 628 | catch (std::exception &e) { | 645 | catch (std::exception &e) { |
| 629 | test_try_failure(e); | 646 | test_try_failure(e); |
| 630 | } | 647 | } |
| 631 | - | 648 | + |
| 632 | // Return | 649 | // Return |
| 633 | return; | 650 | return; |
| 634 | } | 651 | } |
| @@ -638,7 +655,77 @@ void TestGCTAResponse::test_response_edisp2D(void) | @@ -638,7 +655,77 @@ void TestGCTAResponse::test_response_edisp2D(void) | ||
| 638 | ***************************************************************************/ | 655 | ***************************************************************************/ |
| 639 | void TestGCTAResponse::test_response_edispPerfTable(void) | 656 | void TestGCTAResponse::test_response_edispPerfTable(void) |
| 640 | { | 657 | { |
| 658 | + /// /// TO DO | ||
| 659 | + | ||
| 660 | + // Load response | ||
| 661 | + GCTAResponseIrf rsp; | ||
| 662 | + rsp.caldb(GCaldb(cta_caldb)); | ||
| 641 | 663 | ||
| 664 | + // Test Energy Dispersion | ||
| 665 | + test_energy_integration(rsp); | ||
| 666 | + | ||
| 667 | + | ||
| 668 | + // Test GCTAEdispPerfTable constructor | ||
| 669 | + test_try("GCTAEdispPerfTable constructor"); | ||
| 670 | + try { | ||
| 671 | + GCTAEdispPerfTable test(cta_caldb+"/"+cta_irf+".dat"); | ||
| 672 | + test_try_success(); | ||
| 673 | + } | ||
| 674 | + catch (std::exception &e) { | ||
| 675 | + test_try_failure(e); | ||
| 676 | + } | ||
| 677 | + | ||
| 678 | + GCTAEdispPerfTable test2(cta_caldb+"/"+cta_irf+".dat"); | ||
| 679 | + | ||
| 680 | + // Test ebounds_obs and ebounds_src methods | ||
| 681 | + test_try("GCTAEdispPerfTable ebounds_obs and ebounds_src methods"); | ||
| 682 | + try { | ||
| 683 | + //std::cout << "TEST EBOUNDS PERFTABLE" << std::endl; | ||
| 684 | + // ebounds_obs (for a given logEsrc) | ||
| 685 | + //std::cout << test2.ebounds_obs(-1.0).print(EXPLICIT) << std::endl; | ||
| 686 | + // ebounds_src (for a given logEobs) | ||
| 687 | + //std::cout << test2.ebounds_src(2.0).print(EXPLICIT) << std::endl; | ||
| 688 | + test_try_success(); | ||
| 689 | + } | ||
| 690 | + catch (std::exception &e) { | ||
| 691 | + test_try_failure(e); | ||
| 692 | + } | ||
| 693 | + | ||
| 694 | + // Test mc method | ||
| 695 | + test_try("GCTAEdispPerfTable mc method"); | ||
| 696 | + try { | ||
| 697 | + GRan ran; | ||
| 698 | + //std::cout << "TEST MC PERFTABLE" << std::endl; | ||
| 699 | + for (int i = 0; i < 20; ++i) { | ||
| 700 | + //std::cout << test2.mc(ran, -1.0).GeV() << std::endl; | ||
| 701 | + } | ||
| 702 | + test_try_success(); | ||
| 703 | + } | ||
| 704 | + catch (std::exception &e) { | ||
| 705 | + test_try_failure(e); | ||
| 706 | + } | ||
| 707 | + | ||
| 708 | + // Test normalization | ||
| 709 | + test_try("GCTAEdispPerfTable normalization"); | ||
| 710 | + try { | ||
| 711 | + //std::cout << "TEST NORM PERFTABLE" << std::endl; | ||
| 712 | + const double deltaLogE = 0.01; | ||
| 713 | + for(double logEsrc = -3.0; logEsrc < 4.0; logEsrc += deltaLogE) { | ||
| 714 | + double sum = 0.0; | ||
| 715 | + for(double logEobs = -3.0; logEobs < 7.0; logEobs += deltaLogE) { | ||
| 716 | + sum += test2(logEobs, logEsrc) * deltaLogE; | ||
| 717 | + } | ||
| 718 | + //std::cout << sum << std::endl; | ||
| 719 | + } | ||
| 720 | + | ||
| 721 | + test_try_success(); | ||
| 722 | + } | ||
| 723 | + catch (std::exception &e) { | ||
| 724 | + test_try_failure(e); | ||
| 725 | + } | ||
| 726 | + | ||
| 727 | + | ||
| 728 | + // Return | ||
| 642 | return; | 729 | return; |
| 643 | } | 730 | } |
| 644 | 731 |