Commit 89cecd4a8dc4bbe61de2d555f061ade20cec803b

Authored by Jürgen Knödlseder
1 parent 145877c4

Adapt to new GCaldb interface.

A new logic has been implemented concerning the caldb parameter. If the name specified by caldb is a directory, the directory is set as the root directory of the calibration database. The file specified by irf must then be a file provided within this root directory.

If the name is not a directory it is used as the mission name that is used to build the calibration directory path. The irf is then the response name.
scripts/cspull.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # This script generates the pull distribution for all model parameters. 3 # This script generates the pull distribution for all model parameters.
4 # 4 #
5 -# Copyright (C) 2011-2013 Juergen Knoedlseder 5 +# Copyright (C) 2011-2014 Juergen Knoedlseder
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 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 8 # it under the terms of the GNU General Public License as published by
@@ -97,7 +97,7 @@ class cspull(GApplication): @@ -97,7 +97,7 @@ class cspull(GApplication):
97 pars.append(GApplicationPar("srcmdl","f","a","$GAMMALIB/share/models/crab.xml","","","Source model")) 97 pars.append(GApplicationPar("srcmdl","f","a","$GAMMALIB/share/models/crab.xml","","","Source model"))
98 pars.append(GApplicationPar("outfile","f","a","pull.dat","","","Output file name")) 98 pars.append(GApplicationPar("outfile","f","a","pull.dat","","","Output file name"))
99 pars.append(GApplicationPar("ntrials","i","a","10","","","Number of trials")) 99 pars.append(GApplicationPar("ntrials","i","a","10","","","Number of trials"))
100 - pars.append(GApplicationPar("caldb","s","a","$GAMMALIB/share/caldb/cta","","","Calibration database")) 100 + pars.append(GApplicationPar("caldb","s","h","","","","Calibration database"))
101 pars.append(GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function")) 101 pars.append(GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function"))
102 pars.append(GApplicationPar("ra","r","a","83.6331","0","360","RA of pointing (deg)")) 102 pars.append(GApplicationPar("ra","r","a","83.6331","0","360","RA of pointing (deg)"))
103 pars.append(GApplicationPar("dec","r","a","22.0145","-90","90","Dec of pointing (deg)")) 103 pars.append(GApplicationPar("dec","r","a","22.0145","-90","90","Dec of pointing (deg)"))
scripts/obsutils.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # This script provides a number of functions that are useful for handling 2 # This script provides a number of functions that are useful for handling
3 # CTA observations. 3 # CTA observations.
4 # 4 #
5 -# Copyright (C) 2011-2013 Juergen Knoedlseder 5 +# Copyright (C) 2011-2014 Juergen Knoedlseder
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 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 8 # it under the terms of the GNU General Public License as published by
@@ -18,136 +18,136 @@ @@ -18,136 +18,136 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # 19 #
20 # ========================================================================== 20 # ==========================================================================
21 -from ctools import *  
22 -from gammalib import * 21 +import ctools
  22 +import gammalib
23 23
24 24
25 # ===================== # 25 # ===================== #
26 # Simulate observations # 26 # Simulate observations #
27 # ===================== # 27 # ===================== #
28 def sim(obs, log=False, debug=False, seed=0, nbins=0, binsz=0.05, npix=200): 28 def sim(obs, log=False, debug=False, seed=0, nbins=0, binsz=0.05, npix=200):
29 - """  
30 - Simulate events for all observations in the container.  
31 -  
32 - Parameters:  
33 - obs - Observation container  
34 - Keywords:  
35 - log - Create log file(s)  
36 - debug - Create screen dump  
37 - seed - Seed value for simulations (default: 0)  
38 - nbins - Number of energy bins (default: 0=unbinned)  
39 - binsz - Pixel size for binned simulation (deg/pixel)  
40 - npix - Number of pixels in X and Y for binned simulation  
41 - """  
42 - # Allocate ctobssim application and set parameters  
43 - sim = ctobssim(obs)  
44 - sim['seed'].integer(seed)  
45 -  
46 - # Optionally open the log file  
47 - if log:  
48 - sim.logFileOpen() 29 + """
  30 + Simulate events for all observations in the container.
  31 +
  32 + Parameters:
  33 + obs - Observation container
  34 + Keywords:
  35 + log - Create log file(s)
  36 + debug - Create screen dump
  37 + seed - Seed value for simulations (default: 0)
  38 + nbins - Number of energy bins (default: 0=unbinned)
  39 + binsz - Pixel size for binned simulation (deg/pixel)
  40 + npix - Number of pixels in X and Y for binned simulation
  41 + """
  42 + # Allocate ctobssim application and set parameters
  43 + sim = ctools.ctobssim(obs)
  44 + sim['seed'].integer(seed)
  45 +
  46 + # Optionally open the log file
  47 + if log:
  48 + sim.logFileOpen()
