/***********************************************************************//** * @brief Create sky map * * This code illustrates the creation of a sky map. ***************************************************************************/ int main(void) { // Create a SNR shell model. The shell is centred on RA=0.3 deg and // Dec=0.1 deg. The shell has an inner radius of 0.5 deg and a width // of 0.1 deg. GSkyDir centre; centre.radec_deg(0.3, 0.1); GModelSpatialRadialShell model(centre, 0.5, 0.1); // Create an empty sky map in celestial coordinates using a cartesian // projection. The image is centred on RA=Dec=0, has a bin size of // 0.01 degrees and 300 pixels in RA and Dec double ra(0.0); double dec(0.0); double binsz(0.01); int npix(300); GSkyMap image("CAR", "CEL", ra, dec, -binsz, binsz, npix, npix, 1); // Fill the sky map with the model image GEnergy energy; // Dummy (not relevant as model is not energy dependent) GTime time; // Dummy (not relevant as model is not time dependent) for (int index = 0; index < image.npix(); ++index) { GSkyDir dir = image.inx2dir(index); // sky coordinate of pixel double theta = centre.dist(dir); // distance in radians image(index) = model.eval(theta, energy, time); } // Save the image to a FITS file image.save("my_sky_map.fits", true); // Exit return 0; }
/***********************************************************************//** * @brief Checks where model contains specified sky direction * * @param[in] dir Sky direction. * @param[in] margin Margin to be added to sky direction (degrees) * @return True if the model contains the sky direction. * * Signals whether a sky direction is contained in the radial gauss model. ***************************************************************************/ bool GModelSpatialRadialGauss::contains(const GSkyDir& dir, const double& margin) const { // Compute distance to centre (radians) double distance = dir.dist(this->dir()); // Return flag return (distance <= theta_max() + margin*gammalib::deg2rad); }
/***********************************************************************//** * @brief Return model value and set analytical gradients * * @param[in] srcDir True photon arrival direction. * * Evaluates the radial spatial model for a given true photon arrival * direction. ***************************************************************************/ double GModelRadial::eval_gradients(const GSkyDir& srcDir) const { // Compute distance from source (in radians) double theta = srcDir.dist(dir()); // Evaluate model and set gradients double value = eval_gradients(theta); // Return result return value; }
/***********************************************************************//** * @brief Return simulated list of photons * * @param[in] area Simulation surface area (cm2). * @param[in] dir Centre of simulation cone. * @param[in] radius Radius of simulation cone (deg). * @param[in] emin Minimum photon energy. * @param[in] emax Maximum photon energy. * @param[in] tmin Minimum photon arrival time. * @param[in] tmax Maximum photon arrival time. * @param[in] ran Random number generator. * * This method returns a list of photons that has been derived by Monte Carlo * simulation from the model. A simulation region is define by specification * of a simulation cone (a circular region on the sky), * of an energy range [emin, emax], and * of a time interval [tmin, tmax]. * The simulation cone may eventually cover the entire sky (by setting * the radius to 180 degrees), yet simulations will be more efficient if * only the sky region will be simulated that is actually observed by the * telescope. * * @todo Check usage for diffuse models * @todo Implement photon arrival direction simulation for diffuse models * @todo Implement unique model ID to assign as Monte Carlo ID ***************************************************************************/ GPhotons GModelSky::mc(const double& area, const GSkyDir& dir, const double& radius, const GEnergy& emin, const GEnergy& emax, const GTime& tmin, const GTime& tmax, GRan& ran) const { // Allocate photons GPhotons photons; // Continue only if model is valid) if (valid_model()) { // Get point source pointer GModelSpatialPtsrc* ptsrc = dynamic_cast<GModelSpatialPtsrc*>(m_spatial); // Check if model will produce any photons in the specified // simulation region. If the model is a point source we check if the // source is located within the simulation code. If the model is a // diffuse source we check if the source overlaps with the simulation // code bool use_model = true; if (ptsrc != NULL) { if (dir.dist(ptsrc->dir()) > radius) { use_model = false; } } else { //TODO } // Continue only if model overlaps with simulation region if (use_model) { // Compute flux within [emin, emax] in model from spectral // component (units: ph/cm2/s) double flux = m_spectral->flux(emin, emax); // Derive expecting counting rate within simulation surface // (units: ph/s) double rate = flux * area; // Debug option: dump rate #if G_DUMP_MC std::cout << "GModelSky::mc(\"" << name() << "\": "; std::cout << "flux=" << flux << " ph/cm2/s, "; std::cout << "rate=" << rate << " ph/s)" << std::endl; #endif // Get photon arrival times from temporal model GTimes times = m_temporal->mc(rate, tmin, tmax, ran); // Reserve space for photons if (times.size() > 0) { photons.reserve(times.size()); } // Loop over photons for (int i = 0; i < times.size(); ++i) { // Allocate photon GPhoton photon; // Set photon arrival time photon.time(times[i]); // Set incident photon direction photon.dir(m_spatial->mc(ran)); // Set photon energy photon.energy(m_spectral->mc(emin, emax, ran)); // Append photon photons.append(photon); } // endfor: looped over photons } // endif: model was used } // endif: model was valid // Return photon list return photons; }