48#if defined(G_LEGACY_XML_FORMAT)
54#define G_MC "GModelSpatialDiffuseCube::mc(GEnergy&, GTime&, GRan&)"
55#define G_READ "GModelSpatialDiffuseCube::read(GXmlElement&)"
56#define G_WRITE "GModelSpatialDiffuseCube::write(GXmlElement&)"
57#define G_ENERGIES "GModelSpatialDiffuseCube::energies(GEnergies&)"
58#define G_LOAD_CUBE "GModelSpatialDiffuseCube::load_cube(GFilename&)"
59#define G_READ_FITS "GModelSpatialDiffuseCube::read(GFits&)"
101 const std::string& type) :
148 const double& value) :
181 const double& value) :
251 if (
this != &model) {
323 const bool& gradients)
const
391 std::string msg =
"No map cube defined. Please specify a valid map cube.";
397 std::string msg =
"The energy boundaries of the maps in the cube have "
398 "not been defined. Maybe the map cube file is missing "
399 "the \"ENERGIES\" extension which defines the energy "
400 "of each map in the cube. Please provide the energy "
413 if (max_left > 0.0 && max_right > 0.0) {
416 max = std::exp(max_log);
418 else if (max_left > 0.0) {
421 else if (max_right > 0.0) {
431 msg =
"Simulation cone has not been defined. Please specify a "
432 "valid simulation cone before calling the method.";
435 msg =
"The map cube is empty at "+energy.
print()+
" within the "
436 "simulation cone. Please specify a valid map cube or "
437 "restrict the simulated energies to values where the map "
438 "cube is non-zero within the simulation cone.";
447 #if defined(G_DEBUG_MC)
448 int num_iterations = 0;
455 #if defined(G_DEBUG_MC)
462 double phi = 360.0 * ran.
uniform();
470 if (value_left > 0.0 && value_right > 0.0) {
473 value = std::exp(value_log);
475 else if (value_left > 0.0) {
478 else if (value_right > 0.0) {
491 if (uniform <=
value) {
498 #if defined(G_DEBUG_MC)
499 std::cout << num_iterations <<
" ";
518 const double& margin)
const
573 #if defined(G_LEGACY_XML_FORMAT)
582 #if defined(G_LEGACY_XML_FORMAT)
583 std::string msg =
"Diffuse map cube model requires either "
584 "\"Normalization\" or \"Value\" parameter.";
586 std::string msg =
"Diffuse map cube model requires \"Normalization\" "
686 std::string msg =
"Number of specified energies ("+
gammalib::str(num)+
")"
687 " does not match the number of maps ("
689 "The energies argument shall provide a vector of length"
695 for (
int i = 0; i < num; ++i) {
735 for (
int i = 0; i < num; ++i) {
781 if (npix > 0 && nmaps > 0) {
784 std::vector<double> total_flux(nmaps, 0.0);
785 std::vector<double> max_intensity(nmaps, 0.0);
788 for (
int k = 0; k < npix; ++k) {
795 for (
int i = 0; i < nmaps; ++i) {
800 total_flux[i] +=
flux;
805 if (
value > max_intensity[i]) {
806 max_intensity[i] =
value;
820 for (
int i = 0; i < nmaps; ++i) {
823 m_mc_max.push_back(max_intensity[i]);
834 if (total_flux[i] > 0.0) {
843 #if defined(G_DEBUG_MC_CACHE)
844 std::cout <<
"GModelSpatialDiffuseCube::mc_cone:" << std::endl;
845 std::cout <<
" Maximum map intensity:" << std::endl;
846 for (
int i = 0; i <
m_mc_max.size(); ++i) {
849 std::cout <<
" " << i;
850 std::cout <<
" " << energy;
851 std::cout <<
" " <<
m_mc_max[i] <<
" ph/cm2/s/sr/MeV";
852 std::cout << std::endl;
854 std::cout <<
" Spatially integrated flux:" << std::endl;
856 std::cout <<
" " << i;
859 std::cout <<
" ph/cm2/s/MeV" << std::endl;
901 const bool& clobber)
const
935 for (
int extno = 0; extno < fits.
size(); ++extno) {
953 std::string msg =
"Number of energies in \"ENERGIES\" extension ("+
956 "map cube. The \"ENERGIES\" extension table shall "
957 "provide one enegy value for each map in the cube.";
962 for (
int i = 0; i < num; ++i) {
996 double energy = std::pow(10.0,
m_logE[i]);
1044 const GTime& srcTime)
const
1063 if (left_flux > 0.0 && right_flux > 0.0) {
1066 flux = std::exp(log_flux);
1068 else if (left_flux > 0.0) {
1071 else if (right_flux > 0.0) {
1100 result.append(
"=== GModelSpatialDiffuseCube ===");
1106 result.append(
" [loaded]");
1110 for (
int i = 0; i <
size(); ++i) {
1129 result.append(
" MeV (log10E=");
1133 result.append(
" [");
1135 result.append(
", ");
1142 result.append(
"not specified");
1156 result.append(
"not specified");
1181 m_type =
"DiffuseMapCube";
1267 #pragma omp critical(GModelSpatialDiffuseCube_fetch_cube)
1313 std::string msg =
"Number of energies in \"ENERGIES\" extension ("+
1316 "map cube. The \"ENERGIES\" extension table shall "
1317 "provide one enegy value for each map in the cube.";
1322 for (
int i = 0; i < num; ++i) {
1362 for (
int i = 0; i < num; ++i) {
1421 double intensity = 0.0;
1434 if (left_intensity > 0.0 && right_intensity > 0.0) {
1435 double log_intensity =
m_logE.
wgt_left() * std::log(left_intensity) +
1437 intensity = std::exp(log_intensity);
1439 else if (left_intensity > 0.0) {
1440 intensity = left_intensity;
1442 else if (right_intensity > 0.0) {
1443 intensity = right_intensity;
Energy container class definition.
Exception handler interface definition.
FITS table column abstract base class definition.
FITS table abstract base class interface definition.
FITS file class interface definition.
HealPix projection class definition.
Mathematical function definitions.
const GModelSpatialDiffuseCube g_spatial_cube_seed
Spatial map cube model class interface definition.
Spatial model registry class definition.
double max(const GVector &vector)
Computes maximum vector element.
XML element node class interface definition.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
void append(const GEnergy &emin, const GEnergy &emax)
Append energy interval.
int size(void) const
Return number of energy boundaries.
void clear(void)
Clear energy boundaries.
const GEnergy & emin(void) const
Return minimum energy of all intervals.
void read(const GFitsTable &table)
Read energies from FITS table.
int size(void) const
Return number of energies in container.
void reserve(const int &num)
Reserves space for energies in container.
GEnergy & append(const GEnergy &energy)
Append energy to container.
void write(GFits &file, const std::string &extname=gammalib::extname_energies) const
Write energies into FITS object.
Class that handles energies in a unit independent way.
double log10MeV(void) const
Return log10 of energy in MeV.
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
bool is_empty(void) const
Signal if filename is empty.
void clear(void)
Clear file name.
Abstract FITS extension base class.
virtual HDUType exttype(void) const =0
bool has_card(const int &cardno) const
Check existence of header card.
int integer(const std::string &keyname) const
Return card value as integer.
void saveto(const GFilename &filename, const bool &clobber=false)
Saves to specified FITS file.
int size(void) const
Return number of HDUs in FITS file.
GFitsHDU * at(const int &extno)
Get pointer to HDU.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
void set_energy_boundaries(void)
Set energy boundaries.
const GFilename & filename(void) const
Get file name.
void load_cube(const GFilename &filename)
Load map cube.
void update_mc_cache(void)
Update Monte Carlo cache.
double m_mc_one_minus_cosrad
1-cosine of radius
GModelSpatialDiffuseCube(void)
Void constructor.
const GSkyMap & cube(void) const
Get map cube.
void load(const GFilename &filename)
Load cube into the model class.
std::vector< double > m_mc_max
Maximum values for MC.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
const GSkyRegionCircle & mc_cone(void) const
Get Monte Carlo simulation cone.
double cube_intensity(const GPhoton &photon) const
Compute cube intensity by log-log interpolation.
bool m_loaded
Signals if map cube has been loaded.
void copy_members(const GModelSpatialDiffuseCube &model)
Copy class members.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print map cube information.
virtual double flux(const GSkyRegion ®ion, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns diffuse cube flux integrated in sky region.
virtual void write(GXmlElement &xml) const
Write model into XML element.
GModelSpectralNodes m_mc_spectrum
Map cube spectrum.
virtual void read(const GXmlElement &xml)
Read model from XML element.
GFilename m_filename
Name of map cube.
double value(void) const
Get model value.
GNodeArray m_logE
Log10(energy) values of the maps.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const
Evaluate function.
void save(const GFilename &filename, const bool &clobber=false) const
Save cube into FITS file.
GEbounds m_ebounds
Energy bounds of the maps.
void fetch_cube(void) const
Fetch cube.
GEnergies energies(void)
Returns map cube energies.
virtual GModelSpatialDiffuseCube & operator=(const GModelSpatialDiffuseCube &model)
Assignment operator.
GSkyRegionCircle m_mc_cone
MC cone.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Signals whether model contains sky direction.
virtual void clear(void)
Clear map cube model.
virtual ~GModelSpatialDiffuseCube(void)
Destructor.
virtual GModelSpatialDiffuseCube * clone(void) const
Clone map cube model.
virtual void set_region(void) const
Set boundary sky region.
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.
void autoscale(void)
Autoscale parameters.
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.
void reserve(const int &num)
Reserve space for nodes.
virtual void clear(void)
Clear spectral nodes model.
int nodes(void) const
Return number of nodes.
void append(const GEnergy &energy, const double &intensity)
Append node.
double intensity(const int &index) const
Return node intensity.
GEnergy energy(const int &index) const
Return node energy.
void set_value(const double &value) const
Set indices and weighting factors for interpolation.
const int & inx_right(void) const
Returns right node index.
const int & inx_left(void) const
Returns left node index.
const double & wgt_right(void) const
Returns right node weight.
const double & wgt_left(void) const
Returns left node weight.
void clear(void)
Clear node array.
int size(void) const
Return number of nodes in node array.
void append(const double &node)
Append one node to array.
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.
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.
const GSkyDir & dir(void) const
Return photon sky direction.
const GEnergy & energy(void) const
Return photon energy.
Random number generator class.
double uniform(void)
Returns random double precision floating value in range 0 to 1.
void rotate_deg(const double &phi, const double &theta)
Rotate sky direction by zenith and azimuth angle.
double dist_deg(const GSkyDir &dir) const
Compute angular distance between sky directions in degrees.
const int & nmaps(void) const
Returns number of maps.
void clear(void)
Clear instance.
GSkyRegionCircle region_circle(void) const
Return sky region circle that encloses the sky map.
double flux(const int &index, const int &map=0) const
Returns flux in pixel.
void read(const GFitsHDU &hdu)
Read skymap from FITS HDU.
const int & npix(void) const
Returns number of pixels.
GFitsHDU * write(GFits &file, const std::string &extname="") const
Write sky map into FITS file.
GSkyDir pix2dir(const GSkyPixel &pixel) const
Returns sky direction of pixel.
void load(const GFilename &filename)
Load skymap from FITS file.
std::string print(const GChatter &chatter=NORMAL) const
Print sky map.
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.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
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.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
GFilename xml_file_reduce(const GXmlElement &xml, const std::string &filename)
Reduce file name provided for writing as XML attribute.
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
bool xml_has_par(const GXmlElement &xml, const std::string &name)
Checks if parameter with given name in XML element exists.
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.
const std::string extname_energies