Commit 581a934b78c97cd4bd4a740c90a3624180a4f17e

Authored by Jürgen Knödlseder
1 parent 00e1b0bb

Response cubes computed by get_stacked_response() have at least 30 energy bins per decade

cscripts/cspull.py
@@ -180,29 +180,19 @@ class cspull(ctools.cscript): @@ -180,29 +180,19 @@ class cspull(ctools.cscript):
180 self._log.header2('Trial '+str(seed-self._seed+1)) 180 self._log.header2('Trial '+str(seed-self._seed+1))
181 181
182 # If we have a binned obeservation then specify the lower and 182 # If we have a binned obeservation then specify the lower and
183 - # upper energy limit 183 + # upper energy limit in TeV
184 if self._enumbins > 0: 184 if self._enumbins > 0:
185 -  
186 - # Get energy range in TeV  
187 emin = self['emin'].real() 185 emin = self['emin'].real()
188 emax = self['emax'].real() 186 emax = self['emax'].real()
189 -  
190 - # Set number of energy bins to at least 30 per energy decade  
191 - enumbins = int((math.log10(self['emax'].real()) -  
192 - math.log10(self['emin'].real())) * 30.0)  
193 - if self._enumbins > enumbins:  
194 - enumbins = self._enumbins  
195 -  
196 else: 187 else:
197 - emin = None  
198 - emax = None  
199 - enumbins = 0 188 + emin = None
  189 + emax = None
200 190
201 # Simulate events 191 # Simulate events
202 obs = obsutils.sim(self._obs, 192 obs = obsutils.sim(self._obs,
203 emin=emin, 193 emin=emin,
204 emax=emax, 194 emax=emax,
205 - nbins=enumbins, 195 + nbins=self._enumbins,
206 addbounds=True, 196 addbounds=True,
207 seed=seed, 197 seed=seed,
208 binsz=self._binsz, 198 binsz=self._binsz,
cscripts/obsutils.py
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # 18 #
19 # ========================================================================== 19 # ==========================================================================
  20 +import math
20 import gammalib 21 import gammalib
21 import ctools 22 import ctools
22 23
@@ -468,8 +469,12 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, @@ -468,8 +469,12 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
468 """ 469 """
469 Get stacked response cubes 470 Get stacked response cubes
470 471
471 - If no xref and yref arguments have been specified then use the pointing  
472 - information to determine the map centre 472 + The number of energies bins are set to at least 30 bins per decade, and
  473 + the "enumbins" parameter is only used if the number of bins is larger
  474 + than 30 bins per decade.
  475 +
  476 + If the xref or yref arguments are "None" the response cube centre will be
  477 + determined from the pointing information in the observation container.
473 478
474 Parameters 479 Parameters
475 ---------- 480 ----------
@@ -518,11 +523,17 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, @@ -518,11 +523,17 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
518 else: 523 else:
519 usepnt = False 524 usepnt = False
520 525
  526 + # Set number of energy bins to at least 30 per energy decade
  527 + _enumbins = int((math.log10(emax) - math.log10(emin)) * 30.0)
  528 + if enumbins > _enumbins:
  529 + _enumbins = enumbins
  530 +
521 # Compute spatial binning for point spread function and energy dispersion 531 # Compute spatial binning for point spread function and energy dispersion
522 - # cubes 532 + # cubes. The spatial binning is 10 times coarser than the spatial binning
  533 + # of the exposure and background cubes. At least 2 spatial are required.
523 psf_binsz = 10.0 * binsz 534 psf_binsz = 10.0 * binsz
524 - psf_nxpix = min(nxpix // 10, 2) # Make sure result is int  
525 - psf_nypix = min(nypix // 10, 2) # Make sure result is int 535 + psf_nxpix = max(nxpix // 10, 2) # Make sure result is int
  536 + psf_nypix = max(nypix // 10, 2) # Make sure result is int
526 537
527 # Create exposure cube 538 # Create exposure cube
528 expcube = ctools.ctexpcube(obs) 539 expcube = ctools.ctexpcube(obs)
@@ -532,7 +543,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, @@ -532,7 +543,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
532 expcube['binsz'] = binsz 543 expcube['binsz'] = binsz
533 expcube['nxpix'] = nxpix 544 expcube['nxpix'] = nxpix
534 expcube['nypix'] = nypix 545 expcube['nypix'] = nypix
535 - expcube['enumbins'] = enumbins 546 + expcube['enumbins'] = _enumbins
536 expcube['emin'] = emin 547 expcube['emin'] = emin
537 expcube['emax'] = emax 548 expcube['emax'] = emax
538 expcube['coordsys'] = coordsys 549 expcube['coordsys'] = coordsys
@@ -555,7 +566,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, @@ -555,7 +566,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
555 psfcube['binsz'] = psf_binsz 566 psfcube['binsz'] = psf_binsz
556 psfcube['nxpix'] = psf_nxpix 567 psfcube['nxpix'] = psf_nxpix
557 psfcube['nypix'] = psf_nypix 568 psfcube['nypix'] = psf_nypix
558 - psfcube['enumbins'] = enumbins 569 + psfcube['enumbins'] = _enumbins
559 psfcube['emin'] = emin 570 psfcube['emin'] = emin
560 psfcube['emax'] = emax 571 psfcube['emax'] = emax
561 psfcube['coordsys'] = coordsys 572 psfcube['coordsys'] = coordsys
@@ -578,7 +589,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, @@ -578,7 +589,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
578 bkgcube['binsz'] = binsz 589 bkgcube['binsz'] = binsz
579 bkgcube['nxpix'] = nxpix 590 bkgcube['nxpix'] = nxpix
580 bkgcube['nypix'] = nypix 591 bkgcube['nypix'] = nypix
581 - bkgcube['enumbins'] = enumbins 592 + bkgcube['enumbins'] = _enumbins
582 bkgcube['emin'] = emin 593 bkgcube['emin'] = emin
583 bkgcube['emax'] = emax 594 bkgcube['emax'] = emax
584 bkgcube['coordsys'] = coordsys 595 bkgcube['coordsys'] = coordsys
@@ -602,7 +613,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, @@ -602,7 +613,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
602 edispcube['binsz'] = psf_binsz 613 edispcube['binsz'] = psf_binsz
603 edispcube['nxpix'] = psf_nxpix 614 edispcube['nxpix'] = psf_nxpix
604 edispcube['nypix'] = psf_nypix 615 edispcube['nypix'] = psf_nypix
605 - edispcube['enumbins'] = enumbins 616 + edispcube['enumbins'] = _enumbins
606 edispcube['emin'] = emin 617 edispcube['emin'] = emin
607 edispcube['emax'] = emax 618 edispcube['emax'] = emax
608 edispcube['coordsys'] = coordsys 619 edispcube['coordsys'] = coordsys