GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GModelSpectralLogParabola.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpectralLogParabola.cpp - Log parabola spectral model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2012-2021 by Michael Mayer *
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 GModelSpectralLogParabola.cpp
23 * @brief Log parabola spectral model class definition
24 * @author Michael Mayer
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include <cmath>
32#include "GException.hpp"
33#include "GTools.hpp"
34#include "GRan.hpp"
35#include "GIntegral.hpp"
38
39/* __ Constants __________________________________________________________ */
40
41/* __ Globals ____________________________________________________________ */
43 "Prefactor",
44 "Index",
45 "PivotEnergy",
46 "Curvature");
47const GModelSpectralRegistry g_spectral_logp_registry1(&g_spectral_logp_seed1);
48#if defined(G_LEGACY_XML_FORMAT)
49const GModelSpectralLogParabola g_spectral_logp_seed2("LogParabola",
50 "norm",
51 "alpha",
52 "Eb",
53 "beta");
54const GModelSpectralLogParabola g_spectral_logp_seed3("LogParabola",
55 "Prefactor",
56 "Index",
57 "Scale",
58 "Curvature");
59const GModelSpectralRegistry g_spectral_logp_registry2(&g_spectral_logp_seed2);
60const GModelSpectralRegistry g_spectral_logp_registry3(&g_spectral_logp_seed3);
61#endif
62
63/* __ Method name definitions ____________________________________________ */
64#define G_FLUX "GModelSpectralLogParabola::flux(GEnergy&, GEnergy&)"
65#define G_EFLUX "GModelSpectralLogParabola::eflux(GEnergy&, GEnergy&)"
66#define G_MC "GModelSpectralLogParabola::mc(GEnergy&, GEnergy&, GTime&,"\
67 " GRan&)"
68#define G_READ "GModelSpectralLogParabola::read(GXmlElement&)"
69#define G_WRITE "GModelSpectralLogParabola::write(GXmlElement&)"
70
71/* __ Macros _____________________________________________________________ */
72
73/* __ Coding definitions _________________________________________________ */
74
75/* __ Debug definitions __________________________________________________ */
76
77
78/*==========================================================================
79 = =
80 = Constructors/destructors =
81 = =
82 ==========================================================================*/
83
84/***********************************************************************//**
85 * @brief Void constructor
86 ***************************************************************************/
88{
89 // Initialise private members
91
92 // Return
93 return;
94}
95
96
97/***********************************************************************//**
98 * @brief Model type and parameter name constructor
99 *
100 * @param[in] type Model type.
101 * @param[in] prefactor Name of prefactor parameter.
102 * @param[in] index Name of index parameter.
103 * @param[in] pivot Name of pivot parameter.
104 * @param[in] curvature Name of curvature parameter.
105 ***************************************************************************/
107 const std::string& prefactor,
108 const std::string& index,
109 const std::string& pivot,
110 const std::string& curvature) :
112{
113 // Initialise members
114 init_members();
115
116 // Set model type
117 m_type = type;
118
119 // Set parameter names
124
125 // Return
126 return;
127}
128
129
130/***********************************************************************//**
131 * @brief Constructor
132 *
133 * @param[in] prefactor Power law pre factor.
134 * @param[in] index Power law index.
135 * @param[in] pivot Pivot energy.
136 * @param[in] curvature Curvature.
137 *
138 * Construct a LogParabola model from
139 * - a pre factor (in ph/cm2/s/MeV),
140 * - a spectral index,
141 * - a pivot energy, and
142 * - a curvature.
143 ***************************************************************************/
145 const double& index,
146 const GEnergy& pivot,
147 const double& curvature) :
149{
150 // Initialise members
151 init_members();
152
153 // Set parameters
158
159 // Autoscale parameters
160 autoscale();
161
162 // Return
163 return;
164}
165
166
167/***********************************************************************//**
168 * @brief XML constructor
169 *
170 * @param[in] xml XML element.
171 *
172 * Constructs log parabola spectral model by extracting information from an
173 * XML element. See the read() method for more information about the expected
174 * structure of the XML element.
175 ***************************************************************************/
178{
179 // Initialise members
180 init_members();
181
182 // Read information from XML element
183 read(xml);
184
185 // Return
186 return;
187}
188
189
190/***********************************************************************//**
191 * @brief Copy constructor
192 *
193 * @param[in] model LogParabola model.
194 ***************************************************************************/
196 GModelSpectral(model)
197{
198 // Initialise members
199 init_members();
200
201 // Copy members
202 copy_members(model);
203
204 // Return
205 return;
206}
207
208
209/***********************************************************************//**
210 * @brief Destructor
211 ***************************************************************************/
213{
214 // Free members
215 free_members();
216
217 // Return
218 return;
219}
220
221
222/*==========================================================================
223 = =
224 = Operators =
225 = =
226 ==========================================================================*/
227
228/***********************************************************************//**
229 * @brief Assignment operator
230 *
231 * @param[in] model LogParabola model.
232 * @return LogParabola model.
233 ***************************************************************************/
235{
236 // Execute only if object is not identical
237 if (this != &model) {
238
239 // Copy base class members
240 this->GModelSpectral::operator=(model);
241
242 // Free members
243 free_members();
244
245 // Initialise members
246 init_members();
247
248 // Copy members
249 copy_members(model);
250
251 } // endif: object was not identical
252
253 // Return
254 return *this;
255}
256
257
258/*==========================================================================
259 = =
260 = Public methods =
261 = =
262 ==========================================================================*/
263
264/***********************************************************************//**
265 * @brief Clear log parabola model
266 ***************************************************************************/
268{
269 // Free class members (base and derived classes, derived class first)
270 free_members();
272
273 // Initialise members
275 init_members();
276
277 // Return
278 return;
279}
280
281
282/***********************************************************************//**
283 * @brief Clone log parabola model
284 *
285 * @return Pointer to deep copy of log parabola spectrum.
286 ***************************************************************************/
288{
289 // Clone log parabola model
290 return new GModelSpectralLogParabola(*this);
291}
292
293
294/***********************************************************************//**
295 * @brief Evaluate model
296 *
297 * @param[in] srcEng True photon energy.
298 * @param[in] srcTime True photon arrival time.
299 * @param[in] gradients Compute gradients?
300 * @return Model value (ph/cm2/s/MeV).
301 *
302 * Computes
303 *
304 * \f[
305 * S_{\rm E}(E | t) = {\tt m\_norm}
306 * \left( \frac{E}{\tt m\_pivot} \right)^{{\tt m\_index} +
307 * {\tt m\_curvature} \, \ln \frac{E}{\tt m\_pivot}}
308 * \f]
309 *
310 * where
311 * - \f${\tt m\_norm}\f$ is the normalization or prefactor,
312 * - \f${\tt m\_index}\f$ is the spectral index,
313 * - \f${\tt m\_curvature}\f$ is the spectral curvature, and
314 * - \f${\tt m\_pivot}\f$ is the pivot energy.
315 *
316 * If the @p gradients flag is true the method will also compute the
317 * partial derivatives of the model with respect to the parameters using
318 *
319 * \f[
320 * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_norm}} =
321 * \frac{S_{\rm E}(E | t)}{{\tt m\_norm}}
322 * \f]
323 *
324 * \f[
325 * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_index}} =
326 * S_{\rm E}(E | t) \, \ln(E/{\tt m_pivot})
327 * \f]
328 *
329 * \f[
330 * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_curvature}} =
331 * S_{\rm E}(E | t) \, (\ln(E/{\tt m_pivot})^2)
332 * \f]
333 *
334 * \f[
335 * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_pivot}} =
336 * -S_{\rm E}(E | t) \,
337 * \left( \frac{2 {\tt m\_curvature} \ln(E/{\tt m_pivot}) + {\tt m\_index}}
338 * {{\tt m\_pivot}} \right)
339 * \f]
340 *
341 * @todo The method expects that energy!=0. Otherwise Inf or NaN may result.
342 ***************************************************************************/
344 const GTime& srcTime,
345 const bool& gradients) const
346{
347 // Update the evaluation cache
348 update_eval_cache(srcEng);
349
350 // Compute function value
351 double value = m_norm.value() * m_last_power;
352
353 // Optionally compute gradients
354 if (gradients) {
355
356 // Compute partial derivatives of the parameter values
357 double g_norm = (m_norm.is_free())
358 ? m_norm.scale() * m_last_power : 0.0;
359 double g_index = (m_index.is_free())
360 ? value * m_index.scale() * m_last_log_e_norm : 0.0;
361 double g_curvature = (m_curvature.is_free())
362 ? value * m_curvature.scale() * m_last_log_e_norm *
363 m_last_log_e_norm : 0.0;
364 double g_pivot = (m_pivot.is_free() && m_pivot.factor_value() != 0.0)
365 ? -value * (m_last_exponent + m_curvature.value() *
367
368 // Set gradients
369 m_norm.factor_gradient(g_norm);
370 m_index.factor_gradient(g_index);
371 m_curvature.factor_gradient(g_curvature);
372 m_pivot.factor_gradient(g_pivot);
373
374 } // endif: gradient computation was requested
375
376 // Compile option: Check for NaN/Inf
377 #if defined(G_NAN_CHECK)
378 if (gammalib::is_notanumber(value) || gammalib::is_infinite(value)) {
379 std::cout << "*** ERROR: GModelSpectralLogParabola::eval";
380 std::cout << "(srcEng=" << srcEng;
381 std::cout << ", srcTime=" << srcTime << "):";
382 std::cout << " NaN/Inf encountered";
383 std::cout << " (value=" << value;
384 std::cout << ", pivot=" << m_last_pivot;
385 std::cout << ", index=" << m_last_index;
386 std::cout << ", curvature=" << m_last_curvature;
387 std::cout << ", e_norm=" << m_last_e_norm;
388 std::cout << ", log_e_norm=" << m_last_log_e_norm;
389 std::cout << ", exponent=" << m_last_exponent;
390 std::cout << ", power=" << m_last_power;
391 std::cout << ")" << std::endl;
392 }
393 #endif
394
395 // Return
396 return value;
397}
398
399
400/***********************************************************************//**
401 * @brief Returns model photon flux between [emin, emax] (units: ph/cm2/s)
402 *
403 * @param[in] emin Minimum photon energy.
404 * @param[in] emax Maximum photon energy.
405 * @return Photon flux (ph/cm2/s).
406 *
407 * Computes
408 *
409 * \f[
410 * \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) dE
411 * \f]
412 *
413 * where
414 * - [@p emin, @p emax] is an energy interval, and
415 * - \f$S_{\rm E}(E | t)\f$ is the spectral model (ph/cm2/s/MeV).
416 * The integration is done numerically.
417 ***************************************************************************/
419 const GEnergy& emax) const
420{
421 // Initialise flux
422 double flux = 0.0;
423
424 // Compute only if integration range is valid
425 if (emin < emax) {
426
427 // Initialise function to integrate
428 flux_kern kernel(prefactor(), index(), curvature(), pivot());
429
430 // Initialise integral class with function
431 GIntegral integral(&kernel);
432
433 // Set integration precision
434 integral.eps(1.0e-8);
435
436 // Calculate integral between emin and emax
437 flux = integral.romberg(emin.MeV(), emax.MeV());
438
439 } // endif: integration range was valid
440
441 // Return flux
442 return flux;
443}
444
445
446/***********************************************************************//**
447 * @brief Returns model energy flux between [emin, emax] (units: erg/cm2/s)
448 *
449 * @param[in] emin Minimum photon energy.
450 * @param[in] emax Maximum photon energy.
451 * @return Energy flux (erg/cm2/s).
452 *
453 * Computes
454 *
455 * \f[
456 * \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) E \, dE
457 * \f]
458 *
459 * where
460 * - [@p emin, @p emax] is an energy interval, and
461 * - \f$S_{\rm E}(E | t)\f$ is the spectral model (ph/cm2/s/MeV).
462 * The integration is done numerically.
463 ***************************************************************************/
465 const GEnergy& emax) const
466{
467 // Initialise flux
468 double eflux = 0.0;
469
470 // Compute only if integration range is valid
471 if (emin < emax) {
472
473 // Initialise function to integrate
474 eflux_kern kernel(prefactor(), index(), curvature(), pivot());
475
476 // Initialise integral class with function
477 GIntegral integral(&kernel);
478
479 // Set integration precision
480 integral.eps(1.0e-8);
481
482 // Calculate integral between emin and emax
483 eflux = integral.romberg(emin.MeV(), emax.MeV());
484
485 // Convert from MeV/cm2/s to erg/cm2/s
487
488 } // endif: integration range was valid
489
490 // Return flux
491 return eflux;
492}
493
494
495/***********************************************************************//**
496 * @brief Returns Monte Carlo energy between [emin, emax]
497 *
498 * @param[in] emin Minimum photon energy.
499 * @param[in] emax Maximum photon energy.
500 * @param[in] time True photon arrival time.
501 * @param[in,out] ran Random number generator.
502 * @return Energy.
503 *
504 * Returns Monte Carlo energy by randomly drawing from the spectral model.
505 ***************************************************************************/
507 const GEnergy& emax,
508 const GTime& time,
509 GRan& ran) const
510{
511 // Check energy interval
513
514 // Allocate energy
515 GEnergy energy;
516
517 // Update cache
518 update_mc_cache(emin, emax, time);
519
520 // Initialise energy
521 double eng;
522
523 // Initialse acceptance fraction
524 double acceptance_fraction;
525
526 // Use rejection method to draw a random energy. We first draw
527 // analytically from a power law, and then compare the power law
528 // at the drawn energy to the curved function. This
529 // gives an acceptance fraction, and we accept the energy only if
530 // a uniform random number is <= the acceptance fraction.
531 do {
532
533 // Get uniform random number
534 double u = ran.uniform();
535
536 // Case A: Corresponding mc Plaw-Index is not -1
537 if (m_mc_exponent != 0.0) {
538 if (u > 0.0) {
539 eng = std::exp(std::log(u * m_mc_pow_ewidth + m_mc_pow_emin) /
541 }
542 else {
543 eng = 0.0;
544 }
545 }
546
547 // Case B: Corresponding mc Plaw-Index is -1
548 else {
549 eng = std::exp(u * m_mc_pow_ewidth + m_mc_pow_emin);
550 }
551
552 // Compute powerlaw at given energy
553 double e_norm = eng / m_pivot.value();
554 double plaw = m_mc_norm * std::pow(e_norm, m_mc_exponent-1.0);
555
556 // Compute logparabola at given energy
557 double logparabola = prefactor() *
558 std::pow(e_norm,index()+curvature()*std::log(e_norm));
559
560 // Compute acceptance fraction
561 acceptance_fraction = logparabola / plaw;
562
563 } while (ran.uniform() > acceptance_fraction);
564
565 // Set energy
566 energy.MeV(eng);
567
568 // Return energy
569 return energy;
570}
571
572
573/***********************************************************************//**
574 * @brief Read model from XML element
575 *
576 * @param[in] xml XML element.
577 *
578 * Read the spectral log parabola information from an XML element.
579 ***************************************************************************/
581{
582 // Verify number of model parameters
584
585 // Get parameter pointers
590
591 // Read parameters
592 m_norm.read(*norm);
596
597 // In case that legacy parameters were used we need to negate the index
598 // and curvature because they are differently defined
599 if (gammalib::xml_has_par(xml, "alpha") &&
600 gammalib::xml_has_par(xml, "beta")) {
607 }
608
609 // Return
610 return;
611}
612
613
614/***********************************************************************//**
615 * @brief Write model into XML element
616 *
617 * @param[in] xml XML element.
618 *
619 * Write the LogParabola model information into an XML element.
620 ***************************************************************************/
622{
623 // Verify model type
625
626 // Check if parameters are Fermi/LAT style and need to be negated
627 GModelPar inx = m_index;
629 if (inx.name() == "alpha") {
630 inx.min(-inx.max());
631 inx.max(-inx.min());
632 inx.value(-inx.value());
633 }
634 if (crv.name() == "beta") {
635 crv.min(-crv.max());
636 crv.max(-crv.min());
637 crv.value(-crv.value());
638 }
639
640 // Get XML parameters
645
646 // Write parameters
647 m_norm.write(*norm);
648 inx.write(*index);
649 crv.write(*curvature);
651
652 // Return
653 return;
654}
655
656
657/***********************************************************************//**
658 * @brief Print LogParabola information
659 *
660 * @param[in] chatter Chattiness (defaults to NORMAL).
661 * @return String containing LogParabola information.
662 ***************************************************************************/
663std::string GModelSpectralLogParabola::print(const GChatter& chatter) const
664{
665 // Initialise result string
666 std::string result;
667
668 // Continue only if chatter is not silent
669 if (chatter != SILENT) {
670
671 // Append header
672 result.append("=== GModelSpectralLogParabola ===");
673
674 // Append information
675 result.append("\n"+gammalib::parformat("Number of parameters"));
676 result.append(gammalib::str(size()));
677 for (int i = 0; i < size(); ++i) {
678 result.append("\n"+m_pars[i]->print(chatter));
679 }
680
681 } // endif: chatter was not silent
682
683 // Return result
684 return result;
685}
686
687
688/*==========================================================================
689 = =
690 = Private methods =
691 = =
692 ==========================================================================*/
693
694/***********************************************************************//**
695 * @brief Initialise class members
696 ***************************************************************************/
698{
699 // Initialise model type
700 m_type = "LogParabola";
701
702 // Initialise powerlaw normalisation
703 m_norm.clear();
704 m_norm.name("Prefactor");
705 m_norm.unit("ph/cm2/s/MeV");
706 m_norm.scale(1.0);
707 m_norm.value(1.0); // default: 1.0
708 m_norm.min(0.0); // min: 0.0
709 m_norm.free();
710 m_norm.gradient(0.0);
711 m_norm.has_grad(true);
712
713 // Initialise powerlaw index
714 m_index.clear();
715 m_index.name("Index");
716 m_index.scale(1.0);
717 m_index.value(-2.0); // default: -2.0
718 m_index.range(-10.0,+10.0); // range: [-10,+10]
719 m_index.free();
720 m_index.gradient(0.0);
721 m_index.has_grad(true);
722
723 // Initialise curvature
725 m_curvature.name("Curvature");
726 m_curvature.scale(1.0);
727 m_curvature.value(-0.1); // default: -2.0
728 m_curvature.range(-10.0,+10.0); // range: [-10,+10]
731 m_curvature.has_grad(true);
732
733 // Initialise pivot energy
734 m_pivot.clear();
735 m_pivot.name("PivotEnergy");
736 m_pivot.unit("MeV");
737 m_pivot.scale(1.0);
738 m_pivot.value(100.0); // default: 100
739 m_pivot.fix();
740 m_pivot.gradient(0.0);
741 m_pivot.has_grad(true);
742
743 // Set parameter pointer(s)
744 m_pars.clear();
745 m_pars.push_back(&m_norm);
746 m_pars.push_back(&m_index);
747 m_pars.push_back(&m_curvature);
748 m_pars.push_back(&m_pivot);
749
750 // Initialise eval cache
752 m_last_index = 1.0e30;
753 m_last_curvature = 1.0e30;
754 m_last_pivot = 1.0e30;
755 m_last_e_norm = 0.0;
756 m_last_log_e_norm = 0.0;
757 m_last_exponent = 0.0;
758 m_last_power = 0.0;
759
760 // Initialise MC cache
761 m_mc_emin = 0.0;
762 m_mc_emax = 0.0;
763 m_mc_exponent = 0.0;
764 m_mc_pow_emin = 0.0;
765 m_mc_pow_ewidth = 0.0;
766 m_mc_norm = 0.0;
767
768 // Return
769 return;
770}
771
772
773/***********************************************************************//**
774 * @brief Copy class members
775 *
776 * @param[in] model GModelSpectralLogParabola members which should be copied.
777 ***************************************************************************/
779{
780 // Copy members
781 m_type = model.m_type;
782 m_norm = model.m_norm;
783 m_index = model.m_index;
784 m_curvature = model.m_curvature;
785 m_pivot = model.m_pivot;
786
787 // Set parameter pointer(s)
788 m_pars.clear();
789 m_pars.push_back(&m_norm);
790 m_pars.push_back(&m_index);
791 m_pars.push_back(&m_curvature);
792 m_pars.push_back(&m_pivot);
793
794 // Copy eval cache
803
804 // Copy MC cache
805 m_mc_emin = model.m_mc_emin;
806 m_mc_emax = model.m_mc_emax;
810 m_mc_norm = model.m_mc_norm;
811
812 // Return
813 return;
814}
815
816
817/***********************************************************************//**
818 * @brief Delete class members
819 ***************************************************************************/
821{
822 // Return
823 return;
824}
825
826
827/***********************************************************************//**
828 * @brief Update eval precomputation cache
829 *
830 * @param[in] energy Energy.
831 *
832 * Updates the precomputation cache for eval() method.
833 ***************************************************************************/
835{
836 // Get parameter values (takes 3 multiplications which are difficult
837 // to avoid)
838 double index = m_index.value();
839 double curvature = m_curvature.value();
840 double pivot = m_pivot.value();
841
842 // If the energy or one of the parameters index, curvature or pivot energy
843 // has changed then recompute the cache
844 if ((m_last_energy != energy) ||
845 (m_last_index != index) ||
847 (m_last_pivot != pivot)) {
848
849 // Store actual energy and parameter values
850 m_last_energy = energy;
854
855 // Compute and store value
856 double eng = energy.MeV();
861
862 } // endif: recomputation was required
863
864 // Return
865 return;
866}
867
868
869/***********************************************************************//**
870 * @brief Update Monte Carlo pre computation cache
871 *
872 * @param[in] emin Minimum photon energy.
873 * @param[in] emax Maximum photon energy.
874 * @param[in] time True photon arrival time.
875 *
876 * Updates the precomputation cache for Monte Carlo simulations.
877 ***************************************************************************/
879 const GEnergy& emax,
880 const GTime& time) const
881
882{
883 // Only update if boundaries have changed
884 if(emin.MeV() != m_mc_emin || emax.MeV() != m_mc_emax){
885
886 // Store energy boundaries
887 m_mc_emin = emin.MeV();
888 m_mc_emax = emax.MeV();
889
890 // Find a corresponding power law with the criterion
891 // Plaw > LogParabola in the given interval
892 double index_pl;
893
894 // Checking the sign of spectrum curvature
895 if (curvature() < 0) {
896
897 // Use the spectral index at the pivot energy of the LogParabola
898 index_pl = index();
900 }
901 else {
902 // Use a power law which connects the ends of the convex,
903 // curved model
904
905 // Plaw index defined by the slope of a straight line in the
906 // log-log-plane
907 index_pl = std::log(eval(emin,time)/eval(emax,time)) /
908 std::log(emin.MeV()/emax.MeV());
909
910 // Plaw norm defined such that Plaw = LogParabola at emin
911 m_mc_norm = eval(emin,time) / std::pow(emin.MeV()/m_pivot.value(),index_pl);
912
913 }
914
915 // Set precomputation cache
916 if (index_pl != -1.0) {
917 m_mc_exponent = index_pl + 1.0;
918 m_mc_pow_emin = std::pow(emin.MeV(), m_mc_exponent);
919 m_mc_pow_ewidth = std::pow(emax.MeV(), m_mc_exponent) - m_mc_pow_emin;
920 }
921 else {
922 m_mc_exponent = 0.0;
923 m_mc_pow_emin = std::log(emin.MeV());
924 m_mc_pow_ewidth = std::log(emax.MeV()) - m_mc_pow_emin;
925 }
926
927 }
928
929 // Return
930 return;
931}
#define G_WRITE
#define G_READ
Exception handler interface definition.
Integration class interface definition.
const GModelSpectralLogParabola g_spectral_logp_seed1("LogParabola", "Prefactor", "Index", "PivotEnergy", "Curvature")
Log parabola spectral model class definition.
Spectral model registry class definition.
Random number generator class definition.
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
double norm(const GVector &vector)
Computes vector norm.
Definition GVector.cpp:932
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
double MeV(void) const
Return energy in MeV.
Definition GEnergy.cpp:342
void clear(void)
Clear instance.
Definition GEnergy.cpp:267
GIntegral class interface definition.
Definition GIntegral.hpp:46
void eps(const double &eps)
Set relative precision.
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
Model parameter class.
Definition GModelPar.hpp:87
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
LogParabola spectral model class.
void free_members(void)
Delete class members.
virtual void write(GXmlElement &xml) const
Write model into XML element.
double m_last_e_norm
Last E/Epivot value.
void copy_members(const GModelSpectralLogParabola &model)
Copy class members.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns Monte Carlo energy between [emin, emax].
double m_last_index
Last index parameter.
void update_eval_cache(const GEnergy &energy) const
Update eval precomputation cache.
double index(void) const
Return spectral index.
virtual ~GModelSpectralLogParabola(void)
Destructor.
GModelPar m_norm
Normalization factor.
GModelSpectralLogParabola(void)
Void constructor.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax, const GTime &time) const
Update Monte Carlo pre computation cache.
double m_last_pivot
Last pivot parameter.
GEnergy m_last_energy
Last energy value.
double m_last_curvature
Last curvature parameters.
double m_mc_pow_ewidth
Power of energy width.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
virtual std::string type(void) const
Return model type.
virtual void clear(void)
Clear log parabola model.
double prefactor(void) const
Return pre factor.
double m_mc_exponent
Exponent (index+1)
virtual GModelSpectralLogParabola & operator=(const GModelSpectralLogParabola &model)
Assignment operator.
virtual void read(const GXmlElement &xml)
Read model from XML element.
double m_mc_norm
Norm of powerlaw model at logparabola pivot energy.
virtual GModelSpectralLogParabola * clone(void) const
Clone log parabola model.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate model.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print LogParabola information.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
void init_members(void)
Initialise class members.
double curvature(void) const
Return spectral curvature.
GEnergy pivot(void) const
Return pivot energy.
double m_mc_pow_emin
Power of minimum energy.
double m_last_log_e_norm
Last ln(E/Epivot) value.
Interface definition for the spectral model registry class.
Abstract spectral model base class.
void free_members(void)
Delete class members.
virtual GModelSpectral & operator=(const GModelSpectral &model)
Assignment operator.
std::vector< GModelPar * > m_pars
Parameter pointers.
void autoscale(void)
Autoscale parameters.
int size(void) const
Return number of parameters.
void init_members(void)
Initialise class members.
const double & factor_value(void) const
Return parameter factor value.
bool is_free(void) const
Signal if parameter is free.
void free(void)
Free a parameter.
const double & scale(void) const
Return parameter scale.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
const std::string & unit(void) const
Return parameter unit.
double max(void) const
Return parameter maximum boundary.
double min(void) const
Return parameter minimum boundary.
const double & factor_gradient(void) const
Return parameter factor gradient.
void fix(void)
Fix a parameter.
double gradient(void) const
Return parameter gradient.
void clear(void)
Clear parameter.
double value(void) const
Return parameter value.
const std::string & name(void) const
Return parameter name.
Random number generator class.
Definition GRan.hpp:44
double uniform(void)
Returns random double precision floating value in range 0 to 1.
Definition GRan.cpp:242
Time class.
Definition GTime.hpp:55
XML element node class.
void check_energy_interval(const std::string &origin, const GEnergy &emin, const GEnergy &emax)
Checks energy interval.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition GTools.cpp:1162
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition GTools.hpp:186
bool is_notanumber(const double &x)
Signal if argument is not a number.
Definition GTools.hpp:203
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:508
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:1708
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:1656
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
Definition GTools.cpp:1796
bool xml_has_par(const GXmlElement &xml, const std::string &name)
Checks if parameter with given name in XML element exists.
Definition GTools.cpp:1615
const double MeV2erg
Definition GTools.hpp:45
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.
Definition GTools.cpp:1838