Commit db94cfe7f05450e88a79b6fffdc23a7129b44393
1 parent
0c91771d
Add limits for component scales
Showing
2 changed files
with
32 additions
and
7 deletions
include/GModelSpatialComposite.hpp
| @@ -82,7 +82,9 @@ public: | @@ -82,7 +82,9 @@ public: | ||
| 82 | void append(const GModelSpatial& component, | 82 | void append(const GModelSpatial& component, |
| 83 | const std::string& name = "", | 83 | const std::string& name = "", |
| 84 | const double& scale = 1.0, | 84 | const double& scale = 1.0, |
| 85 | - const bool& freeScale = false); | 85 | + const bool& freeScale = false, |
| 86 | + const double& minScale = 1.e-10, | ||
| 87 | + const double& maxScale = 1.e13); | ||
| 86 | const GModelSpatial* component(const int& index) const; | 88 | const GModelSpatial* component(const int& index) const; |
| 87 | const GModelSpatial* component(const std::string& name) const; | 89 | const GModelSpatial* component(const std::string& name) const; |
| 88 | double scale(const int& index) const; | 90 | double scale(const int& index) const; |
src/model/GModelSpatialComposite.cpp
| @@ -360,8 +360,10 @@ void GModelSpatialComposite::read(const GXmlElement& xml) | @@ -360,8 +360,10 @@ void GModelSpatialComposite::read(const GXmlElement& xml) | ||
| 360 | // Initialise scale | 360 | // Initialise scale |
| 361 | double scale = 1.0; | 361 | double scale = 1.0; |
| 362 | 362 | ||
| 363 | - // Initialise freeScale | 363 | + // Initialise scale attributes |
| 364 | double freeScale = false; | 364 | double freeScale = false; |
| 365 | + double minScale = 1.e-10; | ||
| 366 | + double maxScale = 1.e13; | ||
| 365 | 367 | ||
| 366 | // Get scale value | 368 | // Get scale value |
| 367 | if (spec-> has_attribute("scale")) { | 369 | if (spec-> has_attribute("scale")) { |
| @@ -371,10 +373,19 @@ void GModelSpatialComposite::read(const GXmlElement& xml) | @@ -371,10 +373,19 @@ void GModelSpatialComposite::read(const GXmlElement& xml) | ||
| 371 | if (spec->has_attribute("free_scale")) { | 373 | if (spec->has_attribute("free_scale")) { |
| 372 | freeScale = gammalib::toint(spec->attribute("free_scale")); | 374 | freeScale = gammalib::toint(spec->attribute("free_scale")); |
| 373 | } | 375 | } |
| 376 | + | ||
| 377 | + // Check if scale minimum is specified | ||
| 378 | + if (spec->has_attribute("scale_min")) { | ||
| 379 | + minScale = gammalib::todouble(spec->attribute("scale_min")); | ||
| 380 | + } | ||
| 381 | + // Check if scale maximum is specified | ||
| 382 | + if (spec->has_attribute("scale_max")) { | ||
| 383 | + maxScale = gammalib::todouble(spec->attribute("scale_max")); | ||
| 384 | + } | ||
| 374 | } | 385 | } |
| 375 | 386 | ||
| 376 | // Append spatial component to container | 387 | // Append spatial component to container |
| 377 | - append(*ptr, name, scale, freeScale); | 388 | + append(*ptr, name, scale, freeScale, minScale, maxScale); |
| 378 | 389 | ||
| 379 | } // endfor: loop over components | 390 | } // endfor: loop over components |
| 380 | 391 | ||
| @@ -461,6 +472,10 @@ void GModelSpatialComposite::write(GXmlElement& xml) const | @@ -461,6 +472,10 @@ void GModelSpatialComposite::write(GXmlElement& xml) const | ||
| 461 | if (m_scales_fit[i]->is_free()) { | 472 | if (m_scales_fit[i]->is_free()) { |
| 462 | matching_model->attribute("scale_error", | 473 | matching_model->attribute("scale_error", |
| 463 | gammalib::str(m_scales_fit[i]->error())); | 474 | gammalib::str(m_scales_fit[i]->error())); |
| 475 | + matching_model->attribute("scale_min", | ||
| 476 | + gammalib::str(m_scales_fit[i]->min())); | ||
| 477 | + matching_model->attribute("scale_max", | ||
| 478 | + gammalib::str(m_scales_fit[i]->max())); | ||
| 464 | } | 479 | } |
| 465 | matching_model->attribute("free_scale", | 480 | matching_model->attribute("free_scale", |
| 466 | gammalib::str(m_scales_fit[i]->is_free())); | 481 | gammalib::str(m_scales_fit[i]->is_free())); |
| @@ -479,8 +494,12 @@ void GModelSpatialComposite::write(GXmlElement& xml) const | @@ -479,8 +494,12 @@ void GModelSpatialComposite::write(GXmlElement& xml) const | ||
| 479 | if (m_scales_fit[i]->value() != 1.0 || m_scales_fit[i]->is_free()) { | 494 | if (m_scales_fit[i]->value() != 1.0 || m_scales_fit[i]->is_free()) { |
| 480 | element.attribute("scale", gammalib::str(m_scales_fit[i]->value())); | 495 | element.attribute("scale", gammalib::str(m_scales_fit[i]->value())); |
| 481 | if (m_scales_fit[i]->is_free()) { | 496 | if (m_scales_fit[i]->is_free()) { |
| 482 | - element.attribute("scale_error", | ||
| 483 | - gammalib::str(m_scales_fit[i]->error())); | 497 | + element.attribute("scale_error", |
| 498 | + gammalib::str(m_scales_fit[i]->error())); | ||
| 499 | + element.attribute("scale_min", | ||
| 500 | + gammalib::str(m_scales_fit[i]->min())); | ||
| 501 | + element.attribute("scale_max", | ||
| 502 | + gammalib::str(m_scales_fit[i]->max())); | ||
| 484 | } | 503 | } |
| 485 | element.attribute("free_scale", | 504 | element.attribute("free_scale", |
| 486 | gammalib::str(m_scales_fit[i]->is_free())); | 505 | gammalib::str(m_scales_fit[i]->is_free())); |
| @@ -507,13 +526,17 @@ void GModelSpatialComposite::write(GXmlElement& xml) const | @@ -507,13 +526,17 @@ void GModelSpatialComposite::write(GXmlElement& xml) const | ||
| 507 | * @param[in] name Name of spatial model (can be empty). | 526 | * @param[in] name Name of spatial model (can be empty). |
| 508 | * @param[in] scale Optional spatial model scaling factor. | 527 | * @param[in] scale Optional spatial model scaling factor. |
| 509 | * @param[in] freeScale Free scale parameter (default:false). | 528 | * @param[in] freeScale Free scale parameter (default:false). |
| 529 | + * @param[in] minScale Minimum for scale parameter (default:1.e-10). | ||
| 530 | + * @param[in] maxScale Maximum for scale parameter (default:1.e13). | ||
| 510 | * | 531 | * |
| 511 | * Appends a spatial component to the composite model | 532 | * Appends a spatial component to the composite model |
| 512 | ***************************************************************************/ | 533 | ***************************************************************************/ |
| 513 | void GModelSpatialComposite::append(const GModelSpatial& component, | 534 | void GModelSpatialComposite::append(const GModelSpatial& component, |
| 514 | const std::string& name, | 535 | const std::string& name, |
| 515 | const double& scale, | 536 | const double& scale, |
| 516 | - const bool& freeScale) | 537 | + const bool& freeScale, |
| 538 | + const double& minScale, | ||
| 539 | + const double& maxScale) | ||
| 517 | { | 540 | { |
| 518 | // Append model container | 541 | // Append model container |
| 519 | m_components.push_back(component.clone()); | 542 | m_components.push_back(component.clone()); |
| @@ -560,7 +583,7 @@ void GModelSpatialComposite::append(const GModelSpatial& component, | @@ -560,7 +583,7 @@ void GModelSpatialComposite::append(const GModelSpatial& component, | ||
| 560 | m_scales_fit[index]->clear(); | 583 | m_scales_fit[index]->clear(); |
| 561 | m_scales_fit[index]->name(component_name + ":scale"); | 584 | m_scales_fit[index]->name(component_name + ":scale"); |
| 562 | m_scales_fit[index]->value(scale); | 585 | m_scales_fit[index]->value(scale); |
| 563 | - m_scales_fit[index]->range(1e-10,1e13); | 586 | + m_scales_fit[index]->range(minScale,maxScale); |
| 564 | if(freeScale) | 587 | if(freeScale) |
| 565 | m_scales_fit[index]->free(); | 588 | m_scales_fit[index]->free(); |
| 566 | else | 589 | else |