Commit ea342bf13896ba2a31b08a826b960c5d4007f9ea

Authored by Jürgen Knödlseder
1 parent 239868b4

Add optional cntcube parameter to obsutils.get_stacked_response()

Showing 1 changed file with 25 additions and 15 deletions
cscripts/obsutils.py
... ... @@ -517,7 +517,7 @@ def set_observations(ra, dec, rad, tstart, duration, emin, emax, irf, caldb,
517 517 def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
518 518 emin=0.1, emax=100.0, enumbins=20, edisp=False,
519 519 coordsys='GAL', proj='TAN', addbounds=False,
520   - log=False, debug=False, chatter=2):
  520 + cntcube=None, log=False, debug=False, chatter=2):
521 521 """
522 522 Get stacked response cubes
523 523  
... ... @@ -556,6 +556,8 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
556 556 Projection
557 557 addbounds : bool, optional
558 558 Add boundaries at observation energies
  559 + cntcube : `~gammalib.GCTAEventCube`, optional
  560 + Counts cube
559 561 log : bool, optional
560 562 Create log file(s)
561 563 debug : bool, optional
... ... @@ -637,23 +639,26 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
637 639 # for the counts cube since no interpolation should be actually done
638 640 # for the background cube.
639 641 bkgcube = ctools.ctbkgcube(obs)
640   - bkgcube['incube'] = 'NONE'
  642 + if cntcube != None:
  643 + bkgcube.cntcube(cntcube)
  644 + else:
  645 + bkgcube['incube'] = 'NONE'
  646 + bkgcube['ebinalg'] = 'LOG'
  647 + bkgcube['binsz'] = binsz
  648 + bkgcube['nxpix'] = nxpix
  649 + bkgcube['nypix'] = nypix
  650 + bkgcube['enumbins'] = enumbins
  651 + bkgcube['emin'] = emin
  652 + bkgcube['emax'] = emax
  653 + bkgcube['coordsys'] = coordsys
  654 + bkgcube['proj'] = proj
  655 + if not usepnt:
  656 + bkgcube['xref'] = xref
  657 + bkgcube['yref'] = yref
641 658 bkgcube['usepnt'] = usepnt
642   - bkgcube['ebinalg'] = 'LOG'
643   - bkgcube['binsz'] = binsz
644   - bkgcube['nxpix'] = nxpix
645   - bkgcube['nypix'] = nypix
646   - bkgcube['enumbins'] = enumbins
647   - bkgcube['emin'] = emin
648   - bkgcube['emax'] = emax
649   - bkgcube['coordsys'] = coordsys
650   - bkgcube['proj'] = proj
651 659 bkgcube['addbounds'] = addbounds
652 660 bkgcube['debug'] = debug
653 661 bkgcube['chatter'] = chatter
654   - if not usepnt:
655   - bkgcube['xref'] = xref
656   - bkgcube['yref'] = yref
657 662 if log:
658 663 bkgcube.logFileOpen()
659 664 bkgcube.run()
... ... @@ -735,6 +740,10 @@ def get_stacked_obs(cls, obs):
735 740 cntcube['proj'] = cls['proj'].string()
736 741 cntcube.run()
737 742  
  743 + # Store counts cube so that we can use it to build the background
  744 + # cube
  745 + cube = cntcube.cube().copy()
  746 +
738 747 # Write header
739 748 if cls._logExplicit():
740 749 cls._log.header3('Creating stacked response')
... ... @@ -751,7 +760,8 @@ def get_stacked_obs(cls, obs):
751 760 enumbins=cls['enumbins'].integer(),
752 761 edisp=cls['edisp'].boolean(),
753 762 coordsys=cls['coordsys'].string(),
754   - proj=cls['proj'].string())
  763 + proj=cls['proj'].string(),
  764 + cntcube=cube)
755 765  
756 766 # Retrieve a new oberservation container
757 767 new_obs = cntcube.obs().copy()
... ...