ctools  2.0.0
 All Classes Namespaces Files Functions Variables Macros Pages
ctbutterfly.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * ctbutterfly - butterfly calculation tool *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2014-2022 by Michael Mayer *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file ctbutterfly.hpp
23  * @brief Butterfly calculation tool interface definition
24  * @author Michael Mayer
25  */
26 
27 #ifndef CTBUTTERFLY_HPP
28 #define CTBUTTERFLY_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include "GammaLib.hpp"
32 #include "GCTALib.hpp"
33 #include "ctlikelihood.hpp"
34 
35 /* __Definitions _________________________________________________________ */
36 #define CTBUTTERFLY_NAME "ctbutterfly"
37 
38 
39 /***********************************************************************//**
40  * @class ctbutterfly
41  *
42  * @brief Butterfly calculation tool
43  *
44  * This class computes the confidence interval of a fitted spectrum
45  * (butterfly) for a given set of observations.
46  *
47  * The class operates on predefined observation containers, an individual
48  * event list or an observation definition XML file.
49  *
50  * During the computation the covariance matrix of the fit is used to
51  * propagate uncertainties and their correlations through the entire energy
52  * range. The output is saved as an ascii files containing the confidence
53  * band boundaries
54  ***************************************************************************/
55 class ctbutterfly : public ctlikelihood {
56 
57 public:
58  // Constructors and destructors
59  ctbutterfly(void);
60  explicit ctbutterfly(const GObservations& obs);
61  ctbutterfly(int argc, char *argv[]);
62  ctbutterfly(const ctbutterfly& app);
63  virtual ~ctbutterfly(void);
64 
65  // Operators
66  ctbutterfly& operator=(const ctbutterfly& app);
67 
68  // Methods
69  void clear(void);
70  void process(void);
71  void save(void);
72  const GFits& butterfly(void) const;
73 
74 protected:
75  // Protected methods
76  void init_members(void);
77  void copy_members(const ctbutterfly& app);
78  void free_members(void);
79  void get_parameters(void);
80  void gaussian_error_propagation(GModels& models);
81  void ellipsoid_boundary(GModels& models);
82  void check_model(void);
83  void eigenvectors(const double& a,
84  const double& b,
85  const double& c,
86  const double& d,
87  double* lambda1,
88  double* lambda2,
89  GVector* vector1,
90  GVector* vector2);
91  void create_fits(void);
92 
93  // User parameters
94  std::string m_srcname; //!< Name of source to compute butterfly
95  std::string m_method; //!< Computation method
96  double m_confidence; //!< Confidence level
97  int m_max_iter; //!< Maximum number of iterations
98  bool m_apply_edisp; //!< Apply energy dispersion?
99  bool m_fit; //!< Do fit?
100  GEbounds m_ebounds; //!< Energy binning definition
101  GFilename m_outfile; //!< Output ASCII file name
102  GChatter m_chatter; //!< Chattiness
103 
104  // Protected members
105  GMatrixSparse m_covariance; //!< Covariance matrix
106  std::vector<double> m_energies; //!< Energy values
107  std::vector<double> m_intensities; //!< Power law intensity
108  std::vector<double> m_min_intensities; //!< Minimum intensities
109  std::vector<double> m_max_intensities; //!< Maximum intensities
110  GFits m_fits; //!< FITS file holding butterfly
111 };
112 
113 
114 /***********************************************************************//**
115  * @brief Return butterfly FITS file
116  *
117  * @return Butterfly FITS file.
118  ***************************************************************************/
119 inline
120 const GFits& ctbutterfly::butterfly(void) const
121 {
122  return (m_fits);
123 }
124 
125 #endif /* CTBUTTERFLY_HPP */
ctbutterfly & operator=(const ctbutterfly &app)
Assignment operator.
void save(void)
Save butterfly diagram.
GFits m_fits
FITS file holding butterfly.
const GObservations & obs(void) const
Return observation container.
GFilename m_outfile
Output ASCII file name.
void process(void)
Computes the butterfly.
ctbutterfly(void)
Void constructor.
Definition: ctbutterfly.cpp:55
void create_fits(void)
Set result FITS file.
double m_confidence
Confidence level.
Definition: ctbutterfly.hpp:96
std::vector< double > m_intensities
Power law intensity.
bool m_fit
Do fit?
Definition: ctbutterfly.hpp:99
Likelihood tool base class interface definition.
void init_members(void)
Initialise class members.
void clear(void)
Clear ctbutterfly tool.
void check_model(void)
Check if sky model is valid.
void ellipsoid_boundary(GModels &models)
Compute butterfly using the ellipsoid boundary method.
bool m_apply_edisp
Apply energy dispersion?
Definition: ctbutterfly.hpp:98
void eigenvectors(const double &a, const double &b, const double &c, const double &d, double *lambda1, double *lambda2, GVector *vector1, GVector *vector2)
Compute normalized eigenvectors and eigenvalues.
virtual ~ctbutterfly(void)
Destructor.
int m_max_iter
Maximum number of iterations.
Definition: ctbutterfly.hpp:97
GChatter m_chatter
Chattiness.
void free_members(void)
Delete class members.
const GFits & butterfly(void) const
Return butterfly FITS file.
std::vector< double > m_min_intensities
Minimum intensities.
void gaussian_error_propagation(GModels &models)
Compute butterfly using Gaussian error propagation.
void copy_members(const ctbutterfly &app)
Copy class members.
std::vector< double > m_energies
Energy values.
GEbounds m_ebounds
Energy binning definition.
std::string m_method
Computation method.
Definition: ctbutterfly.hpp:95
std::string m_srcname
Name of source to compute butterfly.
Definition: ctbutterfly.hpp:94
Butterfly calculation tool.
Definition: ctbutterfly.hpp:55
Base class for likelihood tools.
std::vector< double > m_max_intensities
Maximum intensities.
GMatrixSparse m_covariance
Covariance matrix.
void get_parameters(void)
Get application parameters.