Commit 5d9790f3b4839c85831433d18d3bc7555a0a094b
Merge branch 'integration' into devel
Showing
1 changed file
with
26 additions
and
9 deletions
cscripts/csphagen.py
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | # Computes the PHA spectra for source/background and ARF/RMF files using the |
| 4 | 4 | # reflected region method |
| 5 | 5 | # |
| 6 | -# Copyright (C) 2017-2019 Luigi Tibaldo | |
| 6 | +# Copyright (C) 2017-2020 Luigi Tibaldo | |
| 7 | 7 | # |
| 8 | 8 | # This program is free software: you can redistribute it and/or modify |
| 9 | 9 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -374,7 +374,7 @@ class csphagen(ctools.csobservation): |
| 374 | 374 | # Determine number of background regions to skip |
| 375 | 375 | N_skip = self['bkgregskip'].integer() |
| 376 | 376 | N_start = 1 + N_skip |
| 377 | - N_lim = 1 + 2*N_skip | |
| 377 | + N_lim = 1 + 2 * N_skip | |
| 378 | 378 | |
| 379 | 379 | # Compute the angular separation of reflected regions wrt |
| 380 | 380 | # camera center. The factor 1.05 ensures background regions |
| ... | ... | @@ -397,26 +397,36 @@ class csphagen(ctools.csobservation): |
| 397 | 397 | # regions |
| 398 | 398 | else: |
| 399 | 399 | |
| 400 | - # Log appending of reflected regions | |
| 401 | - msg = ' Use %d reflected regions.' % (N-N_lim) | |
| 402 | - self._log_string(gammalib.NORMAL, msg) | |
| 403 | - | |
| 404 | 400 | # Append reflected regions |
| 405 | - alpha = 360.0 / N | |
| 406 | - for s in range(N_start, N - N_skip): | |
| 407 | - dphi = s * alpha | |
| 401 | + alpha = 360.0 / N | |
| 402 | + dphi_max = 360.0 - alpha * (1 + N_skip) | |
| 403 | + dphi = alpha * (1 + N_skip) | |
| 404 | + while dphi <= dphi_max: | |
| 408 | 405 | ctr_dir = pnt_dir.clone() |
| 409 | 406 | ctr_dir.rotate_deg(posang + dphi, offset) |
| 410 | 407 | region = gammalib.GSkyRegionCircle(ctr_dir, self._rad) |
| 411 | 408 | if self._has_exclusion: |
| 412 | 409 | if self._excl_reg.overlaps(region): |
| 410 | + | |
| 411 | + # Signal region overlap | |
| 413 | 412 | msg = ' Reflected region overlaps with '\ |
| 414 | 413 | 'exclusion region.' |
| 415 | 414 | self._log_string(gammalib.EXPLICIT, msg) |
| 415 | + | |
| 416 | + # If region overlaps with exclusion region | |
| 417 | + # try to increment by 10% of angular step | |
| 418 | + dphi += 0.1 * alpha | |
| 419 | + | |
| 416 | 420 | else: |
| 417 | 421 | regions.append(region) |
| 422 | + dphi += alpha | |
| 418 | 423 | else: |
| 419 | 424 | regions.append(region) |
| 425 | + dphi += alpha | |
| 426 | + | |
| 427 | + # Log number of reflected regions | |
| 428 | + msg = ' Use %d reflected regions.' % (regions.size()) | |
| 429 | + self._log_string(gammalib.NORMAL, msg) | |
| 420 | 430 | |
| 421 | 431 | # Return reflected regions |
| 422 | 432 | return regions |
| ... | ... | @@ -670,6 +680,13 @@ class csphagen(ctools.csobservation): |
| 670 | 680 | # Set On/Off observation ID |
| 671 | 681 | onoff.id(obs.id()) |
| 672 | 682 | |
| 683 | + # Otherwise log observation skipped | |
| 684 | + else: | |
| 685 | + msg = ' Skip because the number %d of regions ' \ | |
| 686 | + 'for background estimation is smaller than ' \ | |
| 687 | + '"bkgregmin"=%d.' % (bkg_reg.size(), self['bkgregmin'].integer()) | |
| 688 | + self._log_string(gammalib.NORMAL, msg) | |
| 689 | + | |
| 673 | 690 | # Construct dictionary with results |
| 674 | 691 | result = {'onoff' : onoff, |
| 675 | 692 | 'bkg_reg' : bkg_reg, | ... | ... |