From c9445eb451f000f6a251f01250899b35f8c1021e Mon Sep 17 00:00:00 2001 From: ldivenere Date: Thu, 13 Apr 2017 00:08:11 +0200 Subject: [PATCH] added multiple phase interval selection in ctselect --- src/ctselect/ctselect.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++---------------- src/ctselect/ctselect.hpp | 6 ++++-- src/ctselect/ctselect.par | 5 +++-- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index 180776b..ab3b984 100644 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -595,7 +595,7 @@ void ctselect::get_parameters(void) m_select_energy = false; } - // Check for sanity of phase selection parameters + /* // Check for sanity of phase selection parameters if ((*this)["phasemin"].is_valid() && (*this)["phasemax"].is_valid()) { m_phasemin = (*this)["phasemin"].real(); m_phasemax = (*this)["phasemax"].real(); @@ -603,6 +603,21 @@ void ctselect::get_parameters(void) } else { m_select_phase = false; + }*/ + + // Check for sanity of phase selection parameters + if ((*this)["phase"].is_valid()) { + std::string phase_expr = (*this)["phase"].string(); + std::vector phase_splits = gammalib::split(phase_expr, ","); + for (int i=0; i < phase_splits.size(); i++) { + std::vector phase_toks = gammalib::split(phase_splits[i], ":"); + m_phasemin.push_back( std::strtod(phase_toks[0].c_str(), NULL) ); + m_phasemax.push_back( std::strtod(phase_toks[1].c_str(), NULL) ); + } + m_select_phase = true; + } + else { + m_select_phase = false; } // Get other User parameters @@ -739,21 +754,36 @@ void ctselect::select_events(GCTAObservation* obs, if (m_select_phase) { // Check if event_list has phase if (list->has_phase()) { - // Check if phasemax is larger than phasemin - if (m_phasemax > m_phasemin) { - // Format phase with sufficient accuracy and add to selection string - char cmin[80]; - char cmax[80]; - sprintf(cmin, "%.8f", m_phasemin); - sprintf(cmax, "%.8f", m_phasemax); - selection += add + "PHASE >= "+std::string(cmin)+" && PHASE <= "+std::string(cmax); - add = " && "; - log_value(NORMAL, "Phase range", - gammalib::str(m_phasemin)+" - "+gammalib::str(m_phasemax)); - } - else { - log << "Invalid values for phasemin and phasemax. "; - log << "Phase selection skipped." << std::endl; + bool is_first = true; + // Loop over phase selections + for (int i=0; i < m_phasemin.size(); i++) { + // Check if phasemax is larger than phasemin + if (m_phasemax[i] > m_phasemin[i]) { + if (is_first) { + selection += add + "( "; + } + else { + selection += add; + } + // Format phase with sufficient accuracy and add to selection string + char cmin[80]; + char cmax[80]; + sprintf(cmin, "%.8f", m_phasemin[i]); + sprintf(cmax, "%.8f", m_phasemax[i]); + selection += "(PHASE >= "+std::string(cmin)+" && PHASE <= "+std::string(cmax)+")"; + add = " || "; + is_first = false; + log_value(NORMAL, "Phase range", + gammalib::str(m_phasemin[i])+" - "+gammalib::str(m_phasemax[i])); + } + else { + log << "Invalid values for phasemin and phasemax in interval "< m_phasemin; //!< Lower phase + std::vector m_phasemax; //!< Upper phase std::string m_expr; //!< Selection expression std::string m_usethres; //!< Energy threshold type GChatter m_chatter; //!< Chattiness diff --git a/src/ctselect/ctselect.par b/src/ctselect/ctselect.par index 641fb2b..44b72c4 100644 --- a/src/ctselect/ctselect.par +++ b/src/ctselect/ctselect.par @@ -32,8 +32,9 @@ tmin, r, a, 0.0,,, "Start time (CTA MET in seconds)" tmax, r, a, 0.0,,, "End time (CTA MET in seconds)" emin, r, a, 0.1,,, "Lower energy limit (TeV)" emax, r, a, 100.0,,, "Upper energy limit (TeV)" -phasemin,r, h, 0.0,0,1, "Lower phase limit" -phasemax,r, h, 1.0,0,1, "Upper phase limit" +phase, s, h, "NONE",,, "Phase expression in the format phasemin0:phasemax0,phasemin1:phasemax1" +#phasemin,r, h, 0.0,0,1, "Lower phase limit" +#phasemax,r, h, 1.0,0,1, "Upper phase limit" expr, s, h, "",,, "Additional selection expression" usethres,s, h, "NONE",NONE|DEFAULT|USER,, "Energy threshold type" -- libgit2 0.21.4