/***********************************************************************//** * @brief Returns model energy flux between [emin, emax] (units: erg/cm2/s) * * @param[in] emin Minimum photon energy. * @param[in] emax Maximum photon energy. * @return Energy flux (erg/cm2/s). * * Computes * * \f[ * \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) E \, dE * \f] * * where * - [@p emin, @p emax] is an energy interval, and * - \f$S_{\rm E}(E | t)\f$ is the spectral model (ph/cm2/s/MeV). * The integration is done numerically. ***************************************************************************/ double GModelSpectralSmoothBrokenPlaw::eflux(const GEnergy& emin, const GEnergy& emax) const { // Initialise flux double eflux = 0.0; // Compute only if integration range is valid if (emin < emax) { // Initialise function to integrate eflux_kern kernel(prefactor(), index1(), pivot(), index2(), breakenergy(), beta()); // Initialise integral class with function GIntegral integral(&kernel); // Set integration precision integral.eps(1.0e-8); // Calculate integral between emin and emax eflux = integral.romberg(emin.MeV(), emax.MeV()); // Convert from MeV/cm2/s to erg/cm2/s eflux *= gammalib::MeV2erg; } // endif: integration range was valid // Return flux return eflux; }
void Factor(const LL &x, vector<LL> &v) { LL n = x; if(n==1) { puts("Factor 1"); return; } prefactor(n,v); if(n==1) return; comfactor(n,v); sort(v.begin(),v.end()); }
/***********************************************************************//** * @brief Update Monte Carlo pre computation cache * * Updates the precomputation cache for Monte Carlo simulations. ***************************************************************************/ void GModelSpectralSmoothBrokenPlaw::update_mc_cache(void) const { // Check if we need to update the cache if (prefactor() != m_mc_prefactor || index1() != m_mc_index1 || index2() != m_mc_index2 || pivot().MeV() != m_mc_pivot || breakenergy().MeV() != m_mc_breakenergy) { // Set parameters for which Monte Carlo cache was computed m_mc_prefactor = prefactor(); m_mc_index1 = index1(); m_mc_index2 = index2(); m_mc_pivot = pivot().MeV(); m_mc_breakenergy = breakenergy().MeV(); // Compute prefactor at pivot energy double pre = prefactor() * std::pow(breakenergy().MeV()/pivot().MeV(), index1()); // Find out which index is harder. This is important since the smoothly // broken power law follows the hard index below the break energy and // the softer index above the break energy. double index1 = (m_mc_index1 > m_mc_index2) ? m_mc_index1 : m_mc_index2; double index2 = (m_mc_index1 > m_mc_index2) ? m_mc_index2 : m_mc_index1; // Set broken power law for Monte Carlo simulations m_mc_brokenplaw = GModelSpectralBrokenPlaw(pre, index1, breakenergy(), index2); } // endif: Update was required // Return return; }