Commit 4a9ae7e1ce088f24e40dc014f6916a5985df910c
1 parent
cee203af
Integrate code
Showing
5 changed files
with
139 additions
and
143 deletions
include/GRmf.hpp
| ... | ... | @@ -65,6 +65,8 @@ public: |
| 65 | 65 | int size(void) const; |
| 66 | 66 | int ntrue(void) const; |
| 67 | 67 | int nmeasured(void) const; |
| 68 | + int itruemax(void) const; | |
| 69 | + int imeasmax(void) const; | |
| 68 | 70 | double& at(const int& itrue, const int& imeasured); |
| 69 | 71 | const double& at(const int& itrue, const int& imeasured) const; |
| 70 | 72 | const GEbounds& etrue(void) const; |
| ... | ... | @@ -81,8 +83,6 @@ public: |
| 81 | 83 | const std::string& unit = "keV") const; |
| 82 | 84 | const std::string& filename(void) const; |
| 83 | 85 | std::string print(const GChatter& chatter = NORMAL) const; |
| 84 | - int itruemax(void) const; | |
| 85 | - int imeasmax(void) const; | |
| 86 | 86 | |
| 87 | 87 | protected: |
| 88 | 88 | // Protected methods |
| ... | ... | @@ -95,8 +95,8 @@ protected: |
| 95 | 95 | GEbounds m_ebds_true; //!< True energy boundaries |
| 96 | 96 | GEbounds m_ebds_measured; //!< Measured energy boundaries |
| 97 | 97 | GMatrixSparse m_matrix; //!< Sparse redistribution matrix |
| 98 | - mutable int m_imeasmax; | |
| 99 | - mutable int m_itruemax; | |
| 98 | + int m_imeasmax; //!< Index of measured maximum | |
| 99 | + int m_itruemax; //!< Index of true maximum | |
| 100 | 100 | |
| 101 | 101 | }; |
| 102 | 102 | |
| ... | ... | @@ -187,6 +187,36 @@ int GRmf::nmeasured(void) const |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
| 190 | + | |
| 191 | + | |
| 192 | +/***********************************************************************//** | |
| 193 | + * @brief Return true energy index of maximum value of the redistribution matrix | |
| 194 | + * | |
| 195 | + * @return True energy index of maximum value of the redistribution matrix. | |
| 196 | + * | |
| 197 | + * Returns the true energy index of maximum value of the redistribution matrix. | |
| 198 | + ***************************************************************************/ | |
| 199 | +inline | |
| 200 | +int GRmf::itruemax(void) const | |
| 201 | +{ | |
| 202 | + return m_itruemax; | |
| 203 | +} | |
| 204 | + | |
| 205 | + | |
| 206 | +/***********************************************************************//** | |
| 207 | + * @brief Return measured energy index of maximum value of the redistribution matrix | |
| 208 | + * | |
| 209 | + * @return Measured energy index of maximum value of the redistribution matrix. | |
| 210 | + * | |
| 211 | + * Returns the measured energy index of maximum value of the redistribution matrix. | |
| 212 | + ***************************************************************************/ | |
| 213 | +inline | |
| 214 | +int GRmf::imeasmax(void) const | |
| 215 | +{ | |
| 216 | + return m_imeasmax; | |
| 217 | +} | |
| 218 | + | |
| 219 | + | |
| 190 | 220 | /***********************************************************************//** |
| 191 | 221 | * @brief Return true energy boundaries |
| 192 | 222 | * |
| ... | ... | @@ -243,31 +273,4 @@ const std::string& GRmf::filename(void) const |
| 243 | 273 | return (m_filename); |
| 244 | 274 | } |
| 245 | 275 | |
| 246 | - | |
| 247 | -/***********************************************************************//** | |
| 248 | - * @brief Return true energy index of maximum value of the redistribution matrix | |
| 249 | - * | |
| 250 | - * @return True energy index of maximum value of the redistribution matrix. | |
| 251 | - * | |
| 252 | - * Returns the true energy index of maximum value of the redistribution matrix. | |
| 253 | - ***************************************************************************/ | |
| 254 | -inline | |
| 255 | -int GRmf::itruemax(void) const | |
| 256 | -{ | |
| 257 | - return m_itruemax; | |
| 258 | -} | |
| 259 | - | |
| 260 | -/***********************************************************************//** | |
| 261 | - * @brief Return measured energy index of maximum value of the redistribution matrix | |
| 262 | - * | |
| 263 | - * @return Measured energy index of maximum value of the redistribution matrix. | |
| 264 | - * | |
| 265 | - * Returns the measured energy index of maximum value of the redistribution matrix. | |
| 266 | - ***************************************************************************/ | |
| 267 | -inline | |
| 268 | -int GRmf::imeasmax(void) const | |
| 269 | -{ | |
| 270 | - return m_imeasmax; | |
| 271 | -} | |
| 272 | - | |
| 273 | 276 | #endif /* GRMF_HPP */ | ... | ... |
inst/cta/include/GCTAEdisp2D.hpp
| ... | ... | @@ -121,6 +121,7 @@ private: |
| 121 | 121 | std::string m_filename; //!< Name of Edisp response file |
| 122 | 122 | GCTAResponseTable m_edisp; //!< Edisp response table |
| 123 | 123 | |
| 124 | + // Monte Carlo cache | |
| 124 | 125 | mutable bool m_cdf_computed; |
| 125 | 126 | mutable double m_theta; |
| 126 | 127 | mutable bool m_ebounds_obs_computed; |
| ... | ... | @@ -131,11 +132,11 @@ private: |
| 131 | 132 | mutable int m_index_src; |
| 132 | 133 | mutable double m_fmax; |
| 133 | 134 | |
| 134 | - mutable std::vector<GEbounds> m_ebounds_obs; | |
| 135 | - mutable std::vector<GEbounds> m_ebounds_src; | |
| 135 | + mutable std::vector<GEbounds> m_ebounds_obs; | |
| 136 | + mutable std::vector<GEbounds> m_ebounds_src; | |
| 136 | 137 | mutable std::vector<std::vector<std::pair<double, double> > > m_cumul; |
| 137 | - mutable std::vector<double> m_eobs_axis; | |
| 138 | - mutable std::vector<std::vector<double> > m_temp; | |
| 138 | + mutable std::vector<double> m_eobs_axis; | |
| 139 | + mutable std::vector<std::vector<double> > m_temp; | |
| 139 | 140 | }; |
| 140 | 141 | |
| 141 | 142 | ... | ... |
inst/cta/include/GCTAEdispRmf.hpp
| ... | ... | @@ -141,12 +141,12 @@ private: |
| 141 | 141 | mutable double m_logEobs; |
| 142 | 142 | mutable std::vector<std::vector<std::pair<double, double> > > m_cumul; |
| 143 | 143 | |
| 144 | - mutable bool m_ebounds_obs_computed; | |
| 144 | + mutable bool m_ebounds_obs_computed; | |
| 145 | 145 | mutable std::vector<GEbounds> m_ebounds_obs; |
| 146 | - mutable int m_index_obs; | |
| 147 | - mutable bool m_ebounds_src_computed; | |
| 146 | + mutable int m_index_obs; | |
| 147 | + mutable bool m_ebounds_src_computed; | |
| 148 | 148 | mutable std::vector<GEbounds> m_ebounds_src; |
| 149 | - mutable int m_index_src; | |
| 149 | + mutable int m_index_src; | |
| 150 | 150 | |
| 151 | 151 | }; |
| 152 | 152 | ... | ... |
inst/cta/src/GCTAEdisp2D.cpp
| ... | ... | @@ -327,25 +327,19 @@ void GCTAEdisp2D::read(const GFits& fits) |
| 327 | 327 | // Set offset angle axis to radians |
| 328 | 328 | m_edisp.axis_radians(2); |
| 329 | 329 | |
| 330 | - | |
| 331 | -// for (int i_theta = 0; i_theta < theta_size; ++i_theta) { | |
| 332 | - | |
| 333 | - m_temp.clear(); | |
| 334 | - | |
| 335 | - int step = migra_size / etrue_size; | |
| 336 | - | |
| 337 | - for (int itrue = 0; itrue < etrue_size; ++itrue) { | |
| 338 | - double logEsrc = std::log10(0.5 * (m_edisp.axis_hi(0, itrue) + | |
| 339 | - m_edisp.axis_lo(0, itrue))); | |
| 340 | - m_temp.push_back(std::vector<double>()); | |
| 341 | - for (int iobs = 0; iobs < etrue_size; ++iobs) { | |
| 342 | - double EobsOverEsrc = 0.5 * (m_edisp.axis_hi(1, iobs*step) + | |
| 343 | - m_edisp.axis_lo(1, iobs*step)); | |
| 344 | - m_temp[itrue].push_back(operator()(logEsrc, EobsOverEsrc)); | |
| 345 | - } | |
| 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)); | |
| 346 | 341 | } |
| 347 | - | |
| 348 | - // } | |
| 342 | + } | |
| 349 | 343 | |
| 350 | 344 | // Return |
| 351 | 345 | return; |
| ... | ... | @@ -395,56 +389,6 @@ void GCTAEdisp2D::save(const std::string& filename, const bool& clobber) const |
| 395 | 389 | return; |
| 396 | 390 | } |
| 397 | 391 | |
| 398 | -/***********************************************************************//** | |
| 399 | - * @brief Find maximum energy dispersion | |
| 400 | - * | |
| 401 | -***************************************************************************/ | |
| 402 | -void GCTAEdisp2D::set_fmax(void) const | |
| 403 | -{ | |
| 404 | - | |
| 405 | - double max = 0.0; | |
| 406 | - | |
| 407 | - // Loop over Esrc | |
| 408 | - for (int i = 0; i < m_edisp.axis(0); ++i) { | |
| 409 | - | |
| 410 | - // Set Esrc | |
| 411 | - double Esrc = 0.5 * (m_edisp.axis_hi(0, i) + | |
| 412 | - m_edisp.axis_lo(0, i)); | |
| 413 | - double logEsrc = std::log10(Esrc); | |
| 414 | - | |
| 415 | - // Loop over EobsOverEsrc | |
| 416 | - for (int j = 0; j < m_edisp.axis(1); ++j) { | |
| 417 | - | |
| 418 | - // Set EobsOverEsrc | |
| 419 | - double EobsOverEsrc = 0.5 * (m_edisp.axis_hi(1, j) + | |
| 420 | - m_edisp.axis_lo(1, j)); | |
| 421 | -/* | |
| 422 | - // Loop over theta | |
| 423 | - for (int k = 0; k < m_edisp.axis(2); ++k) { | |
| 424 | - | |
| 425 | - // Set theta | |
| 426 | - double theta = 0.5 * (m_edisp.axis_hi(2, k) + | |
| 427 | - m_edisp.axis_lo(2, k)); | |
| 428 | - | |
| 429 | - double test = operator()(logEsrc, EobsOverEsrc, theta); | |
| 430 | -*/ | |
| 431 | - double test = operator()(logEsrc, EobsOverEsrc); | |
| 432 | - if (max < test) { | |
| 433 | - max = test; | |
| 434 | - } | |
| 435 | -/* | |
| 436 | - } // endfor: looped over theta | |
| 437 | -*/ | |
| 438 | - } // endfor: looped over EobsOverEsrc | |
| 439 | - | |
| 440 | - } // endfor: looped over Esrc | |
| 441 | - | |
| 442 | - // Set fmax | |
| 443 | - m_fmax = max; | |
| 444 | - | |
| 445 | - // Return | |
| 446 | - return; | |
| 447 | -} | |
| 448 | 392 | |
| 449 | 393 | /***********************************************************************//** |
| 450 | 394 | * @brief Simulate energy dispersion |
| ... | ... | @@ -479,7 +423,6 @@ GEnergy GCTAEdisp2D::mc(GRan& ran, |
| 479 | 423 | if (m_fmax == -1.0) { |
| 480 | 424 | set_fmax(); |
| 481 | 425 | } |
| 482 | - | |
| 483 | 426 | double fmax = m_fmax; |
| 484 | 427 | |
| 485 | 428 | // Find energy by rejection method |
| ... | ... | @@ -493,9 +436,9 @@ GEnergy GCTAEdisp2D::mc(GRan& ran, |
| 493 | 436 | ftest = ran.uniform() * fmax; |
| 494 | 437 | } |
| 495 | 438 | |
| 439 | + // Set energy | |
| 496 | 440 | energy.log10TeV(e); |
| 497 | 441 | |
| 498 | - | |
| 499 | 442 | // Return energy |
| 500 | 443 | return energy; |
| 501 | 444 | |
| ... | ... | @@ -760,23 +703,22 @@ void GCTAEdisp2D::init_members(void) |
| 760 | 703 | m_edisp.clear(); |
| 761 | 704 | |
| 762 | 705 | // Initialise Monte Carlo cache |
| 763 | - m_theta = 0.0; | |
| 764 | - m_logEsrc =-30.0; | |
| 765 | - m_logEobs =-30.0; | |
| 766 | - m_fmax = -1.0; | |
| 767 | - m_index_obs = 0; | |
| 768 | - m_index_src = 0; | |
| 769 | - m_cdf_computed = false; | |
| 706 | + m_theta = 0.0; | |
| 707 | + m_logEsrc = -30.0; | |
| 708 | + m_logEobs = -30.0; | |
| 709 | + m_fmax = -1.0; | |
| 710 | + m_index_obs = 0; | |
| 711 | + m_index_src = 0; | |
| 712 | + m_cdf_computed = false; | |
| 770 | 713 | m_ebounds_obs_computed = false; |
| 771 | 714 | m_ebounds_src_computed = false; |
| 772 | 715 | |
| 773 | - m_cumul.clear(); | |
| 774 | - | |
| 775 | - // Initialize ebounds | |
| 716 | + // Initialize vectors | |
| 776 | 717 | m_ebounds_obs.clear(); |
| 777 | 718 | m_ebounds_src.clear(); |
| 778 | - | |
| 719 | + m_cumul.clear(); | |
| 779 | 720 | m_eobs_axis.clear(); |
| 721 | + m_temp.clear(); | |
| 780 | 722 | |
| 781 | 723 | // Return |
| 782 | 724 | return; |
| ... | ... | @@ -793,17 +735,22 @@ void GCTAEdisp2D::copy_members(const GCTAEdisp2D& edisp) |
| 793 | 735 | // Copy members |
| 794 | 736 | m_filename = edisp.m_filename; |
| 795 | 737 | m_edisp = edisp.m_edisp; |
| 796 | - m_theta = edisp.m_theta; | |
| 797 | - m_logEsrc = edisp.m_logEsrc; | |
| 798 | - m_logEobs = edisp.m_logEobs; | |
| 799 | - m_index_obs = edisp.m_index_obs; | |
| 800 | - m_index_src = edisp.m_index_src; | |
| 801 | - | |
| 802 | - m_ebounds_obs = edisp.m_ebounds_obs; | |
| 803 | - m_ebounds_src = edisp.m_ebounds_src; | |
| 804 | - m_cumul = edisp.m_cumul; | |
| 805 | - m_eobs_axis = edisp.m_eobs_axis; | |
| 806 | - m_temp = edisp.m_temp; | |
| 738 | + | |
| 739 | + // Copy Monte Carlo cache | |
| 740 | + m_theta = edisp.m_theta; | |
| 741 | + m_logEsrc = edisp.m_logEsrc; | |
| 742 | + m_logEobs = edisp.m_logEobs; | |
| 743 | + m_fmax = edisp.m_fmax; | |
| 744 | + m_index_obs = edisp.m_index_obs; | |
| 745 | + m_index_src = edisp.m_index_src; | |
| 746 | + m_cdf_computed = edisp.m_cdf_computed; | |
| 747 | + m_ebounds_obs_computed = edisp.m_ebounds_obs_computed; | |
| 748 | + m_ebounds_src_computed = edisp.m_ebounds_src_computed; | |
| 749 | + m_ebounds_obs = edisp.m_ebounds_obs; | |
| 750 | + m_ebounds_src = edisp.m_ebounds_src; | |
| 751 | + m_cumul = edisp.m_cumul; | |
| 752 | + m_eobs_axis = edisp.m_eobs_axis; | |
| 753 | + m_temp = edisp.m_temp; | |
| 807 | 754 | |
| 808 | 755 | // Return |
| 809 | 756 | return; |
| ... | ... | @@ -1118,3 +1065,41 @@ void GCTAEdisp2D::compute_cumul(const double& theta, |
| 1118 | 1065 | return; |
| 1119 | 1066 | } |
| 1120 | 1067 | #endif |
| 1068 | + | |
| 1069 | + | |
| 1070 | +/***********************************************************************//** | |
| 1071 | + * @brief Find maximum energy dispersion | |
| 1072 | + ***************************************************************************/ | |
| 1073 | +void GCTAEdisp2D::set_fmax(void) const | |
| 1074 | +{ | |
| 1075 | + // Initialise maximum | |
| 1076 | + double max = 0.0; | |
| 1077 | + | |
| 1078 | + // Loop over Esrc | |
| 1079 | + for (int i = 0; i < m_edisp.axis(0); ++i) { | |
| 1080 | + | |
| 1081 | + // Set Esrc | |
| 1082 | + double Esrc = 0.5 * (m_edisp.axis_hi(0,i) + m_edisp.axis_lo(0,i)); | |
| 1083 | + double logEsrc = std::log10(Esrc); | |
| 1084 | + | |
| 1085 | + // Loop over EobsOverEsrc | |
| 1086 | + for (int j = 0; j < m_edisp.axis(1); ++j) { | |
| 1087 | + | |
| 1088 | + // Set EobsOverEsrc | |
| 1089 | + double EobsOverEsrc = 0.5 * (m_edisp.axis_hi(1, j) + | |
| 1090 | + m_edisp.axis_lo(1, j)); | |
| 1091 | + double test = operator()(logEsrc, EobsOverEsrc); | |
| 1092 | + if (max < test) { | |
| 1093 | + max = test; | |
| 1094 | + } | |
| 1095 | + | |
| 1096 | + } // endfor: looped over EobsOverEsrc | |
| 1097 | + | |
| 1098 | + } // endfor: looped over Esrc | |
| 1099 | + | |
| 1100 | + // Set fmax | |
| 1101 | + m_fmax = max; | |
| 1102 | + | |
| 1103 | + // Return | |
| 1104 | + return; | |
| 1105 | +} | ... | ... |
inst/cta/src/GCTAEdispRmf.cpp
| ... | ... | @@ -715,18 +715,17 @@ void GCTAEdispRmf::init_members(void) |
| 715 | 715 | // Initialise Monte Carlo cache |
| 716 | 716 | m_mc_measured_start.clear(); |
| 717 | 717 | m_mc_measured_cdf.clear(); |
| 718 | - m_cdf_computed = false; | |
| 719 | - m_theta = 0.0; | |
| 720 | - m_logEsrc = -30.0; | |
| 721 | - m_logEobs = -30.0; | |
| 718 | + m_cdf_computed = false; | |
| 719 | + m_theta = 0.0; | |
| 720 | + m_logEsrc = -30.0; | |
| 721 | + m_logEobs = -30.0; | |
| 722 | 722 | m_cumul.clear(); |
| 723 | - | |
| 724 | 723 | m_ebounds_obs_computed = false; |
| 725 | 724 | m_ebounds_obs.clear(); |
| 726 | - m_index_obs = 0; | |
| 725 | + m_index_obs = 0; | |
| 727 | 726 | m_ebounds_src_computed = false; |
| 728 | 727 | m_ebounds_src.clear(); |
| 729 | - m_index_src = 0; | |
| 728 | + m_index_src = 0; | |
| 730 | 729 | |
| 731 | 730 | // Return |
| 732 | 731 | return; |
| ... | ... | @@ -760,11 +759,19 @@ void GCTAEdispRmf::copy_members(const GCTAEdispRmf& edisp) |
| 760 | 759 | m_wgt4 = edisp.m_wgt4; |
| 761 | 760 | |
| 762 | 761 | // Copy Monte Carlo cache |
| 763 | - m_mc_measured_start = edisp.m_mc_measured_start; | |
| 764 | - m_mc_measured_cdf = edisp.m_mc_measured_cdf; | |
| 765 | - m_theta = edisp.m_theta; | |
| 766 | - m_cumul = edisp.m_cumul; | |
| 767 | - m_cdf_computed = edisp.m_cdf_computed; | |
| 762 | + m_mc_measured_start = edisp.m_mc_measured_start; | |
| 763 | + m_mc_measured_cdf = edisp.m_mc_measured_cdf; | |
| 764 | + m_cdf_computed = edisp.m_cdf_computed; | |
| 765 | + m_theta = edisp.m_theta; | |
| 766 | + m_logEsrc = edisp.m_logEsrc; | |
| 767 | + m_logEobs = edisp.m_logEobs; | |
| 768 | + m_cumul = edisp.m_cumul; | |
| 769 | + m_ebounds_obs_computed = edisp.m_ebounds_obs_computed; | |
| 770 | + m_ebounds_obs = edisp.m_ebounds_obs; | |
| 771 | + m_index_obs = edisp.m_index_obs; | |
| 772 | + m_ebounds_src_computed = edisp.m_ebounds_src_computed; | |
| 773 | + m_ebounds_src = edisp.m_ebounds_src; | |
| 774 | + m_index_src = edisp.m_index_src; | |
| 768 | 775 | |
| 769 | 776 | // Return |
| 770 | 777 | return; | ... | ... |