GammaLib 2.0.0
Loading...
Searching...
No Matches
GLATPsfBase.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GLATPsfBase.cpp - Abstract Fermi LAT point spread function base class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2012-2021 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 GLATPsfBase.cpp
23 * @brief Abstract Fermi LAT point spread function base class implementation
24 * @author Juergen Knoedlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include "GTools.hpp"
32#include "GFitsBinTable.hpp"
34#include "GLATPsfBase.hpp"
35
36/* __ Method name definitions ____________________________________________ */
37#define G_READ_SCALE "GLATPsfBase::read_scale(GFitsTable&)"
38
39/* __ Macros _____________________________________________________________ */
40
41/* __ Coding definitions _________________________________________________ */
42
43/* __ Debug definitions __________________________________________________ */
44
45/* __ Constants __________________________________________________________ */
46
47
48/*==========================================================================
49 = =
50 = Constructors/destructors =
51 = =
52 ==========================================================================*/
53
54/***********************************************************************//**
55 * @brief Void constructor
56 ***************************************************************************/
58{
59 // Initialise class members
61
62 // Return
63 return;
64}
65
66
67/***********************************************************************//**
68 * @brief Copy constructor
69 *
70 * @param[in] psf Point spread function.
71 ***************************************************************************/
73{
74 // Initialise class members
76
77 // Copy members
79
80 // Return
81 return;
82}
83
84
85/***********************************************************************//**
86 * @brief Destructor
87 ***************************************************************************/
89{
90 // Free members
92
93 // Return
94 return;
95}
96
97
98/*==========================================================================
99 = =
100 = Operators =
101 = =
102 ==========================================================================*/
103
104/***********************************************************************//**
105 * @brief Assignment operator
106 *
107 * @param[in] psf Point spread function.
108 * @return Point spread function.
109 ***************************************************************************/
111{
112 // Execute only if object is not identical
113 if (this != &psf) {
114
115 // Free members
116 free_members();
117
118 // Initialise private members
119 init_members();
120
121 // Copy members
123
124 } // endif: object was not identical
125
126 // Return this object
127 return *this;
128}
129
130
131/*==========================================================================
132 = =
133 = Public methods =
134 = =
135 ==========================================================================*/
136
137
138/*==========================================================================
139 = =
140 = Private methods =
141 = =
142 ==========================================================================*/
143
144/***********************************************************************//**
145 * @brief Initialise class members
146 ***************************************************************************/
148{
149 // Initialise members
150 m_front = true;
152 m_scale_par1 = 0.0;
153 m_scale_par2 = 0.0;
154 m_scale_index = 0.0;
155 m_min_ctheta = 0.0;
156
157 // Return
158 return;
159}
160
161
162/***********************************************************************//**
163 * @brief Copy class members
164 *
165 * @param[in] psf Point spread function.
166 ***************************************************************************/
168{
169 // Copy members
170 m_front = psf.m_front;
171 m_rpsf_bins = psf.m_rpsf_bins;
172 m_scale_par1 = psf.m_scale_par1;
173 m_scale_par2 = psf.m_scale_par2;
174 m_scale_index = psf.m_scale_index;
175 m_min_ctheta = psf.m_min_ctheta;
176
177 // Return
178 return;
179}
180
181
182/***********************************************************************//**
183 * @brief Delete class members
184 ***************************************************************************/
186{
187 // Return
188 return;
189}
190
191
192/***********************************************************************//**
193 * @brief Read PSF scale factors from FITS table
194 *
195 * @param[in] table FITS table.
196 *
197 * Reads the PSF scale factors from column "PSFSCALE" of a FITS table.
198 ***************************************************************************/
200{
201 // Get pointer to column
202 const GFitsTableCol* scale = table["PSFSCALE"];
203
204 // If we have 3 colums in the table we have a Pass 8 response and hence
205 // the table only applies to the specific event type. The first two table
206 // elements are the scales, the third element is the index.
207 if (scale->number() == 3) {
208 m_scale_par1 = scale->real(0,0);
209 m_scale_par2 = scale->real(0,1);
210 m_scale_index = scale->real(0,2);
211 }
212
213 // ... otherwise we have an earlier response, and the front scales
214 // are stored in the first 2 elements while the back scales are
215 // stored in the second 2 elements, and the index is in the fifth
216 // element
217 else {
218 if (front()) {
219 m_scale_par1 = scale->real(0,0);
220 m_scale_par2 = scale->real(0,1);
221 }
222 else {
223 m_scale_par1 = scale->real(0,2);
224 m_scale_par2 = scale->real(0,3);
225 }
226 m_scale_index = scale->real(0,4);
227 }
228
229 // Return
230 return;
231}
232
233
234/***********************************************************************//**
235 * @brief Write PSF scale factors
236 *
237 * @param[in] file FITS file.
238 *
239 * Writes the PSF scale factors in the extension "PSF_SCALING_PARAMS". This
240 * method appends an extension "PSF_SCALING_PARAMS" to the FITS file,
241 * irrespectively of whether the extension exists already or not.
242 * The scale facors are written into the column "PSFSCALE".
243 *
244 * @todo Check if PSF_SCALING_PARAMS exists already in FITS file
245 ***************************************************************************/
247{
248 // Create new binary table
249 GFitsBinTable* hdu_scale = new GFitsBinTable;
250
251 // Set table attributes
252 hdu_scale->extname("PSF_SCALING_PARAMS");
253
254 // Allocate floating point vector column
255 GFitsTableFloatCol col_scale = GFitsTableFloatCol("PSFSCALE", 1, 5);
256
257 // Fill columns
258 if (front()) {
259 col_scale(0,0) = m_scale_par1;
260 col_scale(0,1) = m_scale_par2;
261 col_scale(0,2) = 0.0;
262 col_scale(0,3) = 0.0;
263 }
264 else {
265 col_scale(0,0) = 0.0;
266 col_scale(0,1) = 0.0;
267 col_scale(0,2) = m_scale_par1;
268 col_scale(0,3) = m_scale_par2;
269 }
270 col_scale(0,4) = m_scale_index;
271
272 // Append column to table
273 hdu_scale->append(col_scale);
274
275 // Append HDU to FITS file
276 file.append(*hdu_scale);
277
278 // Free binary table
279 delete hdu_scale;
280
281 // Return
282 return;
283}
284
285
286/***********************************************************************//**
287 * @brief Return scale factor for energy (in MeV)
288 *
289 * @param[in] energy Photon energy (in MeV).
290 ***************************************************************************/
291double GLATPsfBase::scale_factor(const double& energy) const
292{
293 // Compute scale factor
294 double f1 = m_scale_par1 * std::pow(0.01*energy, m_scale_index);
295 double scale = std::sqrt(f1*f1 + m_scale_par2*m_scale_par2);
296
297 // Return scale factor
298 return scale;
299}
FITS binary table class definition.
FITS table float column class interface definition.
Abstract Fermi/LAT point spread function base class definition.
Gammalib tools definition.
FITS binary table class.
const std::string & extname(void) const
Return extension name.
Definition GFitsHDU.hpp:162
Abstract interface for FITS table column.
void number(const int &number)
Set number of elements in column.
virtual double real(const int &row, const int &inx=0) const =0
FITS table float column.
Abstract interface for FITS table.
GFitsTableCol * append(const GFitsTableCol &column)
Append column to the table.
FITS file class.
Definition GFits.hpp:63
GFitsHDU * append(const GFitsHDU &hdu)
Append HDU to FITS file.
Definition GFits.cpp:678
Abstract Fermi/LAT point spread function base class.
GLATPsfBase(void)
Void constructor.
double m_scale_par2
PSF scaling parameter 2.
void write_scale(GFits &file) const
Write PSF scale factors.
GLATResponseTable m_rpsf_bins
PSF energy and cos theta binning.
void free_members(void)
Delete class members.
virtual double psf(const double &offset, const double &logE, const double &ctheta)=0
bool m_front
PSF is for front section?
void init_members(void)
Initialise class members.
const bool & front(void) const
Signal that point spread function is for front section.
double m_scale_par1
PSF scaling parameter 1.
virtual ~GLATPsfBase(void)
Destructor.
double m_scale_index
PSF scaling index.
void read_scale(const GFitsTable &hdu)
Read PSF scale factors from FITS table.
GLATPsfBase & operator=(const GLATPsfBase &psf)
Assignment operator.
double m_min_ctheta
Minimum valid cos(theta)
void copy_members(const GLATPsfBase &psf)
Copy class members.
double scale_factor(const double &energy) const
Return scale factor for energy (in MeV)
void clear(void)
Clear instance.