GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GLATEfficiency.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GLATEfficiency.cpp - Fermi-LAT IRF efficiency factor functor *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2012-2018 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 GLATEfficiency.cpp
23  * @brief Fermi-LAT IRF efficiency factor functor class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GLATEfficiency.hpp"
32 #include "GTools.hpp"
33 
34 /* __ Method name definitions ____________________________________________ */
35 
36 /* __ Macros _____________________________________________________________ */
37 
38 /* __ Coding definitions _________________________________________________ */
39 
40 /* __ Debug definitions __________________________________________________ */
41 
42 /* __ Constants __________________________________________________________ */
43 
44 
45 /*==========================================================================
46  = =
47  = Constructors/destructors =
48  = =
49  ==========================================================================*/
50 
51 /***********************************************************************//**
52  * @brief Void constructor
53  ***************************************************************************/
55 {
56  // Initialise class members
57  init_members();
58 
59  // Return
60  return;
61 }
62 
63 
64 /***********************************************************************//**
65  * @brief Assignment constructor
66  *
67  * @param[in] pars Efficiency factor parameters.
68  ***************************************************************************/
69 GLATEfficiency::GLATEfficiency(const std::vector<double>& pars)
70 {
71  // Initialise class members
72  init_members();
73 
74  // Assign members
75  m_a0 = pars.at(0);
76  m_b0 = pars.at(1);
77  m_a1 = pars.at(2);
78  m_logEb1 = pars.at(3);
79  m_a2 = pars.at(4);
80  m_logEb2 = pars.at(5);
81 
82  // Precompute additional offsets
83  m_b1 = (m_a0 - m_a1)*m_logEb1 + m_b0;
84  m_b2 = (m_a1 - m_a2)*m_logEb2 + m_b1;
85 
86  // Return
87  return;
88 }
89 
90 
91 /***********************************************************************//**
92  * @brief Copy constructor
93  *
94  * @param[in] eff Efficiency factor functor.
95  ***************************************************************************/
97 {
98  // Initialise class members
99  init_members();
100 
101  // Copy members
102  copy_members(eff);
103 
104  // Return
105  return;
106 }
107 
108 
109 /***********************************************************************//**
110  * @brief Destructor
111  ***************************************************************************/
113 {
114  // Free members
115  free_members();
116 
117  // Return
118  return;
119 }
120 
121 
122 /*==========================================================================
123  = =
124  = Operators =
125  = =
126  ==========================================================================*/
127 
128 /***********************************************************************//**
129  * @brief Assignment operator
130  *
131  * @param[in] eff Efficiency factor functor.
132  * @return Efficiency factor functor.
133  ***************************************************************************/
135 {
136  // Execute only if object is not identical
137  if (this != &eff) {
138 
139  // Free members
140  free_members();
141 
142  // Initialise private members
143  init_members();
144 
145  // Copy members
146  copy_members(eff);
147 
148  } // endif: object was not identical
149 
150  // Return this object
151  return *this;
152 }
153 
154 
155 /***********************************************************************//**
156  * @brief Functor operator
157  *
158  * @param[in] logE log10 of energy (MeV).
159  ***************************************************************************/
160 double GLATEfficiency::operator() (const double& logE) const
161 {
162  // Initialise the result
163  double factor = 0;
164 
165  // Set efficiency factor depending on the energy domain
166  if (logE < m_logEb1) {
167  factor = m_a0*logE + m_b0;
168  }
169  else if (logE < m_logEb2) {
170  factor = m_a1*logE + m_b1;
171  }
172  else {
173  factor = m_a2*logE + m_b2;
174  }
175 
176  // Return factor
177  return factor;
178 }
179 
180 
181 /*==========================================================================
182  = =
183  = Public methods =
184  = =
185  ==========================================================================*/
186 
187 /***********************************************************************//**
188  * @brief Clear efficiency factor functor
189  *
190  * This method properly resets the object to an initial state.
191  ***************************************************************************/
193 {
194  // Free class members
195  free_members();
196 
197  // Initialise members
198  init_members();
199 
200  // Return
201  return;
202 }
203 
204 
205 /***********************************************************************//**
206  * @brief Clone efficiency factor functor
207  *
208  * @return Pointer to deep copy of efficiency factor functor.
209  ***************************************************************************/
211 {
212  return new GLATEfficiency(*this);
213 }
214 
215 
216 /***********************************************************************//**
217  * @brief Return efficiency parameters
218  *
219  * @return Vector of efficiency parameters.
220  *
221  * Returns a vector with 6 elements containing the efficiency parameters.
222  ***************************************************************************/
223 std::vector<double> GLATEfficiency::pars(void) const
224 {
225  // Initialise vector
226  std::vector<double> pars(6);
227 
228  // Set vector
229  pars[0] = m_a0;
230  pars[1] = m_b0;
231  pars[2] = m_a1;
232  pars[3] = m_logEb1;
233  pars[4] = m_a2;
234  pars[5] = m_logEb2;
235 
236  // Return vector
237  return pars;
238 }
239 
240 
241 /***********************************************************************//**
242  * @brief Print efficiency factors
243  *
244  * @param[in] chatter Chattiness.
245  * @return String containing efficiency factors information.
246  ***************************************************************************/
247 std::string GLATEfficiency::print(const GChatter& chatter) const
248 {
249  // Initialise result string
250  std::string result;
251 
252  // Continue only if chatter is not silent
253  if (chatter != SILENT) {
254 
255  // Append header
256  result.append("=== GLATEfficiency ===");
257 
258  // Append information
259  result.append("\n"+gammalib::parformat("Scale 1 (a0)")+gammalib::str(m_a0));
260  result.append("\n"+gammalib::parformat("Scale 2 (a1)")+gammalib::str(m_a1));
261  result.append("\n"+gammalib::parformat("Scale 3 (a2)")+gammalib::str(m_a2));
262  result.append("\n"+gammalib::parformat("Offset 1 (b0)")+gammalib::str(m_b0));
263  result.append("\n"+gammalib::parformat("Offset 2 (b1)")+gammalib::str(m_b1));
264  result.append("\n"+gammalib::parformat("Offset 3 (b2)")+gammalib::str(m_b2));
265  result.append("\n"+gammalib::parformat("Energy domains 1/2 limit (logEb1)")+gammalib::str(m_logEb1));
266  result.append("\n"+gammalib::parformat("Energy domains 2/3 limit (logEb2)")+gammalib::str(m_logEb2));
267 
268  } // endif: chatter was not silent
269 
270  // Return result
271  return result;
272 }
273 
274 
275 /*==========================================================================
276  = =
277  = Private methods =
278  = =
279  ==========================================================================*/
280 
281 /***********************************************************************//**
282  * @brief Initialise class members
283  ***************************************************************************/
285 {
286  // Initialise members
287  m_a0 = 0.0;
288  m_a1 = 0.0;
289  m_a2 = 0.0;
290  m_b0 = 0.0;
291  m_b1 = 0.0;
292  m_b2 = 0.0;
293  m_logEb1 = 0.0;
294  m_logEb2 = 0.0;
295 
296  // Return
297  return;
298 }
299 
300 
301 /***********************************************************************//**
302  * @brief Copy class members
303  *
304  * @param[in] eff Efficiency factor functor.
305  ***************************************************************************/
307 {
308  // Copy members
309  m_a0 = eff.m_a0;
310  m_a1 = eff.m_a1;
311  m_a2 = eff.m_a2;
312  m_b0 = eff.m_b0;
313  m_b1 = eff.m_b1;
314  m_b2 = eff.m_b2;
315  m_logEb1 = eff.m_logEb1;
316  m_logEb2 = eff.m_logEb2;
317 
318  // Return
319  return;
320 }
321 
322 
323 /***********************************************************************//**
324  * @brief Delete class members
325  ***************************************************************************/
327 {
328  // Return
329  return;
330 }
double m_logEb2
Separation of energy domains 2/3.
double m_a1
Energy domain 2 scale.
GLATEfficiency & operator=(const GLATEfficiency &eff)
Assignment operator.
virtual ~GLATEfficiency(void)
Destructor.
std::vector< double > pars(void) const
Return efficiency parameters.
Interface for the Fermi/LAT efficiency factor functor.
Gammalib tools definition.
GLATEfficiency(void)
Void constructor.
GLATEfficiency * clone(void) const
Clone efficiency factor functor.
Fermi/LAT IRF efficiency factor functor class definition.
double m_a2
Energy domain 3 scale.
void init_members(void)
Initialise class members.
double operator()(const double &logE) const
Functor operator.
std::string print(const GChatter &chatter=NORMAL) const
Print efficiency factors.
void copy_members(const GLATEfficiency &eff)
Copy class members.
GChatter
Definition: GTypemaps.hpp:33
double m_b2
Energy domain 3 offset.
void clear(void)
Clear efficiency factor functor.
double m_logEb1
Separation of energy domains 1/2.
double m_b0
Energy domain 1 offset.
double m_b1
Energy domain 2 offset.
double m_a0
Energy domain 1 scale.
void free_members(void)
Delete class members.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1143
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489