Commit f32c950480d7bc1eb71f43bf1281fbbf83425b72
1 parent
30417fa6
implement dummy flux() and mc() methods
Showing
1 changed file
with
68 additions
and
1 deletions
src/model/GModelSpectralPlaw2.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralPlaw2.cpp - Spectral power law model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010 by Jurgen Knodlseder * | |
| 4 | + * copyright (C) 2010-2011 by Jurgen Knodlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software; you can redistribute it and/or modify * |
| ... | ... | @@ -26,6 +26,7 @@ |
| 26 | 26 | #include "GModelSpectralPlaw2.hpp" |
| 27 | 27 | |
| 28 | 28 | /* __ Method name definitions ____________________________________________ */ |
| 29 | +#define G_FLUX "GModelSpectralPlaw2::flux(GEnergy&, GEnergy&)" | |
| 29 | 30 | #define G_READ "GModelSpectralPlaw2::read(GXmlElement&)" |
| 30 | 31 | #define G_WRITE "GModelSpectralPlaw2::write(GXmlElement&)" |
| 31 | 32 | |
| ... | ... | @@ -292,6 +293,72 @@ double GModelSpectralPlaw2::eval_gradients(const GEnergy& srcEng) |
| 292 | 293 | |
| 293 | 294 | |
| 294 | 295 | /***********************************************************************//** |
| 296 | + * @brief Returns model flux between [emin, emax] (units: ph/cm2/s) | |
| 297 | + * | |
| 298 | + * @param[in] emin Minimum photon energy. | |
| 299 | + * @param[in] emax Minimum photon energy. | |
| 300 | + * | |
| 301 | + * Computes | |
| 302 | + * \f[\int_{E_{\rm min}}^{E_{\rm max}} I(E) dE\f] | |
| 303 | + * where | |
| 304 | + * \f$E_{\rm min}\f$ and \f$E_{\rm max}\f$ are the minimum and maximum | |
| 305 | + * energy, respectively, and | |
| 306 | + * \f$I(E)\f$ is the spectral model (units: ph/cm2/s/MeV). | |
| 307 | + * | |
| 308 | + * @todo Implement method | |
| 309 | + ***************************************************************************/ | |
| 310 | +double GModelSpectralPlaw2::flux(const GEnergy& emin, const GEnergy& emax) const | |
| 311 | +{ | |
| 312 | + // Dump warning that method is not yet implemented | |
| 313 | + throw GException::feature_not_implemented(G_FLUX); | |
| 314 | + | |
| 315 | + // Return flux | |
| 316 | + return 0.0; | |
| 317 | +} | |
| 318 | + | |
| 319 | + | |
| 320 | +/***********************************************************************//** | |
| 321 | + * @brief Returns MC energy between [emin, emax] | |
| 322 | + * | |
| 323 | + * @param[in] emin Minimum photon energy. | |
| 324 | + * @param[in] emax Maximum photon energy. | |
| 325 | + * @param[in] ran Random number generator. | |
| 326 | + * | |
| 327 | + * Returns Monte Carlo energy by randomly drawing from a power law. | |
| 328 | + ***************************************************************************/ | |
| 329 | +GEnergy GModelSpectralPlaw2::mc(const GEnergy& emin, const GEnergy& emax, | |
| 330 | + GRan& ran) const | |
| 331 | +{ | |
| 332 | + // Allocate energy | |
| 333 | + GEnergy energy; | |
| 334 | + | |
| 335 | + // Case A: Index is not -1 | |
| 336 | + if (index() != -1.0) { | |
| 337 | + double exponent = index() + 1.0; | |
| 338 | + double e_max = pow(emax.MeV(), exponent); | |
| 339 | + double e_min = pow(emin.MeV(), exponent); | |
| 340 | + double u = ran.uniform(); | |
| 341 | + double eng = (u > 0.0) | |
| 342 | + ? exp(log(u * (e_max - e_min) + e_min) / exponent) | |
| 343 | + : 0.0; | |
| 344 | + energy.MeV(eng); | |
| 345 | + } | |
| 346 | + | |
| 347 | + // Case B: Index is -1 | |
| 348 | + else { | |
| 349 | + double e_max = log(emax.MeV()); | |
| 350 | + double e_min = log(emin.MeV()); | |
| 351 | + double u = ran.uniform(); | |
| 352 | + double eng = exp(u * (e_max - e_min) + e_min); | |
| 353 | + energy.MeV(eng); | |
| 354 | + } | |
| 355 | + | |
| 356 | + // Return energy | |
| 357 | + return energy; | |
| 358 | +} | |
| 359 | + | |
| 360 | + | |
| 361 | +/***********************************************************************//** | |
| 295 | 362 | * @brief Read model from XML element |
| 296 | 363 | * |
| 297 | 364 | * @param[in] xml XML element. | ... | ... |