Commit 252ad2dc2d10b23e18a196b6b9ed2573a78de2a1
1 parent
6d02c035
Fixed response computations for composite model
Showing
3 changed files
with
24 additions
and
9 deletions
inst/cta/src/GCTAResponseCube.cpp
| @@ -1516,13 +1516,25 @@ double GCTAResponseCube::irf_composite(const GEvent& event, | @@ -1516,13 +1516,25 @@ double GCTAResponseCube::irf_composite(const GEvent& event, | ||
| 1516 | // Initialise IRF | 1516 | // Initialise IRF |
| 1517 | double irf = 0.0; | 1517 | double irf = 0.0; |
| 1518 | 1518 | ||
| 1519 | + // Get pointer to composite model | ||
| 1519 | const GModelSpatialComposite* model = dynamic_cast<const GModelSpatialComposite*>(source.model()); | 1520 | const GModelSpatialComposite* model = dynamic_cast<const GModelSpatialComposite*>(source.model()); |
| 1520 | 1521 | ||
| 1522 | + // Loop over model components | ||
| 1521 | for (int i=0;i<model->components();++i) { | 1523 | for (int i=0;i<model->components();++i) { |
| 1524 | + | ||
| 1525 | + // Get pointer to spatial component | ||
| 1522 | GModelSpatial* spat = const_cast<GModelSpatial*>(model->component(i)); | 1526 | GModelSpatial* spat = const_cast<GModelSpatial*>(model->component(i)); |
| 1527 | + | ||
| 1528 | + // Create new GSource object | ||
| 1523 | GSource src(source.name(), spat, source.energy(), source.time()); | 1529 | GSource src(source.name(), spat, source.energy(), source.time()); |
| 1530 | + | ||
| 1531 | + // Compute irf value | ||
| 1524 | irf += this->irf(event, source, obs); | 1532 | irf += this->irf(event, source, obs); |
| 1525 | } | 1533 | } |
| 1526 | 1534 | ||
| 1535 | + // Divide by number of model components | ||
| 1536 | + irf /= (double)model->components(); | ||
| 1537 | + | ||
| 1538 | + | ||
| 1527 | return irf; | 1539 | return irf; |
| 1528 | } | 1540 | } |
inst/cta/src/GCTAResponseIrf.cpp
| @@ -2882,9 +2882,12 @@ double GCTAResponseIrf::irf_composite(const GEvent& event, | @@ -2882,9 +2882,12 @@ double GCTAResponseIrf::irf_composite(const GEvent& event, | ||
| 2882 | GSource src(source.name(), spat, source.energy(), source.time()); | 2882 | GSource src(source.name(), spat, source.energy(), source.time()); |
| 2883 | 2883 | ||
| 2884 | // Compute irf value | 2884 | // Compute irf value |
| 2885 | - irf = this->irf(event, source, obs); | 2885 | + irf += this->irf(event, src, obs); |
| 2886 | } | 2886 | } |
| 2887 | 2887 | ||
| 2888 | + // Divide by number of model components | ||
| 2889 | + irf /= (double)model->components(); | ||
| 2890 | + | ||
| 2888 | // Return IRF value | 2891 | // Return IRF value |
| 2889 | return irf; | 2892 | return irf; |
| 2890 | } | 2893 | } |
| @@ -3516,24 +3519,24 @@ double GCTAResponseIrf::nroi_composite(const GModelSky& model, | @@ -3516,24 +3519,24 @@ double GCTAResponseIrf::nroi_composite(const GModelSky& model, | ||
| 3516 | double nroi = 0.0; | 3519 | double nroi = 0.0; |
| 3517 | 3520 | ||
| 3518 | // Get composite model | 3521 | // Get composite model |
| 3519 | - const GModelSpatialComposite* comp = dynamic_cast<const GModelSpatialComposite*>(model.spatial()); | 3522 | + GModelSpatialComposite* comp = dynamic_cast<GModelSpatialComposite*>(model.spatial()); |
| 3520 | 3523 | ||
| 3521 | // Loop over model components | 3524 | // Loop over model components |
| 3522 | - for (int i=0;i<comp->components();++i) { | ||
| 3523 | - | ||
| 3524 | - // Retrieve pointer to spatial component | ||
| 3525 | - GModelSpatial* spat = const_cast<GModelSpatial*>(comp->component(i)); | 3525 | + for (int i = 0; i < comp->components(); ++i) { |
| 3526 | 3526 | ||
| 3527 | // Create new sky model | 3527 | // Create new sky model |
| 3528 | GModelSky sky = GModelSky(model); | 3528 | GModelSky sky = GModelSky(model); |
| 3529 | 3529 | ||
| 3530 | // Assign spatial part | 3530 | // Assign spatial part |
| 3531 | - sky.spatial(spat); | 3531 | + sky.spatial(comp->component(i)); |
| 3532 | 3532 | ||
| 3533 | // Compute nroi | 3533 | // Compute nroi |
| 3534 | - nroi = this->nroi(sky, srcEng, srcTime, obsEng, obsTime, obs); | 3534 | + nroi += this->nroi(sky, srcEng, srcTime, obsEng, obsTime, obs); |
| 3535 | } | 3535 | } |
| 3536 | 3536 | ||
| 3537 | + // Divide by number of model components | ||
| 3538 | + nroi /= (double)comp->components(); | ||
| 3539 | + | ||
| 3537 | // Return nroi | 3540 | // Return nroi |
| 3538 | return nroi; | 3541 | return nroi; |
| 3539 | 3542 |
src/model/GModelSpatialComposite.cpp
| @@ -628,7 +628,7 @@ const GModelSpatial* GModelSpatialComposite::component(const std::string& name) | @@ -628,7 +628,7 @@ const GModelSpatial* GModelSpatialComposite::component(const std::string& name) | ||
| 628 | void GModelSpatialComposite::init_members(void) | 628 | void GModelSpatialComposite::init_members(void) |
| 629 | { | 629 | { |
| 630 | // Initialise model type | 630 | // Initialise model type |
| 631 | - m_type = "SpatialComposite"; | 631 | + m_type = "Composite"; |
| 632 | 632 | ||
| 633 | // Initialise models vector | 633 | // Initialise models vector |
| 634 | m_components.clear(); | 634 | m_components.clear(); |