include/GModelSpectralPlaw2.hpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *        GModelSpectralPlaw2.hpp - Spectral power law model class         *
00003  * ----------------------------------------------------------------------- *
00004  *  copyright (C) 2011-2016 by Juergen Knoedlseder                         *
00005  * ----------------------------------------------------------------------- *
00006  *                                                                         *
00007  *  This program is free software: you can redistribute it and/or modify   *
00008  *  it under the terms of the GNU General Public License as published by   *
00009  *  the Free Software Foundation, either version 3 of the License, or      *
00010  *  (at your option) any later version.                                    *
00011  *                                                                         *
00012  *  This program is distributed in the hope that it will be useful,        *
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00015  *  GNU General Public License for more details.                           *
00016  *                                                                         *
00017  *  You should have received a copy of the GNU General Public License      *
00018  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
00019  *                                                                         *
00020  ***************************************************************************/
00021 /**
00022  * @file GModelSpectralPlaw2.hpp
00023  * @brief Flux normalized power law spectral model class interface definition
00024  * @author Juergen Knoedlseder
00025  */
00026 
00027 #ifndef GMODELSPECTRALPLAW2_HPP
00028 #define GMODELSPECTRALPLAW2_HPP
00029 
00030 /* __ Includes ___________________________________________________________ */
00031 #include <string>
00032 #include "GModelSpectral.hpp"
00033 #include "GModelPar.hpp"
00034 #include "GEnergy.hpp"
00035 
00036 /* __ Forward declarations _______________________________________________ */
00037 class GRan;
00038 class GTime;
00039 class GXmlElement;
00040 
00041 
00042 /***********************************************************************//**
00043  * @class GModelSpectralPlaw2
00044  *
00045  * @brief Flux normalized power law spectral model class
00046  *
00047  * This class implements a power law spectrum. The model is defined by
00048  *
00049  * \f[
00050  *    S_{\rm E}(E | t) = {\tt m\_integral}
00051  *    \frac{{\tt m\_index}+1}
00052  *         {{\tt e\_max}^{{\tt m\_index}+1} -
00053  *          {\tt e\_min}^{{\tt m\_index}+1}}
00054  *    E^{\tt m\_index}
00055  * \f]
00056  *
00057  * for \f${\tt m\_index} \ne -1\f$ and
00058  *
00059  * \f[
00060  *    S_{\rm E}(E | t) = 
00061  *    \frac{{\tt m\_integral}}
00062  *         {\log {\tt e\_max} - \log {\tt e\_min}}
00063  *    E^{\tt m\_index}
00064  * \f]
00065  *
00066  * for \f${\tt m\_index} = -1\f$, where
00067  * - \f${\tt e\_min}\f$ is the minimum energy of an interval,
00068  * - \f${\tt e\_max}\f$ is the maximum energy of an interval,
00069  * - \f${\tt m\_integral}\f$ is the integral flux between 
00070  *   \f${\tt e\_min}\f$ and \f${\tt e\_max}\f$, and
00071  * - \f${\tt m\_index}\f$ is the spectral index.
00072  ***************************************************************************/
00073 class GModelSpectralPlaw2 : public GModelSpectral {
00074 
00075 public:
00076     // Constructors and destructors
00077     GModelSpectralPlaw2(void);
00078     GModelSpectralPlaw2(const std::string& type,
00079                         const std::string& integral,
00080                         const std::string& index,
00081                         const std::string& emin,
00082                         const std::string& emax);
00083     GModelSpectralPlaw2(const double&  integral,
00084                         const double&  index,
00085                         const GEnergy& emin,
00086                         const GEnergy& emax);
00087     explicit GModelSpectralPlaw2(const GXmlElement& xml);
00088     GModelSpectralPlaw2(const GModelSpectralPlaw2& model);
00089     virtual ~GModelSpectralPlaw2(void);
00090 
00091     // Operators
00092     virtual GModelSpectralPlaw2& operator=(const GModelSpectralPlaw2& model);
00093 
00094     // Implemented pure virtual base class methods
00095     virtual void                 clear(void);
00096     virtual GModelSpectralPlaw2* clone(void) const;
00097     virtual std::string          classname(void) const;
00098     virtual std::string          type(void) const;
00099     virtual double               eval(const GEnergy& srcEng,
00100                                       const GTime&   srcTime = GTime()) const;
00101     virtual double               eval_gradients(const GEnergy& srcEng,
00102                                                 const GTime&   srcTime = GTime());
00103     virtual double               flux(const GEnergy& emin,
00104                                       const GEnergy& emax) const;
00105     virtual double               eflux(const GEnergy& emin,
00106                                        const GEnergy& emax) const;
00107     virtual GEnergy              mc(const GEnergy& emin,
00108                                     const GEnergy& emax,
00109                                     const GTime&   time,
00110                                     GRan&          ran) const;
00111     virtual void                 read(const GXmlElement& xml);
00112     virtual void                 write(GXmlElement& xml) const;
00113     virtual std::string          print(const GChatter& chatter = NORMAL) const;
00114 
00115     // Other methods
00116     double  integral(void) const;
00117     void    integral(const double& integral);
00118     double  index(void) const;
00119     void    index(const double& index);
00120     GEnergy emin(void) const;
00121     void    emin(const GEnergy& emin);
00122     GEnergy emax(void) const;
00123     void    emax(const GEnergy& emax);
00124 
00125 protected:
00126     // Protected methods
00127     void init_members(void);
00128     void copy_members(const GModelSpectralPlaw2& model);
00129     void free_members(void);
00130     void update(const GEnergy& srcEng) const;
00131 
00132     // Protected members
00133     std::string     m_type;            //!< Model type
00134     GModelPar       m_integral;        //!< Integral flux
00135     GModelPar       m_index;           //!< Spectral index
00136     GModelPar       m_emin;            //!< Lower energy limit (MeV)
00137     GModelPar       m_emax;            //!< Upper energy limit (MeV)
00138 
00139     // Cached members used for pre-computations
00140     mutable double  m_log_emin;        //!< Log(emin)
00141     mutable double  m_log_emax;        //!< Log(emax)
00142     mutable double  m_pow_emin;        //!< emin^(index+1)
00143     mutable double  m_pow_emax;        //!< emax^(index+1)
00144     mutable double  m_norm;            //!< Power-law normalization (for pivot energy 1 MeV)
00145     mutable double  m_g_norm;          //!< Power-law normalization gradient
00146     mutable double  m_power;           //!< Power-law factor
00147     mutable double  m_last_integral;   //!< Last integral flux
00148     mutable double  m_last_index;      //!< Last spectral index (MeV)
00149     mutable GEnergy m_last_emin;       //!< Last lower energy limit
00150     mutable GEnergy m_last_emax;       //!< Last upper energy limit
00151     mutable GEnergy m_last_energy;     //!< Last source energy
00152     mutable double  m_last_value;      //!< Last function value
00153     mutable double  m_last_g_integral; //!< Last integral flux gradient
00154     mutable double  m_last_g_index;    //!< Last spectral index gradient
00155 };
00156 
00157 
00158 /***********************************************************************//**
00159  * @brief Return class name
00160  *
00161  * @return String containing the class name ("GModelSpectralPlaw2").
00162  ***************************************************************************/
00163 inline
00164 std::string GModelSpectralPlaw2::classname(void) const
00165 {
00166     return ("GModelSpectralPlaw2");
00167 }
00168 
00169 
00170 /***********************************************************************//**
00171  * @brief Return model type
00172  *
00173  * @return Model type.
00174  *
00175  * Returns the type of the spectral power law model.
00176  ***************************************************************************/
00177 inline
00178 std::string GModelSpectralPlaw2::type(void) const
00179 {
00180     return (m_type);
00181 }
00182 
00183 
00184 /***********************************************************************//**
00185  * @brief Return integral flux
00186  *
00187  * @return Integral flux (ph/cm2/s).
00188  *
00189  * Returns the integral flux.
00190  ***************************************************************************/
00191 inline
00192 double GModelSpectralPlaw2::integral(void) const
00193 {
00194     return (m_integral.value());
00195 }
00196 
00197 
00198 /***********************************************************************//**
00199  * @brief Set integral flux
00200  *
00201  * @param[in] integral Integral flux (ph/cm2/s).
00202  *
00203  * Sets the integral flux.
00204  ***************************************************************************/
00205 inline
00206 void GModelSpectralPlaw2::integral(const double& integral)
00207 {
00208     m_integral.value(integral);
00209     return;
00210 }
00211 
00212 
00213 
00214 
00215 /***********************************************************************//**
00216  * @brief Return power law index
00217  *
00218  * @return Power law index.
00219  *
00220  * Returns the power law index.
00221  ***************************************************************************/
00222 inline
00223 double GModelSpectralPlaw2::index(void) const
00224 {
00225     return (m_index.value());
00226 }
00227 
00228 
00229 /***********************************************************************//**
00230  * @brief Set power law index 
00231  *
00232  * @param[in] index Power law index.
00233  *
00234  * Sets the power law index.
00235  ***************************************************************************/
00236 inline
00237 void GModelSpectralPlaw2::index(const double& index)
00238 {
00239     m_index.value(index);
00240     return;
00241 }
00242 
00243 
00244 /***********************************************************************//**
00245  * @brief Return minimum energy
00246  *
00247  * @return Minimum energy.
00248  *
00249  * Returns the minimum energy.
00250  ***************************************************************************/
00251 inline
00252 GEnergy GModelSpectralPlaw2::emin(void) const
00253 {
00254     GEnergy energy;
00255     energy.MeV(m_emin.value());
00256     return energy;
00257 }
00258 
00259 
00260 /***********************************************************************//**
00261  * @brief Set minimum energy
00262  *
00263  * @param[in] emin Minimum energy.
00264  *
00265  * Sets the minimum energy.
00266  ***************************************************************************/
00267 inline
00268 void GModelSpectralPlaw2::emin(const GEnergy& emin)
00269 {
00270     m_emin.value(emin.MeV());
00271     return;
00272 }
00273 
00274 
00275 /***********************************************************************//**
00276  * @brief Return maximum energy
00277  *
00278  * @return Maximum energy.
00279  *
00280  * Returns the maximum energy.
00281  ***************************************************************************/
00282 inline
00283 GEnergy GModelSpectralPlaw2::emax(void) const
00284 {
00285     GEnergy energy;
00286     energy.MeV(m_emax.value());
00287     return energy;
00288 }
00289 
00290 
00291 /***********************************************************************//**
00292  * @brief Set maximum energy
00293  *
00294  * @param[in] emax Maximum energy.
00295  *
00296  * Sets the maximum energy.
00297  ***************************************************************************/
00298 inline
00299 void GModelSpectralPlaw2::emax(const GEnergy& emax)
00300 {
00301     m_emax.value(emax.MeV());
00302     return;
00303 }
00304 
00305 #endif /* GMODELSPECTRALPLAW2_HPP */

Generated on Wed Jul 27 22:39:05 2016 for GammaLib by  doxygen 1.4.7