GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GModelSpatialDiffuseMap.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpatialDiffuseMap.cpp - Spatial map model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2012-2024 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GModelSpatialDiffuseMap.cpp
23 * @brief Spatial map model class implementation
24 * @author Juergen Knoedlseder
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"
34#include "GHealpix.hpp"
37
38/* __ Constants __________________________________________________________ */
39
40/* __ Globals ____________________________________________________________ */
42const GModelSpatialRegistry g_spatial_map_registry(&g_spatial_map_seed);
43#if defined(G_LEGACY_XML_FORMAT)
44const GModelSpatialDiffuseMap g_spatial_map_legacy_seed(true, "SpatialMap");
45const GModelSpatialRegistry g_spatial_map_legacy_registry(&g_spatial_map_legacy_seed);
46#endif
47
48/* __ Method name definitions ____________________________________________ */
49#define G_MC "GModelSpatialDiffuseMap::mc(GEnergy&, GTime&, GRan&)"
50#define G_READ "GModelSpatialDiffuseMap::read(GXmlElement&)"
51#define G_WRITE "GModelSpatialDiffuseMap::write(GXmlElement&)"
52
53/* __ Macros _____________________________________________________________ */
54
55/* __ Coding definitions _________________________________________________ */
56
57/* __ Debug definitions __________________________________________________ */
58//#define G_DEBUG_MC //!< Debug MC method
59//#define G_DEBUG_MC_CACHE //!< Debug MC cache
60
61
62/*==========================================================================
63 = =
64 = Constructors/destructors =
65 = =
66 ==========================================================================*/
67
68/***********************************************************************//**
69 * @brief Void constructor
70 *
71 * Constructs empty spatial map model.
72 ***************************************************************************/
75{
76 // Initialise members
78
79 // Return
80 return;
81}
82
83
84/***********************************************************************//**
85 * @brief Model type constructor
86 *
87 * @param[in] dummy Dummy flag.
88 * @param[in] type Model type.
89 *
90 * Constructs empty spatial map model by specifying a model @p type.
91 ***************************************************************************/
93 const std::string& type) :
95{
96 // Initialise members
98
99 // Set model type
100 m_type = type;
101
102 // Return
103 return;
104}
105
106
107/***********************************************************************//**
108 * @brief XML constructor
109 *
110 * @param[in] xml XML element.
111 *
112 * Constructs spatial map model by extracting information from an XML
113 * element. See the read() method for more information about the expected
114 * structure of the XML element.
115 ***************************************************************************/
118{
119 // Initialise members
120 init_members();
121
122 // Read information from XML element
123 read(xml);
124
125 // Return
126 return;
127}
128
129
130/***********************************************************************//**
131 * @brief File name constructor
132 *
133 * @param[in] filename File name.
134 * @param[in] value Normalization factor.
135 * @param[in] normalize Normalize map?
136 *
137 * Constructs spatial map model by loading a sky map from the file specified
138 * by @p filename and by setting the @p value by which the map will be
139 * multiplied (or normalized).
140 ***************************************************************************/
142 const double& value,
143 const bool& normalize) :
145{
146 // Initialise members
147 init_members();
148
149 // Set normalization parameter. Any previous existing range is removed.
152
153 // Set normalization flag
155
156 // Load sky map
157 load(filename);
158
159 // Return
160 return;
161}
162
163
164/***********************************************************************//**
165 * @brief Sky map constructor
166 *
167 * @param[in] map Sky map.
168 * @param[in] value Normalization factor.
169 * @param[in] normalize Normalize map.
170 *
171 * Constructs spatial map model by setting the sky @p map and by setting the
172 * @p value by which the map will be multiplied (or normalized).
173 ***************************************************************************/
175 const double& value,
176 const bool& normalize) :
178{
179 // Initialise members
180 init_members();
181
182 // Set normalization parameter. Any previous existing range is removed.
185
186 // Set normalization flag
188
189 // Set sky map
190 m_map = map;
191
192 // Prepare sky map
193 prepare_map();
194
195 // Return
196 return;
197}
198
199
200/***********************************************************************//**
201 * @brief Copy constructor
202 *
203 * @param[in] model Spatial map model.
204 *
205 * Construct a spatial map model by copying another spatial map model.
206 ***************************************************************************/
209{
210 // Initialise members
211 init_members();
212
213 // Copy members
214 copy_members(model);
215
216 // Return
217 return;
218}
219
220
221/***********************************************************************//**
222 * @brief Destructor
223 ***************************************************************************/
225{
226 // Free members
227 free_members();
228
229 // Return
230 return;
231}
232
233
234/*==========================================================================
235 = =
236 = Operators =
237 = =
238 ==========================================================================*/
239
240/***********************************************************************//**
241 * @brief Assignment operator
242 *
243 * @param[in] model Spatial map model.
244 * @return Spatial map model.
245 *
246 * Assigns a spatial map model to another spatial map model.
247 ***************************************************************************/
249{
250 // Execute only if object is not identical
251 if (this != &model) {
252
253 // Copy base class members
255
256 // Free members
257 free_members();
258
259 // Initialise members
260 init_members();
261
262 // Copy members
263 copy_members(model);
264
265 } // endif: object was not identical
266
267 // Return
268 return *this;
269}
270
271
272/*==========================================================================
273 = =
274 = Public methods =
275 = =
276 ==========================================================================*/
277
278/***********************************************************************//**
279 * @brief Clear spatial map model
280 ***************************************************************************/
282{
283 // Free class members (base and derived classes, derived class first)
284 free_members();
287
288 // Initialise members
291 init_members();
292
293 // Return
294 return;
295}
296
297
298/***********************************************************************//**
299 * @brief Clone spatial map model
300 *
301 * @return Pointer to deep copy of spatial map model.
302 ***************************************************************************/
304{
305 // Clone diffuse map
306 return new GModelSpatialDiffuseMap(*this);
307}
308
309
310/***********************************************************************//**
311 * @brief Return intensity of sky map
312 *
313 * @param[in] photon Incident photon.
314 * @param[in] gradients Compute gradients?
315 * @return Sky map intensity (\f$\mbox{ph cm}^{-2}\mbox{sr}^{-1}\mbox{s}^{-1}\f$)
316 *
317 * Returns the intensity of the sky map at the specified sky direction
318 * multiplied by the normalization factor. If the sky direction falls outside
319 * the sky map, an intensity of 0 is returned.
320 *
321 * If the @p gradients flag is true the method will also evaluate the partial
322 * derivatives of the model.
323 ***************************************************************************/
325 const bool& gradients) const
326{
327 // Get skymap intensity
328 double intensity = m_map(photon.dir());
329
330 // Optionally compute partial derivatives
331 if (gradients) {
332
333 // Compute partial derivatives of the parameter values
334 double g_value = (m_value.is_free()) ? intensity * m_value.scale() : 0.0;
335
336 // Set gradient
337 m_value.factor_gradient(g_value);
338
339 } // endif: computed partial derivatives
340
341 // Return intensity times normalization factor
342 return (intensity * m_value.value());
343}
344
345
346/***********************************************************************//**
347 * @brief Returns MC sky direction
348 *
349 * @param[in] energy Photon energy (ignored).
350 * @param[in] time Photon arrival time (ignored).
351 * @param[in,out] ran Random number generator.
352 * @return Sky direction.
353 *
354 * @exception GException::invalid_value
355 * No sky map defined.
356 * @exception GException::invalid_return_value
357 * Simulation cone not defined, does not overlap with map or map
358 * is empty.
359 *
360 * Returns a random sky direction according to the intensity distribution of
361 * the model sky map. The method uses a rejection method to determine the sky
362 * direction. If no sky direction could be determined, the method throws an
363 * GException::invalid_return_value exception.
364 ***************************************************************************/
366 const GTime& time,
367 GRan& ran) const
368{
369 // Throw an exception if the maximum MC intensity is not positive. This
370 // can be the case because the simulation cone has not been defined or
371 // because it does not overlap with the sky map
372 if (m_mc_max <= 0.0) {
373 std::string msg = "Simulation cone has not been defined or does not "
374 "overlap with the sky map. Please specify a valid "
375 "simulation cone.";
377 }
378
379 // Determine number of skymap pixels
380 int npix = m_map.npix();
381
382 // Throw an exception if there are no sky map pixels
383 if (npix <= 0) {
384 std::string msg = "No sky map defined. Please specify a valid sky map.";
386 }
387
388 // Allocate sky direction
389 GSkyDir dir;
390
391 // Debug option: initialise counter
392 #if defined(G_DEBUG_MC)
393 int num_iterations = 0;
394 #endif
395
396 // Get sky direction
397 while (true) {
398
399 // Debug option: increment counter
400 #if defined(G_DEBUG_MC)
401 num_iterations++;
402 #endif
403
404 // Simulate random sky direction within Monte Carlo simulation cone
405 double theta = std::acos(1.0 - ran.uniform() * m_mc_one_minus_cosrad) *
407 double phi = 360.0 * ran.uniform();
408 dir = m_mc_cone.centre();
409 dir.rotate_deg(phi, theta);
410
411 // Get map value at simulated sky direction. If the map value is non-
412 // positive then simulate a new sky direction.
413 double value = m_map(dir);
414 if (value <= 0.0) {
415 continue;
416 }
417
418 // Get uniform random number
419 double uniform = ran.uniform() * m_mc_max;
420
421 // Exit loop if the random number is not larger than the sky map value
422 if (uniform <= value) {
423 break;
424 }
425
426 } // endwhile: loop until sky direction was accepted
427
428 // Debug option: log counter
429 #if defined(G_DEBUG_MC)
430 std::cout << num_iterations << " ";
431 #endif
432
433 // Return sky direction
434 return dir;
435}
436
437
438/***********************************************************************//**
439 * @brief Return normalization of diffuse map for Monte Carlo simulations
440 *
441 * @param[in] dir Centre of simulation cone.
442 * @param[in] radius Radius of simulation cone (degrees).
443 * @return Normalization.
444 *
445 * Returns the normalization of a diffuse map. The normalization is given
446 * by the model value times the integrated flux in the sky map over a
447 * circular region.
448 ***************************************************************************/
450 const double& radius) const
451{
452 // Set the MC cone
453 mc_cone(GSkyRegionCircle(dir, radius));
454
455 // Retrieve normalization
456 double norm = m_mc_norm * value();
457
458 // Return normalization
459 return norm;
460}
461
462
463/***********************************************************************//**
464 * @brief Signals whether model contains sky direction
465 *
466 * @param[in] dir Sky direction.
467 * @param[in] margin Margin to be added to sky direction (degrees)
468 * @return True if the model contains the sky direction.
469 *
470 * Signals whether a sky direction falls within the bounding circle of
471 * the diffuse map.
472 ***************************************************************************/
474 const double& margin) const
475{
476 // Initialise containment flag
477 bool contains = false;
478
479 // Continue only if radius is positive
480 if (m_region.radius() > 0.0) {
481
482 // Compute distance to centre
483 double distance = m_region.centre().dist_deg(dir);
484
485 // If distance is smaller than radius plus margin we consider
486 // the position to be contained within the bounding circle
487 if (distance < m_region.radius() + margin) {
488 contains = true;
489 }
490
491 }
492
493 // Return containment
494 return (contains);
495}
496
497
498/***********************************************************************//**
499 * @brief Read model from XML element
500 *
501 * @param[in] xml XML element.
502 *
503 * @exception GException::invalid_value
504 * Model parameters not found in XML element.
505 *
506 * Reads the spatial information for a diffuse map from an XML element. The
507 * expected format of the XML element is
508 *
509 * <spatialModel type="DiffuseMap" file="myfile.fits" normalize="1">
510 * <parameter name="Normalization" ../>
511 * </spatialModel>
512 *
513 * The @p file attribute provides the filename of the diffuse map FITS file.
514 * The filename may be either an absolute filename (starting with '/') or a
515 * relative filename. If no access path is given, the file is expected to
516 * reside in the same location as the XML file.
517 *
518 * The @p normalize attribute specifies whether the sky map should be
519 * normalized to unity flux or not. If the attribute is not given, the map
520 * will be automatically normalized. To prevent normalization,
521 * @p normalize="0" needs to be specified.
522 ***************************************************************************/
524{
525 // Verify number of model parameters
527
528 // If "Normalization" parameter exists then read parameter from this
529 // XML element
530 if (gammalib::xml_has_par(xml, "Normalization")) {
531 const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Normalization");
532 m_value.read(*par);
533 }
534
535 // ... otherwise try reading parameter from "Prefactor" parameter
536 #if defined(G_LEGACY_XML_FORMAT)
537 else if (gammalib::xml_has_par(xml, "Prefactor")) {
538 const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Prefactor");
539 m_value.read(*par);
540 }
541 #endif
542
543 // ... otherwise throw an exception
544 else {
545 #if defined(G_LEGACY_XML_FORMAT)
546 std::string msg = "Diffuse map model requires either "
547 "\"Normalization\" or \"Prefactor\" parameter.";
548 #else
549 std::string msg = "Diffuse map model requires \"Normalization\" "
550 "parameter.";
551 #endif
553 }
554
555 // Get optional normalization attribute
556 m_normalize = true;
557 m_has_normalize = false;
558 if (xml.has_attribute("normalize")) {
559 m_has_normalize = true;
560 std::string arg = xml.attribute("normalize");
561 if (arg == "0" || gammalib::tolower(arg) == "false") {
562 m_normalize = false;
563 }
564 }
565
566 // Load sky map.
567 load(gammalib::xml_file_expand(xml, xml.attribute("file")));
568
569 // Return
570 return;
571}
572
573
574/***********************************************************************//**
575 * @brief Write model into XML element
576 *
577 * @param[in] xml XML element.
578 *
579 * @exception GException::model_invalid_spatial
580 * Existing XML element is not of type "SpatialMap"
581 * @exception GException::model_invalid_parnum
582 * Invalid number of model parameters found in XML element.
583 * @exception GException::model_invalid_parnames
584 * Invalid model parameter names found in XML element.
585 *
586 * Writes the spatial information for a diffuse map into an XML element. The
587 * format of the XML element is
588 *
589 * <spatialModel type="DiffuseMap" file="myfile.fits" normalize="1">
590 * <parameter name="Prefactor" value="1" min="0.1" max="10" scale="1" free="0"/>
591 * </spatialModel>
592 *
593 * The @p file attribute provides the filename of the diffuse map FITS file.
594 * The filename may be either an absolute filename (starting with '/') or a
595 * relative filename. If no access path is given, the file is expected to
596 * reside in the same location as the XML file.
597 *
598 * The @p normalize attribute specifies whether the sky map should be
599 * normalized to unity flux or not. The attribute will only be written if the
600 * normalization is disabled.
601 ***************************************************************************/
603{
604 // Verify model type
606
607 // Get or create parameter
609
610 // Write parameters
612
613 // Set sky map file name
615
616 // Set optional normalization attribute
618 if (m_normalize) {
619 xml.attribute("normalize", "1");
620 }
621 else {
622 xml.attribute("normalize", "0");
623 }
624 }
625
626 // Return
627 return;
628}
629
630
631/***********************************************************************//**
632 * @brief Set Monte Carlo simulation cone
633 *
634 * @param[in] cone Monte Carlo simulation cone.
635 *
636 * Sets the simulation cone that defines the directions that will be
637 * simulated using the mc() method and pre-computes the maximum intensity and
638 * the spatially integrated flux of the map within the simulation cone
639 * region.
640 ***************************************************************************/
642{
643 // Continue only if the simulation cone has changed
644 if (cone != m_mc_cone) {
645
646 // Save simulation cone definition
647 m_mc_cone = cone;
648
649 // Pre-compute 1 - cosine of radius
651
652 // Initialise map maximum and normalisation
653 m_mc_max = 0.0;
654 m_mc_norm = 0.0;
655
656 // Determine number of skymap pixels
657 int npix = m_map.npix();
658
659 // Continue only if there are pixels
660 if (npix > 0) {
661
662 // Compute flux and maximum map intensity within the simulation cone
663 double sum = 0.0;
664 double sum_map = 0.0;
665 for (int i = 0; i < npix; ++i) {
666
667 // Get map flux, intensity and distance from MC cone centre
668 double flux = m_map.flux(i);
669 double intensity = m_map(i);
670 double distance = m_mc_cone.centre().dist_deg(m_map.pix2dir(i));
671
672 // Add flux if positive
673 if (flux > 0.0) {
674 if (distance <= m_mc_cone.radius()) {
675 sum += flux; // flux within simulation cone
676 }
677 sum_map += flux; // total flux
678 }
679
680 // Update maximum intensity
681 if (distance <= m_mc_cone.radius()) {
682 if (intensity > m_mc_max) {
683 m_mc_max = intensity;
684 }
685 }
686
687 } // endfor: looped over all map pixels
688
689 // Set the normalization factor for the MC simulations. In case
690 // that the map is normalised, this is the fraction of the flux
691 // that is comprised within the simulation cone. For non-normalised
692 // maps, this is simply the flux comprised within the simulation
693 // cone.
694 if (sum_map > 0.0) {
695 if (m_normalize) {
696 m_mc_norm = sum / sum_map;
697 }
698 else {
699 m_mc_norm = sum;
700 }
701 }
702
703 // Log maximum intensity and total flux for debugging
704 #if defined(G_DEBUG_MC_CACHE)
705 std::cout << "GModelSpatialDiffuseMap::mc_cone:" << std::endl;
706 std::cout << " Maximum map intensity:";
707 std::cout << m_mc_max << " ph/cm2/s/sr" << std::endl;
708 std::cout << " Spatially integrated flux:" << std::endl;
709 std::cout << sum << " ph/cm2/s" << std::endl;
710 std::cout << " Map normalisation:" << std::endl;
711 std::cout << m_mc_norm << " ph/cm2/s" << std::endl;
712 #endif
713
714 } // endif: there were map pixels
715
716 } // endif: simulation cone has changed
717
718 // Return
719 return;
720}
721
722
723/***********************************************************************//**
724 * @brief Returns diffuse map flux integrated in sky region
725 *
726 * @param[in] region Sky region.
727 * @param[in] srcEng Energy.
728 * @param[in] srcTime Time.
729 * @return Flux (adimensional or ph/cm2/s).
730 *
731 * Returns diffuse map flux within a sky region. The flux is defined as the
732 * sum of the flux in all diffuse map pixels that are contained within the
733 * sky region multiplied by the diffuse map normalisation factor.
734 ***************************************************************************/
736 const GEnergy& srcEng,
737 const GTime& srcTime) const
738{
739 // Compute flux in sky region
740 double flux = m_map.flux(region) * m_value.value();
741
742 // Return flux
743 return flux;
744}
745
746
747/***********************************************************************//**
748 * @brief Print map information
749 *
750 * @param[in] chatter Chattiness.
751 * @return String with diffuse map model information.
752 ***************************************************************************/
753std::string GModelSpatialDiffuseMap::print(const GChatter& chatter) const
754{
755 // Initialise result string
756 std::string result;
757
758 // Continue only if chatter is not silent
759 if (chatter != SILENT) {
760
761 // Append header
762 result.append("=== GModelSpatialDiffuseMap ===");
763
764 // Append parameters
765 result.append("\n"+gammalib::parformat("Sky map file"));
766 result.append(m_filename);
767 result.append("\n"+gammalib::parformat("Map normalization"));
768 result.append(gammalib::str(m_mc_norm)+" ph/cm2/s");
769 if (normalize()) {
770 result.append(" [normalized]");
771 }
772 result.append("\n"+gammalib::parformat("Map centre"));
773 result.append(m_region.centre().print());
774 result.append("\n"+gammalib::parformat("Map radius"));
775 result.append(gammalib::str(m_region.radius())+" deg");
776 result.append("\n"+gammalib::parformat("Number of parameters"));
777 result.append(gammalib::str(size()));
778 for (int i = 0; i < size(); ++i) {
779 result.append("\n"+m_pars[i]->print(chatter));
780 }
781
782 } // endif: chatter was not silent
783
784 // Return result
785 return result;
786}
787
788
789/***********************************************************************//**
790 * @brief Load skymap into the model class
791 *
792 * @param[in] filename Sky map file.
793 *
794 * Loads skymap into the model class. The method calls the protected method
795 * prepare_map() that prepares the map for usage by the class.
796 *
797 * If the @p filename is empty, no map will be loaded.
798 ***************************************************************************/
800{
801 // Initialise skymap
802 m_map.clear();
803
804 // Continue only if filename is not empty
805 if (!filename.is_empty()) {
806
807 // Store filename of skymap (for XML writing). Note that we do not
808 // expand any environment variable at this level, so that if we
809 // write back the XML element we write the filepath with the
810 // environment variables
812
813 // Load sky map
815
816 // Prepare sky map
817 prepare_map();
818
819 } // endif: filename was not empty
820
821 // Return
822 return;
823}
824
825
826/*==========================================================================
827 = =
828 = Private methods =
829 = =
830 ==========================================================================*/
831
832/***********************************************************************//**
833 * @brief Initialise class members
834 ***************************************************************************/
836{
837 // Initialise model type
838 m_type = "DiffuseMap";
839
840 // Initialise Value
841 m_value.clear();
842 m_value.name("Normalization");
843 m_value.value(1.0);
844 m_value.scale(1.0);
845 m_value.range(0.001, 1000.0);
846 m_value.gradient(0.0);
847 m_value.fix();
848 m_value.has_grad(true);
849
850 // Set parameter pointer(s)
851 m_pars.clear();
852 m_pars.push_back(&m_value);
853
854 // Initialise other members
855 m_map.clear();
857 m_normalize = true;
858 m_has_normalize = false;
859
860 // Initialise MC cache
863 m_mc_norm = 0.0;
864 m_mc_max = 0.0;
865
866 // Return
867 return;
868}
869
870
871/***********************************************************************//**
872 * @brief Copy class members
873 *
874 * @param[in] model Spatial map cube model.
875 ***************************************************************************/
877{
878 // Copy members
879 m_type = model.m_type; // Needed to conserve model type
880 m_value = model.m_value;
881 m_map = model.m_map;
882 m_filename = model.m_filename;
883 m_normalize = model.m_normalize;
885
886 // Copy MC cache
887 m_mc_cone = model.m_mc_cone;
889 m_mc_norm = model.m_mc_norm;
890 m_mc_max = model.m_mc_max;
891
892 // Set parameter pointer(s)
893 m_pars.clear();
894 m_pars.push_back(&m_value);
895
896 // Return
897 return;
898}
899
900
901/***********************************************************************//**
902 * @brief Delete class members
903 ***************************************************************************/
905{
906 // Return
907 return;
908}
909
910
911/***********************************************************************//**
912 * @brief Prepare sky map after loading
913 *
914 * Prepares a sky map after loading. Infinite or undefined skymap pixels
915 * are set to zero intensity. The method also determine the centre and
916 * radius of a circle enclosing the map, and the Monte Carlo simulation cone
917 * is set to this circle.
918 *
919 * If normalize() is true, the map is furthermore normalised so that the
920 * total flux in the map amounts to 1 ph/cm2/s.
921 ***************************************************************************/
923{
924 // Initialise region
925 m_region.clear();
926
927 // Determine number of skymap pixels
928 int npix = m_map.npix();
929
930 // Continue only if there are skymap pixels
931 if (npix > 0) {
932
933 // Initialise flux sum
934 double sum = 0.0;
935
936 // Set invalid pixels to zero intensity and compute total flux
937 for (int i = 0; i < npix; ++i) {
938 double flux = m_map.flux(i);
941 m_map(i) = 0.0;
942 flux = 0.0;
943 }
944 sum += flux;
945 }
946
947 // Optionally normalize the sky map
948 if (sum > 0.0) {
949 if (normalize()) {
950 for (int i = 0; i < npix; ++i) {
951 m_map(i) /= sum;
952 }
953 }
954 }
955
956 // Get region circle
958
959 // Set simulation cone
961
962 } // endif: there were skymap pixels
963
964 // Return
965 return;
966}
967
968
969/***********************************************************************//**
970 * @brief Set boundary sky region
971 ***************************************************************************/
973{
974 // Return
975 return;
976}
#define G_WRITE
#define G_READ
Exception handler interface definition.
HealPix projection class definition.
Mathematical function definitions.
const GModelSpatialDiffuseMap g_spatial_map_seed
Spatial map model class interface definition.
Spatial model registry class definition.
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
double norm(const GVector &vector)
Computes vector norm.
Definition GVector.cpp:932
double sum(const GVector &vector)
Computes vector sum.
Definition GVector.cpp:1012
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Filename class.
Definition GFilename.hpp:62
bool is_empty(void) const
Signal if filename is empty.
void clear(void)
Clear file name.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
virtual void clear(void)
Clear spatial map model.
void load(const GFilename &filename)
Load skymap into the model class.
void init_members(void)
Initialise class members.
virtual double mc_norm(const GSkyDir &dir, const double &radius) const
Return normalization of diffuse map for Monte Carlo simulations.
virtual GModelSpatialDiffuseMap * clone(void) const
Clone spatial map model.
bool m_normalize
Normalize map (default: true)
virtual ~GModelSpatialDiffuseMap(void)
Destructor.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const
Return intensity of sky map.
void prepare_map(void)
Prepare sky map after loading.
double m_mc_max
Map maximum for MC.
const GFilename & filename(void) const
Get file name.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Signals whether model contains sky direction.
bool normalize(void) const
Return normalization flag.
virtual double flux(const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns diffuse map flux integrated in sky region.
bool m_has_normalize
XML has normalize attribute.
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.
const GSkyMap & map(void) const
Get map.
const GSkyRegionCircle & mc_cone(void) const
Get Monte Carlo simulation cone.
double m_mc_norm
Map normalization.
virtual void set_region(void) const
Set boundary sky region.
double value(void) const
Get model value.
GFilename m_filename
Name of skymap.
virtual void write(GXmlElement &xml) const
Write model into XML element.
GModelSpatialDiffuseMap(void)
Void constructor.
GSkyRegionCircle m_mc_cone
MC cone.
void copy_members(const GModelSpatialDiffuseMap &model)
Copy class members.
virtual GModelSpatialDiffuseMap & operator=(const GModelSpatialDiffuseMap &model)
Assignment operator.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print map information.
double m_mc_one_minus_cosrad
1-cosine of radius
void free_members(void)
Delete class members.
Abstract diffuse spatial model base class.
void init_members(void)
Initialise class members.
virtual GModelSpatialDiffuse & operator=(const GModelSpatialDiffuse &model)
Assignment operator.
void free_members(void)
Delete class members.
Interface definition for the spatial model registry 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.
std::vector< GModelPar * > m_pars
Parameter pointers.
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.
bool is_free(void) const
Signal if parameter is free.
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_range(void)
Removes minimum and maximum boundary.
const double & factor_gradient(void) const
Return parameter factor gradient.
void fix(void)
Fix a parameter.
double gradient(void) const
Return parameter gradient.
void clear(void)
Clear parameter.
double value(void) const
Return parameter value.
const std::string & name(void) const
Return parameter name.
Class that handles photons.
Definition GPhoton.hpp:47
const GSkyDir & dir(void) const
Return photon sky direction.
Definition GPhoton.hpp:110
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
void rotate_deg(const double &phi, const double &theta)
Rotate sky direction by zenith and azimuth angle.
Definition GSkyDir.cpp:573
double dist_deg(const GSkyDir &dir) const
Compute angular distance between sky directions in degrees.
Definition GSkyDir.hpp:288
std::string print(const GChatter &chatter=NORMAL) const
Print sky direction information.
Definition GSkyDir.cpp:1376
Sky map class.
Definition GSkyMap.hpp:89
void clear(void)
Clear instance.
Definition GSkyMap.cpp:1100
GSkyRegionCircle region_circle(void) const
Return sky region circle that encloses the sky map.
Definition GSkyMap.cpp:2401
double flux(const int &index, const int &map=0) const
Returns flux in pixel.
Definition GSkyMap.cpp:1551
const int & npix(void) const
Returns number of pixels.
Definition GSkyMap.hpp:383
GSkyDir pix2dir(const GSkyPixel &pixel) const
Returns sky direction of pixel.
Definition GSkyMap.cpp:1360
void load(const GFilename &filename)
Load skymap from FITS file.
Definition GSkyMap.cpp:2511
Interface for the circular sky region class.
void clear(void)
Clear instance.
const double & radius(void) const
Return circular region radius (in degrees)
const GSkyDir & centre(void) const
Return circular region centre.
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.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition GTools.cpp:1162
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition GTools.hpp:186
bool is_notanumber(const double &x)
Signal if argument is not a number.
Definition GTools.hpp:203
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:508
const GXmlElement * xml_get_par(const std::string &origin, const GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
Definition GTools.cpp:1708
std::string tolower(const std::string &s)
Convert string to lower case.
Definition GTools.cpp:974
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
Definition GTools.cpp:1656
GFilename xml_file_reduce(const GXmlElement &xml, const std::string &filename)
Reduce file name provided for writing as XML attribute.
Definition GTools.cpp:1965
const double deg2rad
Definition GMath.hpp:43
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
Definition GTools.cpp:1796
bool xml_has_par(const GXmlElement &xml, const std::string &name)
Checks if parameter with given name in XML element exists.
Definition GTools.cpp:1615
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.
Definition GTools.cpp:1908
const double rad2deg
Definition GMath.hpp:44
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.
Definition GTools.cpp:1838