Commit fd5d424f93bde8a76521fc4b4dd6276b0aebe149
1 parent
3186c66e
Add instances for HESS, VERITAS and MAGIC
Showing
2 changed files
with
98 additions
and
47 deletions
inst/cta/include/GCTAOnOffObservation.hpp
| ... | ... | @@ -69,6 +69,7 @@ class GCTAOnOffObservation : public GObservation { |
| 69 | 69 | public: |
| 70 | 70 | // Constructors and destructors |
| 71 | 71 | GCTAOnOffObservation(void); |
| 72 | + GCTAOnOffObservation(const bool& dummy, const std::string& instrument); | |
| 72 | 73 | GCTAOnOffObservation(const GObservations& obs); |
| 73 | 74 | GCTAOnOffObservation(const GPha& pha_on, |
| 74 | 75 | const GPha& pha_off, | ... | ... |
inst/cta/src/GCTAOnOffObservation.cpp
| ... | ... | @@ -35,6 +35,7 @@ |
| 35 | 35 | #include "GMatrixSparse.hpp" |
| 36 | 36 | #include "GModels.hpp" |
| 37 | 37 | #include "GModelSky.hpp" |
| 38 | +#include "GModelData.hpp" | |
| 38 | 39 | #include "GModelSpatial.hpp" |
| 39 | 40 | #include "GModelSpectral.hpp" |
| 40 | 41 | #include "GModelTemporal.hpp" |
| ... | ... | @@ -50,7 +51,6 @@ |
| 50 | 51 | #include "GCTAResponseIrf.hpp" |
| 51 | 52 | #include "GCTAAeff2D.hpp" |
| 52 | 53 | #include "GCTACubeBackground.hpp" |
| 53 | -#include "GCTAModelIrfBackground.hpp" | |
| 54 | 54 | #include "GCTAOnOffObservation.hpp" |
| 55 | 55 | #include "GCTASupport.hpp" |
| 56 | 56 | |
| ... | ... | @@ -60,8 +60,14 @@ |
| 60 | 60 | #endif |
| 61 | 61 | |
| 62 | 62 | /* __ Globals ____________________________________________________________ */ |
| 63 | -const GCTAOnOffObservation g_onoff_obs_cta_seed; | |
| 63 | +const GCTAOnOffObservation g_onoff_obs_cta_seed(true, "CTAOnOff"); | |
| 64 | +const GCTAOnOffObservation g_onoff_obs_hess_seed(true, "HESSOnOff"); | |
| 65 | +const GCTAOnOffObservation g_onoff_obs_magic_seed(true, "MAGICOnOff"); | |
| 66 | +const GCTAOnOffObservation g_onoff_obs_veritas_seed(true, "VERITASOnOff"); | |
| 64 | 67 | const GObservationRegistry g_onoff_obs_cta_registry(&g_onoff_obs_cta_seed); |
| 68 | +const GObservationRegistry g_onoff_obs_hess_registry(&g_onoff_obs_hess_seed); | |
| 69 | +const GObservationRegistry g_onoff_obs_magic_registry(&g_onoff_obs_magic_seed); | |
| 70 | +const GObservationRegistry g_onoff_obs_veritas_registry(&g_onoff_obs_veritas_seed); | |
| 65 | 71 | |
| 66 | 72 | /* __ Method name definitions ____________________________________________ */ |
| 67 | 73 | #define G_CONSTRUCTOR1 "GCTAOnOffObservation::GCTAOnOffObservation(GPha&, "\ |
| ... | ... | @@ -125,6 +131,35 @@ GCTAOnOffObservation::GCTAOnOffObservation(void) : GObservation() |
| 125 | 131 | |
| 126 | 132 | |
| 127 | 133 | /***********************************************************************//** |
| 134 | + * @brief Instrument constructor | |
| 135 | + * | |
| 136 | + * @param[in] dummy Dummy flag. | |
| 137 | + * @param[in] instrument Instrument name. | |
| 138 | + * | |
| 139 | + * Constructs an empty CTA On/Off observation for a given instrument. | |
| 140 | + * | |
| 141 | + * This method is specifically used allocation of global class instances for | |
| 142 | + * observation registry. By specifying explicit instrument names it is | |
| 143 | + * possible to use the "CTA" module are for other Imaging Air Cherenkov | |
| 144 | + * Telescopes. So far, the following instrument codes are supported: | |
| 145 | + * "CTAOnOff", "HESSOnOff", "VERITASOnOff", "MAGICOnOff". | |
| 146 | + ***************************************************************************/ | |
| 147 | +GCTAOnOffObservation::GCTAOnOffObservation(const bool& dummy, | |
| 148 | + const std::string& instrument) : | |
| 149 | + GObservation() | |
| 150 | +{ | |
| 151 | + // Initialise members | |
| 152 | + init_members(); | |
| 153 | + | |
| 154 | + // Set instrument | |
| 155 | + m_instrument = instrument; | |
| 156 | + | |
| 157 | + // Return | |
| 158 | + return; | |
| 159 | +} | |
| 160 | + | |
| 161 | + | |
| 162 | +/***********************************************************************//** | |
| 128 | 163 | * @brief Copy constructor |
| 129 | 164 | * |
| 130 | 165 | * @param[in] obs On/Off observation. |
| ... | ... | @@ -285,6 +320,10 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GCTAObservation& obs, |
| 285 | 320 | * \f$RMF_i(E_{\rm true}, E_{\rm reco})\f$ is the Redistribution Matrix File |
| 286 | 321 | * of observation \f$i\f$, and |
| 287 | 322 | * \f$\tau_i\f$ is the livetime of observation \f$i\f$. |
| 323 | + * | |
| 324 | + * The method extracts the instrument name from the first On/Off observation | |
| 325 | + * in the observation container and only stacks subsequent On/Off | |
| 326 | + * observations with the same instrument name. | |
| 288 | 327 | ***************************************************************************/ |
| 289 | 328 | GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 290 | 329 | GObservation() |
| ... | ... | @@ -302,6 +341,9 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 302 | 341 | GEnergy emin_obs; |
| 303 | 342 | GEnergy emax_obs; |
| 304 | 343 | |
| 344 | + // Allocate instrument | |
| 345 | + std::string instrument; | |
| 346 | + | |
| 305 | 347 | // Loop over all observation in container |
| 306 | 348 | for (int i = 0; i < obs.size(); ++i) { |
| 307 | 349 | |
| ... | ... | @@ -314,6 +356,16 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 314 | 356 | continue; |
| 315 | 357 | } |
| 316 | 358 | |
| 359 | + // If the instrument name is empty then set the instrument now. | |
| 360 | + // Otherwise, skip the observation if it does not correspond | |
| 361 | + // to the same instrument. | |
| 362 | + if (instrument.empty()) { | |
| 363 | + instrument = onoff->instrument(); | |
| 364 | + } | |
| 365 | + else if (instrument != onoff->instrument()) { | |
| 366 | + continue; | |
| 367 | + } | |
| 368 | + | |
| 317 | 369 | // Check consistency of On/Off observation |
| 318 | 370 | onoff->check_consistency(G_CONSTRUCTOR2); |
| 319 | 371 | |
| ... | ... | @@ -322,8 +374,6 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 322 | 374 | GEnergy emax = onoff->on_spec().emax_obs(); |
| 323 | 375 | |
| 324 | 376 | // Get stacked ARF and RMF |
| 325 | - //GArf arf_stacked = this->arf_stacked(onoff->arf(), emin, emax); | |
| 326 | - //GRmf rmf_stacked = this->rmf_stacked(onoff->rmf(), emin, emax); | |
| 327 | 377 | GArf arf_stacked = onoff->arf(); |
| 328 | 378 | GRmf rmf_stacked = onoff->rmf(); |
| 329 | 379 | |
| ... | ... | @@ -347,23 +397,23 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 347 | 397 | // and store result intermediately into BACKRESP column of off |
| 348 | 398 | // spectum |
| 349 | 399 | std::vector<double>& backresp = m_off_spec["BACKRESP"]; |
| 350 | - for (int i = 0; i < backresp.size(); ++i) { | |
| 351 | - backresp[i] *= exposure; | |
| 400 | + for (int k = 0; k < backresp.size(); ++k) { | |
| 401 | + backresp[k] *= exposure; | |
| 352 | 402 | } |
| 353 | 403 | |
| 354 | 404 | // Compute background scaling factor contribution |
| 355 | - for (int i = 0; i < m_on_spec.size(); ++i) { | |
| 356 | - double background = onoff->off_spec()["BACKRESP"][i]; | |
| 357 | - double alpha = onoff->on_spec().backscal(i); | |
| 405 | + for (int k = 0; k < m_on_spec.size(); ++k) { | |
| 406 | + double background = onoff->off_spec()["BACKRESP"][k]; | |
| 407 | + double alpha = onoff->on_spec().backscal(k); | |
| 358 | 408 | double scale = alpha * background * exposure; |
| 359 | - m_on_spec.backscal(i,scale); | |
| 409 | + m_on_spec.backscal(k,scale); | |
| 360 | 410 | } |
| 361 | 411 | |
| 362 | 412 | // Compute RMF contribution |
| 363 | 413 | for (int itrue = 0; itrue < m_rmf.ntrue(); ++itrue) { |
| 364 | 414 | double arf = m_arf[itrue]; |
| 365 | - for (int imeasured = 0; imeasured < m_rmf.nmeasured(); ++imeasured) { | |
| 366 | - m_rmf(itrue,imeasured) *= arf; | |
| 415 | + for (int ireco = 0; ireco < m_rmf.nmeasured(); ++ireco) { | |
| 416 | + m_rmf(itrue,ireco) *= arf; | |
| 367 | 417 | } |
| 368 | 418 | } |
| 369 | 419 | |
| ... | ... | @@ -412,11 +462,11 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 412 | 462 | m_off_spec += onoff->off_spec(); |
| 413 | 463 | |
| 414 | 464 | // Compute background scaling factor contribution |
| 415 | - for (int i = 0; i < m_on_spec.size(); ++i) { | |
| 416 | - double background = onoff->off_spec()["BACKRESP"][i]; | |
| 417 | - double alpha = onoff->on_spec().backscal(i); | |
| 465 | + for (int k = 0; k < m_on_spec.size(); ++k) { | |
| 466 | + double background = onoff->off_spec()["BACKRESP"][k]; | |
| 467 | + double alpha = onoff->on_spec().backscal(k); | |
| 418 | 468 | double scale = alpha * background * exposure; |
| 419 | - m_on_spec.backscal(i, m_on_spec.backscal(i) + scale); | |
| 469 | + m_on_spec.backscal(k, m_on_spec.backscal(k) + scale); | |
| 420 | 470 | } |
| 421 | 471 | |
| 422 | 472 | // Add ARF |
| ... | ... | @@ -425,15 +475,15 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 425 | 475 | // Add number of background events/MeV from BACKRESP column |
| 426 | 476 | const std::vector<double>& src = onoff->off_spec()["BACKRESP"]; |
| 427 | 477 | std::vector<double>& dst = m_off_spec["BACKRESP"]; |
| 428 | - for (int i = 0; i < dst.size(); ++i) { | |
| 429 | - dst[i] += src[i] * exposure; | |
| 478 | + for (int k = 0; k < dst.size(); ++k) { | |
| 479 | + dst[k] += src[k] * exposure; | |
| 430 | 480 | } |
| 431 | 481 | |
| 432 | 482 | // Add RMF |
| 433 | 483 | for (int itrue = 0; itrue < m_rmf.ntrue(); ++itrue) { |
| 434 | 484 | double arf = arf_stacked[itrue] * exposure; |
| 435 | - for (int imeasured = 0; imeasured < m_rmf.nmeasured(); ++imeasured) { | |
| 436 | - m_rmf(itrue,imeasured) += rmf_stacked(itrue,imeasured) * arf; | |
| 485 | + for (int ireco = 0; ireco < m_rmf.nmeasured(); ++ireco) { | |
| 486 | + m_rmf(itrue,ireco) += rmf_stacked(itrue,ireco) * arf; | |
| 437 | 487 | } |
| 438 | 488 | } |
| 439 | 489 | |
| ... | ... | @@ -455,14 +505,14 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 455 | 505 | } // endfor: looped over observations |
| 456 | 506 | |
| 457 | 507 | // Compute stacked background scaling factor |
| 458 | - for (int i = 0; i < m_on_spec.size(); ++i) { | |
| 459 | - double norm = m_off_spec["BACKRESP"][i]; | |
| 508 | + for (int k = 0; k < m_on_spec.size(); ++k) { | |
| 509 | + double norm = m_off_spec["BACKRESP"][k]; | |
| 460 | 510 | if (norm > 0.0) { |
| 461 | - double scale = m_on_spec.backscal(i) / norm; | |
| 462 | - m_on_spec.backscal(i,scale); | |
| 511 | + double scale = m_on_spec.backscal(k) / norm; | |
| 512 | + m_on_spec.backscal(k,scale); | |
| 463 | 513 | } |
| 464 | 514 | else { |
| 465 | - m_on_spec.backscal(i,0.0); | |
| 515 | + m_on_spec.backscal(k,0.0); | |
| 466 | 516 | } |
| 467 | 517 | } |
| 468 | 518 | |
| ... | ... | @@ -470,8 +520,8 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 470 | 520 | for (int itrue = 0; itrue < m_rmf.ntrue(); ++itrue) { |
| 471 | 521 | double arf = m_arf[itrue]; |
| 472 | 522 | if (arf > 0.0) { |
| 473 | - for (int imeasured = 0; imeasured < m_rmf.nmeasured(); ++imeasured) { | |
| 474 | - m_rmf(itrue,imeasured) /= arf; | |
| 523 | + for (int ireco = 0; ireco < m_rmf.nmeasured(); ++ireco) { | |
| 524 | + m_rmf(itrue,ireco) /= arf; | |
| 475 | 525 | } |
| 476 | 526 | } |
| 477 | 527 | } |
| ... | ... | @@ -484,8 +534,8 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 484 | 534 | // Compute background events/MeV/sec and store them in BACKRESP column |
| 485 | 535 | if (total_exposure > 0.0) { |
| 486 | 536 | std::vector<double>& backresp = m_off_spec["BACKRESP"]; |
| 487 | - for (int i = 0; i < backresp.size(); ++i) { | |
| 488 | - backresp[i] /= total_exposure; | |
| 537 | + for (int k = 0; k < backresp.size(); ++k) { | |
| 538 | + backresp[k] /= total_exposure; | |
| 489 | 539 | } |
| 490 | 540 | } |
| 491 | 541 | |
| ... | ... | @@ -495,6 +545,9 @@ GCTAOnOffObservation::GCTAOnOffObservation(const GObservations& obs) : |
| 495 | 545 | m_off_spec.emin_obs(emin_obs); |
| 496 | 546 | m_off_spec.emax_obs(emax_obs); |
| 497 | 547 | |
| 548 | + // Set instrument name | |
| 549 | + m_instrument = instrument; | |
| 550 | + | |
| 498 | 551 | // Return |
| 499 | 552 | return; |
| 500 | 553 | } |
| ... | ... | @@ -1354,6 +1407,9 @@ void GCTAOnOffObservation::set(const GCTAObservation& obs, |
| 1354 | 1407 | m_arf.header(arf_header); |
| 1355 | 1408 | m_rmf.header(rmf_header); |
| 1356 | 1409 | |
| 1410 | + // Set instrument name | |
| 1411 | + m_instrument = obs.instrument() + "OnOff"; | |
| 1412 | + | |
| 1357 | 1413 | // Return |
| 1358 | 1414 | return; |
| 1359 | 1415 | } |
| ... | ... | @@ -2379,9 +2435,6 @@ double GCTAOnOffObservation::N_gamma(const GModels& models, |
| 2379 | 2435 | * |
| 2380 | 2436 | * which are the gradients in the predicted number of background events |
| 2381 | 2437 | * with respect to all model parameters. |
| 2382 | - * | |
| 2383 | - * The method assumes that the model parameters are stored in the order | |
| 2384 | - * spectral-temporal. | |
| 2385 | 2438 | ***********************************************************************/ |
| 2386 | 2439 | double GCTAOnOffObservation::N_bgd(const GModels& models, |
| 2387 | 2440 | const int& ibin, |
| ... | ... | @@ -2433,16 +2486,17 @@ double GCTAOnOffObservation::N_bgd(const GModels& models, |
| 2433 | 2486 | continue; |
| 2434 | 2487 | } |
| 2435 | 2488 | |
| 2436 | - // Fall through if model is not an IRF background component | |
| 2437 | - const GCTAModelIrfBackground* bgd = | |
| 2438 | - dynamic_cast<const GCTAModelIrfBackground*>(mptr); | |
| 2489 | + // Fall through if model is not a background component | |
| 2490 | + const GModelData* bgd = dynamic_cast<const GModelData*>(mptr); | |
| 2439 | 2491 | if (bgd == NULL) { |
| 2440 | 2492 | ipar += mptr->size(); |
| 2441 | 2493 | continue; |
| 2442 | 2494 | } |
| 2443 | 2495 | |
| 2444 | - // Get spectral component | |
| 2445 | - GModelSpectral* spectral = bgd->spectral(); | |
| 2496 | + // Extract model dependent spectral component | |
| 2497 | + const GModelSpectral* spectral = gammalib::cta_model_spectral(*bgd); | |
| 2498 | + | |
| 2499 | + // Get value from spectral component | |
| 2446 | 2500 | if (spectral != NULL) { |
| 2447 | 2501 | |
| 2448 | 2502 | // Determine the number of background events in model by |
| ... | ... | @@ -2453,22 +2507,18 @@ double GCTAOnOffObservation::N_bgd(const GModels& models, |
| 2453 | 2507 | // dependence. We simply use a dummy time here. |
| 2454 | 2508 | value += spectral->eval(emean, GTime(), true) * norm; |
| 2455 | 2509 | |
| 2456 | - // Compute the parameter gradients for all spectral model | |
| 2457 | - // parameters | |
| 2458 | - for (int k = 0; k < spectral->size(); ++k, ++ipar) { | |
| 2459 | - GModelPar& par = (*spectral)[k]; | |
| 2510 | + // Compute the parameter gradients for all model parameters | |
| 2511 | + for (int k = 0; k < mptr->size(); ++k) { | |
| 2512 | + const GModelPar& par = (*mptr)[k]; | |
| 2460 | 2513 | if (par.is_free() && ipar < npars) { |
| 2461 | - (*grad)[ipar] += par.factor_gradient() * norm; | |
| 2514 | + (*grad)[ipar+k] += par.factor_gradient() * norm; | |
| 2462 | 2515 | } |
| 2463 | 2516 | } |
| 2464 | 2517 | |
| 2465 | 2518 | } // endif: pointer to spectral component was not NULL |
| 2466 | 2519 | |
| 2467 | - // Increase parameter counter for temporal parameter | |
| 2468 | - GModelTemporal* temporal = bgd->temporal(); | |
| 2469 | - if (temporal != NULL) { | |
| 2470 | - ipar += temporal->size(); | |
| 2471 | - } | |
| 2520 | + // Increment the parameter index | |
| 2521 | + ipar += mptr->size(); | |
| 2472 | 2522 | |
| 2473 | 2523 | } // endfor: looped over model components |
| 2474 | 2524 | ... | ... |