Commit bd585ba9693962677f47f5006e4fe51761c74aed
1 parent
86d4c073
Add maxrate parameter to throw an exception in case that the source event rate is too high (#807).
Showing
5 changed files
with
97 additions
and
19 deletions
doc/source/reference_manual/ctobssim.rst
| @@ -9,9 +9,9 @@ Simulates CTA events. | @@ -9,9 +9,9 @@ Simulates CTA events. | ||
| 9 | Synopsis | 9 | Synopsis |
| 10 | -------- | 10 | -------- |
| 11 | 11 | ||
| 12 | -Generate photon events from astrophysical sources and process those photons | ||
| 13 | -according to the specified instrument response functions and generate | ||
| 14 | -instrumental background events. | 12 | +Generate photon events from astrophysical sources and background events |
| 13 | +from an instrumental background model. | ||
| 14 | + | ||
| 15 | 15 | ||
| 16 | General parameters | 16 | General parameters |
| 17 | ------------------ | 17 | ------------------ |
| @@ -24,7 +24,7 @@ General parameters | @@ -24,7 +24,7 @@ General parameters | ||
| 24 | 24 | ||
| 25 | ``inmodel [file]`` | 25 | ``inmodel [file]`` |
| 26 | XML file that describes the astrophysical sources and the instrumental | 26 | XML file that describes the astrophysical sources and the instrumental |
| 27 | - background. | 27 | + background model. |
| 28 | 28 | ||
| 29 | ``outevents [file]`` | 29 | ``outevents [file]`` |
| 30 | Output event list or observation definition XML file. | 30 | Output event list or observation definition XML file. |
| @@ -39,7 +39,10 @@ General parameters | @@ -39,7 +39,10 @@ General parameters | ||
| 39 | Instrumental response function. | 39 | Instrumental response function. |
| 40 | 40 | ||
| 41 | ``(seed = 1) [integer]`` | 41 | ``(seed = 1) [integer]`` |
| 42 | - Integer seed value to be used for Monte Carlo simulations. | 42 | + Integer seed value to be used for Monte Carlo simulations. Keep this |
| 43 | + parameter at the same value for repeatable simulations, or increment | ||
| 44 | + this value for subsequent runs if non-repeatable simulations are | ||
| 45 | + required. | ||
| 43 | 46 | ||
| 44 | ``ra [real]`` | 47 | ``ra [real]`` |
| 45 | Right Ascension of CTA pointing (J2000, in degrees). | 48 | Right Ascension of CTA pointing (J2000, in degrees). |
| @@ -57,10 +60,10 @@ General parameters | @@ -57,10 +60,10 @@ General parameters | ||
| 57 | Mission elapsed stop time of observation (in seconds). | 60 | Mission elapsed stop time of observation (in seconds). |
| 58 | 61 | ||
| 59 | ``emin [real]`` | 62 | ``emin [real]`` |
| 60 | - Lower energy limit of events (in TeV). | 63 | + Lower energy limit of simulated events (in TeV). |
| 61 | 64 | ||
| 62 | ``emax [real]`` | 65 | ``emax [real]`` |
| 63 | - Upper energy limit of events (in TeV). | 66 | + Upper energy limit of simulated events (in TeV). |
| 64 | 67 | ||
| 65 | ``(edisp = no) [boolean]`` | 68 | ``(edisp = no) [boolean]`` |
| 66 | Apply energy dispersion? | 69 | Apply energy dispersion? |
| @@ -68,6 +71,13 @@ General parameters | @@ -68,6 +71,13 @@ General parameters | ||
| 68 | ``(deadc = 0.95) [real]`` | 71 | ``(deadc = 0.95) [real]`` |
| 69 | Average deadtime correction factor. | 72 | Average deadtime correction factor. |
| 70 | 73 | ||
| 74 | +``(maxrate = 1.0e6) [real]`` | ||
| 75 | + Maximum photon rate for source models. Source models that exceed this | ||
| 76 | + maximum photon rate will lead to an exception as very likely the | ||
| 77 | + specified model normalisation is too large (probably due to the | ||
| 78 | + a misinterpretation of units). Note that ctools specifies intensity | ||
| 79 | + units per MeV. | ||
| 80 | + | ||
| 71 | 81 | ||
| 72 | Standard parameters | 82 | Standard parameters |
| 73 | ------------------- | 83 | ------------------- |
pyext/ctobssim.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * ctobssim - Observation simulator tool * | 2 | * ctobssim - Observation simulator tool * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2014 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2015 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -48,6 +48,8 @@ public: | @@ -48,6 +48,8 @@ public: | ||
| 48 | void run(void); | 48 | void run(void); |
| 49 | void save(void); | 49 | void save(void); |
| 50 | const GObservations& obs(void) const; | 50 | const GObservations& obs(void) const; |
| 51 | + const double& max_rate(void) const; | ||
| 52 | + void max_rate(const double& max_rate); | ||
| 51 | }; | 53 | }; |
| 52 | 54 | ||
| 53 | 55 |
src/ctobssim/ctobssim.cpp
| @@ -494,6 +494,7 @@ void ctobssim::init_members(void) | @@ -494,6 +494,7 @@ void ctobssim::init_members(void) | ||
| 494 | m_prefix.clear(); | 494 | m_prefix.clear(); |
| 495 | m_seed = 1; | 495 | m_seed = 1; |
| 496 | m_apply_edisp = false; | 496 | m_apply_edisp = false; |
| 497 | + m_max_rate = 1.0e6; | ||
| 497 | 498 | ||
| 498 | // Initialise protected members | 499 | // Initialise protected members |
| 499 | m_rans.clear(); | 500 | m_rans.clear(); |
| @@ -524,6 +525,7 @@ void ctobssim::copy_members(const ctobssim& app) | @@ -524,6 +525,7 @@ void ctobssim::copy_members(const ctobssim& app) | ||
| 524 | m_prefix = app.m_prefix; | 525 | m_prefix = app.m_prefix; |
| 525 | m_seed = app.m_seed; | 526 | m_seed = app.m_seed; |
| 526 | m_apply_edisp = app.m_apply_edisp; | 527 | m_apply_edisp = app.m_apply_edisp; |
| 528 | + m_max_rate = app.m_max_rate; | ||
| 527 | 529 | ||
| 528 | // Copy protected members | 530 | // Copy protected members |
| 529 | m_area = app.m_area; | 531 | m_area = app.m_area; |
| @@ -577,6 +579,7 @@ void ctobssim::get_parameters(void) | @@ -577,6 +579,7 @@ void ctobssim::get_parameters(void) | ||
| 577 | // Get other parameters | 579 | // Get other parameters |
| 578 | m_seed = (*this)["seed"].integer(); | 580 | m_seed = (*this)["seed"].integer(); |
| 579 | m_apply_edisp = (*this)["edisp"].boolean(); | 581 | m_apply_edisp = (*this)["edisp"].boolean(); |
| 582 | + m_max_rate = (*this)["maxrate"].real(); | ||
| 580 | 583 | ||
| 581 | // Optionally read ahead parameters so that they get correctly | 584 | // Optionally read ahead parameters so that they get correctly |
| 582 | // dumped into the log file | 585 | // dumped into the log file |
| @@ -768,6 +771,36 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models, | @@ -768,6 +771,36 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models, | ||
| 768 | } | 771 | } |
| 769 | GTime tslice(duration, "sec"); | 772 | GTime tslice(duration, "sec"); |
| 770 | 773 | ||
| 774 | + // If photon rate exceeds the maximum photon rate | ||
| 775 | + // then throw an exception | ||
| 776 | + if (rate > m_max_rate) { | ||
| 777 | + std::string modnam = (model->name().length() > 0) ? | ||
| 778 | + model->name() : "Unknown"; | ||
| 779 | + std::string msg = "Photon rate "+ | ||
| 780 | + gammalib::str(rate)+ | ||
| 781 | + " photons/sec for model \""+ | ||
| 782 | + modnam+"\" exceeds maximum" | ||
| 783 | + " allowed photon rate of "+ | ||
| 784 | + gammalib::str(m_max_rate)+ | ||
| 785 | + " photons/sec. Please check" | ||
| 786 | + " the model parameters for" | ||
| 787 | + " model \""+modnam+"\" or" | ||
| 788 | + " increase the value of the" | ||
| 789 | + " hidden \"maxrate\"" | ||
| 790 | + " parameter."; | ||
| 791 | + throw GException::invalid_value(G_SIMULATE_SOURCE, msg); | ||
| 792 | + } | ||
| 793 | + | ||
| 794 | + // Dump length of time slice and rate | ||
| 795 | + if (logExplicit()) { | ||
| 796 | + *wrklog << gammalib::parformat("Photon rate", indent); | ||
| 797 | + *wrklog << rate << " photons/sec"; | ||
| 798 | + if (model->name().length() > 0) { | ||
| 799 | + *wrklog << " [" << model->name() << "]"; | ||
| 800 | + } | ||
| 801 | + *wrklog << std::endl; | ||
| 802 | + } | ||
| 803 | + | ||
| 771 | // To reduce memory requirements we split long time | 804 | // To reduce memory requirements we split long time |
| 772 | // intervals into several slices. | 805 | // intervals into several slices. |
| 773 | GTime tstart = tmin; | 806 | GTime tstart = tmin; |
| @@ -795,6 +828,10 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models, | @@ -795,6 +828,10 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models, | ||
| 795 | *wrklog << " - "; | 828 | *wrklog << " - "; |
| 796 | *wrklog << tstop.convert(m_cta_ref); | 829 | *wrklog << tstop.convert(m_cta_ref); |
| 797 | *wrklog << " s" << std::endl; | 830 | *wrklog << " s" << std::endl; |
| 831 | + if (model->name().length() > 0) { | ||
| 832 | + *wrklog << " [" << model->name() << "]"; | ||
| 833 | + } | ||
| 834 | + *wrklog << std::endl; | ||
| 798 | } | 835 | } |
| 799 | 836 | ||
| 800 | // Get photons | 837 | // Get photons |
src/ctobssim/ctobssim.hpp
| @@ -66,6 +66,8 @@ public: | @@ -66,6 +66,8 @@ public: | ||
| 66 | void run(void); | 66 | void run(void); |
| 67 | void save(void); | 67 | void save(void); |
| 68 | const GObservations& obs(void) const; | 68 | const GObservations& obs(void) const; |
| 69 | + const double& max_rate(void) const; | ||
| 70 | + void max_rate(const double& max_rate); | ||
| 69 | 71 | ||
| 70 | protected: | 72 | protected: |
| 71 | // Protected methods | 73 | // Protected methods |
| @@ -95,6 +97,7 @@ protected: | @@ -95,6 +97,7 @@ protected: | ||
| 95 | mutable bool m_save_and_dispose; //!< Save and dispose immediately | 97 | mutable bool m_save_and_dispose; //!< Save and dispose immediately |
| 96 | double m_area; //!< Surface area for simulation (cm2) | 98 | double m_area; //!< Surface area for simulation (cm2) |
| 97 | int m_max_photons; //!< Maximum number of photons/slice | 99 | int m_max_photons; //!< Maximum number of photons/slice |
| 100 | + double m_max_rate; //!< Maximum photon rate | ||
| 98 | std::vector<GRan> m_rans; //!< Random number generators | 101 | std::vector<GRan> m_rans; //!< Random number generators |
| 99 | int m_event_id; //!< Event identifier | 102 | int m_event_id; //!< Event identifier |
| 100 | }; | 103 | }; |
| @@ -108,7 +111,32 @@ protected: | @@ -108,7 +111,32 @@ protected: | ||
| 108 | inline | 111 | inline |
| 109 | const GObservations& ctobssim::obs(void) const | 112 | const GObservations& ctobssim::obs(void) const |
| 110 | { | 113 | { |
| 111 | - return m_obs; | 114 | + return (m_obs); |
| 115 | +} | ||
| 116 | + | ||
| 117 | + | ||
| 118 | +/***********************************************************************//** | ||
| 119 | + * @brief Return maximum photon rate | ||
| 120 | + * | ||
| 121 | + * @return Reference to maximum photon rate. | ||
| 122 | + ***************************************************************************/ | ||
| 123 | +inline | ||
| 124 | +const double& ctobssim::max_rate(void) const | ||
| 125 | +{ | ||
| 126 | + return (m_max_rate); | ||
| 127 | +} | ||
| 128 | + | ||
| 129 | + | ||
| 130 | +/***********************************************************************//** | ||
| 131 | + * @brief Set maximum photon rate | ||
| 132 | + * | ||
| 133 | + * @param[in] max_rate Maximum photon rate. | ||
| 134 | + ***************************************************************************/ | ||
| 135 | +inline | ||
| 136 | +void ctobssim::max_rate(const double& max_rate) | ||
| 137 | +{ | ||
| 138 | + m_max_rate = max_rate; | ||
| 139 | + return; | ||
| 112 | } | 140 | } |
| 113 | 141 | ||
| 114 | #endif /* CTOBSSIM_HPP */ | 142 | #endif /* CTOBSSIM_HPP */ |
src/ctobssim/ctobssim.par
| @@ -29,16 +29,17 @@ irf, s, a, "cta_dummy_irf",,, "Instrument response function" | @@ -29,16 +29,17 @@ irf, s, a, "cta_dummy_irf",,, "Instrument response function" | ||
| 29 | # | 29 | # |
| 30 | # Simulation parameters | 30 | # Simulation parameters |
| 31 | #====================== | 31 | #====================== |
| 32 | -seed, i, h, 1,,, "Random number generator seed" | ||
| 33 | -ra, r, a, 83.63,0,360, "RA of pointing (degrees)" | ||
| 34 | -dec, r, a, 22.01,-90,90, "Dec of pointing (degrees)" | ||
| 35 | -rad, r, a, 5.0,0,180, "Radius of FOV (degrees)" | ||
| 36 | -tmin, r, a, 0.0,,, "Start time (MET in s)" | ||
| 37 | -tmax, r, a, 1800.0,,, "End time (MET in s)" | ||
| 38 | -emin, r, a, 0.1,,, "Lower energy limit (TeV)" | ||
| 39 | -emax, r, a, 100.0,,, "Upper energy limit (TeV)" | ||
| 40 | -edisp, b, h, no,,, "Apply energy dispersion?" | ||
| 41 | -deadc, r, h, 0.95,0,1, "Average deadtime correction factor" | 32 | +seed, i, h, 1,,, "Random number generator seed" |
| 33 | +ra, r, a, 83.63,0,360, "RA of pointing (degrees)" | ||
| 34 | +dec, r, a, 22.01,-90,90, "Dec of pointing (degrees)" | ||
| 35 | +rad, r, a, 5.0,0,180, "Radius of FOV (degrees)" | ||
| 36 | +tmin, r, a, 0.0,,, "Start time (MET in s)" | ||
| 37 | +tmax, r, a, 1800.0,,, "End time (MET in s)" | ||
| 38 | +emin, r, a, 0.1,,, "Lower energy limit (TeV)" | ||
| 39 | +emax, r, a, 100.0,,, "Upper energy limit (TeV)" | ||
| 40 | +edisp, b, h, no,,, "Apply energy dispersion?" | ||
| 41 | +deadc, r, h, 0.95,0,1, "Average deadtime correction factor" | ||
| 42 | +maxrate, r, h, 1.0e6,,, "Maximum photon rate" | ||
| 42 | # | 43 | # |
| 43 | # Standard parameters | 44 | # Standard parameters |
| 44 | #==================== | 45 | #==================== |