Commit d664295a5886906fc25bfa7b7b952ddf857ccbd6
1 parent
e8e73b77
Use additional ARF columns to store background and alpha vectors
Showing
3 changed files
with
41 additions
and
48 deletions
inst/cta/include/GCTAOnOffObservation.hpp
| @@ -88,7 +88,6 @@ public: | @@ -88,7 +88,6 @@ public: | ||
| 88 | const GPha& on_spec(void) const; | 88 | const GPha& on_spec(void) const; |
| 89 | const GPha& off_spec(void) const; | 89 | const GPha& off_spec(void) const; |
| 90 | const GArf& arf(void) const; | 90 | const GArf& arf(void) const; |
| 91 | - const GArf& bgd(void) const; | ||
| 92 | const GRmf& rmf(void) const; | 91 | const GRmf& rmf(void) const; |
| 93 | void fill(const GCTAObservation& obs); | 92 | void fill(const GCTAObservation& obs); |
| 94 | void compute_response(const GCTAObservation& obs, | 93 | void compute_response(const GCTAObservation& obs, |
| @@ -107,19 +106,17 @@ protected: | @@ -107,19 +106,17 @@ protected: | ||
| 107 | double model_off(const GModels& models, int ibin, GVector* mod_grad) const; | 106 | double model_off(const GModels& models, int ibin, GVector* mod_grad) const; |
| 108 | 107 | ||
| 109 | // Protected data members | 108 | // Protected data members |
| 110 | - std::string m_instrument; //!< Instrument name | ||
| 111 | - GCTAResponse* m_response; //!< Pointer to instrument response functions | ||
| 112 | - double m_ontime; //!< Ontime (seconds) | ||
| 113 | - double m_livetime; //!< Livetime (seconds) | ||
| 114 | - double m_deadc; //!< Deadtime correction (livetime/ontime) | ||
| 115 | - GPha m_on_spec; //!< On counts spectrum | ||
| 116 | - GPha m_off_spec; //!< Off counts spectrum | ||
| 117 | - GArf m_arf; //!< Effective area vector | ||
| 118 | - GArf m_bgd; //!< Background rate vector | ||
| 119 | - GRmf m_rmf; //!< Energy dispersion matrix | ||
| 120 | - GSkyRegions m_on_regions; //!< Container of On region | ||
| 121 | - GSkyRegions m_off_regions; //!< Container of Off regions | ||
| 122 | - std::vector<double> m_alpha; //!< Ratios of On/Off exposure | 109 | + std::string m_instrument; //!< Instrument name |
| 110 | + GCTAResponse* m_response; //!< Pointer to IRFs | ||
| 111 | + double m_ontime; //!< Ontime (seconds) | ||
| 112 | + double m_livetime; //!< Livetime (seconds) | ||
| 113 | + double m_deadc; //!< Deadtime correction (livetime/ontime) | ||
| 114 | + GPha m_on_spec; //!< On counts spectrum | ||
| 115 | + GPha m_off_spec; //!< Off counts spectrum | ||
| 116 | + GArf m_arf; //!< Auxiliary Response Function vector | ||
| 117 | + GRmf m_rmf; //!< Redistribution matrix | ||
| 118 | + GSkyRegions m_on_regions; //!< Container of On region | ||
| 119 | + GSkyRegions m_off_regions; //!< Container of Off regions | ||
| 123 | }; | 120 | }; |
| 124 | 121 | ||
| 125 | 122 | ||
| @@ -267,18 +264,6 @@ const GArf& GCTAOnOffObservation::arf(void) const | @@ -267,18 +264,6 @@ const GArf& GCTAOnOffObservation::arf(void) const | ||
| 267 | 264 | ||
| 268 | 265 | ||
| 269 | /***********************************************************************//** | 266 | /***********************************************************************//** |
| 270 | - * @brief Return Background Rate | ||
| 271 | - * | ||
| 272 | - * @return Background Rate. | ||
| 273 | - ***************************************************************************/ | ||
| 274 | -inline | ||
| 275 | -const GArf& GCTAOnOffObservation::bgd(void) const | ||
| 276 | -{ | ||
| 277 | - return (m_bgd); | ||
| 278 | -} | ||
| 279 | - | ||
| 280 | - | ||
| 281 | -/***********************************************************************//** | ||
| 282 | * @brief Return Redistribution Matrix File | 267 | * @brief Return Redistribution Matrix File |
| 283 | * | 268 | * |
| 284 | * @return Redistribution Matrix File. | 269 | * @return Redistribution Matrix File. |
| @@ -291,9 +276,9 @@ const GRmf& GCTAOnOffObservation::rmf(void) const | @@ -291,9 +276,9 @@ const GRmf& GCTAOnOffObservation::rmf(void) const | ||
| 291 | 276 | ||
| 292 | 277 | ||
| 293 | /***********************************************************************//** | 278 | /***********************************************************************//** |
| 294 | - * @brief Return Redistribution Matrix File | 279 | + * @brief Return number of observed events |
| 295 | * | 280 | * |
| 296 | - * @return Redistribution Matrix File. | 281 | + * @return Number of observed events. |
| 297 | ***************************************************************************/ | 282 | ***************************************************************************/ |
| 298 | inline | 283 | inline |
| 299 | int GCTAOnOffObservation::nobserved(void) const | 284 | int GCTAOnOffObservation::nobserved(void) const |
inst/cta/pyext/GCTAOnOffObservation.i
| @@ -95,7 +95,6 @@ public: | @@ -95,7 +95,6 @@ public: | ||
| 95 | const GPha& on_spec(void) const; | 95 | const GPha& on_spec(void) const; |
| 96 | const GPha& off_spec(void) const; | 96 | const GPha& off_spec(void) const; |
| 97 | const GArf& arf(void) const; | 97 | const GArf& arf(void) const; |
| 98 | - const GArf& bgd(void) const; | ||
| 99 | const GRmf& rmf(void) const; | 98 | const GRmf& rmf(void) const; |
| 100 | void fill(const GCTAObservation& obs); | 99 | void fill(const GCTAObservation& obs); |
| 101 | void compute_response(const GCTAObservation& obs, | 100 | void compute_response(const GCTAObservation& obs, |
inst/cta/src/GCTAOnOffObservation.cpp
| @@ -369,7 +369,7 @@ void GCTAOnOffObservation::read(const GXmlElement& xml) | @@ -369,7 +369,7 @@ void GCTAOnOffObservation::read(const GXmlElement& xml) | ||
| 369 | // Get filename | 369 | // Get filename |
| 370 | std::string filename = par->attribute("file"); | 370 | std::string filename = par->attribute("file"); |
| 371 | 371 | ||
| 372 | - // load on regions | 372 | + // Load on regions |
| 373 | m_on_regions.load(filename); | 373 | m_on_regions.load(filename); |
| 374 | 374 | ||
| 375 | // Increase number of parameters | 375 | // Increase number of parameters |
| @@ -395,7 +395,7 @@ void GCTAOnOffObservation::read(const GXmlElement& xml) | @@ -395,7 +395,7 @@ void GCTAOnOffObservation::read(const GXmlElement& xml) | ||
| 395 | // Get filename | 395 | // Get filename |
| 396 | std::string filename = par->attribute("file"); | 396 | std::string filename = par->attribute("file"); |
| 397 | 397 | ||
| 398 | - // load arf | 398 | + // Load arf |
| 399 | m_arf.load(filename); | 399 | m_arf.load(filename); |
| 400 | 400 | ||
| 401 | // Increase number of parameters | 401 | // Increase number of parameters |
| @@ -408,7 +408,7 @@ void GCTAOnOffObservation::read(const GXmlElement& xml) | @@ -408,7 +408,7 @@ void GCTAOnOffObservation::read(const GXmlElement& xml) | ||
| 408 | // Get filename | 408 | // Get filename |
| 409 | std::string filename = par->attribute("file"); | 409 | std::string filename = par->attribute("file"); |
| 410 | 410 | ||
| 411 | - // load Rmf | 411 | + // Load Rmf |
| 412 | m_rmf.load(filename); | 412 | m_rmf.load(filename); |
| 413 | 413 | ||
| 414 | // Increase number of parameters | 414 | // Increase number of parameters |
| @@ -736,6 +736,9 @@ double GCTAOnOffObservation::likelihood(const GModels& models, | @@ -736,6 +736,9 @@ double GCTAOnOffObservation::likelihood(const GModels& models, | ||
| 736 | 736 | ||
| 737 | // Allocate working array | 737 | // Allocate working array |
| 738 | GVector colvar(npars); | 738 | GVector colvar(npars); |
| 739 | + | ||
| 740 | + // Get reference to alpha parameters | ||
| 741 | + const std::vector<double>& alpha = m_arf["ALPHA"]; | ||
| 739 | 742 | ||
| 740 | // Check that there is at least one parameter | 743 | // Check that there is at least one parameter |
| 741 | if (npars > 0) { | 744 | if (npars > 0) { |
| @@ -759,7 +762,7 @@ double GCTAOnOffObservation::likelihood(const GModels& models, | @@ -759,7 +762,7 @@ double GCTAOnOffObservation::likelihood(const GModels& models, | ||
| 759 | double nbgd = model_off(models, i, &bgd_grad); | 762 | double nbgd = model_off(models, i, &bgd_grad); |
| 760 | 763 | ||
| 761 | // Skip bin if model is too small (avoids -Inf or NaN gradients) | 764 | // Skip bin if model is too small (avoids -Inf or NaN gradients) |
| 762 | - double nonpred = ngam + m_alpha[i] * nbgd; | 765 | + double nonpred = ngam + alpha[i] * nbgd; |
| 763 | if ((nbgd <= minmod) || (nonpred <= minmod)) { | 766 | if ((nbgd <= minmod) || (nonpred <= minmod)) { |
| 764 | #if defined(G_LIKELIHOOD_DEBUG) | 767 | #if defined(G_LIKELIHOOD_DEBUG) |
| 765 | n_small_model++; | 768 | n_small_model++; |
| @@ -783,10 +786,10 @@ double GCTAOnOffObservation::likelihood(const GModels& models, | @@ -783,10 +786,10 @@ double GCTAOnOffObservation::likelihood(const GModels& models, | ||
| 783 | // Fill derivatives | 786 | // Fill derivatives |
| 784 | double fa = non/nonpred; | 787 | double fa = non/nonpred; |
| 785 | double fb = fa/nonpred; | 788 | double fb = fa/nonpred; |
| 786 | - double fc = m_alpha[i] * fb; | ||
| 787 | - double fd = fc * m_alpha[i] + noff/(nbgd*nbgd); | 789 | + double fc = alpha[i] * fb; |
| 790 | + double fd = fc * alpha[i] + noff/(nbgd*nbgd); | ||
| 788 | double sky_factor = 1.0 - fa; | 791 | double sky_factor = 1.0 - fa; |
| 789 | - double bgd_factor = 1.0 + m_alpha[i] - m_alpha[i] * fa - noff/nbgd; | 792 | + double bgd_factor = 1.0 + alpha[i] - alpha[i] * fa - noff/nbgd; |
| 790 | 793 | ||
| 791 | // Loop over all parameters | 794 | // Loop over all parameters |
| 792 | for (int j = 0; j < npars; ++j) { | 795 | for (int j = 0; j < npars; ++j) { |
| @@ -977,11 +980,9 @@ void GCTAOnOffObservation::init_members(void) | @@ -977,11 +980,9 @@ void GCTAOnOffObservation::init_members(void) | ||
| 977 | m_on_spec.clear(); | 980 | m_on_spec.clear(); |
| 978 | m_off_spec.clear(); | 981 | m_off_spec.clear(); |
| 979 | m_arf.clear(); | 982 | m_arf.clear(); |
| 980 | - m_bgd.clear(); | ||
| 981 | m_rmf.clear(); | 983 | m_rmf.clear(); |
| 982 | m_on_regions.clear(); | 984 | m_on_regions.clear(); |
| 983 | m_off_regions.clear(); | 985 | m_off_regions.clear(); |
| 984 | - m_alpha.clear(); | ||
| 985 | 986 | ||
| 986 | // Return | 987 | // Return |
| 987 | return; | 988 | return; |
| @@ -1003,11 +1004,9 @@ void GCTAOnOffObservation::copy_members(const GCTAOnOffObservation& obs) | @@ -1003,11 +1004,9 @@ void GCTAOnOffObservation::copy_members(const GCTAOnOffObservation& obs) | ||
| 1003 | m_on_spec = obs.m_on_spec; | 1004 | m_on_spec = obs.m_on_spec; |
| 1004 | m_off_spec = obs.m_off_spec; | 1005 | m_off_spec = obs.m_off_spec; |
| 1005 | m_arf = obs.m_arf; | 1006 | m_arf = obs.m_arf; |
| 1006 | - m_bgd = obs.m_bgd; | ||
| 1007 | m_rmf = obs.m_rmf; | 1007 | m_rmf = obs.m_rmf; |
| 1008 | m_on_regions = obs.m_on_regions; | 1008 | m_on_regions = obs.m_on_regions; |
| 1009 | m_off_regions = obs.m_off_regions; | 1009 | m_off_regions = obs.m_off_regions; |
| 1010 | - m_alpha = obs.m_alpha; | ||
| 1011 | 1010 | ||
| 1012 | // Clone members | 1011 | // Clone members |
| 1013 | m_response = (obs.m_response != NULL) ? obs.m_response->clone() : NULL; | 1012 | m_response = (obs.m_response != NULL) ? obs.m_response->clone() : NULL; |
| @@ -1054,7 +1053,7 @@ void GCTAOnOffObservation::compute_alpha(const GCTAObservation& obs) | @@ -1054,7 +1053,7 @@ void GCTAOnOffObservation::compute_alpha(const GCTAObservation& obs) | ||
| 1054 | if (nreco > 0) { | 1053 | if (nreco > 0) { |
| 1055 | 1054 | ||
| 1056 | // Initialise On/Off exposure ratios | 1055 | // Initialise On/Off exposure ratios |
| 1057 | - m_alpha.assign(nreco, 0.0); | 1056 | + std::vector<double> alpha(nreco, 0.0); |
| 1058 | 1057 | ||
| 1059 | // Get CTA response pointer. Throw an exception if no response is found | 1058 | // Get CTA response pointer. Throw an exception if no response is found |
| 1060 | const GCTAResponseIrf* response = | 1059 | const GCTAResponseIrf* response = |
| @@ -1130,10 +1129,13 @@ void GCTAOnOffObservation::compute_alpha(const GCTAObservation& obs) | @@ -1130,10 +1129,13 @@ void GCTAOnOffObservation::compute_alpha(const GCTAObservation& obs) | ||
| 1130 | 1129 | ||
| 1131 | // Compute alpha for this energy bin | 1130 | // Compute alpha for this energy bin |
| 1132 | if (aoff > 0.0) { | 1131 | if (aoff > 0.0) { |
| 1133 | - m_alpha[i] = aon/aoff; | 1132 | + alpha[i] = aon/aoff; |
| 1134 | } | 1133 | } |
| 1135 | 1134 | ||
| 1136 | } // endfor: looped over reconstructed energies | 1135 | } // endfor: looped over reconstructed energies |
| 1136 | + | ||
| 1137 | + // Append alpha vector to ARF | ||
| 1138 | + m_arf.append("ALPHA", alpha); | ||
| 1137 | 1139 | ||
| 1138 | } // endif: there were energy bins | 1140 | } // endif: there were energy bins |
| 1139 | 1141 | ||
| @@ -1246,15 +1248,15 @@ void GCTAOnOffObservation::compute_bgd(const GCTAObservation& obs) | @@ -1246,15 +1248,15 @@ void GCTAOnOffObservation::compute_bgd(const GCTAObservation& obs) | ||
| 1246 | // Continue only if there are spectral bins | 1248 | // Continue only if there are spectral bins |
| 1247 | int nreco = ereco.size(); | 1249 | int nreco = ereco.size(); |
| 1248 | if (nreco > 0) { | 1250 | if (nreco > 0) { |
| 1251 | + | ||
| 1252 | + // Initialise background rayes | ||
| 1253 | + std::vector<double> background(nreco, 0.0); | ||
| 1249 | 1254 | ||
| 1250 | // Get CTA observation pointing direction, zenith, and azimuth | 1255 | // Get CTA observation pointing direction, zenith, and azimuth |
| 1251 | GCTAPointing obspnt(obs.pointing()); | 1256 | GCTAPointing obspnt(obs.pointing()); |
| 1252 | double zenith = obspnt.zenith(); | 1257 | double zenith = obspnt.zenith(); |
| 1253 | double azimuth = obspnt.azimuth(); | 1258 | double azimuth = obspnt.azimuth(); |
| 1254 | 1259 | ||
| 1255 | - // Initialize background rate array | ||
| 1256 | - m_bgd = GArf(ereco); | ||
| 1257 | - | ||
| 1258 | // Get pointer on CTA IRF response | 1260 | // Get pointer on CTA IRF response |
| 1259 | const GCTAResponseIrf* rsp = | 1261 | const GCTAResponseIrf* rsp = |
| 1260 | dynamic_cast<const GCTAResponseIrf*>(obs.response()); | 1262 | dynamic_cast<const GCTAResponseIrf*>(obs.response()); |
| @@ -1296,12 +1298,16 @@ void GCTAOnOffObservation::compute_bgd(const GCTAObservation& obs) | @@ -1296,12 +1298,16 @@ void GCTAOnOffObservation::compute_bgd(const GCTAObservation& obs) | ||
| 1296 | double logEreco = m_on_spec.ebounds().elogmean(i).log10TeV(); | 1298 | double logEreco = m_on_spec.ebounds().elogmean(i).log10TeV(); |
| 1297 | 1299 | ||
| 1298 | // Get rate in events/s/MeV | 1300 | // Get rate in events/s/MeV |
| 1299 | - m_bgd[i] += (*bgd)(logEreco, offdir.detx(), offdir.dety()) * | ||
| 1300 | - skyreg->solidangle(); | 1301 | + background[i] += (*bgd)(logEreco, |
| 1302 | + offdir.detx(), | ||
| 1303 | + offdir.dety()) * skyreg->solidangle(); | ||
| 1301 | 1304 | ||
| 1302 | } // endfor: looped over energy bins | 1305 | } // endfor: looped over energy bins |
| 1303 | 1306 | ||
| 1304 | } // endfor: looped over sky regions | 1307 | } // endfor: looped over sky regions |
| 1308 | + | ||
| 1309 | + // Append background vector to ARF | ||
| 1310 | + m_arf.append("BACKGROUND", background); | ||
| 1305 | 1311 | ||
| 1306 | } // endif: there were spectral bins | 1312 | } // endif: there were spectral bins |
| 1307 | 1313 | ||
| @@ -1557,6 +1563,9 @@ double GCTAOnOffObservation::model_off(const GModels& models, | @@ -1557,6 +1563,9 @@ double GCTAOnOffObservation::model_off(const GModels& models, | ||
| 1557 | 1563 | ||
| 1558 | // Continue only if bin number is in range and if there are parameters | 1564 | // Continue only if bin number is in range and if there are parameters |
| 1559 | if ((ibin < m_off_spec.size()) && (npars > 0)) { | 1565 | if ((ibin < m_off_spec.size()) && (npars > 0)) { |
| 1566 | + | ||
| 1567 | + // Get reference to background rates | ||
| 1568 | + const std::vector<double>& background = m_arf["BACKGROUND"]; | ||
| 1560 | 1569 | ||
| 1561 | // Get energy bin mean and width | 1570 | // Get energy bin mean and width |
| 1562 | const GEnergy emean = m_off_spec.ebounds().elogmean(ibin); | 1571 | const GEnergy emean = m_off_spec.ebounds().elogmean(ibin); |
| @@ -1564,7 +1573,7 @@ double GCTAOnOffObservation::model_off(const GModels& models, | @@ -1564,7 +1573,7 @@ double GCTAOnOffObservation::model_off(const GModels& models, | ||
| 1564 | 1573 | ||
| 1565 | // Compute normalisation factor | 1574 | // Compute normalisation factor |
| 1566 | double exposure = m_off_spec.exposure(); | 1575 | double exposure = m_off_spec.exposure(); |
| 1567 | - double norm = m_bgd[ibin] * exposure * ewidth; | 1576 | + double norm = background[ibin] * exposure * ewidth; |
| 1568 | 1577 | ||
| 1569 | // Loop over models | 1578 | // Loop over models |
| 1570 | for (int j = 0; j < models.size(); ++j) { | 1579 | for (int j = 0; j < models.size(); ++j) { |