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