Commit b8404cc090f7fad9ccded5b05c738719bf3577e7

Authored by Jürgen Knödlseder
1 parent 70bc4daf

Add GPhases class (#1996)

ChangeLog
1   -2017-04-11
  1 +2017-04-14
2 2  
3 3 * Version 1.3.0 released
4 4 =========================
5 5  
  6 + Add GPhases class (#1996)
6 7 Add GEventList::has_phase() and GEventList::has_detxy() methods (#1982)
7 8 Add GEventList::append_column() method (#1991)
8 9 Add scalar addition and subtraction operators to matrix classes (#1990)
... ...
1 1 New Features and Important Changes in GammaLib 1.3.0.dev1
2 2  
3   -11 April 2017
  3 +14 April 2017
4 4  
5 5  
6 6 1. Introduction
... ... @@ -12,6 +12,7 @@ made since the last release of GammaLib.
12 12 2. Public interface modifications
13 13 ---------------------------------
14 14 The following classes have been added:
  15 +- GPhases
15 16 - GWcsGLS
16 17 - GWcsSFL
17 18 - GModelSpectralSmoothBrokenPlaw
... ... @@ -134,6 +135,8 @@ GEbounds::set_log() method throws an exception if either the minimum or
134 135 maximum energy are zero. Furthermore, the methods clear the energy boundaries
135 136 if the requested number of intervals is non-zero (#1989).
136 137  
  138 +The GPhases class has been added to handle phase selections of events (#1996).
  139 +
137 140  
138 141 11. Optimization module
139 142 -----------------------
... ...
include/GPhases.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GPhases.hpp - Phase intervals class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2017 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 GPhases.hpp
  23 + * @brief Phase intervals class interface definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +#ifndef GPHASES_HPP
  28 +#define GPHASES_HPP
  29 +
  30 +/* __ Includes ___________________________________________________________ */
  31 +#include <string>
  32 +#include "GContainer.hpp"
  33 +
  34 +/* __ Forward declarations _______________________________________________ */
  35 +
  36 +
  37 +/***********************************************************************//**
  38 + * @class GPhases
  39 + *
  40 + * @brief Phase Intervals class
  41 + ***************************************************************************/
  42 +class GPhases : public GContainer {
  43 +
  44 +public:
  45 + // Constructors and destructors
  46 + GPhases(void);
  47 + GPhases(const GPhases& phases);
  48 + GPhases(const double& pmin, const double& pmax);
  49 + virtual ~GPhases(void);
  50 +
  51 + // Operators
  52 + GPhases& operator=(const GPhases& phases);
  53 +
  54 + // Methods
  55 + void clear(void);
  56 + GPhases* clone(void) const;
  57 + std::string classname(void) const;
  58 + int size(void) const;
  59 + bool is_empty(void) const;
  60 + void append(const double& pmin, const double& pmax);
  61 + void remove(const int& index);
  62 + void reserve(const int& num);
  63 + void extend(const GPhases& phases);
  64 + double pmin(const int& index) const;
  65 + double pmax(const int& index) const;
  66 + std::string print(const GChatter& chatter = NORMAL) const;
  67 +
  68 +protected:
  69 + // Protected methods
  70 + void init_members(void);
  71 + void copy_members(const GPhases& phases);
  72 + void free_members(void);
  73 + void insert_interval(const int& index, const double& pmin,
  74 + const double& pmax);
  75 +
  76 + // Protected data area
  77 + std::vector<double> m_pmin; // Lower phase interval boundaries
  78 + std::vector<double> m_pmax; // Upper phase interval boundaries
  79 +};
  80 +
  81 +
  82 +/***********************************************************************//**
  83 + * @brief Return class name
  84 + *
  85 + * @return String containing the class name ("GPhases").
  86 + ***************************************************************************/
  87 +inline
  88 +std::string GPhases::classname(void) const
  89 +{
  90 + return ("GPhases");
  91 +}
  92 +
  93 +
  94 +/***********************************************************************//**
  95 + * @brief Return number of phase intervals
  96 + *
  97 + * @return Number of phase intervals.
  98 + ***************************************************************************/
  99 +inline
  100 +int GPhases::size(void) const
  101 +{
  102 + return (int)m_pmin.size();
  103 +}
  104 +
  105 +
  106 +/***********************************************************************//**
  107 + * @brief Signal if there are no phase intervals
  108 + *
  109 + * @return True if there are no phase intervals.
  110 + ***************************************************************************/
  111 +inline
  112 +bool GPhases::is_empty(void) const
  113 +{
  114 + return (m_pmin.size() == 0);
  115 +}
  116 +
  117 +#endif /* GPHASES_HPP */
... ...
include/GammaLib.hpp
... ... @@ -183,6 +183,7 @@
183 183 #include "GGti.hpp"
184 184 #include "GRoi.hpp"
185 185 #include "GEbounds.hpp"
  186 +#include "GPhases.hpp"
186 187 #include "GInstDir.hpp"
187 188 #include "GResponse.hpp"
188 189 #include "GPhotons.hpp"
... ...
include/Makefile.am
... ... @@ -143,6 +143,7 @@ pkginclude_HEADERS = GammaLib.hpp \
143 143 GGti.hpp \
144 144 GRoi.hpp \
145 145 GEbounds.hpp \
  146 + GPhases.hpp \
146 147 GInstDir.hpp \
147 148 GResponse.hpp \
148 149 GPhotons.hpp \
... ...
pyext/GGti.i
... ... @@ -35,7 +35,7 @@
35 35 *
36 36 * @brief Good Time Interval class
37 37 ***************************************************************************/
38   -class GGti : public GBase {
  38 +class GGti : public GContainer {
39 39  
40 40 public:
41 41 // Constructors and destructors
... ...
pyext/GPhases.i 0 → 100644
  1 +/***************************************************************************
  2 + * GPhases.i - Phase intervals class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2017 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 GPhases.i
  23 + * @brief Phase intervals class interface definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +%{
  27 +/* Put headers and other declarations here that are needed for compilation */
  28 +#include "GPhases.hpp"
  29 +#include "GTools.hpp"
  30 +%}
  31 +
  32 +
  33 +/***********************************************************************//**
  34 + * @class GPhases
  35 + *
  36 + * @brief Phase intervals class
  37 + ***************************************************************************/
  38 +class GPhases : public GContainer {
  39 +
  40 +public:
  41 + // Constructors and destructors
  42 + GPhases(void);
  43 + GPhases(const GPhases& phases);
  44 + GPhases(const double& pmin, const double& pmax);
  45 + virtual ~GPhases(void);
  46 +
  47 + // Methods
  48 + void clear(void);
  49 + GPhases* clone(void) const;
  50 + std::string classname(void) const;
  51 + int size(void) const;
  52 + bool is_empty(void) const;
  53 + void append(const double& pmin, const double& pmax);
  54 + void remove(const int& index);
  55 + void reserve(const int& num);
  56 + void extend(const GPhases& phases);
  57 + double pmin(const int& index) const;
  58 + double pmax(const int& index) const;
  59 +};
  60 +
  61 +
  62 +/***********************************************************************//**
  63 + * @brief GPhases class extension
  64 + ***************************************************************************/
  65 +%extend GPhases {
  66 + int __len__() {
  67 + return (self->size());
  68 + }
  69 + GPhases copy() {
  70 + return (*self);
  71 + }
  72 +};
... ...
pyext/gammalib/obs.i
1 1 /***************************************************************************
2 2 * obs.i - Observation module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2011-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2011-2017 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -171,6 +171,7 @@
171 171 %include "GEventBin.i"
172 172 %include "GInstDir.i"
173 173 %include "GRoi.i"
  174 +%include "GPhases.i"
174 175 %include "GResponse.i"
175 176 %include "GPhoton.i"
176 177 %include "GPhotons.i"
... ...
src/obs/GGti.cpp
... ... @@ -100,7 +100,7 @@ GGti::GGti(const GFilename&amp; filename)
100 100 *
101 101 * @param[in] gti Good Time Intervals.
102 102 *
103   - * Constructs Good Time Intervals by coping other Good Time Intervals.
  103 + * Constructs Good Time Intervals by copying other Good Time Intervals.
104 104 ***************************************************************************/
105 105 GGti::GGti(const GGti& gti)
106 106 {
... ...
src/obs/GPhases.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GPhases.cpp - Phase intervals class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2017 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 GPhases.cpp
  23 + * @brief Phase intervals class implementation
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +#include "GException.hpp"
  32 +#include "GTools.hpp"
  33 +#include "GPhases.hpp"
  34 +
  35 +/* __ Method name definitions ____________________________________________ */
  36 +#define G_REMOVE "GPhases::remove(int&)"
  37 +#define G_PMIN "GPhases::pmin(int&)"
  38 +#define G_PMAX "GPhases::pmax(int&)"
  39 +#define G_INSERT_INTERVAL "GPhases::insert_interval(int&, double&, double&)"
  40 +
  41 +/* __ Macros _____________________________________________________________ */
  42 +
  43 +/* __ Coding definitions _________________________________________________ */
  44 +
  45 +/* __ Debug definitions __________________________________________________ */
  46 +
  47 +
  48 +/*==========================================================================
  49 + = =
  50 + = Constructors/destructors =
  51 + = =
  52 + ==========================================================================*/
  53 +
  54 +/***********************************************************************//**
  55 + * @brief Void constructor
  56 + *
  57 + * Constructs empty phase intervals.
  58 + ***************************************************************************/
  59 +GPhases::GPhases(void)
  60 +{
  61 + // Initialise class members
  62 + init_members();
  63 +
  64 + // Return
  65 + return;
  66 +}
  67 +
  68 +
  69 +/***********************************************************************//**
  70 + * @brief Copy constructor
  71 + *
  72 + * @param[in] phases Phase intervals.
  73 + *
  74 + * Constructs phase intervals by copying other phase intervals.
  75 + ***************************************************************************/
  76 +GPhases::GPhases(const GPhases& phases)
  77 +{
  78 + // Initialise class members
  79 + init_members();
  80 +
  81 + // Copy members
  82 + copy_members(phases);
  83 +
  84 + // Return
  85 + return;
  86 +}
  87 +
  88 +
  89 +/***********************************************************************//**
  90 + * @brief Single phase interval constructor
  91 + *
  92 + * @param[in] pmin Lower boundary of phase interval.
  93 + * @param[in] pmax Upper boundary of phase interval.
  94 + *
  95 + * Constructs Good Time Intervals from a single phase interval, given by
  96 + * [p@ pmin, @p pmax].
  97 + ***************************************************************************/
  98 +GPhases::GPhases(const double& pmin, const double& pmax)
  99 +{
  100 + // Initialise members
  101 + init_members();
  102 +
  103 + // Append phase interval
  104 + append(pmin, pmax);
  105 +
  106 + // Return
  107 + return;
  108 +}
  109 +
  110 +
  111 +/***********************************************************************//**
  112 + * @brief Destructor
  113 + ***************************************************************************/
  114 +GPhases::~GPhases(void)
  115 +{
  116 + // Free members
  117 + free_members();
  118 +
  119 + // Return
  120 + return;
  121 +}
  122 +
  123 +
  124 +/*==========================================================================
  125 + = =
  126 + = Operators =
  127 + = =
  128 + ==========================================================================*/
  129 +
  130 +/***********************************************************************//**
  131 + * @brief Assignment operator
  132 + *
  133 + * @param[in] phases Phase intervals.
  134 + * @return Phase intervals.
  135 + ***************************************************************************/
  136 +GPhases& GPhases::operator=(const GPhases& phases)
  137 +{
  138 + // Execute only if object is not identical
  139 + if (this != &phases) {
  140 +
  141 + // Free members
  142 + free_members();
  143 +
  144 + // Initialise private members
  145 + init_members();
  146 +
  147 + // Copy members
  148 + copy_members(phases);
  149 +
  150 + } // endif: object was not identical
  151 +
  152 + // Return this object
  153 + return *this;
  154 +}
  155 +
  156 +
  157 +/*==========================================================================
  158 + = =
  159 + = Public methods =
  160 + = =
  161 + ==========================================================================*/
  162 +
  163 +/***********************************************************************//**
  164 + * @brief Clear phase intervals
  165 + ***************************************************************************/
  166 +void GPhases::clear(void)
  167 +{
  168 + // Free members
  169 + free_members();
  170 +
  171 + // Initialise private members
  172 + init_members();
  173 +
  174 + // Return
  175 + return;
  176 +}
  177 +
  178 +
  179 +/***********************************************************************//**
  180 + * @brief Clone phase intervals
  181 + *
  182 + * @return Pointer to deep copy of phase intervals.
  183 + ***************************************************************************/
  184 +GPhases* GPhases::clone(void) const
  185 +{
  186 + return new GPhases(*this);
  187 +}
  188 +
  189 +
  190 +/***********************************************************************//**
  191 + * @brief Append phase interval
  192 + *
  193 + * @param[in] pmin Lower boundary of phase interval.
  194 + * @param[in] pmax Upper boundary of phase interval.
  195 + *
  196 + * Appends a phase interval at the end of the container.
  197 + ***************************************************************************/
  198 +void GPhases::append(const double& pmin, const double& pmax)
  199 +{
  200 + // Insert phase interval at the end of the list
  201 + insert_interval(size(), pmin, pmax);
  202 +
  203 + // Return
  204 + return;
  205 +}
  206 +
  207 +
  208 +/***********************************************************************//**
  209 + * @brief Remove phase interval
  210 + *
  211 + * @param[in] index Phase interval index (0,...,size()-1).
  212 + *
  213 + * Removes phase interval at @p index from the container. All intervals
  214 + * after the specified @p index are moved forward by one position.
  215 + ***************************************************************************/
  216 +void GPhases::remove(const int& index)
  217 +{
  218 + #if defined(G_RANGE_CHECK)
  219 + // If index is outside boundary then throw an error
  220 + if (index < 0 || index >= size()) {
  221 + throw GException::out_of_range(G_REMOVE, "Phase interval", index,
  222 + size());
  223 + }
  224 + #endif
  225 +
  226 + // Remove lower and upper boundaries
  227 + m_pmin.erase(m_pmin.begin() + index);
  228 + m_pmax.erase(m_pmax.begin() + index);
  229 +
  230 + // Return
  231 + return;
  232 +}
  233 +
  234 +
  235 +/***********************************************************************//**
  236 + * @brief Reserve space for phase intervals
  237 + *
  238 + * @param[in] num Number of elements.
  239 + ***************************************************************************/
  240 +void GPhases::reserve(const int& num)
  241 +{
  242 + // Reserves memory
  243 + m_pmin.reserve(num);
  244 + m_pmax.reserve(num);
  245 +
  246 + // Return
  247 + return;
  248 +}
  249 +
  250 +
  251 +/***********************************************************************//**
  252 + * @brief Append phase intervals
  253 + *
  254 + * @param[in] phases Phase intervals.
  255 + *
  256 + * Append phase intervals to the container.
  257 + ***************************************************************************/
  258 +void GPhases::extend(const GPhases& phases)
  259 +{
  260 + // Continue only if phase intervals are not empty
  261 + if (!phases.is_empty()) {
  262 +
  263 + // Get size. Note that we extract the size first to avoid an
  264 + // endless loop that arises when a container is appended to
  265 + // itself.
  266 + int num = phases.size();
  267 +
  268 + // Resize the boundary vectors
  269 + reserve(size() + num);
  270 +
  271 + // Loop over all elements and append them to container
  272 + for (int i = 0; i < num; ++i) {
  273 + m_pmin.push_back(phases.pmin(i));
  274 + m_pmax.push_back(phases.pmax(i));
  275 + }
  276 +
  277 + } // endif: Phase intervals were not empty
  278 +
  279 + // Return
  280 + return;
  281 +}
  282 +
  283 +
  284 +/***********************************************************************//**
  285 + * @brief Returns lower boundary for a given phase interval
  286 + *
  287 + * @param[in] index Phase interval index (0,...,size()-1).
  288 + * @return Lower boundary of phase interval.
  289 + *
  290 + * @exception GException::out_of_range
  291 + * Specified index is out of range.
  292 + ***************************************************************************/
  293 +double GPhases::pmin(const int& index) const
  294 +{
  295 + #if defined(G_RANGE_CHECK)
  296 + // If index is outside boundary then throw an error
  297 + if (index < 0 || index >= size()) {
  298 + throw GException::out_of_range(G_PMIN, "Phase interval", index,
  299 + size());
  300 + }
  301 + #endif
  302 +
  303 + // Return
  304 + return (m_pmin[index]);
  305 +}
  306 +
  307 +
  308 +/***********************************************************************//**
  309 + * @brief Returns upper boundary for a given phase interval
  310 + *
  311 + * @param[in] index Phase interval index (0,...,size()-1).
  312 + * @return Upper boundary of phase interval.
  313 + *
  314 + * @exception GException::out_of_range
  315 + * Specified index is out of range.
  316 + ***************************************************************************/
  317 +double GPhases::pmax(const int& index) const
  318 +{
  319 + #if defined(G_RANGE_CHECK)
  320 + // If index is outside boundary then throw an error
  321 + if (index < 0 || index >= size()) {
  322 + throw GException::out_of_range(G_PMAX, "Phase interval", index,
  323 + size());
  324 + }
  325 + #endif
  326 +
  327 + // Return
  328 + return (m_pmax[index]);
  329 +}
  330 +
  331 +
  332 +/***********************************************************************//**
  333 + * @brief Print phase intervals
  334 + *
  335 + * @param[in] chatter Chattiness.
  336 + * @return String containing phase interval information.
  337 + ***************************************************************************/
  338 +std::string GPhases::print(const GChatter& chatter) const
  339 +{
  340 + // Initialise result string
  341 + std::string result;
  342 +
  343 + // Continue only if chatter is not silent
  344 + if (chatter != SILENT) {
  345 +
  346 + // Append header
  347 + result.append("=== GPhases ===");
  348 +
  349 + // Append phase interval information
  350 + result.append("\n"+gammalib::parformat("Number of intervals"));
  351 + result.append(gammalib::str(size()));
  352 +
  353 + } // endif: chatter was not silent
  354 +
  355 + // Return result
  356 + return result;
  357 +}
  358 +
  359 +
  360 +/*==========================================================================
  361 + = =
  362 + = Private methods =
  363 + = =
  364 + ==========================================================================*/
  365 +
  366 +/***********************************************************************//**
  367 + * @brief Initialise class members
  368 + ***************************************************************************/
  369 +void GPhases::init_members(void)
  370 +{
  371 + // Initialise members
  372 + m_pmin.clear();
  373 + m_pmax.clear();
  374 +
  375 + // Return
  376 + return;
  377 +}
  378 +
  379 +
  380 +/***********************************************************************//**
  381 + * @brief Copy class members
  382 + *
  383 + * @param[in] phases Phase intervals.
  384 + ***************************************************************************/
  385 +void GPhases::copy_members(const GPhases& phases)
  386 +{
  387 + // Copy attributes
  388 + m_pmin = phases.m_pmin;
  389 + m_pmax = phases.m_pmax;
  390 +
  391 + // Return
  392 + return;
  393 +}
  394 +
  395 +
  396 +/***********************************************************************//**
  397 + * @brief Delete class members
  398 + ***************************************************************************/
  399 +void GPhases::free_members(void)
  400 +{
  401 + // Return
  402 + return;
  403 +}
  404 +
  405 +
  406 +/***********************************************************************//**
  407 + * @brief Insert phase interval
  408 + *
  409 + * @param[in] index Index after which interval is inserted.
  410 + * @param[in] pmin Lower boundary of interval.
  411 + * @param[in] pmax Upper boundary of interval.
  412 + *
  413 + * @exception GException::invalid_argument
  414 + * Invalid phase interval boundaries specified
  415 + *
  416 + * Inserts a phase interval before the interval with the specified @p index.
  417 + * If no interval with the specified index exists then append the interval
  418 + * at the end of the existing phase intervals.
  419 + ***************************************************************************/
  420 +void GPhases::insert_interval(const int& index,
  421 + const double& pmin,
  422 + const double& pmax)
  423 +{
  424 + // Throw an exception if phase minimum is outside the range [0,1]
  425 + if (pmin < 0.0 || pmin > 1.0) {
  426 + std::string msg = "Phase minimum "+gammalib::str(pmin)+
  427 + " outside the valid range [0,1]. Please "
  428 + "specify phase interval boundaries comprised "
  429 + "within 0 and 1.";
  430 + throw GException::invalid_argument(G_INSERT_INTERVAL, msg);
  431 + }
  432 +
  433 + // Throw an exception if phase minimum is outside the range [0,1]
  434 + if (pmax < 0.0 || pmax > 1.0) {
  435 + std::string msg = "Phase maximum "+gammalib::str(pmax)+
  436 + " outside the valid range [0,1]. Please "
  437 + "specify phase interval boundaries comprised "
  438 + "within 0 and 1.";
  439 + throw GException::invalid_argument(G_INSERT_INTERVAL, msg);
  440 + }
  441 +
  442 + // If phase minimum is smaller than phase maximum then append or insert
  443 + // a single interval ...
  444 + if (pmin < pmax) {
  445 + if (index >= size()) {
  446 + m_pmin.push_back(pmin);
  447 + m_pmax.push_back(pmax);
  448 + }
  449 + else {
  450 + m_pmin.insert(m_pmin.begin()+index, pmin);
  451 + m_pmax.insert(m_pmax.begin()+index, pmax);
  452 + }
  453 + }
  454 +
  455 + // ... otherwise if the phase minimum is larger than the maximum then
  456 + // consider this a wrap around interval and append or insert one interval
  457 + // from phase minimum to 1 and another interval from 0 to phase maximum
  458 + else if (pmin > pmax) {
  459 + if (pmin < 1.0) {
  460 + if (index >= size()) {
  461 + m_pmin.push_back(pmin);
  462 + m_pmax.push_back(1.0);
  463 + }
  464 + else {
  465 + m_pmin.insert(m_pmin.begin()+index, pmin);
  466 + m_pmax.insert(m_pmax.begin()+index, 1.0);
  467 + }
  468 + }
  469 + if (pmax > 0.0) {
  470 + if (index >= size()) {
  471 + m_pmin.push_back(0.0);
  472 + m_pmax.push_back(pmax);
  473 + }
  474 + else {
  475 + m_pmin.insert(m_pmin.begin()+index, 0.0);
  476 + m_pmax.insert(m_pmax.begin()+index, pmax);
  477 + }
  478 + }
  479 + }
  480 +
  481 + // Return
  482 + return;
  483 +}
... ...
src/obs/Makefile.am
1 1 #############################################################################
2 2 # Makefile.am for obs module #
3 3 # ------------------------------------------------------------------------- #
4   -# Copyright (C) 2016 Juergen Knoedlseder #
  4 +# Copyright (C) 2016-2017 Juergen Knoedlseder #
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7 7 # This program is free software: you can redistribute it and/or modify #
... ... @@ -44,6 +44,7 @@ sources = GEnergies.cpp \
44 44 GGti.cpp \
45 45 GRoi.cpp \
46 46 GEbounds.cpp \
  47 + GPhases.cpp \
47 48 GResponse.cpp \
48 49 GInstDir.cpp \
49 50 GPhotons.cpp \
... ...
test/test_GObservation.cpp
... ... @@ -69,6 +69,8 @@ void TestGObservation::set(void)
69 69 "Test GEnergies class");
70 70 append(static_cast<pfunction>(&TestGObservation::test_ebounds),
71 71 "Test GEbounds class");
  72 + append(static_cast<pfunction>(&TestGObservation::test_phases),
  73 + "Test GPhases class");
72 74 append(static_cast<pfunction>(&TestGObservation::test_photons),
73 75 "Test GPhotons class");
74 76 append(static_cast<pfunction>(&TestGObservation::test_observations_optimizer),
... ... @@ -1343,6 +1345,74 @@ void TestGObservation::test_photons(void)
1343 1345  
1344 1346  
1345 1347 /***********************************************************************//**
  1348 + * @brief Test GPhases
  1349 + ***************************************************************************/
  1350 +void TestGObservation::test_phases(void)
  1351 +{
  1352 + // Test void constructor
  1353 + test_try("Void constructor");
  1354 + try {
  1355 + GPhases phases;
  1356 + test_try_success();
  1357 + }
  1358 + catch (std::exception &e) {
  1359 + test_try_failure(e);
  1360 + }
  1361 +
  1362 + // Manipulate GPhases starting from an empty object
  1363 + GPhases phases;
  1364 + test_value(phases.size(), 0);
  1365 + test_assert(phases.is_empty(), "Test for empty GPhases object");
  1366 +
  1367 + // Add one phase interval
  1368 + phases.append(0.3, 0.5);
  1369 + test_value(phases.size(), 1);
  1370 + test_value(phases.pmin(0), 0.3);
  1371 + test_value(phases.pmax(0), 0.5);
  1372 + test_assert(!phases.is_empty(), "Test for non-empty GPhases object");
  1373 +
  1374 + // Remove phase interval
  1375 + phases.remove(0);
  1376 + test_value(phases.size(), 0);
  1377 + test_assert(phases.is_empty(), "Test for empty GPhases object");
  1378 +
  1379 + // Append two phase intervals
  1380 + phases.append(0.3, 0.5);
  1381 + phases.append(0.4, 0.7);
  1382 + test_value(phases.pmin(0), 0.3);
  1383 + test_value(phases.pmax(0), 0.5);
  1384 + test_value(phases.pmin(1), 0.4);
  1385 + test_value(phases.pmax(1), 0.7);
  1386 + test_value(phases.size(), 2);
  1387 + test_assert(!phases.is_empty(), "Test for non-empty GPhases object");
  1388 +
  1389 + // Copy phase intervals
  1390 + GPhases phases2(phases);
  1391 + test_value(phases2.pmin(0), 0.3);
  1392 + test_value(phases2.pmax(0), 0.5);
  1393 + test_value(phases2.pmin(1), 0.4);
  1394 + test_value(phases2.pmax(1), 0.7);
  1395 + test_value(phases2.size(), 2);
  1396 + test_assert(!phases2.is_empty(), "Test for non-empty GPhases object");
  1397 +
  1398 + // Clear object
  1399 + phases.clear();
  1400 + test_value(phases.size(), 0);
  1401 + test_assert(phases.is_empty(), "Test for empty GPhases object");
  1402 +
  1403 + // Extend photons
  1404 + phases.append(0.3, 0.5);
  1405 + phases.append(0.4, 0.7);
  1406 + phases.extend(phases);
  1407 + test_value(phases.size(), 4);
  1408 + test_assert(!phases.is_empty(), "Test for non-empty GPhases object");
  1409 +
  1410 + // Return
  1411 + return;
  1412 +}
  1413 +
  1414 +
  1415 +/***********************************************************************//**
1346 1416 * @brief Test GObservations::likelihood
1347 1417 ***************************************************************************/
1348 1418 void TestGObservation::test_observations_optimizer(void)
... ...
test/test_GObservation.hpp
... ... @@ -49,6 +49,7 @@ public:
49 49 virtual std::string classname(void) const { return "TestGObservation"; }
50 50 void test_ebounds(void);
51 51 void test_gti(void);
  52 + void test_phases(void);
52 53 void test_photons(void);
53 54 void test_time_reference(void);
54 55 void test_time(void);
... ...