GammaLib  2.0.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCOMModelDRBFitting.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCOMModelDRBFitting.cpp - COMPTEL DRB model fitting class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2012-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 GCOMModelDRBFitting.cpp
23  * @brief COMPTEL DRB model fitting 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 "GCOMModelDRBFitting.hpp"
36 #include "GCOMObservation.hpp"
37 #include "GCOMEventBin.hpp"
38 
39 /* __ Constants __________________________________________________________ */
40 
41 /* __ Globals ____________________________________________________________ */
43 const GModelRegistry g_com_drb_fitting_registry(&g_com_drb_fitting_seed);
44 
45 /* __ Method name definitions ____________________________________________ */
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&)"
49 #define G_READ "GCOMModelDRBFitting::read(GXmlElement&)"
50 #define G_WRITE "GCOMModelDRBFitting::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 DRB fitting model.
69  ***************************************************************************/
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 DRB fitting model from the information that is found
86  * in an XML element. Please refer to the method GCOMModelDRBFitting::read
87  * to learn more about the information that is expected in the XML element.
88  ***************************************************************************/
90  GModelData(xml)
91 {
92  // Initialise members
93  init_members();
94 
95  // Read XML
96  read(xml);
97 
98  // Return
99  return;
100 }
101 
102 
103 /***********************************************************************//**
104  * @brief Copy constructor
105  *
106  * @param[in] model COMPTEL DRB fitting model.
107  *
108  * Constructs a COMPTEL DRB fitting model by copying information from an
109  * existing model. Note that the copy is a deep copy, so the original object
110  * can be destroyed after the copy without any loss of information.
111  ***************************************************************************/
113  GModelData(model)
114 {
115  // Initialise private members for clean destruction
116  init_members();
117 
118  // Copy members
119  copy_members(model);
120 
121  // Return
122  return;
123 }
124 
125 
126 /***********************************************************************//**
127  * @brief Destructor
128  *
129  * Destroys a COMPTEL DRB fitting model.
130  ***************************************************************************/
132 {
133  // Free members
134  free_members();
135 
136  // Return
137  return;
138 }
139 
140 
141 /*==========================================================================
142  = =
143  = Operators =
144  = =
145  ==========================================================================*/
146 
147 /***********************************************************************//**
148  * @brief Assignment operator
149  *
150  * @param[in] model COMPTEL DRB fitting model.
151  * @return COMPTEL DRB fitting model
152  *
153  * Assigns the information from a COMPTEL DRB fitting model to the actual
154  * object. Note that a deep copy of the information is performed, so the
155  * original object can be destroyed after the assignment without any loss of
156  * information.
157  ***************************************************************************/
159 {
160  // Execute only if object is not identical
161  if (this != &model) {
162 
163  // Copy base class members
164  this->GModelData::operator=(model);
165 
166  // Free members
167  free_members();
168 
169  // Initialise members
170  init_members();
171 
172  // Copy members
173  copy_members(model);
174 
175  } // endif: object was not identical
176 
177  // Return
178  return *this;
179 }
180 
181 
182 /*==========================================================================
183  = =
184  = Public methods =
185  = =
186  ==========================================================================*/
187 
188 /***********************************************************************//**
189  * @brief Clear instance
190  *
191  * Resets the object to a clean initial state. All information that resided
192  * in the object will be lost.
193  ***************************************************************************/
195 {
196  // Free class members (base and derived classes, derived class first)
197  free_members();
198  this->GModelData::free_members();
199  this->GModel::free_members();
200 
201  // Initialise members
202  this->GModel::init_members();
203  this->GModelData::init_members();
204  init_members();
205 
206  // Return
207  return;
208 }
209 
210 
211 /***********************************************************************//**
212  * @brief Clone instance
213  *
214  * @return Pointer to deep copy of COMPTEL DRB fitting model.
215  *
216  * Clone a COMPTEL DRB fitting model. Cloning performs a deep copy of the
217  * information, so the original object can be destroyed after cloning without
218  * any loss of information.
219  ***************************************************************************/
221 {
222  return new GCOMModelDRBFitting(*this);
223 }
224 
225 
226 /***********************************************************************//**
227  * @brief Evaluate function
228  *
229  * @param[in] event Observed event.
230  * @param[in] obs Observation.
231  * @param[in] gradients Compute gradients?
232  * @return Background model value.
233  *
234  * @exception GException::invalid_argument
235  * Observation is not a COMPTEL observation.
236  * Event is not a COMPTEL event bin.
237  *
238  * Evaluates the COMPTEL DRB fitting model.
239  ***************************************************************************/
240 double GCOMModelDRBFitting::eval(const GEvent& event,
241  const GObservation& obs,
242  const bool& gradients) const
243 {
244  // Extract COMPTEL observation
245  const GCOMObservation* observation = dynamic_cast<const GCOMObservation*>(&obs);
246  if (observation == NULL) {
247  std::string cls = std::string(typeid(&obs).name());
248  std::string msg = "Observation of type \""+cls+"\" is not a COMPTEL "
249  "observations. Please specify a COMPTEL observation "
250  "as argument.";
252  }
253 
254  // Extract COMPTEL event bin
255  const GCOMEventBin* bin = dynamic_cast<const GCOMEventBin*>(&event);
256  if (bin == NULL) {
257  std::string cls = std::string(typeid(&event).name());
258  std::string msg = "Event of type \""+cls+"\" is not a COMPTEL event. "
259  "Please specify a COMPTEL event as argument.";
261  }
262 
263  // Initialise value
264  double value = 0.0;
265 
266  // Optionally initialise gradients
267  if (gradients) {
268  for (int i = 0; i < m_values.size(); ++i) {
269  m_values[i].factor_gradient(0.0);
270  }
271  }
272 
273  // Get bin index
274  int index = bin->index();
275 
276  // Get bin size.
277  double size = bin->size();
278 
279  // Continue only if bin size is positive
280  if (size > 0.0) {
281 
282  // Initialise scaling factor
283  double scale = 1.0;
284 
285  // Get DRB model value
286  value = observation->drb().map().pixels()[index] / size;
287 
288  // If the model has a single scaling factor then use the first
289  // parameter as scaling factor of the model
290  if (m_scale) {
291 
292  // Get scale factor
293  scale = m_values[0].value();
294 
295  // Optionally compute gradients
296  if (gradients) {
297 
298  // Compute partial derivative
299  double grad = (m_values[0].is_free())
300  ? value * m_values[0].scale() : 0.0;
301 
302  // Set gradient
303  m_values[0].factor_gradient(grad);
304 
305  } // endif: gradient computation was requested
306 
307  } // endif: model is a scaling factor
308 
309  // ... otherwise perform a linear interpolation
310  else {
311 
312  // Get Phibar value
313  double phibar = bin->dir().phibar();
314 
315  // Update evaluation cache
316  update_cache();
317 
318  // Set node array for linear interpolation
319  m_nodes.set_value(phibar);
320 
321  // Get indices and weights for interpolation
322  int inx_left = m_nodes.inx_left();
323  int inx_right = m_nodes.inx_right();
324  double wgt_left = m_nodes.wgt_left();
325  double wgt_right = m_nodes.wgt_right();
326 
327  // Get scale factor
328  scale = m_values[inx_left].value() * wgt_left +
329  m_values[inx_right].value() * wgt_right;
330 
331  // Optionally compute gradients
332  if (gradients) {
333 
334  // Compute partial derivatives
335  double g_left = (m_values[inx_left].is_free())
336  ? wgt_left * value * m_values[inx_left].scale()
337  : 0.0;
338  double g_right = (m_values[inx_right].is_free())
339  ? wgt_right * value * m_values[inx_right].scale()
340  : 0.0;
341 
342  // Set gradients
343  m_values[inx_left].factor_gradient(g_left);
344  m_values[inx_right].factor_gradient(g_right);
345 
346  } // endif: gradient computation was requested
347 
348  } // endelse: performed linear interpolation
349 
350  // Compute background value
351  value *= scale;
352 
353  // Compile option: Check for NaN/Inf
354  #if defined(G_NAN_CHECK)
355  if (gammalib::is_notanumber(value) || gammalib::is_infinite(value)) {
356  std::cout << "*** ERROR: GCOMModelDRBFitting::eval";
357  std::cout << "(index=" << index << "):";
358  std::cout << " NaN/Inf encountered";
359  std::cout << " (value=" << value;
360  std::cout << ", scale=" << scale;
361  std::cout << ")" << std::endl;
362  }
363  #endif
364 
365  } // endif: binsize was positive
366 
367  // Return
368  return value;
369 }
370 
371 
372 /***********************************************************************//**
373  * @brief Return spatially integrated data model
374  *
375  * @param[in] obsEng Measured event energy.
376  * @param[in] obsTime Measured event time.
377  * @param[in] obs Observation.
378  * @return Spatially integrated data model.
379  *
380  * @exception GException::feature_not_implemented
381  * Method is not implemented.
382  *
383  * Spatially integrates the data model for a given measured event energy and
384  * event time.
385  *
386  * @todo Implement method.
387  ***************************************************************************/
388 double GCOMModelDRBFitting::npred(const GEnergy& obsEng,
389  const GTime& obsTime,
390  const GObservation& obs) const
391 {
392  // Initialise result
393  double npred = 0.0;
394 
395  // Method is not implemented
396  std::string msg = "Spatial integration of data model is not implemented.";
398 
399  // Return
400  return npred;
401 }
402 
403 
404 /***********************************************************************//**
405  * @brief Return simulated list of events
406  *
407  * @param[in] obs Observation.
408  * @param[in] ran Random number generator.
409  * @return COMPTEL event cube.
410  *
411  * @exception GException::feature_not_implemented
412  * Method is not implemented.
413  *
414  * Draws a sample of events from the COMPTEL DRB fitting model using a Monte
415  * Carlo simulation.
416  *
417  * @todo Implement method.
418  ***************************************************************************/
420  GRan& ran) const
421 {
422  // Initialise new event cube
423  GCOMEventCube* cube = new GCOMEventCube;
424 
425  // Method is not implemented
426  std::string msg = "Monte Carlo simulation of data model is not implemented.";
428 
429  // Return
430  return cube;
431 }
432 
433 
434 /***********************************************************************//**
435  * @brief Read model from XML element
436  *
437  * @param[in] xml XML element.
438  *
439  * @exception GException::invalid_value
440  * Model definition requires at least one node.
441  *
442  * Read the COMPTEL DRB fitting model from an XML element.
443  *
444  * The model is composed of nodes that define the normalization value as
445  * function of Phibar value. The following XML file syntax is expected:
446  *
447  * <source name="Background" type="DRBFitting" instrument="COM">
448  * <node>
449  * <parameter name="Phibar" .../>
450  * <parameter name="Normalization" .../>
451  * </node>
452  * ...
453  * <node>
454  * <parameter name="Phibar" .../>
455  * <parameter name="Normalization" .../>
456  * </node>
457  * </source>
458  ***************************************************************************/
460 {
461  // Free space for nodes
462  m_phibars.clear();
463  m_values.clear();
464 
465  // Get number of nodes from XML file
466  int nodes = xml.elements("node");
467 
468  // Throw an error if there are no nodes
469  if (nodes < 1) {
470  std::string msg = "DRB fitting model requires at least one Phibar "
471  "node. Please correct XML format.";
472  throw GException::invalid_value(G_READ, msg);
473  }
474 
475  // Loop over all nodes
476  for (int i = 0; i < nodes; ++i) {
477 
478  // Allocate node parameters
479  GModelPar phibar;
480  GModelPar normalization;
481 
482  // Get node
483  const GXmlElement* node = xml.element("node", i);
484 
485  // Read Phibar parameter
486  const GXmlElement* par = gammalib::xml_get_par(G_READ, *node, "Phibar");
487  phibar.read(*par);
488 
489  // Read Normalization parameter
490  par = gammalib::xml_get_par(G_READ, *node, "Normalization");
491  normalization.read(*par);
492 
493  // Set parameter names
494  std::string phibar_name = "Phibar layer "+gammalib::str(i);
495  std::string normalization_name = "Scale factor "+gammalib::str(i);
496 
497  // Set Phibar attributes
498  phibar.name(phibar_name);
499  phibar.unit("deg");
500  phibar.has_grad(false);
501 
502  // Set normalization attributes
503  normalization.name(normalization_name);
504  normalization.unit("");
505  normalization.has_grad(true);
506 
507  // Push node parameters on list
508  m_phibars.push_back(phibar);
509  m_values.push_back(normalization);
510 
511  } // endfor: looped over nodes
512 
513  // Read model attributes
514  read_attributes(xml);
515 
516  // Set pointers
517  set_pointers();
518 
519  // Set evluation cache
520  set_cache();
521 
522  // Return
523  return;
524 }
525 
526 
527 /***********************************************************************//**
528  * @brief Write model into XML element
529  *
530  * @param[in] xml XML element.
531  *
532  * @exception GException::model_invalid_spectral
533  * Existing XML element is not of required type
534  * @exception GException::model_invalid_parnum
535  * Invalid number of model parameters or nodes found in XML element.
536  * @exception GException::model_invalid_parnames
537  * Invalid model parameter names found in XML element.
538  *
539  * Write the COMPTEL DRB fitting model into an XML element.
540  *
541  * The model is composed of nodes that define the normalization value as
542  * function of Phibar value. The following XML file syntax is expected:
543  *
544  * <source name="Background" type="DRBFitting" instrument="COM">
545  * <node>
546  * <parameter name="Phibar" .../>
547  * <parameter name="Normalization" .../>
548  * </node>
549  * ...
550  * <node>
551  * <parameter name="Phibar" .../>
552  * <parameter name="Normalization" .../>
553  * </node>
554  * </source>
555  ***************************************************************************/
557 {
558  // Initialise pointer on source
559  GXmlElement* src = NULL;
560 
561  // Search corresponding source
562  int n = xml.elements("source");
563  for (int k = 0; k < n; ++k) {
564  GXmlElement* element = xml.element("source", k);
565  if (element->attribute("name") == name()) {
566  src = element;
567  break;
568  }
569  }
570 
571  // If no source with corresponding name was found then append one.
572  // Set also the type and the instrument.
573  if (src == NULL) {
574  src = xml.append("source");
575  src->attribute("name", name());
576  src->attribute("type", type());
577  if (instruments().length() > 0) {
578  src->attribute("instrument", instruments());
579  }
580  }
581 
582  // Verify model type
583  if (src->attribute("type") != type()) {
584  std::string msg = "Invalid model type \""+src->attribute("type")+"\" "
585  "found in XML file. Model type \""+type()+"\" "
586  "expected.";
588  }
589 
590  // Determine number of nodes
591  int nodes = m_phibars.size();
592 
593  // If XML element has 0 nodes then append nodes
594  if (src->elements() == 0) {
595  for (int i = 0; i < nodes; ++i) {
596  src->append(GXmlElement("node"));
597  }
598  }
599 
600  // Verify that XML element has the required number of nodes
601  if (src->elements() != nodes || src->elements("node") != nodes) {
602  std::string msg = "Invalid number of nodes "+
603  gammalib::str(src->elements("node"))+
604  " found in XML file, but model requires exactly "+
605  gammalib::str(nodes)+" nodes.";
607  }
608 
609  // Loop over all nodes
610  for (int i = 0; i < nodes; ++i) {
611 
612  // Get node
613  GXmlElement* node = src->element("node", i);
614 
615  // Write Phibar parameter
616  GXmlElement* par = gammalib::xml_need_par(G_WRITE, *node, "Phibar");
617  GModelPar mpar = m_phibars[i];
618  mpar.name("Phibar");
619  mpar.write(*par);
620 
621  // Write Normalization parameter
622  par = gammalib::xml_need_par(G_WRITE, *node, "Normalization");
623  mpar = m_values[i];
624  mpar.name("Normalization");
625  mpar.write(*par);
626 
627  } // endfor: looped over nodes
628 
629  // Write model attributes
630  write_attributes(*src);
631 
632  // Return
633  return;
634 }
635 
636 
637 /***********************************************************************//**
638  * @brief Print model information
639  *
640  * @param[in] chatter Chattiness (defaults to NORMAL).
641  * @return String containing model information.
642  ***************************************************************************/
643 std::string GCOMModelDRBFitting::print(const GChatter& chatter) const
644 {
645  // Initialise result string
646  std::string result;
647 
648  // Continue only if chatter is not silent
649  if (chatter != SILENT) {
650 
651  // Append header
652  result.append("=== GCOMModelDRBFitting ===");
653 
654  // Append attributes
655  result.append("\n"+print_attributes());
656 
657  // Append node summary
658  result.append("\n"+gammalib::parformat("Number of nodes"));
659  result.append(gammalib::str(m_phibars.size()));
660  result.append("\n"+gammalib::parformat("Number of parameters"));
661  result.append(gammalib::str(size()));
662  for (int i = 0; i < size(); ++i) {
663  result.append("\n"+m_pars[i]->print(chatter));
664  }
665 
666  } // endif: chatter was not silent
667 
668  // Return result
669  return result;
670 }
671 
672 
673 /*==========================================================================
674  = =
675  = Private methods =
676  = =
677  ==========================================================================*/
678 
679 /***********************************************************************//**
680  * @brief Initialise class members
681  ***************************************************************************/
683 {
684  // Initialise members
685  m_phibars.clear();
686  m_values.clear();
687 
688  // Initialise cache
689  m_scale = true;
690  m_fixed = true;
691  m_old_phibars.clear();
692  m_nodes.clear();
693 
694  // Return
695  return;
696 }
697 
698 
699 /***********************************************************************//**
700  * @brief Copy class members
701  *
702  * @param[in] model Model.
703  ***************************************************************************/
705 {
706  // Copy members
707  m_phibars = model.m_phibars;
708  m_values = model.m_values;
709 
710  // Copy cache
711  m_scale = model.m_scale;
712  m_fixed = model.m_fixed;
714  m_nodes = model.m_nodes;
715 
716  // Set parameter pointers
717  set_pointers();
718 
719  // Return
720  return;
721 }
722 
723 
724 /***********************************************************************//**
725  * @brief Delete class members
726  ***************************************************************************/
728 {
729  // Return
730  return;
731 }
732 
733 
734 /***********************************************************************//**
735  * @brief Set pointers
736  *
737  * Set pointers to all model parameters. The pointers are stored in a vector
738  * that is member of the GModel base class.
739  ***************************************************************************/
741 {
742  // Clear parameter pointer(s)
743  m_pars.clear();
744 
745  // Get number of nodes
746  int nodes = m_phibars.size();
747 
748  // Set parameter pointers for all nodes
749  for (int i = 0; i < nodes; ++i) {
750 
751  // Signal that Phibar values have no gradients
752  m_phibars[i].has_grad(false);
753 
754  // Signal that values have gradients
755  m_values[i].has_grad(true);
756 
757  // Set pointer
758  m_pars.push_back(&(m_phibars[i]));
759  m_pars.push_back(&(m_values[i]));
760 
761  } // endfor: looped over nodes
762 
763  // Return
764  return;
765 }
766 
767 
768 /***********************************************************************//**
769  * @brief Set evaluation cache
770  *
771  * Set the evaluation cache for fast computations. The evaluation cache
772  * consists of the Phibar values stored in a node array. The evaluation
773  * cache is only filled if at least 2 nodes are available. If only a single
774  * node is available, the model is considered as a simple scaling factor.
775  ***************************************************************************/
777 {
778  // Clear any existing values
779  m_old_phibars.clear();
780  m_nodes.clear();
781  m_fixed = true;
782  m_scale = true; // Signals that model is a scale factor
783 
784  // Determine number of parameters
785  int num = m_phibars.size();
786 
787  // Continue only if we have at least two nodes
788  if (num >= 2) {
789 
790  // Signal that model is not a scale factor
791  m_scale = false;
792 
793  // Set Phibar node array. Signal if one of the Phibar values is free
794  for (int i = 0; i < num; ++i) {
795  double phibar = m_phibars[i].value();
796  m_nodes.append(phibar);
797  m_old_phibars.push_back(phibar);
798  if (m_phibars[i].is_free()) {
799  m_fixed = false;
800  }
801  }
802 
803  } // endif: there were at least two nodes
804 
805  // Return
806  return;
807 }
808 
809 
810 /***********************************************************************//**
811  * @brief Update evaluation cache
812  *
813  * Updates the evaluation cache by computing the
814  * changed.
815  ***************************************************************************/
817 {
818  // Determine number of parameters
819  int num = m_phibars.size();
820 
821  // Continue only if we have at least two nodes
822  if (num >= 2) {
823 
824  // Update Phibar values
825  for (int i = 0; i < num; ++i) {
826  double phibar = m_phibars[i].value();
827  if (phibar != m_old_phibars[i]) {
828  m_nodes[i] = phibar;
829  m_old_phibars[i] = phibar;
830  }
831  }
832 
833  } // endif: there were at least two nodes
834 
835  // Return
836  return;
837 }
COMPTEL DRB model fitting class.
void phibar(const double &phibar)
Set event Compton scatter angle.
void free_members(void)
Delete class members.
Definition: GModel.cpp:672
const int & index(void) const
Return bin index.
const std::string & name(void) const
Return parameter name.
std::string print_attributes(void) const
Print model attributes.
Definition: GModel.cpp:770
virtual void read(const GXmlElement &xml)
Read model from XML element.
Interface definition for the model registry class.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
Definition: GModelPar.cpp:351
virtual GCOMModelDRBFitting * clone(void) const
Clone instance.
COMPTEL observation class interface definition.
Abstract interface for the event classes.
Definition: GEvent.hpp:71
XML element node class.
Definition: GXmlElement.hpp:48
const double & wgt_left(void) const
Returns left node weight.
Definition: GNodeArray.hpp:264
void free_members(void)
Delete class members.
Definition: GModelData.cpp:300
bool m_fixed
All Phibar values are fixed.
void clear(void)
Clear node array.
Definition: GNodeArray.cpp:235
const GCOMDri & drb(void) const
Return background model.
Random number generator class.
Definition: GRan.hpp:44
virtual std::string type(void) const
Return model type.
virtual int elements(void) const
Return number of GXMLElement children of node.
Definition: GXmlNode.cpp:586
Time class.
Definition: GTime.hpp:55
Gammalib tools definition.
void set_value(const double &value) const
Set indices and weighting factors for interpolation.
Definition: GNodeArray.cpp:587
virtual GCOMModelDRBFitting & operator=(const GCOMModelDRBFitting &model)
Assignment operator.
COMPTEL event bin class.
virtual void clear(void)
Clear instance.
virtual GCOMEventCube * mc(const GObservation &obs, GRan &ran) const
Return simulated list of events.
COMPTEL event bin class interface definition.
bool is_notanumber(const double &x)
Signal if argument is not a number.
Definition: GTools.hpp:200
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
Definition: GModel.hpp:178
int size(void) const
Return number of parameters in model.
Definition: GModel.hpp:233
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition: GTools.hpp:183
#define G_MC
void init_members(void)
Initialise class members.
Definition: GModel.cpp:622
Model parameter class.
Definition: GModelPar.hpp:87
#define G_WRITE
void init_members(void)
Initialise class members.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
const double & wgt_right(void) const
Returns right node weight.
Definition: GNodeArray.hpp:279
const GXmlAttribute * attribute(const int &index) const
Return attribute.
const std::string & name(void) const
Return parameter name.
Definition: GModel.hpp:261
const GSkyMap & map(void) const
Return DRI sky map.
Definition: GCOMDri.hpp:267
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
Definition: GTools.cpp:1610
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
Abstract data model class.
Definition: GModelData.hpp:55
virtual GModelData & operator=(const GModelData &model)
Assignment operator.
Definition: GModelData.cpp:125
void free_members(void)
Delete class members.
std::string instruments(void) const
Returns instruments to which model applies.
Definition: GModel.cpp:310
GChatter
Definition: GTypemaps.hpp:33
void update_cache(void) const
Update evaluation cache.
const int & inx_left(void) const
Returns left node index.
Definition: GNodeArray.hpp:235
Abstract observation base class.
COMPTEL event bin container class.
GModelPar & scale(const int &index)
Returns reference to scale parameter by index.
Definition: GModel.cpp:369
GCOMModelDRBFitting(void)
Void constructor.
const int & inx_right(void) const
Returns right node index.
Definition: GNodeArray.hpp:249
void write_attributes(GXmlElement &xml) const
Write model attributes.
Definition: GModel.cpp:723
bool m_scale
Model is a scale factor.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
Definition: GXmlNode.cpp:640
COMPTEL DRB model fitting class interface definition.
#define G_EVAL
virtual const GCOMInstDir & dir(void) const
Return instrument direction of event bin.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated data model.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
Definition: GModelPar.cpp:229
Interface class for COMPTEL observations.
const std::string & unit(void) const
Return parameter unit.
const GCOMModelDRBFitting g_com_drb_fitting_seed
Exception handler interface definition.
std::vector< GModelPar > m_values
Node values.
void read_attributes(const GXmlElement &xml)
Read model attributes.
Definition: GModel.cpp:684
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Evaluate function.
std::vector< double > m_old_phibars
Old Phibar values.
virtual void write(GXmlElement &xml) const
Write model into XML element.
Model registry class definition.
void set_cache(void) const
Set evaluation cache.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
Definition: GXmlNode.cpp:287
std::vector< GModelPar > m_phibars
Node Phibar values.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1116
virtual double size(void) const
Return size of event bin.
void append(const double &node)
Append one node to array.
Definition: GNodeArray.cpp:351
GNodeArray m_nodes
Phibar node values.
virtual ~GCOMModelDRBFitting(void)
Destructor.
const GXmlElement * xml_get_par(const std::string &origin, const GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
Definition: GTools.cpp:1662
const double * pixels(void) const
Returns pointer to pixel data.
Definition: GSkyMap.hpp:475
void set_pointers(void)
Set pointers.
void init_members(void)
Initialise class members.
Definition: GModelData.cpp:278
#define G_NRED
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
void copy_members(const GCOMModelDRBFitting &model)
Copy class members.
#define G_READ
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:462