GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatialRadialShell.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpatialRadialShell.cpp - Radial shell source model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2011-2022 by Christoph Deil *
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 GModelSpatialRadialShell.cpp
23  * @brief Radial shell model class implementation
24  * @author Christoph Deil
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GException.hpp"
32 #include "GTools.hpp"
33 #include "GMath.hpp"
36 
37 /* __ Constants __________________________________________________________ */
38 
39 /* __ Globals ____________________________________________________________ */
41 const GModelSpatialRegistry g_radial_shell_registry(&g_radial_shell_seed);
42 #if defined(G_LEGACY_XML_FORMAT)
43 const GModelSpatialRadialShell g_radial_shell_legacy_seed(true, "ShellFunction");
44 const GModelSpatialRegistry g_radial_shell_legacy_registry(&g_radial_shell_legacy_seed);
45 #endif
46 
47 /* __ Method name definitions ____________________________________________ */
48 #define G_CONSTRUCTOR "GModelSpatialRadialShell::GModelSpatialRadialShell("\
49  "GSkyDir&, double&, double&, std::string&)"
50 #define G_MC "GModelSpatialRadialShell::mc(GEnergy&, GTime&, GRan&)"
51 #define G_READ "GModelSpatialRadialShell::read(GXmlElement&)"
52 #define G_WRITE "GModelSpatialRadialShell::write(GXmlElement&)"
53 
54 /* __ Macros _____________________________________________________________ */
55 
56 /* __ Coding definitions _________________________________________________ */
57 
58 /* __ Debug definitions __________________________________________________ */
59 //#define G_DEBUG_MC //!< Debug MC method
60 
61 
62 /*==========================================================================
63  = =
64  = Constructors/destructors =
65  = =
66  ==========================================================================*/
67 
68 /***********************************************************************//**
69  * @brief Void constructor
70  *
71  * Constructs empty radial shell model.
72  ***************************************************************************/
74 {
75  // Initialise members
76  init_members();
77 
78  // Return
79  return;
80 }
81 
82 
83 /***********************************************************************//**
84  * @brief Model type constructor
85  *
86  * @param[in] dummy Dummy flag.
87  * @param[in] type Model type.
88  *
89  * Constructs empty radial shell model by specifying a model @p type.
90  ***************************************************************************/
92  const std::string& type) :
94 {
95  // Initialise members
96  init_members();
97 
98  // Set model type
99  m_type = type;
100 
101  // Return
102  return;
103 }
104 
105 
106 /***********************************************************************//**
107  * @brief Shell constructor
108  *
109  * @param[in] dir Sky position of shell centre.
110  * @param[in] radius Inner shell radius (degrees).
111  * @param[in] width Shell width (degrees).
112  * @param[in] coordsys Coordinate system (either "CEL" or "GAL")
113  *
114  * @exception GException::invalid_argument
115  * Invalid @p coordsys argument specified.
116  *
117  * Constructs the shell model from the shell centre (@p dir), the inner
118  * shell @p radius, and the shell @p width. The @p coordsys parameter
119  * specifies whether the sky direction should be interpreted in the celestial
120  * or Galactic coordinate system.
121  ***************************************************************************/
123  const double& radius,
124  const double& width,
125  const std::string& coordsys) :
127 {
128  // Throw an exception if the coordinate system is invalid
129  if ((coordsys != "CEL") && (coordsys != "GAL")) {
130  std::string msg = "Invalid coordinate system \""+coordsys+"\" "
131  "specified. Please specify either \"CEL\" or "
132  "\"GAL\".";
134  }
135 
136  // Initialise members
137  init_members();
138 
139  // Set parameter names
140  if (coordsys == "CEL") {
141  m_lon.name("RA");
142  m_lat.name("DEC");
143  }
144  else {
145  m_lon.name("GLON");
146  m_lat.name("GLAT");
147  }
148 
149  // Assign parameters
150  this->dir(dir);
151  this->radius(radius);
152  this->width(width);
153 
154  // Return
155  return;
156 }
157 
158 
159 /***********************************************************************//**
160  * @brief XML constructor
161  *
162  * @param[in] xml XML element.
163  *
164  * Constructs shell spatial model by extracting information from an XML
165  * element. See the read() method for more information about the expected
166  * structure of the XML element.
167  ***************************************************************************/
170 {
171  // Initialise members
172  init_members();
173 
174  // Read information from XML element
175  read(xml);
176 
177  // Return
178  return;
179 }
180 
181 
182 /***********************************************************************//**
183  * @brief Copy constructor
184  *
185  * @param[in] model Radial shell source model.
186  ***************************************************************************/
188  GModelSpatialRadial(model)
189 {
190  // Initialise members
191  init_members();
192 
193  // Copy members
194  copy_members(model);
195 
196  // Return
197  return;
198 }
199 
200 
201 /***********************************************************************//**
202  * @brief Destructor
203  ***************************************************************************/
205 {
206  // Free members
207  free_members();
208 
209  // Return
210  return;
211 }
212 
213 
214 /*==========================================================================
215  = =
216  = Operators =
217  = =
218  ==========================================================================*/
219 
220 /***********************************************************************//**
221  * @brief Assignment operator
222  *
223  * @param[in] model Radial shell source model.
224  * @return Radial shell source model.
225  ***************************************************************************/
227 {
228  // Execute only if object is not identical
229  if (this != &model) {
230 
231  // Copy base class members
232  this->GModelSpatialRadial::operator=(model);
233 
234  // Free members
235  free_members();
236 
237  // Initialise members
238  init_members();
239 
240  // Copy members
241  copy_members(model);
242 
243  } // endif: object was not identical
244 
245  // Return
246  return *this;
247 }
248 
249 
250 /*==========================================================================
251  = =
252  = Public methods =
253  = =
254  ==========================================================================*/
255 
256 /***********************************************************************//**
257  * @brief Clear radial shell model
258  ***************************************************************************/
260 {
261  // Free class members (base and derived classes, derived class first)
262  free_members();
265 
266  // Initialise members
269  init_members();
270 
271  // Return
272  return;
273 }
274 
275 
276 /***********************************************************************//**
277  * @brief Clone radial shell model
278  *
279  * @return Pointer to deep copy of radial shell model.
280  ***************************************************************************/
282 {
283  // Clone radial shell model
284  return new GModelSpatialRadialShell(*this);
285 }
286 
287 
288 /***********************************************************************//**
289  * @brief Evaluate function (in units of sr^-1)
290  *
291  * @param[in] theta Angular distance from shell centre (radians).
292  * @param[in] energy Photon energy.
293  * @param[in] time Photon arrival time.
294  * @param[in] gradients Compute gradients?
295  * @return Model value.
296  *
297  * Evaluates the spatial part for a shell source model. The shell source
298  * model is a radial function \f$f(\theta)\f$, where \f$\theta\f$ is the
299  * angular separation between shell centre and the actual location.
300  *
301  * The function is given by
302  * \f[
303  * S_{\rm p}(\vec{p} | E, t) = {\tt m\_norm} \left \{
304  * \begin{array}{l l}
305  * \displaystyle
306  * \sqrt{ \sin^2 \theta_{\rm out} - \sin^2 \theta } -
307  * \sqrt{ \sin^2 \theta_{\rm in} - \sin^2 \theta }
308  * & \mbox{if $\theta \le \theta_{\rm in}$} \\
309  * \\
310  * \displaystyle
311  * \sqrt{ \sin^2 \theta_{\rm out} - \sin^2 \theta }
312  * & \mbox{if $\theta_{\rm in} < \theta \le \theta_{\rm out}$} \\
313  * \\
314  * \displaystyle
315  * 0 & \mbox{if $\theta > \theta_{\rm out}$}
316  * \end{array}
317  * \right .
318  * \f]
319  *
320  * Here, \f$\theta_{\rm in}\f$ and \f$\theta_{\rm out}\f$ are the shell inner
321  * and outer radius.
322  *
323  * The method will not compute analytical parameter gradients, even if the
324  * @p gradients argument is set to true. Radial disk parameter gradients
325  * need to be computed numerically.
326  ***************************************************************************/
327 double GModelSpatialRadialShell::eval(const double& theta,
328  const GEnergy& energy,
329  const GTime& time,
330  const bool& gradients) const
331 {
332  // Update precomputation cache
333  update();
334 
335  // Set x appropriately
336  double x = std::sin(theta);
337  x *= x;
338 
339  // Compute result
340  double result = 0.0;
341  if (x < m_x_out) {
342  result = std::sqrt(m_x_out - x);
343  if (x < m_x_in) {
344  result -= std::sqrt(m_x_in - x);
345  }
346  result *= m_norm;
347  }
348 
349  // Compile option: Check for NaN/Inf
350  #if defined(G_NAN_CHECK)
351  if (gammalib::is_notanumber(result) || gammalib::is_infinite(result)) {
352  std::cout << "*** ERROR: GModelSpatialRadialShell::eval";
353  std::cout << "(theta=" << theta << "): NaN/Inf encountered";
354  std::cout << " (result=" << result;
355  std::cout << ", m_norm=" << m_norm;
356  std::cout << ", x=" << x;
357  std::cout << ", m_x_out=" << m_x_out;
358  std::cout << ", m_x_in=" << m_x_in;
359  std::cout << ")" << std::endl;
360  }
361  #endif
362 
363  // Return normalised value
364  return result;
365 }
366 
367 
368 /***********************************************************************//**
369  * @brief Returns MC sky direction
370  *
371  * @param[in] energy Photon energy.
372  * @param[in] time Photon arrival time.
373  * @param[in,out] ran Random number generator.
374  * @return Sky direction.
375  *
376  * @exception GException::invalid_return_value
377  * Invalid u_max value
378  *
379  * Draws an arbitrary sky position from the 2D shell distribution.
380  ***************************************************************************/
382  const GTime& time,
383  GRan& ran) const
384 {
385  // Update precomputation cache
386  update();
387 
388  // Initialise simulation
389  #if defined(G_DEBUG_MC)
390  int n_samples = 0;
391  #endif
392  double u_max = m_norm * m_x_out;
393  double value = 0.0;
394  double u = 1.0;
395  double theta = 0.0;
396 
397  // Throw an exception if the maximum value is zero
398  if (u_max <= 0.0) {
399  std::string msg = "Non positive maximum radial shell model value.";
401  }
402 
403  // Simulate offset from photon arrival direction using a rejection method
404  do {
405  theta = ran.uniform() * m_theta_out;
406  value = eval(theta, energy, time) * std::sin(theta);
407  u = ran.uniform() * u_max;
408  #if defined(G_DEBUG_MC)
409  n_samples++;
410  #endif
411  } while (u > value);
412  #if defined(G_DEBUG_MC)
413  std::cout << "#=" << n_samples << " ";
414  #endif
415 
416  // Simulate azimuth angle
417  double phi = 360.0 * ran.uniform();
418 
419  // Rotate pointing direction by offset and azimuth angle
420  GSkyDir sky_dir = dir();
421  sky_dir.rotate_deg(phi, theta * gammalib::rad2deg);
422 
423  // Return sky direction
424  return sky_dir;
425 }
426 
427 
428 /***********************************************************************//**
429  * @brief Checks where model contains specified sky direction
430  *
431  * @param[in] dir Sky direction.
432  * @param[in] margin Margin to be added to sky direction (degrees)
433  * @return True if the model contains the sky direction.
434  *
435  * Signals whether a sky direction is contained in the radial shell model.
436  ***************************************************************************/
438  const double& margin) const
439 {
440  // Compute distance to centre (radians)
441  double distance = dir.dist(this->dir());
442 
443  // Return flag
444  return (distance <= theta_max() + margin*gammalib::deg2rad);
445 }
446 
447 
448 /***********************************************************************//**
449  * @brief Return maximum model radius (in radians)
450  *
451  * @return Maximum model radius (in radians).
452  ***************************************************************************/
454 {
455  // Return value
456  return ((radius()+width()) * gammalib::deg2rad);
457 }
458 
459 
460 /***********************************************************************//**
461  * @brief Read model from XML element
462  *
463  * @param[in] xml XML element.
464  *
465  * Reads the radial shell model information from an XML element. The XML
466  * element shall have either the format
467  *
468  * <spatialModel type="RadialShell">
469  * <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="1"/>
470  * <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="1"/>
471  * <parameter name="Radius" scale="1.0" value="0.30" min="0.01" max="10" free="1"/>
472  * <parameter name="Width" scale="1.0" value="0.10" min="0.01" max="10" free="1"/>
473  * </spatialModel>
474  *
475  * or
476  *
477  * <spatialModel type="RadialShell">
478  * <parameter name="GLON" scale="1.0" value="83.6331" min="-360" max="360" free="1"/>
479  * <parameter name="GLAT" scale="1.0" value="22.0145" min="-90" max="90" free="1"/>
480  * <parameter name="Radius" scale="1.0" value="0.30" min="0.01" max="10" free="1"/>
481  * <parameter name="Width" scale="1.0" value="0.10" min="0.01" max="10" free="1"/>
482  * </spatialModel>
483  *
484  * @todo Implement tests of the radius and radius boundary and the width and
485  * width boundary. The radius and radius boundary should be >=0, the
486  * width and width boundary should be >0.
487  ***************************************************************************/
489 {
490  // Verify number of model parameters
492 
493  // Read shell location
495 
496  // Get parameters
499 
500  // Read parameters
501  m_radius.read(*radius);
502  m_width.read(*width);
503 
504  // Return
505  return;
506 }
507 
508 
509 /***********************************************************************//**
510  * @brief Write model into XML element
511  *
512  * @param[in] xml XML element into which model information is written.
513  *
514  * Writes the radial shell model information into an XML element. The XML
515  * element will have the format
516  *
517  * <spatialModel type="RadialShell">
518  * <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="1"/>
519  * <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="1"/>
520  * <parameter name="Radius" scale="1.0" value="0.30" min="0.01" max="10" free="1"/>
521  * <parameter name="Width" scale="1.0" value="0.10" min="0.01" max="10" free="1"/>
522  * </spatialModel>
523  *
524  ***************************************************************************/
526 {
527  // Verify model type
529 
530  // Write shell location
532 
533  // Get or create parameters
536 
537  // Write parameters
538  m_radius.write(*radius);
539  m_width.write(*width);
540 
541  // Return
542  return;
543 }
544 
545 
546 /***********************************************************************//**
547  * @brief Print information
548  *
549  * @param[in] chatter Chattiness.
550  * @return String containing model information.
551  ***************************************************************************/
552 std::string GModelSpatialRadialShell::print(const GChatter& chatter) const
553 {
554  // Initialise result string
555  std::string result;
556 
557  // Continue only if chatter is not silent
558  if (chatter != SILENT) {
559 
560  // Append header
561  result.append("=== GModelSpatialRadialShell ===");
562 
563  // Append parameters
564  result.append("\n"+gammalib::parformat("Number of parameters"));
565  result.append(gammalib::str(size()));
566  for (int i = 0; i < size(); ++i) {
567  result.append("\n"+m_pars[i]->print(chatter));
568  }
569 
570  } // endif: chatter was not silent
571 
572  // Return result
573  return result;
574 }
575 
576 
577 /*==========================================================================
578  = =
579  = Private methods =
580  = =
581  ==========================================================================*/
582 
583 /***********************************************************************//**
584  * @brief Initialise class members
585  ***************************************************************************/
587 {
588  // Initialise model type
589  m_type = "RadialShell";
590 
591  // Initialise Radius
592  m_radius.clear();
593  m_radius.name("Radius");
594  m_radius.unit("deg");
595  m_radius.value(0.0);
596  m_radius.min(0.0);
597  m_radius.free();
598  m_radius.scale(1.0);
599  m_radius.gradient(0.0);
600  m_radius.has_grad(false); // Radial components never have gradients
601 
602  // Initialise Width
603  m_width.clear();
604  m_width.name("Width");
605  m_width.unit("deg");
606  m_width.value(2.778e-4);
607  m_width.min(2.778e-4); // 1 arcsec
608  m_width.free();
609  m_width.scale(1.0);
610  m_width.gradient(0.0);
611  m_width.has_grad(false); // Radial components never have gradients
612 
613  // Set parameter pointer(s)
614  m_pars.push_back(&m_radius);
615  m_pars.push_back(&m_width);
616 
617  // Initialise precomputation cache. Note that zero values flag
618  // uninitialised as a zero radius and width shell is not meaningful
619  m_last_radius = 0.0;
620  m_last_width = 0.0;
621  m_theta_in = 0.0;
622  m_x_in = 0.0;
623  m_theta_out = 0.0;
624  m_x_out = 0.0;
625  m_norm = 0.0;
626 
627  // Return
628  return;
629 }
630 
631 
632 /***********************************************************************//**
633  * @brief Copy class members
634  *
635  * @param[in] model Radial shell source model.
636  *
637  * We do not have to push back the members on the parameter stack as this
638  * should have been done by init_members() that was called before. Otherwise
639  * we would have the radius and width twice on the stack.
640  ***************************************************************************/
642 {
643  // Copy members
644  m_type = model.m_type; // Needed to conserve model type
645  m_radius = model.m_radius;
646  m_width = model.m_width;
647 
648  // Copy precomputation cache
650  m_last_width = model.m_last_width;
651  m_theta_in = model.m_theta_in;
652  m_x_in = model.m_x_in;
653  m_theta_out = model.m_theta_out;
654  m_x_out = model.m_x_out;
655  m_norm = model.m_norm;
656 
657  // Return
658  return;
659 }
660 
661 
662 /***********************************************************************//**
663  * @brief Delete class members
664  ***************************************************************************/
666 {
667  // Return
668  return;
669 }
670 
671 
672 /***********************************************************************//**
673  * @brief Update precomputation cache
674  *
675  * Performs precomputations that are valid for a given pair of radius and
676  * width values. The following members are set by this method:
677  * m_last_radius, m_last_width, m_theta_in, m_theta_out, m_x_in, m_x_out
678  * and m_norm.
679  *
680  * m_theta_in contains the inner shell radius in radians, while m_theta_out
681  * contains the outer shell radius in radians.
682  *
683  * \f${\tt m\_x\_in} = \sin^2 {\tt m\_theta\_in}\f$,
684  * \f${\tt m\_x\_out} = \sin^2 {\tt m\_theta\_out}\f$, and
685  * \f[{\tt m\_norm} = \frac{1}{2 \pi}
686  * \frac{\sqrt{1-\cos 2 {\tt m\_theta\_out}} -
687  * \sqrt{1-\cos 2 {\tt m\_theta\_in}}}{2 \sqrt{2}} +
688  * \frac{1+\cos 2 {\tt m\_theta\_out}}{4} \ln \left(
689  * \frac{\sqrt{2} \cos {\tt m\_theta\_out}}
690  * {\sqrt{2} + \sqrt{1 - \cos 2 {\tt m\_theta\_out}}} \right) -
691  * \frac{1+\cos 2 {\tt m\_theta\_in}}{4} \ln \left(
692  * \frac{\sqrt{2} \cos {\tt m\_theta\_in}}
693  * {\sqrt{2} + \sqrt{1 - \cos 2 {\tt m\_theta\_in}}} \right)\f]
694  ***************************************************************************/
696 {
697  // Set constants
698  //const double c1 = gammalib::twopi / 3.0;
699  const double c2 = 1.0 / (2.0 * gammalib::sqrt_two);
700 
701  // Update if radius or width have changed
702  if (m_last_radius != radius() || m_last_width != width()) {
703 
704  // Store last values
705  m_last_radius = radius();
706  m_last_width = width();
707 
708  // Perform precomputations
711  double sin_theta_in = std::sin(m_theta_in);
712  double sin_theta_out = std::sin(m_theta_out);
713  double term1 = (f1(m_theta_out) - f1(m_theta_in)) * c2;
714  double term2 = f2(m_theta_out);
715  double term3 = f2(m_theta_in);
716  double denom = gammalib::twopi * (term1 + term2 - term3);
717  m_norm = (denom > 0.0) ? 1.0 / denom : 0.0;
718  m_x_in = sin_theta_in * sin_theta_in;
719  m_x_out = sin_theta_out * sin_theta_out;
720 
721  } // endif: update required
722 
723  // Compile option: Check for NaN/Inf
724  #if defined(G_NAN_CHECK)
726  std::cout << "*** ERROR: GModelSpatialRadialShell::update:";
727  std::cout << " NaN/Inf encountered";
728  std::cout << " (m_norm=" << m_norm;
729  std::cout << ", radius=" << radius();
730  std::cout << ", width=" << width();
731  std::cout << ", m_theta_in=" << m_theta_in;
732  std::cout << ", m_theta_out=" << m_theta_out;
733  std::cout << ", term1=" << (f1(m_theta_out) - f1(m_theta_in)) * c2;
734  std::cout << ", term2=" << f2(m_theta_out);
735  std::cout << ", term3=" << f2(m_theta_in);
736  std::cout << ")" << std::endl;
737  }
738  #endif
739 
740  // Return
741  return;
742 }
743 
744 
745 /***********************************************************************//**
746  * @brief Return function 1 value needed for precomputation
747  *
748  * Computes \f$f1(x) = \sqrt{1 - \cos 2 x}\f$.
749  ***************************************************************************/
751 {
752  // Compute value
753  double f1 = std::sqrt(1.0 - std::cos(2.0 * x));
754 
755  // Return value
756  return f1;
757 }
758 
759 
760 /***********************************************************************//**
761  * @brief Return function 2 value needed for precomputation
762  *
763  * Compute
764  * \f[f2(x) = \frac{1+\cos 2x}{4}
765  * \ln \left( \frac{\sqrt{2} \cos x}{\sqrt{2} + \sqrt{ 1 - \cos 2 x}}
766  * \right)\f].
767  ***************************************************************************/
769 {
770  // Compute value
771  double t1 = (1.0 + std::cos(2.0*x)) / 4.0;
772  double t2 = gammalib::sqrt_two * std::cos(x);
773  double t3 = gammalib::sqrt_two + f1(x);
774  double f2 = t1 * std::log(t2 / t3);
775 
776  // Return value
777  return f2;
778 }
779 
780 
781 /***********************************************************************//**
782  * @brief Set boundary sky region
783  ***************************************************************************/
785 {
786  // Set sky region circle (maximum Gaussian sigma times a scaling
787  // factor (actually 3))
789 
790  // Set region (circumvent const correctness)
791  const_cast<GModelSpatialRadialShell*>(this)->m_region = region;
792 
793  // Return
794  return;
795 }
double width(void) const
Return shell width.
GModelPar m_width
Shell thickness (deg)
virtual GModelSpatialRadialShell & operator=(const GModelSpatialRadialShell &model)
Assignment operator.
Radial shell model class interface definition.
const std::string & name(void) const
Return parameter name.
double gradient(void) const
Return parameter gradient.
int size(void) const
Return number of parameters.
double m_last_width
Last shell width (deg)
void init_members(void)
Initialise class members.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
Definition: GModelPar.cpp:351
GVector cos(const GVector &vector)
Computes cosine of vector elements.
Definition: GVector.cpp:1190
const GModelSpatialRadialShell g_radial_shell_seed
XML element node class.
Definition: GXmlElement.hpp:48
virtual void set_region(void) const
Set boundary sky region.
virtual void read(const GXmlElement &xml)
Read model from XML element.
Random number generator class.
Definition: GRan.hpp:44
#define G_MC
Time class.
Definition: GTime.hpp:55
Gammalib tools definition.
Interface for the circular sky region class.
#define G_READ
const double sqrt_two
Definition: GMath.hpp:54
Interface definition for the spatial model registry class.
double min(void) const
Return parameter minimum boundary.
void init_members(void)
Initialise class members.
static double f2(double x)
Return function 2 value needed for precomputation.
GSkyRegionCircle m_region
Bounding circle.
bool is_notanumber(const double &x)
Signal if argument is not a number.
Definition: GTools.hpp:201
double m_x_in
sin(m_theta_in)^2
const double & scale(void) const
Return parameter scale.
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition: GTools.hpp:184
double radius(void) const
Return shell radius.
const double deg2rad
Definition: GMath.hpp:43
void free_members(void)
Delete class members.
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
Definition: GVector.cpp:1358
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
void copy_members(const GModelSpatialRadialShell &model)
Copy class members.
void update(void) const
Update precomputation cache.
const GSkyDir & dir(void) const
Return position of radial spatial model.
void free_members(void)
Delete class members.
void free(void)
Free a parameter.
std::vector< GModelPar * > m_pars
Parameter pointers.
void rotate_deg(const double &phi, const double &theta)
Rotate sky direction by zenith and azimuth angle.
Definition: GSkyDir.cpp:424
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
Definition: GTools.cpp:1637
virtual void read(const GXmlElement &xml)
Read model from XML element.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
Definition: GVector.cpp:1274
double uniform(void)
Returns random double precision floating value in range 0 to 1.
Definition: GRan.cpp:242
void clear(void)
Clear parameter.
virtual double theta_max(void) const
Return maximum model radius (in radians)
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual ~GModelSpatialRadialShell(void)
Destructor.
Spatial model registry class definition.
virtual GModelSpatialRadialShell * clone(void) const
Clone radial shell model.
GChatter
Definition: GTypemaps.hpp:33
double m_last_radius
Last shell radius (deg)
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Checks where model contains specified sky direction.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
std::string type(void) const
Return model type.
GModelPar m_radius
Inner shell radius (deg)
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
Definition: GTools.cpp:1777
#define G_WRITE
virtual void write(GXmlElement &xml) const
Write model into XML element.
GModelSpatialRadialShell(void)
Void constructor.
virtual void clear(void)
Clear radial shell model.
double m_theta_in
Inner shell radius (rad)
const GSkyRegion * region(void) const
Return boundary sky region.
virtual GModelSpatialRadial & operator=(const GModelSpatialRadial &model)
Assignment operator.
void free_members(void)
Delete class members.
std::string m_type
Spatial model type.
GModelPar m_lat
Declination or Galactic latitude (deg)
virtual double eval(const double &theta, const GEnergy &energy, const GTime &time, const bool &gradients=false) const
Evaluate function (in units of sr^-1)
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
Definition: GModelPar.cpp:229
double value(void) const
Return parameter value.
GModelPar m_lon
Right Ascension or Galactic longitude (deg)
const std::string & unit(void) const
Return parameter unit.
double m_theta_out
Outer shell radius (rad)
GVector sin(const GVector &vector)
Computes sine of vector elements.
Definition: GVector.cpp:1316
Exception handler interface definition.
double dist(const GSkyDir &dir) const
Compute angular distance between sky directions in radians.
Definition: GSkyDir.hpp:271
#define G_CONSTRUCTOR
static double f1(double x)
Return function 1 value needed for precomputation.
Abstract radial spatial model base class.
void init_members(void)
Initialise class members.
const double twopi
Definition: GMath.hpp:36
double m_norm
Shell normalization.
const double rad2deg
Definition: GMath.hpp:44
double m_x_out
sin(m_theta_out)^2
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1143
Sky direction class.
Definition: GSkyDir.hpp:62
const GXmlElement * xml_get_par(const std::string &origin, const GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
Definition: GTools.cpp:1689
Mathematical function definitions.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual std::string print(const GChatter &chatter=NORMAL) const
Print information.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.
Definition: GTools.cpp:1819