Commit cbde400471044d7e68ad7352a8e05a7dbe554439
1 parent
05329764
Integrate code.
Showing
5 changed files
with
114 additions
and
78 deletions
ChangeLog
| 1 | -2015-12-02 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | 1 | +2015-12-16 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> |
| 2 | 2 | ||
| 3 | * Version 1.1.0 released | 3 | * Version 1.1.0 released |
| 4 | ========================= | 4 | ========================= |
| 5 | 5 | ||
| 6 | + Read only mandatary columns in GCTAEventList (#1600) | ||
| 6 | Add GModel::has_ts() method (#1578) | 7 | Add GModel::has_ts() method (#1578) |
| 7 | 8 | ||
| 8 | 9 |
NEWS
| @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 1.1.0 | @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 1.1.0 | ||
| 2 | 2 | ||
| 3 | Author(s) : Juergen Knoedlseder | 3 | Author(s) : Juergen Knoedlseder |
| 4 | 4 | ||
| 5 | -2 December 2015 | 5 | +16 December 2015 |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 1. Introduction | 8 | 1. Introduction |
| @@ -109,9 +109,12 @@ None | @@ -109,9 +109,12 @@ None | ||
| 109 | 109 | ||
| 110 | 20. CTA interface | 110 | 20. CTA interface |
| 111 | ----------------- | 111 | ----------------- |
| 112 | -The IRF loaders now check the existence of the file before loading, and now throw | 112 | +The IRF loaders now check the existence of the file before loading, and now throws |
| 113 | appropriate error messages in case that the files do not exist (#1586). | 113 | appropriate error messages in case that the files do not exist (#1586). |
| 114 | 114 | ||
| 115 | +Only manadatory columns are read by GCTAEventsList, while any other columns will only | ||
| 116 | +be stored for back writing in a FITS file. | ||
| 117 | + | ||
| 115 | 118 | ||
| 116 | 21. COMPTEL interface | 119 | 21. COMPTEL interface |
| 117 | --------------------- | 120 | --------------------- |
inst/cta/include/GCTAEventList.hpp
| @@ -88,24 +88,22 @@ protected: | @@ -88,24 +88,22 @@ protected: | ||
| 88 | void free_members(void); | 88 | void free_members(void); |
| 89 | virtual void set_energies(void) { return; } | 89 | virtual void set_energies(void) { return; } |
| 90 | virtual void set_times(void) { return; } | 90 | virtual void set_times(void) { return; } |
| 91 | - void read_events(const GFitsTable& hdu); | ||
| 92 | - void write_events(GFitsBinTable& hdu) const; | 91 | + void read_events(const GFitsTable& table); |
| 92 | + void write_events(GFitsBinTable& table) const; | ||
| 93 | void write_ds_keys(GFitsHDU& hdu) const; | 93 | void write_ds_keys(GFitsHDU& hdu) const; |
| 94 | int irf_cache_init(const std::string& name) const; | 94 | int irf_cache_init(const std::string& name) const; |
| 95 | int irf_cache_index(const std::string& name) const; | 95 | int irf_cache_index(const std::string& name) const; |
| 96 | 96 | ||
| 97 | // Protected members | 97 | // Protected members |
| 98 | - GCTARoi m_roi; //!< Region of interest | ||
| 99 | - std::vector<GCTAEventAtom> m_events; //!< Events | 98 | + GCTARoi m_roi; //!< Region of interest |
| 99 | + std::vector<GCTAEventAtom> m_events; //!< Events | ||
| 100 | std::vector<GFitsTableCol*> m_columns; //!< Pointers to optional columns | 100 | std::vector<GFitsTableCol*> m_columns; //!< Pointers to optional columns |
| 101 | - bool m_has_phase; //!< Signal presence of phase | ||
| 102 | - bool m_has_detxy; //!< Signal presence of detector coordinates | 101 | + bool m_has_phase; //!< Signal presence of phase |
| 102 | + bool m_has_detxy; //!< Signal presence of detector coordinates | ||
| 103 | 103 | ||
| 104 | // IRF cache for diffuse models | 104 | // IRF cache for diffuse models |
| 105 | mutable std::vector<std::string> m_irf_names; //!< Model names | 105 | mutable std::vector<std::string> m_irf_names; //!< Model names |
| 106 | mutable std::vector<std::vector<double> > m_irf_values; //!< IRF values | 106 | mutable std::vector<std::vector<double> > m_irf_values; //!< IRF values |
| 107 | - | ||
| 108 | - | ||
| 109 | }; | 107 | }; |
| 110 | 108 | ||
| 111 | 109 |
inst/cta/src/GCTAEventAtom.cpp
| @@ -207,9 +207,9 @@ void GCTAEventAtom::init_members(void) | @@ -207,9 +207,9 @@ void GCTAEventAtom::init_members(void) | ||
| 207 | m_dir.clear(); | 207 | m_dir.clear(); |
| 208 | m_time.clear(); | 208 | m_time.clear(); |
| 209 | m_energy.clear(); | 209 | m_energy.clear(); |
| 210 | - m_index = 0; | ||
| 211 | - m_event_id = 0; | ||
| 212 | - m_phase = 0.0; | 210 | + m_index = 0; |
| 211 | + m_event_id = 0; | ||
| 212 | + m_phase = 0.0; | ||
| 213 | 213 | ||
| 214 | // Return | 214 | // Return |
| 215 | return; | 215 | return; |
| @@ -224,12 +224,12 @@ void GCTAEventAtom::init_members(void) | @@ -224,12 +224,12 @@ void GCTAEventAtom::init_members(void) | ||
| 224 | void GCTAEventAtom::copy_members(const GCTAEventAtom& atom) | 224 | void GCTAEventAtom::copy_members(const GCTAEventAtom& atom) |
| 225 | { | 225 | { |
| 226 | // Copy members | 226 | // Copy members |
| 227 | - m_dir = atom.m_dir; | ||
| 228 | - m_time = atom.m_time; | ||
| 229 | - m_energy = atom.m_energy; | ||
| 230 | - m_index = atom.m_index; | ||
| 231 | - m_event_id = atom.m_event_id; | ||
| 232 | - m_phase = atom.m_phase; | 227 | + m_dir = atom.m_dir; |
| 228 | + m_time = atom.m_time; | ||
| 229 | + m_energy = atom.m_energy; | ||
| 230 | + m_index = atom.m_index; | ||
| 231 | + m_event_id = atom.m_event_id; | ||
| 232 | + m_phase = atom.m_phase; | ||
| 233 | 233 | ||
| 234 | // Return | 234 | // Return |
| 235 | return; | 235 | return; |
inst/cta/src/GCTAEventList.cpp
| @@ -634,10 +634,24 @@ void GCTAEventList::free_members(void) | @@ -634,10 +634,24 @@ void GCTAEventList::free_members(void) | ||
| 634 | * | 634 | * |
| 635 | * @param[in] table FITS table. | 635 | * @param[in] table FITS table. |
| 636 | * | 636 | * |
| 637 | - * This method reads the CTA event list from a FITS table HDU into memory. | ||
| 638 | - * It reads required columns for analysis such as "EVENT_ID", "OBS_ID", | ||
| 639 | - * "RA", "DEC", "TIME" and "ENERGY". All other columns are stored as well | ||
| 640 | - * and will be written out in the write()-method. | 637 | + * This method reads the CTA event list from a FITS table into memory. |
| 638 | + * The following columns are mandatory in the FITS table: | ||
| 639 | + * | ||
| 640 | + * - EVENT_ID | ||
| 641 | + * - TIME | ||
| 642 | + * - RA | ||
| 643 | + * - DEC | ||
| 644 | + * - ENERGY | ||
| 645 | + * | ||
| 646 | + * Optionally, the | ||
| 647 | + * | ||
| 648 | + * - DETX | ||
| 649 | + * - DETY | ||
| 650 | + * - PHASE | ||
| 651 | + * | ||
| 652 | + * columns are read. Any other columns present in the FITS table will also be | ||
| 653 | + * read, and written into the FITS table when the write_events() method is | ||
| 654 | + * called. | ||
| 641 | ***************************************************************************/ | 655 | ***************************************************************************/ |
| 642 | void GCTAEventList::read_events(const GFitsTable& table) | 656 | void GCTAEventList::read_events(const GFitsTable& table) |
| 643 | { | 657 | { |
| @@ -654,57 +668,60 @@ void GCTAEventList::read_events(const GFitsTable& table) | @@ -654,57 +668,60 @@ void GCTAEventList::read_events(const GFitsTable& table) | ||
| 654 | m_events.reserve(num); | 668 | m_events.reserve(num); |
| 655 | 669 | ||
| 656 | // Get column pointers | 670 | // Get column pointers |
| 657 | - const GFitsTableCol* ptr_eid = table["EVENT_ID"]; | ||
| 658 | - const GFitsTableCol* ptr_time = table["TIME"]; | ||
| 659 | - const GFitsTableCol* ptr_ra = table["RA"]; | ||
| 660 | - const GFitsTableCol* ptr_dec = table["DEC"]; | ||
| 661 | - const GFitsTableCol* ptr_energy = table["ENERGY"]; | ||
| 662 | - | ||
| 663 | - // Check for phase column | ||
| 664 | - const GFitsTableCol* ptr_phase; | ||
| 665 | - if (table.contains("PHASE")) { | ||
| 666 | - m_has_phase = true; | ||
| 667 | - ptr_phase = table["PHASE"]; | ||
| 668 | - } | ||
| 669 | - else { | ||
| 670 | - m_has_phase = false; | ||
| 671 | - } | 671 | + const GFitsTableCol* ptr_eid = table["EVENT_ID"]; |
| 672 | + const GFitsTableCol* ptr_time = table["TIME"]; | ||
| 673 | + const GFitsTableCol* ptr_ra = table["RA"]; | ||
| 674 | + const GFitsTableCol* ptr_dec = table["DEC"]; | ||
| 675 | + const GFitsTableCol* ptr_energy = table["ENERGY"]; | ||
| 672 | 676 | ||
| 673 | // Check for DETX and DETY columns | 677 | // Check for DETX and DETY columns |
| 674 | const GFitsTableCol* ptr_detx; | 678 | const GFitsTableCol* ptr_detx; |
| 675 | const GFitsTableCol* ptr_dety; | 679 | const GFitsTableCol* ptr_dety; |
| 676 | if (table.contains("DETX") && table.contains("DETY")) { | 680 | if (table.contains("DETX") && table.contains("DETY")) { |
| 677 | m_has_detxy = true; | 681 | m_has_detxy = true; |
| 678 | - ptr_detx = table["DETX"]; | ||
| 679 | - ptr_dety = table["DETY"]; | 682 | + ptr_detx = table["DETX"]; |
| 683 | + ptr_dety = table["DETY"]; | ||
| 680 | } | 684 | } |
| 681 | else { | 685 | else { |
| 682 | m_has_detxy = false; | 686 | m_has_detxy = false; |
| 683 | } | 687 | } |
| 684 | 688 | ||
| 689 | + // Check for PHASE column | ||
| 690 | + const GFitsTableCol* ptr_phase; | ||
| 691 | + if (table.contains("PHASE")) { | ||
| 692 | + m_has_phase = true; | ||
| 693 | + ptr_phase = table["PHASE"]; | ||
| 694 | + } | ||
| 695 | + else { | ||
| 696 | + m_has_phase = false; | ||
| 697 | + } | ||
| 698 | + | ||
| 685 | // Copy data from columns into GCTAEventAtom objects | 699 | // Copy data from columns into GCTAEventAtom objects |
| 686 | GCTAEventAtom event; | 700 | GCTAEventAtom event; |
| 687 | for (int i = 0; i < num; ++i) { | 701 | for (int i = 0; i < num; ++i) { |
| 688 | - event.m_index = i; | 702 | + |
| 703 | + // Set mandatory information | ||
| 689 | event.m_time.set(ptr_time->real(i), m_gti.reference()); | 704 | event.m_time.set(ptr_time->real(i), m_gti.reference()); |
| 690 | event.m_dir.dir().radec_deg(ptr_ra->real(i), ptr_dec->real(i)); | 705 | event.m_dir.dir().radec_deg(ptr_ra->real(i), ptr_dec->real(i)); |
| 691 | event.m_energy.TeV(ptr_energy->real(i)); | 706 | event.m_energy.TeV(ptr_energy->real(i)); |
| 692 | - event.m_event_id = ptr_eid->integer(i); | 707 | + event.m_event_id = ptr_eid->integer(i); |
| 708 | + event.m_index = i; | ||
| 693 | 709 | ||
| 694 | - // Set detector coordinates if available | 710 | + // If available, set detector coordinates in radians |
| 695 | if (m_has_detxy) { | 711 | if (m_has_detxy) { |
| 696 | event.m_dir.detx(ptr_detx->real(i)*gammalib::deg2rad); | 712 | event.m_dir.detx(ptr_detx->real(i)*gammalib::deg2rad); |
| 697 | event.m_dir.dety(ptr_dety->real(i)*gammalib::deg2rad); | 713 | event.m_dir.dety(ptr_dety->real(i)*gammalib::deg2rad); |
| 698 | } | 714 | } |
| 699 | 715 | ||
| 700 | - // Set pulse phase if available | 716 | + // If available, set pulse phase |
| 701 | if (m_has_phase) { | 717 | if (m_has_phase) { |
| 702 | event.m_phase = ptr_phase->real(i); | 718 | event.m_phase = ptr_phase->real(i); |
| 703 | } | 719 | } |
| 704 | 720 | ||
| 705 | // Append event | 721 | // Append event |
| 706 | m_events.push_back(event); | 722 | m_events.push_back(event); |
| 707 | - } | 723 | + |
| 724 | + } // endfor: looped over all events | ||
| 708 | 725 | ||
| 709 | // Loop over table and find optional columns | 726 | // Loop over table and find optional columns |
| 710 | for (int i = 0; i < table.ncols(); ++i) { | 727 | for (int i = 0; i < table.ncols(); ++i) { |
| @@ -715,13 +732,19 @@ void GCTAEventList::read_events(const GFitsTable& table) | @@ -715,13 +732,19 @@ void GCTAEventList::read_events(const GFitsTable& table) | ||
| 715 | // Get column name | 732 | // Get column name |
| 716 | const std::string name = col->name(); | 733 | const std::string name = col->name(); |
| 717 | 734 | ||
| 718 | - // Check if column was handled before | ||
| 719 | - if (name == "EVENT_ID" || name == "ENERGY" || | ||
| 720 | - name == "RA" || name == "DEC" || | ||
| 721 | - name == "TIME" || name == "DETX" || | ||
| 722 | - name == "DETY" || name == "PHASE") { | 735 | + // If column was mandatory or optional then skip it ... |
| 736 | + if (name == "EVENT_ID" || | ||
| 737 | + name == "TIME" || | ||
| 738 | + name == "RA" || | ||
| 739 | + name == "DEC" || | ||
| 740 | + name == "ENERGY" || | ||
| 741 | + name == "DETX" || | ||
| 742 | + name == "DETY" || | ||
| 743 | + name == "PHASE") { | ||
| 723 | continue; | 744 | continue; |
| 724 | } | 745 | } |
| 746 | + | ||
| 747 | + // ... otherwise keep a copy | ||
| 725 | else { | 748 | else { |
| 726 | m_columns.push_back(col->clone()); | 749 | m_columns.push_back(col->clone()); |
| 727 | } | 750 | } |
| @@ -738,11 +761,26 @@ void GCTAEventList::read_events(const GFitsTable& table) | @@ -738,11 +761,26 @@ void GCTAEventList::read_events(const GFitsTable& table) | ||
| 738 | /***********************************************************************//** | 761 | /***********************************************************************//** |
| 739 | * @brief Write CTA events into FITS table | 762 | * @brief Write CTA events into FITS table |
| 740 | * | 763 | * |
| 741 | - * @param[in] hdu FITS table HDU. | 764 | + * @param[in] table FITS binary table. |
| 742 | * | 765 | * |
| 743 | - * Write the CTA event list into FITS table. | 766 | + * Write the CTA event list into a FITS binary table. |
| 744 | * | 767 | * |
| 745 | - * @todo Implement agreed column format | 768 | + * The following mandatory columns will be written into the FITS table: |
| 769 | + * | ||
| 770 | + * - EVENT_ID | ||
| 771 | + * - TIME | ||
| 772 | + * - RA | ||
| 773 | + * - DEC | ||
| 774 | + * - ENERGY | ||
| 775 | + * | ||
| 776 | + * If available, also the | ||
| 777 | + * | ||
| 778 | + * - DETX | ||
| 779 | + * - DETY | ||
| 780 | + * - PHASE | ||
| 781 | + * | ||
| 782 | + * columns are written. Any other columns that were read by the read_events() | ||
| 783 | + * method will be also written into the table. | ||
| 746 | ***************************************************************************/ | 784 | ***************************************************************************/ |
| 747 | void GCTAEventList::write_events(GFitsBinTable& hdu) const | 785 | void GCTAEventList::write_events(GFitsBinTable& hdu) const |
| 748 | { | 786 | { |
| @@ -752,51 +790,47 @@ void GCTAEventList::write_events(GFitsBinTable& hdu) const | @@ -752,51 +790,47 @@ void GCTAEventList::write_events(GFitsBinTable& hdu) const | ||
| 752 | // If there are events then write them now | 790 | // If there are events then write them now |
| 753 | if (size() > 0) { | 791 | if (size() > 0) { |
| 754 | 792 | ||
| 755 | - // Allocate required columns | ||
| 756 | - GFitsTableULongCol col_eid = GFitsTableULongCol("EVENT_ID", size()); | ||
| 757 | - GFitsTableDoubleCol col_time = GFitsTableDoubleCol("TIME", size()); | ||
| 758 | - GFitsTableFloatCol col_ra = GFitsTableFloatCol("RA", size()); | ||
| 759 | - GFitsTableFloatCol col_dec = GFitsTableFloatCol("DEC", size()); | ||
| 760 | - GFitsTableFloatCol col_energy = GFitsTableFloatCol("ENERGY", size()); | 793 | + // Allocate mandatory columns |
| 794 | + GFitsTableULongCol col_eid = GFitsTableULongCol("EVENT_ID", size()); | ||
| 795 | + GFitsTableDoubleCol col_time = GFitsTableDoubleCol("TIME", size()); | ||
| 796 | + GFitsTableFloatCol col_ra = GFitsTableFloatCol("RA", size()); | ||
| 797 | + GFitsTableFloatCol col_dec = GFitsTableFloatCol("DEC", size()); | ||
| 798 | + GFitsTableFloatCol col_energy = GFitsTableFloatCol("ENERGY", size()); | ||
| 761 | 799 | ||
| 762 | - // Fill columns | 800 | + // Fill mandatory columns |
| 763 | for (int i = 0; i < size(); ++i) { | 801 | for (int i = 0; i < size(); ++i) { |
| 764 | - col_eid(i) = m_events[i].m_event_id; | ||
| 765 | - col_time(i) = m_events[i].time().convert(m_gti.reference()); | ||
| 766 | - col_ra(i) = m_events[i].dir().dir().ra_deg(); | ||
| 767 | - col_dec(i) = m_events[i].dir().dir().dec_deg(); | ||
| 768 | - col_energy(i) = m_events[i].energy().TeV(); | ||
| 769 | - } // endfor: loop over columns | ||
| 770 | - | ||
| 771 | - // Append columns to table | 802 | + col_eid(i) = m_events[i].m_event_id; |
| 803 | + col_time(i) = m_events[i].time().convert(m_gti.reference()); | ||
| 804 | + col_ra(i) = m_events[i].dir().dir().ra_deg(); | ||
| 805 | + col_dec(i) = m_events[i].dir().dir().dec_deg(); | ||
| 806 | + col_energy(i) = m_events[i].energy().TeV(); | ||
| 807 | + } | ||
| 808 | + | ||
| 809 | + // Append mandatory columns to table | ||
| 772 | hdu.append(col_eid); | 810 | hdu.append(col_eid); |
| 773 | hdu.append(col_time); | 811 | hdu.append(col_time); |
| 774 | hdu.append(col_ra); | 812 | hdu.append(col_ra); |
| 775 | hdu.append(col_dec); | 813 | hdu.append(col_dec); |
| 776 | hdu.append(col_energy); | 814 | hdu.append(col_energy); |
| 777 | 815 | ||
| 778 | - // Fill detector coordinates if required | 816 | + // If available, add detector coordinates in degrees |
| 779 | if (m_has_detxy) { | 817 | if (m_has_detxy) { |
| 780 | - GFitsTableFloatCol col_detx = GFitsTableFloatCol("DETX", size()); | ||
| 781 | - GFitsTableFloatCol col_dety = GFitsTableFloatCol("DETY", size()); | 818 | + GFitsTableFloatCol col_detx = GFitsTableFloatCol("DETX", size()); |
| 819 | + GFitsTableFloatCol col_dety = GFitsTableFloatCol("DETY", size()); | ||
| 782 | for (int i = 0; i < size(); ++i) { | 820 | for (int i = 0; i < size(); ++i) { |
| 783 | col_detx(i) = m_events[i].dir().detx() * gammalib::rad2deg; | 821 | col_detx(i) = m_events[i].dir().detx() * gammalib::rad2deg; |
| 784 | col_dety(i) = m_events[i].dir().dety() * gammalib::rad2deg; | 822 | col_dety(i) = m_events[i].dir().dety() * gammalib::rad2deg; |
| 785 | } | 823 | } |
| 786 | - | ||
| 787 | - // Append columns to table | ||
| 788 | hdu.append(col_detx); | 824 | hdu.append(col_detx); |
| 789 | hdu.append(col_dety); | 825 | hdu.append(col_dety); |
| 790 | } | 826 | } |
| 791 | 827 | ||
| 792 | - // Fill pulse phase if required | 828 | + // If available, add event phase |
| 793 | if (m_has_phase) { | 829 | if (m_has_phase) { |
| 794 | - GFitsTableFloatCol col_phase = GFitsTableFloatCol("PHASE", size()); | 830 | + GFitsTableFloatCol col_phase = GFitsTableFloatCol("PHASE", size()); |
| 795 | for (int i = 0; i < size(); ++i) { | 831 | for (int i = 0; i < size(); ++i) { |
| 796 | col_phase(i) = m_events[i].m_phase; | 832 | col_phase(i) = m_events[i].m_phase; |
| 797 | } | 833 | } |
| 798 | - | ||
| 799 | - // Append column to table | ||
| 800 | hdu.append(col_phase); | 834 | hdu.append(col_phase); |
| 801 | } | 835 | } |
| 802 | 836 |