GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatialComposite.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpatialComposite.cpp - Spatial composite model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2016-2017 by Domenico Tiziani *
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 GModelSpatialComposite.cpp
23  * @brief Spatial composite model class implementation
24  * @author Domenico Tiziani
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 "GMath.hpp"
36 
37 /* __ Constants __________________________________________________________ */
38 
39 
40 /* __ Globals ____________________________________________________________ */
42 const GModelSpatialRegistry g_spatial_comp_registry(&g_spatial_comp_seed);
43 
44 /* __ Method name definitions ____________________________________________ */
45 #define G_READ "GModelSpatialComposite::read(GXmlElement&)"
46 #define G_WRITE "GModelSpatialComposite::write(GXmlElement&)"
47 #define G_COMPONENT_INDEX "GModelSpatialComposite::component(int&)"
48 #define G_COMPONENT_NAME "GModelSpatialComposite::component(std::string&)"
49 #define G_APPEND "GModelSpatialComposite::append(GModelSpatial&, "\
50  "std::string&, GModelPar&)"
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 empty spatial composite model.
69  ***************************************************************************/
71 {
72  // Initialise members
73  init_members();
74 
75  // Return
76  return;
77 }
78 
79 
80 /***********************************************************************//**
81  * @brief Model type constructor
82  *
83  * @param[in] dummy Dummy flag.
84  * @param[in] type Model type.
85  *
86  * Constructs empty spatial composite model by specifying a model @p type.
87  ***************************************************************************/
89  const std::string& type) :
91 {
92  // Initialise members
93  init_members();
94 
95  // Set model type
96  m_type = type;
97 
98  // Return
99  return;
100 }
101 
102 
103 /***********************************************************************//**
104  * @brief XML constructor
105  *
106  * @param[in] xml XML element.
107  *
108  * Construct a spatial composite model by extracting information from an
109  * XML element. See the read() method for more information about the expected
110  * structure of the XML element.
111  ***************************************************************************/
113  GModelSpatial()
114 {
115  // Initialise members
116  init_members();
117 
118  // Read information from XML element
119  read(xml);
120 
121  // Return
122  return;
123 }
124 
125 
126 /***********************************************************************//**
127  * @brief Copy constructor
128  *
129  * @param[in] model Spatial composite model.
130  ***************************************************************************/
132  GModelSpatial(model)
133 {
134  // Initialise members
135  init_members();
136 
137  // Copy members
138  copy_members(model);
139 
140  // Return
141  return;
142 }
143 
144 
145 /***********************************************************************//**
146  * @brief Destructor
147  ***************************************************************************/
149 {
150  // Free members
151  free_members();
152 
153  // Return
154  return;
155 }
156 
157 
158 /*==========================================================================
159  = =
160  = Operators =
161  = =
162  ==========================================================================*/
163 
164 /***********************************************************************//**
165  * @brief Assignment operator
166  *
167  * @param[in] model Spatial composite model.
168  * @return Spatial composite model.
169  ***************************************************************************/
171 {
172  // Execute only if object is not identical
173  if (this != &model) {
174 
175  // Copy base class members
176  this->GModelSpatial::operator=(model);
177 
178  // Free members
179  free_members();
180 
181  // Initialise members
182  init_members();
183 
184  // Copy members
185  copy_members(model);
186 
187  } // endif: object was not identical
188 
189  // Return
190  return *this;
191 }
192 
193 
194 /*==========================================================================
195  = =
196  = Public methods =
197  = =
198  ==========================================================================*/
199 
200 /***********************************************************************//**
201  * @brief Clear spatial composite model
202  ***************************************************************************/
204 {
205  // Free class members (base and derived classes, derived class first)
206  free_members();
208 
209  // Initialise members
211  init_members();
212 
213  // Return
214  return;
215 }
216 
217 
218 /***********************************************************************//**
219  * @brief Clone spatial composite model
220  *
221  * @return Pointer to deep copy of spatial composite model.
222  ***************************************************************************/
224 {
225  // Clone point source model
226  return new GModelSpatialComposite(*this);
227 }
228 
229 
230 /***********************************************************************//**
231  * @brief Evaluate function
232  *
233  * @param[in] photon Incident photon.
234  * @param[in] gradients Compute gradients?
235  * @return Model value.
236  *
237  * Evaluates the spatial composite model by summing all model components,
238  * weighting by their scale and dividing the sum of all scales.
239  ***************************************************************************/
241  const bool& gradients) const
242 {
243  // Initialise value
244  double value = 0.0;
245 
246  // Sum over all components
247  for (int i = 0; i < m_components.size(); ++i) {
248  value += m_components[i]->eval(photon, gradients) *
249  m_scales[i]->value();
250  }
251 
252  // Normalise sum by sum of scales
253  if (sum_of_scales() > 0) {
254  value /= sum_of_scales();
255  }
256 
257  // Return value
258  return value;
259 }
260 
261 
262 /***********************************************************************//**
263  * @brief Returns MC sky direction
264  *
265  * @param[in] energy Photon energy.
266  * @param[in] time Photon arrival time.
267  * @param[in,out] ran Random number generator.
268  * @return Sky direction.
269  *
270  * Draws an arbitrary model component and an arbitrary direction from that
271  * component.
272  ***************************************************************************/
274  const GTime& time,
275  GRan& ran) const
276 {
277  // Randomly choose one model component weighted by scale
278 
279  // Calculate random number
280  double random = ran.uniform() * sum_of_scales();
281 
282  // Find index of chosen model component
283  double sum = 0.0;
284  int index = 0;
285  for (int i = 0; i < m_scales.size(); ++i) {
286  sum += m_scales[i]->value();
287  if (random <= sum) {
288  index = i;
289  break;
290  }
291  }
292 
293  if (index >= m_components.size()) {
294  index = m_components.size();
295  }
296 
297  // Draw random sky direction from the selected component
298  GSkyDir sky_dir = m_components[index]->mc(energy, time, ran);
299 
300  // Return sky direction
301  return (sky_dir);
302 }
303 
304 
305 /***********************************************************************//**
306  * @brief Checks where model contains specified sky direction
307  *
308  * @param[in] dir Sky direction.
309  * @param[in] margin Margin to be added to sky direction (degrees)
310  * @return True if the model contains the sky direction.
311  *
312  * Signals whether a sky direction is contained in one of the
313  * model components.
314  ***************************************************************************/
316  const double& margin) const
317 {
318  // Initialise containment flag
319  bool containment = false;
320 
321  // Loop over all components
322  for (int i = 0; i < m_components.size(); ++i) {
323  if (m_components[i]->contains(dir, margin) &&
324  m_scales[i]->value() != 0.0) {
325  containment = true;
326  break;
327  }
328  }
329 
330  // Return containment
331  return containment;
332 }
333 
334 
335 /***********************************************************************//**
336  * @brief Read model from XML element
337  *
338  * @param[in] xml XML element.
339  *
340  * Reads the spatial information from an XML element.
341  ***************************************************************************/
343 {
344  // Get number of spatial components
345  int n_comp = xml.elements("spatialModel");
346 
347  // Loop over spatial elements
348  for (int i = 0; i < n_comp; ++i) {
349 
350  // Get spatial XML element
351  const GXmlElement* spec = xml.element("spatialModel", i);
352 
353  // Initialise a spatial registry object
354  GModelSpatialRegistry registry;
355 
356  // Read spatial model
357  GModelSpatial* ptr = registry.alloc(*spec);
358 
359  // Get component attribute from XML file
360  std::string name = spec->attribute("component");
361 
362  // Initialise scale parameter
363  GModelPar scale("", 1.0);
364  scale.range(1.0e-10, 1.0e10);
365  scale.fix();
366 
367  // Get scale value
368  if (spec->has_attribute("scale")) {
369 
370  // Get scale value
371  scale.value(gammalib::todouble(spec->attribute("scale")));
372 
373  // If there is a "free_scale" attribute the fix or free the scaling
374  // parameter accordingly
375  if (spec->has_attribute("free_scale")) {
376  if (gammalib::toint(spec->attribute("free_scale")) == 1) {
377  scale.free();
378  }
379  else {
380  scale.fix();
381  }
382  }
383 
384  // If there is a "scale_min" attribute set the minimum accordingly;
385  // otherwise remove minimum
386  if (spec->has_attribute("scale_min")) {
387  scale.min(gammalib::todouble(spec->attribute("scale_min")));
388  }
389  else {
390  scale.remove_min();
391  }
392 
393  // If there is a "scale_max" attribute set the maximum accordingly;
394  // otherwise remove maximum
395  if (spec->has_attribute("scale_max")) {
396  scale.max(gammalib::todouble(spec->attribute("scale_max")));
397  }
398  else {
399  scale.remove_max();
400  }
401 
402  } // endif: there was a scale attribute
403 
404  // Append spatial component to container
405  append(*ptr, name, scale);
406 
407  // Free spatial model
408  delete ptr;
409 
410  } // endfor: loop over components
411 
412  // Return
413  return;
414 }
415 
416 
417 /***********************************************************************//**
418  * @brief Write model into XML element
419  *
420  * @param[in] xml XML element into which model information is written.
421  *
422  * @exception GException::model_invalid_spatial
423  * Existing XML element is not of appropriate type
424  * @exception GException::model_invalid_parnum
425  * Invalid number of model parameters found in XML element.
426  * @exception GException::model_invalid_parnames
427  * Invalid model parameter names found in XML element.
428  *
429  * Write the spatial information into an XML element.
430  ***************************************************************************/
432 {
433  // Set model type
434  if (xml.attribute("type") == "") {
435  xml.attribute("type", type());
436  }
437 
438  // Verify model type
439  if (xml.attribute("type") != type()) {
441  "Spatial model is not of type \""+type()+"\".");
442  }
443 
444  // Write all model components
445  for (int i = 0; i < m_components.size(); ++i) {
446 
447  // Get spatial component
449 
450  // Fall through if component is empty
451  if (component == NULL) {
452  continue;
453  }
454 
455  // Create copy of the spatial model
456  GModelSpatial* spatial = component->clone();
457 
458  // Loop over all parameters of component and strip prefix
459  for (int k = 0; k < spatial->size(); ++k) {
460 
461  // Get model parameter
462  GModelPar& par = (*spatial)[k];
463 
464  // If name contains colon then strip the prefix and the colon from
465  // the name
466  std::string name = par.name();
467  int found = name.find(":");
468  if (found != std::string::npos) {
469  name = name.substr(found+1, std::string::npos);
470  par.name(name);
471  }
472 
473  } // endfor: looped over all parameters
474 
475  // Find XML element with matching name
476  GXmlElement *matching_model = NULL;
477  for (int k = 0; k < xml.elements("spatialModel"); ++k) {
478  if (xml.element("spatialModel", k)->attribute("component") ==
479  m_names[i]) {
480  matching_model = xml.element("spatialModel", k);
481  break;
482  }
483  } // endfor: loop over all XML elements
484 
485  // If no XML element with matching name was found then create a new
486  // XML element and append it
487  if (matching_model == NULL) {
488 
489  // Create XML element
490  GXmlElement element("spatialModel");
491 
492  // Write component name
493  element.attribute("component", m_names[i]);
494 
495  // Append XML element
496  xml.append(element);
497 
498  // Set pointer to XML element
499  matching_model = xml.element("spatialModel",
500  xml.elements("spatialModel")-1);
501 
502  } // endif: XML element created
503 
504  // Write component into XML element
505  spatial->write(*matching_model);
506 
507  // Write scale to XML element if needed
508  if (m_scales[i]->value() != 1.0 ||
509  m_scales[i]->is_free() ||
510  matching_model->has_attribute("scale")) {
511  matching_model->attribute("scale",
512  gammalib::str(m_scales[i]->value()));
513  if (m_scales[i]->is_free()) {
514  matching_model->attribute("scale_error",
515  gammalib::str(m_scales[i]->error()));
516  }
517  if (m_scales[i]->has_min()) {
518  matching_model->attribute("scale_min",
519  gammalib::str(m_scales[i]->min()));
520  }
521  if (m_scales[i]->has_max()) {
522  matching_model->attribute("scale_max",
523  gammalib::str(m_scales[i]->max()));
524  }
525  matching_model->attribute("free_scale",
526  gammalib::str(m_scales[i]->is_free()));
527  }
528 
529  // Delete clone
530  delete spatial;
531 
532  } // endfor: loop over all components
533 
534  // TODO: Remove unused xml elements
535 
536  // Return
537  return;
538 }
539 
540 
541 /***********************************************************************//**
542  * @brief Append spatial component
543  *
544  * @param[in] component Spatial model component to append.
545  * @param[in] name Name of spatial model.
546  * @param[in] par Model scaling parameter.
547  *
548  * Appends a spatial component to the composite model
549  ***************************************************************************/
551  const std::string& name,
552  const GModelPar& par)
553 {
554  // Append model container
555  m_components.push_back(component.clone());
556 
557  // Get index of latest model
558  int index = m_components.size()-1;
559 
560  // Use model index if component name is empty
561  std::string component_name = !name.empty() ? name
562  : gammalib::str(m_components.size());
563 
564  // Check if component name is unique, throw exception if not
565  if (gammalib::contains(m_names, component_name)) {
566  std::string msg = "Attempt to append component \""+component_name+"\" "
567  "to composite spatial model, but a component with the "
568  "same name exists already. Each component needs a "
569  "unique name.";
571  }
572 
573  // Add component name
574  m_names.push_back(component_name);
575 
576  // Get number of spectral parameters from model
577  int npars = m_components[index]->size();
578 
579  // Loop over model parameters
580  for (int ipar = 0; ipar < npars; ++ipar) {
581 
582  // Get model parameter
583  GModelPar* p = &(m_components[index]->operator[](ipar));
584 
585  // Modify parameter name
586  p->name(component_name+":"+p->name());
587 
588  // Append model parameter with new name to internal container
589  m_pars.push_back(p);
590 
591  } // endfor: loop over model parameters
592 
593  // Set scaling parameter
594  GModelPar* scale = new GModelPar(par);
595  scale->name(component_name + ":scale");
596  scale->scale(1.0);
597  scale->gradient(0.0);
598  scale->has_grad(false); // for the moment use numerical gradient
599 
600  // Push scale parameter in vector
601  m_scales.push_back(scale);
602 
603  // Push scale parameter in parameter stack
604  m_pars.push_back(scale);
605 
606  // Return
607  return;
608 }
609 
610 
611 /***********************************************************************//**
612  * @brief Returns pointer to spatial component element
613  *
614  * @param[in] index Index of spatial component [0,...,components()-1].
615  * @return Spatial model.
616  *
617  * @exception GException::out_of_range
618  * Index is out of range.
619  *
620  * Returns a spatial component to the composite model
621  ***************************************************************************/
622 const GModelSpatial* GModelSpatialComposite::component(const int& index) const
623 {
624  // Check if index is in validity range
625  if (index < 0 || index >= m_components.size()) {
626  throw GException::out_of_range(G_COMPONENT_INDEX, "Component Index",
627  index, m_components.size());
628  }
629 
630  // Return spatial component
631  return m_components[index];
632 }
633 
634 
635 /***********************************************************************//**
636  * @brief Returns pointer to specific spatial component
637  *
638  * @param[in] name Name of spatial component.
639  * @return Spatial model.
640  *
641  * @exception GException::invalid_argument
642  * Spatial model not found.
643  *
644  * Returns a spatial component of the composite model
645  ***************************************************************************/
646 const GModelSpatial* GModelSpatialComposite::component(const std::string& name) const
647 {
648  // Check if model name is found
649  int index = -1;
650  for (int i = 0; i < m_names.size(); ++i) {
651  if (m_names[i] == name) {
652  index = i;
653  break;
654  }
655  }
656 
657  // Check if component name was found
658  if (index == -1) {
659  std::string msg = "Model component \""+name+"\" not found in composite "
660  "spatial model.";
662  }
663 
664  // Return spatial component
665  return m_components[index];
666 }
667 
668 
669 /***********************************************************************//**
670  * @brief Returns scale of spatial component
671  *
672  * @param[in] index Index of spatial component [0,...,components()-1].
673  * @return Scale.
674  *
675  * @exception GException::out_of_range
676  * Index is out of range.
677  *
678  * Returns the scale of a spatial component to the composite model
679  ***************************************************************************/
680 double GModelSpatialComposite::scale(const int& index) const
681 {
682  // Check if index is in validity range
683  if (index < 0 || index >= m_scales.size()) {
684  throw GException::out_of_range(G_COMPONENT_INDEX, "Component Index",
685  index, m_scales.size());
686  }
687 
688  // Return spatial component scale
689  return m_scales[index]->value();
690 }
691 
692 
693 /***********************************************************************//**
694  * @brief Returns sum of all model scales
695  *
696  * @return Sum of all model scales
697  ***************************************************************************/
699 {
700  // Initialise sum
701  double sum = 0.0;
702 
703  // Loop over all component scales
704  for (int i = 0; i < m_scales.size(); ++i) {
705 
706  // Add scale to sum
707  sum += m_scales[i]->value();
708  }
709 
710  // Return sum
711  return sum;
712 }
713 
714 
715 /***********************************************************************//**
716  * @brief Print composite spatial model information
717  *
718  * @param[in] chatter Chattiness.
719  * @return String containing composite spatial model information.
720  ***************************************************************************/
721 std::string GModelSpatialComposite::print(const GChatter& chatter) const
722 {
723  // Initialise result string
724  std::string result;
725 
726  // Continue only if chatter is not silent
727  if (chatter != SILENT) {
728 
729  // Append header
730  result.append("=== GModelSpatialComposite ===");
731 
732  // Append information
733  result.append("\n"+gammalib::parformat("Number of components"));
734  result.append(gammalib::str(components()));
735  result.append("\n"+gammalib::parformat("Number of parameters"));
736  result.append(gammalib::str(size()));
737 
738  // Print parameter information
739  for (int i = 0; i < size(); ++i) {
740  result.append("\n"+m_pars[i]->print(chatter));
741  }
742 
743  } // endif: chatter was not silent
744 
745  // Return result
746  return result;
747 }
748 
749 
750 /*==========================================================================
751  = =
752  = Private methods =
753  = =
754  ==========================================================================*/
755 
756 /***********************************************************************//**
757  * @brief Initialise class members
758  ***************************************************************************/
760 {
761  // Initialise model type
762  m_type = "Composite";
763 
764  // Initialise other members
765  m_components.clear();
766  m_names.clear();
767  m_region.clear();
768  m_pars.clear();
769  m_scales.clear();
770 
771  // Return
772  return;
773 }
774 
775 
776 /***********************************************************************//**
777  * @brief Copy class members
778  *
779  * @param[in] model Spatial composite model.
780  ***************************************************************************/
782 {
783  // Copy members
784  m_type = model.m_type;
785  m_names = model.m_names;
786  m_region = model.m_region;
787 
788  // Initialise components and scales
789  m_components.clear();
790  m_scales.clear();
791  m_pars.clear();
792 
793  // Copy components
794  for (int i = 0; i < model.m_components.size(); ++i) {
795 
796  // Clone component
797  m_components.push_back(model.m_components[i]->clone());
798 
799  // Get number of parameters to append
800  int npars = m_components[i]->size();
801 
802  // Append parameter references
803  for (int ipar = 0; ipar < npars; ++ipar) {
804  GModelPar& par = (*m_components[i])[ipar];
805  m_pars.push_back(&par);
806  }
807 
808  } // endfor: looped over all components
809 
810  // Copy scales
811  for (int i = 0; i < model.m_scales.size(); ++i) {
812 
813  // Clone scale
814  GModelPar* scale = model.m_scales[i]->clone();
815 
816  // Push scale parameter in vector
817  m_scales.push_back(scale);
818 
819  // Push scale parameter in parameter stack
820  m_pars.push_back(scale);
821 
822  } // endfor: looped over scales
823 
824  // Return
825  return;
826 }
827 
828 
829 /***********************************************************************//**
830  * @brief Delete class members
831  ***************************************************************************/
833 {
834  // Free model components
835  for (int i = 0; i < m_components.size(); ++i) {
836 
837  // Delete component i
838  if (m_components[i] != NULL) {
839  delete m_components[i];
840  }
841 
842  // Signal free pointer
843  m_components[i] = NULL;
844 
845  }
846 
847  // Free scaling parameters
848  for (int i = 0; i < m_scales.size(); ++i) {
849 
850  // Delete component i
851  if (m_scales[i] != NULL) {
852  delete m_scales[i];
853  }
854 
855  // Signal free pointer
856  m_scales[i] = NULL;
857 
858  }
859 
860  // Return
861  return;
862 }
863 
864 
865 /***********************************************************************//**
866  * @brief Set boundary sky region
867  *
868  * @todo Implement computation of sky boundary region
869  ***************************************************************************/
871 {
872  // Set sky region centre to (0,0)
873  m_region.centre(0.0, 0.0);
874 
875  // Set sky region radius to 180 degrees (all points included)
876  m_region.radius(180.0);
877 
878  // Return
879  return;
880 }
bool contains(const std::string &str, const std::string &substring)
Checks if a substring is in a string.
Definition: GTools.cpp:1221
void remove_min(void)
Removes minimum boundary.
#define G_COMPONENT_INDEX
virtual void read(const GXmlElement &xml)
Read model from XML element.
const std::string & name(void) const
Return parameter name.
double gradient(void) const
Return parameter gradient.
int size(void) const
Return number of parameters.
const GModelSpatial * component(const int &index) const
Returns pointer to spatial component element.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual void clear(void)
Clear spatial composite model.
GModelSpatialComposite(void)
Void constructor.
XML element node class.
Definition: GXmlElement.hpp:47
double max(void) const
Return parameter maximum boundary.
virtual GModelSpatial & operator=(const GModelSpatial &model)
Assignment operator.
double sum(const GVector &vector)
Computes vector sum.
Definition: GVector.cpp:901
Random number generator class.
Definition: GRan.hpp:44
virtual int elements(void) const
Return number of GXMLElement children of node.
Definition: GXmlNode.cpp:580
Time class.
Definition: GTime.hpp:54
Gammalib tools definition.
#define G_WRITE
double min(const GVector &vector)
Computes minimum vector element.
Definition: GVector.cpp:843
Interface definition for the spatial model registry class.
double min(void) const
Return parameter minimum boundary.
const double & radius(void) const
Return circular region radius (in degrees)
double sum_of_scales(void) const
Returns sum of all model scales.
Class that handles photons.
Definition: GPhoton.hpp:47
const double & scale(void) const
Return parameter scale.
Model parameter class.
Definition: GModelPar.hpp:87
virtual GModelSpatialComposite * clone(void) const
Clone spatial composite model.
std::vector< std::string > m_names
Component names.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
void free(void)
Free a parameter.
std::vector< GModelSpatial * > m_components
Components.
std::vector< GModelPar * > m_pars
Parameter pointers.
const GModelSpatialComposite g_spatial_comp_seed
void fix(void)
Fix a parameter.
#define G_APPEND
bool has_attribute(const std::string &name) const
Check if element has a given attribute.
double uniform(void)
Returns random double precision floating value in range 0 to 1.
Definition: GRan.cpp:242
Spatial model registry class definition.
void remove_max(void)
Removes maximum boundary.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
GChatter
Definition: GTypemaps.hpp:33
GModelSpatial * alloc(const GXmlElement &xml) const
Allocate spatial model that is found in XML element.
Spatial composite model class interface definition.
void copy_members(const GModelSpatialComposite &model)
Copy class members.
Spatial composite model.
GSkyRegionCircle m_region
Bounding circle.
virtual GModelSpatialComposite & operator=(const GModelSpatialComposite &model)
Assignment operator.
double max(const GVector &vector)
Computes maximum vector element.
Definition: GVector.cpp:872
void append(const GModelSpatial &component, const std::string &name="", const GModelPar &par=GModelPar("", 1.0))
Append spatial component.
std::vector< GModelPar * > m_scales
Component scales.
int components(void) const
Return number of model components.
void free_members(void)
Delete class members.
const GSkyDir & centre(void) const
Return circular region centre.
void free_members(void)
Delete class members.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
Definition: GXmlNode.cpp:634
std::string m_type
Model type.
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
double value(void) const
Return parameter value.
#define G_COMPONENT_NAME
Exception handler interface definition.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print composite spatial model information.
Abstract spatial model base class.
virtual void write(GXmlElement &xml) const =0
int toint(const std::string &arg)
Convert string into integer value.
Definition: GTools.cpp:700
void init_members(void)
Initialise class members.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Checks where model contains specified sky direction.
virtual std::string type(void) const
Return model type.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const
Evaluate function.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
Definition: GXmlNode.cpp:284
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1022
Sky direction class.
Definition: GSkyDir.hpp:62
void set_region(void) const
Set boundary sky region.
virtual GModelSpatial * clone(void) const =0
Clones object.
double scale(const int &index) const
Returns scale of spatial component.
Mathematical function definitions.
virtual ~GModelSpatialComposite(void)
Destructor.
void clear(void)
Clear instance.
double todouble(const std::string &arg)
Convert string into double precision value.
Definition: GTools.cpp:805
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
void init_members(void)
Initialise class members.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:413