49 49
50 - # Optionally switch-on debugging model  
51 - if debug:  
52 - sim["debug"].boolean(True)  
53 -  
54 - # Run ctobssim application. This will loop over all observations in the  
55 - # container and simulation the events for each observation. Note that  
56 - # events are not added together, they still apply to each observation  
57 - # separately.  
58 - sim.run()  
59 -  
60 - # Binned option?  
61 - if nbins > 0:  
62 -  
63 - # Determine common energy boundaries for observations  
64 - emin = None  
65 - emax = None  
66 - for run in sim.obs():  
67 - run_emin = run.events().ebounds().emin().TeV()  
68 - run_emax = run.events().ebounds().emax().TeV()  
69 - if emin == None:  
70 - emin = run_emin  
71 - elif run_emin > emin:  
72 - emin = run_emin  
73 - if emax == None:  
74 - emax = run_emax  
75 - elif run_emax > emax:  
76 - emax = run_emax  
77 -  
78 - # Allocate ctbin application and set parameters  
79 - bin = ctbin(sim.obs())  
80 - bin["ebinalg"].string("LOG")  
81 - bin["emin"].real(emin)  
82 - bin["emax"].real(emax)  
83 - bin["enumbins"].integer(nbins)  
84 - bin["usepnt"].boolean(True) # Use pointing for map centre  
85 - bin["nxpix"].integer(npix)  
86 - bin["nypix"].integer(npix)  
87 - bin["binsz"].real(binsz)  
88 - bin["coordsys"].string("GAL")  
89 - bin["proj"].string("TAN")  
90 -  
91 - # Optionally open the log file  
92 - if log:  
93 - bin.logFileOpen() 50 + # Optionally switch-on debugging model
  51 + if debug:
  52 + sim["debug"].boolean(True)
  53 +
  54 + # Run ctobssim application. This will loop over all observations in the
  55 + # container and simulation the events for each observation. Note that
  56 + # events are not added together, they still apply to each observation
  57 + # separately.
  58 + sim.run()
  59 +
  60 + # Binned option?
  61 + if nbins > 0:
  62 +
  63 + # Determine common energy boundaries for observations
  64 + emin = None
  65 + emax = None
  66 + for run in sim.obs():
  67 + run_emin = run.events().ebounds().emin().TeV()
  68 + run_emax = run.events().ebounds().emax().TeV()
  69 + if emin == None:
  70 + emin = run_emin
  71 + elif run_emin > emin:
  72 + emin = run_emin
  73 + if emax == None:
  74 + emax = run_emax
  75 + elif run_emax > emax:
  76 + emax = run_emax
  77 +
  78 + # Allocate ctbin application and set parameters
  79 + bin = ctools.ctbin(sim.obs())
  80 + bin["ebinalg"].string("LOG")
  81 + bin["emin"].real(emin)
  82 + bin["emax"].real(emax)
  83 + bin["enumbins"].integer(nbins)
  84 + bin["usepnt"].boolean(True) # Use pointing for map centre
  85 + bin["nxpix"].integer(npix)
  86 + bin["nypix"].integer(npix)
  87 + bin["binsz"].real(binsz)
  88 + bin["coordsys"].string("GAL")
  89 + bin["proj"].string("TAN")
  90 +
  91 + # Optionally open the log file
  92 + if log:
  93 + bin.logFileOpen()
