GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCOMDris.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCOMDris.hpp - COMPTEL Data Space container class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2023 by Juergen Knodlseder *
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 GCOMDris.hpp
23  * @brief COMPTEL Data Space container class definition
24  * @author Juergen Knodlseder
25  */
26 
27 #ifndef GCOMDRIS_HPP
28 #define GCOMDRIS_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GContainer.hpp"
34 #include "GNdarray.hpp"
35 #include "GOptimizerFunction.hpp"
36 #include "GCOMDri.hpp"
37 
38 /* __ Forward declarations _______________________________________________ */
39 class GOptimizer;
40 class GCOMObservation;
41 class GCOMEventList;
42 class GCOMSelection;
43 
44 /* __ Constants __________________________________________________________ */
45 
46 
47 /***********************************************************************//**
48  * @class GCOMDris
49  *
50  * @brief COMPTEL Data Space container class
51  *
52  * The COMPTEL Data Space container class holds instances of the COMPTEL
53  * Data Space. It allows for an efficient computation of data and response
54  * information for multiple energy bins.
55  ***************************************************************************/
56 class GCOMDris : public GContainer {
57 
58 public:
59  // Constructors and destructors
60  GCOMDris(void);
61  GCOMDris(const GCOMDris& dris);
62  virtual ~GCOMDris(void);
63 
64  // Operators
65  GCOMDris& operator=(const GCOMDris& dris);
66  GCOMDri& operator[](const int& index);
67  const GCOMDri& operator[](const int& index) const;
68 
69  // Methods
70  void clear(void);
71  GCOMDris* clone(void) const;
72  std::string classname(void) const;
73  GCOMDri& at(const int& index);
74  const GCOMDri& at(const int& index) const;
75  int size(void) const;
76  bool is_empty(void) const;
77  GCOMDri& append(const GCOMDri& dri);
78  GCOMDri& insert(const int& index, const GCOMDri& dri);
79  void remove(const int& index);
80  void reserve(const int& num);
81  void extend(const GCOMDris& dris);
82  void compute_drws(const GCOMObservation& obs,
83  const GCOMSelection& select = GCOMSelection(),
84  const double& zetamin = 5.0,
85  const double& timebin = 300.0,
86  const std::string& method = "phibar");
87  std::string print(const GChatter& chatter = NORMAL) const;
88 
89  // Likelihood function
90  class likelihood : public GOptimizerFunction {
91  public:
92  // Constructors and destructors
93  likelihood(GCOMDris *dris, const int& ieng, const double& norm);
94 
95  // Implemented pure virtual base class methods
96  virtual void eval(const GOptimizerPars& pars);
97  virtual double value(void) const;
98  virtual GVector* gradient(void);
99  virtual GMatrixSparse* curvature(void);
100 
101  protected:
102  int m_ieng; //!< DRW energy bin
103  double m_norm; //!< Normalisation value
104  int m_nsp; //!< Number of superpackets
105  int m_nphibar; //!< Number of phibar layers
106  GNdarray m_vetorate; //!< Vetorate array multiplied by EHA cut correction
107  GNdarray m_activrate; //!< Activation rate array multiplied by EHA cut correction
108  GNdarray m_diffrate; //!< Vetorate - activation rate array
109  GNdarray m_vetorate_sum; //!< Time integrated vetorate array
110  GNdarray m_activrate_sum; //!< Time integrated activation rate array
111  GNdarray m_diffrate_sum; //!< Time integrated difference rate array
112  double m_value; //!< Function value
113  GVector m_gradient; //!< Gradient vector
114  GMatrixSparse m_curvature; //!< Curvature matrix
115  GCOMDris* m_this; //!< Pointer to GCOMDris object
116  };
117 
118 protected:
119  // Protected methods
120  void init_members(void);
121  void copy_members(const GCOMDris& dris);
122  void free_members(void);
123  void compute_drws_energy(const GCOMObservation& obs,
124  const GCOMEventList* events,
125  const GCOMSelection& select,
126  const double& zetamin,
127  const double& timebin);
128  void compute_drws_phibar(const GCOMObservation& obs,
129  const GCOMEventList* events,
130  const GCOMSelection& select,
131  const double& zetamin,
132  const double& timebin);
133  void compute_drws_vetorate(const GCOMObservation& obs,
134  const GCOMEventList* events,
135  const GCOMSelection& select,
136  const double& zetamin);
137  void vetorate_setup(const GCOMObservation& obs,
138  const GCOMEventList* events,
139  const GCOMSelection& select,
140  const double& zetamin);
141  void vetorate_fit(void);
142  void vetorate_update_activ(void);
143  void vetorate_generate(const GCOMObservation& obs,
144  const GCOMSelection& select,
145  const double& zetamin);
146  void vetorate_finish(const GCOMObservation& obs);
147  void vetorate_save(const GFilename& filename) const;
148  void vetorate_load(const GFilename& filename);
149 
150  // Protected data members
151  std::vector<GCOMDri> m_dris; //!< Data space instances
152 
153  // Working arrays for vetorate computation
154  GNdarray m_wrk_counts; //!< 3D event cube array
155  GNdarray m_wrk_ehacutcorr; //!< 2D geometry response array
156  GNdarray m_wrk_vetorate; //!< 1D vetorates array
157  GNdarray m_wrk_activrate; //!< 2D activation rate array
158  GNdarray m_wrk_rate; //!< 2D rate array
159  std::vector<bool> m_wrk_use_sp; //!< 1D superpacket usage array
160 };
161 
162 
163 /***********************************************************************//**
164  * @brief Return class name
165  *
166  * @return String containing the class name ("GCOMDris").
167  ***************************************************************************/
168 inline
169 std::string GCOMDris::classname(void) const
170 {
171  return ("GCOMDris");
172 }
173 
174 
175 /***********************************************************************//**
176  * @brief Return reference to Data space instance
177  *
178  * @param[in] index Data space index [0,...,size()-1].
179  *
180  * Returns a reference to the Data space instance with the specified @p index.
181  ***************************************************************************/
182 inline
183 GCOMDri& GCOMDris::operator[](const int& index)
184 {
185  return (m_dris[index]);
186 }
187 
188 
189 /***********************************************************************//**
190  * @brief Return reference to Data space instance (const version)
191  *
192  * @param[in] index Data space index [0,...,size()-1].
193  *
194  * Returns a reference to the Data space instance with the specified @p index.
195  ***************************************************************************/
196 inline
197 const GCOMDri& GCOMDris::operator[](const int& index) const
198 {
199  return (m_dris[index]);
200 }
201 
202 
203 /***********************************************************************//**
204  * @brief Return number of Data space instances in container
205  *
206  * @return Number of Data space instances in container.
207  *
208  * Returns the number of Data space instances in the container.
209  ***************************************************************************/
210 inline
211 int GCOMDris::size(void) const
212 {
213  return (int)m_dris.size();
214 }
215 
216 
217 /***********************************************************************//**
218  * @brief Signals if there are no Data space instances in container
219  *
220  * @return True if container is empty, false otherwise.
221  *
222  * Signals if the Data space instances container does not contain any Data
223  * space instances.
224  ***************************************************************************/
225 inline
226 bool GCOMDris::is_empty(void) const
227 {
228  return (m_dris.empty());
229 }
230 
231 
232 /***********************************************************************//**
233  * @brief Reserves space for Data space instances in container
234  *
235  * @param[in] num Number of Data space instances.
236  *
237  * Reserves space for @p num Data space instances in the container.
238  ***************************************************************************/
239 inline
240 void GCOMDris::reserve(const int& num)
241 {
242  m_dris.reserve(num);
243  return;
244 }
245 
246 
247 /***********************************************************************//**
248  * @brief Return log-likelihood value of optimizer function
249  *
250  * @return Log-likelihood value of optimizer function.
251  *
252  * Returns the log-likelihood value of optimizer function.
253  ***************************************************************************/
254 inline
255 double GCOMDris::likelihood::value(void) const
256 {
257  return m_value;
258 }
259 
260 
261 /***********************************************************************//**
262  * @brief Return pointer to gradient vector
263  *
264  * @return Pointer to gradient vector.
265  *
266  * Returns a pointer to the parameter gradient vector.
267  ***************************************************************************/
268 inline
270 {
271  return &(m_gradient);
272 }
273 
274 
275 /***********************************************************************//**
276  * @brief Return pointer to curvature matrix
277  *
278  * @return Pointer to curvature matrix.
279  *
280  * Returns a pointer to the parameter curvature matrix.
281  ***************************************************************************/
282 inline
284 {
285  return &(m_curvature);
286 }
287 
288 #endif /* GCOMDRIS_HPP */
GCOMDris * m_this
Pointer to GCOMDris object.
Definition: GCOMDris.hpp:115
GCOMDris & operator=(const GCOMDris &dris)
Assignment operator.
Definition: GCOMDris.cpp:140
void compute_drws(const GCOMObservation &obs, const GCOMSelection &select=GCOMSelection(), const double &zetamin=5.0, const double &timebin=300.0, const std::string &method="phibar")
Compute background weighting cubes.
Definition: GCOMDris.cpp:378
virtual void eval(const GOptimizerPars &pars)
Log-likelihood function evaluation.
Definition: GCOMDris.cpp:2327
Optimizer function abstract base class.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:864
Sparse matrix class interface definition.
GNdarray m_diffrate
Vetorate - activation rate array.
Definition: GCOMDris.hpp:108
void reserve(const int &num)
Reserves space for Data space instances in container.
Definition: GCOMDris.hpp:240
COMPTEL Data Space container class.
Definition: GCOMDris.hpp:56
COMPTEL Data Space class definition.
Optimizer parameter container class.
GNdarray m_wrk_counts
3D event cube array
Definition: GCOMDris.hpp:154
GMatrixSparse m_curvature
Curvature matrix.
Definition: GCOMDris.hpp:114
void compute_drws_phibar(const GCOMObservation &obs, const GCOMEventList *events, const GCOMSelection &select, const double &zetamin, const double &timebin)
Compute background weighting cubes using Phibar dependent rates.
Definition: GCOMDris.cpp:922
bool is_empty(void) const
Signals if there are no Data space instances in container.
Definition: GCOMDris.hpp:226
GCOMDris(void)
Void constructor.
Definition: GCOMDris.cpp:87
likelihood(GCOMDris *dris, const int &ieng, const double &norm)
Log-likelihood function constructor.
Definition: GCOMDris.cpp:2268
GNdarray m_vetorate
Vetorate array multiplied by EHA cut correction.
Definition: GCOMDris.hpp:106
double m_value
Function value.
Definition: GCOMDris.hpp:112
COMPTEL selection set class.
void vetorate_save(const GFilename &filename) const
Save working arrays for vetorate computation.
Definition: GCOMDris.cpp:2126
GVector m_gradient
Gradient vector.
Definition: GCOMDris.hpp:113
virtual GVector * gradient(void)
Return pointer to gradient vector.
Definition: GCOMDris.hpp:269
int m_nsp
Number of superpackets.
Definition: GCOMDris.hpp:104
void extend(const GCOMDris &dris)
Append Data Space container.
Definition: GCOMDris.cpp:332
GCOMDri & at(const int &index)
Return reference to Data Space.
Definition: GCOMDris.cpp:204
GCOMDri & operator[](const int &index)
Return reference to Data space instance.
Definition: GCOMDris.hpp:183
void vetorate_fit(void)
Fit working arrays for vetorate computation.
Definition: GCOMDris.cpp:1636
Optimizer function abstract base class.
Filename class.
Definition: GFilename.hpp:62
GNdarray m_vetorate_sum
Time integrated vetorate array.
Definition: GCOMDris.hpp:109
N-dimensional array class interface definition.
void copy_members(const GCOMDris &dris)
Copy class members.
Definition: GCOMDris.cpp:551
virtual ~GCOMDris(void)
Destructor.
Definition: GCOMDris.cpp:118
GNdarray m_wrk_vetorate
1D vetorates array
Definition: GCOMDris.hpp:156
void free_members(void)
Delete class members.
Definition: GCOMDris.cpp:572
Abstract optimizer abstract base class.
Definition: GOptimizer.hpp:54
GNdarray m_activrate_sum
Time integrated activation rate array.
Definition: GCOMDris.hpp:110
GNdarray m_wrk_rate
2D rate array
Definition: GCOMDris.hpp:158
GChatter
Definition: GTypemaps.hpp:33
GCOMDris * clone(void) const
Clone Data Space container.
Definition: GCOMDris.cpp:188
std::string print(const GChatter &chatter=NORMAL) const
Print Data Space container.
Definition: GCOMDris.cpp:497
void init_members(void)
Initialise class members.
Definition: GCOMDris.cpp:528
GNdarray m_wrk_activrate
2D activation rate array
Definition: GCOMDris.hpp:157
N-dimensional array class.
Definition: GNdarray.hpp:44
void vetorate_finish(const GCOMObservation &obs)
Finish DRWs.
Definition: GCOMDris.cpp:2039
void vetorate_load(const GFilename &filename)
Load working arrays for vetorate computation.
Definition: GCOMDris.cpp:2194
GNdarray m_activrate
Activation rate array multiplied by EHA cut correction.
Definition: GCOMDris.hpp:107
void clear(void)
Clear Data Space container.
Definition: GCOMDris.cpp:170
double m_norm
Normalisation value.
Definition: GCOMDris.hpp:103
int m_ieng
DRW energy bin.
Definition: GCOMDris.hpp:102
std::vector< bool > m_wrk_use_sp
1D superpacket usage array
Definition: GCOMDris.hpp:159
std::vector< GCOMDri > m_dris
Data space instances.
Definition: GCOMDris.hpp:151
std::string classname(void) const
Return class name.
Definition: GCOMDris.hpp:169
void compute_drws_vetorate(const GCOMObservation &obs, const GCOMEventList *events, const GCOMSelection &select, const double &zetamin)
Compute background weighting cubes using veto rates.
Definition: GCOMDris.cpp:1250
Interface class for COMPTEL observations.
GNdarray m_diffrate_sum
Time integrated difference rate array.
Definition: GCOMDris.hpp:111
virtual double value(void) const
Return log-likelihood value of optimizer function.
Definition: GCOMDris.hpp:255
void compute_drws_energy(const GCOMObservation &obs, const GCOMEventList *events, const GCOMSelection &select, const double &zetamin, const double &timebin)
Compute background weighting cubes using energy dependent rates.
Definition: GCOMDris.cpp:606
COMPTEL event list class.
COMPTEL Data Space class.
Definition: GCOMDri.hpp:62
GCOMDri & insert(const int &index, const GCOMDri &dri)
Insert Data Space into container.
Definition: GCOMDris.cpp:271
Definition of interface for container classes.
Vector class.
Definition: GVector.hpp:46
void vetorate_setup(const GCOMObservation &obs, const GCOMEventList *events, const GCOMSelection &select, const double &zetamin)
Setup working arrays for vetorate computation.
Definition: GCOMDris.cpp:1325
int size(void) const
Return number of Data space instances in container.
Definition: GCOMDris.hpp:211
int m_nphibar
Number of phibar layers.
Definition: GCOMDris.hpp:105
GNdarray m_wrk_ehacutcorr
2D geometry response array
Definition: GCOMDris.hpp:155
void vetorate_update_activ(void)
Update activation rate.
Definition: GCOMDris.cpp:1754
void vetorate_generate(const GCOMObservation &obs, const GCOMSelection &select, const double &zetamin)
Generate DRWs.
Definition: GCOMDris.cpp:1888
virtual GMatrixSparse * curvature(void)
Return pointer to curvature matrix.
Definition: GCOMDris.hpp:283
GCOMDri & append(const GCOMDri &dri)
Append Data Space to container.
Definition: GCOMDris.cpp:249
Interface class for container classes.
Definition: GContainer.hpp:52