Commit f12b32d12afccf3e833c6e5988797084cf7900b2
1 parent
c5d689f9
Add GAUSS(E) model to csbkgmodel (#2868)
Showing
5 changed files
with
79 additions
and
15 deletions
ChangeLog
| 1 | -2019-04-03 | 1 | +2019-04-14 |
| 2 | 2 | ||
| 3 | * Version 1.6.0 released | 3 | * Version 1.6.0 released |
| 4 | ======================== | 4 | ======================== |
| 5 | 5 | ||
| 6 | + Add GAUSS(E) model to csbkgmodel (#2868) | ||
| 6 | Move ctool::set_obs_bounds() to ctobservation::set_obs_bounds() | 7 | Move ctool::set_obs_bounds() to ctobservation::set_obs_bounds() |
| 7 | Log warning if edisp=no (#2842) | 8 | Log warning if edisp=no (#2842) |
| 8 | Fix ring background computation in ctskymap for small roiradius (#2839) | 9 | Fix ring background computation in ctskymap for small roiradius (#2839) |
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 | -3 April 2019 | 3 | +14 April 2019 |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | Introduction | 6 | Introduction |
| @@ -270,6 +270,9 @@ None | @@ -270,6 +270,9 @@ None | ||
| 270 | 270 | ||
| 271 | csbkgmodel - Generate background model for 3D analysis | 271 | csbkgmodel - Generate background model for 3D analysis |
| 272 | ------------------------------------------------------ | 272 | ------------------------------------------------------ |
| 273 | +A model named GAUSS(E) was added to implement an energy-dependent Gaussian | ||
| 274 | +spatial function (#2868). | ||
| 275 | + | ||
| 273 | Introduced the script that generates a background for a 3D analysis. This | 276 | Introduced the script that generates a background for a 3D analysis. This |
| 274 | script is particularly useful to generate a background model for the analysis | 277 | script is particularly useful to generate a background model for the analysis |
| 275 | of the H.E.S.S. public data release (#2694). | 278 | of the H.E.S.S. public data release (#2694). |
cscripts/csbkgmodel.par
| @@ -25,13 +25,16 @@ outmodel, f, a, model.xml,,, "Output model definition XML file" | @@ -25,13 +25,16 @@ outmodel, f, a, model.xml,,, "Output model definition XML file" | ||
| 25 | # Script parameters | 25 | # Script parameters |
| 26 | #================== | 26 | #================== |
| 27 | instrument, s, a, CTA,,, "Instrument name (for multi-instrument analysis)" | 27 | instrument, s, a, CTA,,, "Instrument name (for multi-instrument analysis)" |
| 28 | -spatial, s, a, GAUSS,IRF|AEFF|GAUSS,, "Spatial model component" | 28 | +spatial, s, a, GAUSS,IRF|AEFF|GAUSS|GAUSS(E),, "Spatial model component" |
| 29 | +snumbins, i, a, 3,1,200, "Number of energy nodes for sigma(E)" | ||
| 30 | +smin, r, a, 0.1,,, "Lower energy limit for sigma(E) energy nodes (TeV)" | ||
| 31 | +smax, r, a, 10.0,,, "Upper energy limit for sigma(E) energy nodes (TeV)" | ||
| 29 | gradient, b, a, yes,,, "Allow for spatial gradient?" | 32 | gradient, b, a, yes,,, "Allow for spatial gradient?" |
| 30 | spectral, s, a, NODES,PLAW|NODES,, "Spectral model component" | 33 | spectral, s, a, NODES,PLAW|NODES,, "Spectral model component" |
| 31 | -ebinalg, s, a, LOG,FILE|LIN|LOG,, "Algorithm for defining energy nodes" | 34 | +ebinalg, s, a, LOG,FILE|LIN|LOG,, "Algorithm for defining spectral energy nodes" |
| 32 | emin, r, a, 0.1,,, "Lower energy limit (TeV)" | 35 | emin, r, a, 0.1,,, "Lower energy limit (TeV)" |
| 33 | emax, r, a, 100.0,,, "Upper energy limit (TeV)" | 36 | emax, r, a, 100.0,,, "Upper energy limit (TeV)" |
| 34 | -enumbins, i, a, 8,1,200, "Number of energy nodes" | 37 | +enumbins, i, a, 8,1,200, "Number of spectral energy nodes" |
| 35 | ebinfile, f, a, NONE,,, "Name of the file containing the energy node definition" | 38 | ebinfile, f, a, NONE,,, "Name of the file containing the energy node definition" |
| 36 | runwise, b, a, yes,,, "Generate runwise background model?" | 39 | runwise, b, a, yes,,, "Generate runwise background model?" |
| 37 | rad, r, h, 2.0,,, "Radius for event selection (degrees)" | 40 | rad, r, h, 2.0,,, "Radius for event selection (degrees)" |
cscripts/csbkgmodel.py
| @@ -95,10 +95,15 @@ class csbkgmodel(ctools.csobservation): | @@ -95,10 +95,15 @@ class csbkgmodel(ctools.csobservation): | ||
| 95 | 95 | ||
| 96 | # Query input parameters | 96 | # Query input parameters |
| 97 | spatial = self['spatial'].string() | 97 | spatial = self['spatial'].string() |
| 98 | - if spatial == 'GAUSS': | 98 | + if spatial == 'GAUSS(E)': |
| 99 | + snumbins = self['snumbins'].integer() | ||
| 100 | + if snumbins > 1: | ||
| 101 | + self['smin'].real() | ||
| 102 | + self['smax'].real() | ||
| 103 | + if spatial == 'GAUSS' or spatial == 'GAUSS(E)': | ||
| 99 | self['gradient'].boolean() | 104 | self['gradient'].boolean() |
| 100 | - self['spectral'].string() | ||
| 101 | - if spatial == 'NODES': | 105 | + spectral = self['spectral'].string() |
| 106 | + if spectral == 'NODES': | ||
| 102 | self._create_energies() | 107 | self._create_energies() |
| 103 | self['runwise'].boolean() | 108 | self['runwise'].boolean() |
| 104 | self['emin'].real() | 109 | self['emin'].real() |
| @@ -142,10 +147,17 @@ class csbkgmodel(ctools.csobservation): | @@ -142,10 +147,17 @@ class csbkgmodel(ctools.csobservation): | ||
| 142 | # Return instrument | 147 | # Return instrument |
| 143 | return instrument | 148 | return instrument |
| 144 | 149 | ||
| 145 | - def _generate_initial_model(self): | 150 | + def _generate_initial_model(self, sigma_min=2.0, sigma_max=1000.0): |
| 146 | """ | 151 | """ |
| 147 | Generate initial background model | 152 | Generate initial background model |
| 148 | 153 | ||
| 154 | + Parameters | ||
| 155 | + ---------- | ||
| 156 | + sigma_min : float, optional | ||
| 157 | + Minimum sigma | ||
| 158 | + sigma_max : float, optional | ||
| 159 | + Maximum sigma | ||
| 160 | + | ||
| 149 | Returns | 161 | Returns |
| 150 | ------- | 162 | ------- |
| 151 | model : `~gammalib.GModelData()` | 163 | model : `~gammalib.GModelData()` |
| @@ -165,22 +177,65 @@ class csbkgmodel(ctools.csobservation): | @@ -165,22 +177,65 @@ class csbkgmodel(ctools.csobservation): | ||
| 165 | 177 | ||
| 166 | # Handle GAUSS model | 178 | # Handle GAUSS model |
| 167 | elif self['spatial'].string() == 'GAUSS': | 179 | elif self['spatial'].string() == 'GAUSS': |
| 180 | + | ||
| 181 | + # Set spatial model | ||
| 182 | + factor1 = gammalib.GCTAModelRadialGauss(3.0) | ||
| 183 | + factor1['Sigma'].min(sigma_min) | ||
| 184 | + factor1['Sigma'].max(sigma_max) | ||
| 185 | + | ||
| 186 | + # Optionally add gradient | ||
| 168 | if self['gradient'].boolean(): | 187 | if self['gradient'].boolean(): |
| 169 | spatial = gammalib.GCTAModelSpatialMultiplicative() | 188 | spatial = gammalib.GCTAModelSpatialMultiplicative() |
| 189 | + factor2 = gammalib.GCTAModelSpatialGradient() | ||
| 190 | + spatial.append(factor1) | ||
| 191 | + spatial.append(factor2) | ||
| 192 | + else: | ||
| 193 | + spatial = factor1 | ||
| 194 | + | ||
| 195 | + # Set spectral model | ||
| 196 | + epivot = gammalib.GEnergy(1.0, 'TeV') | ||
| 197 | + spectral = gammalib.GModelSpectralPlaw(3.0e-4, -1.5, epivot) | ||
| 198 | + spectral['Prefactor'].min(1.0e-8) | ||
| 199 | + | ||
| 200 | + # Set background model | ||
| 201 | + model = gammalib.GCTAModelBackground(spatial, spectral) | ||
| 202 | + | ||
| 203 | + # Handle GAUSS(E) model | ||
| 204 | + elif self['spatial'].string() == 'GAUSS(E)': | ||
| 205 | + | ||
| 206 | + # Set spatial model | ||
| 207 | + if self['snumbins'].integer() == 1: | ||
| 170 | factor1 = gammalib.GCTAModelRadialGauss(3.0) | 208 | factor1 = gammalib.GCTAModelRadialGauss(3.0) |
| 171 | - factor1['Sigma'].min(1.5) | ||
| 172 | - factor1['Sigma'].max(10.0) | 209 | + factor1['Sigma'].min(sigma_min) |
| 210 | + factor1['Sigma'].max(sigma_max) | ||
| 211 | + else: | ||
| 212 | + emin = gammalib.GEnergy(self['smin'].real(), 'TeV') | ||
| 213 | + emax = gammalib.GEnergy(self['smax'].real(), 'TeV') | ||
| 214 | + energies = gammalib.GEnergies(self['snumbins'].integer(), emin, emax) | ||
| 215 | + spectrum = gammalib.GModelSpectralConst(3.0) | ||
| 216 | + nodes = gammalib.GModelSpectralNodes(spectrum, energies) | ||
| 217 | + for i in range(nodes.nodes()): | ||
| 218 | + nodes[i*2+1].min(sigma_min) | ||
| 219 | + nodes[i*2+1].max(sigma_max) | ||
| 220 | + nodes.autoscale() | ||
| 221 | + factor1 = gammalib.GCTAModelSpatialGaussSpectrum(nodes) | ||
| 222 | + | ||
| 223 | + # Optionally add gradient | ||
| 224 | + if self['gradient'].boolean(): | ||
| 225 | + spatial = gammalib.GCTAModelSpatialMultiplicative() | ||
| 173 | factor2 = gammalib.GCTAModelSpatialGradient() | 226 | factor2 = gammalib.GCTAModelSpatialGradient() |
| 174 | spatial.append(factor1) | 227 | spatial.append(factor1) |
| 175 | spatial.append(factor2) | 228 | spatial.append(factor2) |
| 176 | else: | 229 | else: |
| 177 | - spatial = gammalib.GCTAModelRadialGauss(3.0) | ||
| 178 | - spatial['Sigma'].min(1.5) | ||
| 179 | - spatial['Sigma'].max(10.0) | 230 | + spatial = factor1 |
| 231 | + | ||
| 232 | + # Set spectral model | ||
| 180 | epivot = gammalib.GEnergy(1.0, 'TeV') | 233 | epivot = gammalib.GEnergy(1.0, 'TeV') |
| 181 | spectral = gammalib.GModelSpectralPlaw(3.0e-4, -1.5, epivot) | 234 | spectral = gammalib.GModelSpectralPlaw(3.0e-4, -1.5, epivot) |
| 182 | spectral['Prefactor'].min(1.0e-8) | 235 | spectral['Prefactor'].min(1.0e-8) |
| 183 | - model = gammalib.GCTAModelBackground(spatial, spectral) | 236 | + |
| 237 | + # Set background model | ||
| 238 | + model = gammalib.GCTAModelBackground(spatial, spectral) | ||
| 184 | 239 | ||
| 185 | # Any other strings (should never occur) | 240 | # Any other strings (should never occur) |
| 186 | else: | 241 | else: |
doc/source/admin/release_history/1.6.rst
| @@ -46,6 +46,8 @@ Bug fixes | @@ -46,6 +46,8 @@ Bug fixes | ||
| 46 | Improvements | 46 | Improvements |
| 47 | ------------ | 47 | ------------ |
| 48 | 48 | ||
| 49 | +* [`2868 <https://cta-redmine.irap.omp.eu/issues/2868>`_] - | ||
| 50 | + Add ``GAUSS(E)`` model to :ref:`csbkgmodel` | ||
| 49 | * [`2842 <https://cta-redmine.irap.omp.eu/issues/2842>`_] - | 51 | * [`2842 <https://cta-redmine.irap.omp.eu/issues/2842>`_] - |
| 50 | Log warning if ``edisp=no`` | 52 | Log warning if ``edisp=no`` |
| 51 | * Add ``max_iter`` parameter to :ref:`ctbutterfly`, :ref:`cterror`, | 53 | * Add ``max_iter`` parameter to :ref:`ctbutterfly`, :ref:`cterror`, |