Commit 3cf567e2364103cd34b4c30ec4bd24eb6af9485d
1 parent
e9ae0dd9
adapt to new GObservation/GEvents interfaces
Showing
4 changed files
with
87 additions
and
49 deletions
pyext/ctobssim.i
| ... | ... | @@ -43,6 +43,7 @@ public: |
| 43 | 43 | void save(void); |
| 44 | 44 | GObservations& obs(void); |
| 45 | 45 | void get_parameters(void); |
| 46 | + void set_list(GCTAObservation* obs); | |
| 46 | 47 | GPhotons simulate_photons(const GCTAObservation* obs, const GModels& models); |
| 47 | 48 | void simulate_source(GCTAObservation* obs, const GPhotons& photons); |
| 48 | 49 | void simulate_background(GCTAObservation* obs, const GModels& models); | ... | ... |
src/ctbin/ctbin.cpp
| ... | ... | @@ -407,8 +407,10 @@ void ctbin::bin_events(GCTAObservation* obs) |
| 407 | 407 | emin.TeV(m_emin); |
| 408 | 408 | emax.TeV(m_emax); |
| 409 | 409 | ebds.setlog(emin, emax, m_enumbins); |
| 410 | - obs->ebounds(ebds); | |
| 411 | 410 | |
| 411 | + // Get Good Time intervals | |
| 412 | + GGti gti = obs->events()->gti(); | |
| 413 | + | |
| 412 | 414 | // Create skymap |
| 413 | 415 | GSkymap map = GSkymap(m_proj, m_coordsys, |
| 414 | 416 | m_xref, m_yref, m_binsz, m_binsz, |
| ... | ... | @@ -436,7 +438,7 @@ void ctbin::bin_events(GCTAObservation* obs) |
| 436 | 438 | } |
| 437 | 439 | |
| 438 | 440 | // Determine energy bin. Skip if we are outside the energy range |
| 439 | - int index = obs->ebounds().index(event->energy()); | |
| 441 | + int index = ebds.index(event->energy()); | |
| 440 | 442 | if (index == -1) { |
| 441 | 443 | num_outside_ebds++; |
| 442 | 444 | continue; |
| ... | ... | @@ -470,7 +472,7 @@ void ctbin::bin_events(GCTAObservation* obs) |
| 470 | 472 | } |
| 471 | 473 | |
| 472 | 474 | // Create events cube from sky map |
| 473 | - GCTAEventCube cube(map, obs->ebounds(), obs->gti()); | |
| 475 | + GCTAEventCube cube(map, ebds, gti); | |
| 474 | 476 | |
| 475 | 477 | // Replace event list by event cube in observation |
| 476 | 478 | obs->events(&cube); | ... | ... |
src/ctobssim/ctobssim.cpp
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | #ifdef HAVE_CONFIG_H |
| 21 | 21 | #include <config.h> |
| 22 | 22 | #endif |
| 23 | -#include <stdio.h> | |
| 23 | +#include <cstdio> | |
| 24 | 24 | #include "ctobssim.hpp" |
| 25 | 25 | #include "GTools.hpp" |
| 26 | 26 | |
| ... | ... | @@ -266,12 +266,6 @@ void ctobssim::run(void) |
| 266 | 266 | log.header3("Observation"); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - // Allocate CTA event list and attach it to the observation. | |
| 270 | - // Note that the events() method removes any existing event | |
| 271 | - // list before attaching a new event list. | |
| 272 | - GCTAEventList* events = new GCTAEventList; | |
| 273 | - obs->events(events); | |
| 274 | - | |
| 275 | 269 | // Write header for photon simulation |
| 276 | 270 | //if (logTerse()) |
| 277 | 271 | // log.header3("Simulate photons"); |
| ... | ... | @@ -370,15 +364,64 @@ void ctobssim::get_parameters(void) |
| 370 | 364 | m_irf = par("irf")->value(); |
| 371 | 365 | m_ra = par("ra")->real(); |
| 372 | 366 | m_dec = par("dec")->real(); |
| 373 | - m_rad = par("rad")->real(); | |
| 374 | - m_tmin = par("tmin")->real(); | |
| 375 | - m_tmax = par("tmax")->real(); | |
| 376 | - m_emin = par("emin")->real(); | |
| 377 | - m_emax = par("emax")->real(); | |
| 367 | + | |
| 368 | + // Set pointing direction | |
| 369 | + GCTAPointing pnt; | |
| 370 | + GSkyDir skydir; | |
| 371 | + skydir.radec_deg(m_ra, m_dec); | |
| 372 | + pnt.dir(skydir); | |
| 378 | 373 | |
| 379 | 374 | // Allocate CTA observation |
| 380 | 375 | GCTAObservation obs; |
| 381 | 376 | |
| 377 | + // Set CTA observation attributes | |
| 378 | + obs.pointing(pnt); | |
| 379 | + obs.response(m_irf, m_caldb); | |
| 380 | + | |
| 381 | + // Set event list (queries remaining parameters) | |
| 382 | + set_list(&obs); | |
| 383 | + | |
| 384 | + // Append CTA observation to container | |
| 385 | + m_obs.append(obs); | |
| 386 | + | |
| 387 | + // Load models into container | |
| 388 | + m_obs.models(m_infile); | |
| 389 | + | |
| 390 | + } // endif: there was no observation in the container | |
| 391 | + | |
| 392 | + // Get other parameters | |
| 393 | + m_seed = par("seed")->integer(); | |
| 394 | + | |
| 395 | + // Initialise random number generator | |
| 396 | + m_ran.seed(m_seed); | |
| 397 | + | |
| 398 | + // Return | |
| 399 | + return; | |
| 400 | +} | |
| 401 | + | |
| 402 | + | |
| 403 | +/***********************************************************************//** | |
| 404 | + * @brief Set empty CTA event list | |
| 405 | + * | |
| 406 | + * @param[in] obs Attach empty event list to CTA observation | |
| 407 | + ***************************************************************************/ | |
| 408 | +void ctobssim::set_list(GCTAObservation* obs) | |
| 409 | +{ | |
| 410 | + // Continue only if observation is valid | |
| 411 | + if (obs != NULL) { | |
| 412 | + | |
| 413 | + // Get CTA observation parameters | |
| 414 | + m_ra = par("ra")->real(); | |
| 415 | + m_dec = par("dec")->real(); | |
| 416 | + m_rad = par("rad")->real(); | |
| 417 | + m_tmin = par("tmin")->real(); | |
| 418 | + m_tmax = par("tmax")->real(); | |
| 419 | + m_emin = par("emin")->real(); | |
| 420 | + m_emax = par("emax")->real(); | |
| 421 | + | |
| 422 | + // Allocate CTA event list | |
| 423 | + GCTAEventList events; | |
| 424 | + | |
| 382 | 425 | // Set pointing direction |
| 383 | 426 | GCTAPointing pnt; |
| 384 | 427 | GSkyDir skydir; |
| ... | ... | @@ -408,26 +451,15 @@ void ctobssim::get_parameters(void) |
| 408 | 451 | emax.TeV(m_emax); |
| 409 | 452 | ebounds.append(emin, emax); |
| 410 | 453 | |
| 411 | - // Set CTA observation attributes | |
| 412 | - obs.pointing(pnt); | |
| 413 | - obs.response(m_irf, m_caldb); | |
| 414 | - obs.roi(&roi); | |
| 415 | - obs.gti(gti); | |
| 416 | - obs.ebounds(ebounds); | |
| 417 | - | |
| 418 | - // Append CTA observation to container | |
| 419 | - m_obs.append(obs); | |
| 420 | - | |
| 421 | - // Load models into container | |
| 422 | - m_obs.models(m_infile); | |
| 423 | - | |
| 424 | - } // endif: there was no observation in the container | |
| 454 | + // Set CTA event list attributes | |
| 455 | + events.roi(roi); | |
| 456 | + events.gti(gti); | |
| 457 | + events.ebounds(ebounds); | |
| 425 | 458 | |
| 426 | - // Get other parameters | |
| 427 | - m_seed = par("seed")->integer(); | |
| 459 | + // Attach event list to CTA observation | |
| 460 | + obs->events(&events); | |
| 428 | 461 | |
| 429 | - // Initialise random number generator | |
| 430 | - m_ran.seed(m_seed); | |
| 462 | + } // endif: oberservation was valid | |
| 431 | 463 | |
| 432 | 464 | // Return |
| 433 | 465 | return; |
| ... | ... | @@ -455,10 +487,12 @@ GPhotons ctobssim::simulate_photons(const GCTAObservation* obs, |
| 455 | 487 | // Initialise indentation for logging |
| 456 | 488 | int indent = 0; |
| 457 | 489 | |
| 458 | - // Extract MC parameters from observation | |
| 459 | - const GCTARoi* roi = static_cast<const GCTARoi*>(obs->roi()); | |
| 460 | - GSkyDir dir = roi->centre().skydir(); | |
| 461 | - double rad = roi->radius(); | |
| 490 | + // Get CTA event list | |
| 491 | + const GCTAEventList* events = dynamic_cast<const GCTAEventList*>(obs->events()); | |
| 492 | + | |
| 493 | + // Extract ROI | |
| 494 | + GSkyDir dir = events->roi().centre().skydir(); | |
| 495 | + double rad = events->roi().radius(); | |
| 462 | 496 | |
| 463 | 497 | // Dump simulation cone information |
| 464 | 498 | if (logNormal()) { |
| ... | ... | @@ -476,15 +510,15 @@ GPhotons ctobssim::simulate_photons(const GCTAObservation* obs, |
| 476 | 510 | GPhotons photons; |
| 477 | 511 | |
| 478 | 512 | // Loop over all Good Time Intervals |
| 479 | - for (int it = 0; it < obs->gti().size(); ++it) { | |
| 513 | + for (int it = 0; it < events->gti().size(); ++it) { | |
| 480 | 514 | |
| 481 | 515 | // Extract time interval |
| 482 | - GTime tmin = obs->gti().tstart(it); | |
| 483 | - GTime tmax = obs->gti().tstop(it); | |
| 516 | + GTime tmin = events->gti().tstart(it); | |
| 517 | + GTime tmax = events->gti().tstop(it); | |
| 484 | 518 | |
| 485 | 519 | // Dump time interval |
| 486 | 520 | if (logNormal()) { |
| 487 | - if (obs->gti().size() > 1) { | |
| 521 | + if (events->gti().size() > 1) { | |
| 488 | 522 | indent++; |
| 489 | 523 | log.indent(indent); |
| 490 | 524 | } |
| ... | ... | @@ -493,15 +527,15 @@ GPhotons ctobssim::simulate_photons(const GCTAObservation* obs, |
| 493 | 527 | } |
| 494 | 528 | |
| 495 | 529 | // Loop over all energy boundaries |
| 496 | - for (int ie = 0; ie < obs->ebounds().size(); ++ie) { | |
| 530 | + for (int ie = 0; ie < events->ebounds().size(); ++ie) { | |
| 497 | 531 | |
| 498 | 532 | // Extract energy boundaries |
| 499 | - GEnergy emin = obs->ebounds().emin(ie); | |
| 500 | - GEnergy emax = obs->ebounds().emax(ie); | |
| 533 | + GEnergy emin = events->ebounds().emin(ie); | |
| 534 | + GEnergy emax = events->ebounds().emax(ie); | |
| 501 | 535 | |
| 502 | 536 | // Dump energy range |
| 503 | 537 | if (logNormal()) { |
| 504 | - if (obs->ebounds().size() > 1) { | |
| 538 | + if (events->ebounds().size() > 1) { | |
| 505 | 539 | indent++; |
| 506 | 540 | log.indent(indent); |
| 507 | 541 | } |
| ... | ... | @@ -582,7 +616,7 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GPhotons& photons) |
| 582 | 616 | // pointings implement we just determine the pointing from the |
| 583 | 617 | // beginning of the observation. Throw an exception if the pointing |
| 584 | 618 | // is not defined. |
| 585 | - GCTAPointing* pnt = obs->pointing(obs->tstart()); | |
| 619 | + GCTAPointing* pnt = obs->pointing(obs->events()->tstart()); | |
| 586 | 620 | if (pnt == NULL) |
| 587 | 621 | throw GCTAException::no_pointing(G_SIMULATE_SOURCE); |
| 588 | 622 | |
| ... | ... | @@ -595,7 +629,7 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GPhotons& photons) |
| 595 | 629 | // Make sure that the observation holds a CTA event list. If this |
| 596 | 630 | // is not the case then allocate and attach a CTA event list now. |
| 597 | 631 | if (dynamic_cast<const GCTAEventList*>(obs->events()) == NULL) |
| 598 | - obs->events(new GCTAEventList); | |
| 632 | + set_list(obs); | |
| 599 | 633 | |
| 600 | 634 | // Get pointer on event list (circumvent const correctness) |
| 601 | 635 | GCTAEventList* events = (GCTAEventList*)(obs->events()); |
| ... | ... | @@ -644,7 +678,7 @@ void ctobssim::simulate_background(GCTAObservation* obs, const GModels& models) |
| 644 | 678 | // Make sure that the observation holds a CTA event list. If this |
| 645 | 679 | // is not the case then allocate and attach a CTA event list now. |
| 646 | 680 | if (dynamic_cast<const GCTAEventList*>(obs->events()) == NULL) |
| 647 | - obs->events(new GCTAEventList); | |
| 681 | + set_list(obs); | |
| 648 | 682 | |
| 649 | 683 | // Get pointer on event list (circumvent const correctness) |
| 650 | 684 | GCTAEventList* events = (GCTAEventList*)(obs->events()); |
| ... | ... | @@ -667,7 +701,7 @@ void ctobssim::simulate_background(GCTAObservation* obs, const GModels& models) |
| 667 | 701 | |
| 668 | 702 | // Append events |
| 669 | 703 | for (int k = 0; k < list->size(); k++) |
| 670 | - events->append(*(list->pointer(k))); | |
| 704 | + events->append(*((*list)[k])); | |
| 671 | 705 | |
| 672 | 706 | // Dump simulation results |
| 673 | 707 | if (logNormal()) { | ... | ... |
src/ctobssim/ctobssim.hpp
| ... | ... | @@ -58,6 +58,7 @@ public: |
| 58 | 58 | void save(void); |
| 59 | 59 | GObservations& obs(void) { return m_obs; } |
| 60 | 60 | void get_parameters(void); |
| 61 | + void set_list(GCTAObservation* obs); | |
| 61 | 62 | GPhotons simulate_photons(const GCTAObservation* obs, const GModels& models); |
| 62 | 63 | void simulate_source(GCTAObservation* obs, const GPhotons& photons); |
| 63 | 64 | void simulate_background(GCTAObservation* obs, const GModels& models); | ... | ... |