diff --git a/ChangeLog b/ChangeLog index 65bf1cd..1f17178 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2017-08-08 +2017-08-11 * Version 1.5.0 released ======================== + Enhance efficiency of computations in ctmodel (#2189) Use t-type parameters for all "tmin" and "tmax" parameters (#1864) diff --git a/NEWS b/NEWS index 2940dcf..08e26a6 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.5.0 -8 August 2017 +11 October 2017 Introduction @@ -61,6 +61,11 @@ ctmodel - CTA counts cube modelling Use t-type parameters for "tmin" and "tmax" to all specifying times in various formats (#1864). +The tool now also checks which models actually overlap with the RoI of a given +observation and then only use these models to compute the model cube. The +parallelization of the tool has also been optimised so that diffuse models are +not loaded over and over again (#2189). + ctexpcube - CTA exposure cube generation ---------------------------------------- diff --git a/doc/source/admin/release_history/1.5.rst b/doc/source/admin/release_history/1.5.rst index 9e4ab6b..95611b0 100644 --- a/doc/source/admin/release_history/1.5.rst +++ b/doc/source/admin/release_history/1.5.rst @@ -22,7 +22,8 @@ Bug fixes Improvements ------------ -* TBW +* [`2189 `_] - + Enhance efficiency of computations in :ref:`ctmodel` New features diff --git a/src/ctmodel/ctmodel.cpp b/src/ctmodel/ctmodel.cpp index c4fb162..5be5ff0 100644 --- a/src/ctmodel/ctmodel.cpp +++ b/src/ctmodel/ctmodel.cpp @@ -920,9 +920,9 @@ void ctmodel::fill_cube(const GCTAObservation* obs, GModels& models) /***********************************************************************//** * @brief Find the models falling inside a defined region of interest. * - * @param[out] all_models Model container to be trimmed - * @param[in] roi Observation region of interest - * @return New model container contianing only models inside roi + * @param[in,out] all_models Model container to be trimmed. + * @param[in] roi Observation region of interest. + * @return New model container containing only models inside RoI. * * Note that a buffer is added to the observation region to ensure that * point sources (which have radius=0) are appropriately included if they @@ -930,9 +930,9 @@ void ctmodel::fill_cube(const GCTAObservation* obs, GModels& models) ***************************************************************************/ GModels ctmodel::trim_models(GModels& all_models, const GCTARoi& roi) { - // Create the model object to be returned + // Create the model container containing only models in RoI GModels excluded_models; - + // Do nothing if roi is not valid. This will be the case for binned data // sets as they have the default roi radius of 0. In this case we would // remove ALL models, which is obviously incorrect. So we keep all models @@ -940,35 +940,41 @@ GModels ctmodel::trim_models(GModels& all_models, const GCTARoi& roi) if (!roi.is_valid()) { return excluded_models; } - + // Remove all models that dont overlap with the region of interest. Note // that an extra factor is used since point sources have regions of // radius 0, which is a problem when they fall just barely outside the - // ROI. This ensures point sources are appropriately included. + // RoI. This ensures point sources are appropriately included. GSkyRegionCircle obsreg(roi.centre().dir(), roi.radius()+0.5); - + // Loop over the models in the passed container - for (int mod=0; mod(all_models.at(mod)->clone()); - + GModelSky* model = dynamic_cast(all_models[i]); + + // If model is not a GModelSky model than skip if (model == NULL) { - // Model is most likely a background model and should be kept continue; } + // Otherwise, exclude the model if it isn't a diffuse cube and it // doesn't overlap with the observation. - else if (!(model->spatial()->code() == GMODEL_SPATIAL_DIFFUSE) && + if (!(model->spatial()->code() == GMODEL_SPATIAL_DIFFUSE) && (!model->spatial()->region()->overlaps(obsreg))) { - // Model represents a source, that doesn't overlap the observation - // and should be removed for now. + + // Append model to the excluded models excluded_models.append(*model); - all_models.remove(mod); - mod--; // decrement to prevent skipping models + + // Remove model + all_models.remove(i); + + // Decrement to prevent skipping models + i--; } - - delete model; - } - + + } // endfor: looped over all models + + // Return excluded models return excluded_models; } diff --git a/src/ctmodel/ctmodel.hpp b/src/ctmodel/ctmodel.hpp index 587061a..2ce9564 100644 --- a/src/ctmodel/ctmodel.hpp +++ b/src/ctmodel/ctmodel.hpp @@ -74,16 +74,16 @@ public: protected: // Protected methods - void init_members(void); - void copy_members(const ctmodel& app); - void free_members(void); - void get_parameters(void); - void get_obs(void); - void extract_cube_properties(void); - void fill_cube(const GCTAObservation* obs, GModels& models); - bool has_cube(void) const; + void init_members(void); + void copy_members(const ctmodel& app); + void free_members(void); + void get_parameters(void); + void get_obs(void); + void extract_cube_properties(void); + void fill_cube(const GCTAObservation* obs, GModels& models); + bool has_cube(void) const; GModels trim_models(GModels& all_models, const GCTARoi& roi); - + // User parameters GFilename m_outcube; //!< Output model cube bool m_apply_edisp; //!< Apply energy dispersion?