Commit 5fcc4acfa753a689249c0be2e8e8a080b0e8a49c
1 parent
ed2b3a80
included read/write support for PULSE_PHASE column for CTA event lists
Showing
4 changed files
with
60 additions
and
0 deletions
inst/cta/include/GCTAEventAtom.hpp
inst/cta/include/GCTAEventList.hpp
| ... | ... | @@ -103,6 +103,8 @@ protected: |
| 103 | 103 | // IRF cache for diffuse models |
| 104 | 104 | mutable std::vector<std::string> m_irf_names; //!< Model names |
| 105 | 105 | mutable std::vector<std::vector<double> > m_irf_values; //!< IRF values |
| 106 | + | |
| 107 | + bool m_has_phase; //!< Flag to signal if pulsar phase is available | |
| 106 | 108 | }; |
| 107 | 109 | |
| 108 | 110 | ... | ... |
inst/cta/src/GCTAEventAtom.cpp
| ... | ... | @@ -227,6 +227,7 @@ void GCTAEventAtom::init_members(void) |
| 227 | 227 | m_hil_msw_err = 0.0; |
| 228 | 228 | m_hil_msl = 0.0; |
| 229 | 229 | m_hil_msl_err = 0.0; |
| 230 | + m_pulse_phase = 0.0; | |
| 230 | 231 | |
| 231 | 232 | // Return |
| 232 | 233 | return; |
| ... | ... | @@ -264,6 +265,7 @@ void GCTAEventAtom::copy_members(const GCTAEventAtom& atom) |
| 264 | 265 | m_hil_msw_err = atom.m_hil_msw_err; |
| 265 | 266 | m_hil_msl = atom.m_hil_msl; |
| 266 | 267 | m_hil_msl_err = atom.m_hil_msl_err; |
| 268 | + m_pulse_phase = atom.m_pulse_phase; | |
| 267 | 269 | |
| 268 | 270 | // Return |
| 269 | 271 | return; | ... | ... |
inst/cta/src/GCTAEventList.cpp
| ... | ... | @@ -534,6 +534,9 @@ void GCTAEventList::init_members(void) |
| 534 | 534 | m_irf_names.clear(); |
| 535 | 535 | m_irf_values.clear(); |
| 536 | 536 | |
| 537 | + // initialise pulse phase flag | |
| 538 | + m_has_phase = false; | |
| 539 | + | |
| 537 | 540 | // Return |
| 538 | 541 | return; |
| 539 | 542 | } |
| ... | ... | @@ -554,6 +557,9 @@ void GCTAEventList::copy_members(const GCTAEventList& list) |
| 554 | 557 | m_irf_names = list.m_irf_names; |
| 555 | 558 | m_irf_values = list.m_irf_values; |
| 556 | 559 | |
| 560 | + // Copy pulse phase flag | |
| 561 | + m_has_phase = list.m_has_phase; | |
| 562 | + | |
| 557 | 563 | // Return |
| 558 | 564 | return; |
| 559 | 565 | } |
| ... | ... | @@ -652,6 +658,16 @@ void GCTAEventList::read_events_v0(const GFitsTable& table) |
| 652 | 658 | const GFitsTableCol* ptr_energy = table["ENERGY"]; |
| 653 | 659 | const GFitsTableCol* ptr_energy_err = table["ENERGY_ERR"]; |
| 654 | 660 | |
| 661 | + // check for pulse phase column | |
| 662 | + const GFitsTableCol* ptr_pulse_phase; | |
| 663 | + if (table.contains("PULSE_PHASE")) { | |
| 664 | + m_has_phase = true; | |
| 665 | + ptr_pulse_phase = table["PULSE_PHASE"]; | |
| 666 | + } | |
| 667 | + else { | |
| 668 | + m_has_phase = false; | |
| 669 | + } | |
| 670 | + | |
| 655 | 671 | // Copy data from columns into GCTAEventAtom objects |
| 656 | 672 | GCTAEventAtom event; |
| 657 | 673 | for (int i = 0; i < num; ++i) { |
| ... | ... | @@ -676,6 +692,12 @@ void GCTAEventList::read_events_v0(const GFitsTable& table) |
| 676 | 692 | event.m_shwidth = 0.0; |
| 677 | 693 | event.m_shlength = 0.0; |
| 678 | 694 | event.m_energy_err = ptr_energy_err->real(i); |
| 695 | + | |
| 696 | + // Set pulse phase if available | |
| 697 | + if (m_has_phase) { | |
| 698 | + event.m_pulse_phase = ptr_pulse_phase->real(i); | |
| 699 | + } | |
| 700 | + | |
| 679 | 701 | m_events.push_back(event); |
| 680 | 702 | } |
| 681 | 703 | |
| ... | ... | @@ -731,6 +753,16 @@ void GCTAEventList::read_events_v1(const GFitsTable& table) |
| 731 | 753 | const GFitsTableCol* ptr_energy = table["ENERGY"]; |
| 732 | 754 | const GFitsTableCol* ptr_energy_err = table["ENERGY_ERR"]; |
| 733 | 755 | |
| 756 | + // check for pulse phase column | |
| 757 | + const GFitsTableCol* ptr_pulse_phase; | |
| 758 | + if (table.contains("PULSE_PHASE")) { | |
| 759 | + m_has_phase = true; | |
| 760 | + ptr_pulse_phase = table["PULSE_PHASE"]; | |
| 761 | + } | |
| 762 | + else { | |
| 763 | + m_has_phase = false; | |
| 764 | + } | |
| 765 | + | |
| 734 | 766 | // Copy data from columns into GCTAEventAtom objects |
| 735 | 767 | GCTAEventAtom event; |
| 736 | 768 | for (int i = 0; i < num; ++i) { |
| ... | ... | @@ -755,6 +787,12 @@ void GCTAEventList::read_events_v1(const GFitsTable& table) |
| 755 | 787 | event.m_shwidth = ptr_shw->real(i); |
| 756 | 788 | event.m_shlength = ptr_shl->real(i); |
| 757 | 789 | event.m_energy_err = ptr_energy_err->real(i); |
| 790 | + | |
| 791 | + // Set pulse phase if available | |
| 792 | + if (m_has_phase) { | |
| 793 | + event.m_pulse_phase = ptr_pulse_phase->real(i); | |
| 794 | + } | |
| 795 | + | |
| 758 | 796 | m_events.push_back(event); |
| 759 | 797 | } |
| 760 | 798 | |
| ... | ... | @@ -874,6 +912,12 @@ void GCTAEventList::write_events(GFitsBinTable& hdu) const |
| 874 | 912 | GFitsTableFloatCol col_hil_msl = GFitsTableFloatCol("HIL_MSL", size()); |
| 875 | 913 | GFitsTableFloatCol col_hil_msl_err = GFitsTableFloatCol("HIL_MSL_ERR", size()); |
| 876 | 914 | |
| 915 | + // Create pulse phase column if required | |
| 916 | + GFitsTableFloatCol col_pulse_phase; | |
| 917 | + if (m_has_phase) { | |
| 918 | + col_pulse_phase = GFitsTableFloatCol("PULSE_PHASE", size()); | |
| 919 | + } | |
| 920 | + | |
| 877 | 921 | // Fill columns |
| 878 | 922 | for (int i = 0; i < size(); ++i) { |
| 879 | 923 | col_eid(i) = m_events[i].m_event_id; |
| ... | ... | @@ -902,6 +946,12 @@ void GCTAEventList::write_events(GFitsBinTable& hdu) const |
| 902 | 946 | col_hil_msw_err(i) = m_events[i].m_hil_msw_err; |
| 903 | 947 | col_hil_msl(i) = m_events[i].m_hil_msl; |
| 904 | 948 | col_hil_msl_err(i) = m_events[i].m_hil_msl_err; |
| 949 | + | |
| 950 | + // Optionally fill pulse phase column | |
| 951 | + if (m_has_phase) { | |
| 952 | + col_pulse_phase(i) = m_events[i].m_pulse_phase; | |
| 953 | + } | |
| 954 | + | |
| 905 | 955 | } // endfor: looped over rows |
| 906 | 956 | |
| 907 | 957 | // Append columns to table |
| ... | ... | @@ -932,6 +982,11 @@ void GCTAEventList::write_events(GFitsBinTable& hdu) const |
| 932 | 982 | hdu.append(col_hil_msl); |
| 933 | 983 | hdu.append(col_hil_msl_err); |
| 934 | 984 | |
| 985 | + // Optionally write phase column | |
| 986 | + if (m_has_phase) { | |
| 987 | + hdu.append(col_pulse_phase); | |
| 988 | + } | |
| 989 | + | |
| 935 | 990 | } // endif: there were events to write |
| 936 | 991 | |
| 937 | 992 | // Return | ... | ... |