From 4380d4e282f19b053e03254bf8bac0d8059c333c Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Thu, 25 Feb 2016 16:12:05 +0100 Subject: [PATCH] Adapt to revised GTime operators. --- ChangeLog | 3 ++- NEWS | 2 +- cscripts/cslightcrv.py | 13 ++++++------- cscripts/csobsinfo.py | 8 +++----- src/ctobssim/ctobssim.cpp | 19 +++++++++---------- src/ctselect/ctselect.cpp | 3 +-- 6 files changed, 22 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d90b91..152d70f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2016-02-24 Juergen Knoedlseder +2016-02-25 Juergen Knoedlseder * Version 1.1.0 released ======================== + Adapt to revise GTime operators (#1714) Add publish() methods to tools producing images (#1710) Read ahead output filename in cterror (#1700) Subdivide simulation energy range in ctobssim (#1673) diff --git a/NEWS b/NEWS index 8a744a2..2753ebf 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 1.1.0 Author(s) : Juergen Knoedlseder -24 February 2016 +25 February 2016 1. Introduction diff --git a/cscripts/cslightcrv.py b/cscripts/cslightcrv.py index cf6959e..6b778b9 100755 --- a/cscripts/cslightcrv.py +++ b/cscripts/cslightcrv.py @@ -2,7 +2,7 @@ # ========================================================================== # Light curve generation script. # -# Copyright (C) 2014-2015 Michael Mayer +# Copyright (C) 2014-2016 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,6 +22,7 @@ import gammalib import ctools import sys + # ============ # # csspec class # # ============ # @@ -358,14 +359,12 @@ class cslightcrv(ctools.cscript): tmax = self.m_tbins.tstop(i) # Compute time bin center and time width - tmean = (tmin + tmax) - tmean *= 0.5 - twidth = (tmax - tmin) - twidth *= 0.5 + twidth = 0.5 * (tmax - tmin) # in seconds + tmean = tmin + twidth # Store time as MJD - MJD[i] = tmean.mjd() - e_MJD[i] = twidth.days() + MJD[i] = tmean.mjd() + e_MJD[i] = twidth / gammalib.sec_in_day # in days # Log information if self.logExplicit(): diff --git a/cscripts/csobsinfo.py b/cscripts/csobsinfo.py index 585e784..f63da5a 100755 --- a/cscripts/csobsinfo.py +++ b/cscripts/csobsinfo.py @@ -186,9 +186,7 @@ class csobsinfo(ctools.cscript): obs_gti = obs.events().gti() # Compute mean time and dead time fraction in percent - tmean = (obs_gti.tstart() + obs_gti.tstop()) - tmean *= 0.5 - deadfrac = (1.0-obs.deadc(tmean))*100.0 + deadfrac = (1.0-obs.deadc())*100.0 # Retrieve pointing and store Ra,Dec pnt_dir = obs.pointing().dir() @@ -202,8 +200,8 @@ class csobsinfo(ctools.cscript): # Append time interval self.gti.merge(obs_gti.tstart(), obs_gti.tstop()) - # increment global livetime and ontime - ontime += obs.ontime() + # Increment global livetime and ontime + ontime += obs.ontime() livetime += obs.livetime() # Log the event type (binned or unbinned) diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index 8893fe8..190c616 100644 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -947,17 +947,16 @@ void ctobssim::simulate_interval(GCTAObservation* obs, double flux = get_model_flux(model, emin, emax, dir, rad, indent, wrklog); double rate = flux * area; - double duration = 1800.0; // default: 1800 sec + double duration = 1800.0; // default: 1800 sec if (rate > 0.0) { duration = m_max_photons / rate; - if (duration < 1.0) { // not <1 sec + if (duration < 1.0) { // not <1 sec duration = 1.0; } else if (duration > 180000.0) { // not >50 hr duration = 180000.0; } } - GTime tslice(duration, "sec"); // Skip model if photon rate is 0 if (rate <= 0.0) { @@ -983,16 +982,16 @@ void ctobssim::simulate_interval(GCTAObservation* obs, " photons/s for model \""+mod+"\" exceeds " "maximum allowed photon rate of "+ gammalib::str(m_max_rate)+" photons/s. " - "Please check the model parameters for " - "model \""+mod+"\" or increase the value " - "of the \"maxrate\" parameter."; + "Please check the parameters of model " + "\""+mod+"\" or increase the value of the " + "\"maxrate\" parameter."; throw GException::invalid_value(G_SIMULATE_INTERVAL, msg); } // To reduce memory requirements we split long time intervals into // several time slices GTime tstart = tmin; - GTime tstop = tstart + tslice; + GTime tstop = tstart + duration; // Save state of photon and event counters before doing the // simulation @@ -1009,7 +1008,7 @@ void ctobssim::simulate_interval(GCTAObservation* obs, // Log time slice if (logExplicit()) { - if (tmax - tmin > tslice) { + if (tmax - tmin > duration) { indent++; wrklog->indent(indent); } @@ -1030,11 +1029,11 @@ void ctobssim::simulate_interval(GCTAObservation* obs, // Go to next time slice tstart = tstop; - tstop = tstart + tslice; + tstop = tstart + duration; // Reset indentation if (logExplicit()) { - if (tmax - tmin > tslice) { + if (tmax - tmin > duration) { indent--; wrklog->indent(indent); } diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index cc5d5a9..6b99fd4 100644 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -954,9 +954,8 @@ void ctselect::select_events(GCTAObservation* obs, } // Recompute ontime and livetime. - GTime meantime = 0.5 * (list->gti().tstart() + list->gti().tstop()); obs->ontime(list->gti().ontime()); - obs->livetime(list->gti().ontime() * obs->deadc(meantime)); + obs->livetime(list->gti().ontime() * obs->deadc()); // Return return; -- libgit2 0.21.4