Commit f6150a99c46b9e50cb37806238fe047c60b7a05d
1 parent
f4dea160
Add csbkgmodel script (#2694)
Showing
10 changed files
with
568 additions
and
14 deletions
ChangeLog
| 1 | -2018-10-17 | 1 | +2018-10-18 |
| 2 | 2 | ||
| 3 | * Version 1.6.0 released | 3 | * Version 1.6.0 released |
| 4 | ======================== | 4 | ======================== |
| 5 | 5 | ||
| 6 | + Add csbkgmodel script (#2694) | ||
| 6 | Compute DETX and DETY in ctmodel if they are not available (#2694) | 7 | Compute DETX and DETY in ctmodel if they are not available (#2694) |
| 7 | Do no longer set missing boundaries in ctool::get_observations and | 8 | Do no longer set missing boundaries in ctool::get_observations and |
| 8 | ctool::setup_observations (#2686) | 9 | ctool::setup_observations (#2686) |
NEWS
| 1 | New Features and Important Changes in ctools 1.6.0 | 1 | New Features and Important Changes in ctools 1.6.0 |
| 2 | 2 | ||
| 3 | -17 October 2018 | 3 | +18 October 2018 |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | Introduction | 6 | Introduction |
| @@ -200,6 +200,13 @@ support - Support classes | @@ -200,6 +200,13 @@ support - Support classes | ||
| 200 | None | 200 | None |
| 201 | 201 | ||
| 202 | 202 | ||
| 203 | +csbkgmodel - Generate background model for 3D analysis | ||
| 204 | +------------------------------------------------------ | ||
| 205 | +Introduced the script that generates a background for a 3D analysis. This | ||
| 206 | +script is particularly useful to generate a background model for the analysis | ||
| 207 | +of the H.E.S.S. public data release (#2694). | ||
| 208 | + | ||
| 209 | + | ||
| 203 | cscaldb - Inspect calibration database | 210 | cscaldb - Inspect calibration database |
| 204 | -------------------------------------- | 211 | -------------------------------------- |
| 205 | None | 212 | None |
cscripts/Makefile.am
| @@ -21,6 +21,7 @@ | @@ -21,6 +21,7 @@ | ||
| 21 | 21 | ||
| 22 | # Scripts to be distributed in $(pyexecdir)/cscripts | 22 | # Scripts to be distributed in $(pyexecdir)/cscripts |
| 23 | pythonscripts = $(top_builddir)/cscripts/__init__.py \ | 23 | pythonscripts = $(top_builddir)/cscripts/__init__.py \ |
| 24 | + $(srcdir)/csbkgmodel.py \ | ||
| 24 | $(srcdir)/cscaldb.py \ | 25 | $(srcdir)/cscaldb.py \ |
| 25 | $(srcdir)/csebins.py \ | 26 | $(srcdir)/csebins.py \ |
| 26 | $(srcdir)/csinfo.py \ | 27 | $(srcdir)/csinfo.py \ |
| @@ -58,7 +59,8 @@ pythonscripts = $(top_builddir)/cscripts/__init__.py \ | @@ -58,7 +59,8 @@ pythonscripts = $(top_builddir)/cscripts/__init__.py \ | ||
| 58 | $(srcdir)/mputils.py | 59 | $(srcdir)/mputils.py |
| 59 | 60 | ||
| 60 | # Parfiles to be distributed in $(prefix)/syspfiles | 61 | # Parfiles to be distributed in $(prefix)/syspfiles |
| 61 | -parfiles = $(srcdir)/cscaldb.par \ | 62 | +parfiles = $(srcdir)/csbkgmodel.par \ |
| 63 | + $(srcdir)/cscaldb.par \ | ||
| 62 | $(srcdir)/csebins.par \ | 64 | $(srcdir)/csebins.par \ |
| 63 | $(srcdir)/cslightcrv.par \ | 65 | $(srcdir)/cslightcrv.par \ |
| 64 | $(srcdir)/csmodelinfo.par \ | 66 | $(srcdir)/csmodelinfo.par \ |
| @@ -89,7 +91,8 @@ parfiles = $(srcdir)/cscaldb.par \ | @@ -89,7 +91,8 @@ parfiles = $(srcdir)/cscaldb.par \ | ||
| 89 | $(srcdir)/csiactobs.par | 91 | $(srcdir)/csiactobs.par |
| 90 | 92 | ||
| 91 | # Scripts for which symbolic links will be created in bindir | 93 | # Scripts for which symbolic links will be created in bindir |
| 92 | -linkscripts = cscaldb \ | 94 | +linkscripts = csbkgmodel \ |
| 95 | + cscaldb \ | ||
| 93 | csebins \ | 96 | csebins \ |
| 94 | csinfo \ | 97 | csinfo \ |
| 95 | cslightcrv \ | 98 | cslightcrv \ |
cscripts/__init__.py.in
| @@ -24,6 +24,7 @@ cur_version = sys.version_info | @@ -24,6 +24,7 @@ cur_version = sys.version_info | ||
| 24 | 24 | ||
| 25 | # List all scripts in this module | 25 | # List all scripts in this module |
| 26 | __all__ = [ | 26 | __all__ = [ |
| 27 | + "csbkgmodel", | ||
| 27 | "cscaldb", | 28 | "cscaldb", |
| 28 | "csebins", | 29 | "csebins", |
| 29 | "csinfo", | 30 | "csinfo", |
| @@ -63,9 +64,10 @@ if cur_version > req_version: | @@ -63,9 +64,10 @@ if cur_version > req_version: | ||
| 63 | "csiactobs"]) | 64 | "csiactobs"]) |
| 64 | 65 | ||
| 65 | # Import | 66 | # Import |
| 67 | +from cscripts.csbkgmodel import csbkgmodel | ||
| 66 | from cscripts.cscaldb import cscaldb | 68 | from cscripts.cscaldb import cscaldb |
| 67 | -from cscripts.csinfo import csinfo | ||
| 68 | from cscripts.csebins import csebins | 69 | from cscripts.csebins import csebins |
| 70 | +from cscripts.csinfo import csinfo | ||
| 69 | from cscripts.cslightcrv import cslightcrv | 71 | from cscripts.cslightcrv import cslightcrv |
| 70 | from cscripts.csmodelinfo import csmodelinfo | 72 | from cscripts.csmodelinfo import csmodelinfo |
| 71 | from cscripts.csmodelmerge import csmodelmerge | 73 | from cscripts.csmodelmerge import csmodelmerge |
cscripts/csbkgmodel.par
0 → 100755
| 1 | +############################################################################# | ||
| 2 | +# # | ||
| 3 | +# CTA Science Analysis Tools # | ||
| 4 | +# # | ||
| 5 | +# ------------------------------------------------------------------------- # | ||
| 6 | +# # | ||
| 7 | +# File: csbkgmodel.par # | ||
| 8 | +# # | ||
| 9 | +# Author: Juergen Knoedlseder # | ||
| 10 | +# Jurgen.Knodlseder@irap.omp.eu # | ||
| 11 | +# IRAP # | ||
| 12 | +# # | ||
| 13 | +# Purpose: Parameter file for the csbkgmodel script # | ||
| 14 | +# # | ||
| 15 | +############################################################################# | ||
| 16 | +# | ||
| 17 | +# Input and output parameters | ||
| 18 | +#============================ | ||
| 19 | +inobs, f, a, obs.xml,,, "Input observation definition XML file" | ||
| 20 | +outmodel, f, a, model.xml,,, "Output model definition XML file" | ||
| 21 | + | ||
| 22 | +# | ||
| 23 | +# Script parameters | ||
| 24 | +#================== | ||
| 25 | +instrument, s, a, CTA,,, "Instrument name (for multi-instrument analysis)" | ||
| 26 | +spatial, s, a, GAUSS,IRF|AEFF|GAUSS,, "Spatial model component" | ||
| 27 | +gradient, b, a, yes,,, "Allow for spatial gradient?" | ||
| 28 | +spectral, s, a, HESS,PLAW|HESS,, "Spectral model component" | ||
| 29 | +runwise, b, a, yes,,, "Generate runwise background model?" | ||
| 30 | +rad, r, h, 2.0,,, "Radius for event selection (degrees)" | ||
| 31 | + | ||
| 32 | +# | ||
| 33 | +# Standard parameters | ||
| 34 | +#==================== | ||
| 35 | +chatter, i, h, 2,0,4, "Chattiness of output" | ||
| 36 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | ||
| 37 | +debug, b, h, no,,, "Activate debugging mode?" | ||
| 38 | +mode, s, h, ql,,, "Mode of automatic parameters" | ||
| 39 | +logfile, f, h, csbkgmodel.log,,, "Log filename" |
cscripts/csbkgmodel.py
0 → 100755
| 1 | +#! /usr/bin/env python | ||
| 2 | +# ========================================================================== | ||
| 3 | +# Generates background model | ||
| 4 | +# | ||
| 5 | +# Copyright (C) 2018 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 sys | ||
| 22 | +import math | ||
| 23 | +import gammalib | ||
| 24 | +import ctools | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +# ================ # | ||
| 28 | +# csbkgmodel class # | ||
| 29 | +# ================ # | ||
| 30 | +class csbkgmodel(ctools.csobservation): | ||
| 31 | + """ | ||
| 32 | + Generates background model | ||
| 33 | + """ | ||
| 34 | + | ||
| 35 | + # Constructor | ||
| 36 | + def __init__(self, *argv): | ||
| 37 | + """ | ||
| 38 | + Constructor | ||
| 39 | + """ | ||
| 40 | + # Initialise application by calling the appropriate class constructor | ||
| 41 | + self._init_csobservation(self.__class__.__name__, ctools.__version__, argv) | ||
| 42 | + | ||
| 43 | + # Set members | ||
| 44 | + self._models = gammalib.GModels() | ||
| 45 | + self._instrument = '' | ||
| 46 | + | ||
| 47 | + # Return | ||
| 48 | + return | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + # Private methods | ||
| 52 | + def _get_parameters(self): | ||
| 53 | + """ | ||
| 54 | + Get parameters from parfile | ||
| 55 | + """ | ||
| 56 | + # Setup observations (do not require response, allow event list and | ||
| 57 | + # counts cube) | ||
| 58 | + self._setup_observations(self.obs(), False, True, True) | ||
| 59 | + | ||
| 60 | + # Set instrument name | ||
| 61 | + self._instrument = self._get_instrument() | ||
| 62 | + | ||
| 63 | + # Query input parameters | ||
| 64 | + spatial = self['spatial'].string() | ||
| 65 | + if self['spatial'].string() == 'GAUSS': | ||
| 66 | + self['gradient'].boolean() | ||
| 67 | + self['spectral'].string() | ||
| 68 | + self['runwise'].boolean() | ||
| 69 | + self['rad'].real() | ||
| 70 | + | ||
| 71 | + # Query ahead output model filename | ||
| 72 | + if self._read_ahead(): | ||
| 73 | + self['outmodel'].filename() | ||
| 74 | + | ||
| 75 | + # Write input parameters into logger | ||
| 76 | + self._log_parameters(gammalib.TERSE) | ||
| 77 | + | ||
| 78 | + # Return | ||
| 79 | + return | ||
| 80 | + | ||
| 81 | + def _get_instrument(self): | ||
| 82 | + """ | ||
| 83 | + Get instrument name | ||
| 84 | + | ||
| 85 | + Extracts the instrument name from the observation container. If there | ||
| 86 | + are multiple instruments in the container then use the "instrument" | ||
| 87 | + parameter to set the instrument name. | ||
| 88 | + | ||
| 89 | + Returns | ||
| 90 | + ------- | ||
| 91 | + instrument : str | ||
| 92 | + Instrument name | ||
| 93 | + """ | ||
| 94 | + # Initialise instrument | ||
| 95 | + instrument = '' | ||
| 96 | + | ||
| 97 | + # Loop over all observations | ||
| 98 | + for obs in self.obs(): | ||
| 99 | + if instrument == '': | ||
| 100 | + instrument = obs.instrument() | ||
| 101 | + elif instrument != obs.instrument(): | ||
| 102 | + instrument = self['instrument'].string() | ||
| 103 | + break | ||
| 104 | + | ||
| 105 | + # Return instrument | ||
| 106 | + return instrument | ||
| 107 | + | ||
| 108 | + def _generate_initial_model(self): | ||
| 109 | + """ | ||
| 110 | + Generate initial background model | ||
| 111 | + | ||
| 112 | + Returns | ||
| 113 | + ------- | ||
| 114 | + model : `~gammalib.GModelData()` | ||
| 115 | + Background model | ||
| 116 | + """ | ||
| 117 | + # Handle IRF model | ||
| 118 | + if self['spatial'].string() == 'IRF': | ||
| 119 | + epivot = gammalib.GEnergy(1.0, 'TeV') | ||
| 120 | + spectral = gammalib.GModelSpectralPlaw(1.0, 0.0, epivot) | ||
| 121 | + model = gammalib.GCTAModelIrfBackground(spectral) | ||
| 122 | + | ||
| 123 | + # Handle AEFF model | ||
| 124 | + elif self['spatial'].string() == 'AEFF': | ||
| 125 | + epivot = gammalib.GEnergy(1.0, 'TeV') | ||
| 126 | + spectral = gammalib.GModelSpectralPlaw(1.0e-13, -2.5, epivot) | ||
| 127 | + model = gammalib.GCTAModelAeffBackground(spectral) | ||
| 128 | + | ||
| 129 | + # Handle GAUSS model | ||
| 130 | + elif self['spatial'].string() == 'GAUSS': | ||
| 131 | + if self['gradient'].boolean(): | ||
| 132 | + spatial = gammalib.GCTAModelSpatialMultiplicative() | ||
| 133 | + factor1 = gammalib.GCTAModelRadialGauss(3.0) | ||
| 134 | + factor2 = gammalib.GCTAModelSpatialGradient() | ||
| 135 | + spatial.append(factor1) | ||
| 136 | + spatial.append(factor2) | ||
| 137 | + else: | ||
| 138 | + spatial = gammalib.GCTAModelRadialGauss(3.0) | ||
| 139 | + epivot = gammalib.GEnergy(1.0, 'TeV') | ||
| 140 | + spectral = gammalib.GModelSpectralPlaw(3.0e-4, -1.5, epivot) | ||
| 141 | + spectral['Prefactor'].min(1.0e-8) | ||
| 142 | + model = gammalib.GCTAModelBackground(spatial, spectral) | ||
| 143 | + | ||
| 144 | + # Any other strings (should never occur) | ||
| 145 | + else: | ||
| 146 | + model = None | ||
| 147 | + | ||
| 148 | + # Set background name and instrument | ||
| 149 | + if model is not None: | ||
| 150 | + model.name('Background') | ||
| 151 | + model.instruments(self._instrument) | ||
| 152 | + | ||
| 153 | + # Return model | ||
| 154 | + return model | ||
| 155 | + | ||
| 156 | + def _select_events(self, obs): | ||
| 157 | + """ | ||
| 158 | + Select events within a given RoI radius | ||
| 159 | + | ||
| 160 | + Parameters | ||
| 161 | + ---------- | ||
| 162 | + obs : `~gammalib.GObservations()` | ||
| 163 | + Observation container | ||
| 164 | + | ||
| 165 | + Returns | ||
| 166 | + ------- | ||
| 167 | + obs : `~gammalib.GObservations()` | ||
| 168 | + Observation container | ||
| 169 | + """ | ||
| 170 | + # Setup task parameters | ||
| 171 | + select = ctools.ctselect(obs) | ||
| 172 | + select['ra'] = 'UNDEF' | ||
| 173 | + select['dec'] = 'UNDEF' | ||
| 174 | + select['rad'] = self['rad'].real() | ||
| 175 | + select['tmin'] = 'UNDEF' | ||
| 176 | + select['tmax'] = 'UNDEF' | ||
| 177 | + select['emin'] = 'UNDEF' | ||
| 178 | + select['emax'] = 'UNDEF' | ||
| 179 | + select['usethres'] = 'DEFAULT' | ||
| 180 | + | ||
| 181 | + # Select events | ||
| 182 | + select.run() | ||
| 183 | + | ||
| 184 | + # Extract observation | ||
| 185 | + obs = select.obs().copy() | ||
| 186 | + | ||
| 187 | + # Return observation | ||
| 188 | + return obs | ||
| 189 | + | ||
| 190 | + def _create_nodes(self, model): | ||
| 191 | + """ | ||
| 192 | + Replace spectral model by node function | ||
| 193 | + | ||
| 194 | + Parameters | ||
| 195 | + ---------- | ||
| 196 | + model : `~gammalib.GModelData()` | ||
| 197 | + Input background model | ||
| 198 | + | ||
| 199 | + Returns | ||
| 200 | + ------- | ||
| 201 | + model : `~gammalib.GModelData()` | ||
| 202 | + Background model with spectral node function | ||
| 203 | + """ | ||
| 204 | + # Extract spectral model of background component | ||
| 205 | + spectrum = model.spectral() | ||
| 206 | + | ||
| 207 | + # Define 8 node energies | ||
| 208 | + energies = gammalib.GEnergies() | ||
| 209 | + energies.append(gammalib.GEnergy(0.1, 'TeV')) | ||
| 210 | + energies.append(gammalib.GEnergy(0.2, 'TeV')) | ||
| 211 | + energies.append(gammalib.GEnergy(0.4, 'TeV')) | ||
| 212 | + energies.append(gammalib.GEnergy(0.8, 'TeV')) | ||
| 213 | + energies.append(gammalib.GEnergy(1.6, 'TeV')) | ||
| 214 | + energies.append(gammalib.GEnergy(3.2, 'TeV')) | ||
| 215 | + energies.append(gammalib.GEnergy(6.4, 'TeV')) | ||
| 216 | + energies.append(gammalib.GEnergy(12.8, 'TeV')) | ||
| 217 | + | ||
| 218 | + # Create node spectrum | ||
| 219 | + nodes = gammalib.GModelSpectralNodes(spectrum, energies) | ||
| 220 | + nodes.autoscale() | ||
| 221 | + | ||
| 222 | + # Set minimum node intensities (this avoids NaNs during model fitting) | ||
| 223 | + for i in range(nodes.size()): | ||
| 224 | + nodes[i].min(1.0e-6*nodes[i].value()) | ||
| 225 | + | ||
| 226 | + # Set node spectrum | ||
| 227 | + model.spectral(nodes) | ||
| 228 | + | ||
| 229 | + # Return | ||
| 230 | + return model | ||
| 231 | + | ||
| 232 | + def _generate_bkg(self, obs): | ||
| 233 | + """ | ||
| 234 | + Generate background models | ||
| 235 | + | ||
| 236 | + Parameters | ||
| 237 | + ---------- | ||
| 238 | + obs : `~gammalib.GObservations()` | ||
| 239 | + Observations container | ||
| 240 | + | ||
| 241 | + Returns | ||
| 242 | + ------- | ||
| 243 | + model : `~gammalib.GModelData()` | ||
| 244 | + Background model component | ||
| 245 | + """ | ||
| 246 | + # Write header for event selection | ||
| 247 | + self._log_header3(gammalib.EXPLICIT, 'Select events from observation') | ||
| 248 | + | ||
| 249 | + # Select events | ||
| 250 | + obs = self._select_events(obs) | ||
| 251 | + | ||
| 252 | + # Write header for initial background model generation | ||
| 253 | + self._log_header3(gammalib.EXPLICIT, 'Generate initial background model') | ||
| 254 | + | ||
| 255 | + # Generate initial background model | ||
| 256 | + model = self._generate_initial_model() | ||
| 257 | + | ||
| 258 | + # Attach initial background model | ||
| 259 | + models = gammalib.GModels() | ||
| 260 | + models.append(model) | ||
| 261 | + obs.models(models) | ||
| 262 | + | ||
| 263 | + # Write header for initial model fitting | ||
| 264 | + self._log_header3(gammalib.EXPLICIT, 'Fit initial background model') | ||
| 265 | + | ||
| 266 | + # Perform maximum likelihood fitting with initial model | ||
| 267 | + like = ctools.ctlike(obs) | ||
| 268 | + like.run() | ||
| 269 | + | ||
| 270 | + # Extract fitted model | ||
| 271 | + model = like.obs().models()[0].copy() | ||
| 272 | + | ||
| 273 | + # If a HESS model is requested then refit a node spectrum | ||
| 274 | + if self['spectral'].string() == 'HESS': | ||
| 275 | + | ||
| 276 | + # Create nodes spectrum from fitted initial model | ||
| 277 | + model = self._create_nodes(model) | ||
| 278 | + | ||
| 279 | + # Attach node spectrum | ||
| 280 | + models = gammalib.GModels() | ||
| 281 | + models.append(model) | ||
| 282 | + obs.models(models) | ||
| 283 | + | ||
| 284 | + # Write header for node model fitting | ||
| 285 | + self._log_header3(gammalib.EXPLICIT, 'Fit nodes background model') | ||
| 286 | + | ||
| 287 | + # Perform maximum likelihood fitting with node model | ||
| 288 | + like = ctools.ctlike(obs) | ||
| 289 | + like.run() | ||
| 290 | + | ||
| 291 | + # Extract fitted model | ||
| 292 | + model = like.obs().models()[0].copy() | ||
| 293 | + | ||
| 294 | + # Return model | ||
| 295 | + return model | ||
| 296 | + | ||
| 297 | + def _generate_runwise_bkg(self): | ||
| 298 | + """ | ||
| 299 | + Generate background models | ||
| 300 | + | ||
| 301 | + Parameters | ||
| 302 | + ---------- | ||
| 303 | + responses : list of dict | ||
| 304 | + List of response dictionaries | ||
| 305 | + energy : float | ||
| 306 | + Energy to insert (TeV) | ||
| 307 | + comment : str | ||
| 308 | + Reason for energy insertion | ||
| 309 | + """ | ||
| 310 | + # Loop over observations | ||
| 311 | + for run in self.obs(): | ||
| 312 | + | ||
| 313 | + # Write header | ||
| 314 | + self._log_header2(gammalib.TERSE, self._get_obs_header(run)) | ||
| 315 | + | ||
| 316 | + # Build observation container with single run | ||
| 317 | + obs = gammalib.GObservations() | ||
| 318 | + obs.append(run) | ||
| 319 | + | ||
| 320 | + # Generate background model for | ||
| 321 | + model = self._generate_bkg(obs) | ||
| 322 | + | ||
| 323 | + # Set model attributes | ||
| 324 | + model.name(('Background_%s' % run.id())) | ||
| 325 | + model.ids(run.id()) | ||
| 326 | + | ||
| 327 | + # Write model | ||
| 328 | + self._log_string(gammalib.NORMAL, str(model)) | ||
| 329 | + | ||
| 330 | + # Append background model | ||
| 331 | + self._models.append(model) | ||
| 332 | + | ||
| 333 | + # Return | ||
| 334 | + return | ||
| 335 | + | ||
| 336 | + | ||
| 337 | + # Public methods | ||
| 338 | + def run(self): | ||
| 339 | + """ | ||
| 340 | + Run the script | ||
| 341 | + """ | ||
| 342 | + # Switch screen logging on in debug mode | ||
| 343 | + if self._logDebug(): | ||
| 344 | + self._log.cout(True) | ||
| 345 | + | ||
| 346 | + # Get parameters | ||
| 347 | + self._get_parameters() | ||
| 348 | + | ||
| 349 | + # Write observation into logger | ||
| 350 | + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') | ||
| 351 | + | ||
| 352 | + # Write header | ||
| 353 | + self._log_header1(gammalib.TERSE, 'Generate background models') | ||
| 354 | + | ||
| 355 | + # Clear models | ||
| 356 | + self._models.clear() | ||
| 357 | + | ||
| 358 | + # Generate background models | ||
| 359 | + if self['runwise'].boolean(): | ||
| 360 | + self._generate_runwise_bkg() | ||
| 361 | + else: | ||
| 362 | + model = self._generate_bkg(self.obs()) | ||
| 363 | + self._models.append(model) | ||
| 364 | + | ||
| 365 | + # Write models | ||
| 366 | + self._log_models(gammalib.NORMAL, self._models, 'Output models') | ||
| 367 | + | ||
| 368 | + # Return | ||
| 369 | + return | ||
| 370 | + | ||
| 371 | + def save(self): | ||
| 372 | + """ | ||
| 373 | + Save models | ||
| 374 | + """ | ||
| 375 | + # Write header | ||
| 376 | + self._log_header1(gammalib.TERSE, 'Save models') | ||
| 377 | + | ||
| 378 | + # Get models filename | ||
| 379 | + outmodel = self['outmodel'].filename() | ||
| 380 | + | ||
| 381 | + # Log file name | ||
| 382 | + self._log_value(gammalib.NORMAL, 'Models file', outmodel.url()) | ||
| 383 | + | ||
| 384 | + # Save models | ||
| 385 | + self._models.save(outmodel) | ||
| 386 | + | ||
| 387 | + # Return | ||
| 388 | + return | ||
| 389 | + | ||
| 390 | + def models(self): | ||
| 391 | + """ | ||
| 392 | + Return background models | ||
| 393 | + | ||
| 394 | + Returns | ||
| 395 | + ------- | ||
| 396 | + ebounds : `~gammalib.GModels()` | ||
| 397 | + Background models | ||
| 398 | + """ | ||
| 399 | + # Return | ||
| 400 | + return self._models | ||
| 401 | + | ||
| 402 | + | ||
| 403 | +# ======================== # | ||
| 404 | +# Main routine entry point # | ||
| 405 | +# ======================== # | ||
| 406 | +if __name__ == '__main__': | ||
| 407 | + | ||
| 408 | + # Create instance of application | ||
| 409 | + app = csbkgmodel(sys.argv) | ||
| 410 | + | ||
| 411 | + # Execute application | ||
| 412 | + app.execute() |
doc/source/admin/release_history/1.6.rst
| @@ -10,6 +10,7 @@ ctools 1.6 is a major release that adds significant functionality. | @@ -10,6 +10,7 @@ ctools 1.6 is a major release that adds significant functionality. | ||
| 10 | 10 | ||
| 11 | In particular, this release provides: | 11 | In particular, this release provides: |
| 12 | 12 | ||
| 13 | +* Support for H.E.S.S. public data release analysis | ||
| 13 | * Support for Xspec spectral analysis | 14 | * Support for Xspec spectral analysis |
| 14 | * Improved computation speed for :ref:`ctskymap` and :ref:`csphagen` | 15 | * Improved computation speed for :ref:`ctskymap` and :ref:`csphagen` |
| 15 | * Parallelisation of various cscripts | 16 | * Parallelisation of various cscripts |
| @@ -89,6 +90,8 @@ Improvements | @@ -89,6 +90,8 @@ Improvements | ||
| 89 | New features | 90 | New features |
| 90 | ------------ | 91 | ------------ |
| 91 | 92 | ||
| 93 | +* [`2694 <https://cta-redmine.irap.omp.eu/issues/2694>`_] - | ||
| 94 | + Add :ref:`csbkgmodel` script | ||
| 92 | * [`2421 <https://cta-redmine.irap.omp.eu/issues/2421>`_] - | 95 | * [`2421 <https://cta-redmine.irap.omp.eu/issues/2421>`_] - |
| 93 | Parallelise :ref:`cslightcrv`, :ref:`csphasecrv`, :ref:`csspec`, :ref:`cssens`, | 96 | Parallelise :ref:`cslightcrv`, :ref:`csphasecrv`, :ref:`csspec`, :ref:`cssens`, |
| 94 | :ref:`csphagen`, :ref:`cspull` and :ref:`cstsdist` | 97 | :ref:`csphagen`, :ref:`cspull` and :ref:`cstsdist` |
doc/source/users/reference_manual/csbkgmodel.rst
0 → 100755
| 1 | +.. _csbkgmodel: | ||
| 2 | + | ||
| 3 | +csbkgmodel | ||
| 4 | +========== | ||
| 5 | + | ||
| 6 | +Generates background model for 3D analysis. | ||
| 7 | + | ||
| 8 | + | ||
| 9 | +Synopsis | ||
| 10 | +-------- | ||
| 11 | + | ||
| 12 | +This script generates a background model for a 3D analysis. | ||
| 13 | + | ||
| 14 | +:ref:`csbkgmodel` writes an model definition XML file. | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +General parameters | ||
| 18 | +------------------ | ||
| 19 | + | ||
| 20 | +``inobs [file]`` | ||
| 21 | + Event list, counts cube or input observation definition XML file. | ||
| 22 | + | ||
| 23 | +``outmodel [file]`` | ||
| 24 | + Output model XML file. | ||
| 25 | + | ||
| 26 | +``instrument [string]`` | ||
| 27 | + Instrument name for which background models should be generated. If the | ||
| 28 | + input observation definition XML contains only observations for a given | ||
| 29 | + instrument, the instrument name will be extracted from the observation | ||
| 30 | + definition XML file. | ||
| 31 | + | ||
| 32 | +``spatial <IRF|AEFF|GAUSS> [string]`` | ||
| 33 | + Spatial model component. So far IRF template, effective area and radial | ||
| 34 | + Gaussian models are supported. | ||
| 35 | + | ||
| 36 | +``gradient [boolean]`` | ||
| 37 | + Allow for a spatial gradient in the background event distribution? | ||
| 38 | + This option only applies to the ``GAUSS`` spatial model component. | ||
| 39 | + | ||
| 40 | +``spectral <PLAW|HESS> [string]`` | ||
| 41 | + Spectral model component. ``PLAW`` specifies a simple power law model, | ||
| 42 | + ``HESS`` specifies a piecewise broken power-law using 8 energy nodes | ||
| 43 | + spread over the energy range from 100 GeV to 12.8 TeV. | ||
| 44 | + | ||
| 45 | +``runwise [boolean]`` | ||
| 46 | + Generate runwise background model? If ``yes`` is specified a background | ||
| 47 | + model component for each observation in the observation definition XML | ||
| 48 | + file will be added to the output model XML file. | ||
| 49 | + | ||
| 50 | +``(rad = 2.0) [real]`` | ||
| 51 | + Radius for event selection. Only events within this radius around the | ||
| 52 | + pointing direction will be used for model fitting. | ||
| 53 | + | ||
| 54 | + | ||
| 55 | +Standard parameters | ||
| 56 | +------------------- | ||
| 57 | + | ||
| 58 | +``(chatter = 2) [integer]`` | ||
| 59 | + Verbosity of the executable: | ||
| 60 | + ``chatter = 0``: no information will be logged | ||
| 61 | + | ||
| 62 | + ``chatter = 1``: only errors will be logged | ||
| 63 | + | ||
| 64 | + ``chatter = 2``: errors and actions will be logged | ||
| 65 | + | ||
| 66 | + ``chatter = 3``: report about the task execution | ||
| 67 | + | ||
| 68 | + ``chatter = 4``: detailed report about the task execution | ||
| 69 | + | ||
| 70 | +``(clobber = yes) [boolean]`` | ||
| 71 | + Specifies whether an existing energy boundaries output file should be overwritten. | ||
| 72 | + | ||
| 73 | +``(debug = no) [boolean]`` | ||
| 74 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | ||
| 75 | + | ||
| 76 | +``(mode = ql) [string]`` | ||
| 77 | + Mode of automatic parameters (default is ``ql``, i.e. "query and learn"). | ||
| 78 | + | ||
| 79 | +``(logfile = csbkgmodel.log) [filename]`` | ||
| 80 | + Log filename. | ||
| 81 | + | ||
| 82 | + | ||
| 83 | +Related tools or scripts | ||
| 84 | +------------------------ | ||
| 85 | + | ||
| 86 | +:doc:`ctlike` |
doc/source/users/reference_manual/csmodelinfo.rst
| @@ -28,28 +28,28 @@ General parameters | @@ -28,28 +28,28 @@ General parameters | ||
| 28 | ------------------ | 28 | ------------------ |
| 29 | 29 | ||
| 30 | ``inmodel [file]`` | 30 | ``inmodel [file]`` |
| 31 | - Event list, counts cube, or observation definition file | 31 | + Input model XML file. |
| 32 | 32 | ||
| 33 | ``outds9file [file]`` | 33 | ``outds9file [file]`` |
| 34 | - Output DS9 region file containing soucre positions | 34 | + Output DS9 region file containing soucre positions. |
| 35 | 35 | ||
| 36 | ``(pnt_type=cross) <circle|box|diamond|cross|x|arrow|boxcircle> [string]`` | 36 | ``(pnt_type=cross) <circle|box|diamond|cross|x|arrow|boxcircle> [string]`` |
| 37 | - Marker type for point sources | 37 | + Marker type for point sources. |
| 38 | 38 | ||
| 39 | ``(pnt_mark_size=12) [integer]`` | 39 | ``(pnt_mark_size=12) [integer]`` |
| 40 | - Marker size for point sources | 40 | + Marker size for point sources. |
| 41 | 41 | ||
| 42 | ``(show_labels=yes) [boolean]`` | 42 | ``(show_labels=yes) [boolean]`` |
| 43 | Add source labels? | 43 | Add source labels? |
| 44 | 44 | ||
| 45 | ``(width=2) [integer]`` | 45 | ``(width=2) [integer]`` |
| 46 | - Line width for regions | 46 | + Line width for regions. |
| 47 | 47 | ||
| 48 | ``(fontfamily=helvetica) <helvetica|times|courier> [string]`` | 48 | ``(fontfamily=helvetica) <helvetica|times|courier> [string]`` |
| 49 | - Font for source labels | 49 | + Font for source labels. |
| 50 | 50 | ||
| 51 | ``(fontsize=12) [integer]`` | 51 | ``(fontsize=12) [integer]`` |
| 52 | - Font size for source labels | 52 | + Font size for source labels. |
| 53 | 53 | ||
| 54 | ``(fontweight=normal) <normal|bold> [string]`` | 54 | ``(fontweight=normal) <normal|bold> [string]`` |
| 55 | Use normal or bold font? | 55 | Use normal or bold font? |
| @@ -61,10 +61,10 @@ General parameters | @@ -61,10 +61,10 @@ General parameters | ||
| 61 | Show type of extended model in source name? | 61 | Show type of extended model in source name? |
| 62 | 62 | ||
| 63 | ``(free_color=green) [string]`` | 63 | ``(free_color=green) [string]`` |
| 64 | - Color for sources with free parameters (any ds9 color or hex code) | 64 | + Color for sources with free parameters (any ds9 color or hex code). |
| 65 | 65 | ||
| 66 | ``(fixed_color=magenta) [string]`` | 66 | ``(fixed_color=magenta) [string]`` |
| 67 | - Color for sources without free parameters (any ds9 color or hex code) | 67 | + Color for sources without free parameters (any ds9 color or hex code). |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | Standard parameters | 70 | Standard parameters |
doc/source/users/reference_manual/index.rst
| @@ -43,6 +43,7 @@ cscripts | @@ -43,6 +43,7 @@ cscripts | ||
| 43 | .. toctree:: | 43 | .. toctree:: |
| 44 | :maxdepth: 1 | 44 | :maxdepth: 1 |
| 45 | 45 | ||
| 46 | + csbkgmodel --- Generates background model for 3D analysis <csbkgmodel> | ||
| 46 | cscaldb --- Lists available instrument response functions <cscaldb> | 47 | cscaldb --- Lists available instrument response functions <cscaldb> |
| 47 | csebins --- Generates energy boundaries for stacked analysis <csebins> | 48 | csebins --- Generates energy boundaries for stacked analysis <csebins> |
| 48 | cslightcrv --- Computes light curve <cslightcrv> | 49 | cslightcrv --- Computes light curve <cslightcrv> |