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