Commit f18179e55c7929bb144d4ea301c850afc2756dc7
1 parent
b9635d15
Remove obsolete code and rename a few data members.
Showing
2 changed files
with
80 additions
and
321 deletions
inst/cta/include/GCTAEdisp2D.hpp
| ... | ... | @@ -29,7 +29,6 @@ |
| 29 | 29 | |
| 30 | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | 31 | #include <string> |
| 32 | -//#include "GFits.hpp" | |
| 33 | 32 | #include "GCTAEdisp.hpp" |
| 34 | 33 | #include "GCTAResponseTable.hpp" |
| 35 | 34 | |
| ... | ... | @@ -103,10 +102,6 @@ private: |
| 103 | 102 | void update(const double& logEobs, |
| 104 | 103 | const double& logEsrc, |
| 105 | 104 | const double& theta) const; |
| 106 | - void compute_cumul(const double& theta = 0.0, | |
| 107 | - const double& phi = 0.0, | |
| 108 | - const double& zenith = 0.0, | |
| 109 | - const double& azimuth = 0.0) const; | |
| 110 | 105 | void compute_ebounds_obs(const double& theta = 0.0, |
| 111 | 106 | const double& phi = 0.0, |
| 112 | 107 | const double& zenith = 0.0, |
| ... | ... | @@ -115,28 +110,24 @@ private: |
| 115 | 110 | const double& phi = 0.0, |
| 116 | 111 | const double& zenith = 0.0, |
| 117 | 112 | const double& azimuth = 0.0) const; |
| 118 | - void set_fmax(void) const; | |
| 113 | + void set_max_edisp(void) const; | |
| 119 | 114 | |
| 120 | 115 | // Members |
| 121 | 116 | std::string m_filename; //!< Name of Edisp response file |
| 122 | 117 | GCTAResponseTable m_edisp; //!< Edisp response table |
| 123 | 118 | |
| 124 | - // Monte Carlo cache | |
| 125 | - mutable bool m_cdf_computed; | |
| 126 | - mutable double m_theta; | |
| 127 | - mutable bool m_ebounds_obs_computed; | |
| 128 | - mutable bool m_ebounds_src_computed; | |
| 129 | - mutable double m_logEsrc; | |
| 130 | - mutable double m_logEobs; | |
| 131 | - mutable int m_index_obs; | |
| 132 | - mutable int m_index_src; | |
| 133 | - mutable double m_fmax; | |
| 134 | - | |
| 135 | - mutable std::vector<GEbounds> m_ebounds_obs; | |
| 136 | - mutable std::vector<GEbounds> m_ebounds_src; | |
| 137 | - mutable std::vector<std::vector<std::pair<double, double> > > m_cumul; | |
| 138 | - mutable std::vector<double> m_eobs_axis; | |
| 139 | - mutable std::vector<std::vector<double> > m_temp; | |
| 119 | + // Computation cache | |
| 120 | + mutable bool m_ebounds_obs_computed; | |
| 121 | + mutable bool m_ebounds_src_computed; | |
| 122 | + mutable double m_last_theta_obs; | |
| 123 | + mutable double m_last_theta_src; | |
| 124 | + mutable double m_last_logEsrc; | |
| 125 | + mutable double m_last_logEobs; | |
| 126 | + mutable int m_index_obs; | |
| 127 | + mutable int m_index_src; | |
| 128 | + mutable double m_max_edisp; | |
| 129 | + mutable std::vector<GEbounds> m_ebounds_obs; | |
| 130 | + mutable std::vector<GEbounds> m_ebounds_src; | |
| 140 | 131 | }; |
| 141 | 132 | |
| 142 | 133 | ... | ... |
inst/cta/src/GCTAEdisp2D.cpp
| ... | ... | @@ -37,9 +37,6 @@ |
| 37 | 37 | #include "GFitsBinTable.hpp" |
| 38 | 38 | #include "GCTAEdisp2D.hpp" |
| 39 | 39 | |
| 40 | -//#define G_CDF_METHOD | |
| 41 | -#define G_REJECTION | |
| 42 | - | |
| 43 | 40 | /* __ Method name definitions ____________________________________________ */ |
| 44 | 41 | |
| 45 | 42 | /* __ Macros _____________________________________________________________ */ |
| ... | ... | @@ -169,8 +166,9 @@ GCTAEdisp2D& GCTAEdisp2D::operator=(const GCTAEdisp2D& edisp) |
| 169 | 166 | * @param[in] zenith Zenith angle in Earth system (rad). Not used in this method. |
| 170 | 167 | * @param[in] azimuth Azimuth angle in Earth system (rad). Not used in this method. |
| 171 | 168 | * |
| 172 | - * Returns the energy dispersion in units of s^-1 MeV^-1 for a given observed energy, | |
| 173 | - * true photon energy and offset angle. | |
| 169 | + * Returns the energy dispersion in units of s^-1 MeV^-1 for a given observed | |
| 170 | + * energy @p logEobs, true photon energy @p logEsrc and offset angle | |
| 171 | + * @p theta. | |
| 174 | 172 | ***************************************************************************/ |
| 175 | 173 | double GCTAEdisp2D::operator()(const double& logEobs, |
| 176 | 174 | const double& logEsrc, |
| ... | ... | @@ -239,7 +237,6 @@ GCTAEdisp2D* GCTAEdisp2D::clone(void) const |
| 239 | 237 | ***************************************************************************/ |
| 240 | 238 | void GCTAEdisp2D::load(const std::string& filename) |
| 241 | 239 | { |
| 242 | - | |
| 243 | 240 | // Open FITS file |
| 244 | 241 | GFits fits(filename); |
| 245 | 242 | |
| ... | ... | @@ -272,7 +269,6 @@ void GCTAEdisp2D::load(const std::string& filename) |
| 272 | 269 | ***************************************************************************/ |
| 273 | 270 | void GCTAEdisp2D::read(const GFits& fits) |
| 274 | 271 | { |
| 275 | - | |
| 276 | 272 | // Clear response table |
| 277 | 273 | m_edisp.clear(); |
| 278 | 274 | |
| ... | ... | @@ -327,22 +323,8 @@ void GCTAEdisp2D::read(const GFits& fits) |
| 327 | 323 | // Set offset angle axis to radians |
| 328 | 324 | m_edisp.axis_radians(2); |
| 329 | 325 | |
| 330 | - // ... | |
| 331 | - m_temp.clear(); | |
| 332 | - int step = migra_size / etrue_size; | |
| 333 | - for (int itrue = 0; itrue < etrue_size; ++itrue) { | |
| 334 | - double logEsrc = std::log10(0.5 * (m_edisp.axis_hi(0, itrue) + | |
| 335 | - m_edisp.axis_lo(0, itrue))); | |
| 336 | - m_temp.push_back(std::vector<double>()); | |
| 337 | - for (int iobs = 0; iobs < etrue_size; ++iobs) { | |
| 338 | - double EobsOverEsrc = 0.5 * (m_edisp.axis_hi(1, iobs*step) + | |
| 339 | - m_edisp.axis_lo(1, iobs*step)); | |
| 340 | - m_temp[itrue].push_back(operator()(logEsrc, EobsOverEsrc)); | |
| 341 | - } | |
| 342 | - } | |
| 343 | - | |
| 344 | - // Set fmax | |
| 345 | - set_fmax(); | |
| 326 | + // Set maximum energy dispersion value | |
| 327 | + set_max_edisp(); | |
| 346 | 328 | |
| 347 | 329 | // Return |
| 348 | 330 | return; |
| ... | ... | @@ -398,14 +380,14 @@ void GCTAEdisp2D::save(const std::string& filename, const bool& clobber) const |
| 398 | 380 | * |
| 399 | 381 | * @param[in] ran Random number generator. |
| 400 | 382 | * @param[in] logEsrc Log10 of the true photon energy (TeV). |
| 401 | - * @param[in] theta Offset angle in camera system (rad). Not used. | |
| 402 | - * @param[in] phi Azimuth angle in camera system (rad). Not used. | |
| 403 | - * @param[in] zenith Zenith angle in Earth system (rad). Not used. | |
| 404 | - * @param[in] azimuth Azimuth angle in Earth system (rad). Not used. | |
| 383 | + * @param[in] theta Offset angle in camera system (rad). | |
| 384 | + * @param[in] phi Azimuth angle in camera system (rad). | |
| 385 | + * @param[in] zenith Zenith angle in Earth system (rad). | |
| 386 | + * @param[in] azimuth Azimuth angle in Earth system (rad). | |
| 405 | 387 | * |
| 406 | - * Draws observed energy value. | |
| 388 | + * Draws observed energy value given a true energy @p logEsrc and offset | |
| 389 | + * angle @p theta. | |
| 407 | 390 | ***************************************************************************/ |
| 408 | -#if defined(G_REJECTION) | |
| 409 | 391 | GEnergy GCTAEdisp2D::mc(GRan& ran, |
| 410 | 392 | const double& logEsrc, |
| 411 | 393 | const double& theta, |
| ... | ... | @@ -420,13 +402,15 @@ GEnergy GCTAEdisp2D::mc(GRan& ran, |
| 420 | 402 | |
| 421 | 403 | // Find energy by rejection method |
| 422 | 404 | double ewidth = emax - emin; |
| 423 | - double logEobs = emin; | |
| 424 | - double f = 0.0; | |
| 425 | - double ftest = 1.0; | |
| 426 | - while (ftest > f) { | |
| 427 | - logEobs = emin + ewidth * ran.uniform(); | |
| 428 | - f = operator()(logEobs, logEsrc, theta, phi, zenith, azimuth); | |
| 429 | - ftest = ran.uniform() * m_fmax; | |
| 405 | + double logEobs = 0.5*(emin+emax); | |
| 406 | + if (m_max_edisp > 0.0) { | |
| 407 | + double f = 0.0; | |
| 408 | + double ftest = 1.0; | |
| 409 | + while (ftest > f) { | |
| 410 | + logEobs = emin + ewidth * ran.uniform(); | |
| 411 | + f = operator()(logEobs, logEsrc, theta, phi, zenith, azimuth); | |
| 412 | + ftest = ran.uniform() * m_max_edisp; | |
| 413 | + } | |
| 430 | 414 | } |
| 431 | 415 | |
| 432 | 416 | // Set observed energy |
| ... | ... | @@ -435,82 +419,8 @@ GEnergy GCTAEdisp2D::mc(GRan& ran, |
| 435 | 419 | |
| 436 | 420 | // Return energy |
| 437 | 421 | return energy; |
| 438 | - | |
| 439 | 422 | } |
| 440 | -#else | |
| 441 | -GEnergy GCTAEdisp2D::mc(GRan& ran, | |
| 442 | - const double& logEsrc, | |
| 443 | - const double& theta, | |
| 444 | - const double& phi, | |
| 445 | - const double& zenith, | |
| 446 | - const double& azimuth) const | |
| 447 | -{ | |
| 448 | - // Compute cumulative probability | |
| 449 | - compute_cumul(theta, phi, zenith, azimuth); | |
| 450 | - | |
| 451 | - // Find right logEsrc index with bisection search | |
| 452 | - int low = 0; | |
| 453 | - int high = m_edisp.axis(0); | |
| 454 | - double Esrc = std::exp(logEsrc*gammalib::ln10); | |
| 455 | - while ((high-low) > 1) { | |
| 456 | - int mid = (low+high) / 2; | |
| 457 | - if (Esrc < m_edisp.axis_lo(0, mid)) { | |
| 458 | - high = mid; | |
| 459 | - } | |
| 460 | - else { | |
| 461 | - low = mid; | |
| 462 | - } | |
| 463 | - } | |
| 464 | - // Index found | |
| 465 | - int isrc = low; | |
| 466 | - | |
| 467 | - // Draw random number between 0 and 1 from uniform distribution | |
| 468 | - double p = ran.uniform(); | |
| 469 | - | |
| 470 | - // Find right index with bisection search | |
| 471 | - low = 0; | |
| 472 | - high = m_cumul[isrc].size(); | |
| 473 | - while ((high-low) > 1) { | |
| 474 | - int mid = (low+high) / 2; | |
| 475 | - if (p < m_cumul[isrc][mid].second) { | |
| 476 | - high = mid; | |
| 477 | - } | |
| 478 | - else if (m_cumul[isrc][mid].second <= p) { | |
| 479 | - low = mid; | |
| 480 | - } | |
| 481 | - } | |
| 482 | - | |
| 483 | - // Index found | |
| 484 | - int index = 0; | |
| 485 | - if (low >= m_cumul[isrc].size() - 1) { | |
| 486 | - index = m_cumul[isrc].size() - 2; | |
| 487 | - } | |
| 488 | - else { | |
| 489 | - index = low; | |
| 490 | - } | |
| 491 | - | |
| 492 | 423 | |
| 493 | - // Interpolate EobsOverEsrc value | |
| 494 | - double EobsOverEsrc = 0.0; | |
| 495 | - | |
| 496 | - if (m_cumul[isrc][index+1].second == m_cumul[isrc][index].second) { | |
| 497 | - EobsOverEsrc = m_cumul[isrc][index].first; | |
| 498 | - } | |
| 499 | - else { | |
| 500 | - EobsOverEsrc = (m_cumul[isrc][index+1].second - p)*m_cumul[isrc][index].first | |
| 501 | - + (p - m_cumul[isrc][index].second)*m_cumul[isrc][index+1].first; | |
| 502 | - EobsOverEsrc /= (m_cumul[isrc][index+1].second - m_cumul[isrc][index].second); | |
| 503 | - } | |
| 504 | - | |
| 505 | - | |
| 506 | - // Set energy | |
| 507 | - GEnergy energy; | |
| 508 | - energy.TeV(EobsOverEsrc * Esrc); | |
| 509 | - | |
| 510 | - // Return energy | |
| 511 | - return energy; | |
| 512 | -} | |
| 513 | -#endif | |
| 514 | 424 | |
| 515 | 425 | /***********************************************************************//** |
| 516 | 426 | * @brief Return observed energy interval that contains the energy dispersion. |
| ... | ... | @@ -533,10 +443,11 @@ GEbounds GCTAEdisp2D::ebounds_obs(const double& logEsrc, |
| 533 | 443 | const double& azimuth) const |
| 534 | 444 | { |
| 535 | 445 | // Compute only if parameters changed |
| 536 | - if (!m_ebounds_obs_computed || theta != m_theta) { | |
| 446 | + if (!m_ebounds_obs_computed || theta != m_last_theta_obs) { | |
| 537 | 447 | |
| 448 | + // Set computation flag | |
| 538 | 449 | m_ebounds_obs_computed = true; |
| 539 | - m_theta = theta; | |
| 450 | + m_last_theta_obs = theta; | |
| 540 | 451 | |
| 541 | 452 | // Compute ebounds_obs |
| 542 | 453 | compute_ebounds_obs(theta, phi, zenith, azimuth); |
| ... | ... | @@ -544,9 +455,10 @@ GEbounds GCTAEdisp2D::ebounds_obs(const double& logEsrc, |
| 544 | 455 | } |
| 545 | 456 | |
| 546 | 457 | // Search index only if logEsrc has changed |
| 547 | - if (logEsrc != m_logEsrc) { | |
| 458 | + if (logEsrc != m_last_logEsrc) { | |
| 548 | 459 | |
| 549 | - m_logEsrc = logEsrc; | |
| 460 | + // Store last log(Esrc) | |
| 461 | + m_last_logEsrc = logEsrc; | |
| 550 | 462 | |
| 551 | 463 | // Find right index with bisection |
| 552 | 464 | int low = 0; |
| ... | ... | @@ -561,6 +473,7 @@ GEbounds GCTAEdisp2D::ebounds_obs(const double& logEsrc, |
| 561 | 473 | low = mid; |
| 562 | 474 | } |
| 563 | 475 | } |
| 476 | + | |
| 564 | 477 | // Index found |
| 565 | 478 | m_index_obs = low; |
| 566 | 479 | |
| ... | ... | @@ -592,10 +505,11 @@ GEbounds GCTAEdisp2D::ebounds_src(const double& logEobs, |
| 592 | 505 | const double& azimuth) const |
| 593 | 506 | { |
| 594 | 507 | // Compute only if parameters changed |
| 595 | - if (!m_ebounds_src_computed || theta != m_theta) { | |
| 508 | + if (!m_ebounds_src_computed || theta != m_last_theta_src) { | |
| 596 | 509 | |
| 510 | + // Set computation flag | |
| 597 | 511 | m_ebounds_src_computed = true; |
| 598 | - m_theta = theta; | |
| 512 | + m_last_theta_src = theta; | |
| 599 | 513 | |
| 600 | 514 | // Compute ebounds_src |
| 601 | 515 | compute_ebounds_src(theta, phi, zenith, azimuth); |
| ... | ... | @@ -603,19 +517,17 @@ GEbounds GCTAEdisp2D::ebounds_src(const double& logEobs, |
| 603 | 517 | } |
| 604 | 518 | |
| 605 | 519 | // Search index only if logEobs has changed |
| 606 | - if (logEobs != m_logEobs) { | |
| 520 | + if (logEobs != m_last_logEobs) { | |
| 607 | 521 | |
| 608 | - m_logEobs = logEobs; | |
| 522 | + // Store observed energy | |
| 523 | + m_last_logEobs = logEobs; | |
| 609 | 524 | |
| 610 | 525 | // Find right index with bisection |
| 611 | - int low = 0; | |
| 526 | + int low = 0; | |
| 612 | 527 | int high = m_ebounds_src.size(); |
| 613 | - | |
| 614 | 528 | while ((high-low) > 1) { |
| 615 | 529 | int mid = (low+high) / 2; |
| 616 | - | |
| 617 | 530 | double e = m_edisp.axis_lo(0, mid); |
| 618 | - //double e = m_eobs_axis[mid]; | |
| 619 | 531 | if (logEobs < std::log10(e)) { |
| 620 | 532 | high = mid; |
| 621 | 533 | } |
| ... | ... | @@ -623,11 +535,9 @@ GEbounds GCTAEdisp2D::ebounds_src(const double& logEobs, |
| 623 | 535 | low = mid; |
| 624 | 536 | } |
| 625 | 537 | } |
| 538 | + | |
| 626 | 539 | // Index found |
| 627 | 540 | m_index_src = low; |
| 628 | - //m_index_src = low * m_edisp.axis(1) / m_edisp.axis(0); | |
| 629 | - //std::cout << "emin = " << m_ebounds_src[m_index_src].emin().TeV() << std::endl; | |
| 630 | - //std::cout << "emax = " << m_ebounds_src[m_index_src].emax().TeV() << std::endl; | |
| 631 | 541 | |
| 632 | 542 | } |
| 633 | 543 | |
| ... | ... | @@ -694,23 +604,18 @@ void GCTAEdisp2D::init_members(void) |
| 694 | 604 | m_filename.clear(); |
| 695 | 605 | m_edisp.clear(); |
| 696 | 606 | |
| 697 | - // Initialise Monte Carlo cache | |
| 698 | - m_theta = 0.0; | |
| 699 | - m_logEsrc = -30.0; | |
| 700 | - m_logEobs = -30.0; | |
| 701 | - m_fmax = -1.0; | |
| 702 | - m_index_obs = 0; | |
| 703 | - m_index_src = 0; | |
| 704 | - m_cdf_computed = false; | |
| 607 | + // Initialise computation cache | |
| 705 | 608 | m_ebounds_obs_computed = false; |
| 706 | 609 | m_ebounds_src_computed = false; |
| 707 | - | |
| 708 | - // Initialize vectors | |
| 610 | + m_last_theta_obs = -1.0; | |
| 611 | + m_last_theta_src = -1.0; | |
| 612 | + m_last_logEsrc = -30.0; | |
| 613 | + m_last_logEobs = -30.0; | |
| 614 | + m_index_obs = 0; | |
| 615 | + m_index_src = 0; | |
| 616 | + m_max_edisp = 0.0; | |
| 709 | 617 | m_ebounds_obs.clear(); |
| 710 | 618 | m_ebounds_src.clear(); |
| 711 | - m_cumul.clear(); | |
| 712 | - m_eobs_axis.clear(); | |
| 713 | - m_temp.clear(); | |
| 714 | 619 | |
| 715 | 620 | // Return |
| 716 | 621 | return; |
| ... | ... | @@ -728,21 +633,18 @@ void GCTAEdisp2D::copy_members(const GCTAEdisp2D& edisp) |
| 728 | 633 | m_filename = edisp.m_filename; |
| 729 | 634 | m_edisp = edisp.m_edisp; |
| 730 | 635 | |
| 731 | - // Copy Monte Carlo cache | |
| 732 | - m_theta = edisp.m_theta; | |
| 733 | - m_logEsrc = edisp.m_logEsrc; | |
| 734 | - m_logEobs = edisp.m_logEobs; | |
| 735 | - m_fmax = edisp.m_fmax; | |
| 736 | - m_index_obs = edisp.m_index_obs; | |
| 737 | - m_index_src = edisp.m_index_src; | |
| 738 | - m_cdf_computed = edisp.m_cdf_computed; | |
| 636 | + // Copy computation cache | |
| 739 | 637 | m_ebounds_obs_computed = edisp.m_ebounds_obs_computed; |
| 740 | 638 | m_ebounds_src_computed = edisp.m_ebounds_src_computed; |
| 639 | + m_last_theta_obs = edisp.m_last_theta_obs; | |
| 640 | + m_last_theta_src = edisp.m_last_theta_src; | |
| 641 | + m_last_logEsrc = edisp.m_last_logEsrc; | |
| 642 | + m_last_logEobs = edisp.m_last_logEobs; | |
| 643 | + m_index_obs = edisp.m_index_obs; | |
| 644 | + m_index_src = edisp.m_index_src; | |
| 645 | + m_max_edisp = edisp.m_max_edisp; | |
| 741 | 646 | m_ebounds_obs = edisp.m_ebounds_obs; |
| 742 | 647 | m_ebounds_src = edisp.m_ebounds_src; |
| 743 | - m_cumul = edisp.m_cumul; | |
| 744 | - m_eobs_axis = edisp.m_eobs_axis; | |
| 745 | - m_temp = edisp.m_temp; | |
| 746 | 648 | |
| 747 | 649 | // Return |
| 748 | 650 | return; |
| ... | ... | @@ -758,9 +660,14 @@ void GCTAEdisp2D::free_members(void) |
| 758 | 660 | return; |
| 759 | 661 | } |
| 760 | 662 | |
| 663 | + | |
| 761 | 664 | /***********************************************************************//** |
| 762 | 665 | * @brief Compute ebounds_obs vector |
| 763 | 666 | * |
| 667 | + * @param[in] theta Offset angle (rad). | |
| 668 | + * @param[in] phi Azimuth angle (rad). | |
| 669 | + * @param[in] zenith Zenith angle (rad). | |
| 670 | + * @param[in] azimuth Azimuth angle (rad). | |
| 764 | 671 | ***************************************************************************/ |
| 765 | 672 | void GCTAEdisp2D::compute_ebounds_obs(const double& theta, |
| 766 | 673 | const double& phi, |
| ... | ... | @@ -831,97 +738,32 @@ void GCTAEdisp2D::compute_ebounds_obs(const double& theta, |
| 831 | 738 | // Add energy boundaries to vector |
| 832 | 739 | m_ebounds_obs.push_back(GEbounds(emin, emax)); |
| 833 | 740 | |
| 834 | - } | |
| 835 | - | |
| 741 | + } // endfor: looped over logEsrc | |
| 836 | 742 | |
| 837 | 743 | // Return |
| 838 | 744 | return; |
| 839 | 745 | } |
| 840 | 746 | |
| 747 | + | |
| 841 | 748 | /***********************************************************************//** |
| 842 | 749 | * @brief Compute ebounds_src vector |
| 843 | 750 | * |
| 751 | + * @param[in] theta Offset angle (rad). | |
| 752 | + * @param[in] phi Azimuth angle (rad). | |
| 753 | + * @param[in] zenith Zenith angle (rad). | |
| 754 | + * @param[in] azimuth Azimuth angle (rad). | |
| 844 | 755 | ***************************************************************************/ |
| 845 | 756 | void GCTAEdisp2D::compute_ebounds_src(const double& theta, |
| 846 | 757 | const double& phi, |
| 847 | 758 | const double& zenith, |
| 848 | 759 | const double& azimuth) const |
| 849 | 760 | { |
| 850 | - | |
| 851 | 761 | // Clear ebounds_src vector |
| 852 | 762 | m_ebounds_src.clear(); |
| 853 | 763 | |
| 854 | 764 | // Set epsilon |
| 855 | 765 | const double eps = 1.0e-06; |
| 856 | 766 | |
| 857 | -/* | |
| 858 | - // Loop over EobsOverEsrc | |
| 859 | - for (int iobs = 0; iobs < m_edisp.axis(1); ++iobs) { | |
| 860 | - | |
| 861 | - // Set EobsOverEsrc | |
| 862 | - double EobsOverEsrc = 0.5 * (m_edisp.axis_hi(1, iobs) + | |
| 863 | - m_edisp.axis_lo(1, iobs)); | |
| 864 | - | |
| 865 | - // Initialise results | |
| 866 | - double logEsrcMin = -10.0; | |
| 867 | - double logEsrcMax = 30.0; | |
| 868 | - bool minFound = false; | |
| 869 | - bool maxFound = false; | |
| 870 | - | |
| 871 | - // Find boundaries, loop over Esrc | |
| 872 | - for (int i = 0; i < m_edisp.axis(0); ++i) { | |
| 873 | - | |
| 874 | - // Compute value of corresponding logEsrc | |
| 875 | - double Esrc = 0.5 * (m_edisp.axis_hi(0, i) + | |
| 876 | - m_edisp.axis_lo(0, i)); | |
| 877 | - double logEsrc = std::log10(Esrc); | |
| 878 | - | |
| 879 | - // Find first non-negligible matrix term | |
| 880 | - if (!minFound && m_edisp(0, logEsrc, EobsOverEsrc, theta) >= eps) { | |
| 881 | - minFound = true; | |
| 882 | - logEsrcMin = logEsrc; | |
| 883 | - } | |
| 884 | - | |
| 885 | - // Find last non-negligible matrix term | |
| 886 | - else if (minFound && !maxFound && | |
| 887 | - m_edisp(0, logEsrc, EobsOverEsrc, theta) < eps) { | |
| 888 | - maxFound = true; | |
| 889 | - logEsrcMax = logEsrc; | |
| 890 | - } | |
| 891 | - | |
| 892 | - // Continue | |
| 893 | - else if (minFound && maxFound && | |
| 894 | - m_edisp(0, logEsrc, EobsOverEsrc, theta) >= eps) { | |
| 895 | - maxFound = false; | |
| 896 | - } | |
| 897 | - | |
| 898 | - } // endfor: looped over true energy | |
| 899 | - | |
| 900 | - // If energy dispersion has never become negligible until end of loop, | |
| 901 | - // reset logEobsMax | |
| 902 | - if (!maxFound) { | |
| 903 | - logEsrcMax = 30.0; | |
| 904 | - } | |
| 905 | - | |
| 906 | - // Set energy boundaries | |
| 907 | - GEnergy emin; | |
| 908 | - GEnergy emax; | |
| 909 | - emin.log10TeV(logEsrcMin); | |
| 910 | - emax.log10TeV(logEsrcMax); | |
| 911 | - | |
| 912 | - // Add energy boundaries to vector | |
| 913 | - m_ebounds_src.push_back(GEbounds(emin, emax)); | |
| 914 | - | |
| 915 | - } | |
| 916 | - | |
| 917 | - const int step = m_edisp.axis(1) / m_edisp.axis(0); | |
| 918 | - | |
| 919 | - // Loop over EobsOverEsrc to create Eobs axis | |
| 920 | - for (int i = 0; i < m_edisp.axis(0); ++i) { | |
| 921 | - m_eobs_axis.push_back(m_edisp.axis_lo(1, i*step) * m_edisp.axis_lo(0, i)); | |
| 922 | - } | |
| 923 | -*/ | |
| 924 | - | |
| 925 | 767 | // Loop over Eobs |
| 926 | 768 | for (int iobs = 0; iobs < m_edisp.axis(0); ++iobs) { |
| 927 | 769 | |
| ... | ... | @@ -969,7 +811,6 @@ void GCTAEdisp2D::compute_ebounds_src(const double& theta, |
| 969 | 811 | logEsrcMax = 30.0; |
| 970 | 812 | } |
| 971 | 813 | |
| 972 | - | |
| 973 | 814 | // Set energy boundaries |
| 974 | 815 | GEnergy emin; |
| 975 | 816 | GEnergy emax; |
| ... | ... | @@ -981,97 +822,24 @@ void GCTAEdisp2D::compute_ebounds_src(const double& theta, |
| 981 | 822 | |
| 982 | 823 | } // endfor : loopend over observed energy |
| 983 | 824 | |
| 984 | - | |
| 985 | 825 | // Return |
| 986 | 826 | return; |
| 987 | 827 | } |
| 988 | 828 | |
| 989 | 829 | |
| 990 | 830 | /***********************************************************************//** |
| 991 | - * @brief Compute cumulative probability | |
| 992 | - * | |
| 993 | - ***************************************************************************/ | |
| 994 | -#if defined(G_CDF_METHOD) | |
| 995 | -void GCTAEdisp2D::compute_cumul(const double& theta, | |
| 996 | - const double& phi, | |
| 997 | - const double& zenith, | |
| 998 | - const double& azimuth) const | |
| 999 | -{ | |
| 1000 | - // TODO ? compute also for each theta ?? | |
| 1001 | - | |
| 1002 | - if (!m_cdf_computed) { | |
| 1003 | - | |
| 1004 | - m_cumul.clear(); | |
| 1005 | - | |
| 1006 | - //m_theta = theta; | |
| 1007 | - m_cdf_computed = true; | |
| 1008 | - | |
| 1009 | - // Loop over Esrc | |
| 1010 | - for (int isrc = 0; isrc < m_edisp.axis(0); ++isrc) { | |
| 1011 | - | |
| 1012 | - m_cumul.push_back(std::vector<std::pair<double, double> >()); | |
| 1013 | - | |
| 1014 | - //double Esrc = 0.5 * (m_edisp.axis_lo(0, isrc) + m_edisp.axis_hi(0, isrc)); | |
| 1015 | - double Esrc = m_edisp.axis_lo(0, isrc); | |
| 1016 | - | |
| 1017 | - // Initialize cumulative probability | |
| 1018 | - double sum = 0.0; | |
| 1019 | - | |
| 1020 | - // Divide bin into n sub-bins | |
| 1021 | - const int n = 10; | |
| 1022 | - | |
| 1023 | - // Loop over EobsOverEtrue | |
| 1024 | - for (int imigra = 0; imigra < m_edisp.axis(1); ++imigra) { | |
| 1025 | - | |
| 1026 | - // Compute delta(Eobs/Etrue) and Eobs/Etrue values | |
| 1027 | - double delta = m_edisp.axis_hi(1, imigra) - | |
| 1028 | - m_edisp.axis_lo(1, imigra); | |
| 1029 | - double EobsOverEsrcmin = m_edisp.axis_lo(1, imigra); | |
| 1030 | - | |
| 1031 | - for (int i = 0; i < n; ++i) { | |
| 1032 | - | |
| 1033 | - double EobsOverEsrc = EobsOverEsrcmin + i*delta/n; | |
| 1034 | - | |
| 1035 | - // Compute cumulative probability | |
| 1036 | - double add = m_edisp(0, std::log10(Esrc), EobsOverEsrc, theta) * | |
| 1037 | - delta / (n * EobsOverEsrc * gammalib::ln10); | |
| 1038 | - | |
| 1039 | - // Add to sum (and keep sum lower or equal to 1) | |
| 1040 | - sum = sum+add >= 1.0 ? 1.0 : sum+add; | |
| 1041 | - | |
| 1042 | - // Create pair containing EobsOverEsrc and cumulated probability | |
| 1043 | - std::pair<double, double> pair(EobsOverEsrc, sum); | |
| 1044 | - | |
| 1045 | - // Add to vector | |
| 1046 | - m_cumul[isrc].push_back(pair); | |
| 1047 | - | |
| 1048 | - } | |
| 1049 | - | |
| 1050 | - } // endfor: looped over EobsOverEsrc | |
| 1051 | - | |
| 1052 | - } | |
| 1053 | - | |
| 1054 | - } | |
| 1055 | - | |
| 1056 | - // Return | |
| 1057 | - return; | |
| 1058 | -} | |
| 1059 | -#endif | |
| 1060 | - | |
| 1061 | - | |
| 1062 | -/***********************************************************************//** | |
| 1063 | - * @brief Find maximum energy dispersion value | |
| 831 | + * @brief Set maximum energy dispersion value | |
| 1064 | 832 | ***************************************************************************/ |
| 1065 | -void GCTAEdisp2D::set_fmax(void) const | |
| 833 | +void GCTAEdisp2D::set_max_edisp(void) const | |
| 1066 | 834 | { |
| 1067 | 835 | // Initialise maximum |
| 1068 | - m_fmax = 0.0; | |
| 836 | + m_max_edisp = 0.0; | |
| 1069 | 837 | |
| 1070 | 838 | // Loop over all response table elements |
| 1071 | 839 | for (int i = 0; i < m_edisp.elements(); ++i) { |
| 1072 | 840 | double value = m_edisp(0,i); |
| 1073 | - if (value > m_fmax) { | |
| 1074 | - m_fmax = value; | |
| 841 | + if (value > m_max_edisp) { | |
| 842 | + m_max_edisp = value; | |
| 1075 | 843 | } |
| 1076 | 844 | } |
| 1077 | 845 | ... | ... |