Commit 7fbb63fe431ece7fa22ffb7458d4ffebd25b097e
1 parent
3b405d4c
Correct estimate photon rate for diffuse map cube
Showing
2 changed files
with
80 additions
and
12 deletions
src/ctobssim/ctobssim.cpp
| ... | ... | @@ -762,7 +762,9 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models, |
| 762 | 762 | // number of simulated photons to m_max_photons. |
| 763 | 763 | // The photon rate is estimated from the model flux |
| 764 | 764 | // and used to set the duration of the time slice. |
| 765 | - double flux = model->spectral()->flux(emin, emax); | |
| 765 | + //double flux = model->spectral()->flux(emin, emax); | |
| 766 | + double flux = get_model_flux(model, emin, emax, | |
| 767 | + dir, rad); | |
| 766 | 768 | double rate = flux * m_area; |
| 767 | 769 | double duration = 1800.0; // default: 1800 sec |
| 768 | 770 | if (rate > 0.0) { |
| ... | ... | @@ -960,6 +962,67 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models, |
| 960 | 962 | |
| 961 | 963 | |
| 962 | 964 | /***********************************************************************//** |
| 965 | + * @brief Determine sky model flux | |
| 966 | + * | |
| 967 | + * @param[in] model Sky model. | |
| 968 | + * @param[in] emin Minimum energy. | |
| 969 | + * @param[in] emin Maximum energy. | |
| 970 | + * @param[in] centre Centre of region for photon rate determination. | |
| 971 | + * @param[in] radius Radius of region for photon rate determination. | |
| 972 | + * @return Model flux (photons/cm2/sec). | |
| 973 | + ***************************************************************************/ | |
| 974 | +double ctobssim::get_model_flux(const GModelSky* model, | |
| 975 | + const GEnergy& emin, | |
| 976 | + const GEnergy& emax, | |
| 977 | + const GSkyDir& centre, | |
| 978 | + const double& radius) | |
| 979 | +{ | |
| 980 | + // Initialise de-allocation flag | |
| 981 | + bool free_spectral = false; | |
| 982 | + | |
| 983 | + // Get pointer to spectral model | |
| 984 | + const GModelSpectral* spectral = model->spectral(); | |
| 985 | + | |
| 986 | + // If the spatial model is a diffuse cube then create a node function | |
| 987 | + // spectral model that is the product of the diffuse cube node function | |
| 988 | + // and the spectral model evaluated at the energies of the node function | |
| 989 | + GModelSpatialDiffuseCube* cube = dynamic_cast<GModelSpatialDiffuseCube*>(model->spatial()); | |
| 990 | + if (cube != NULL) { | |
| 991 | + | |
| 992 | + // Set MC cone | |
| 993 | + cube->set_mc_cone(centre, radius); | |
| 994 | + | |
| 995 | + // Allocate node function to replace the spectral component | |
| 996 | + GModelSpectralNodes* nodes = new GModelSpectralNodes(cube->spectrum()); | |
| 997 | + for (int i = 0; i < nodes->nodes(); ++i) { | |
| 998 | + GEnergy energy = nodes->energy(i); | |
| 999 | + GTime time; // Dummy time | |
| 1000 | + double intensity = nodes->intensity(i); | |
| 1001 | + double norm = spectral->eval(energy, time); | |
| 1002 | + nodes->intensity(i, norm*intensity); | |
| 1003 | + } | |
| 1004 | + | |
| 1005 | + // Signal that node function needs to be de-allocated later | |
| 1006 | + free_spectral = true; | |
| 1007 | + | |
| 1008 | + // Set the spectral model pointer to the node function | |
| 1009 | + spectral = nodes; | |
| 1010 | + | |
| 1011 | + } // endif: spatial model was a diffuse cube | |
| 1012 | + | |
| 1013 | + // Compute flux within [emin, emax] in model from spectral | |
| 1014 | + // component (units: ph/cm2/s) | |
| 1015 | + double flux = spectral->flux(emin, emax); | |
| 1016 | + | |
| 1017 | + // Free spectral model if required | |
| 1018 | + if (free_spectral) delete spectral; | |
| 1019 | + | |
| 1020 | + // Return model flux | |
| 1021 | + return flux; | |
| 1022 | +} | |
| 1023 | + | |
| 1024 | + | |
| 1025 | +/***********************************************************************//** | |
| 963 | 1026 | * @brief Simulate background events from model |
| 964 | 1027 | * |
| 965 | 1028 | * @param[in] obs Pointer on CTA observation. | ... | ... |
src/ctobssim/ctobssim.hpp
| ... | ... | @@ -71,20 +71,25 @@ public: |
| 71 | 71 | |
| 72 | 72 | protected: |
| 73 | 73 | // Protected methods |
| 74 | - void init_members(void); | |
| 75 | - void copy_members(const ctobssim& app); | |
| 76 | - void free_members(void); | |
| 77 | - void get_parameters(void); | |
| 78 | - void simulate_source(GCTAObservation* obs, | |
| 74 | + void init_members(void); | |
| 75 | + void copy_members(const ctobssim& app); | |
| 76 | + void free_members(void); | |
| 77 | + void get_parameters(void); | |
| 78 | + void simulate_source(GCTAObservation* obs, | |
| 79 | 79 | const GModels& models, |
| 80 | 80 | GRan& ran, |
| 81 | 81 | GLog* wrklog = NULL); |
| 82 | - void simulate_background(GCTAObservation* obs, | |
| 83 | - const GModels& models, | |
| 84 | - GRan& ran, | |
| 85 | - GLog* wrklog = NULL); | |
| 86 | - void save_fits(void); | |
| 87 | - void save_xml(void); | |
| 82 | + double get_model_flux(const GModelSky* model, | |
| 83 | + const GEnergy& emin, | |
| 84 | + const GEnergy& emax, | |
| 85 | + const GSkyDir& centre, | |
| 86 | + const double& radius); | |
| 87 | + void simulate_background(GCTAObservation* obs, | |
| 88 | + const GModels& models, | |
| 89 | + GRan& ran, | |
| 90 | + GLog* wrklog = NULL); | |
| 91 | + void save_fits(void); | |
| 92 | + void save_xml(void); | |
| 88 | 93 | |
| 89 | 94 | // User parameters |
| 90 | 95 | std::string m_outevents; //!< Output events file | ... | ... |