94 94
95 - # Optionally switch-on debugging model  
96 - if debug:  
97 - bin["debug"].boolean(True) 95 + # Optionally switch-on debugging model
  96 + if debug:
  97 + bin["debug"].boolean(True)
98 98
99 - # Run ctbin application. This will loop over all observations in  
100 - # the container and bin the events in counts maps  
101 - bin.run()  
102 -  
103 - # Make a deep copy of the observation that will be returned  
104 - # (the ctbin object will go out of scope one the function is  
105 - # left)  
106 - obs = bin.obs().copy()  
107 -  
108 - else:  
109 -  
110 - # Make a deep copy of the observation that will be returned  
111 - # (the ctobssim object will go out of scope one the function is  
112 - # left)  
113 - obs = sim.obs().copy() 99 + # Run ctbin application. This will loop over all observations in
  100 + # the container and bin the events in counts maps
  101 + bin.run()
  102 +
  103 + # Make a deep copy of the observation that will be returned
  104 + # (the ctbin object will go out of scope one the function is
  105 + # left)
  106 + obs = bin.obs().copy()
  107 +
  108 + else:
  109 +
  110 + # Make a deep copy of the observation that will be returned
  111 + # (the ctobssim object will go out of scope one the function is
  112 + # left)
  113 + obs = sim.obs().copy()
114 114
115 - # Delete the simulation  
116 - del sim  
117 -  
118 - # Return observation container  
119 - return obs 115 + # Delete the simulation
  116 + del sim
  117 +
  118 + # Return observation container
  119 + return obs
120 120
121 121
122 # ================ # 122 # ================ #
123 # Fit observations # 123 # Fit observations #
124 # ================ # 124 # ================ #
125 def fit(obs, log=False, debug=False): 125 def fit(obs, log=False, debug=False):
126 - """  
127 - Perform maximum likelihood fitting of observations in the container.  
128 -  
129 - Parameters:  
130 - obs - Observation container  
131 - Keywords:  
132 - log - Create log file(s)  
133 - debug - Create screen dump  
134 - """  
135 - # Allocate ctlike application  
136 - like = ctlike(obs)  
137 -  
138 - # Optionally open the log file  
139 - if log:  
140 - like.logFileOpen()  
141 -  
142 - # Optionally switch-on debugging model  
143 - if debug:  
144 - like["debug"].boolean(True) 126 + """
  127 + Perform maximum likelihood fitting of observations in the container.
  128 +
  129 + Parameters:
  130 + obs - Observation container
  131 + Keywords:
  132 + log - Create log file(s)
  133 + debug - Create screen dump
  134 + """
  135 + # Allocate ctlike application
  136 + like = ctools.ctlike(obs)
  137 +
  138 + # Optionally open the log file
  139 + if log:
  140 + like.logFileOpen()
  141 +
  142 + # Optionally switch-on debugging model
  143 + if debug:
  144 + like["debug"].boolean(True)
145 145
146 - # Run ctlike application.  
147 - like.run()  
148 -  
149 - # Return observations  
150 - return like 146 + # Run ctlike application.
  147 + like.run()
  148 +
  149 + # Return observations
  150 + return like
