Commit 05082dd5790f1c3d3798f33d2d1ddf5a09accfc4

Authored by Jürgen Knödlseder
1 parent cc97b107

Use GPhases class for handling of phase selection (#1996)

src/ctselect/ctselect.cpp
... ... @@ -482,8 +482,7 @@ void ctselect::init_members(void)
482 482 m_gtiname.clear();
483 483 m_timemin.clear();
484 484 m_timemax.clear();
485   - m_phasemin.clear();
486   - m_phasemax.clear();
  485 + m_phases.clear();
487 486 m_select_energy = false;
488 487 m_select_roi = false;
489 488 m_select_time = false;
... ... @@ -520,8 +519,7 @@ void ctselect::copy_members(const ctselect& app)
520 519 m_gtiname = app.m_gtiname;
521 520 m_timemin = app.m_timemin;
522 521 m_timemax = app.m_timemax;
523   - m_phasemin = app.m_phasemin;
524   - m_phasemax = app.m_phasemax;
  522 + m_phases = app.m_phases;
525 523 m_select_energy = app.m_select_energy;
526 524 m_select_roi = app.m_select_roi;
527 525 m_select_time = app.m_select_time;
... ... @@ -554,6 +552,9 @@ void ctselect::free_members(void)
554 552 ***************************************************************************/
555 553 void ctselect::get_parameters(void)
556 554 {
  555 + // Clear some members
  556 + m_phases.clear();
  557 +
557 558 // Initialise selection flags
558 559 m_select_energy = false;
559 560 m_select_roi = false;
... ... @@ -661,32 +662,13 @@ void ctselect::get_parameters(void)
661 662 throw GException::invalid_value(G_GET_PARAMETERS, msg);
662 663 }
663 664  
664   - // If phase minimum is smaller than phase maximum then append a
665   - // single interval
666   - if (phase_min < phase_max) {
667   - m_phasemin.push_back(phase_min);
668   - m_phasemax.push_back(phase_max);
669   - }
670   -
671   - // Otherwise if the phase minimum is larger than the maximum then
672   - // consider this a wrap around interval and append one interval
673   - // from phase minimum to 1 and another interval from 0 to phase
674   - // maximum
675   - else if (phase_min > phase_max) {
676   - if (phase_min < 1.0) {
677   - m_phasemin.push_back(phase_min);
678   - m_phasemax.push_back(1.0);
679   - }
680   - if (phase_max > 0.0) {
681   - m_phasemin.push_back(0.0);
682   - m_phasemax.push_back(phase_max);
683   - }
684   - }
  665 + // Append phase interval
  666 + m_phases.append(phase_min, phase_max);
685 667  
686 668 } // endfor: looped over phase selection string
687 669  
688 670 // Signal that a phase selection information is available
689   - m_select_phase = (m_phasemin.size() > 0);
  671 + m_select_phase = (m_phases.size() > 0);
690 672  
691 673 } // endif: phase selection parameters were valid
692 674  
... ... @@ -827,7 +809,7 @@ void ctselect::select_events(GCTAObservation* obs,
827 809 if (list->has_phase()) {
828 810  
829 811 // Loop over phase selections
830   - for (int i = 0; i < m_phasemin.size(); ++i) {
  812 + for (int i = 0; i < m_phases.size(); ++i) {
831 813  
832 814 // Check if phasemax is larger than phasemin
833 815 if (i == 0) {
... ... @@ -840,20 +822,20 @@ void ctselect::select_events(GCTAObservation* obs,
840 822 // Format phase with sufficient accuracy and add to selection string
841 823 char cmin[80];
842 824 char cmax[80];
843   - sprintf(cmin, "%.8f", m_phasemin[i]);
844   - sprintf(cmax, "%.8f", m_phasemax[i]);
  825 + sprintf(cmin, "%.8f", m_phases.pmin(i));
  826 + sprintf(cmax, "%.8f", m_phases.pmax(i));
845 827 selection += "(PHASE >= "+std::string(cmin)+" && PHASE <= "+
846 828 std::string(cmax)+")";
847 829 add = " || ";
848 830 log_value(NORMAL, "Phase range "+gammalib::str(i+1),
849   - gammalib::str(m_phasemin[i])+" - "+
850   - gammalib::str(m_phasemax[i]));
  831 + gammalib::str(m_phases.pmin(i))+" - "+
  832 + gammalib::str(m_phases.pmax(i)));
851 833  
852 834 } // end for loop
853 835  
854 836 // If phase intervals have been appended then close the selection
855 837 // string and take provision for appending another selection
856   - if (m_phasemin.size() > 0) {
  838 + if (m_phases.size() > 0) {
857 839 selection += " )";
858 840 add = " && ";
859 841 }
... ... @@ -1076,6 +1058,11 @@ void ctselect::select_events(GCTAObservation* obs,
1076 1058 list->ebounds(old_ebounds);
1077 1059 }
1078 1060  
  1061 + // If a phase selection has been applied set the phase boundaries
  1062 + if (m_select_phase && list->has_phase()) {
  1063 + list->phases(m_phases);
  1064 + }
  1065 +
1079 1066 // Recompute ontime and livetime.
1080 1067 obs->ontime(list->gti().ontime());
1081 1068 obs->livetime(list->gti().ontime() * obs->deadc());
... ...
src/ctselect/ctselect.hpp
... ... @@ -99,8 +99,7 @@ protected:
99 99 std::vector<std::string> m_gtiname; //!< GTI extension names
100 100 GTime m_timemin; //!< Earliest time
101 101 GTime m_timemax; //!< Latest time
102   - std::vector<double> m_phasemin; //!< Phase bin minima
103   - std::vector<double> m_phasemax; //!< Phase bin maxima
  102 + GPhases m_phases; //!< Phase intervals
104 103 bool m_select_energy; //!< Perform energy selection
105 104 bool m_select_roi; //!< Perform RoI selection
106 105 bool m_select_time; //!< Perform time selection
... ...