Commit c9445eb451f000f6a251f01250899b35f8c1021e
1 parent
ed36f092
added multiple phase interval selection in ctselect
Showing
3 changed files
with
53 additions
and
20 deletions
src/ctselect/ctselect.cpp
| @@ -595,7 +595,7 @@ void ctselect::get_parameters(void) | @@ -595,7 +595,7 @@ void ctselect::get_parameters(void) | ||
| 595 | m_select_energy = false; | 595 | m_select_energy = false; |
| 596 | } | 596 | } |
| 597 | 597 | ||
| 598 | - // Check for sanity of phase selection parameters | 598 | + /* // Check for sanity of phase selection parameters |
| 599 | if ((*this)["phasemin"].is_valid() && (*this)["phasemax"].is_valid()) { | 599 | if ((*this)["phasemin"].is_valid() && (*this)["phasemax"].is_valid()) { |
| 600 | m_phasemin = (*this)["phasemin"].real(); | 600 | m_phasemin = (*this)["phasemin"].real(); |
| 601 | m_phasemax = (*this)["phasemax"].real(); | 601 | m_phasemax = (*this)["phasemax"].real(); |
| @@ -603,6 +603,21 @@ void ctselect::get_parameters(void) | @@ -603,6 +603,21 @@ void ctselect::get_parameters(void) | ||
| 603 | } | 603 | } |
| 604 | else { | 604 | else { |
| 605 | m_select_phase = false; | 605 | m_select_phase = false; |
| 606 | + }*/ | ||
| 607 | + | ||
| 608 | + // Check for sanity of phase selection parameters | ||
| 609 | + if ((*this)["phase"].is_valid()) { | ||
| 610 | + std::string phase_expr = (*this)["phase"].string(); | ||
| 611 | + std::vector<std::string> phase_splits = gammalib::split(phase_expr, ","); | ||
| 612 | + for (int i=0; i < phase_splits.size(); i++) { | ||
| 613 | + std::vector<std::string> phase_toks = gammalib::split(phase_splits[i], ":"); | ||
| 614 | + m_phasemin.push_back( std::strtod(phase_toks[0].c_str(), NULL) ); | ||
| 615 | + m_phasemax.push_back( std::strtod(phase_toks[1].c_str(), NULL) ); | ||
| 616 | + } | ||
| 617 | + m_select_phase = true; | ||
| 618 | + } | ||
| 619 | + else { | ||
| 620 | + m_select_phase = false; | ||
| 606 | } | 621 | } |
| 607 | 622 | ||
| 608 | // Get other User parameters | 623 | // Get other User parameters |
| @@ -739,21 +754,36 @@ void ctselect::select_events(GCTAObservation* obs, | @@ -739,21 +754,36 @@ void ctselect::select_events(GCTAObservation* obs, | ||
| 739 | if (m_select_phase) { | 754 | if (m_select_phase) { |
| 740 | // Check if event_list has phase | 755 | // Check if event_list has phase |
| 741 | if (list->has_phase()) { | 756 | if (list->has_phase()) { |
| 742 | - // Check if phasemax is larger than phasemin | ||
| 743 | - if (m_phasemax > m_phasemin) { | ||
| 744 | - // Format phase with sufficient accuracy and add to selection string | ||
| 745 | - char cmin[80]; | ||
| 746 | - char cmax[80]; | ||
| 747 | - sprintf(cmin, "%.8f", m_phasemin); | ||
| 748 | - sprintf(cmax, "%.8f", m_phasemax); | ||
| 749 | - selection += add + "PHASE >= "+std::string(cmin)+" && PHASE <= "+std::string(cmax); | ||
| 750 | - add = " && "; | ||
| 751 | - log_value(NORMAL, "Phase range", | ||
| 752 | - gammalib::str(m_phasemin)+" - "+gammalib::str(m_phasemax)); | ||
| 753 | - } | ||
| 754 | - else { | ||
| 755 | - log << "Invalid values for phasemin and phasemax. "; | ||
| 756 | - log << "Phase selection skipped." << std::endl; | 757 | + bool is_first = true; |
| 758 | + // Loop over phase selections | ||
| 759 | + for (int i=0; i < m_phasemin.size(); i++) { | ||
| 760 | + // Check if phasemax is larger than phasemin | ||
| 761 | + if (m_phasemax[i] > m_phasemin[i]) { | ||
| 762 | + if (is_first) { | ||
| 763 | + selection += add + "( "; | ||
| 764 | + } | ||
| 765 | + else { | ||
| 766 | + selection += add; | ||
| 767 | + } | ||
| 768 | + // Format phase with sufficient accuracy and add to selection string | ||
| 769 | + char cmin[80]; | ||
| 770 | + char cmax[80]; | ||
| 771 | + sprintf(cmin, "%.8f", m_phasemin[i]); | ||
| 772 | + sprintf(cmax, "%.8f", m_phasemax[i]); | ||
| 773 | + selection += "(PHASE >= "+std::string(cmin)+" && PHASE <= "+std::string(cmax)+")"; | ||
| 774 | + add = " || "; | ||
| 775 | + is_first = false; | ||
| 776 | + log_value(NORMAL, "Phase range", | ||
| 777 | + gammalib::str(m_phasemin[i])+" - "+gammalib::str(m_phasemax[i])); | ||
| 778 | + } | ||
| 779 | + else { | ||
| 780 | + log << "Invalid values for phasemin and phasemax in interval "<<i<<". "; | ||
| 781 | + log << "Phase selection skipped for this interval." << std::endl; | ||
| 782 | + } | ||
| 783 | + } // end for loop | ||
| 784 | + if (!is_first) { | ||
| 785 | + add = " && "; | ||
| 786 | + selection += " )"; | ||
| 757 | } | 787 | } |
| 758 | } | 788 | } |
| 759 | else { | 789 | else { |
src/ctselect/ctselect.hpp
| @@ -97,8 +97,10 @@ protected: | @@ -97,8 +97,10 @@ protected: | ||
| 97 | double m_tmax; //!< Stop time | 97 | double m_tmax; //!< Stop time |
| 98 | double m_emin; //!< Lower energy | 98 | double m_emin; //!< Lower energy |
| 99 | double m_emax; //!< Upper energy | 99 | double m_emax; //!< Upper energy |
| 100 | - double m_phasemin; //!< Lower phase | ||
| 101 | - double m_phasemax; //!< Upper phase | 100 | + // double m_phasemin; //!< Lower phase |
| 101 | + //double m_phasemax; //!< Upper phase | ||
| 102 | + std::vector<double> m_phasemin; //!< Lower phase | ||
| 103 | + std::vector<double> m_phasemax; //!< Upper phase | ||
| 102 | std::string m_expr; //!< Selection expression | 104 | std::string m_expr; //!< Selection expression |
| 103 | std::string m_usethres; //!< Energy threshold type | 105 | std::string m_usethres; //!< Energy threshold type |
| 104 | GChatter m_chatter; //!< Chattiness | 106 | GChatter m_chatter; //!< Chattiness |
src/ctselect/ctselect.par
| @@ -32,8 +32,9 @@ tmin, r, a, 0.0,,, "Start time (CTA MET in seconds)" | @@ -32,8 +32,9 @@ tmin, r, a, 0.0,,, "Start time (CTA MET in seconds)" | ||
| 32 | tmax, r, a, 0.0,,, "End time (CTA MET in seconds)" | 32 | tmax, r, a, 0.0,,, "End time (CTA MET in seconds)" |
| 33 | emin, r, a, 0.1,,, "Lower energy limit (TeV)" | 33 | emin, r, a, 0.1,,, "Lower energy limit (TeV)" |
| 34 | emax, r, a, 100.0,,, "Upper energy limit (TeV)" | 34 | emax, r, a, 100.0,,, "Upper energy limit (TeV)" |
| 35 | -phasemin,r, h, 0.0,0,1, "Lower phase limit" | ||
| 36 | -phasemax,r, h, 1.0,0,1, "Upper phase limit" | 35 | +phase, s, h, "NONE",,, "Phase expression in the format phasemin0:phasemax0,phasemin1:phasemax1" |
| 36 | +#phasemin,r, h, 0.0,0,1, "Lower phase limit" | ||
| 37 | +#phasemax,r, h, 1.0,0,1, "Upper phase limit" | ||
| 37 | expr, s, h, "",,, "Additional selection expression" | 38 | expr, s, h, "",,, "Additional selection expression" |
| 38 | usethres,s, h, "NONE",NONE|DEFAULT|USER,, "Energy threshold type" | 39 | usethres,s, h, "NONE",NONE|DEFAULT|USER,, "Energy threshold type" |
| 39 | 40 |