Commit 415f66bad4b0db6417dbf6a82ba590ea919e9ce6

Authored by knodlseder
1 parent 2207c982

rename GSkyModel to GModelSky

include/GResponse.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GResponse.hpp - Abstract response base class * 2 * GResponse.hpp - Abstract response base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2008-2010 by Jurgen Knodlseder * 4 + * copyright (C) 2008-2011 by Jurgen Knodlseder *
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 *
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 #include "GEvent.hpp" 26 #include "GEvent.hpp"
27 #include "GEnergy.hpp" 27 #include "GEnergy.hpp"
28 #include "GTime.hpp" 28 #include "GTime.hpp"
29 -#include "GSkyModel.hpp" 29 +#include "GModelSky.hpp"
30 30
31 /* __ Forward declarations _______________________________________________ */ 31 /* __ Forward declarations _______________________________________________ */
32 class GObservation; 32 class GObservation;
@@ -66,10 +66,10 @@ public: @@ -66,10 +66,10 @@ public:
66 virtual GResponse* clone(void) const = 0; 66 virtual GResponse* clone(void) const = 0;
67 virtual bool hasedisp(void) const = 0; 67 virtual bool hasedisp(void) const = 0;
68 virtual bool hastdisp(void) const = 0; 68 virtual bool hastdisp(void) const = 0;
69 - virtual double irf(const GEvent& event, const GSkyModel& model, 69 + virtual double irf(const GEvent& event, const GModelSky& model,
70 const GEnergy& srcEng, const GTime& srcTime, 70 const GEnergy& srcEng, const GTime& srcTime,
71 const GObservation& obs) const = 0; 71 const GObservation& obs) const = 0;
72 - virtual double npred(const GSkyModel& model, const GEnergy& srcEng, 72 + virtual double npred(const GModelSky& model, const GEnergy& srcEng,
73 const GTime& srcTime, 73 const GTime& srcTime,
74 const GObservation& obs) const = 0; 74 const GObservation& obs) const = 0;
75 virtual std::string print(void) const = 0; 75 virtual std::string print(void) const = 0;
pyext/GResponse.i
@@ -39,10 +39,10 @@ public: @@ -39,10 +39,10 @@ public:
39 virtual GResponse* clone(void) const = 0; 39 virtual GResponse* clone(void) const = 0;
40 virtual bool hasedisp(void) const = 0; 40 virtual bool hasedisp(void) const = 0;
41 virtual bool hastdisp(void) const = 0; 41 virtual bool hastdisp(void) const = 0;
42 - virtual double irf(const GEvent& event, const GSkyModel& model, 42 + virtual double irf(const GEvent& event, const GModelSky& model,
43 const GEnergy& srcEng, const GTime& srcTime, 43 const GEnergy& srcEng, const GTime& srcTime,
44 const GObservation& obs) const = 0; 44 const GObservation& obs) const = 0;
45 - virtual double npred(const GSkyModel& model, const GEnergy& srcEng, 45 + virtual double npred(const GModelSky& model, const GEnergy& srcEng,
46 const GTime& srcTime, 46 const GTime& srcTime,
47 const GObservation& obs) const = 0; 47 const GObservation& obs) const = 0;
48 }; 48 };
src/obs/GObservation.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GObservation.cpp - Observation abstract base class * 2 * GObservation.cpp - Observation abstract base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2008-2010 by Jurgen Knodlseder * 4 + * copyright (C) 2008-2011 by Jurgen Knodlseder *
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 *
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 #include <cmath> 23 #include <cmath>
24 #include "GException.hpp" 24 #include "GException.hpp"
25 #include "GObservation.hpp" 25 #include "GObservation.hpp"
  26 +#include "GModelSky.hpp"
