Commit b33b0f65c74a9749628ce3d692abcae29ed28c1e
1 parent
45ed9e48
Correct MC simulations for normalized phase curves (#2172)
Showing
3 changed files
with
14 additions
and
8 deletions
ChangeLog
| 1 | -2017-07-27 | 1 | +2017-07-28 |
| 2 | 2 | ||
| 3 | * Version 1.4.0 released | 3 | * Version 1.4.0 released |
| 4 | ========================= | 4 | ========================= |
| 5 | 5 | ||
| 6 | Add GCTAEventBin::ipix() and ieng() setter methods (#2171) | 6 | Add GCTAEventBin::ipix() and ieng() setter methods (#2171) |
| 7 | Write response information into simulated observation definition file (#2170) | 7 | Write response information into simulated observation definition file (#2170) |
| 8 | - Normalise phase curves by default (#2154) | 8 | + Normalise phase curves by default (#2154, #2172) |
| 9 | Support Python list slicing for container classes (#2128) | 9 | Support Python list slicing for container classes (#2128) |
| 10 | Add GSkyRegions::overlaps() and GSkyMap::overlaps() classes (#1980) | 10 | Add GSkyRegions::overlaps() and GSkyMap::overlaps() classes (#1980) |
| 11 | 11 |
include/GModelTemporalPhaseCurve.hpp
| @@ -144,9 +144,10 @@ protected: | @@ -144,9 +144,10 @@ protected: | ||
| 144 | bool m_has_normalize; //!< XML has normalize attribute | 144 | bool m_has_normalize; //!< XML has normalize attribute |
| 145 | 145 | ||
| 146 | // Protected members | 146 | // Protected members |
| 147 | - mutable GNodeArray m_nodes; //!< Phase values of nodes | ||
| 148 | - std::vector<double> m_values; //!< Function values at nodes | ||
| 149 | - GFilename m_filename; //!< Name of phase file function | 147 | + mutable GNodeArray m_nodes; //!< Phase values of nodes |
| 148 | + std::vector<double> m_values; //!< Function values at nodes | ||
| 149 | + double m_scale; //!< Scale factor due to normalization | ||
| 150 | + GFilename m_filename; //!< Name of phase file function | ||
| 150 | }; | 151 | }; |
| 151 | 152 | ||
| 152 | 153 |
src/model/GModelTemporalPhaseCurve.cpp
| @@ -316,7 +316,7 @@ GTimes GModelTemporalPhaseCurve::mc(const double& rate, const GTime& tmin, | @@ -316,7 +316,7 @@ GTimes GModelTemporalPhaseCurve::mc(const double& rate, const GTime& tmin, | ||
| 316 | GTimes times; | 316 | GTimes times; |
| 317 | 317 | ||
| 318 | // Compute event rate (in events per seconds) | 318 | // Compute event rate (in events per seconds) |
| 319 | - double lambda = rate * norm(); | 319 | + double lambda = rate * norm() * m_scale; |
| 320 | 320 | ||
| 321 | // Initialise start and stop times in seconds | 321 | // Initialise start and stop times in seconds |
| 322 | double time = tmin.secs(); | 322 | double time = tmin.secs(); |
| @@ -341,7 +341,7 @@ GTimes GModelTemporalPhaseCurve::mc(const double& rate, const GTime& tmin, | @@ -341,7 +341,7 @@ GTimes GModelTemporalPhaseCurve::mc(const double& rate, const GTime& tmin, | ||
| 341 | double value = eval(srcTime); | 341 | double value = eval(srcTime); |
| 342 | 342 | ||
| 343 | // Get uniform random number | 343 | // Get uniform random number |
| 344 | - double uniform = ran.uniform(); | 344 | + double uniform = ran.uniform() * m_scale; |
| 345 | 345 | ||
| 346 | // If the random number is not larger than the phase curve value | 346 | // If the random number is not larger than the phase curve value |
| 347 | // then accept the time | 347 | // then accept the time |
| @@ -686,6 +686,7 @@ void GModelTemporalPhaseCurve::init_members(void) | @@ -686,6 +686,7 @@ void GModelTemporalPhaseCurve::init_members(void) | ||
| 686 | m_nodes.clear(); | 686 | m_nodes.clear(); |
| 687 | m_values.clear(); | 687 | m_values.clear(); |
| 688 | m_filename.clear(); | 688 | m_filename.clear(); |
| 689 | + m_scale = 1.0; | ||
| 689 | m_normalize = true; | 690 | m_normalize = true; |
| 690 | m_has_normalize = false; | 691 | m_has_normalize = false; |
| 691 | 692 | ||
| @@ -711,6 +712,7 @@ void GModelTemporalPhaseCurve::copy_members(const GModelTemporalPhaseCurve& mode | @@ -711,6 +712,7 @@ void GModelTemporalPhaseCurve::copy_members(const GModelTemporalPhaseCurve& mode | ||
| 711 | m_nodes = model.m_nodes; | 712 | m_nodes = model.m_nodes; |
| 712 | m_values = model.m_values; | 713 | m_values = model.m_values; |
| 713 | m_filename = model.m_filename; | 714 | m_filename = model.m_filename; |
| 715 | + m_scale = model.m_scale; | ||
| 714 | m_normalize = model.m_normalize; | 716 | m_normalize = model.m_normalize; |
| 715 | m_has_normalize = model.m_has_normalize; | 717 | m_has_normalize = model.m_has_normalize; |
| 716 | 718 | ||
| @@ -909,9 +911,12 @@ void GModelTemporalPhaseCurve::normalize_nodes(void) | @@ -909,9 +911,12 @@ void GModelTemporalPhaseCurve::normalize_nodes(void) | ||
| 909 | throw GException::invalid_value(G_NORMALISE_NODES, msg); | 911 | throw GException::invalid_value(G_NORMALISE_NODES, msg); |
| 910 | } | 912 | } |
| 911 | 913 | ||
| 914 | + // Set scale factor | ||
| 915 | + m_scale = 1.0 / sum; | ||
| 916 | + | ||
| 912 | // Normalise the node values | 917 | // Normalise the node values |
| 913 | for (int i = 0; i < m_values.size(); ++i) { | 918 | for (int i = 0; i < m_values.size(); ++i) { |
| 914 | - m_values[i] /= sum; | 919 | + m_values[i] *= m_scale; |
| 915 | } | 920 | } |
| 916 | 921 | ||
| 917 | // Return | 922 | // Return |