Commit 33193185188a8893ec36a2863afa71b902fde3b2
1 parent
ed0d4b4b
Updated ctmodel (#2189)
Implemented a change to remove all models that dont overlap the current observation when filling the cube. This speeds up the computation when filling from a large number of models.
Showing
2 changed files
with
50 additions
and
2 deletions
src/ctmodel/ctmodel.cpp
| ... | ... | @@ -820,7 +820,8 @@ void ctmodel::fill_cube(const GCTAObservation* obs) |
| 820 | 820 | |
| 821 | 821 | // Extract copy of models from observation container |
| 822 | 822 | GModels models(m_obs.models()); |
| 823 | - | |
| 823 | + trim_models(models, roi); | |
| 824 | + | |
| 824 | 825 | // Get pointer to event cube pixels |
| 825 | 826 | double* pixels = const_cast<double*>(m_cube.counts().pixels()); |
| 826 | 827 | |
| ... | ... | @@ -905,3 +906,49 @@ void ctmodel::fill_cube(const GCTAObservation* obs) |
| 905 | 906 | // Return |
| 906 | 907 | return; |
| 907 | 908 | } |
| 909 | + | |
| 910 | + | |
| 911 | +/***********************************************************************//** | |
| 912 | + * @brief Remove the models falling outside a defined region of interest | |
| 913 | + * | |
| 914 | + * @param[out] models Model container to be trimmed | |
| 915 | + * @param[in] roi Observation region of interest | |
| 916 | + ***************************************************************************/ | |
| 917 | +void ctmodel::trim_models(GModels& models, const GCTARoi& roi) | |
| 918 | +{ | |
| 919 | + // Do nothing if roi is not valid. This will be the case for binned data | |
| 920 | + // sets as they have the default roi radius of 0. In this case we would | |
| 921 | + // remove ALL models, which is obviously incorrect. So we keep all models | |
| 922 | + // when filling based on a counts cube. | |
| 923 | + if (!roi.is_valid()) { | |
| 924 | + return; | |
| 925 | + } | |
| 926 | + | |
| 927 | + // Remove all models that dont overlap with the region of interest. Note | |
| 928 | + // that an extra factor of 0.5 is used since point sources have regions | |
| 929 | + // of radius 0, which is a problem when they fall just barely outside the | |
| 930 | + // ROI. This ensures point sources are appropriately included. | |
| 931 | + GSkyRegionCircle obsreg( | |
| 932 | + roi.centre().dir().ra_deg(), | |
| 933 | + roi.centre().dir().dec_deg(), | |
| 934 | + roi.radius()+0.5); | |
| 935 | + | |
| 936 | + // Loop over the models in the passed container | |
| 937 | + for (int mod=0; mod<models.size(); mod++) { | |
| 938 | + GModelSky* model = dynamic_cast<GModelSky*>(models.at(mod)); | |
| 939 | + | |
| 940 | + if (model == NULL) { | |
| 941 | + // Model is most likely a background model and should be kept | |
| 942 | + continue; | |
| 943 | + } else if (!model->spatial()->region()->overlaps(obsreg)) { | |
| 944 | + // Model represents a source, does not overlap the observation | |
| 945 | + // and should be removed. | |
| 946 | + models.remove(mod); | |
| 947 | + | |
| 948 | + // Decrement the index variable to prevent skipping the next model | |
| 949 | + mod--; | |
| 950 | + } | |
| 951 | + } | |
| 952 | + | |
| 953 | + return; | |
| 954 | +} | ... | ... |
src/ctmodel/ctmodel.hpp
| ... | ... | @@ -82,7 +82,8 @@ protected: |
| 82 | 82 | void extract_cube_properties(void); |
| 83 | 83 | void fill_cube(const GCTAObservation* obs); |
| 84 | 84 | bool has_cube(void) const; |
| 85 | - | |
| 85 | + void trim_models(GModels& models, const GCTARoi& roi); | |
| 86 | + | |
| 86 | 87 | // User parameters |
| 87 | 88 | GFilename m_outcube; //!< Output model cube |
| 88 | 89 | bool m_apply_edisp; //!< Apply energy dispersion? | ... | ... |