Commit 7883799b9fd8ab9530f440f9af9541516879e9e1
1 parent
c51109f5
Add GResponse::use_source() method (#3312)
Showing
2 changed files
with
74 additions
and
42 deletions
include/GResponse.hpp
| ... | ... | @@ -119,6 +119,9 @@ protected: |
| 119 | 119 | const bool& grad) const; |
| 120 | 120 | |
| 121 | 121 | // Virtual protected methods |
| 122 | + virtual bool use_source(const GEvent& event, | |
| 123 | + const GSource& source, | |
| 124 | + const GObservation& obs) const; | |
| 122 | 125 | virtual double irf_ptsrc(const GEvent& event, |
| 123 | 126 | const GSource& source, |
| 124 | 127 | const GObservation& obs) const; | ... | ... |
src/obs/GResponse.cpp
| ... | ... | @@ -308,50 +308,55 @@ double GResponse::irf_spatial(const GEvent& event, |
| 308 | 308 | // Initialise IRF value |
| 309 | 309 | double irf = 0.0; |
| 310 | 310 | |
| 311 | - // Set IRF value attributes | |
| 312 | - std::string name = obs.id() + "::" + source.name(); | |
| 313 | - const GInstDir& dir = event.dir(); | |
| 314 | - const GEnergy& ereco = event.energy(); | |
| 315 | - const GEnergy& etrue = source.energy(); | |
| 316 | - | |
| 317 | - // Signal if spatial model has free parameters | |
| 318 | - bool has_free_pars = source.model()->has_free_pars(); | |
| 319 | - | |
| 320 | - // If the spatial model component has free parameters, or the response | |
| 321 | - // cache should not be used, or the cache does not contain the requested | |
| 322 | - // IRF value then compute the IRF value for the spatial model. | |
| 323 | - if (has_free_pars || | |
| 324 | - !m_use_irf_cache || | |
| 325 | - !m_irf_cache.contains(name, dir, ereco, etrue, &irf)) { | |
| 326 | - | |
| 327 | - // Compute IRF for spatial model | |
| 328 | - switch (source.model()->code()) { | |
| 329 | - case GMODEL_SPATIAL_POINT_SOURCE: | |
| 330 | - irf = irf_ptsrc(event, source, obs); | |
| 331 | - break; | |
| 332 | - case GMODEL_SPATIAL_RADIAL: | |
| 333 | - irf = irf_radial(event, source, obs); | |
| 334 | - break; | |
| 335 | - case GMODEL_SPATIAL_ELLIPTICAL: | |
| 336 | - irf = irf_elliptical(event, source, obs); | |
| 337 | - break; | |
| 338 | - case GMODEL_SPATIAL_DIFFUSE: | |
| 339 | - irf = irf_diffuse(event, source, obs); | |
| 340 | - break; | |
| 341 | - case GMODEL_SPATIAL_COMPOSITE: | |
| 342 | - irf = irf_composite(event, source, obs); | |
| 343 | - break; | |
| 344 | - default: | |
| 345 | - break; | |
| 346 | - } | |
| 311 | + // Continue only if source should be used | |
| 312 | + if (use_source(event, source, obs)) { | |
| 313 | + | |
| 314 | + // Set IRF value attributes | |
| 315 | + std::string name = obs.id() + "::" + source.name(); | |
| 316 | + const GInstDir& dir = event.dir(); | |
| 317 | + const GEnergy& ereco = event.energy(); | |
| 318 | + const GEnergy& etrue = source.energy(); | |
| 319 | + | |
| 320 | + // Signal if spatial model has free parameters | |
| 321 | + bool has_free_pars = source.model()->has_free_pars(); | |
| 322 | + | |
| 323 | + // If the spatial model component has free parameters, or the response | |
| 324 | + // cache should not be used, or the cache does not contain the requested | |
| 325 | + // IRF value then compute the IRF value for the spatial model. | |
| 326 | + if (has_free_pars || | |
| 327 | + !m_use_irf_cache || | |
| 328 | + !m_irf_cache.contains(name, dir, ereco, etrue, &irf)) { | |
| 329 | + | |
| 330 | + // Compute IRF for spatial model | |
| 331 | + switch (source.model()->code()) { | |
| 332 | + case GMODEL_SPATIAL_POINT_SOURCE: | |
| 333 | + irf = irf_ptsrc(event, source, obs); | |
| 334 | + break; | |
| 335 | + case GMODEL_SPATIAL_RADIAL: | |
| 336 | + irf = irf_radial(event, source, obs); | |
| 337 | + break; | |
| 338 | + case GMODEL_SPATIAL_ELLIPTICAL: | |
| 339 | + irf = irf_elliptical(event, source, obs); | |
| 340 | + break; | |
| 341 | + case GMODEL_SPATIAL_DIFFUSE: | |
| 342 | + irf = irf_diffuse(event, source, obs); | |
| 343 | + break; | |
| 344 | + case GMODEL_SPATIAL_COMPOSITE: | |
| 345 | + irf = irf_composite(event, source, obs); | |
| 346 | + break; | |
| 347 | + default: | |
| 348 | + break; | |
| 349 | + } | |
| 347 | 350 | |
| 348 | - } // endif: computed spatial model | |
| 351 | + } // endif: computed spatial model | |
| 349 | 352 | |
| 350 | - // If the spatial model has no free parameters and the response cache | |
| 351 | - // should be used then put the IRF value in the response cache. | |
| 352 | - if (!has_free_pars && m_use_irf_cache) { | |
| 353 | - m_irf_cache.set(name, dir, ereco, etrue, irf); | |
| 354 | - } | |
| 353 | + // If the spatial model has no free parameters and the response cache | |
| 354 | + // should be used then put the IRF value in the response cache. | |
| 355 | + if (!has_free_pars && m_use_irf_cache) { | |
| 356 | + m_irf_cache.set(name, dir, ereco, etrue, irf); | |
| 357 | + } | |
| 358 | + | |
| 359 | + } // endif: source was used | |
| 355 | 360 | |
| 356 | 361 | // Return IRF value |
| 357 | 362 | return irf; |
| ... | ... | @@ -439,6 +444,30 @@ void GResponse::free_members(void) |
| 439 | 444 | |
| 440 | 445 | |
| 441 | 446 | /***********************************************************************//** |
| 447 | + * @brief Check if source should be used | |
| 448 | + * | |
| 449 | + * @param[in] event Observed event. | |
| 450 | + * @param[in] source Source. | |
| 451 | + * @param[in] obs Observation. | |
| 452 | + * @return True if source should be used. | |
| 453 | + * | |
| 454 | + * Returns true if the source should be used. | |
| 455 | + * | |
| 456 | + * This method is a hook. The base class version of this method returns | |
| 457 | + * always true, but derived classes may implement a version of this method | |
| 458 | + * that actually evaluates whether a source should be used or not for a given | |
| 459 | + * event. | |
| 460 | + ***************************************************************************/ | |
| 461 | +bool GResponse::use_source(const GEvent& event, | |
| 462 | + const GSource& source, | |
| 463 | + const GObservation& obs) const | |
| 464 | +{ | |
| 465 | + // Return true | |
| 466 | + return true; | |
| 467 | +} | |
| 468 | + | |
| 469 | + | |
| 470 | +/***********************************************************************//** | |
| 442 | 471 | * @brief Return instrument response to point source |
| 443 | 472 | * |
| 444 | 473 | * @param[in] event Observed event. | ... | ... |