GammaLib  2.1.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-2021 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  * Write the spatial information into an XML element.
423  ***************************************************************************/
425 {
426  // Verify model type
428 
429  // Write all model components
430  for (int i = 0; i < m_components.size(); ++i) {
431 
432  // Get spatial component
434 
435  // Fall through if component is empty
436  if (component == NULL) {
437  continue;
438  }
439 
440  // Create copy of the spatial model
441  GModelSpatial* spatial = component->clone();
442 
443  // Loop over all parameters of component and strip prefix
444  for (int k = 0; k < spatial->size(); ++k) {
445 
446  // Get model parameter
447  GModelPar& par = (*spatial)[k];
448 
449  // If name contains colon then strip the prefix and the colon from
450  // the name
451  std::string name = par.name();
452  int found = name.find(":");
453  if (found != std::string::npos) {
454  name = name.substr(found+1, std::string::npos);
455  par.name(name);
456  }
457 
458  } // endfor: looped over all parameters
459 
460  // Find XML element with matching name
461  GXmlElement *matching_model = NULL;
462  for (int k = 0; k < xml.elements("spatialModel"); ++k) {
463  if (xml.element("spatialModel", k)->attribute("component") ==
464  m_names[i]) {
465  matching_model = xml.element("spatialModel", k);
466  break;
467  }
468  } // endfor: loop over all XML elements
469 
470  // If no XML element with matching name was found then create a new
471  // XML element and append it
472  if (matching_model == NULL) {
473 
474  // Create XML element
475  GXmlElement element("spatialModel");
476 
477  // Write component name
478  element.attribute("component", m_names[i]);
479 
480  // Append XML element
481  xml.append(element);
482 
483  // Set pointer to XML element
484  matching_model = xml.element("spatialModel",
485  xml.elements("spatialModel")-1);
486 
487  } // endif: XML element created
488 
489  // Write component into XML element
490  spatial->write(*matching_model);
491 
492  // Write scale to XML element if needed
493  if (m_scales[i]->value() != 1.0 ||
494  m_scales[i]->is_free() ||
495  matching_model->has_attribute("scale")) {
496  matching_model->attribute("scale",
497  gammalib::str(m_scales[i]->value()));
498  if (m_scales[i]->is_free()) {
499  matching_model->attribute("scale_error",
500  gammalib::str(m_scales[i]->error()));
501  }
502  if (m_scales[i]->has_min()) {
503  matching_model->attribute("scale_min",
504  gammalib::str(m_scales[i]->min()));
505  }
506  if (m_scales[i]->has_max()) {
507  matching_model->attribute("scale_max",
508  gammalib::str(m_scales[i]->max()));
509  }
510  matching_model->attribute("free_scale",
511  gammalib::str(m_scales[i]->is_free()));
512  }
513 
514  // Delete clone
515  delete spatial;
516 
517  } // endfor: loop over all components
518 
519  // TODO: Remove unused xml elements
520 
521  // Return
522  return;
523 }
524 
525 
526 /***********************************************************************//**
527  * @brief Append spatial component
528  *
529  * @param[in] component Spatial model component to append.
530  * @param[in] name Name of spatial model.
531  * @param[in] par Model scaling parameter.
532  *
533  * Appends a spatial component to the composite model
534  ***************************************************************************/
536  const std::string& name,
537  const GModelPar& par)
538 {
539  // Append model container
540  m_components.push_back(component.clone());
541 
542  // Get index of latest model
543  int index = m_components.size()-1;
544 
545  // Use model index if component name is empty
546  std::string component_name = !name.empty() ? name
547  : gammalib::str(m_components.size());
548 
549  // Check if component name is unique, throw exception if not
550  if (gammalib::contains(m_names, component_name)) {
551  std::string msg = "Attempt to append component \""+component_name+"\" "
552  "to composite spatial model, but a component with the "
553  "same name exists already. Each component needs a "
554  "unique name.";
556  }
557 
558  // Add component name
559  m_names.push_back(component_name);
560 
561  // Get number of spectral parameters from model
562  int npars = m_components[index]->size();
563 
564  // Loop over model parameters
565  for (int ipar = 0; ipar < npars; ++ipar) {
566 
567  // Get model parameter
568  GModelPar* p = &(m_components[index]->operator[](ipar));
569 
570  // Modify parameter name
571  p->name(component_name+":"+p->name());
572 
573  // Append model parameter with new name to internal container
574  m_pars.push_back(p);
575 
576  } // endfor: loop over model parameters
577 
578  // Set scaling parameter
579  GModelPar* scale = new GModelPar(par);
580  scale->name(component_name + ":scale");
581  scale->scale(1.0);
582  scale->gradient(0.0);
583  scale->has_grad(false); // for the moment use numerical gradient
584 
585  // Push scale parameter in vector
586  m_scales.push_back(scale);
587 
588  // Push scale parameter in parameter stack
589  m_pars.push_back(scale);
590 
591  // Return
592  return;
593 }
594 
595 
596 /***********************************************************************//**
597  * @brief Returns pointer to spatial component element
598  *
599  * @param[in] index Index of spatial component [0,...,components()-1].
600  * @return Spatial model.
601  *
602  * @exception GException::out_of_range
603  * Index is out of range.
604  *
605  * Returns a spatial component to the composite model
606  ***************************************************************************/
607 const GModelSpatial* GModelSpatialComposite::component(const int& index) const
608 {
609  // Check if index is in validity range
610  if (index < 0 || index >= m_components.size()) {
611  throw GException::out_of_range(G_COMPONENT_INDEX, "Component Index",
612  index, m_components.size());
613  }
614 
615  // Return spatial component
616  return m_components[index];
617 }
618 
619 
620 /***********************************************************************//**
621  * @brief Returns pointer to specific spatial component
622  *
623  * @param[in] name Name of spatial component.
624  * @return Spatial model.
625  *
626  * @exception GException::invalid_argument
627  * Spatial model not found.
628  *
629  * Returns a spatial component of the composite model
630  ***************************************************************************/
631 const GModelSpatial* GModelSpatialComposite::component(const std::string& name) const
632 {
633  // Check if model name is found
634  int index = -1;
635  for (int i = 0; i < m_names.size(); ++i) {
636  if (m_names[i] == name) {
637  index = i;
638  break;
639  }
640  }
641 
642  // Check if component name was found
643  if (index == -1) {
644  std::string msg = "Model component \""+name+"\" not found in composite "
645  "spatial model.";
647  }
648 
649  // Return spatial component
650  return m_components[index];
651 }
652 
653 
654 /***********************************************************************//**
655  * @brief Returns scale of spatial component
656  *
657  * @param[in] index Index of spatial component [0,...,components()-1].
658  * @return Scale.
659  *
660  * @exception GException::out_of_range
661  * Index is out of range.
662  *
663  * Returns the scale of a spatial component to the composite model
664  ***************************************************************************/
665 double GModelSpatialComposite::scale(const int& index) const
666 {
667  // Check if index is in validity range
668  if (index < 0 || index >= m_scales.size()) {
669  throw GException::out_of_range(G_COMPONENT_INDEX, "Component Index",
670  index, m_scales.size());
671  }
672 
673  // Return spatial component scale
674  return m_scales[index]->value();
675 }
676 
677 
678 /***********************************************************************//**
679  * @brief Returns sum of all model scales
680  *
681  * @return Sum of all model scales
682  ***************************************************************************/
684 {
685  // Initialise sum
686  double sum = 0.0;
687 
688  // Loop over all component scales
689  for (int i = 0; i < m_scales.size(); ++i) {
690 
691  // Add scale to sum
692  sum += m_scales[i]->value();
693  }
694 
695  // Return sum
696  return sum;
697 }
698 
699 
700 /***********************************************************************//**
701  * @brief Returns flux integrated in sky region
702  *
703  * @param[in] region Sky region.
704  * @param[in] srcEng Energy.
705  * @param[in] srcTime Time.
706  * @return Flux (adimensional or ph/cm2/s).
707  *
708  * Returns flux within a sky region.
709  ***************************************************************************/
711  const GEnergy& srcEng,
712  const GTime& srcTime) const
713 {
714  // Initialise flux
715  double flux = 0.0;
716 
717  // Sum over all components
718  for (int i = 0; i < m_components.size(); ++i) {
719  flux += m_components[i]->flux(region, srcEng, srcTime) *
720  m_scales[i]->value();
721  }
722 
723  // Normalise sum by sum of scales
724  if (sum_of_scales() > 0) {
725  flux /= sum_of_scales();
726  }
727 
728  // Return flux
729  return flux;
730 }
731 
732 
733 /***********************************************************************//**
734  * @brief Print composite spatial model information
735  *
736  * @param[in] chatter Chattiness.
737  * @return String containing composite spatial model information.
738  ***************************************************************************/
739 std::string GModelSpatialComposite::print(const GChatter& chatter) const
740 {
741  // Initialise result string
742  std::string result;
743 
744  // Continue only if chatter is not silent
745  if (chatter != SILENT) {
746 
747  // Append header
748  result.append("=== GModelSpatialComposite ===");
749 
750  // Append information
751  result.append("\n"+gammalib::parformat("Number of components"));
752  result.append(gammalib::str(components()));
753  result.append("\n"+gammalib::parformat("Number of parameters"));
754  result.append(gammalib::str(size()));
755 
756  // Print parameter information
757  for (int i = 0; i < size(); ++i) {
758  result.append("\n"+m_pars[i]->print(chatter));
759  }
760 
761  } // endif: chatter was not silent
762 
763  // Return result
764  return result;
765 }
766 
767 
768 /*==========================================================================
769  = =
770  = Private methods =
771  = =
772  ==========================================================================*/
773 
774 /***********************************************************************//**
775  * @brief Initialise class members
776  ***************************************************************************/
778 {
779  // Initialise model type
780  m_type = "Composite";
781 
782  // Initialise other members
783  m_components.clear();
784  m_names.clear();
785  m_pars.clear();
786  m_scales.clear();
787 
788  // Return
789  return;
790 }
791 
792 
793 /***********************************************************************//**
794  * @brief Copy class members
795  *
796  * @param[in] model Spatial composite model.
797  ***************************************************************************/
799 {
800  // Copy members
801  m_type = model.m_type; // To copy model type
802  m_names = model.m_names;
803 
804  // Initialise components and scales
805  m_components.clear();
806  m_scales.clear();
807  m_pars.clear();
808 
809  // Copy components
810  for (int i = 0; i < model.m_components.size(); ++i) {
811 
812  // Clone component
813  m_components.push_back(model.m_components[i]->clone());
814 
815  // Get number of parameters to append
816  int npars = m_components[i]->size();
817 
818  // Append parameter references
819  for (int ipar = 0; ipar < npars; ++ipar) {
820  GModelPar& par = (*m_components[i])[ipar];
821  m_pars.push_back(&par);
822  }
823 
824  } // endfor: looped over all components
825 
826  // Copy scales
827  for (int i = 0; i < model.m_scales.size(); ++i) {
828 
829  // Clone scale
830  GModelPar* scale = model.m_scales[i]->clone();
831 
832  // Push scale parameter in vector
833  m_scales.push_back(scale);
834 
835  // Push scale parameter in parameter stack
836  m_pars.push_back(scale);
837 
838  } // endfor: looped over scales
839 
840  // Return
841  return;
842 }
843 
844 
845 /***********************************************************************//**
846  * @brief Delete class members
847  ***************************************************************************/
849 {
850  // Free model components
851  for (int i = 0; i < m_components.size(); ++i) {
852 
853  // Delete component i
854  if (m_components[i] != NULL) {
855  delete m_components[i];
856  }
857 
858  // Signal free pointer
859  m_components[i] = NULL;
860 
861  }
862 
863  // Free scaling parameters
864  for (int i = 0; i < m_scales.size(); ++i) {
865 
866  // Delete component i
867  if (m_scales[i] != NULL) {
868  delete m_scales[i];
869  }
870 
871  // Signal free pointer
872  m_scales[i] = NULL;
873 
874  }
875 
876  // Return
877  return;
878 }
879 
880 
881 /***********************************************************************//**
882  * @brief Set boundary sky region
883  *
884  * @todo Implement computation of sky boundary region
885  ***************************************************************************/
887 {
888  // Set sky region circle (all sky)
889  GSkyRegionCircle region(0.0, 0.0, 180.0);
890 
891  // Set region (circumvent const correctness)
892  const_cast<GModelSpatialComposite*>(this)->m_region = region;
893 
894  // Return
895  return;
896 }
bool contains(const std::string &str, const std::string &substring)
Checks if a substring is in a string.
Definition: GTools.cpp:1342
virtual double flux(const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns flux integrated in sky region.
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:48
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:944
Random number generator class.
Definition: GRan.hpp:44
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.
#define G_WRITE
Interface for the circular sky region class.
double min(const GVector &vector)
Computes minimum vector element.
Definition: GVector.cpp:886
Interface definition for the spatial model registry class.
double min(void) const
Return parameter minimum boundary.
GSkyRegionCircle m_region
Bounding circle.
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.
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
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.
std::string type(void) const
Return model type.
virtual GModelSpatialComposite & operator=(const GModelSpatialComposite &model)
Assignment operator.
double max(const GVector &vector)
Computes maximum vector element.
Definition: GVector.cpp:915
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.
const GSkyRegion * region(void) const
Return boundary sky region.
void free_members(void)
Delete class members.
void free_members(void)
Delete class members.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
Definition: GXmlNode.cpp:640
std::string m_type
Spatial 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:821
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 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:287
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1143
Sky direction class.
Definition: GSkyDir.hpp:62
virtual 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.
double todouble(const std::string &arg)
Convert string into double precision value.
Definition: GTools.cpp:926
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:489
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.
Definition: GTools.cpp:1819