Commit d7db885409caaa627bdf574f1d97d6fdeb5b5224
1 parent
1c4721c7
cssens now is able to respect existing energy cuts
Showing
1 changed file
with
34 additions
and
1 deletions
cscripts/cssens.py
| ... | ... | @@ -270,8 +270,41 @@ class cssens(ctools.cscript): |
| 270 | 270 | # Loop over all observations in container |
| 271 | 271 | for obs in self._obs: |
| 272 | 272 | |
| 273 | + # Get observation energy boundaries | |
| 274 | + obs_ebounds = obs.events().ebounds() | |
| 275 | + | |
| 276 | + # Get minimum and maximum energy | |
| 277 | + obs_emin = obs_ebounds.emin() | |
| 278 | + obs_emax = obs_ebounds.emax() | |
| 279 | + | |
| 280 | + # Case A: bin fully contained in observation ebounds | |
| 281 | + if obs_emin <= emin and obs_emax >= emax: | |
| 282 | + ebounds = gammalib.GEbounds(emin, emax) | |
| 283 | + | |
| 284 | + # Case B: bin fully outside of obs ebounds | |
| 285 | + elif emax < obs_emin or emin > obs_emax: | |
| 286 | + | |
| 287 | + # Set zero range (inspired by ctselect) | |
| 288 | + e0 = gammalib.GEnergy(0.0, "TeV") | |
| 289 | + ebounds = gammalib.GEbounds(e0, e0) | |
| 290 | + | |
| 291 | + # Case C: bin partly overlapping with observation ebounds | |
| 292 | + else: | |
| 293 | + | |
| 294 | + # Set energy range as obs ebounds were fully contained inside energy bin | |
| 295 | + set_emin = emin | |
| 296 | + set_emax = emax | |
| 297 | + | |
| 298 | + # Adjust energy bin to respect observation energy boundary | |
| 299 | + if emin < obs_emin: | |
| 300 | + set_emin = obs_emin | |
| 301 | + if emax > obs_emax: | |
| 302 | + set_emax = obs_emax | |
| 303 | + | |
| 304 | + #Set energy boundaries | |
| 305 | + ebounds = gammalib.GEbounds(set_emin, set_emax) | |
| 306 | + | |
| 273 | 307 | # Set energy boundaries |
| 274 | - ebounds = gammalib.GEbounds(emin, emax) | |
| 275 | 308 | obs.events().ebounds(ebounds) |
| 276 | 309 | |
| 277 | 310 | # Return | ... | ... |