151 151
152 152
153 # ================= # 153 # ================= #
@@ -155,45 +155,45 @@ def fit(obs, log=False, debug=False): @@ -155,45 +155,45 @@ def fit(obs, log=False, debug=False):
155 # ================= # 155 # ================= #
156 def cntmap(obs, proj="TAN", coord="GAL", xval=0.0, yval=0.0, \ 156 def cntmap(obs, proj="TAN", coord="GAL", xval=0.0, yval=0.0, \
157 binsz=0.05, nxpix=200, nypix=200, \ 157 binsz=0.05, nxpix=200, nypix=200, \
158 - outname="cntmap.fits"):  
159 - """  
160 - Creates a counts map by combining the events of all observations.  
161 - The counts map will be a summed map over all energies.  
162 -  
163 - Parameters:  
164 - obs - Observation container  
165 - Keywords:  
166 - proj - Projection type (e.g. TAN, CAR, STG, ...) (default: TAN)  
167 - coord - Coordinate type (GAL, CEL) (default: GAL)  
168 - xval - Reference longitude value [deg] (default: 0.0)  
169 - yval - Reference latitude value [deg] (default: 0.0)  
170 - binsz - Pixel size [deg/pixel] (default: 0.05)  
171 - nxpix - Number of pixels in X direction (default: 200)  
172 - nypix - Number of pixels in Y direction (default: 200)  
173 - outname - Counts map FITS filename (default: cntmap.fits)  
174 - """  
175 - # Allocate counts map  
176 - map = GSkymap(proj, coord, xval, yval, -binsz, binsz, nxpix, nypix, 1)  
177 -  
178 - # Fill all observations  
179 - for run in obs:  
180 -  
181 - # Loop over all events  
182 - for event in run.events():  
183 -  
184 - # Determine sky pixel  
185 - skydir = GCTAInstDir(event.dir()).dir()  
186 - pixel = map.dir2inx(skydir)  
187 -  
188 - # Set pixel  
189 - map[pixel] += 1.0  
190 -  
191 - # Save sky map. The clobber flag is set to True, so any existing FITS  
192 - # file will be overwritten.  
193 - map.save(outname, True)  
194 -  
195 - # Return counts map  
196 - return map 158 + outname="cntmap.fits"):
  159 + """
  160 + Creates a counts map by combining the events of all observations.
  161 + The counts map will be a summed map over all energies.
  162 +
  163 + Parameters:
  164 + obs - Observation container
  165 + Keywords:
  166 + proj - Projection type (e.g. TAN, CAR, STG, ...) (default: TAN)
  167 + coord - Coordinate type (GAL, CEL) (default: GAL)
  168 + xval - Reference longitude value [deg] (default: 0.0)
  169 + yval - Reference latitude value [deg] (default: 0.0)
  170 + binsz - Pixel size [deg/pixel] (default: 0.05)
  171 + nxpix - Number of pixels in X direction (default: 200)
  172 + nypix - Number of pixels in Y direction (default: 200)
  173 + outname - Counts map FITS filename (default: cntmap.fits)
  174 + """
  175 + # Allocate counts map
  176 + map = gammalib.GSkymap(proj, coord, xval, yval, -binsz, binsz, nxpix, nypix, 1)
  177 +
  178 + # Fill all observations
  179 + for run in obs:
  180 +
  181 + # Loop over all events
  182 + for event in run.events():
  183 +
  184 + # Determine sky pixel
  185 + skydir = gammalib.GCTAInstDir(event.dir()).dir()
  186 + pixel = map.dir2inx(skydir)
  187 +
  188 + # Set pixel
  189 + map[pixel] += 1.0
  190 +
  191 + # Save sky map. The clobber flag is set to True, so any existing FITS
  192 + # file will be overwritten.
  193 + map.save(outname, True)
  194 +
  195 + # Return counts map
  196 + return map
