diff --git a/cscripts/cslightcrv.par b/cscripts/cslightcrv.par index bf0658d..ec4f7bf 100644 --- a/cscripts/cslightcrv.par +++ b/cscripts/cslightcrv.par @@ -33,10 +33,10 @@ tmin, t, a, MJD 51544.5,,,"Lightcurve start time (UTC string, JD, MJD or ME tmax, t, a, MJD 51544.6,,,"Lightcurve stop time (UTC string, JD, MJD or MET in seconds)" tbins, i, a, 5,1,10000, "Number of time bins" tbinfile, f, a, NONE,,, "File defining the time binning" -method, s, a, CUBE, CUBE|ONOFF,, "Analysis method" +method, s, a, 3D, 3D|ONOFF,, "Analysis method" emin, r, a, 0.1,,, "Lower energy limit of events (TeV)" emax, r, a, 100.0,,, "Upper energy limit of events (TeV)" -enumbins, i, a, 0,0,100, "Number of energy bins for binned (0=unbinned for Cube analysis only)" +enumbins, i, a, 0,0,100, "Number of energy bins for binned (0=unbinned for 3D analysis only)" coordsys, s, a, CEL,CEL|GAL,, "Coordinate System" proj, s, a, CAR,AIT|AZP|CAR|GLS|MER|MOL|SFL|SIN|STG|TAN,, "Projection method" xref, r, a, 83.63,0,360, "First coordinate of image/source region center in degrees (RA or galactic l)" diff --git a/cscripts/cslightcrv.py b/cscripts/cslightcrv.py index da06dc1..c6ef94c 100755 --- a/cscripts/cslightcrv.py +++ b/cscripts/cslightcrv.py @@ -112,7 +112,6 @@ class cslightcrv(ctools.csobservation): if not self._onoff: self._stacked = self._is_stacked() - # Query the hidden parameters, just in case self['edisp'].boolean() self['calc_ulim'].boolean() diff --git a/cscripts/csphasecrv.par b/cscripts/csphasecrv.par index 0b15516..49720a3 100644 --- a/cscripts/csphasecrv.par +++ b/cscripts/csphasecrv.par @@ -31,10 +31,10 @@ outfile, f, a, phasecrv.fits,,, "Output fits file name." phbinalg, s, a, LIN,LIN|FILE,, "Algorithm for defining phase bins" phbins, i, a, 5,1,10000, "Number of phase bins" phbinfile, f, a, NONE,,, "File defining the phase binning" -method, s, a, CUBE, CUBE|ONOFF,, "Analysis method" +method, s, a, 3D, 3D|ONOFF,, "Analysis method" emin, r, a, 0.1,,, "Lower energy limit of events (TeV)" emax, r, a, 100.0,,, "Upper energy limit of events (TeV)" -enumbins, i, a, 0,0,100, "Number of energy bins for binned (0=unbinned for Cube analysis only))" +enumbins, i, a, 0,0,100, "Number of energy bins for binned (0=unbinned for 3D analysis only))" coordsys, s, a, CEL,CEL|GAL,, "Coordinate System" proj, s, a, CAR,AIT|AZP|CAR|GLS|MER|MOL|SFL|SIN|STG|TAN,, "Projection method" xref, r, a, 83.63,0,360, "First coordinate of image/source region center in degrees (RA or galactic l)" diff --git a/cscripts/csphasecrv.py b/cscripts/csphasecrv.py index 2d884ad..59d8455 100755 --- a/cscripts/csphasecrv.py +++ b/cscripts/csphasecrv.py @@ -242,17 +242,20 @@ class csphasecrv(ctools.csobservation): # Store fit results phname = str(phmin)+'-'+str(phmax) + # If the model contains the source of interest fill results try: source = self._fitmodels[phname][self._srcname] for par in pars: result['values'][par] = source[par].value() result['values']['e_'+par] = source[par].error() - # Otherwise fills with zeros + + # ... otherwise fills with zeros except: for par in pars: result['values'][par] = 0. result['values']['e_'+par] = 0. + # Append result to list of dictionaries results.append(result) diff --git a/cscripts/obsutils.py b/cscripts/obsutils.py index 941001f..10af62c 100755 --- a/cscripts/obsutils.py +++ b/cscripts/obsutils.py @@ -761,9 +761,10 @@ def get_stacked_obs(cls, obs): # Return new oberservation container return new_obs -# ================================= # + +# ================================ # # Get On/Off observation container # -# ================================= # +# ================================ # def get_onoff_obs(cls, obs): """ Create On/Off observations container from given observations @@ -784,16 +785,17 @@ def get_onoff_obs(cls, obs): if cls._logExplicit(): cls._log.header3('Creating On/Off observations') + # Create On/Off observations phagen = cscripts.csphagen(obs) phagen['inexclusion'] = cls['inexclusion'].value() - phagen['emin'] = cls['emin'].real() - phagen['emax'] = cls['emax'].real() - phagen['enumbins'] = cls['enumbins'].integer() - phagen['ebinalg'] = 'LOG' - phagen['srcshape'] = cls['srcshape'].string() - phagen['coordsys'] = cls['coordsys'].string() + phagen['emin'] = cls['emin'].real() + phagen['emax'] = cls['emax'].real() + phagen['enumbins'] = cls['enumbins'].integer() + phagen['ebinalg'] = 'LOG' + phagen['srcshape'] = cls['srcshape'].string() + phagen['coordsys'] = cls['coordsys'].string() if cls['coordsys'].string() == 'CEL': - phagen['ra'] = cls['xref'].real() + phagen['ra'] = cls['xref'].real() phagen['dec'] = cls['yref'].real() elif cls['coordsys'].string() == 'GAL': phagen['glon'] = cls['xref'].real() @@ -804,15 +806,16 @@ def get_onoff_obs(cls, obs): if cls['bkgmethod'].string() == 'REFLECTED': phagen['bkgregmin'] = cls['bkgregmin'].integer() phagen['maxoffset'] = cls['maxoffset'].real() - phagen['stack'] = True - phagen['etruemin'] = cls['etruemin'].real() - phagen['etruemax'] = cls['etruemax'].real() + phagen['stack'] = True + phagen['etruemin'] = cls['etruemin'].real() + phagen['etruemax'] = cls['etruemax'].real() phagen['etruebins'] = cls['etruebins'].integer() - phagen['chatter'] = cls['chatter'].integer() - phagen['clobber'] = cls['clobber'].boolean() - phagen['debug'] = cls['debug'].boolean() + phagen['chatter'] = cls['chatter'].integer() + phagen['clobber'] = cls['clobber'].boolean() + phagen['debug'] = cls['debug'].boolean() phagen.run() + # Clone resulting observation container onoff_obs = phagen.obs().copy() # On/Off observations are created with CSTAT as default statistic @@ -823,4 +826,5 @@ def get_onoff_obs(cls, obs): for observation in onoff_obs: observation.statistic(cls['statistic'].string()) + # Return On/Off oberservation container return onoff_obs diff --git a/doc/source/users/reference_manual/cslightcrv.rst b/doc/source/users/reference_manual/cslightcrv.rst index 7d22ec8..de23b36 100644 --- a/doc/source/users/reference_manual/cslightcrv.rst +++ b/doc/source/users/reference_manual/cslightcrv.rst @@ -69,8 +69,8 @@ General parameters ``tbinfile [file]`` File defining the time binning. -``method [string]`` - Selects between CUBE analysis (3D spatial/energy likelihood) and ONOFF +``method <3D|ONOFF> [string]`` + Selects between 3D analysis (3D spatial/energy likelihood) and ONOFF analysis (1D likelihood with background from Off regions). ``emin [real]`` diff --git a/doc/source/users/reference_manual/csphasecrv.rst b/doc/source/users/reference_manual/csphasecrv.rst index 214281c..fdfaedb 100644 --- a/doc/source/users/reference_manual/csphasecrv.rst +++ b/doc/source/users/reference_manual/csphasecrv.rst @@ -63,8 +63,8 @@ General parameters ``phbinfile [file]`` File defining the phase binning. -``method [string]`` - Selects between CUBE analysis (3D spatial/energy likelihood) and ONOFF +``method <3D|ONOFF> [string]`` + Selects between 3D analysis (3D spatial/energy likelihood) and ONOFF analysis (1D likelihood with background from Off regions). ``emin [real]`` diff --git a/doc/source/users/tutorials/howto/howto_lightcurve.rst b/doc/source/users/tutorials/howto/howto_lightcurve.rst index 31e8d2e..d45f456 100644 --- a/doc/source/users/tutorials/howto/howto_lightcurve.rst +++ b/doc/source/users/tutorials/howto/howto_lightcurve.rst @@ -37,7 +37,7 @@ The time interval is linearly divided into 20 time bins. Lightcurve start time (UTC string, JD, MJD or MET in seconds) [MJD 51544.5] MJD 59235.5 Lightcurve stop time (UTC string, JD, MJD or MET in seconds) [MJD 51544.6] MJD 59236.0 Number of time bins (1-10000) [5] 20 - Analysis method (CUBE|ONOFF) [CUBE] CUBE + Analysis method (3D|ONOFF) [3D] Lower energy limit of events (TeV) [0.1] Upper energy limit of events (TeV) [100.0] Number of energy bins for binned (0=unbinned for Cube analysis only) (0-100) [0] diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index bea123a..bd6922a 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -1193,6 +1193,7 @@ bool ctool::is_stacked(void) return stacked; } + /***********************************************************************//** * @brief Query user parameters for On/Off analysis * @@ -1200,44 +1201,47 @@ bool ctool::is_stacked(void) * * Queries the parameter "method", and if this is "ONOFF" signal that an On/ * Off analysis is requested. In that case, all necessary input parameters of - * csphagen are queried: "inexclusion", "srcshape", "rad", "bkgmethod", - * "bkgregmin", "maxoffset", "stack", "etruemin", "etruemax", "etruebins" + * csphagen are queried: "inexclusion", "emin", "emax", "enumbins", + * "coordsys", "xref", "yref", "srcshape", "rad", "bkgmethod", "bkgregmin", + * "maxoffset", "etruemin", "etruemax", and "etruebins". * * Using this method assures that the parameters are always queried in the * same order. ***************************************************************************/ bool ctool::is_onoff(void) { - // initialise onoff flag - bool onoff = false; - // query analysis method chosen - if ((*this)["method"].string() == "ONOFF"){ - //modify onoff flag - onoff = true; - //query csphagen parameters - (*this)["inexclusion"].filename(); - (*this)["emin"].real(); - (*this)["emax"].real(); - (*this)["enumbins"].integer(); - (*this)["coordsys"].string(); - (*this)["xref"].real(); - (*this)["yref"].real(); - if ((*this)["srcshape"].string() == "CIRCLE"){ - (*this)["rad"].real(); - } - if ((*this)["bkgmethod"].string() == "REFLECTED"){ - (*this)["bkgregmin"].integer(); - } - (*this)["maxoffset"].real(); - (*this)["etruemin"].real(); - (*this)["etruemax"].real(); - (*this)["etruebins"].integer(); - } + // Set onoff flag + bool onoff = ((*this)["method"].string() == "ONOFF"); + + // Query analysis method chosen + if (onoff) { + + // Query csphagen parameters + (*this)["inexclusion"].filename(); + (*this)["emin"].real(); + (*this)["emax"].real(); + (*this)["enumbins"].integer(); + (*this)["coordsys"].string(); + (*this)["xref"].real(); + (*this)["yref"].real(); + if ((*this)["srcshape"].string() == "CIRCLE"){ + (*this)["rad"].real(); + } + if ((*this)["bkgmethod"].string() == "REFLECTED"){ + (*this)["bkgregmin"].integer(); + } + (*this)["maxoffset"].real(); + (*this)["etruemin"].real(); + (*this)["etruemax"].real(); + (*this)["etruebins"].integer(); + + } // endif: method was ONOFF // Return onoff flag return onoff; } + /***********************************************************************//** * @brief Set response for all CTA observations in container * diff --git a/test/test_cscript.py b/test/test_cscript.py index e20d6c4..3b32b78 100755 --- a/test/test_cscript.py +++ b/test/test_cscript.py @@ -456,7 +456,7 @@ class Test(test): # TODO: implement # Test is_onoff() method - # TODO: implemen + # TODO: implement # Test set_response() method # TODO: implement diff --git a/test/test_cslightcrv.py b/test/test_cslightcrv.py index 07ba68c..c69b271 100755 --- a/test/test_cslightcrv.py +++ b/test/test_cslightcrv.py @@ -77,7 +77,7 @@ class Test(test): ' inmodel="'+self._model+'" srcname="Crab"'+ \ ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ ' tbinalg="LIN" tmin="MJD 51544.50" tmax="MJD 51544.53"'+ \ - ' tbins=3 method="CUBE" enumbins=0 emin=0.1 emax=100.0'+ \ + ' tbins=3 method="3D" enumbins=0 emin=0.1 emax=100.0'+ \ ' outfile="lightcurve_cmd1.fits"'+ \ ' logfile="cslightcrv_cmd1.log" chatter=1' @@ -97,7 +97,7 @@ class Test(test): ' inmodel="'+self._model+'" srcname="Crab"'+ \ ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ ' tbinalg="LIN" tmin="MJD 51544.50" tmax="MJD 51544.53"'+ \ - ' tbins=3 method="CUBE" enumbins=0 emin=0.1 emax=100.0'+ \ + ' tbins=3 method="3D" enumbins=0 emin=0.1 emax=100.0'+ \ ' outfile="lightcurve_cmd1.fits"'+ \ ' logfile="cslightcrv_cmd2.log" debug=yes' @@ -127,7 +127,7 @@ class Test(test): lcrv['tmin'] = 'MJD 51544.50' lcrv['tmax'] = 'MJD 51544.53' lcrv['tbins'] = 3 - lcrv['method'] = 'CUBE' + lcrv['method'] = '3D' lcrv['enumbins'] = 0 lcrv['emin'] = 0.1 lcrv['emax'] = 100.0 @@ -164,7 +164,7 @@ class Test(test): lcrv['irf'] = self._irf lcrv['tbinalg'] = 'FILE' lcrv['tbinfile'] = 'cslightcrv_py2.dat' - lcrv['method'] = 'CUBE' + lcrv['method'] = '3D' lcrv['enumbins'] = 0 lcrv['emin'] = 0.1 lcrv['emax'] = 100.0 @@ -194,7 +194,7 @@ class Test(test): lcrv['caldb'] = self._caldb lcrv['irf'] = self._irf lcrv['tbinalg'] = 'GTI' - lcrv['method'] = 'CUBE' + lcrv['method'] = '3D' lcrv['enumbins'] = 0 lcrv['emin'] = 0.1 lcrv['emax'] = 100.0 @@ -219,7 +219,7 @@ class Test(test): lcrv['tmin'] = 'MJD 51544.50' lcrv['tmax'] = 'MJD 51544.53' lcrv['tbins'] = 2 - lcrv['method'] = 'CUBE' + lcrv['method'] = '3D' lcrv['emin'] = 0.1 lcrv['emax'] = 100.0 lcrv['enumbins'] = 10 diff --git a/test/test_csphasecrv.py b/test/test_csphasecrv.py index 0a03563..bb318c1 100755 --- a/test/test_csphasecrv.py +++ b/test/test_csphasecrv.py @@ -77,7 +77,7 @@ class Test(test): cmd = csphasecrv+' inobs="'+self._phased_events+'"'+ \ ' inmodel="'+self._model+'" srcname="Crab"'+ \ ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ - ' phbinalg="LIN" phbins=5 method="CUBE"'+ \ + ' phbinalg="LIN" phbins=5 method="3D"'+ \ ' enumbins=0 emin=0.1 emax=100.0'+ \ ' outfile="csphasecrv_cmd1.fits"'+ \ ' logfile="csphasecrv_cmd1.log" chatter=1' @@ -97,7 +97,7 @@ class Test(test): cmd = csphasecrv+' inobs="events_that_do_not_exist.fits"'+ \ ' inmodel="'+self._model+'" srcname="Crab"'+ \ ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ - ' phbinalg="LIN" phbins=5 method="CUBE"'+ \ + ' phbinalg="LIN" phbins=5 method="3D"'+ \ ' enumbins=0 emin=0.1 emax=100.0'+ \ ' outfile="csphasecrv_cmd2.fits"'+ \ ' logfile="csphasecrv_cmd2.log" debug=yes chatter=1' @@ -126,7 +126,7 @@ class Test(test): pcrv['irf'] = self._irf pcrv['phbinalg'] = 'LIN' pcrv['phbins'] = 5 - pcrv['method'] = 'CUBE' + pcrv['method'] = '3D' pcrv['enumbins'] = 0 pcrv['emin'] = 0.1 pcrv['emax'] = 100.0 @@ -163,7 +163,7 @@ class Test(test): pcrv['irf'] = self._irf pcrv['phbinalg'] = 'FILE' pcrv['phbinfile'] = 'csphasecrv_py2.dat' - pcrv['method'] = 'CUBE' + pcrv['method'] = '3D' pcrv['enumbins'] = 0 pcrv['emin'] = 0.1 pcrv['emax'] = 100.0 @@ -194,7 +194,7 @@ class Test(test): pcrv['irf'] = self._irf pcrv['phbinalg'] = 'LIN' pcrv['phbins'] = 5 - pcrv['method'] = 'CUBE' + pcrv['method'] = '3D' pcrv['enumbins'] = 0 pcrv['emin'] = 0.1 pcrv['emax'] = 100.0 @@ -218,7 +218,7 @@ class Test(test): pcrv['irf'] = self._irf pcrv['phbinalg'] = 'LIN' pcrv['phbins'] = 2 - pcrv['method'] = 'CUBE' + pcrv['method'] = '3D' pcrv['emin'] = 0.1 pcrv['emax'] = 100.0 pcrv['enumbins'] = 10