Commit b6c5a7499466e81336f2bcadd816234138bed065

Authored by Maria Haupt
1 parent 464e5f56

reference manual and tests for ctedispcube, minor changes in source code (#1724)

doc/source/reference_manual/ctedispcube.rst 0 → 100644
  1 +.. _ctedispcube:
  2 +
  3 +ctedispcube
  4 +=========
  5 +
  6 +Generate energy dispersion cube for a counts cube.
  7 +
  8 +
  9 +Synopsis
  10 +--------
  11 +
  12 +This tool generates an energy dispersion cube for a counts cube. An energy
  13 +dispersion cube is a 4-dimensional cube spanned by Right Ascension or
  14 +Galactic longitude, Declination or Galactic latitude, energy, and fraction
  15 +between recontructed and true photon energy. The energy binning of the cube
  16 +may be either linear, logarithmic, or custom defined using an input file.
  17 +
  18 +ctedispcube requires on input the event list or observation definition file
  19 +that has been used in the generation of the counts cube using :doc:`ctbin`.
  20 +
  21 +It is not recommended to use the counts cube for the energy dispersion
  22 +cube definition, although this is formally possible by specifying the counts
  23 +cube as ``incube`` parameter. This leads however to a large FITS file on
  24 +output since the number of bins in the counts cube will be multiplied by
  25 +the number of offset angle bins (typically 200). Since the energy dispersion
  26 +varies only little over the field of view of the camera it is
  27 +recommended to use a rather coarse spatial binning to keep the file size
  28 +manageable (with a typical value of ``binsz=1.0``).
  29 +
  30 +ctedispcube generates an energy dispersion cube FITS file comprising three
  31 +extensions. The primary extension contains a 3-dimensional image that contains
  32 +the energy disperison values. The energy and fraction dimensions of the enrgy
  33 +dispersion cube are folded into the 3rd dimension of the FITS image. The next
  34 +extension named ``EBOUNDS`` contains a binary table that defines the energy
  35 +boundaries of the exposure cube. The last extension named ``DELTAS`` contains
  36 +a binary table that defines the fraction between recontructed and true photon
  37 +energy.
  38 +
  39 +
  40 +General parameters
  41 +------------------
  42 +
  43 +``inobs [file]``
  44 + Input event list or observation definition XML file.
  45 +
  46 +``incube [file]``
  47 + Input counts cube file to extract energy dispersion cube definition.
  48 +
  49 +``caldb [string]``
  50 + Calibration database.
  51 +
  52 +``irf [string]``
  53 + Instrument response function.
  54 +
  55 +``(edisp = no) [boolean]``
  56 + Apply energy dispersion for response computation.
  57 +
  58 +``outcube [file]``
  59 + Output energy dispersion cube file.
  60 +
  61 +``ebinalg <FILE|LIN|LOG> [string]``
  62 + Algorithm for defining energy bins.
  63 +
  64 +``emin [real]``
  65 + Lower energy value for first energy bin (in TeV).
  66 +
  67 +``emax [real]``
  68 + Upper energy value for last energy bin (in TeV).
  69 +
  70 +``enumbins [integer]``
  71 + Number of energy bins.
  72 +
  73 +``ebinfile [file]``
  74 + Name of the file containing the energy bin definition.
  75 +
  76 +``(usepnt = no) [boolean]``
  77 + Use CTA pointing direction for cube centre instead of xref/yref parameters?
  78 +
  79 +``nxpix [integer]``
  80 + Number of cube bins in Right Ascension or Galactic longitude.
  81 +
  82 +``nypix [integer]``
  83 + Number of cube bins in Declination or Galactic latitude.
  84 +
  85 +``binsz [real]``
  86 + Cube bin size (in degrees/pixel).
  87 +
  88 +``coordsys <CEL|GAL> [string]``
  89 + Coordinate system (CEL - celestial, GAL - galactic).
  90 +
  91 +``xref [real]``
  92 + Right Ascension / Galactic longitude of cube centre (J2000, in degrees).
  93 +
  94 +``yref [real]``
  95 + Declination / Galactic latitude of cube centre (J2000, in degrees).
  96 +
  97 +``proj <AIT|AZP|CAR|MER|MOL|STG|TAN> [string]``
  98 + Projection method.
  99 +
  100 +``(mmax = 10.0) [real]``
  101 + Upper bound of fraction between recontructed and true photon energy.
  102 +
  103 +``(migrabins = 200) [integer]``
  104 + Number of migration bins.
  105 +
  106 +
  107 +Standard parameters
  108 +-------------------
  109 +
  110 +``(chatter = 2) [integer]``
  111 + Verbosity of the executable:
  112 + chatter = 0: no information will be logged
  113 +
  114 + chatter = 1: only errors will be logged
  115 +
  116 + chatter = 2: errors and actions will be logged
  117 +
  118 + chatter = 3: report about the task execution
  119 +
  120 + chatter = 4: detailed report about the task execution
  121 +
  122 +``(clobber = yes) [boolean]``
  123 + Specifies whether an existing output energy dispersion cube file should be overwritten.
  124 +
  125 +``(debug = no) [boolean]``
  126 + Enables debug mode. In debug mode the executable will dump any log file output to the console.
  127 +
  128 +``(mode = ql) [string]``
  129 + Mode of automatic parameters (default is "ql", i.e. "query and learn").
  130 +
  131 +``(logfile = ctedispcube.log) [string]``
  132 + Name of log file.
  133 +
  134 +
  135 +Related tools or scripts
  136 +------------------------
  137 +
  138 +:doc:`ctbin`
... ...
doc/source/reference_manual/ctpsfcube.rst
... ... @@ -20,7 +20,7 @@ ctpsfcube requires on input the event list or observation definition file
20 20 that has been used in the generation of the counts cube using :doc:`ctbin`.
21 21  
22 22 It is not recommended to use the counts cube for the point spread function
23   -cube definition, although this is formally possibly by specifying the counts
  23 +cube definition, although this is formally possible by specifying the counts
24 24 cube as ``incube`` parameter. This leads however to a large FITS file on
25 25 output since the number of bins in the counts cube will be multiplied by
26 26 the number of offset angle bins (typically 200). Since the point spread
... ...
doc/source/reference_manual/index.rst
... ... @@ -19,6 +19,7 @@ ctools
19 19 ctbkgcube --- Generates background cube <ctbkgcube>
20 20 ctbutterfly --- Compute butterfly <ctbutterfly>
21 21 ctcubemask --- Filter counts cube <ctcubemask>
  22 + ctedispcube --- Generates energy dispersion cube <ctedispcube>
22 23 ctexpcube --- Generates exposure cube <ctexpcube>
23 24 ctlike --- Performs maximum likelihood fitting <ctlike>
24 25 ctmodel --- Computes model counts cube <ctmodel>
... ...
src/ctedispcube/ctedispcube.cpp
... ... @@ -376,8 +376,8 @@ void ctedispcube::get_parameters(void)
376 376 std::string incube = (*this)["incube"].filename();
377 377  
378 378 // Get additional binning parameters
379   - double amax = (*this)["amax"].real();
380   - int anumbins = (*this)["anumbins"].integer();
  379 + double mmax = (*this)["mmax"].real();
  380 + int migrabins = (*this)["migrabins"].integer();
381 381  
382 382 // Check for filename validity
383 383 if ((incube == "NONE") || (gammalib::strip_whitespace(incube) == "")) {
... ... @@ -386,7 +386,7 @@ void ctedispcube::get_parameters(void)
386 386 GCTAEventCube cube = create_cube(m_obs);
387 387  
388 388 // Define edisp cube
389   - m_edispcube = GCTACubeEdisp(cube, amax, anumbins);
  389 + m_edispcube = GCTACubeEdisp(cube, mmax, migrabins);
390 390  
391 391 }
392 392  
... ... @@ -397,7 +397,7 @@ void ctedispcube::get_parameters(void)
397 397 GCTAEventCube cube(incube);
398 398  
399 399 // Define edisp cube
400   - m_edispcube = GCTACubeEdisp(cube, amax, anumbins);
  400 + m_edispcube = GCTACubeEdisp(cube, mmax, migrabins);
401 401  
402 402 } // endelse: cube loaded from file
403 403  
... ...
src/ctedispcube/ctedispcube.par
... ... @@ -4,14 +4,14 @@
4 4 # #
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7   -# File: ctpsfcube.par #
8   -# Version: 1.0.0 #
  7 +# File: ctedispcube.par #
  8 +# Version: 1.1.0 #
