GOnOffFitterSpectrum.hpp

Martin Pierrick, 06/23/2013 03:46 PM

Download (6.92 KB)

 
1
/***************************************************************************
2
 *        GOnOffFitterSpectrum.hpp - ON-OFF spectral analysis class        *
3
 * ----------------------------------------------------------------------- *
4
 *  copyright (C) 2009-2013 by Juergen Knoedlseder                         *
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 GOnOffFitterSpectrum.hpp
23
 * @brief ON-OFF spectral analysis class
24
 * @author Pierrick Martin
25
 */
26

    
27
#ifndef GONOFFFITTERSPECTRUM_HPP
28
#define GONOFFFITTERSPECTRUM_HPP
29

    
30
/* __ Includes ___________________________________________________________ */
31
#include <string>
32
#include <vector>
33
#include "GObservations.hpp"
34
#include "GEbounds.hpp"
35
#include "GEnergy.hpp"
36
#include "GOnOffMaker.hpp"
37
#include "GModelSpectral.hpp"
38

    
39

    
40
/***********************************************************************//**
41
* @class GOnOffFitterSpectrum
42
*
43
* @brief ON-OFF spectral analysis class
44
*
45
* This class implements the spectral analysis of data with an ON-OFF
46
* approach for the evaluation of the instrumental background.
47
*
48
* Two kinds of analyses can be considered: either the global fit of 
49
* given spectral shape over the entire energy grid, or the determination
50
* of flux points for all energy bins. The selection of one or the other
51
* option is done from whether or not a GModelSpectral object is passed on
52
* instantiation. In the case of flux points computation, an instance of 
53
* GModelSpectralFunc is created internally and filled with the results.
54
*
55
* The method convolve_spectrum() performs the convolution of the spectral 
56
* model with the instrument response and fills the m_expcts variable.
57
* Note that the convolution is done for each observation run and we store
58
* here only the summed counts.
59
*
60
* The method compute_energy() computes the average true energy and its 
61
* variance for each reconstructed energy bin and fills the m_truemean 
62
* and m_truevar variables. Both cannot be accessed at the moment.
63
* 
64
* The method compute_significance() evaluates the significance of the 
65
* source signal in each energy bin from the Li&Ma-1983 prescription.
66
* The result can be accessed through the significance() method.
67
*
68
* The method sum_data() sets the m_sum flag to indicate if the analysis
69
* is performed on summed ON and OFF data or keeping the ON and OFF
70
* information of each run independent. This implies a separate 
71
* optimization function for each case.
72
*
73
* The results, either best-fit spectral parameters or best-fit flux points,
74
* are written to an XML file through the methods of the GModelSpectral 
75
* object.
76
*
77
* To be decided:
78
* - Output format for the significance ? Just in log file ?
79
* - Do we store expected/observed counts per run in GOnOffBin ?
80
* - Do we want npred/eval/gradient methods as in GModel 
81
*   (working on GonOffBin instead of GEvent) ?
82
*
83
***************************************************************************/
84
class GOnOffFitterSpectrum : public GOnOffFitter {
85
        
86
public:
87
    // Constructors and destructors
88
    GOnOffFitterSpectrum(void);
89
    GOnOffFitterSpectrum(const GOnOffFitterSpectrum& onoff);
90
        explicit GOnOffFitterSpectrum(const std::string& filename, const GOnOffMaker& maker);
91
        explicit GOnOffFitterSpectrum(const GObservations& obs, const GOnOffMaker& maker);
92
        explicit GOnOffFitterSpectrum(const std::string& filename, const GOnOffMaker& maker, const GModelSpectral& spectral);
93
        explicit GOnOffFitterSpectrum(const GObservations& obs, const GOnOffMaker& maker, const GModelSpectral& spectral);
94
        explicit GOnOffFitterSpectrum(const std::string& filename, const GOnOffMaker& maker, const std::string& spec);
95
        explicit GOnOffFitterSpectrum(const GObservations& obs, const GOnOffMaker& maker, const std::string& spec);
96
    virtual ~GOnOffFitterSpectrum(void);
97
        
98
    // Operators
99
    virtual GOnOffFitterSpectrum&    operator=(const GOnOffFitterSpectrum& onoff);
100
        
101
    // Implemented pure virtual base class methods
102
    virtual void                     clear(void);
103
    virtual GOnOffFitterSpectrum*    clone(void) const;
104
    virtual int                      size(void) const;
105
        virtual std::string              type(void) const;
106
    virtual std::string              print(const GChatter& chatter = NORMAL) const;
107
        virtual void                     optimize(GOptimizer& opt);
108
        
109
        // Methods specific to the derived class
110
        void                             spectral(const GModelSpectral& spectral);
111
    void                             spectral(const std::string& filename);
112
    const GModelSpectral*            spectral(void) const;
113
        void                             sum_data(void);
114
        const std::vector<double>        significance(void) const;
115
        const std::vector<GEnergy>       true_energy(void) const;
116
        const std::vector<GEnergy>       true_variance(void) const;
117
    void                             convolve_spectrum(); 
118
        void                             compute_energy();
119
        void                             compute_significance();
120
        
121
protected:
122
    // Protected methods
123
    void init_members(void);
124
    void copy_members(const GOnOffFitterSpectrum& obs);
125
    void free_members(void);
126
        
127
    // Protected members
128
        GModelSpectral*              m_spectral;   //!< Spectral model
129
        std::vector<double>          m_expcts;     //!< Array of expected counts in all reconstructed energy bins (summed over all runs)
130
        std::vector<double>          m_obscts;     //!< Array of observed counts in all reconstructed energy bins (summed over all runs)        
131
    std::vector<GEnergy>         m_truemean;   //!< Array of average true energy for all reconstructed energy bins
132
    std::vector<GEnergy>         m_truevar;    //!< Array of true energy variance for all reconstructed energy bins
133
        std::vector<double>          m_sig;        //!< Array of significances of each flux point
134
        bool                         m_sum         //!< Flag to tell if analysis to be done on summed ON/OFF data
135
};
136

    
137
#endif /* GONOFFFITTERSPECTRUM_HPP */