From 891a9709bc7ed4e292d31de362c4f4f0b227c68f Mon Sep 17 00:00:00 2001 From: mimayer Date: Fri, 17 Jul 2015 12:10:20 +0200 Subject: [PATCH] ctselects now considers previously made RoI and energy selections (only in case no selection was performed) --- cscripts/csspec.py | 6 ++++-- src/ctselect/ctselect.cpp | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cscripts/csspec.py b/cscripts/csspec.py index 2b1a92b..4e3ce60 100755 --- a/cscripts/csspec.py +++ b/cscripts/csspec.py @@ -402,6 +402,7 @@ class csspec(ctools.cscript): psfcube["nxpix"] = self.m_nxpix psfcube["nypix"] = self.m_nypix psfcube["enumbins"] = self.m_ebins + psfcube["anumbins"] = 20 psfcube["emin"] = emin.TeV() psfcube["emax"] = emax.TeV() psfcube["coordsys"] = self.m_coordsys @@ -505,8 +506,9 @@ class csspec(ctools.cscript): # Compute Npred value Npred = 0.0 - for observation in like.obs(): - Npred += observation.npred(source) + if not self.m_binned: + for observation in like.obs(): + Npred += observation.npred(source) # Get differential flux fitted_flux = source.spectral().eval(elogmean,gammalib.GTime()) diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index 5db0822..dc6ff70 100644 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -631,7 +631,13 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename) GCTAEventList* list = static_cast(const_cast(obs->events())); - // Get energy boundaries + // Get existing Roi and energy bounds for possible later use + // (will be empty if unavailable) + GCTARoi old_roi = list->roi(); + GEbounds old_ebounds = list->ebounds(); + + // Determine new energy boundaries for selection + // taking into account previous existing ones double emin = 0.0; double emax = 0.0; GEbounds ebounds = set_ebounds(obs, list->ebounds()); @@ -888,6 +894,12 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename) GCTAInstDir instdir; instdir.dir().radec_deg(ra, dec); list->roi(GCTARoi(instdir, rad)); + } // endif: Roi selection was performed + + else if (old_roi.is_valid()) { + // Restore old Roi information in case no selection was performed + // and RoI was existing before + list->roi(old_roi); } // Set event list GTI (in any case as any event list has a GTI) @@ -898,6 +910,12 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename) GEbounds ebounds; ebounds.append(GEnergy(emin, "TeV"), GEnergy(emax, "TeV")); list->ebounds(ebounds); + } //endif: energy selection was performed + + else if (old_ebounds.size() > 0) { + // Restore old Ebounds in case no energy selection was performed + // and observation already had valid Ebounds + list->ebounds(old_ebounds); } // Recompute ontime and livetime. -- libgit2 0.21.4