Commit 04e6a28189f2fbe86862aff8491d25b3567ee0db

Authored by Jürgen Knödlseder
1 parent e35c6b25

Use ctool::create_energies() method in csbkgmodel

cscripts/csbkgmodel.par
@@ -25,7 +25,12 @@ outmodel, f, a, model.xml,,, "Output model definition XML file" @@ -25,7 +25,12 @@ outmodel, f, a, model.xml,,, "Output model definition XML file"
25 instrument, s, a, CTA,,, "Instrument name (for multi-instrument analysis)" 25 instrument, s, a, CTA,,, "Instrument name (for multi-instrument analysis)"
26 spatial, s, a, GAUSS,IRF|AEFF|GAUSS,, "Spatial model component" 26 spatial, s, a, GAUSS,IRF|AEFF|GAUSS,, "Spatial model component"
27 gradient, b, a, yes,,, "Allow for spatial gradient?" 27 gradient, b, a, yes,,, "Allow for spatial gradient?"
28 -spectral, s, a, HESS,PLAW|HESS,, "Spectral model component" 28 +spectral, s, a, NODES,PLAW|NODES,, "Spectral model component"
  29 +ebinalg, s, a, LOG,FILE|LIN|LOG,, "Algorithm for defining energy nodes"
  30 +emin, r, a, 0.1,,, "First node energy (TeV)"
  31 +emax, r, a, 100.0,,, "Last node energy (TeV)"
  32 +enumbins, i, a, 10,1,200, "Number of energy nodes"
  33 +ebinfile, f, a, NONE,,, "Name of the file containing the energy node definition"
29 runwise, b, a, yes,,, "Generate runwise background model?" 34 runwise, b, a, yes,,, "Generate runwise background model?"
30 rad, r, h, 2.0,,, "Radius for event selection (degrees)" 35 rad, r, h, 2.0,,, "Radius for event selection (degrees)"
31 36
cscripts/csbkgmodel.py
@@ -65,6 +65,8 @@ class csbkgmodel(ctools.csobservation): @@ -65,6 +65,8 @@ class csbkgmodel(ctools.csobservation):
65 if self['spatial'].string() == 'GAUSS': 65 if self['spatial'].string() == 'GAUSS':
66 self['gradient'].boolean() 66 self['gradient'].boolean()
67 self['spectral'].string() 67 self['spectral'].string()
  68 + if self['spatial'].string() == 'NODES':
  69 + self._create_energies()
68 self['runwise'].boolean() 70 self['runwise'].boolean()
69 self['rad'].real() 71 self['rad'].real()
70 72
@@ -204,16 +206,8 @@ class csbkgmodel(ctools.csobservation): @@ -204,16 +206,8 @@ class csbkgmodel(ctools.csobservation):
204 # Extract spectral model of background component 206 # Extract spectral model of background component
205 spectrum = model.spectral() 207 spectrum = model.spectral()
206 208
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')) 209 + # Define node energies
  210 + energies = self._create_energies()
217 211
218 # Create node spectrum 212 # Create node spectrum
219 nodes = gammalib.GModelSpectralNodes(spectrum, energies) 213 nodes = gammalib.GModelSpectralNodes(spectrum, energies)
@@ -221,7 +215,7 @@ class csbkgmodel(ctools.csobservation): @@ -221,7 +215,7 @@ class csbkgmodel(ctools.csobservation):
221 215
222 # Set minimum node intensities (this avoids NaNs during model fitting) 216 # Set minimum node intensities (this avoids NaNs during model fitting)
223 for i in range(nodes.size()): 217 for i in range(nodes.size()):
224 - nodes[i].min(1.0e-6*nodes[i].value()) 218 + nodes[i].min(1.0e-10*nodes[i].value())
225 219
226 # Set node spectrum 220 # Set node spectrum
227 model.spectral(nodes) 221 model.spectral(nodes)
@@ -270,9 +264,9 @@ class csbkgmodel(ctools.csobservation): @@ -270,9 +264,9 @@ class csbkgmodel(ctools.csobservation):
270 # Extract fitted model 264 # Extract fitted model
271 model = like.obs().models()[0].copy() 265 model = like.obs().models()[0].copy()
272 266
273 - # If a HESS model is requested then refit a node spectrum  
274 - if self['spectral'].string() == 'HESS':  
275 - 267 + # If a NODES model is requested then refit a node spectrum
  268 + if self['spectral'].string() == 'NODES':
  269 +
276 # Create nodes spectrum from fitted initial model 270 # Create nodes spectrum from fitted initial model
277 model = self._create_nodes(model) 271 model = self._create_nodes(model)
278 272
doc/source/users/reference_manual/csbkgmodel.rst
@@ -42,6 +42,25 @@ General parameters @@ -42,6 +42,25 @@ General parameters
42 ``HESS`` specifies a piecewise broken power-law using 8 energy nodes 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. 43 spread over the energy range from 100 GeV to 12.8 TeV.
44 44
  45 +``ebinalg <FILE|LIN|LOG> [string]``
  46 + Algorithm for defining energy nodes. For ``FILE``, the energy nodes are
  47 + defined in a FITS file that is specified by the ``ebinfile`` parameter,
  48 + for ``LIN`` and ``LOG`` there will be ``enumbins`` energy nodes spaced
  49 + linearly or logarithmically between ``emin`` and ``emax``, respectively.
  50 +
  51 +``emin [real]``
  52 + First node energy (in TeV) if ``LIN`` or ``LOG`` energy algorithms are
  53 + used.
  54 +
  55 +``emax [real]``
  56 + Last node energy (in TeV) if ``LIN`` or ``LOG`` energy algorithms are used.
  57 +
  58 +``enumbins [integer]``
  59 + Number of energy nodes if ``LIN`` or ``LOG`` energy algorithms are used.
  60 +
  61 +``ebinfile [file]``
  62 + Name of the file containing the energy node definition if ``ebinalg=FILE``.
  63 +
45 ``runwise [boolean]`` 64 ``runwise [boolean]``
46 Generate runwise background model? If ``yes`` is specified a background 65 Generate runwise background model? If ``yes`` is specified a background
47 model component for each observation in the observation definition XML 66 model component for each observation in the observation definition XML