Commit 7459a57debdd365e39bae70bfb042fe0b4da7187
1 parent
784f3185
Add GCOMModelDRM class (#3910)
Showing
11 changed files
with
820 additions
and
8 deletions
ChangeLog
| 1 | -2021-11-25 | |
| 1 | +2021-11-28 | |
| 2 | 2 | |
| 3 | 3 | * Version 2.0.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Add GCOMModelDRM class (#3910) | |
| 6 | 7 | Add angle(GVector&,GVector&) friend function (#3908) |
| 7 | 8 | Make extension name check case insensitive in GFits::extno() |
| 8 | 9 | Add numerical gradient step size member to GObservation | ... | ... |
NEWS
| 1 | 1 | New Features and Important Changes in GammaLib 2.0.0 |
| 2 | 2 | |
| 3 | -25 November 2021 | |
| 3 | +28 November 2021 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | 1. Introduction |
| ... | ... | @@ -22,6 +22,7 @@ The following classes have been added: |
| 22 | 22 | - GModelSpectralBins |
| 23 | 23 | - GCTAModelSkyCube |
| 24 | 24 | - GCTABackground2D |
| 25 | +- GCOMModelDRM | |
| 25 | 26 | |
| 26 | 27 | The following classes have been removed: |
| 27 | 28 | - GCTAExceptionHandler |
| ... | ... | @@ -378,7 +379,9 @@ spatial model gradients (#3203). |
| 378 | 379 | |
| 379 | 380 | 22. COMPTEL interface |
| 380 | 381 | --------------------- |
| 381 | -Add phase selection to GCOMSelection and GCOMDri (#3564). | |
| 382 | +Added GCOMModelDRM class to enable fitting of DRM data cubes to the data (#3910). | |
| 383 | + | |
| 384 | +Added phase selection to GCOMSelection and GCOMDri (#3564). | |
| 382 | 385 | |
| 383 | 386 | Store DRB, DRG and DRX as instances of GCOMDri instead of GSkyMap in GCOMObservation |
| 384 | 387 | (#3560). | ... | ... |
README.md
| 1 | 1 | GammaLib information |
| 2 | 2 | ==================== |
| 3 | -* Version: 2.0.0.dev (25 November 2021) | |
| 3 | +* Version: 2.0.0.dev (28 November 2021) | |
| 4 | 4 | |
| 5 | 5 | [](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) |
| 6 | 6 | ... | ... |
doc/source/admin/release_history/2.0.rst
| 1 | 1 | .. _2.0: |
| 2 | 2 | |
| 3 | -GammaLib 2.0 release (28 May 2021) | |
| 3 | +GammaLib 2.0 release (28 November 2021) | |
| 4 | 4 | ================================== |
| 5 | 5 | |
| 6 | 6 | Overview |
| ... | ... | @@ -11,6 +11,7 @@ GammaLib 2.0 is a major release that adds significant functionality. |
| 11 | 11 | In particular, this release provides: |
| 12 | 12 | |
| 13 | 13 | * vectorised response computation |
| 14 | +* full support of all spatial models for COMPTEL | |
| 14 | 15 | * ... |
| 15 | 16 | |
| 16 | 17 | |
| ... | ... | @@ -35,6 +36,10 @@ Bug fixes |
| 35 | 36 | Improvements |
| 36 | 37 | ------------ |
| 37 | 38 | |
| 39 | +* [`3908 <https://cta-redmine.irap.omp.eu/issues/3908>`_] - | |
| 40 | + Add ``angle(GVector&,GVector&)`` friend function | |
| 41 | +* Make extension name check case insensitive in ``GFits::extno()`` | |
| 42 | +* Add numerical gradient step size member to ``GObservation`` | |
| 38 | 43 | * [`3662 <https://cta-redmine.irap.omp.eu/issues/3662>`_] - |
| 39 | 44 | Add ``stamp()`` methods to ``GApplication`` |
| 40 | 45 | * [`3630 <https://cta-redmine.irap.omp.eu/issues/3630>`_] - |
| ... | ... | @@ -83,6 +88,8 @@ Improvements |
| 83 | 88 | New features |
| 84 | 89 | ------------ |
| 85 | 90 | |
| 91 | +* [`3910 <https://cta-redmine.irap.omp.eu/issues/3910>`_] - | |
| 92 | + Add ``GCOMModelDRM`` class | |
| 86 | 93 | * [`3606 <https://cta-redmine.irap.omp.eu/issues/3606>`_] - |
| 87 | 94 | Add ``GModelSpectralBins`` class |
| 88 | 95 | * [`3527 <https://cta-redmine.irap.omp.eu/issues/3527>`_] - | ... | ... |
inst/com/Makefile.am
| ... | ... | @@ -55,7 +55,8 @@ sources = src/com_helpers_response_vector.cpp \ |
| 55 | 55 | src/GCOMInstChars.cpp \ |
| 56 | 56 | src/GCOMIaq.cpp \ |
| 57 | 57 | src/GCOMObservation.cpp \ |
| 58 | - src/GCOMModelDRBFitting.cpp | |
| 58 | + src/GCOMModelDRBFitting.cpp \ | |
| 59 | + src/GCOMModelDRM.cpp | |
| 59 | 60 | |
| 60 | 61 | # Define headers to be installed |
| 61 | 62 | pkginclude_HEADERS = include/GCOMTools.hpp \ |
| ... | ... | @@ -78,6 +79,7 @@ pkginclude_HEADERS = include/GCOMTools.hpp \ |
| 78 | 79 | include/GCOMIaq.hpp \ |
| 79 | 80 | include/GCOMObservation.hpp \ |
| 80 | 81 | include/GCOMModelDRBFitting.hpp \ |
| 82 | + include/GCOMModelDRM.hpp \ | |
| 81 | 83 | include/GCOMLib.hpp |
| 82 | 84 | |
| 83 | 85 | # Calibration files to distribute | ... | ... |
inst/com/include/GCOMModelDRM.hpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GCOMModelDRM.hpp - COMPTEL DRM model class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2021 by Juergen Knoedlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GCOMModelDRM.hpp | |
| 23 | + * @brief COMPTEL DRM model class interface definition | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 26 | + | |
| 27 | +#ifndef GCOMMODELDRM_HPP | |
| 28 | +#define GCOMMODELDRM_HPP | |
| 29 | + | |
| 30 | +/* __ Includes ___________________________________________________________ */ | |
| 31 | +#include <string> | |
| 32 | +#include "GModelData.hpp" | |
| 33 | +#include "GModelPar.hpp" | |
| 34 | +#include "GEvent.hpp" | |
| 35 | +#include "GObservation.hpp" | |
| 36 | +#include "GNodeArray.hpp" | |
| 37 | +#include "GXmlElement.hpp" | |
| 38 | +#include "GCOMEventCube.hpp" | |
| 39 | + | |
| 40 | + | |
| 41 | +/***********************************************************************//** | |
| 42 | + * @class GCOMModelDRM | |
| 43 | + * | |
| 44 | + * @brief COMPTEL DRM model class | |
| 45 | + * | |
| 46 | + * This class implements a COMPTEL data space model. The model has a | |
| 47 | + * normalization parameters. | |
| 48 | + ***************************************************************************/ | |
| 49 | +class GCOMModelDRM : public GModelData { | |
| 50 | + | |
| 51 | +public: | |
| 52 | + // Constructors and destructors | |
| 53 | + GCOMModelDRM(void); | |
| 54 | + explicit GCOMModelDRM(const GXmlElement& xml); | |
| 55 | + GCOMModelDRM(const GCOMModelDRM& model); | |
| 56 | + virtual ~GCOMModelDRM(void); | |
| 57 | + | |
| 58 | + // Operators | |
| 59 | + virtual GCOMModelDRM& operator=(const GCOMModelDRM& model); | |
| 60 | + | |
| 61 | + // Implemented pure virtual methods | |
| 62 | + virtual void clear(void); | |
| 63 | + virtual GCOMModelDRM* clone(void) const; | |
| 64 | + virtual std::string classname(void) const; | |
| 65 | + virtual std::string type(void) const; | |
| 66 | + virtual bool is_constant(void) const; | |
| 67 | + virtual double eval(const GEvent& event, | |
| 68 | + const GObservation& obs, | |
| 69 | + const bool& gradients = false) const; | |
| 70 | + virtual double npred(const GEnergy& obsEng, const GTime& obsTime, | |
| 71 | + const GObservation& obs) const; | |
| 72 | + virtual GCOMEventCube* mc(const GObservation& obs, GRan& ran) const; | |
| 73 | + virtual void read(const GXmlElement& xml); | |
| 74 | + virtual void write(GXmlElement& xml) const; | |
| 75 | + virtual std::string print(const GChatter& chatter = NORMAL) const; | |
| 76 | + | |
| 77 | +protected: | |
| 78 | + // Protected methods | |
| 79 | + void init_members(void); | |
| 80 | + void copy_members(const GCOMModelDRM& model); | |
| 81 | + void free_members(void); | |
| 82 | + | |
| 83 | + // Proteced data members | |
| 84 | + GModelPar m_norm; //!< Normalisation | |
| 85 | + GCOMDri m_drm; //!< Model | |
| 86 | + GFilename m_filename; //!< Name of DRM FITS file | |
| 87 | +}; | |
| 88 | + | |
| 89 | + | |
| 90 | +/***********************************************************************//** | |
| 91 | + * @brief Return class name | |
| 92 | + * | |
| 93 | + * @return String containing the class name ("GCOMModelDRM"). | |
| 94 | + ***************************************************************************/ | |
| 95 | +inline | |
| 96 | +std::string GCOMModelDRM::classname(void) const | |
| 97 | +{ | |
| 98 | + return ("GCOMModelDRM"); | |
| 99 | +} | |
| 100 | + | |
| 101 | + | |
| 102 | +/***********************************************************************//** | |
| 103 | + * @brief Return model type | |
| 104 | + * | |
| 105 | + * @return Model type. | |
| 106 | + * | |
| 107 | + * Returns the type of the model. The type for a DRM model is "DRM". | |
| 108 | + ***************************************************************************/ | |
| 109 | +inline | |
| 110 | +std::string GCOMModelDRM::type(void) const | |
| 111 | +{ | |
| 112 | + return ("DRM"); | |
| 113 | +} | |
| 114 | + | |
| 115 | + | |
| 116 | +/***********************************************************************//** | |
| 117 | + * @brief Signals if model is temporally constant | |
| 118 | + * | |
| 119 | + * @return True if model is temporally constant, false otherwise. | |
| 120 | + * | |
| 121 | + * Signals if the model is temporally constant. By definition, a DRM model | |
| 122 | + * is always temporally constant. | |
| 123 | + ***************************************************************************/ | |
| 124 | +inline | |
| 125 | +bool GCOMModelDRM::is_constant(void) const | |
| 126 | +{ | |
| 127 | + return (true); | |
| 128 | +} | |
| 129 | + | |
| 130 | +#endif /* GCOMMODELDRM_HPP */ | ... | ... |
inst/com/pyext/GCOMModelDRM.i
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GCOMModelDRM.i - COMPTEL DRM model class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2021 by Juergen Knoedlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GCOMModelDRM.hpp | |
| 23 | + * @brief COMPTEL DRM model class interface definition | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 26 | +%{ | |
| 27 | +/* Put headers and other declarations here that are needed for compilation */ | |
| 28 | +#include "GCOMModelDRM.hpp" | |
| 29 | +%} | |
| 30 | + | |
| 31 | + | |
| 32 | +/***********************************************************************//** | |
| 33 | + * @class GCOMModelDRM | |
| 34 | + * | |
| 35 | + * @brief COMPTEL DRM model class | |
| 36 | + ***************************************************************************/ | |
| 37 | +class GCOMModelDRM : public GModelData { | |
| 38 | +public: | |
| 39 | + // Constructors and destructors | |
| 40 | + GCOMModelDRM(void); | |
| 41 | + explicit GCOMModelDRM(const GXmlElement& xml); | |
| 42 | + GCOMModelDRM(const GCOMModelDRM& model); | |
| 43 | + virtual ~GCOMModelDRM(void); | |
| 44 | + | |
| 45 | + // Implemented pure virtual methods | |
| 46 | + virtual void clear(void); | |
| 47 | + virtual GCOMModelDRM* clone(void) const; | |
| 48 | + virtual std::string classname(void) const; | |
| 49 | + virtual std::string type(void) const; | |
| 50 | + virtual bool is_constant(void) const; | |
| 51 | + virtual double eval(const GEvent& event, | |
| 52 | + const GObservation& obs, | |
| 53 | + const bool& gradients = false) const; | |
| 54 | + virtual double npred(const GEnergy& obsEng, const GTime& obsTime, | |
| 55 | + const GObservation& obs) const; | |
| 56 | + virtual GCOMEventCube* mc(const GObservation& obs, GRan& ran) const; | |
| 57 | + virtual void read(const GXmlElement& xml); | |
| 58 | + virtual void write(GXmlElement& xml) const; | |
| 59 | +}; | |
| 60 | + | |
| 61 | + | |
| 62 | +/***********************************************************************//** | |
| 63 | + * @brief GCOMModelDRM class extension | |
| 64 | + ***************************************************************************/ | |
| 65 | +%extend GCOMModelDRM { | |
| 66 | + GCOMModelDRM copy() { | |
| 67 | + return (*self); | |
| 68 | + } | |
| 69 | +%pythoncode { | |
| 70 | + def __getstate__(self): | |
| 71 | + xml = gammalib.GXmlElement() | |
| 72 | + self.write(xml) | |
| 73 | + state = {'xml': xml} | |
| 74 | + return state | |
| 75 | + def __setstate__(self, state): | |
| 76 | + if state['xml'].elements('parameter') == 0: | |
| 77 | + self.__init__() | |
| 78 | + else: | |
| 79 | + self.__init__(state['xml']) | |
| 80 | +} | |
| 81 | +}; | ... | ... |
inst/com/pyext/com.i
inst/com/src/GCOMModelDRBFitting.cpp
| ... | ... | @@ -44,6 +44,8 @@ const GModelRegistry g_com_drb_fitting_registry(&g_com_drb_fitting_seed); |
| 44 | 44 | |
| 45 | 45 | /* __ Method name definitions ____________________________________________ */ |
| 46 | 46 | #define G_EVAL "GCOMModelDRBFitting::eval(GEvent&, GObservation&, bool&)" |
| 47 | +#define G_NRED "GCOMModelDRBFitting::npred(GEnergy&, GTime&, GObservation&)" | |
| 48 | +#define G_MC "GCOMModelDRBFitting::mc(GObservation&, GRan&)" | |
| 47 | 49 | #define G_READ "GCOMModelDRBFitting::read(GXmlElement&)" |
| 48 | 50 | #define G_WRITE "GCOMModelDRBFitting::write(GXmlElement&)" |
| 49 | 51 | |
| ... | ... | @@ -52,7 +54,6 @@ const GModelRegistry g_com_drb_fitting_registry(&g_com_drb_fitting_seed); |
| 52 | 54 | /* __ Coding definitions _________________________________________________ */ |
| 53 | 55 | |
| 54 | 56 | /* __ Debug definitions __________________________________________________ */ |
| 55 | -//#define G_DUMP_MC //!< Dump MC information | |
| 56 | 57 | |
| 57 | 58 | |
| 58 | 59 | /*========================================================================== |
| ... | ... | @@ -374,6 +375,10 @@ double GCOMModelDRBFitting::eval(const GEvent& event, |
| 374 | 375 | * @param[in] obsEng Measured event energy. |
| 375 | 376 | * @param[in] obsTime Measured event time. |
| 376 | 377 | * @param[in] obs Observation. |
| 378 | + * @return Spatially integrated data model. | |
| 379 | + * | |
| 380 | + * @exception GException::feature_not_implemented | |
| 381 | + * Method is not implemented. | |
| 377 | 382 | * |
| 378 | 383 | * Spatially integrates the data model for a given measured event energy and |
| 379 | 384 | * event time. |
| ... | ... | @@ -387,6 +392,10 @@ double GCOMModelDRBFitting::npred(const GEnergy& obsEng, |
| 387 | 392 | // Initialise result |
| 388 | 393 | double npred = 0.0; |
| 389 | 394 | |
| 395 | + // Method is not implemented | |
| 396 | + std::string msg = "Spatial integration of data model is not implemented."; | |
| 397 | + throw GException::feature_not_implemented(G_NRED, msg); | |
| 398 | + | |
| 390 | 399 | // Return |
| 391 | 400 | return npred; |
| 392 | 401 | } |
| ... | ... | @@ -397,6 +406,10 @@ double GCOMModelDRBFitting::npred(const GEnergy& obsEng, |
| 397 | 406 | * |
| 398 | 407 | * @param[in] obs Observation. |
| 399 | 408 | * @param[in] ran Random number generator. |
| 409 | + * @return COMPTEL event cube. | |
| 410 | + * | |
| 411 | + * @exception GException::feature_not_implemented | |
| 412 | + * Method is not implemented. | |
| 400 | 413 | * |
| 401 | 414 | * Draws a sample of events from the COMPTEL DRB fitting model using a Monte |
| 402 | 415 | * Carlo simulation. |
| ... | ... | @@ -409,6 +422,10 @@ GCOMEventCube* GCOMModelDRBFitting::mc(const GObservation& obs, |
| 409 | 422 | // Initialise new event cube |
| 410 | 423 | GCOMEventCube* cube = new GCOMEventCube; |
| 411 | 424 | |
| 425 | + // Method is not implemented | |
| 426 | + std::string msg = "Monte Carlo simulation of data model is not implemented."; | |
| 427 | + throw GException::feature_not_implemented(G_MC, msg); | |
| 428 | + | |
| 412 | 429 | // Return |
| 413 | 430 | return cube; |
| 414 | 431 | } | ... | ... |
inst/com/src/GCOMModelDRM.cpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GCOMModelDRM.cpp - COMPTEL DRM model class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2021 by Juergen Knoedlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GCOMModelDRM.cpp | |
| 23 | + * @brief COMPTEL DRM model class implementation | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 26 | + | |
| 27 | +/* __ Includes ___________________________________________________________ */ | |
| 28 | +#ifdef HAVE_CONFIG_H | |
| 29 | +#include <config.h> | |
| 30 | +#endif | |
| 31 | +#include <typeinfo> | |
| 32 | +#include "GException.hpp" | |
| 33 | +#include "GTools.hpp" | |
| 34 | +#include "GModelRegistry.hpp" | |
| 35 | +#include "GCOMModelDRM.hpp" | |
| 36 | +#include "GCOMObservation.hpp" | |
| 37 | +#include "GCOMEventBin.hpp" | |
| 38 | + | |
| 39 | +/* __ Constants __________________________________________________________ */ | |
| 40 | + | |
| 41 | +/* __ Globals ____________________________________________________________ */ | |
| 42 | +const GCOMModelDRM g_com_drm_seed; | |
| 43 | +const GModelRegistry g_com_drm_registry(&g_com_drm_seed); | |
| 44 | + | |
| 45 | +/* __ Method name definitions ____________________________________________ */ | |
| 46 | +#define G_EVAL "GCOMModelDRM::eval(GEvent&, GObservation&, bool&)" | |
| 47 | +#define G_NRED "GCOMModelDRM::npred(GEnergy&, GTime&, GObservation&)" | |
| 48 | +#define G_MC "GCOMModelDRM::mc(GObservation&, GRan&)" | |
| 49 | +#define G_READ "GCOMModelDRM::read(GXmlElement&)" | |
| 50 | +#define G_WRITE "GCOMModelDRM::write(GXmlElement&)" | |
| 51 | + | |
| 52 | +/* __ Macros _____________________________________________________________ */ | |
| 53 | + | |
| 54 | +/* __ Coding definitions _________________________________________________ */ | |
| 55 | + | |
| 56 | +/* __ Debug definitions __________________________________________________ */ | |
| 57 | + | |
| 58 | + | |
| 59 | +/*========================================================================== | |
| 60 | + = = | |
| 61 | + = Constructors/destructors = | |
| 62 | + = = | |
| 63 | + ==========================================================================*/ | |
| 64 | + | |
| 65 | +/***********************************************************************//** | |
| 66 | + * @brief Void constructor | |
| 67 | + * | |
| 68 | + * Constructs an empty COMPTEL DRM model. | |
| 69 | + ***************************************************************************/ | |
| 70 | +GCOMModelDRM::GCOMModelDRM(void) : GModelData() | |
| 71 | +{ | |
| 72 | + // Initialise members | |
| 73 | + init_members(); | |
| 74 | + | |
| 75 | + // Return | |
| 76 | + return; | |
| 77 | +} | |
| 78 | + | |
| 79 | + | |
| 80 | +/***********************************************************************//** | |
| 81 | + * @brief XML constructor | |
| 82 | + * | |
| 83 | + * @param[in] xml XML element. | |
| 84 | + * | |
| 85 | + * Constructs a COMPTEL DRM model from the information that is found in an | |
| 86 | + * XML element. Please refer to the method GCOMModelDRM::read to learn more | |
| 87 | + * about the information that is expected in the XML element. | |
| 88 | + ***************************************************************************/ | |
| 89 | +GCOMModelDRM::GCOMModelDRM(const GXmlElement& xml) : GModelData(xml) | |
| 90 | +{ | |
| 91 | + // Initialise members | |
| 92 | + init_members(); | |
| 93 | + | |
| 94 | + // Read XML | |
| 95 | + read(xml); | |
| 96 | + | |
| 97 | + // Return | |
| 98 | + return; | |
| 99 | +} | |
| 100 | + | |
| 101 | + | |
| 102 | +/***********************************************************************//** | |
| 103 | + * @brief Copy constructor | |
| 104 | + * | |
| 105 | + * @param[in] model COMPTEL DRM model. | |
| 106 | + * | |
| 107 | + * Constructs a COMPTEL DRM model by copying information from an existing | |
| 108 | + * model. Note that the copy is a deep copy, so the original object can be | |
| 109 | + * destroyed after the copy without any loss of information. | |
| 110 | + ***************************************************************************/ | |
| 111 | +GCOMModelDRM::GCOMModelDRM(const GCOMModelDRM& model) : GModelData(model) | |
| 112 | +{ | |
| 113 | + // Initialise private members for clean destruction | |
| 114 | + init_members(); | |
| 115 | + | |
| 116 | + // Copy members | |
| 117 | + copy_members(model); | |
| 118 | + | |
| 119 | + // Return | |
| 120 | + return; | |
| 121 | +} | |
| 122 | + | |
| 123 | + | |
| 124 | +/***********************************************************************//** | |
| 125 | + * @brief Destructor | |
| 126 | + * | |
| 127 | + * Destroys a COMPTEL DRM model. | |
| 128 | + ***************************************************************************/ | |
| 129 | +GCOMModelDRM::~GCOMModelDRM(void) | |
| 130 | +{ | |
| 131 | + // Free members | |
| 132 | + free_members(); | |
| 133 | + | |
| 134 | + // Return | |
| 135 | + return; | |
| 136 | +} | |
| 137 | + | |
| 138 | + | |
| 139 | +/*========================================================================== | |
| 140 | + = = | |
| 141 | + = Operators = | |
| 142 | + = = | |
| 143 | + ==========================================================================*/ | |
| 144 | + | |
| 145 | +/***********************************************************************//** | |
| 146 | + * @brief Assignment operator | |
| 147 | + * | |
| 148 | + * @param[in] model COMPTEL DRM model. | |
| 149 | + * @return COMPTEL DRM model | |
| 150 | + * | |
| 151 | + * Assigns the information from a COMPTEL DRM model to the actual object. | |
| 152 | + * Note that a deep copy of the information is performed, so the original | |
| 153 | + * object can be destroyed after the assignment without any loss of | |
| 154 | + * information. | |
| 155 | + ***************************************************************************/ | |
| 156 | +GCOMModelDRM& GCOMModelDRM::operator=(const GCOMModelDRM& model) | |
| 157 | +{ | |
| 158 | + // Execute only if object is not identical | |
| 159 | + if (this != &model) { | |
| 160 | + | |
| 161 | + // Copy base class members | |
| 162 | + this->GModelData::operator=(model); | |
| 163 | + | |
| 164 | + // Free members | |
| 165 | + free_members(); | |
| 166 | + | |
| 167 | + // Initialise members | |
| 168 | + init_members(); | |
| 169 | + | |
| 170 | + // Copy members | |
| 171 | + copy_members(model); | |
| 172 | + | |
| 173 | + } // endif: object was not identical | |
| 174 | + | |
| 175 | + // Return | |
| 176 | + return *this; | |
| 177 | +} | |
| 178 | + | |
| 179 | + | |
| 180 | +/*========================================================================== | |
| 181 | + = = | |
| 182 | + = Public methods = | |
| 183 | + = = | |
| 184 | + ==========================================================================*/ | |
| 185 | + | |
| 186 | +/***********************************************************************//** | |
| 187 | + * @brief Clear instance | |
| 188 | + * | |
| 189 | + * Resets the object to a clean initial state. All information that resided | |
| 190 | + * in the object will be lost. | |
| 191 | + ***************************************************************************/ | |
| 192 | +void GCOMModelDRM::clear(void) | |
| 193 | +{ | |
| 194 | + // Free class members (base and derived classes, derived class first) | |
| 195 | + free_members(); | |
| 196 | + this->GModelData::free_members(); | |
| 197 | + this->GModel::free_members(); | |
| 198 | + | |
| 199 | + // Initialise members | |
| 200 | + this->GModel::init_members(); | |
| 201 | + this->GModelData::init_members(); | |
| 202 | + init_members(); | |
| 203 | + | |
| 204 | + // Return | |
| 205 | + return; | |
| 206 | +} | |
| 207 | + | |
| 208 | + | |
| 209 | +/***********************************************************************//** | |
| 210 | + * @brief Clone instance | |
| 211 | + * | |
| 212 | + * @return Pointer to deep copy of COMPTEL DRM model. | |
| 213 | + * | |
| 214 | + * Clone a COMPTEL DRM model. Cloning performs a deep copy of the | |
| 215 | + * information, so the original object can be destroyed after cloning without | |
| 216 | + * any loss of information. | |
| 217 | + ***************************************************************************/ | |
| 218 | +GCOMModelDRM* GCOMModelDRM::clone(void) const | |
| 219 | +{ | |
| 220 | + return new GCOMModelDRM(*this); | |
| 221 | +} | |
| 222 | + | |
| 223 | + | |
| 224 | +/***********************************************************************//** | |
| 225 | + * @brief Evaluate function | |
| 226 | + * | |
| 227 | + * @param[in] event Observed event. | |
| 228 | + * @param[in] obs Observation. | |
| 229 | + * @param[in] gradients Compute gradients? | |
| 230 | + * @return Background model value. | |
| 231 | + * | |
| 232 | + * @exception GException::invalid_argument | |
| 233 | + * Observation is not a COMPTEL observation. | |
| 234 | + * Event is not a COMPTEL event bin. | |
| 235 | + * | |
| 236 | + * Evaluates the COMPTEL DRM model. | |
| 237 | + ***************************************************************************/ | |
| 238 | +double GCOMModelDRM::eval(const GEvent& event, | |
| 239 | + const GObservation& obs, | |
| 240 | + const bool& gradients) const | |
| 241 | +{ | |
| 242 | + // Extract COMPTEL observation | |
| 243 | + const GCOMObservation* observation = dynamic_cast<const GCOMObservation*>(&obs); | |
| 244 | + if (observation == NULL) { | |
| 245 | + std::string cls = std::string(typeid(&obs).name()); | |
| 246 | + std::string msg = "Observation of type \""+cls+"\" is not a COMPTEL " | |
| 247 | + "observations. Please specify a COMPTEL observation " | |
| 248 | + "as argument."; | |
| 249 | + throw GException::invalid_argument(G_EVAL, msg); | |
| 250 | + } | |
| 251 | + | |
| 252 | + // Extract COMPTEL event bin | |
| 253 | + const GCOMEventBin* bin = dynamic_cast<const GCOMEventBin*>(&event); | |
| 254 | + if (bin == NULL) { | |
| 255 | + std::string cls = std::string(typeid(&event).name()); | |
| 256 | + std::string msg = "Event of type \""+cls+"\" is not a COMPTEL event. " | |
| 257 | + "Please specify a COMPTEL event as argument."; | |
| 258 | + throw GException::invalid_argument(G_EVAL, msg); | |
| 259 | + } | |
| 260 | + | |
| 261 | + // Initialise value | |
| 262 | + double value = 0.0; | |
| 263 | + | |
| 264 | + // Optionally initialise gradients | |
| 265 | + if (gradients) { | |
| 266 | + m_norm.factor_gradient(0.0); | |
| 267 | + } | |
| 268 | + | |
| 269 | + // Get bin index | |
| 270 | + int index = bin->index(); | |
| 271 | + | |
| 272 | + // Get bin size. | |
| 273 | + double size = bin->size(); | |
| 274 | + | |
| 275 | + // Continue only if bin size is positive | |
| 276 | + if (size > 0.0) { | |
| 277 | + | |
| 278 | + // Get DRM model value | |
| 279 | + value = m_drm.map().pixels()[index] / size; | |
| 280 | + | |
| 281 | + // Optionally compute gradients | |
| 282 | + if (gradients) { | |
| 283 | + | |
| 284 | + // Compute partial derivative | |
| 285 | + double grad = (m_norm.is_free()) ? value * m_norm.scale() : 0.0; | |
| 286 | + | |
| 287 | + // Set gradient | |
| 288 | + m_norm.factor_gradient(grad); | |
| 289 | + | |
| 290 | + } // endif: gradient computation was requested | |
| 291 | + | |
| 292 | + // Compute model value | |
| 293 | + value *= m_norm.value(); | |
| 294 | + | |
| 295 | + // Compile option: Check for NaN/Inf | |
| 296 | + #if defined(G_NAN_CHECK) | |
| 297 | + if (gammalib::is_notanumber(value) || gammalib::is_infinite(value)) { | |
| 298 | + std::cout << "*** ERROR: GCOMModelDRM::eval"; | |
| 299 | + std::cout << "(index=" << index << "):"; | |
| 300 | + std::cout << " NaN/Inf encountered"; | |
| 301 | + std::cout << " (value=" << value; | |
| 302 | + std::cout << ")" << std::endl; | |
| 303 | + } | |
| 304 | + #endif | |
| 305 | + | |
| 306 | + } // endif: binsize was positive | |
| 307 | + | |
| 308 | + // Return | |
| 309 | + return value; | |
| 310 | +} | |
| 311 | + | |
| 312 | + | |
| 313 | +/***********************************************************************//** | |
| 314 | + * @brief Return spatially integrated DRM model | |
| 315 | + * | |
| 316 | + * @param[in] obsEng Measured event energy. | |
| 317 | + * @param[in] obsTime Measured event time. | |
| 318 | + * @param[in] obs Observation. | |
| 319 | + * @return Spatially integrated DRM model. | |
| 320 | + * | |
| 321 | + * @exception GException::feature_not_implemented | |
| 322 | + * Method is not implemented. | |
| 323 | + * | |
| 324 | + * Spatially integrates the DRM model for a given measured event energy and | |
| 325 | + * event time. | |
| 326 | + * | |
| 327 | + * @todo Implement method. | |
| 328 | + ***************************************************************************/ | |
| 329 | +double GCOMModelDRM::npred(const GEnergy& obsEng, | |
| 330 | + const GTime& obsTime, | |
| 331 | + const GObservation& obs) const | |
| 332 | +{ | |
| 333 | + // Initialise result | |
| 334 | + double npred = 0.0; | |
| 335 | + | |
| 336 | + // Method is not implemented | |
| 337 | + std::string msg = "Spatial integration of DRM model is not implemented."; | |
| 338 | + throw GException::feature_not_implemented(G_NRED, msg); | |
| 339 | + | |
| 340 | + // Return | |
| 341 | + return npred; | |
| 342 | +} | |
| 343 | + | |
| 344 | + | |
| 345 | +/***********************************************************************//** | |
| 346 | + * @brief Return simulated list of events | |
| 347 | + * | |
| 348 | + * @param[in] obs Observation. | |
| 349 | + * @param[in] ran Random number generator. | |
| 350 | + * @return COMPTEL event cube. | |
| 351 | + * | |
| 352 | + * @exception GException::feature_not_implemented | |
| 353 | + * Method is not implemented. | |
| 354 | + * | |
| 355 | + * Draws a sample of events from the COMPTEL DRM model using a Monte Carlo | |
| 356 | + * simulation. | |
| 357 | + * | |
| 358 | + * @todo Implement method. | |
| 359 | + ***************************************************************************/ | |
| 360 | +GCOMEventCube* GCOMModelDRM::mc(const GObservation& obs, GRan& ran) const | |
| 361 | +{ | |
| 362 | + // Initialise new event cube | |
| 363 | + GCOMEventCube* cube = new GCOMEventCube; | |
| 364 | + | |
| 365 | + // Method is not implemented | |
| 366 | + std::string msg = "Monte Carlo simulation of DRM model is not implemented."; | |
| 367 | + throw GException::feature_not_implemented(G_MC, msg); | |
| 368 | + | |
| 369 | + // Return | |
| 370 | + return cube; | |
| 371 | +} | |
| 372 | + | |
| 373 | + | |
| 374 | +/***********************************************************************//** | |
| 375 | + * @brief Read model from XML element | |
| 376 | + * | |
| 377 | + * @param[in] xml XML element. | |
| 378 | + * | |
| 379 | + * Read the COMPTEL DRM model from an XML element. | |
| 380 | + * | |
| 381 | + * The model has the following XML file syntax: | |
| 382 | + * | |
| 383 | + * <source name="Model" type="DRM" file="drm.fits" instrument="COM"> | |
| 384 | + * <parameter name="Normalization" ../> | |
| 385 | + * </source> | |
| 386 | + ***************************************************************************/ | |
| 387 | +void GCOMModelDRM::read(const GXmlElement& xml) | |
| 388 | +{ | |
| 389 | + // Verify number of model parameters | |
| 390 | + gammalib::xml_check_parnum(G_READ, xml, 1); | |
| 391 | + | |
| 392 | + // Get parameter pointers | |
| 393 | + const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); | |
| 394 | + | |
| 395 | + // Read parameters | |
| 396 | + m_norm.read(*norm); | |
| 397 | + | |
| 398 | + // Read filename | |
| 399 | + m_filename = gammalib::xml_file_expand(xml, xml.attribute("file")); | |
| 400 | + | |
| 401 | + // Load DRM | |
| 402 | + m_drm.load(m_filename); | |
| 403 | + | |
| 404 | + // Read model attributes | |
| 405 | + read_attributes(xml); | |
| 406 | + | |
| 407 | + // Return | |
| 408 | + return; | |
| 409 | +} | |
| 410 | + | |
| 411 | + | |
| 412 | +/***********************************************************************//** | |
| 413 | + * @brief Write model into XML element | |
| 414 | + * | |
| 415 | + * @param[in] xml XML element. | |
| 416 | + * | |
| 417 | + * Write the COMPTEL DRM model into an XML element. | |
| 418 | + * | |
| 419 | + * The model has the following XML file syntax: | |
| 420 | + * | |
| 421 | + * <source name="Model" type="DRM" file="drm.fits" instrument="COM"> | |
| 422 | + * <parameter name="Normalization" ../> | |
| 423 | + * </source> | |
| 424 | + ***************************************************************************/ | |
| 425 | +void GCOMModelDRM::write(GXmlElement& xml) const | |
| 426 | +{ | |
| 427 | + // Initialise pointer on source | |
| 428 | + GXmlElement* src = NULL; | |
| 429 | + | |
| 430 | + // Search corresponding source | |
| 431 | + int n = xml.elements("source"); | |
| 432 | + for (int k = 0; k < n; ++k) { | |
| 433 | + GXmlElement* element = xml.element("source", k); | |
| 434 | + if (element->attribute("name") == name()) { | |
| 435 | + src = element; | |
| 436 | + break; | |
| 437 | + } | |
| 438 | + } | |
| 439 | + | |
| 440 | + // If no source with corresponding name was found then append one. | |
| 441 | + // Set also the type and the instrument. | |
| 442 | + if (src == NULL) { | |
| 443 | + src = xml.append("source"); | |
| 444 | + src->attribute("name", name()); | |
| 445 | + src->attribute("type", type()); | |
| 446 | + if (instruments().length() > 0) { | |
| 447 | + src->attribute("instrument", instruments()); | |
| 448 | + } | |
| 449 | + } | |
| 450 | + | |
| 451 | + // Verify model type | |
| 452 | + gammalib::xml_check_type(G_WRITE, *src, type()); | |
| 453 | + | |
| 454 | + // Get XML parameters | |
| 455 | + GXmlElement* norm = gammalib::xml_need_par(G_WRITE, *src, m_norm.name()); | |
| 456 | + | |
| 457 | + // Write parameters | |
| 458 | + m_norm.write(*norm); | |
| 459 | + | |
| 460 | + // Set DRM file name | |
| 461 | + src->attribute("file", gammalib::xml_file_reduce(*src, m_filename)); | |
| 462 | + | |
| 463 | + // Write model attributes | |
| 464 | + write_attributes(*src); | |
| 465 | + | |
| 466 | + // Return | |
| 467 | + return; | |
| 468 | +} | |
| 469 | + | |
| 470 | + | |
| 471 | +/***********************************************************************//** | |
| 472 | + * @brief Print model information | |
| 473 | + * | |
| 474 | + * @param[in] chatter Chattiness. | |
| 475 | + * @return String containing model information. | |
| 476 | + ***************************************************************************/ | |
| 477 | +std::string GCOMModelDRM::print(const GChatter& chatter) const | |
| 478 | +{ | |
| 479 | + // Initialise result string | |
| 480 | + std::string result; | |
| 481 | + | |
| 482 | + // Continue only if chatter is not silent | |
| 483 | + if (chatter != SILENT) { | |
| 484 | + | |
| 485 | + // Append header | |
| 486 | + result.append("=== GCOMModelDRM ==="); | |
| 487 | + | |
| 488 | + // Append attributes | |
| 489 | + result.append("\n"+print_attributes()); | |
| 490 | + | |
| 491 | + // Append parameters | |
| 492 | + result.append("\n"+gammalib::parformat("DRM file")); | |
| 493 | + result.append(m_filename); | |
| 494 | + result.append("\n"+gammalib::parformat("Number of parameters")); | |
| 495 | + result.append(gammalib::str(size())); | |
| 496 | + for (int i = 0; i < size(); ++i) { | |
| 497 | + result.append("\n"+m_pars[i]->print(chatter)); | |
| 498 | + } | |
| 499 | + | |
| 500 | + } // endif: chatter was not silent | |
| 501 | + | |
| 502 | + // Return result | |
| 503 | + return result; | |
| 504 | +} | |
| 505 | + | |
| 506 | + | |
| 507 | +/*========================================================================== | |
| 508 | + = = | |
| 509 | + = Private methods = | |
| 510 | + = = | |
| 511 | + ==========================================================================*/ | |
| 512 | + | |
| 513 | +/***********************************************************************//** | |
| 514 | + * @brief Initialise class members | |
| 515 | + ***************************************************************************/ | |
| 516 | +void GCOMModelDRM::init_members(void) | |
| 517 | +{ | |
| 518 | + // Initialise Value | |
| 519 | + m_norm.clear(); | |
| 520 | + m_norm.name("Normalization"); | |
| 521 | + m_norm.value(1.0); | |
| 522 | + m_norm.scale(1.0); | |
| 523 | + m_norm.range(0.0, 1.0e6); | |
| 524 | + m_norm.gradient(0.0); | |
| 525 | + m_norm.free(); | |
| 526 | + m_norm.has_grad(true); | |
| 527 | + | |
| 528 | + // Set parameter pointer(s) | |
| 529 | + m_pars.clear(); | |
| 530 | + m_pars.push_back(&m_norm); | |
| 531 | + | |
| 532 | + // Initialise other members | |
| 533 | + m_drm.clear(); | |
| 534 | + m_filename.clear(); | |
| 535 | + | |
| 536 | + // Return | |
| 537 | + return; | |
| 538 | +} | |
| 539 | + | |
| 540 | + | |
| 541 | +/***********************************************************************//** | |
| 542 | + * @brief Copy class members | |
| 543 | + * | |
| 544 | + * @param[in] model Model. | |
| 545 | + ***************************************************************************/ | |
| 546 | +void GCOMModelDRM::copy_members(const GCOMModelDRM& model) | |
| 547 | +{ | |
| 548 | + // Copy members | |
| 549 | + m_norm = model.m_norm; | |
| 550 | + m_drm = model.m_drm; | |
| 551 | + m_filename = model.m_filename; | |
| 552 | + | |
| 553 | + // Set parameter pointer(s) | |
| 554 | + m_pars.clear(); | |
| 555 | + m_pars.push_back(&m_norm); | |
| 556 | + | |
| 557 | + // Return | |
| 558 | + return; | |
| 559 | +} | |
| 560 | + | |
| 561 | + | |
| 562 | +/***********************************************************************//** | |
| 563 | + * @brief Delete class members | |
| 564 | + ***************************************************************************/ | |
| 565 | +void GCOMModelDRM::free_members(void) | |
| 566 | +{ | |
| 567 | + // Return | |
| 568 | + return; | |
| 569 | +} | ... | ... |
inst/com/test/test_COM.py
| 1 | 1 | # ========================================================================== |
| 2 | 2 | # This module performs unit tests for the GammaLib COMPTEL module. |
| 3 | 3 | # |
| 4 | -# Copyright (C) 2012-2018 Juergen Knoedlseder | |
| 4 | +# Copyright (C) 2012-2021 Juergen Knoedlseder | |
| 5 | 5 | # |
| 6 | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | 7 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -60,6 +60,7 @@ class Test(gammalib.GPythonTestSuite): |
| 60 | 60 | #test_support.pickeling(self, gammalib.GCOMInstChars()) |
| 61 | 61 | test_support.pickeling(self, gammalib.GCOMInstDir()) |
| 62 | 62 | test_support.pickeling(self, gammalib.GCOMModelDRBFitting()) |
| 63 | + test_support.pickeling(self, gammalib.GCOMModelDRM()) | |
| 63 | 64 | test_support.pickeling(self, gammalib.GCOMOad()) |
| 64 | 65 | test_support.pickeling(self, gammalib.GCOMOads()) |
| 65 | 66 | test_support.pickeling(self, gammalib.GCOMObservation()) | ... | ... |