Commit a9b96d1968c494994595c507b041d9f9051d2b7b
1 parent
3f9c60f8
Handle special case of point source in GModelSpatial::flux() method (#2961)
Showing
1 changed file
with
70 additions
and
74 deletions
src/model/GModelSpatial.cpp
| ... | ... | @@ -350,85 +350,81 @@ double GModelSpatial::flux(const GSkyRegion* reg, |
| 350 | 350 | |
| 351 | 351 | // Check if the model is a point source |
| 352 | 352 | const GModelSpatialPointSource* ps_model = |
| 353 | - dynamic_cast<const GModelSpatialPointSource*>(this); | |
| 354 | - | |
| 355 | - // If the model is not a point source integrate over circular regions overlap | |
| 356 | - if (ps_model == NULL) { | |
| 357 | - | |
| 358 | - // Thrown an exception if region is not a sky circle | |
| 359 | - const GSkyRegionCircle* reg_circle = | |
| 360 | - dynamic_cast<const GSkyRegionCircle*>(reg); | |
| 361 | - if (reg_circle == NULL) { | |
| 362 | - std::string msg = "Flux can only be computed for a circular " | |
| 363 | - "region."; | |
| 364 | - throw GException::feature_not_implemented(G_FLUX,msg); | |
| 365 | - } | |
| 366 | - | |
| 367 | - // Thrown an exception if model region is not a sky circle | |
| 368 | - const GSkyRegionCircle* model_circle = | |
| 369 | - dynamic_cast<const GSkyRegionCircle*>(model_reg); | |
| 370 | - if (model_circle == NULL) { | |
| 371 | - std::string msg = "Flux can only be computed for spatial model " | |
| 372 | - "with region defined as circle."; | |
| 373 | - throw GException::feature_not_implemented(G_FLUX,msg); | |
| 374 | - } | |
| 375 | - | |
| 376 | - // Model centre and radius in radians | |
| 377 | - GSkyDir model_centre = model_circle->centre(); | |
| 378 | - double model_radius = model_circle->radius() * gammalib::deg2rad; | |
| 379 | - | |
| 380 | - // Distance between region and model centres in radians | |
| 381 | - double distance = model_centre.dist(reg_circle->centre()); | |
| 382 | - | |
| 383 | - // Take the distance between centers minus radius of model region as | |
| 384 | - // the minimum radial integration boundary (in radians) | |
| 385 | - double rho_min = distance - model_radius; | |
| 386 | - | |
| 387 | - // Make sure that rho_min does not become negative | |
| 388 | - if (rho_min < 0.0) { | |
| 389 | - rho_min = 0.0; | |
| 390 | - } | |
| 391 | - | |
| 392 | - // Take the region radius as the maximum radial integration boundary | |
| 393 | - // (in radians) | |
| 394 | - double rho_max = reg_circle->radius() * gammalib::deg2rad; | |
| 395 | - | |
| 396 | - // Pre-compute some quantities for arclength | |
| 397 | - double cosdist = std::cos(distance); | |
| 398 | - double sindist = std::sin(distance); | |
| 399 | - double cosmodrad = std::cos(model_radius); | |
| 400 | - | |
| 401 | - // Setup integration kernel | |
| 402 | - GModelSpatial::circle_int_kern_rho integrand(this, | |
| 403 | - reg_circle, | |
| 404 | - srcEng, | |
| 405 | - srcTime, | |
| 406 | - distance, | |
| 407 | - cosdist, | |
| 408 | - sindist, | |
| 409 | - model_radius, | |
| 410 | - cosmodrad); | |
| 411 | - GIntegral integral(&integrand); | |
| 412 | - | |
| 413 | - // Perform integration | |
| 414 | - flux = integral.romberg(rho_min, rho_max); | |
| 415 | - | |
| 416 | - } | |
| 417 | - | |
| 418 | - // Otherwise, if model is point source since it overlaps | |
| 419 | - // with region set flux to 1 | |
| 420 | - else { | |
| 421 | - | |
| 422 | - flux = 1.0; | |
| 423 | - | |
| 424 | - } // endif, model is point source | |
| 425 | - | |
| 353 | + dynamic_cast<const GModelSpatialPointSource*>(this); | |
| 354 | + | |
| 355 | + // If the model is not a point source integrate over circular regions overlap | |
| 356 | + if (ps_model == NULL) { | |
| 357 | + | |
| 358 | + // Thrown an exception if region is not a sky circle | |
| 359 | + const GSkyRegionCircle* reg_circle = | |
| 360 | + dynamic_cast<const GSkyRegionCircle*>(reg); | |
| 361 | + if (reg_circle == NULL) { | |
| 362 | + std::string msg = "Flux can only be computed for a circular " | |
| 363 | + "region."; | |
| 364 | + throw GException::feature_not_implemented(G_FLUX,msg); | |
| 365 | + } | |
| 366 | + | |
| 367 | + // Thrown an exception if model region is not a sky circle | |
| 368 | + const GSkyRegionCircle* model_circle = | |
| 369 | + dynamic_cast<const GSkyRegionCircle*>(model_reg); | |
| 370 | + if (model_circle == NULL) { | |
| 371 | + std::string msg = "Flux can only be computed for spatial model " | |
| 372 | + "with region defined as circle."; | |
| 373 | + throw GException::feature_not_implemented(G_FLUX,msg); | |
| 374 | + } | |
| 375 | + | |
| 376 | + // Model centre and radius in radians | |
| 377 | + GSkyDir model_centre = model_circle->centre(); | |
| 378 | + double model_radius = model_circle->radius() * gammalib::deg2rad; | |
| 379 | + | |
| 380 | + // Distance between region and model centres in radians | |
| 381 | + double distance = model_centre.dist(reg_circle->centre()); | |
| 382 | + | |
| 383 | + // Take the distance between centers minus radius of model region as | |
| 384 | + // the minimum radial integration boundary (in radians) | |
| 385 | + double rho_min = distance - model_radius; | |
| 386 | + | |
| 387 | + // Make sure that rho_min does not become negative | |
| 388 | + if (rho_min < 0.0) { | |
| 389 | + rho_min = 0.0; | |
| 390 | + } | |
| 391 | + | |
| 392 | + // Take the region radius as the maximum radial integration boundary | |
| 393 | + // (in radians) | |
| 394 | + double rho_max = reg_circle->radius() * gammalib::deg2rad; | |
| 395 | + | |
| 396 | + // Pre-compute some quantities for arclength | |
| 397 | + double cosdist = std::cos(distance); | |
| 398 | + double sindist = std::sin(distance); | |
| 399 | + double cosmodrad = std::cos(model_radius); | |
| 400 | + | |
| 401 | + // Setup integration kernel | |
| 402 | + GModelSpatial::circle_int_kern_rho integrand(this, | |
| 403 | + reg_circle, | |
| 404 | + srcEng, | |
| 405 | + srcTime, | |
| 406 | + distance, | |
| 407 | + cosdist, | |
| 408 | + sindist, | |
| 409 | + model_radius, | |
| 410 | + cosmodrad); | |
| 411 | + GIntegral integral(&integrand); | |
| 412 | + | |
| 413 | + // Perform integration | |
| 414 | + flux = integral.romberg(rho_min, rho_max); | |
| 415 | + | |
| 416 | + } // endif: source model was not a point source | |
| 417 | + | |
| 418 | + // ... otherwise, if model is point source since it overlaps | |
| 419 | + // with region set flux to 1 | |
| 420 | + else { | |
| 421 | + flux = 1.0; | |
| 422 | + } | |
| 426 | 423 | |
| 427 | 424 | } // endif: model overlaps with region |
| 428 | 425 | |
| 429 | 426 | // Return |
| 430 | 427 | return flux; |
| 431 | - | |
| 432 | 428 | } |
| 433 | 429 | |
| 434 | 430 | ... | ... |