197 197
198 198
199 # ================ # 199 # ================ #
@@ -202,63 +202,63 @@ def cntmap(obs, proj=&quot;TAN&quot;, coord=&quot;GAL&quot;, xval=0.0, yval=0.0, \ @@ -202,63 +202,63 @@ def cntmap(obs, proj=&quot;TAN&quot;, coord=&quot;GAL&quot;, xval=0.0, yval=0.0, \
202 def modmap(obs, eref=0.1, proj="TAN", coord="GAL", xval=0.0, yval=0.0, \ 202 def modmap(obs, eref=0.1, proj="TAN", coord="GAL", xval=0.0, yval=0.0, \
203 binsz=0.05, nxpix=200, nypix=200, \ 203 binsz=0.05, nxpix=200, nypix=200, \
204 outname="modmap.fits"): 204 outname="modmap.fits"):
205 - """  
206 - Make model map for a given reference energy by combining all observations.  
207 - The model map will be evaluated for a given reference energy 'eref' and will  
208 - be given in units of [counts/(sr MeV s)].  
209 -  
210 - Parameters:  
211 - obs - Observation container  
212 - Keywords:  
213 - eref - Reference energy for which model is created [TeV] (default: 0.1)  
214 - proj - Projection type (e.g. TAN, CAR, STG, ...) (default: TAN)  
215 - coord - Coordinate type (GAL, CEL) (default: GAL)  
216 - xval - Reference longitude value [deg] (default: 0.0)  
217 - yval - Reference latitude value [deg] (default: 0.0)  
218 - binsz - Pixel size [deg/pixel] (default: 0.05)  
219 - nxpix - Number of pixels in X direction (default: 200)  
220 - nypix - Number of pixels in Y direction (default: 200)  
221 - outname - Model map FITS filename (default: modmap.fits)  
222 - """  
223 - # Allocate model map  
224 - map = GSkymap(proj, coord, xval, yval, -binsz, binsz, nxpix, nypix, 1)  
225 -  
226 - # Set reference energy, time and direction. The time is not initialised and is  
227 - # in fact not used (as the IRF is assumed to be time independent for now).  
228 - # The sky direction is set later using the pixel values.  
229 - energy = GEnergy()  
230 - time = GTime()  
231 - instdir = GCTAInstDir()  
232 - energy.TeV(eref)  
233 -  
234 - # Loop over all map pixels  
235 - for pixel in range(map.npix()):  
236 -  
237 - # Get sky direction  
238 - skydir = map.inx2dir(pixel)  
239 - instdir.dir(skydir)  
240 -  
241 - # Create event atom for map pixel  
242 - atom = GCTAEventAtom()  
243 - atom.dir(instdir)  
244 - atom.energy(energy)  
245 - atom.time(time)  
246 -  
247 - # Initialise model value  
248 - value = 0.0  
249 -  
250 - # Loop over all observations  
251 - for run in obs:  
252 - value += obs.models().eval(atom, run)  
253 -  
254 - # Set map value  
255 - map[pixel] = value  
256 -  
257 - # Save sky map  
258 - map.save(outname, True)  
259 -  
260 - # Return model map  
261 - return map 205 + """
  206 + Make model map for a given reference energy by combining all observations.
  207 + The model map will be evaluated for a given reference energy 'eref' and will
  208 + be given in units of [counts/(sr MeV s)].
  209 +
  210 + Parameters:
  211 + obs - Observation container
  212 + Keywords:
  213 + eref - Reference energy for which model is created [TeV] (default: 0.1)
  214 + proj - Projection type (e.g. TAN, CAR, STG, ...) (default: TAN)
  215 + coord - Coordinate type (GAL, CEL) (default: GAL)
  216 + xval - Reference longitude value [deg] (default: 0.0)
  217 + yval - Reference latitude value [deg] (default: 0.0)
  218 + binsz - Pixel size [deg/pixel] (default: 0.05)
  219 + nxpix - Number of pixels in X direction (default: 200)
  220 + nypix - Number of pixels in Y direction (default: 200)
  221 + outname - Model map FITS filename (default: modmap.fits)
  222 + """
  223 + # Allocate model map
  224 + map = gammalib.GSkymap(proj, coord, xval, yval, -binsz, binsz, nxpix, nypix, 1)
  225 +
  226 + # Set reference energy, time and direction. The time is not initialised and is
  227 + # in fact not used (as the IRF is assumed to be time independent for now).
  228 + # The sky direction is set later using the pixel values.
  229 + energy = gammalib.GEnergy()
  230 + time = gammalib.GTime()
  231 + instdir = gammalib.GCTAInstDir()
  232 + energy.TeV(eref)
  233 +
  234 + # Loop over all map pixels
  235 + for pixel in range(map.npix()):
  236 +
  237 + # Get sky direction
  238 + skydir = map.inx2dir(pixel)
  239 + instdir.dir(skydir)
  240 +
  241 + # Create event atom for map pixel
  242 + atom = gammalib.GCTAEventAtom()
  243 + atom.dir(instdir)
  244 + atom.energy(energy)
  245 + atom.time(time)
  246 +
  247 + # Initialise model value
  248 + value = 0.0
  249 +
  250 + # Loop over all observations
  251 + for run in obs:
  252 + value += obs.models().eval(atom, run)
  253 +
  254 + # Set map value
  255 + map[pixel] = value
  256 +
  257 + # Save sky map
  258 + map.save(outname, True)
  259 +
  260 + # Return model map
  261 + return map
262 262
263 263
264 # ======================= # 264 # ======================= #
@@ -266,66 +266,73 @@ def modmap(obs, eref=0.1, proj=&quot;TAN&quot;, coord=&quot;GAL&quot;, xval=0.0, yval=0.0, \ @@ -266,66 +266,73 @@ def modmap(obs, eref=0.1, proj=&quot;TAN&quot;, coord=&quot;GAL&quot;, xval=0.0, yval=0.0, \
266 # ======================= # 266 # ======================= #
267 def set(pntdir, tstart=0.0, duration=1800.0, deadc=0.95, \ 267 def set(pntdir, tstart=0.0, duration=1800.0, deadc=0.95, \
268 emin=0.1, emax=100.0, rad=5.0, \ 268 emin=0.1, emax=100.0, rad=5.0, \
269 - irf="cta_dummy_irf", caldb="$GAMMALIB/share/caldb/cta"):  
270 - """  
271 - Returns a single CTA observation. By looping over this function we can  
272 - add CTA observations to the observation container.  
273 -  
274 - Parameters:  
275 - pntdir - Pointing direction  
276 - Keywords:  
277 - tstart - Start time [seconds] (default: 0.0)  
278 - duration - Duration of observation [seconds] (default: 1800.0)  
279 - deadc - Deadtime correction factor (default: 0.95)  
280 - emin - Minimum event energy [TeV] (default: 0.1)  
281 - emax - Maximum event energy [TeV] (default: 100.0)  
282 - rad - ROI radius used for analysis [deg] (default: 5.0)  
283 - irf - Instrument response function (default: cta_dummy_irf)  
284 - caldb - Calibration database path (default: $GAMMALIB/share/caldb/cta)  
285 - """  
286 - # Allocate CTA observation  
287 - obs = GCTAObservation()  
288 -  
289 - # Set pointing direction  
290 - pnt = GCTAPointing()  
291 - pnt.dir(pntdir)  
292 - obs.pointing(pnt)  
293 -  
294 - # Set ROI  
295 - roi = GCTARoi()  
296 - instdir = GCTAInstDir()  
297 - instdir.dir(pntdir)  
298 - roi.centre(instdir)  
299 - roi.radius(rad)  
300 -  
301 - # Set GTI  
302 - gti = GGti()  
303 - start = GTime(tstart)  
304 - stop = GTime(tstart+duration)  
305 - gti.append(start, stop)  
306 -  
307 - # Set energy boundaries  
308 - ebounds = GEbounds()  
309 - e_min = GEnergy()  
310 - e_max = GEnergy()  
311 - e_min.TeV(emin)  
312 - e_max.TeV(emax)  
313 - ebounds.append(e_min, e_max) 269 + irf="cta_dummy_irf", caldb=""):
  270 + """
  271 + Returns a single CTA observation. By looping over this function we can
  272 + add CTA observations to the observation container.
  273 +
  274 + Parameters:
  275 + pntdir - Pointing direction
  276 + Keywords:
  277 + tstart - Start time [seconds] (default: 0.0)
  278 + duration - Duration of observation [seconds] (default: 1800.0)
  279 + deadc - Deadtime correction factor (default: 0.95)
  280 + emin - Minimum event energy [TeV] (default: 0.1)
  281 + emax - Maximum event energy [TeV] (default: 100.0)
  282 + rad - ROI radius used for analysis [deg] (default: 5.0)
  283 + irf - Instrument response function (default: cta_dummy_irf)
  284 + caldb - Calibration database path (default: "")
  285 + """
  286 + # Allocate CTA observation
  287 + obs = gammalib.GCTAObservation()
314 288
315 - # Allocate event list  
316 - events = GCTAEventList()  
317 - events.roi(roi)  
318 - events.gti(gti)  
319 - events.ebounds(ebounds)  
320 - obs.events(events)  
321 -  
322 - # Set instrument response  
323 - obs.response(irf, caldb)  
324 -  
325 - # Set ontime, livetime, and deadtime correction factor  
326 - obs.ontime(duration)  
327 - obs.livetime(duration*deadc)  
328 - obs.deadc(deadc)  
329 -  
330 - # Return observation  
331 - return obs 289 + # Set calibration database
  290 + db = gammalib.GCaldb()
  291 + if (gammalib.dir_exists(caldb)):
  292 + db.dir(caldb)
  293 + else:
  294 + db.open("cta", caldb)
  295 +
  296 + # Set pointing direction
  297 + pnt = gammalib.GCTAPointing()
  298 + pnt.dir(pntdir)
  299 + obs.pointing(pnt)
  300 +
  301 + # Set ROI
  302 + roi = gammalib.GCTARoi()
  303 + instdir = gammalib.GCTAInstDir()
  304 + instdir.dir(pntdir)
  305 + roi.centre(instdir)
  306 + roi.radius(rad)
  307 +
  308 + # Set GTI
  309 + gti = gammalib.GGti()
  310 + start = gammalib.GTime(tstart)
  311 + stop = gammalib.GTime(tstart+duration)
  312 + gti.append(start, stop)
  313 +
  314 + # Set energy boundaries
  315 + ebounds = gammalib.GEbounds()
  316 + e_min = gammalib.GEnergy()
  317 + e_max = gammalib.GEnergy()
  318 + e_min.TeV(emin)
  319 + e_max.TeV(emax)
  320 + ebounds.append(e_min, e_max)
  321 +
  322 + # Allocate event list
  323 + events = gammalib.GCTAEventList()
  324 + events.roi(roi)
  325 + events.gti(gti)
  326 + events.ebounds(ebounds)
  327 + obs.events(events)
  328 +
  329 + # Set instrument response
  330 + obs.response(irf, db)
  331 +
  332 + # Set ontime, livetime, and deadtime correction factor
  333 + obs.ontime(duration)
  334 + obs.livetime(duration*deadc)
  335 + obs.deadc(deadc)
  336 +
  337 + # Return observation
  338 + return obs
src/ctlike/ctlike.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * ctlike - CTA maximum likelihood tool * 2 * ctlike - CTA maximum likelihood tool *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2010-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2010-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -361,8 +361,20 @@ void ctlike::get_parameters(void) @@ -361,8 +361,20 @@ void ctlike::get_parameters(void)
361 // Set statistics 361 // Set statistics
362 obs.statistics(m_stat); 362 obs.statistics(m_stat);
363 363
  364 + // Set calibration database. If specified parameter is a
  365 + // directory then use this as the pathname to the calibration
  366 + // database. Otherwise interpret this as the instrument name,
  367 + // the mission being "cta"
  368 + GCaldb caldb;
  369 + if (gammalib::dir_exists(m_caldb)) {
  370 + caldb.dir(m_caldb);
  371 + }
  372 + else {
  373 + caldb.open("cta", m_caldb);
  374 + }
  375 +
364 // Set reponse 376 // Set reponse
365 - obs.response(m_irf, m_caldb); 377 + obs.response(m_irf, caldb);
366 378
367 // Append observation to container 379 // Append observation to container
368 m_obs.append(obs); 380 m_obs.append(obs);
src/ctlike/ctlike.par
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 infile, f, a, "test/data/crab_events.fits.gz",,,"Event list, counts map or observation definition file" 20 infile, f, a, "test/data/crab_events.fits.gz",,,"Event list, counts map or observation definition file"
21 stat, s, h, "POISSON",,, "Optimization statistics" 21 stat, s, h, "POISSON",,, "Optimization statistics"
22 refit, b, h, no,,, "Do refitting?" 22 refit, b, h, no,,, "Do refitting?"
23 -caldb, s, a, "test/irf",,, "Calibration database" 23 +caldb, s, h, "",,, "Calibration database"
24 irf, s, a, "cta_dummy_irf",,, "Instrument response function" 24 irf, s, a, "cta_dummy_irf",,, "Instrument response function"
25 srcmdl, f, a, "test/data/crab.xml",,, "Source model" 25 srcmdl, f, a, "test/data/crab.xml",,, "Source model"
26 outmdl, f, a, "crab_results.xml",,, "Source model output file" 26 outmdl, f, a, "crab_results.xml",,, "Source model output file"
src/ctmodel/ctmodel.cpp
@@ -581,7 +581,21 @@ void ctmodel::setup_obs(void) @@ -581,7 +581,21 @@ void ctmodel::setup_obs(void)
581 581
582 // Set response if it isn't set already 582 // Set response if it isn't set already
583 if (obs->response().aeff() == NULL) { 583 if (obs->response().aeff() == NULL) {
584 - obs->response(m_irf, m_caldb); 584 +
  585 + // Set calibration database. If specified parameter is a
  586 + // directory then use this as the pathname to the calibration
  587 + // database. Otherwise interpret this as the instrument name,
  588 + // the mission being "cta"
  589 + GCaldb caldb;
  590 + if (gammalib::dir_exists(m_caldb)) {
  591 + caldb.dir(m_caldb);
  592 + }
  593 + else {
  594 + caldb.open("cta", m_caldb);
  595 + }
  596 +
  597 + // Set reponse
  598 + obs->response(m_irf, caldb);
585 599
586 } // endif: observation already has a response 600 } // endif: observation already has a response
587 601
src/ctmodel/ctmodel.par
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 infile, f, a, "NONE",,, "Input counts map or observation definition file" 20 infile, f, a, "NONE",,, "Input counts map or observation definition file"
21 outfile, f, a, "modmap.fits",,, "Output counts map or observation definition file" 21 outfile, f, a, "modmap.fits",,, "Output counts map or observation definition file"
22 prefix, s, h, "modmap_",,, "Prefix for counts maps in observation definition file" 22 prefix, s, h, "modmap_",,, "Prefix for counts maps in observation definition file"
23 -caldb, s, a, "test/irf",,, "Calibration database" 23 +caldb, s, h, "",,, "Calibration database"
24 irf, s, a, "cta_dummy_irf",,, "Instrument response function" 24 irf, s, a, "cta_dummy_irf",,, "Instrument response function"
25 srcmdl, f, a, "test/data/crab.xml",,, "Source model" 25 srcmdl, f, a, "test/data/crab.xml",,, "Source model"
26 # 26 #
src/ctobssim/ctobssim.cpp
@@ -432,9 +432,21 @@ void ctobssim::get_parameters(void) @@ -432,9 +432,21 @@ void ctobssim::get_parameters(void)
432 // Allocate CTA observation 432 // Allocate CTA observation
433 GCTAObservation obs; 433 GCTAObservation obs;
434 434
  435 + // Set calibration database. If specified parameter is a directory
  436 + // then use this as the pathname to the calibration database. Other-
  437 + // wise interpret this as the instrument name, the mission being
  438 + // "cta"
  439 + GCaldb caldb;
  440 + if (gammalib::dir_exists(m_caldb)) {
  441 + caldb.dir(m_caldb);
  442 + }
  443 + else {
  444 + caldb.open("cta", m_caldb);
  445 + }
  446 +
435 // Set CTA observation attributes 447 // Set CTA observation attributes
436 obs.pointing(pnt); 448 obs.pointing(pnt);
437 - obs.response(m_irf, m_caldb); 449 + obs.response(m_irf, caldb);
438 450
439 // Set event list (queries remaining parameters) 451 // Set event list (queries remaining parameters)
440 set_list(&obs); 452 set_list(&obs);