9 9 # #
10   -# Author: Chia-Chun Lu #
11   -# c.lu@mpi-hd.mpg.de #
12   -# MPIK #
  10 +# Author: Maria Haupt #
  11 +# maria.haupt@desy.de #
  12 +# DESY #
13 13 # #
14   -# Purpose: Parameter file for the ctpsfcube application #
  14 +# Purpose: Parameter file for the ctedispcube application #
15 15 # #
16 16 #############################################################################
17 17 #
... ... @@ -48,8 +48,8 @@ proj, s, a, &quot;CAR&quot;, AIT|AZP|CAR|MER|MOL|STG|TAN,, &quot;Projection method&quot;
48 48 #
49 49 # Angular separation binning parameters
50 50 #======================================
51   -amax, r, h, 0.3,,, "Upper bound of angular separation between true and measued photon direction (degrees)"
52   -anumbins, i, h, 200,,, "Number of angular separation bins"
  51 +mmax, r, h, 10.0,,, "Upper bound of fraction between recontructed and true photon energy"
  52 +migrabins, i, h, 100,,, "Number of migration bins"
53 53  
54 54 #
55 55 # Standard parameters
... ...
test/test_ctedispcube.py 0 → 100755
  1 +#! /usr/bin/env python
  2 +# ==========================================================================
  3 +# This scripts performs unit tests for the ctedispcube tool.
  4 +#
  5 +# Copyright (C) 2014-2016 Juergen Knoedlseder
  6 +#
  7 +# This program is free software: you can redistribute it and/or modify
  8 +# it under the terms of the GNU General Public License as published by
  9 +# the Free Software Foundation, either version 3 of the License, or
  10 +# (at your option) any later version.
  11 +#
  12 +# This program is distributed in the hope that it will be useful,
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 +# GNU General Public License for more details.
  16 +#
  17 +# You should have received a copy of the GNU General Public License
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 +#
  20 +# ==========================================================================
  21 +import gammalib
  22 +import ctools
  23 +
  24 +
  25 +# ============================= #
  26 +# Test class for ctedispcube tool #
  27 +# ============================= #
  28 +class Test(gammalib.GPythonTestSuite):
  29 + """
  30 + Test class for ctedispcube tool.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + gammalib.GPythonTestSuite.__init__(self)
  39 +
  40 + # Set members
  41 + self.events_name = "data/crab_events.fits"
  42 + self.caldb = "irf"
  43 + self.irf = "cta_dummy_irf"
  44 +
  45 + # Return
  46 + return
  47 +
  48 + # Set test functions
  49 + def set(self):
  50 + """
  51 + Set all test functions.
  52 + """
  53 + # Set test name
  54 + self.name("ctedispcube")
  55 +
  56 + # Append tests
  57 + self.append(self.test_functional, "Test ctedispcube functionality")
  58 +
  59 + # Return
  60 + return
  61 +
  62 + # Test ctedispcube functionnality
  63 + def test_functional(self):
  64 + """
  65 + Test ctedispcube functionnality.
  66 + """
  67 + # Set-up ctedispcube
  68 + edispcube = ctools.ctedispcube()
  69 + edispcube["inobs"] = self.events_name
  70 + edispcube["incube"] = "NONE"
  71 + edispcube["outcube"] = "edispcube.fits"
  72 + edispcube["caldb"] = self.caldb
  73 + edispcube["irf"] = self.irf
  74 + edispcube["ebinalg"] = "LOG"
  75 + edispcube["emin"] = 0.1
  76 + edispcube["emax"] = 100
  77 + edispcube["enumbins"] = 20
  78 + edispcube["nxpix"] = 10
  79 + edispcube["nypix"] = 10
  80 + edispcube["binsz"] = 0.4
  81 + edispcube["coordsys"] = "CEL"
  82 + edispcube["proj"] = "CAR"
  83 + edispcube["xref"] = 83.63
  84 + edispcube["yref"] = 22.01
  85 + edispcube["mmax"] = 0.3
  86 + edispcube["migrabins"] = 10
  87 +
  88 + # Run tool
  89 + self.test_try("Run ctedispcube")
  90 + try:
  91 + edispcube.run()
  92 + self.test_try_success()
  93 + #except Exception as e:
  94 + # msg = "Exception occured in ctedispcube: %s." % (e,)
  95 + except:
  96 + msg = "Exception occured in ctedispcube."
  97 + self.test_try_failure(msg)
  98 +
  99 + # Save EDISP cube
  100 + self.test_try("Save EDISP cube")
  101 + try:
  102 + edispcube.save()
  103 + self.test_try_success()
  104 + #except Exception as e:
  105 + # msg = "Exception occured in saving EDISP cube: %s." % (e,)
  106 + except:
  107 + msg = "Exception occured in saving EDISP cubes."
  108 + self.test_try_failure(msg)
  109 +
  110 + # Return
  111 + return
... ...
test/test_ctools.sh
... ... @@ -43,6 +43,7 @@ ctselect=../src/ctselect/ctselect
43 43 ctskymap=../src/ctskymap/ctskymap
44 44 ctexpcube=../src/ctexpcube/ctexpcube
45 45 ctpsfcube=../src/ctpsfcube/ctpsfcube
  46 +ctedispcube=../src/ctedispcube/ctedispcube
46 47 ctbkgcube=../src/ctbkgcube/ctbkgcube
47 48 ctcubemask=../src/ctcubemask/ctcubemask
48 49 ctbutterfly=../src/ctbutterfly/ctbutterfly
... ... @@ -272,6 +273,57 @@ $ECHO &quot; ok&quot;
272 273  
273 274  
274 275 #
  276 +# Test ctedispcube
  277 +# ==============
  278 +$ECHO -n "Test ctedispcube: "
  279 +#
  280 +# Run 1
  281 +$ctedispcube inobs="data/crab_events.fits" \
  282 + incube="NONE" \
  283 + outcube="edispcube1.fits" \
  284 + caldb="irf" \
  285 + irf="cta_dummy_irf" \
  286 + emin=0.1 \
  287 + emax=100.0 \
  288 + enumbins=20 \
  289 + nxpix=10 \
  290 + nypix=10 \
  291 + binsz=0.4 \
  292 + coordsys="CEL" \
  293 + xref=83.63 \
  294 + yref=22.01 \
  295 + proj="CAR" \
  296 + mmax=10.0 \
  297 + migrabins=100
  298 +$ECHO -n "."
  299 +if [ -s "edispcube1.fits" ]
  300 +then
  301 +$ECHO -n "."
  302 +else
  303 +$ECHO " edispcube1.fits file is not found"
  304 +exit 1
  305 +fi
  306 +#
  307 +# Run 2
  308 +$ctedispcube inobs="events.fits" \
  309 + incube="cntmap2.fits" \
  310 + outcube="edispcube2.fits" \
  311 + caldb="irf" \
  312 + irf="cta_dummy_irf" \
  313 + mmax=10.0 \
  314 + migrabins=5
  315 +$ECHO -n "."
  316 +if [ -s "edispcube2.fits" ]
  317 +then
  318 +$ECHO -n "."
  319 +else
  320 +$ECHO " edispcube2.fits file is not found"
  321 +exit 1
  322 +fi
  323 +$ECHO " ok"
  324 +
  325 +
  326 +#
275 327 # Test ctbkgcube
276 328 # ==============
277 329 $ECHO -n "Test ctbkgcube: "
... ...