156 Generate initial background model
160 sigma_min : float, optional
162 sigma_max : float, optional
167 model : `~gammalib.GModelData()`
171 if self[
'spatial'].string() ==
'IRF':
172 epivot = gammalib.GEnergy(1.0,
'TeV')
173 spectral = gammalib.GModelSpectralPlaw(1.0, 0.0, epivot)
174 model = gammalib.GCTAModelIrfBackground(spectral)
177 elif self[
'spatial'].string() ==
'AEFF':
178 epivot = gammalib.GEnergy(1.0,
'TeV')
179 spectral = gammalib.GModelSpectralPlaw(1.0e-13, -2.5, epivot)
180 model = gammalib.GCTAModelAeffBackground(spectral)
186 if self[
'spatial'].string() ==
'LOOKUP':
189 factor1 = gammalib.GCTAModelSpatialLookup(self[
'slufile'].filename())
192 elif self[
'spatial'].string() ==
'GAUSS':
195 factor1 = gammalib.GCTAModelRadialGauss(3.0)
196 factor1[
'Sigma'].min(sigma_min)
197 factor1[
'Sigma'].max(sigma_max)
200 elif self[
'spatial'].string() ==
'GAUSS(E)':
205 if self[
'snumbins'].integer() == 1:
206 factor1 = gammalib.GCTAModelRadialGauss(3.0)
207 factor1[
'Sigma'].min(sigma_min)
208 factor1[
'Sigma'].max(sigma_max)
210 emin = gammalib.GEnergy(self[
'smin'].real(),
'TeV')
211 emax = gammalib.GEnergy(self[
'smax'].real(),
'TeV')
212 energies = gammalib.GEnergies(self[
'snumbins'].integer(), emin, emax)
213 spectrum = gammalib.GModelSpectralConst(3.0)
214 nodes = gammalib.GModelSpectralNodes(spectrum, energies)
215 for i
in range(nodes.nodes()):
216 nodes[i*2+1].min(sigma_min)
217 nodes[i*2+1].max(sigma_max)
219 factor1 = gammalib.GCTAModelSpatialGaussSpectrum(nodes)
222 elif self[
'spatial'].string() ==
'PROFILE':
225 factor1 = gammalib.GCTAModelRadialProfile(2.0, 4.0, 5.0)
226 factor1[
'Width'].min(1.0)
227 factor1[
'Width'].max(10.0)
228 factor1[
'Core'].min(1.0)
229 factor1[
'Core'].max(10.0)
230 factor1[
'Tail'].min(1.0)
231 factor1[
'Tail'].max(10.0)
232 factor1[
'Tail'].free()
235 elif self[
'spatial'].string() ==
'POLYNOM':
238 factor1 = gammalib.GCTAModelRadialPolynom([1.0, -0.1, +0.1])
239 factor1[
'Coeff0'].min(0.1)
240 factor1[
'Coeff0'].max(10.0)
241 factor1[
'Coeff0'].fix()
242 factor1[
'Coeff1'].min(-10.0)
243 factor1[
'Coeff1'].max(10.0)
244 factor1[
'Coeff2'].min(-10.0)
245 factor1[
'Coeff2'].max(10.0)
252 if self[
'gradient'].boolean():
253 spatial = gammalib.GCTAModelSpatialMultiplicative()
254 factor2 = gammalib.GCTAModelSpatialGradient()
255 spatial.append(factor1)
256 spatial.append(factor2)
261 epivot = gammalib.GEnergy(1.0,
'TeV')
262 spectral = gammalib.GModelSpectralPlaw(3.0e-4, -1.5, epivot)
263 spectral[
'Prefactor'].min(1.0e-8)
266 model = gammalib.GCTAModelBackground(spatial, spectral)
269 if model
is not None:
270 model.name(
'Background')
312 Replace spectral model by node function
316 model : `~gammalib.GModelData()`
317 Input background model
321 model : `~gammalib.GModelData()`
322 Background model with spectral node function
325 spectrum = model.spectral()
328 energies = self._create_energies()
331 nodes = gammalib.GModelSpectralNodes(spectrum, energies)
335 for i
in range(nodes.size()):
336 nodes[i].min(1.0e-10*nodes[i].value())
339 model.spectral(nodes)
346 Generate background models
350 obs : `~gammalib.GObservations()`
351 Observations container
355 model : `~gammalib.GModelData()`
356 Background model component
359 self._log_header3(gammalib.EXPLICIT,
'Select events from observation')
365 self._log_header3(gammalib.EXPLICIT,
'Generate initial background model')
371 models = gammalib.GModels()
376 self._log_header3(gammalib.EXPLICIT,
'Fit initial background model')
379 like = ctools.ctlike(obs)
386 model = like.obs().
models()[0].copy()
389 if self[
'spectral'].string() ==
'NODES':
395 models = gammalib.GModels()
400 self._log_header3(gammalib.EXPLICIT,
'Fit nodes background model')
403 like = ctools.ctlike(obs)
410 model = like.obs().
models()[0].copy()
414 spectral = model.spectral()
415 nodes = spectral.nodes()
416 for i
in range(nodes):
417 iint = 2*(nodes - i) - 1
418 if spectral[iint].error() == 0.0:
419 spectral.remove(nodes - i - 1)
422 self._log_string(gammalib.EXPLICIT, str(opt))
467 self._log_observations(gammalib.NORMAL, self.obs(),
'Input observation')
471 for i
in range(obs.size()-1, -1, -1):
476 self._log_value(gammalib.NORMAL,
'Obs matching instrument', self.obs().size())
479 self._log_header1(gammalib.TERSE,
'Generate background models')
485 if self[
'runwise'].boolean():
492 self._log_models(gammalib.NORMAL, self.
_models,
'Output model')