Commit 8fc4e141a422254ee4bdd05ae677d35d762d4f35
Committed by
Jürgen Knödlseder
1 parent
035428e5
Modified as per issue description
Showing
3 changed files
with
46 additions
and
6 deletions
src/ctselect/ctselect.cpp
| ... | ... | @@ -478,6 +478,7 @@ void ctselect::init_members(void) |
| 478 | 478 | m_phases.clear(); |
| 479 | 479 | m_select_energy = false; |
| 480 | 480 | m_select_phase = false; |
| 481 | + m_forcesel = false; | |
| 481 | 482 | |
| 482 | 483 | // Return |
| 483 | 484 | return; |
| ... | ... | @@ -506,6 +507,7 @@ void ctselect::copy_members(const ctselect& app) |
| 506 | 507 | m_phases = app.m_phases; |
| 507 | 508 | m_select_energy = app.m_select_energy; |
| 508 | 509 | m_select_phase = app.m_select_phase; |
| 510 | + m_forcesel = app.m_forcesel; | |
| 509 | 511 | |
| 510 | 512 | // Return |
| 511 | 513 | return; |
| ... | ... | @@ -548,6 +550,9 @@ void ctselect::get_parameters(void) |
| 548 | 550 | // Query the RoI |
| 549 | 551 | GCTAPointing pnt; |
| 550 | 552 | GCTARoi roi = get_roi(pnt); |
| 553 | + // Signal whether the RoI selection should be enforced | |
| 554 | + // even when leading to invalid RoI | |
| 555 | + m_forcesel = (has_par("forcesel") && (*this)["forcesel"].boolean()); | |
| 551 | 556 | |
| 552 | 557 | // Query Good Time Intervals. The GammaLib time reference is specified |
| 553 | 558 | // as a dummy argument since the relevant intervals will be queried later |
| ... | ... | @@ -730,6 +735,9 @@ void ctselect::select_events(GCTAObservation* obs, |
| 730 | 735 | // Signal that RoI selection should be performed |
| 731 | 736 | bool select_roi = roi.is_valid(); |
| 732 | 737 | |
| 738 | + //Create boolean to remember if RoI selection is enforced regardless of its validity | |
| 739 | + bool enforced_roi = false; | |
| 740 | + | |
| 733 | 741 | // Set time selection interval. We make sure here that the time selection |
| 734 | 742 | // interval cannot be wider than the GTIs covering the data. This is done |
| 735 | 743 | // using GGti's reduce() method. |
| ... | ... | @@ -913,8 +921,38 @@ void ctselect::select_events(GCTAObservation* obs, |
| 913 | 921 | GSkyDir centre; |
| 914 | 922 | centre.radec_deg(ra, dec); |
| 915 | 923 | double distance = centre.dist_deg(roi_centre); |
| 916 | - if (distance + rad > roi_radius) { | |
| 917 | - rad = roi_radius - distance; | |
| 924 | + // If the requested RoI and selected RoI are centred at the same position | |
| 925 | + // and the requested RoI is bigger then the original | |
| 926 | + // keep original radius | |
| 927 | + // RoIs same centre = distance < 1.e-4 | |
| 928 | + // to cope with numerical precision limitations | |
| 929 | + if (distance < 1.e-4 && rad > roi_radius) { | |
| 930 | + rad = roi_radius; | |
| 931 | + } | |
| 932 | + //Otherwise, check if requested RoI is enclosed within original RoI | |
| 933 | + else { | |
| 934 | + if (distance + rad > roi_radius) { | |
| 935 | + //If selection is enforced log warning and store | |
| 936 | + if (m_forcesel){ | |
| 937 | + enforced_roi = true; | |
| 938 | + log_string(TERSE, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
| 939 | + log_string(TERSE,"Enforced RoI selection leading to inconsistent RoI. "\ | |
| 940 | + "RoI of data: Centre(RA,DEC)=("+gammalib::str(ra)+", "+ | |
| 941 | + gammalib::str(dec)+") deg, Radius="+gammalib::str(rad)+ | |
| 942 | + " deg. Requested RoI: Centre(RA,DEC)=("+ | |
| 943 | + gammalib::str(roi_centre.ra_deg())+", "+ | |
| 944 | + gammalib::str(roi_centre.dec_deg())+") deg, Radius="+ | |
| 945 | + gammalib::str(roi_radius)+" deg. The resulting event list "\ | |
| 946 | + "file is not usable for likelihood analysis"); | |
| 947 | + log_string(TERSE, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
| 948 | + } | |
| 949 | + // Otherwise, throw an exception | |
| 950 | + else { | |
| 951 | + std::string message; | |
| 952 | + message = "Invalid RoI selection: the new RoI must be enclosed in the original RoI"; | |
| 953 | + throw GException::invalid_value(G_RUN, message); | |
| 954 | + } | |
| 955 | + } | |
| 918 | 956 | } |
| 919 | 957 | } |
| 920 | 958 | |
| ... | ... | @@ -1011,8 +1049,8 @@ void ctselect::select_events(GCTAObservation* obs, |
| 1011 | 1049 | // closed later |
| 1012 | 1050 | list->fetch(); |
| 1013 | 1051 | |
| 1014 | - // If RoI selection has been applied then set the event list RoI | |
| 1015 | - if (select_roi) { | |
| 1052 | + // If RoI selection has been applied without forcing then set the event list RoI | |
| 1053 | + if (select_roi && !enforced_roi) { | |
| 1016 | 1054 | GCTAInstDir instdir; |
| 1017 | 1055 | instdir.dir().radec_deg(ra, dec); |
| 1018 | 1056 | list->roi(GCTARoi(instdir, rad)); | ... | ... |
src/ctselect/ctselect.hpp
| ... | ... | @@ -87,6 +87,7 @@ protected: |
| 87 | 87 | std::string m_expr; //!< Selection expression |
| 88 | 88 | std::string m_usethres; //!< Energy threshold type |
| 89 | 89 | GChatter m_chatter; //!< Chattiness |
| 90 | + bool m_forcesel; //!< Enforce RoI selection | |
| 90 | 91 | |
| 91 | 92 | // Protected members |
| 92 | 93 | std::vector<std::string> m_infiles; //!< Input event filenames | ... | ... |
src/ctselect/ctselect.par
| ... | ... | @@ -23,10 +23,11 @@ prefix, s, h, selected_,,, "Prefix for event lists in observation definition XML |
| 23 | 23 | # |
| 24 | 24 | # Selection parameters |
| 25 | 25 | #===================== |
| 26 | -usepnt, b, h, no,,, "Use pointing instead of RA/DEC parameters?" | |
| 26 | +usepnt, b, h, yes,,, "Use pointing instead of RA/DEC parameters?" | |
| 27 | 27 | ra, r, a, 83.63,0,360, "RA for ROI centre (degrees)" |
| 28 | 28 | dec, r, a, 22.51,-90,90, "Dec for ROI centre (degrees)" |
| 29 | -rad, r, a, 3.0,0,180, "Radius of ROI (degrees)" | |
| 29 | +rad, r, a, 3.0,0,180, "Radius of ROI around pointing or specified RA/DEC (degrees)" | |
| 30 | +forcesel,b, h, no,,, "Force RoI selection even if it produces invalid RoI" | |
| 30 | 31 | tmin, t, a, NONE,,, "Start time (UTC string, JD, MJD or MET in seconds)" |
| 31 | 32 | tmax, t, a, NONE,,, "Stop time (UTC string, JD, MJD or MET in seconds)" |
| 32 | 33 | emin, r, a, 0.1,,, "Lower energy limit (TeV)" | ... | ... |