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) {
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) {
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\" "
682 int num = energies.
size();
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
910 fits.
saveto(filename, clobber);
935 for (
int extno = 0; extno < fits.
size(); ++extno) {
949 int num = energies.
size();
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) {
1001 energies.
write(fits);
1044 const GTime& srcTime)
const
1063 if (left_flux > 0.0 && right_flux > 0.0) {
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)
1309 int num = energies.
size();
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) {
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;
GFitsHDU * at(const int &extno)
Get pointer to HDU.
int size(void) const
Return number of nodes in node array.
double dist_deg(const GSkyDir &dir) const
Compute angular distance between sky directions in degrees.
double flux(const int &index, const int &map=0) const
Returns flux in pixel.
bool m_loaded
Signals if map cube has been loaded.
void read(const GFitsTable &table)
Read energies from FITS table.
virtual void set_region(void) const
Set boundary sky region.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
bool has_card(const int &cardno) const
Check existence of header card.
void free_members(void)
Delete class members.
const double & factor_gradient(void) const
Return parameter factor gradient.
void fetch_cube(void) const
Fetch cube.
const std::string & name(void) const
Return parameter name.
void write(GFits &file, const std::string &extname=gammalib::extname_energies) const
Write energies into FITS object.
XML element node class interface definition.
double gradient(void) const
Return parameter gradient.
int size(void) const
Return number of parameters.
const GFilename & filename(void) const
Get file name.
virtual double flux(const GSkyRegion ®ion, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns diffuse cube flux integrated in sky region.
void init_members(void)
Initialise class members.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
Abstract FITS extension base class.
GFilename m_filename
Name of map cube.
int size(void) const
Return number of energy boundaries.
void append(const GEnergy &emin, const GEnergy &emax)
Append energy interval.
GVector cos(const GVector &vector)
Computes cosine of vector elements.
bool is_empty(void) const
Signal if filename is empty.
void reserve(const int &num)
Reserves space for energies in container.
const double & wgt_left(void) const
Returns left node weight.
void clear(void)
Clear node array.
virtual HDUType exttype(void) const =0
virtual std::string print(const GChatter &chatter=NORMAL) const
Print map cube information.
double acos(const double &arg)
Computes acos by avoiding NaN due to rounding errors.
Random number generator class.
GSkyRegionCircle m_mc_cone
MC cone.
virtual ~GModelSpatialDiffuseCube(void)
Destructor.
void reserve(const int &num)
Reserve space for nodes.
FITS file class interface definition.
virtual void read(const GXmlElement &xml)
Read model from XML element.
Interface for the circular sky region class.
void set_value(const double &value) const
Set indices and weighting factors for interpolation.
double m_mc_one_minus_cosrad
1-cosine of radius
GFilename xml_file_reduce(const GXmlElement &xml, const std::string &filename)
Reduce file name provided for writing as XML attribute.
Interface definition for the spatial model registry class.
void read(const GFitsHDU &hdu)
Read skymap from FITS HDU.
HealPix projection class definition.
bool is_free(void) const
Signal if parameter is free.
FITS table column abstract base class definition.
GNodeArray m_logE
Log10(energy) values of the maps.
double log10MeV(void) const
Return log10 of energy in MeV.
GSkyRegionCircle m_region
Bounding circle.
virtual GModelSpatialDiffuseCube & operator=(const GModelSpatialDiffuseCube &model)
Assignment operator.
const double & radius(void) const
Return circular region radius (in degrees)
void load(const GFilename &filename)
Load cube into the model class.
void copy_members(const GModelSpatialDiffuseCube &model)
Copy class members.
Class that handles photons.
const double & scale(void) const
Return parameter scale.
std::vector< double > m_mc_max
Maximum values for MC.
void append(const GEnergy &energy, const double &intensity)
Append node.
double value(void) const
Get model value.
void saveto(const GFilename &filename, const bool &clobber=false)
Saves to specified FITS file.
std::string print(const GChatter &chatter=NORMAL) const
Print sky map.
virtual void write(GXmlElement &xml) const
Write model into XML element.
GSkyDir pix2dir(const GSkyPixel &pixel) const
Returns sky direction of pixel.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
void init_members(void)
Initialise class members.
Abstract interface for the sky region class.
const double & wgt_right(void) const
Returns right node weight.
void save(const GFilename &filename, const bool &clobber=false) const
Save cube into FITS file.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
const int & nmaps(void) const
Returns number of maps.
void load_cube(const GFilename &filename)
Load map cube.
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
double cube_intensity(const GPhoton &photon) const
Compute cube intensity by log-log interpolation.
void update_mc_cache(void)
Update Monte Carlo cache.
GFitsHDU * write(GFits &file, const std::string &extname="") const
Write sky map into FITS file.
std::vector< GModelPar * > m_pars
Parameter pointers.
Energy container class definition.
void rotate_deg(const double &phi, const double &theta)
Rotate sky direction by zenith and azimuth angle.
const GEnergy & emin(void) const
Return minimum energy of all intervals.
void fix(void)
Fix a parameter.
int size(void) const
Return number of energies in container.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
double uniform(void)
Returns random double precision floating value in range 0 to 1.
void clear(void)
Clear parameter.
const GSkyRegionCircle & mc_cone(void) const
Get Monte Carlo simulation cone.
Spatial model registry class definition.
int integer(const std::string &keyname) const
Return card value as integer.
const int & inx_left(void) const
Returns left node index.
GEnergy energy(const int &index) const
Return node energy.
void clear(void)
Clear instance.
virtual GModelSpatialDiffuse & operator=(const GModelSpatialDiffuse &model)
Assignment operator.
std::string type(void) const
Return model type.
void clear(void)
Clear energy boundaries.
double max(const GVector &vector)
Computes maximum vector element.
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
const GModelSpatialDiffuseCube g_spatial_cube_seed
bool xml_has_par(const GXmlElement &xml, const std::string &name)
Checks if parameter with given name in XML element exists.
const int & inx_right(void) const
Returns right node index.
const std::string extname_energies
double intensity(const int &index) const
Return node intensity.
GSkyRegionCircle region_circle(void) const
Return sky region circle that encloses the sky map.
void free_members(void)
Delete class members.
GModelSpatialDiffuseCube(void)
Void constructor.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
const GSkyDir & centre(void) const
Return circular region centre.
void free_members(void)
Delete class members.
void clear(void)
Clear file name.
virtual void clear(void)
Clear spectral nodes model.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Signals whether model contains sky direction.
void set_energy_boundaries(void)
Set energy boundaries.
std::string m_type
Spatial model type.
GEnergies energies(void)
Returns map cube energies.
Spatial map cube model class interface definition.
int nodes(void) const
Return number of nodes.
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
double value(void) const
Return parameter value.
int size(void) const
Return number of HDUs in FITS file.
GModelSpectralNodes m_mc_spectrum
Map cube spectrum.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const
Evaluate function.
GVector pow(const GVector &vector, const double &power)
Computes tanh of vector elements.
const GEnergy & energy(void) const
Return photon energy.
GEnergy & append(const GEnergy &energy)
Append energy to container.
Exception handler interface definition.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
void init_members(void)
Initialise class members.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
Abstract diffuse spatial model base class.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void append(const double &node)
Append one node to array.
void load(const GFilename &filename)
Load skymap from FITS file.
const int & npix(void) const
Returns number of pixels.
const GSkyMap & cube(void) const
Get map cube.
const GSkyDir & dir(void) const
Return photon sky direction.
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.
void autoscale(void)
Autoscale parameters.
virtual void clear(void)
Clear map cube model.
GEbounds m_ebounds
Energy bounds of the maps.
virtual GModelSpatialDiffuseCube * clone(void) const
Clone map cube model.
Mathematical function definitions.
void clear(void)
Clear instance.
Class that handles energies in a unit independent way.
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
FITS table abstract base class interface definition.
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.