Commit 40451b0949df60870ef31bbef575367091ddb5ef

Authored by Jürgen Knödlseder
1 parent 79735dc9

Add "inmodel" and "srcname" parameters to csphagen and use the spatial part of t…

…he source model to compute the ARF (#2292)
cscripts/csphagen.par
@@ -17,6 +17,8 @@ @@ -17,6 +17,8 @@
17 # Input and output parameters 17 # Input and output parameters
18 #============================ 18 #============================
19 inobs, f, a, obs.xml,,, "Input event list or observation definition XML file" 19 inobs, f, a, obs.xml,,, "Input event list or observation definition XML file"
  20 +inmodel, f, a, NONE,,, "Input model definition XML file (if NONE, use point source)"
  21 +srcname, s, a, Crab,,, "Source name"
20 caldb, s, a, prod2,,, "Calibration database" 22 caldb, s, a, prod2,,, "Calibration database"
21 irf, s, a, South_0.5h,,, "Instrument response function" 23 irf, s, a, South_0.5h,,, "Instrument response function"
22 inexclusion, f, h, NONE,,, "Sky map of exclusion regions" 24 inexclusion, f, h, NONE,,, "Sky map of exclusion regions"
cscripts/csphagen.py
@@ -45,6 +45,7 @@ class csphagen(ctools.csobservation): @@ -45,6 +45,7 @@ class csphagen(ctools.csobservation):
45 self._ebounds = gammalib.GEbounds() 45 self._ebounds = gammalib.GEbounds()
46 self._src_dir = gammalib.GSkyDir() 46 self._src_dir = gammalib.GSkyDir()
47 self._src_reg = gammalib.GSkyRegions() 47 self._src_reg = gammalib.GSkyRegions()
  48 + self._src_model = None
48 self._bkg_regs = [] 49 self._bkg_regs = []
49 self._excl_reg = None 50 self._excl_reg = None
50 self._has_exclusion = False 51 self._has_exclusion = False
@@ -123,7 +124,6 @@ class csphagen(ctools.csobservation): @@ -123,7 +124,6 @@ class csphagen(ctools.csobservation):
123 # Off region region the parameter 'bkgregfile' for all CTA observations 124 # Off region region the parameter 'bkgregfile' for all CTA observations
124 # without Off region 125 # without Off region
125 for obs in self.obs(): 126 for obs in self.obs():
126 - #if obs.instrument() == 'CTA':  
127 if obs.classname() == 'GCTAObservation': 127 if obs.classname() == 'GCTAObservation':
128 if obs.off_regions().is_empty(): 128 if obs.off_regions().is_empty():
129 filename = self['bkgregfile'].filename() 129 filename = self['bkgregfile'].filename()
@@ -160,6 +160,13 @@ class csphagen(ctools.csobservation): @@ -160,6 +160,13 @@ class csphagen(ctools.csobservation):
160 # allow counts cube) 160 # allow counts cube)
161 self._setup_observations(self.obs(), True, True, False) 161 self._setup_observations(self.obs(), True, True, False)
162 162
  163 + # Get spatial component of source model if an input model is defined
  164 + inmodel = self['inmodel'].filename()
  165 + if not self['inmodel'].is_undefined():
  166 + models = gammalib.GModels(inmodel)
  167 + name = self['srcname'].string()
  168 + self._src_model = models[name].spatial().clone()
  169 +
163 # Set energy bounds 170 # Set energy bounds
164 self._ebounds = self._create_ebounds() 171 self._ebounds = self._create_ebounds()
165 172
@@ -167,8 +174,9 @@ class csphagen(ctools.csobservation): @@ -167,8 +174,9 @@ class csphagen(ctools.csobservation):
167 self._src_reg = gammalib.GSkyRegions() 174 self._src_reg = gammalib.GSkyRegions()
168 175
169 # Exclusion map 176 # Exclusion map
170 - if self['inexclusion'].filename().is_fits():  
171 - self._excl_reg = gammalib.GSkyRegionMap(self['inexclusion'].filename()) 177 + if not self['inexclusion'].is_undefined():
  178 + inexclusion = self['inexclusion'].filename()
  179 + self._excl_reg = gammalib.GSkyRegionMap(inexclusion)
172 self._has_exclusion = True 180 self._has_exclusion = True
173 else: 181 else:
174 self._has_exclusion = False 182 self._has_exclusion = False
@@ -400,6 +408,10 @@ class csphagen(ctools.csobservation): @@ -400,6 +408,10 @@ class csphagen(ctools.csobservation):
400 outobs = gammalib.GObservations() 408 outobs = gammalib.GObservations()
401 self._bkg_regs = [] 409 self._bkg_regs = []
402 410
  411 + # Set spatial model
  412 + if self._src_model == None:
  413 + self._src_model = gammalib.GModelSpatialPointSource(self._src_dir)
  414 +
403 # Loop through observations and generate pha, arf, rmf files 415 # Loop through observations and generate pha, arf, rmf files
404 for obs in self.obs(): 416 for obs in self.obs():
405 417
@@ -420,7 +432,8 @@ class csphagen(ctools.csobservation): @@ -420,7 +432,8 @@ class csphagen(ctools.csobservation):
420 # If there are background regions then create On/Off observation 432 # If there are background regions then create On/Off observation
421 # and append it to the output container 433 # and append it to the output container
422 if bkg_reg.size() >= self['bkgregmin'].integer(): 434 if bkg_reg.size() >= self['bkgregmin'].integer():
423 - onoff = gammalib.GCTAOnOffObservation(obs, self._src_dir, 435 + onoff = gammalib.GCTAOnOffObservation(obs,
  436 + self._src_model,
424 etrue_ebounds, 437 etrue_ebounds,
425 self._ebounds, 438 self._ebounds,
426 self._src_reg, 439 self._src_reg,
doc/source/users/reference_manual/csphagen.rst
@@ -64,6 +64,14 @@ General parameters @@ -64,6 +64,14 @@ General parameters
64 ``inobs [file]`` 64 ``inobs [file]``
65 Input event list or observation definition XML file. 65 Input event list or observation definition XML file.
66 66
  67 +``inmodel [file]``
  68 + Input model XML file (if ``NONE`` a point source at the centre of the
  69 + source region is used).
  70 +
  71 +``srcname [string]``
  72 + Name of the source in the source model XML file which should be used
  73 + for ARF computation. Only the spatial part of the model is used.
  74 +
67 ``caldb [string]`` 75 ``caldb [string]``
68 Calibration database. 76 Calibration database.
69 77