Commit 891a9709bc7ed4e292d31de362c4f4f0b227c68f
1 parent
9a5ae140
ctselects now considers previously made RoI and energy selections (only in case …
…no selection was performed)
Showing
2 changed files
with
23 additions
and
3 deletions
cscripts/csspec.py
| ... | ... | @@ -402,6 +402,7 @@ class csspec(ctools.cscript): |
| 402 | 402 | psfcube["nxpix"] = self.m_nxpix |
| 403 | 403 | psfcube["nypix"] = self.m_nypix |
| 404 | 404 | psfcube["enumbins"] = self.m_ebins |
| 405 | + psfcube["anumbins"] = 20 | |
| 405 | 406 | psfcube["emin"] = emin.TeV() |
| 406 | 407 | psfcube["emax"] = emax.TeV() |
| 407 | 408 | psfcube["coordsys"] = self.m_coordsys |
| ... | ... | @@ -505,8 +506,9 @@ class csspec(ctools.cscript): |
| 505 | 506 | |
| 506 | 507 | # Compute Npred value |
| 507 | 508 | Npred = 0.0 |
| 508 | - for observation in like.obs(): | |
| 509 | - Npred += observation.npred(source) | |
| 509 | + if not self.m_binned: | |
| 510 | + for observation in like.obs(): | |
| 511 | + Npred += observation.npred(source) | |
| 510 | 512 | |
| 511 | 513 | # Get differential flux |
| 512 | 514 | fitted_flux = source.spectral().eval(elogmean,gammalib.GTime()) | ... | ... |
src/ctselect/ctselect.cpp
| ... | ... | @@ -631,7 +631,13 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename) |
| 631 | 631 | GCTAEventList* list = |
| 632 | 632 | static_cast<GCTAEventList*>(const_cast<GEvents*>(obs->events())); |
| 633 | 633 | |
| 634 | - // Get energy boundaries | |
| 634 | + // Get existing Roi and energy bounds for possible later use | |
| 635 | + // (will be empty if unavailable) | |
| 636 | + GCTARoi old_roi = list->roi(); | |
| 637 | + GEbounds old_ebounds = list->ebounds(); | |
| 638 | + | |
| 639 | + // Determine new energy boundaries for selection | |
| 640 | + // taking into account previous existing ones | |
| 635 | 641 | double emin = 0.0; |
| 636 | 642 | double emax = 0.0; |
| 637 | 643 | GEbounds ebounds = set_ebounds(obs, list->ebounds()); |
| ... | ... | @@ -888,6 +894,12 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename) |
| 888 | 894 | GCTAInstDir instdir; |
| 889 | 895 | instdir.dir().radec_deg(ra, dec); |
| 890 | 896 | list->roi(GCTARoi(instdir, rad)); |
| 897 | + } // endif: Roi selection was performed | |
| 898 | + | |
| 899 | + else if (old_roi.is_valid()) { | |
| 900 | + // Restore old Roi information in case no selection was performed | |
| 901 | + // and RoI was existing before | |
| 902 | + list->roi(old_roi); | |
| 891 | 903 | } |
| 892 | 904 | |
| 893 | 905 | // 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) |
| 898 | 910 | GEbounds ebounds; |
| 899 | 911 | ebounds.append(GEnergy(emin, "TeV"), GEnergy(emax, "TeV")); |
| 900 | 912 | list->ebounds(ebounds); |
| 913 | + } //endif: energy selection was performed | |
| 914 | + | |
| 915 | + else if (old_ebounds.size() > 0) { | |
| 916 | + // Restore old Ebounds in case no energy selection was performed | |
| 917 | + // and observation already had valid Ebounds | |
| 918 | + list->ebounds(old_ebounds); | |
| 901 | 919 | } |
| 902 | 920 | |
| 903 | 921 | // Recompute ontime and livetime. | ... | ... |