Commit 784a46ef8998d0aabf5a3d0fcf77324508265a29

Authored by Michael Mayer
1 parent f871c5c8

Added sanity checks for selection parameters

src/ctselect/ctselect.cpp
... ... @@ -405,6 +405,9 @@ void ctselect::init_members(void)
405 405 m_infiles.clear();
406 406 m_timemin.clear();
407 407 m_timemax.clear();
  408 + m_select_energy = true;
  409 + m_select_roi = true;
  410 + m_select_time = true;
408 411  
409 412 // Return
410 413 return;
... ... @@ -437,6 +440,9 @@ void ctselect::copy_members(const ctselect& app)
437 440 m_infiles = app.m_infiles;
438 441 m_timemin = app.m_timemin;
439 442 m_timemax = app.m_timemax;
  443 + m_select_energy = app.m_select_energy;
  444 + m_select_roi = app.m_select_roi;
  445 + m_select_time = app.m_select_time;
440 446  
441 447 // Return
442 448 return;
... ... @@ -480,14 +486,49 @@ void ctselect::get_parameters(void)
480 486 // Get parameters
481 487 m_usepnt = (*this)["usepnt"].boolean();
482 488 if (!m_usepnt) {
483   - m_ra = (*this)["ra"].real();
484   - m_dec = (*this)["dec"].real();
  489 +
  490 + // Check RA/DEC parameters for validity to read
  491 + if ((*this)["ra"].is_valid() && (*this)["dec"].is_valid()) {
  492 + m_ra = (*this)["ra"].real();
  493 + m_dec = (*this)["dec"].real();
  494 + m_select_roi = true;
  495 + }
  496 + else {
  497 + m_select_roi = false;
  498 + }
  499 + }
  500 +
  501 + // Check if radius is vaild for a RoI selection
  502 + if (m_select_roi && (*this)["rad"].is_valid()) {
  503 + m_rad = (*this)["rad"].real();
  504 + }
  505 + else {
  506 + m_select_roi = false;
485 507 }
486   - m_rad = (*this)["rad"].real();
487   - m_tmin = (*this)["tmin"].real();
488   - m_tmax = (*this)["tmax"].real();
489   - m_emin = (*this)["emin"].real();
490   - m_emax = (*this)["emax"].real();
  508 +
  509 + // Check for sanity of time selection parameters
  510 + if ((*this)["tmin"].is_valid() && (*this)["tmax"].is_valid()) {
  511 + m_tmin = (*this)["tmin"].real();
  512 + m_tmax = (*this)["tmax"].real();
  513 +
  514 + // Additional check for time values
  515 + if (m_tmin >= m_tmax) {
  516 + m_select_time = false;
  517 + }
  518 + }
  519 + else {
  520 + m_select_time = false;
  521 + }
  522 +
  523 + // Check for sanity of energy selection parameters
  524 + if ((*this)["emin"].is_valid() && (*this)["emax"].is_valid()) {
  525 + m_emin = (*this)["emin"].real();
  526 + m_emax = (*this)["emax"].real();
  527 + }
  528 + else {
  529 + m_select_energy = false;
  530 + }
  531 +
491 532 m_expr = (*this)["expr"].string();
492 533 m_usethres = (*this)["usethres"].string();
493 534  
... ... @@ -560,10 +601,7 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename)
560 601 emax = ebounds.emax(0).TeV();
561 602 }
562 603  
563   - // Analyse parameters to see what selections are required
564   - bool select_time = (m_tmin != 0.0 || m_tmax != 0.0);
565   - bool select_energy = (emin != 0.0 || emax != 0.0);
566   - bool select_roi = ((m_dec != -1.0 && m_ra != -1.0 && m_rad != -1.0) || m_usepnt);
  604 + // Analyse expression to see if a selection is required
567 605 bool select_expr = (gammalib::strip_whitespace(m_expr).length() > 0);
568 606  
569 607 // Set RA/DEC selection. If the "usepnt" parameter is set to true then
... ... @@ -580,7 +618,7 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename)
580 618 // Set time selection interval. We make sure here that the time selection
581 619 // interval cannot be wider than the GTIs covering the data. This is done
582 620 // using GGti's reduce() method.
583   - if (select_time) {
  621 + if (m_select_time) {
584 622  
585 623 // Reduce GTIs to specified time interval. The complicated cast is
586 624 // necessary here because the gti() method is declared const, so
... ... @@ -593,7 +631,7 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename)
593 631 GGti gti = list->gti();
594 632  
595 633 // Make time selection
596   - if (select_time) {
  634 + if (m_select_time) {
597 635  
598 636 // Extract effective time interval in the reference time of the
599 637 // event list. We get this reference time from gti.reference().
... ... @@ -614,7 +652,7 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename)
614 652 } // endif: made time selection
615 653  
616 654 // Make energy selection
617   - if (select_energy) {
  655 + if (m_select_energy) {
618 656  
619 657 // If we have aready a selection than add an "&&" operator
620 658 if (selection.length() > 0) {
... ... @@ -676,7 +714,7 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename)
676 714 } // endif: made energy selection
677 715  
678 716 // Make ROI selection
679   - if (select_roi) {
  717 + if (m_select_roi) {
680 718  
681 719 // If we have aready a selection than add an "&&" operator
682 720 if (selection.length() > 0) {
... ... @@ -807,7 +845,7 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename)
807 845 list = static_cast<GCTAEventList*>(const_cast<GEvents*>(obs->events()));
808 846  
809 847 // If ROI selection has been applied then set the event list ROI
810   - if (select_roi) {
  848 + if (m_select_roi) {
811 849 GCTAInstDir instdir;
812 850 instdir.dir().radec_deg(ra, dec);
813 851 list->roi(GCTARoi(instdir, rad));
... ... @@ -817,7 +855,7 @@ void ctselect::select_events(GCTAObservation* obs, const std::string&amp; filename)
817 855 list->gti(gti);
818 856  
819 857 // If an energy selection has been applied then set the energy boundaries
820   - if (select_energy) {
  858 + if (m_select_energy) {
821 859 GEbounds ebounds;
822 860 ebounds.append(GEnergy(emin, "TeV"), GEnergy(emax, "TeV"));
823 861 list->ebounds(ebounds);
... ...
src/ctselect/ctselect.hpp
... ... @@ -100,6 +100,9 @@ protected:
100 100 std::vector<std::string> m_infiles; //!< Input event filenames
101 101 GTime m_timemin; //!< Earliest time
102 102 GTime m_timemax; //!< Latest time
  103 + bool m_select_energy; //!< Flag that signals to perform energy selection
  104 + bool m_select_roi; //!< Flag that signals to perform energy selection
  105 + bool m_select_time; //!< Flag that signals to perform energy selection
103 106  
104 107 };
105 108  
... ...