Commit ef55721a179c29b384f1dc7a0a0d134f7dc562ef
1 parent
07c8ec4a
Add hidden etruebins parameter to csphagen that allows setting of number of true…
… energy bins per decade.
Showing
3 changed files
with
65 additions
and
3 deletions
cscripts/csphagen.par
| ... | ... | @@ -42,6 +42,7 @@ bkgmethod, s, h, REFLECTED,REFLECTED,, "Method for background estimation" |
| 42 | 42 | bkgregmin, i, h, 2,1,1000, "Minimum number of background regions" |
| 43 | 43 | maxoffset, r, h, 4.0,,, "Maximum offset of source from camera center to accept observation" |
| 44 | 44 | stack, b, a, no,,, "Stack multiple observations into single PHA, ARF and RMF files?" |
| 45 | +etruebins, i, h, 30,,, "Number of bins per decade for true energy bins" | |
| 45 | 46 | |
| 46 | 47 | # |
| 47 | 48 | # Standard parameters | ... | ... |
cscripts/csphagen.py
| ... | ... | @@ -121,7 +121,7 @@ class csphagen(ctools.csobservation): |
| 121 | 121 | |
| 122 | 122 | Parameters |
| 123 | 123 | ---------- |
| 124 | - obs : `~gammalib.GObservation()` | |
| 124 | + obs : `~gammalib.GCTAObservation()` | |
| 125 | 125 | CTA observation |
| 126 | 126 | |
| 127 | 127 | Returns |
| ... | ... | @@ -147,7 +147,7 @@ class csphagen(ctools.csobservation): |
| 147 | 147 | if self._srcshape == 'CIRCLE': |
| 148 | 148 | # angular separation of reflected regions wrt camera center |
| 149 | 149 | # and number |
| 150 | - alpha = 1.05 * 2 * self._rad / offset | |
| 150 | + alpha = 1.05 * 2.0 * self._rad / offset | |
| 151 | 151 | # 1.05 ensures background regions do not overlap due to |
| 152 | 152 | # numerical precision issues |
| 153 | 153 | N = int(2.0 * math.pi / alpha) |
| ... | ... | @@ -179,6 +179,60 @@ class csphagen(ctools.csobservation): |
| 179 | 179 | # Return reflected regions |
| 180 | 180 | return regions |
| 181 | 181 | |
| 182 | + def _set_models(self, obs): | |
| 183 | + """ | |
| 184 | + Set models in observation container | |
| 185 | + | |
| 186 | + Parameters | |
| 187 | + ---------- | |
| 188 | + obs : `~gammalib.GObservations()` | |
| 189 | + Observation container | |
| 190 | + | |
| 191 | + Returns | |
| 192 | + ------- | |
| 193 | + obs : `~gammalib.GObservations()` | |
| 194 | + Observation container | |
| 195 | + """ | |
| 196 | + # Initialise model container | |
| 197 | + models = gammalib.GModels() | |
| 198 | + | |
| 199 | + # Loop over all models and replace CTA background model by CTAOnOff | |
| 200 | + # background model | |
| 201 | + for model in self.obs().models(): | |
| 202 | + if 'GCTA' in model.classname() and 'CTA' in model.instruments(): | |
| 203 | + model.instruments('CTAOnOff') | |
| 204 | + models.append(model) | |
| 205 | + | |
| 206 | + # Append model to observation container | |
| 207 | + obs.models(models) | |
| 208 | + | |
| 209 | + # Return observation container | |
| 210 | + return obs | |
| 211 | + | |
| 212 | + def _etrue_ebounds(self): | |
| 213 | + """ | |
| 214 | + Set true energy boundaries | |
| 215 | + | |
| 216 | + Returns | |
| 217 | + ------- | |
| 218 | + ebounds : `~gammalib.GEbounds()` | |
| 219 | + True energy boundaries | |
| 220 | + """ | |
| 221 | + # Determine minimum and maximum energies | |
| 222 | + emin = self._ebounds.emin() | |
| 223 | + emax = self._ebounds.emax() | |
| 224 | + | |
| 225 | + # Determine number of energy bins | |
| 226 | + n_decades = (emax.log10TeV() - emin.log10TeV()) | |
| 227 | + n_bins = int(n_decades * float(self['etruebins'].integer())) + 1 | |
| 228 | + | |
| 229 | + # Set energy boundaries | |
| 230 | + ebounds = gammalib.GEbounds(n_bins, emin, emax) | |
| 231 | + | |
| 232 | + # Return energy boundaries | |
| 233 | + return ebounds | |
| 234 | + | |
| 235 | + | |
| 182 | 236 | # Public methods |
| 183 | 237 | def run(self): |
| 184 | 238 | """ |
| ... | ... | @@ -201,6 +255,7 @@ class csphagen(ctools.csobservation): |
| 201 | 255 | # Initialise run variables |
| 202 | 256 | outobs = gammalib.GObservations() |
| 203 | 257 | self._bkg_regs = [] |
| 258 | + etrue_ebounds = self._etrue_ebounds() | |
| 204 | 259 | |
| 205 | 260 | # Loop through observations and generate pha, arf, rmf files |
| 206 | 261 | for obs in self.obs(): |
| ... | ... | @@ -217,7 +272,7 @@ class csphagen(ctools.csobservation): |
| 217 | 272 | # and append it to the output container |
| 218 | 273 | if bkg_reg.size() >= self['bkgregmin'].integer(): |
| 219 | 274 | onoff = gammalib.GCTAOnOffObservation(obs, self._src_dir, |
| 220 | - self._ebounds, | |
| 275 | + etrue_ebounds, | |
| 221 | 276 | self._ebounds, |
| 222 | 277 | self._src_reg, |
| 223 | 278 | bkg_reg) |
| ... | ... | @@ -242,6 +297,9 @@ class csphagen(ctools.csobservation): |
| 242 | 297 | outobs = gammalib.GObservations() |
| 243 | 298 | outobs.append(stacked_obs) |
| 244 | 299 | |
| 300 | + # Set models in output container | |
| 301 | + outobs = self._set_models(outobs) | |
| 302 | + | |
| 245 | 303 | # Set observation container |
| 246 | 304 | self.obs(outobs) |
| 247 | 305 | ... | ... |
doc/source/users/reference_manual/csphagen.rst
| ... | ... | @@ -108,6 +108,9 @@ General parameters |
| 108 | 108 | Specifies whether multiple observations should be stacked (``yes``) or |
| 109 | 109 | whether run-wise PHA, ARF and RMF files should be produced (``no``). |
| 110 | 110 | |
| 111 | +``(etruebins = 30) [integer]`` | |
| 112 | + Number of bins per decade for true energy bins. | |
| 113 | + | |
| 111 | 114 | |
| 112 | 115 | Standard parameters |
| 113 | 116 | ------------------- | ... | ... |