Commit cfd52dd7ef30ec9006bd434b220b7e6b1b14edee

Authored by knodlseder
1 parent 937b71e2

add file function, source type, and offset angle

Showing 1 changed file with 39 additions and 37 deletions
scripts/cssens.py
@@ -3,11 +3,19 @@ @@ -3,11 +3,19 @@
3 # This script computes the CTA sensitivity for a number of energy bins using 3 # This script computes the CTA sensitivity for a number of energy bins using
4 # ctlike. Crab spectra are fitted in narrow energy bins to simulated data, 4 # ctlike. Crab spectra are fitted in narrow energy bins to simulated data,
5 # and the flux level is determined that leads to a particular significance. 5 # and the flux level is determined that leads to a particular significance.
  6 +#
6 # The significance can be either determined using the Test Statistic (which 7 # The significance can be either determined using the Test Statistic (which
7 # is defined as twice the likelihood difference between fitting with and 8 # is defined as twice the likelihood difference between fitting with and
8 # without the test source) or using the source model scaling factor (or 9 # without the test source) or using the source model scaling factor (or
9 # Prefactor) divided by its statistical error. The latter has been turned 10 # Prefactor) divided by its statistical error. The latter has been turned
10 -# out to be more reliable, and is used as default parameter. 11 +# out to be more reliable, and is used as the default parameter.
  12 +#
  13 +# As background model, a GCTAModelRadialGauss model is used for the spatial
  14 +# component. For the spectral component, either a file function is used
  15 +# (specified by the "bkg" parameter), or if left blank, a power law adjusted
  16 +# to Konrad's configuration "E" performance file is employed.
  17 +#
  18 +# The source is modelled as a point source
11 # 19 #
12 # Copyright (C) 2011 Jurgen Knodlseder 20 # Copyright (C) 2011 Jurgen Knodlseder
13 # 21 #
@@ -49,7 +57,7 @@ class cssens(GApplication): @@ -49,7 +57,7 @@ class cssens(GApplication):
49 """ 57 """
50 # Set name 58 # Set name
51 self.name = "cssens" 59 self.name = "cssens"
52 - self.version = "0.1.1" 60 + self.version = "0.2.0"
53 61
54 # Make sure that parfile exists 62 # Make sure that parfile exists
55 file = self.parfile() 63 file = self.parfile()
@@ -100,6 +108,9 @@ class cssens(GApplication): @@ -100,6 +108,9 @@ class cssens(GApplication):
100 pars.append(GPar("outfile","f","h","sensitivity.dat","","","Output file name")) 108 pars.append(GPar("outfile","f","h","sensitivity.dat","","","Output file name"))
101 pars.append(GPar("caldb","s","a","$GAMMALIB/share/caldb/cta","","","Calibration database")) 109 pars.append(GPar("caldb","s","a","$GAMMALIB/share/caldb/cta","","","Calibration database"))
102 pars.append(GPar("irf","s","a","kb_E_50h_v3","","","Instrument response function")) 110 pars.append(GPar("irf","s","a","kb_E_50h_v3","","","Instrument response function"))
  111 + pars.append(GPar("type","s","a","point","","","Source model type (point/gauss/shell/disk)"))
  112 + pars.append(GPar("offset","r","a","0.0","0.0","","Source offset angle (deg)"))
  113 + pars.append(GPar("bkg","s","a","$GAMMALIB/share/models/bkg_kb_E_50h_v3.txt","","","Background model file function (none=power law for E)"))
103 pars.append(GPar("duration","r","a","180000.0","","","Effective exposure time (s)")) 114 pars.append(GPar("duration","r","a","180000.0","","","Effective exposure time (s)"))
104 pars.append(GPar("rad","r","a","5.0","","","Radius of ROI (deg)")) 115 pars.append(GPar("rad","r","a","5.0","","","Radius of ROI (deg)"))
105 pars.append(GPar("enumbins","i","h","0","","","Number of energy bins (0=unbinned)")) 116 pars.append(GPar("enumbins","i","h","0","","","Number of energy bins (0=unbinned)"))
@@ -124,6 +135,9 @@ class cssens(GApplication): @@ -124,6 +135,9 @@ class cssens(GApplication):
124 self.m_outfile = self["outfile"].filename() 135 self.m_outfile = self["outfile"].filename()
125 self.m_caldb = self["caldb"].string() 136 self.m_caldb = self["caldb"].string()
126 self.m_irf = self["irf"].string() 137 self.m_irf = self["irf"].string()
  138 + self.m_type = self["type"].string()
  139 + self.m_offset = self["offset"].real()
  140 + self.m_bkg = self["bkg"].string()
127 self.m_duration = self["duration"].real() 141 self.m_duration = self["duration"].real()
128 self.m_roi = self["rad"].real() 142 self.m_roi = self["rad"].real()
129 self.m_nbins = self["enumbins"].integer() 143 self.m_nbins = self["enumbins"].integer()
@@ -179,7 +193,10 @@ class cssens(GApplication): @@ -179,7 +193,10 @@ class cssens(GApplication):
179 full_model = GModels() 193 full_model = GModels()
180 bkg_model.append(self.set_bkg_model()) 194 bkg_model.append(self.set_bkg_model())
181 full_model.append(self.set_bkg_model()) 195 full_model.append(self.set_bkg_model())
182 - full_model.append(self.set_src_model(0.0, 0.0, index=self.m_index)) 196 + full_model.append(self.set_src_model(0.0, \
  197 + self.m_offset, \
  198 + type=self.m_type, \
  199 + index=self.m_index))
