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