26 #include "GModelSpatialPtsrc.hpp" 27 #include "GModelSpatialPtsrc.hpp"
27 #include "GIntegral.hpp" 28 #include "GIntegral.hpp"
28 29
@@ -33,8 +34,8 @@ @@ -33,8 +34,8 @@
33 #define G_NPRED_SPEC "GObservation::npred_spec(GModel&, GTime&)" 34 #define G_NPRED_SPEC "GObservation::npred_spec(GModel&, GTime&)"
34 #define G_NPRED_SPAT "GObservation::npred_spat(GModel&, int, GEnergy&,"\ 35 #define G_NPRED_SPAT "GObservation::npred_spat(GModel&, int, GEnergy&,"\
35 " GTime&)" 36 " GTime&)"
36 -#define G_NPRED_KERN "GObservation::npred_kern(GModel&, GSkyDir&, GEnergy&,"\  
37 - " GTime&, GPointing&)" 37 +#define G_NPRED_KERN "GObservation::npred_kern(GModel&, GSkyDir&,"\
  38 + " GEnergy&, GTime&, GPointing&)"
38 #define G_NPRED_GRAD_TEMP "GObservation::npred_grad_temp(GModel&, int)" 39 #define G_NPRED_GRAD_TEMP "GObservation::npred_grad_temp(GModel&, int)"
39 #define G_NPRED_GRAD_SPEC "GObservation::npred_grad_spec(GModel&, int,"\ 40 #define G_NPRED_GRAD_SPEC "GObservation::npred_grad_spec(GModel&, int,"\
40 " GTime&)" 41 " GTime&)"
@@ -230,7 +231,7 @@ double GObservation::npred(const GModels&amp; models, GVector* gradient) const @@ -230,7 +231,7 @@ double GObservation::npred(const GModels&amp; models, GVector* gradient) const
230 // Loop over models 231 // Loop over models
231 for (int i = 0; i < models.size(); ++i) { 232 for (int i = 0; i < models.size(); ++i) {
232 233
233 - // Extract pointer to model (bypass const-correctness) 234 + // Extract pointer to model (circumvent const-correctness)
234 GModel* model = (GModel*)models(i); 235 GModel* model = (GModel*)models(i);
235 236
236 // Handle only components that are relevant for the actual 237 // Handle only components that are relevant for the actual
@@ -489,6 +490,8 @@ double GObservation::npred_spec(const GModel&amp; model, @@ -489,6 +490,8 @@ double GObservation::npred_spec(const GModel&amp; model,
489 * 490 *
490 * @exception GException::no_response 491 * @exception GException::no_response
491 * No valid instrument response function for observation. 492 * No valid instrument response function for observation.
  493 + * @exception GException::feature_not_implemented
  494 + * Computation for data-space models not yet implemented.
492 * 495 *
493 * Computes 496 * Computes
494 * \f[\int_{\rm ROI} S(\vec{p}, E, t) 497 * \f[\int_{\rm ROI} S(\vec{p}, E, t)
@@ -506,27 +509,47 @@ double GObservation::npred_spec(const GModel&amp; model, @@ -506,27 +509,47 @@ double GObservation::npred_spec(const GModel&amp; model,
506 * \f${\rm ROI}\f$ is the region of interest that is stored in the 509 * \f${\rm ROI}\f$ is the region of interest that is stored in the
507 * GObservation::m_roi member. 510 * GObservation::m_roi member.
508 * Note that the integration is performed by the GResponse::npred() method. 511 * Note that the integration is performed by the GResponse::npred() method.
  512 + *
  513 + * @todo Implement computation for data-space model
509 ***************************************************************************/ 514 ***************************************************************************/
510 double GObservation::npred_spat(const GModel& model, 515 double GObservation::npred_spat(const GModel& model,
511 const GEnergy& srcEng, 516 const GEnergy& srcEng,
512 const GTime& srcTime) const 517 const GTime& srcTime) const
513 { 518 {
514 - // Get response function  
515 - GResponse* rsp = response();  
516 - if (rsp == NULL)  
517 - throw GException::no_response(G_NPRED_SPAT); 519 + // Initialise result
  520 + double result = 0.0;
  521 +
  522 + // Get sky model (NULL if not a sky model)
  523 + GModelSky* sky = dynamic_cast<GModelSky*>((GModel*)&model);
  524 +
  525 + // Case A: We have a sky model
  526 + if (sky != NULL) {
518 527
519 - // Compute integrated IRF  
520 - double npred = rsp->npred(model, srcEng, srcTime, *this); 528 + // Get response function
  529 + GResponse* rsp = response();
  530 + if (rsp == NULL)
  531 + throw GException::no_response(G_NPRED_SPAT);
521 532
522 - // Compute source model  
523 - double source = 1.0;  
524 - GModel* ptr = (GModel*)&model; // bypass const-correctness  
525 - if (ptr->spectral() != NULL) npred *= ptr->spectral()->eval(srcEng);  
526 - if (ptr->temporal() != NULL) source *= ptr->temporal()->eval(srcTime); 533 + // Compute integrated IRF
  534 + double npred = rsp->npred(*sky, srcEng, srcTime, *this);
  535 +
  536 + // Compute source model
  537 + double source = 1.0;
  538 + if (sky->spectral() != NULL) npred *= sky->spectral()->eval(srcEng);
  539 + if (sky->temporal() != NULL) source *= sky->temporal()->eval(srcTime);
  540 +
  541 + // Set result
  542 + result = source * npred;
  543 +
  544 + }
  545 +
  546 + // Case B: We have a data space model
  547 + else {
  548 + throw GException::feature_not_implemented(G_NPRED_SPAT);
  549 + }
527 550
528 // Return 551 // Return
529 - return (source * npred); 552 + return result;
530 } 553 }
531 554
532 555
@@ -681,30 +704,53 @@ double GObservation::npred_grad_spec(const GModel&amp; model, int ipar, @@ -681,30 +704,53 @@ double GObservation::npred_grad_spec(const GModel&amp; model, int ipar,
681 * 704 *
682 * @exception GException::no_response 705 * @exception GException::no_response
683 * No valid instrument response function for observation. 706 * No valid instrument response function for observation.
  707 + * @exception GException::feature_not_implemented
  708 + * Method not yet implemented for data-space model.
  709 + *
  710 + * @todo Implement method for data-space model.
  711 + * @todo Avoid recomputation of gradients for same model parameters.
684 ***************************************************************************/ 712 ***************************************************************************/
685 double GObservation::npred_grad_spat(const GModel& model, int ipar, 713 double GObservation::npred_grad_spat(const GModel& model, int ipar,
686 const GEnergy& srcEng, 714 const GEnergy& srcEng,
687 const GTime& srcTime) const 715 const GTime& srcTime) const
688 { 716 {
689 - // Get response function  
690 - GResponse* rsp = response();  
691 - if (rsp == NULL)  
692 - throw GException::no_response(G_NPRED_GRAD_SPAT); 717 + // Initialise result
  718 + double result = 0.0;
  719 +
  720 + // Get sky model (NULL if not a sky model)
  721 + GModelSky* sky = dynamic_cast<GModelSky*>((GModel*)&model);
  722 +
  723 + // Case A: We have a sky model
  724 + if (sky != NULL) {
693 725
694 - // Compute integrated IRF  
695 - double npred = rsp->npred(model, srcEng, srcTime, *this); 726 + // Get response function
  727 + GResponse* rsp = response();
  728 + if (rsp == NULL)
  729 + throw GException::no_response(G_NPRED_GRAD_SPAT);
696 730
697 - // Compute source model  
698 - double source = 1.0;  
699 - GModel* ptr = (GModel*)&model; // bypass const-correctness  
700 - if (ptr->spectral() != NULL) source *= ptr->spectral()->eval_gradients(srcEng);  
701 - if (ptr->temporal() != NULL) source *= ptr->temporal()->eval_gradients(srcTime); 731 + // Compute integrated IRF
  732 + double npred = rsp->npred(*sky, srcEng, srcTime, *this);
702 733
703 - // Extract requested model gradient  
704 - double grad = (*ptr)(ipar).gradient(); 734 + // Compute source model
  735 + double source = 1.0;
  736 + if (sky->spectral() != NULL) source *= sky->spectral()->eval_gradients(srcEng);
  737 + if (sky->temporal() != NULL) source *= sky->temporal()->eval_gradients(srcTime);
705 738
  739 + // Extract requested model gradient
  740 + double grad = (*sky)(ipar).gradient();
  741 +
  742 + // Compute result
  743 + result = grad * npred;
  744 +
  745 + }
  746 +
  747 + // Case B: We have a data space model
  748 + else {
  749 + throw GException::feature_not_implemented(G_NPRED_SPAT);
  750 + }
  751 +
706 // Return 752 // Return
707 - return (grad * npred); 753 + return result;
708 } 754 }
709 755
710 756