183 200
184 # Write models into logger 201 # Write models into logger
185 if self.logTerse(): 202 if self.logTerse():
@@ -271,15 +288,19 @@ class cssens(GApplication): @@ -271,15 +288,19 @@ class cssens(GApplication):
271 # Define radial component 288 # Define radial component
272 radial = GCTAModelRadialGauss(3.0) 289 radial = GCTAModelRadialGauss(3.0)
273 290
274 - # Define spectral component  
275 - spectrum = GModelSpectralPlaw(61.8, -1.85)  
276 - spectrum["Prefactor"].scale(1.0e-6)  
277 - spectrum["PivotEnergy"].value(1.0)  
278 - spectrum["PivotEnergy"].scale(1.0e6)  
279 - if fitidx:  
280 - spectrum["Index"].free() 291 + # Define spectral component. If a background model is given then
  292 + # use a file function. Otherwise use a static power law.
  293 + if len(self.m_bkg) > 0:
  294 + spectrum = GModelSpectralFunc(self.m_bkg)
281 else: 295 else:
282 - spectrum["Index"].fix() 296 + spectrum = GModelSpectralPlaw(61.8, -1.85)
  297 + spectrum["Prefactor"].scale(1.0e-6)
  298 + spectrum["PivotEnergy"].value(1.0)
  299 + spectrum["PivotEnergy"].scale(1.0e6)
  300 + if fitidx:
  301 + spectrum["Index"].free()
  302 + else:
  303 + spectrum["Index"].fix()
283 304
284 # Create background model 305 # Create background model
285 model = GCTAModelRadialAcceptance(radial, spectrum) 306 model = GCTAModelRadialAcceptance(radial, spectrum)
@@ -426,14 +447,6 @@ class cssens(GApplication): @@ -426,14 +447,6 @@ class cssens(GApplication):
426 LogL_bgm = like.opt().value() 447 LogL_bgm = like.opt().value()
427 npred_bgm = like.obs().npred() 448 npred_bgm = like.obs().npred()
428 449
429 - # Store results  
430 - Pre_bgm = result_bgm[0]['Prefactor'].value()  
431 - ePre_bgm = result_bgm[0]['Prefactor'].error()  
432 - Inx_bgm = result_bgm[0]['Index'].value()  
433 - eInx_bgm = result_bgm[0]['Index'].error()  
434 - Sig_bgm = result_bgm[0]['Sigma'].value()  
435 - eSig_bgm = result_bgm[0]['Sigma'].error()  
436 -  
437 # Write background fit results 450 # Write background fit results
438 if self.logExplicit(): 451 if self.logExplicit():
439 self.log.header3("Background model fit") 452 self.log.header3("Background model fit")
@@ -459,22 +472,11 @@ class cssens(GApplication): @@ -459,22 +472,11 @@ class cssens(GApplication):
459 ts = 2.0*(LogL_bgm-LogL_all) 472 ts = 2.0*(LogL_bgm-LogL_all)
460 473
461 # Get fitted Crab, photon and energy fluxes 474 # Get fitted Crab, photon and energy fluxes
462 - cflux = result_all[0]['Prefactor'].value()  
463 - pflux = cast_GModelSky(result_all["Test"]).spectral().flux(emin, emax)  
464 - eflux = cast_GModelSky(result_all["Test"]).spectral().eflux(emin, emax) 475 + cflux = result_all["Test"]['Prefactor'].value()
  476 + cflux_err = result_all["Test"]['Prefactor'].error()
  477 + pflux = cast_GModelSky(result_all["Test"]).spectral().flux(emin, emax)
  478 + eflux = cast_GModelSky(result_all["Test"]).spectral().eflux(emin, emax)
465 479
466 - # Store results  
467 - Pre_all = result_all[0]['Prefactor'].value()  
468 - ePre_all = result_all[0]['Prefactor'].error()  
469 - Inx_all = result_all[0]['Index'].value()  
470 - eInx_all = result_all[0]['Index'].error()  
471 - Sig_all = result_all[0]['Sigma'].value()  
472 - eSig_all = result_all[0]['Sigma'].error()  
473 - SPre_all = result_all[1]['Prefactor'].value()  
474 - eSPre_all = result_all[1]['Prefactor'].error()  
475 - SInx_all = result_all[1]['Index'].value()  
476 - eSInx_all = result_all[1]['Index'].error()  
477 -  
478 # Write background and test source fit results 480 # Write background and test source fit results
479 if self.logExplicit(): 481 if self.logExplicit():
480 self.log.header3("Background and test source model fit") 482 self.log.header3("Background and test source model fit")
@@ -520,9 +522,9 @@ class cssens(GApplication): @@ -520,9 +522,9 @@ class cssens(GApplication):
520 if ts > 0: 522 if ts > 0:
521 correct = math.sqrt(self.m_ts_thres/ts) 523 correct = math.sqrt(self.m_ts_thres/ts)
522 else: 524 else:
523 - if SPre_all > 0 and eSPre_all > 0:  
524 - correct = math.sqrt(self.m_ts_thres)/(SPre_all/eSPre_all)  
525 - flux = correct * SPre_all 525 + if cflux > 0 and cflux_err > 0:
  526 + correct = math.sqrt(self.m_ts_thres)/(cflux/cflux_err)
  527 + flux = correct * cflux
526 pflux = correct * pflux 528 pflux = correct * pflux
527 eflux = correct * eflux 529 eflux = correct * eflux
528 flux_value.append(flux) 530 flux_value.append(flux)