Commit 24dbc9ae077ebd03eeff99d9acdd7dded7b02932
1 parent
44df8963
Add likelihood fit event selection hook (#3912)
Showing
4 changed files
with
36 additions
and
2 deletions
ChangeLog
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | * Version 2.0.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Add likelihood fit event selection hook (#3912) | |
| 6 | 7 | Add GCOMModelDRM class (#3910) |
| 7 | 8 | Add angle(GVector&,GVector&) friend function (#3908) |
| 8 | 9 | Make extension name check case insensitive in GFits::extno() | ... | ... |
NEWS
| ... | ... | @@ -248,6 +248,8 @@ of functions (#3328). |
| 248 | 248 | |
| 249 | 249 | 11. Observation module |
| 250 | 250 | ---------------------- |
| 251 | +Add likelihood fit event selection hook (#3912). | |
| 252 | + | |
| 251 | 253 | Add numerical gradient step size as member of GObservation to allow instrument- |
| 252 | 254 | specific step size values. |
| 253 | 255 | ... | ... |
doc/source/admin/release_history/2.0.rst
| ... | ... | @@ -36,6 +36,8 @@ Bug fixes |
| 36 | 36 | Improvements |
| 37 | 37 | ------------ |
| 38 | 38 | |
| 39 | +* [`3912 <https://cta-redmine.irap.omp.eu/issues/3912>`_] - | |
| 40 | + Add likelihood fit event selection hook | |
| 39 | 41 | * [`3908 <https://cta-redmine.irap.omp.eu/issues/3908>`_] - |
| 40 | 42 | Add ``angle(GVector&,GVector&)`` friend function |
| 41 | 43 | * Make extension name check case insensitive in ``GFits::extno()`` | ... | ... |
src/obs/GObservation.cpp
| ... | ... | @@ -1399,8 +1399,10 @@ double GObservation::likelihood_poisson_unbinned(const GModels& models, |
| 1399 | 1399 | // Iterate over all events |
| 1400 | 1400 | for (int i = 0; i < nevents; ++i) { |
| 1401 | 1401 | |
| 1402 | - // Get event pointer | |
| 1403 | - const GEvent* event = (*events())[i]; | |
| 1402 | + // Skip events that should not be used | |
| 1403 | + if (!use_event_for_likelihood(i)) { | |
| 1404 | + continue; | |
| 1405 | + } | |
| 1404 | 1406 | |
| 1405 | 1407 | // Get model value |
| 1406 | 1408 | double model = model_vector[i]; |
| ... | ... | @@ -1533,6 +1535,11 @@ double GObservation::likelihood_poisson_binned(const GModels& models, |
| 1533 | 1535 | // Iterate over all bins |
| 1534 | 1536 | for (int i = 0; i < nevents; ++i) { |
| 1535 | 1537 | |
| 1538 | + // Skip events that should not be used | |
| 1539 | + if (!use_event_for_likelihood(i)) { | |
| 1540 | + continue; | |
| 1541 | + } | |
| 1542 | + | |
| 1536 | 1543 | // Update number of bins |
| 1537 | 1544 | #if defined(G_OPT_DEBUG) |
| 1538 | 1545 | n_bins++; |
| ... | ... | @@ -1735,6 +1742,11 @@ double GObservation::likelihood_gaussian_binned(const GModels& models, |
| 1735 | 1742 | // Iterate over all bins |
| 1736 | 1743 | for (int i = 0; i < nevents; ++i) { |
| 1737 | 1744 | |
| 1745 | + // Skip events that should not be used | |
| 1746 | + if (!use_event_for_likelihood(i)) { | |
| 1747 | + continue; | |
| 1748 | + } | |
| 1749 | + | |
| 1738 | 1750 | // Get event pointer |
| 1739 | 1751 | const GEventBin* bin = |
| 1740 | 1752 | (*(static_cast<GEventCube*>(const_cast<GEvents*>(events()))))[i]; |
| ... | ... | @@ -1824,6 +1836,23 @@ double GObservation::likelihood_gaussian_binned(const GModels& models, |
| 1824 | 1836 | } |
| 1825 | 1837 | |
| 1826 | 1838 | |
| 1839 | +/***********************************************************************//** | |
| 1840 | + * @brief Check whether bin should be used for likelihood analysis | |
| 1841 | + * | |
| 1842 | + * @param[in] index Event index. | |
| 1843 | + * @return True. | |
| 1844 | + * | |
| 1845 | + * This is a dummy virtual method that allows implementation of a hook for | |
| 1846 | + * event selection in the likelihood computation. The dummy method always | |
| 1847 | + * returns true. | |
| 1848 | + ***************************************************************************/ | |
| 1849 | +bool GObservation::use_event_for_likelihood(const int& index) const | |
| 1850 | +{ | |
| 1851 | + // Return true | |
| 1852 | + return true; | |
| 1853 | +} | |
| 1854 | + | |
| 1855 | + | |
| 1827 | 1856 | /*========================================================================== |
| 1828 | 1857 | = = |
| 1829 | 1858 | = Model gradient methods = | ... | ... |